Using gpio led triggers in device tree

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using gpio led triggers in device tree

Jump to solution
10,384 Views
brycejohnson
Contributor I

I am working with a imx6ull custom board.

Was there a way to specify trigger parameters in the devicetree?

For example I'll like gpio 122 to trigger the led to blink.

Current DT:

leds {
 pinctrl-names = "default";
 pinctrl-0 = <&pinctrl_led>;
 compatible = "gpio-leds"; 
 led_wwan {
 label = "led_wwan";
 gpios = <&gpio2 4 GPIO_ACTIVE_LOW>;
};

In the userspace I can do this to make it work:

echo gpio > /sys/class/leds/led_wwan
echo 122 > echo gpio > /sys/class/leds/led_wwan

Adding trigger to DT:

leds {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_led>;
compatible = "gpio-leds"; 
led_wwan {
label = "led_wwan";
gpios = <&gpio2 4 GPIO_ACTIVE_LOW>;
linux,default-trigger = "gpio";
};

Can I set the 122 in the device tree or would I need to always do it in userland with 

echo 122 > /sys/class/leds/led_wwan‍‍/gpio
Labels (1)
0 Kudos
1 Solution
6,531 Views
igorpadykov
NXP Employee
NXP Employee

Hi bryce

no, seems there is no way to set gpio value from dts.

Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
4 Replies
6,531 Views
lategoodbye
Senior Contributor I

Hi Bryce,

AFAIK there is no led trigger GPIO and the idea behind LED triggers is to avoid userspace application to handle them. In case of of blinking try to use the LED trigger "timer" for a periodic one or "heartbeat" which is related to the system load.

Always look at the binding documents for more information:

linux/Documentation/devicetree/bindings/leds/common.txt - Elixir - Free Electrons 

0 Kudos
6,531 Views
brycejohnson
Contributor I

Stefan,

For my use case, I need to pass through a signal to blink an LED.  I could constantly poll the input and set LED, but the trigger for GPIO seems to work much better.

In at least the 4.9.11 kernel in the LED Trigger support you can enable LED GPIO Trigger.

Then for the leds I get these triggers:

cat /sys/class/leds/led_wwan/trigger
none kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock mmc1 timer oneshot heartbeat [gpio] default-on

This will set up the trigger with gpio 122 as a input:

echo gpio > /sys/class/leds/led_wwan/trigger

echo 122 > /sys/class/leds/led_wwan/gpio

When GPIO 122 see a high signal it will turn the LED on and low signal turns it off.  

I thought there might be a way to see the 122 in the device tree, but currently there is not.  I can set it up after boot.

Thanks

Bryce

0 Kudos
6,531 Views
brycejohnson
Contributor I

Thanks for checking.

There appeared to be some work in that area from these posts: [PATCH 1/4] dt-bindings: leds: document property for LED triggers — Linux LEDS Development 

But I didn't see any of that in the stuff I am using, so I assume it uses a later version or didn't get pull in to the kernel.

0 Kudos
6,532 Views
igorpadykov
NXP Employee
NXP Employee

Hi bryce

no, seems there is no way to set gpio value from dts.

Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos