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.

PROCESSOR-SDK-AM65X: GPIO LEDs in device tree

Part Number: PROCESSOR-SDK-AM65X


Hi forum,

I'm feeling really dumb and need some help.  We have two LEDs, a yellow one connected to GPIO1_28 and a red one connected to GPIO1_43.  The LEDs are active high, i.e. they will turn on when the corresponding GPIO line is active high.

We'd like to control them using the "gpio-leds" driver, but having trouble figuring out the correct syntax in the device tree.

Within &main_pmx0, I can define a group of LED pins like:

    led_pins_default: led-pins-default {
        pinctrl-single,pins = <
            AM65X_IOPAD(0x01f0, PIN_OUTPUT, 7)    /* (AD11) GPIO1_28 (LED D2 - Yellow) */
            AM65X_IOPAD(0x022C, PIN_OUTPUT, 7)    /* (AD26) GPIO1_43 (LED D3 - Red) */
        >;

    };

However, I cannot figure out the correct device tree syntax to enable these pins as individual LEDs so that they could be controlled via /sys/class/leds, or connected to kernel events.

Can anyone provide an example, perhaps with and without a kernel event?

Thanks, and apologies for not being able to figure this out from other examples.  I think what is throwing me is that each GPIO port has a large number of pins on it, and that's not the case for most other processors.

Best regards!

Scott

  

  • Hi Scott,

    You can first explore how "gpio-keys" driver is implemented in AM65x DTS : k3-am654-base-board.dts, as for "gpio-leds" we have similar approach.

    Then you can refer to below DTS files for exaple of "gpio-leds" driver coding in DTS:

    linux-kernel/arch/arm/boot/dts/am57xx-beagle-x15-common.dtsi

    linux-kernel/arch/arm/boot/dts/am437x-sk-evm.dts


    linux-kernel/Documentation/devicetree/bindings/leds/leds-gpio.txt


    Check also below e2e threads, these might be in help:

    https://e2e.ti.com/support/processors/f/791/t/658992

    https://e2e.ti.com/support/processors/f/791/t/826370


    Regards,
    Pavel

  • Thanks for your help, Pavel,

    For anyone trying the same sort of thing, this is what I ended up doing.  In my DTS file, I had GPIO lines defined for the LEDs under &main_pmx0:

    &main_pmx0 {

    ...

        main_gpio1_pins_default: main-gpio1-pins-default {
            pinctrl-single,pins = <
                /* LEDs */
                AM65X_IOPAD(0x01f0, PIN_OUTPUT, 7)    /* (AD11) GPIO1_28 (LED D2 - Yellow) */
                AM65X_IOPAD(0x022C, PIN_OUTPUT, 7)    /* (AD26) GPIO1_43 (LED D3 - Red) */
    ..etc...

    At the top level of my DTS file, I then added:

    / {

    ...

        gpio-leds {
            compatible = "gpio-leds";
            
            led-yellow {
                gpios = <&main_gpio1 28 GPIO_ACTIVE_HIGH>;
                default-status = "off";
            };
            
            led-red {
                gpios = <&main_gpio1 43 GPIO_ACTIVE_HIGH>;
                default-state = "off";
            };
        };
    };

    After rebuilding Linux and writing it to an SD card, I was then able to test the LEDs using the sysfs interface, e.g.

    cd /sys/class/leds/led-red

    cat brightness

    0

    echo 1 > brightness # Turns on red LED

    echo 0 > brightness # Turns off red LED

    cat trigger

    [none] kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-al
    tgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd
    -ctrlrlock disk-activity disk-read disk-write ide-disk heartbeat cpu cpu0 cpu1 c
    pu2 cpu3 default-on panic mmc0 mmc1 rfkill-any rfkill-none

    echo heartbeat > trigger # Flashing twice, delays, and repeats

    echo mmc1 > trigger # Nothing happens

    sync # Blinks once

    echo none > trigger

    You can do the same kinds of things using led-yellow, too.

    Hope this helps - I appreciate the help from Pavel and hope this pays it forward a bit!

    Scott