Skip to main content
SChen.11
Associate III
June 7, 2019
Solved

How to use timers2 as pwm-backlight?

  • June 7, 2019
  • 4 replies
  • 3273 views

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?

This topic has been closed for replies.
Best answer by Bernard PUEL

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 };

4 replies

PatrickF
Technical Moderator
June 10, 2019
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.NEW ! Sidekick STM32 AI agent, see here
SChen.11
SChen.11Author
Associate III
June 11, 2019

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
Technical Moderator
June 12, 2019

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.

SChen.11
SChen.11Author
Associate III
June 13, 2019
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
Bernard PUELBest answer
Technical Moderator
June 13, 2019

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 };

SChen.11
SChen.11Author
Associate III
June 13, 2019

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

Bernard PUEL
Technical Moderator
June 13, 2019

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