This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

device-tree entry for pwmleds in linux3.12

Hi,

We are using beaglebone black based custom board,
We are porting linux 3.12 for our board,
We have three leds which are to be controlled using pwm.
those LEDS are connected to following balls,

1. E18 --> Pinmux mode 0 --> eCAP0_in_PWM0_out
2. B19 --> Pinmux mode 3 --> eCAP1_in_PWM1_out
3. C18 --> Pinmux mode 3 --> eCAP2_in_PWM2_out

Now in device tree we have following entries for pin mux,

                backlight_pin: pinmux_backlight_pin {
                        pinctrl-single,pins = <
                                0x164 0x00  /* ecap0_in_pwm0_out.gpio0_7, OUTPUT | MODE0 */
                                0x18C 0x03  /* ecap1_in_pwm1_out.gpio3_6, OUTPUT | MODE3 */
                                0x188 0x03  /* ecap2_in_pwm2_out.gpio3_5, OUTPUT | MODE3 */
                        >;
                };


And now we want to enable ledpwm to control leds by led subsystem,
we referred "omap4-sdp.dts"

pwmleds {
                compatible = "pwm-leds";
                kpad {
                        label = "omap4::keypad";
                        pwms = <&twl_pwm 0 7812500>;
                        max-brightness = <127>;
                };

                charging {
                        label = "omap4:green:chrg";
                        pwms = <&twl_pwmled 0 7812500>;
                        max-brightness = <255>;
                };
        };
and similar way we added our led entry as follows,
        pwmleds {
                compatible = "pwm-leds";
                led1 {
                        label = "led1";
                        pwms = <&ehrpwm0 0 1000>;
                        max-brightness = <127>;
                };
        };

&ehrpwm0 {
        status = "okay";
};

but we have following bootlog

[    4.470590] /pwmleds/led1: arguments longer than property
[    4.476277] of_pwm_get(): can't parse "pwms" property
[    4.481623] leds_pwm pwmleds.5: unable to request PWM for led1

I think we are not able to enable pwm and because of that led1 node is not able to get the pwm,
I think i am missing something,
Any suggestions for enabling pwmleds ?

Thank you,

Regards,
Ankur



  • Hi Ankur,

    Try to change the code like below.

       pwmleds {
                    compatible = "pwm-leds";
                    led1 {
                            label = "omap4::led1";
                            pwms = <&ehrpwm0 0 1000>;
                            max-brightness = <127>;
                    };
            }; 

  • Hi Titus,

    Thank you for reply,

    we tried your suggestion, it didnt work,

    Here is bootlog reported errors,

    [    0.376361] pwmss pwm.4: invalid resource
    [    0.376405] pwmss: probe of pwm.4 failed with error -22

    ----cut----

    [    4.485349] /pwmleds/led1: arguments longer than property
    [    4.491053] of_pwm_get(): can't parse "pwms" property
    [    4.496386] leds_pwm pwmleds.5: unable to request PWM for omap4::led1


    Thanks

    Regards,
    Ankur

  • Hi Ankur,

    And now we want to enable ledpwm to control leds by led subsystem,
    we referred "omap4-sdp.dts"

    Have you referred this "omap3-beagle-xm.dts" file from your source ?

    Sorry. I didn't noticed that you are using "Beagle" board.

    Have a try,

    pwmleds {
                 compatible = "pwm-leds";
                 led1 {
                         label = "beagleboard::led1";
                         pwms = <&ehrpwm0 0 1000>;
                         max-brightness = <127>;
                 };
         };

    Where did you declared the "ehrpwm0" ?

    xx.dtsi ?

    Like below

                ehrpwm0: ehrpwm@48300200 {
                    compatible = "ti,am33xx-ehrpwm";
                    #pwm-cells = <3>;
                    reg = <0x48300200 0x80>;
                    ti,hwmods = "ehrpwm0";
                    status = "disabled";
                };

  • Hi Titus,

    Thank you for replying,

    We are not using beaglebone we using our custom board which is created keeping beaglebone as referance,

    I added changes your suggested, it doesnt work :(

    [    0.376522] ehrpwm pwm.4: failed to get clock
    [    0.376569] ehrpwm: probe of pwm.4 failed with error -2
    [    0.377400] ******list_name:clocks
    [    0.377418] ******size:4
    [    0.377426] ******list_end:50331648
    [    0.378261] ehrpwm 48300200.ehrpwm: unable to select pin group
    
    ---------------cut------------
    
    [    4.504276] ******list_name:pwms
    [    4.507675] ******size:12
    [    4.510459] ******list_end:33554432
    [    4.514151] /pwmleds/led1: arguments longer than property
    [    4.519854] of_pwm_get(): can't parse "pwms" property
    [    4.525187] leds_pwm pwmleds.5: unable to request PWM for beagleboard::led1
    [    4.532751] ledtrig-cpu: registered to indicate activity on CPUs

    yes ehrpwm0 is declared in am33xx.dtsi file,

    we changed its "status" property to "okay" in dtsi itself,

    We see following entries in the /sys/class/pwm/

    # ls /sys/class/pwm/
    pwmchip0  pwmchip1  pwmchip3
    
    # cat /sys/class/pwm/pwmchip0/device/modalias 
    platform:48300100.ecap
    # cat /sys/class/pwm/pwmchip1/device/modalias 
    platform:48300200.ehrpwm
    # cat /sys/class/pwm/pwmchip3/device/modalias 
    platform:48302200.ehrpwm


    Thank you,

    Regards,
    Ankur

  • Ankur,

    I think you need an entry similar to:

    &epwmss0 {
            status = "okay";
    
            ecap0: ecap@48300100 {
                    status = "okay";
                    pinctrl-names = "default";
                    pinctrl-0 = <&pwm_led_pins>;
            };
    };
    

    And, my pwm_led entry looks like this:

    / {
            pwm_led {
                    compatible = "pwm-leds";
    
                    led0 {
                            pwms = <&ecap0 0 50000 1>;
                            max-brightness = <255>;
                            linux,default-trigger = "default-on";
                            brightness = <127>;
                    };
            };
    };
    

    This was done on a BeagleBone Black.

    Hope this helps...

  • Hi RonB,

    Thank you for reply,
    There were syntax errors if i add device-tree as is suggested by you,
    With some modification i changed the device tree, i added following and it compiles fine now,

            am33xx_pinmux: pinmux@44e10800 {
                    pinctrl-names = "default";
                    backlight_pin: pinmux_backlight_pin {
                            pinctrl-single,pins = <
                                    0x164 0x00  /* ecap0_in_pwm0_out.gpio0_7, OUTPUT | MODE0 */
                                    0x18C 0x03  /* ecap1_in_pwm1_out.gpio3_6, OUTPUT | MODE3 */
                                    0x188 0x03  /* ecap2_in_pwm2_out.gpio3_5, OUTPUT | MODE3 */
                            >;
                    };
    	}
          
    
    	ocp {
    
                    epwmss0: epwmss@48300000 {
                            status = "okay";
                            /*ecap0: ecap@48300100 {*/ 
                            ehrpwm0: ehrpwm@48300200 {
                                    status = "okay";
                                    pinctrl-names = "default";
                                    pinctrl-0 = <&backlight_pin>;
                            };  
                    };  
                    epwmss1: epwmss@48302000 {
                            status = "okay";
                            ehrpwm1: ehrpwm@48302200 {
                                    status = "okay";
                                    pinctrl-names = "default";
                                    pinctrl-0 = <&backlight_pin>;
                            };  
                    }; 
    	};
    
    
     	pwm_led {
                    compatible = "pwm-leds";
                    led0 {
                            pwms = <&ehrpwm0 0 50000 1>;
                            max-brightness = <255>;
                            linux,default-trigger = "default-on";
                            brightness = <127>;
                    };
                    led1 {
                            pwms = <&ehrpwm1 1 50000 1>;
                            max-brightness = <255>;
                            linux,default-trigger = "default-on";
                            brightness = <127>;
                    };
    
            };
    

    With above changes we are seeing entries in "/sys/class/pwm/" and in "/sys/class/leds/".
    But the problem is we are not able to control the leds, leds are not switching on,

    # ls /sys/class/leds/
    led0  led1
    # ls /sys/class/leds/led0/
    brightness      max_brightness  subsystem       uevent
    device          power           trigger
    # cat /sys/class/leds/led0/trigger 
    none nand-disk timer oneshot heartbeat backlight gpio cpu0 [default-on] 
    # cat /sys/class/leds/led0/brightness 
    255
    # cat /sys/class/leds/led0/max_brightness 
    255
    
    
    # ls /sys/class/pwm/
    pwmchip0  pwmchip2
    # ls /sys/class/pwm/pwmchip0
    device     export     npwm       power      subsystem  uevent     unexport
    # cat /sys/class/pwm/pwmchip0/device/modalias 
    platform:48300200.ehrpwm

    we tried changing brightness and triggers under the leds but it didnt help,
    Any suggestions? do you see something missing ?

    Thank you,

    Regards,
    Ankur

  • Hi RonB/Titus,

    Thank you for help,
    Ron has suggested "ecap" but our understanding was that ecap is input cpature and ehrpwm is to be used for controlling leds.

    As per suggestion from colleague when we used ecap instead of ehrpwm0 we got pwm-leds working.

    Here is correct device-tree entry.

    am33xx_pinmux: pinmux@44e10800 {
                pinctrl-names = "default"; 
    
                    backlight_pin_0: pinmux_backlight_pin_0 {
                            pinctrl-single,pins = <
                                    0x164 0x00  
                            >;
                    };
                    backlight_pin_1: pinmux_backlight_pin_1 {
                            pinctrl-single,pins = <
                                    0x18C 0x03  
                            >;
                    };
                    backlight_pin_2: pinmux_backlight_pin_2 {
                            pinctrl-single,pins = <
                                    0x188 0x03  
                            >;
                    };
    
    };
    
           pwm_led {
                    compatible = "pwm-leds";
                    led0 {
                            pwms = <&ecap0 0 50000 1>;
                            max-brightness = <255>;
                            linux,default-trigger = "default-on";
                            brightness = <127>;
                    };
                    led1 {
                            pwms = <&ecap1 0 50000 1>;
                            max-brightness = <255>;
                            linux,default-trigger = "default-on";
                            brightness = <127>;
                    };
                    led2 {
                            pwms = <&ecap2 0 50000 1>;
                            max-brightness = <255>;
                            linux,default-trigger = "default-on";
                            brightness = <127>;
                    };
    
            };
    
    
    ocp {
                    epwmss0: epwmss@48300000 {
                            status = "okay";
                            ecap0: ecap@48300100 {
                                    status = "okay";
                                    pinctrl-names = "default";
                                    pinctrl-0 = <&backlight_pin_0>;
                            };
                    };
                    epwmss1: epwmss@48302000 {
                            status = "okay";
                             ecap1: ecap@48302100 {
                                    status = "okay";
                                    pinctrl-names = "default";
                                    pinctrl-0 = <&backlight_pin_1>;
                            };
                    };
    
                    epwmss2: epwmss@48304000 {
                            status = "okay";
                             ecap2: ecap@48304100 {
                                    status = "okay";
                                    pinctrl-names = "default";
                                    pinctrl-0 = <&backlight_pin_2>;
                            };
    		};
    
    };

    With above entry we could control the brightness of the leds.

    Well still we have some questions to get the understanding of these entries.

    1. Why is ecap used instead of ehrpwm ? As per TRM ecap is input capture and LEDs are output devices.
    2. what are the parameters supplied along with pwm in led node. e.g. pwms = <&ecap2 0 50000 1>
       50000 is set as period but, what 0 represents? and what 1 represents?
    3. With above setting we are able to control the brightness of the leds but how do we make it blink at particular rate ?


    Thank you,

    Regards,
    Ankur

  • Hi Ankur,

    Sounds good.

    http://processors.wiki.ti.com/index.php/Linux_Core_PWM_User%27s_Guide

    3. With above setting we are able to control the brightness of the leds but how do we make it blink at particular rate ?

    Try to generate PWM wave with low frequency (50 % duty cycle) ie 1Hz

    2. what are the parameters supplied along with pwm in led node. e.g. pwms = <&ecap2 0 50000 1>
       50000 is set as period but, what 0 represents? and what 1 represents?

    I'm not sure for '0' but

    1 -> PWM_POLARITY_INVERSED

    5000 -> period

    I think, 0 -> default disabled while startup

    And it could be enabled in userspace.

    1. Why is ecap used instead of ehrpwm ? As per TRM ecap is input capture and LEDs are output devices.

    We can use ECAP as PWM.

    I think , they have used ecap as pwm because of non-availability of peripheral (pin control) ie EHRPWM could be pinmuxed for different purpose.

  • Hi Titus,

    Thank you for reply,
    Linux core pwm user guide is very helpful.

    In general we are able to blink the leds using pwm but
    we wanted to use pwm-leds subsystem and wanted to blink it.

    Finaly we figured out how we can blink pwm-leds.
    There is a led-trigger driver which helps in blinking the leds.
    trigger driver allows leds to be associated to different triggers.
    One can find driver in following path

    Symbol: LEDS_TRIGGERS [=y]                                                                                                    │  
      │ Type  : boolean                                                                                                              
      │ Prompt: LED Trigger support                                                                                                  
      │   Location:                                                                                                                  
      │     -> Device Drivers                                                                                                        
      │       -> LED Support (NEW_LEDS [=y]) 
    
    
    Symbol: LEDS_TRIGGER_TIMER [=y]                                                                                               │  
      │ Type  : tristate                                                                                                             
      │ Prompt: LED Timer Trigger                                                                                                    
      │   Location:                                                                                                                  
      │     -> Device Drivers                                                                                                        
      │       -> LED Support (NEW_LEDS [=y])                                                                                         
      │         -> LED Trigger support (LEDS_TRIGGERS [=y])

    in our case we enabled timer trigger, so once timer trigger
    is set we see delay_{on/off} files under "/sys/class/leds/led0/"
    Which allows to set on and off time and allows to blink leds using timer.

    # cd led0
    # ls
    brightness      max_brightness  subsystem       uevent
    device          power           trigger
    # cat trigger 
    none nand-disk timer oneshot heartbeat backlight gpio cpu0 [default-on] transient flash torch 
    # echo timer > trigger 
    # ls
    brightness      delay_on        max_brightness  subsystem       uevent
    delay_off       device          power           trigger
    # cat delay_on 
    500
    # cat delay_off

    Now only mystery is the first parameter passed to the pwm.

    Thank you,

    Regards,
    Ankur

  • Hi Ankur,

    Thats a nice explanation.

    Now only mystery is the first parameter passed to the pwm.

    Have you changed the 1st parameter from '0' to '1' and able to see any differences ?

    Mean while I will look into the PWM code and Linux documentation.

  • Documentation/devicetree/bindings/pwm/pwm.txt

    pwm-specifier typically encodes the chip-relative PWM number and the PWM
    period in nanoseconds.

  • Hi Titus,

    Thank you for reply,
    Yes, i had changed 1st parameter from '0' to '1',
    And when i do that i dont see any entries under /sys/class/leds/
    I get following message in bootlog,

    [    2.409570] leds_pwm pwm_led.4: unable to request PWM for led3

    LED sub-node properties:
    - pwms : PWM property to point to the PWM device (phandle)/port (id) and to
      specify the period time to be used: <&phandle id period_ns>;

    One more observation is,
    Evenif i change one led's pwm entry other leds also doesn't show up, i had seen some patch related to this issue.

    I have one more doubt,
    We have three leds and we want to generate pattern wherein 1 led will be ON at time and each one switches ON one by one at specified interval.
    With current trigger(timer) i couldn't achive this.I tried other triggers also but it didn't help.
    Let me know if you have any suggestions

    Thank you,

    Regards,
    Ankur

  • Hi Titus,

    As it was not possible to generate led pattern from led-pwm driver alone,
    So we moved some logic to application,
    Mainly at what time "delay_on" and "delay_off" to be written, is controlled from application.
    With that logic we could acheive the LED pattern.

    I shall close this question now.

    Thank you,

    Regards,
    Ankur