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.

Linux/AM5728: Setting GPIO output in device tree

Part Number: AM5728

Tool/software: Linux

I would like to be able to set a default GPIO state in the device tree, and I would also like to easily change the output after the system boots. I'm able to use the gpio-hog property to set the initial output, but I am unable to modify its value after boot up by using sysfs. Is there another method of initializing a GPIO's output in the device tree? Or after the gpio-hog property is used in a gpio node, is there a way to modify the output after boot?

  • Hi Heather,

    Do you use AM572x TI board or custom board?

    Do you use AM57x TI PSDK? If yes, which version?

    Please go through the below link:

    processors.wiki.ti.com/.../Processor_SDK_Linux_GPIO_Driver_Overview
  • We're using a custom board, and we're using Ubuntu, but from what I can tell, this capability shouldn't be specific to the PSDK.

    I did come to a solution that at least works, though it would be nice to use the gpio-hog property and still use sysfs. What I do is set an initial GPIO output in the device tree using gpio-hog, and then if I want to modify the output later, I use devmem2 to modify the the registers directly.

  • Heather,

    PSDK kernel driver configures the GPIO HW and makes it available to the sysfs interface for user space interaction. Could you please provide your steps to reproduce the issue? I will try these on AM572x TI EVM with PSDK.

    "gpio-hog" is a gpio node property, which tell the gpio controller to either set the pin to high/low during boot up. I do not think "gpio-hog" will prevent you to use the sysfs control of GPIO.

    See also below e2e thread:

    e2e.ti.com/.../495548

    Regards,
    Pavel
  • Hi Pavel,

    This is what I have in my device tree:

    &gpio8 {
        pinctrl-names = "default";
        pinctrl-0 = <&gpio8_pins>;
        output_gpios {
            gpio-hog;
            gpios = <9 GPIO_ACTIVE_HIGH>;
            output-high;
        };
    };
    

    And when I try export the GPIO in /sys/class/gpio:

    root@enso:/sys/class/gpio# echo 233 > export
    -bash: echo: write error: Device or resource busy

    When I comment out the output_gpios section:

    &gpio8 {
        pinctrl-names = "default";
        pinctrl-0 = <&gpio8_pins>;
    //    output_gpios {
    //        gpio-hog;
    //        gpios = <9 GPIO_ACTIVE_HIGH>;
    //        output-high;
    //    };
    };
    

    I can run the same command without any trouble.

  • Hi Heather,

    Seems that when u-boot or kernel use a GPIO pin (with or without gpio-hog), you can not export that pin from user space.

    See the below pointers for more info:

    e2e.ti.com/.../2349690

    www.spinics.net/.../msg15040.html
    stackoverflow.com/.../purpose-and-usage-of-gpio-hog-declaration

    Regards,
    Pavel
  • So basically the proper way to accomplish what I want is to set the GPIOs as LEDs?

  • Heather,

    GPIO's which are used already in the drivers can not be control from sysfs, unless until driver export that particular pin. Run these commands for knowing what are the GPIO's already requested in the drivers.

    $mount -t debugfs debugfs /sys/kernel/debug

    $cat /sys/kernel/debug/gpio

    For controlling LEDs and Buttons, the kernel has standard drivers, "leds-gpio" and "gpio_keys", respectively, that should be used instead of GPIO directly.  

    Note that standard kernel drivers exist for common "LEDs and Buttons" GPIO tasks:  "leds-gpio" and "gpio_keys", respectively. Use those instead of talking directly to the GPIOs; they integrate with kernel frameworks better than your userspace code could.

     

    You can also try this approach: Try to control the GPIO output value not through gpio-hog, but with internal pull up enable, configured in the CTRL_CORE_PAD_x register. You should control the pinmux in u-boot-spl code.

    Regards,
    Pavel