cancel
Showing results for 
Search instead for 
Did you mean: 

How to use timers2 as pwm-backlight?

SChen.11
Associate III

HI, I needs use timers2 to enable the pwm function. Then it will used as pwm-backlight for LCD. I wasn't known how to write the dts file. Could you show me some example code on this function?

1 ACCEPTED SOLUTION

Accepted Solutions
Bernard PUEL
ST Employee

Could you please try this declaration and use &pwm2 phandle in your pwms declaration ( pwms = <&pwm2 0 5000000>;):

503 &timers2 {

504         status = "okay";

505         /* spare dmas for other usage */

506         /delete-property/dmas;

507         /delete-property/dma-names;

508 -        pwm {

    +        pwm2: pwm {

509                 pinctrl-0 = <&pwm2_pins_a>;

510                 pinctrl-1 = <&pwm2_sleep_pins_a>;

511                 pinctrl-names = "default", "sleep";

512                 #pwm-cells = <2>;

513                 status = "okay";

514         };

515 -        timer@1 {

516 -                status = "disabled";

517 -        };

518 };

View solution in original post

7 REPLIES 7
PatrickF
ST Employee

You could find some details in https://wiki.st.com/stm32mpu/wiki/TIM_device_tree_configuration and https://wiki.st.com/stm32mpu/wiki/PWM_overview

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi PatrickF Thanks. I got this error message.

 Warning (pwms_property): /panel-backlight: Missing property '#pwm-cells' in node /soc/timer@40000000 or bad phandle (referred from pwms[0])

Here is my backlight dts code

187         panel_backlight: panel-backlight {
188                 compatible = "pwm-backlight";
189                 pwms = <&timers2 0 5000000>;
190                 brightness-levels = <0 4 8 16 32 64 128 255>;
191                 default-brightness-level = <6>;
192                 status = "okay";
193         };
 

​It seems my "pwms" value was wrong.

Bernard PUEL
ST Employee

You have first to configure your pinctrl of your pwm output like described in this article (remove the trigger source part):

https://wiki.st.com/stm32mpu/wiki/TIM_device_tree_configuration#TIM_configured_in_PWM_mode_and_trigger_source

Then you will need to use your &pwm1_pins_a phandle defined instead of &timers2 above. see:

https://github.com/STMicroelectronics/linux/blob/v4.19-stm32mp/Documentation/devicetree/bindings/pwm/pwm.txt

As you will use in your backlight declaration 2 arguments (pwms = <&pwm1_pins_a 0 5000000>;), you will need to add this property in your pwm node:

#pwm-cells = <2>;

Hoping it is clear.

503 &timers2 {
504         status = "okay";
505         /* spare dmas for other usage */
506         /delete-property/dmas;
507         /delete-property/dma-names;
508         pwm {
509                 pinctrl-0 = <&pwm2_pins_a>;
510                 pinctrl-1 = <&pwm2_sleep_pins_a>;
511                 pinctrl-names = "default", "sleep";
512                 #pwm-cells = <2>;
513                 status = "okay";
514         };
515         timer@1 {
516                 status = "disabled";
517         };
518 };
 
 
187         panel_backlight: panel-backlight {
188                 compatible = "pwm-backlight";
189                 pwms = <&pwm2_pins_a 0 5000000>;
190                 brightness-levels = <0 4 8 16 32 64 128 255>;
191                 default-brightness-level = <6>;
192                 status = "okay";
193         };

I add the "pwm-cell" attribute to timers2 block. Then I use pwm2_pins_a also has the warning info.

Warning (pwms_property): /panel-backlight: Missing property '#pwm-cells' in node /soc/pin-controller@50002000/pwm2-0 or bad phandle (referred from pwms[0])

Bernard PUEL
ST Employee

Could you please try this declaration and use &pwm2 phandle in your pwms declaration ( pwms = <&pwm2 0 5000000>;):

503 &timers2 {

504         status = "okay";

505         /* spare dmas for other usage */

506         /delete-property/dmas;

507         /delete-property/dma-names;

508 -        pwm {

    +        pwm2: pwm {

509                 pinctrl-0 = <&pwm2_pins_a>;

510                 pinctrl-1 = <&pwm2_sleep_pins_a>;

511                 pinctrl-names = "default", "sleep";

512                 #pwm-cells = <2>;

513                 status = "okay";

514         };

515 -        timer@1 {

516 -                status = "disabled";

517 -        };

518 };

Thanks for your help. It is working for my case.

Bernard PUEL
ST Employee

ok that's great. We will update the wiki for better clarity.