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.

AM3358: Setting GPIO default value when Linux kernel starts

Part Number: AM3358

Hi,

I have a requirement to set a GPIO pin to a default value (e,g, high) during Linux kernel starting up.

This is the snippet of my gpio configuration in am335x-boneblack.dts to change the gpio0_23 configuration:

am33xx_pinmux {
        pinctrl-names = "default";
        pinctrl-0 = <&my_gpio0_pins>;

        my_gpio0_pins: pinmux_my_gpio0_pins {
                pinctrl-single,pins = <
                        ...
                        AM33XX_PADCONF(AM335X_PIN_GPMC_AD9, PIN_OUTPUT, MUX_MODE7)       /* gpmc_ad9.gpio0_23 */
                        ...
                >;
        };
        ...
};

However, I cannot seem to find an example of setting its default value to high.

Question: What is the proper way to do this in Linux?

Thank you for your help!

  • Hi Matt,

    AM33XX_PADCONF(AM335X_PIN_GPMC_AD9, PIN_OUTPUT, MUX_MODE7)       /* gpmc_ad9.gpio0_23 */

    Please try to use PIN_OUTPUT_PULLUP instead of PIN_OUTPUT.

  • Hi Bin,

    Thank you for the reply.

    I did try using the PIN_OUTPUT_PULLUP instead of PIN_OUTPUT. However, compared with using the PIN_OUTPUT_PULLUP, the PIN_OUTPUT voltage amplitude is higher (3.3V vs. 3.14V). Also, it is much faster to drive the the signal using PIN_OUTPUT.

    So is there a way to set the default value to high using PIN_OUTPUT?

    Thank you!

  • Hi Matt,

    I am not sure why enabling GPIO internal pullup would cause these differences. I am looping in our hardware expert for comments.

    So is there a way to set the default value to high using PIN_OUTPUT?

    Can you add external pullup on your board?

  • Hi Bin,

    Yes, please help forward the question to the experts.

    I will check with our hardware engineer for the possibility of adding external pullup.

    But as a general question, shouldn't there be a way to set the default value when the pin is set to PIN_OUTPUT? Or, please explain if this cannot be done.

    Thank you for your help!

  • Bin,

    Matt wants to turn on the output buffer and drive the pin high rather than use the weak internal pull-up to source a high logic level. You need to tell him how to set the GPIO associated with this pin to output mode with a high logic state via Linux.

    Regards,
    Paul

  • Paul,

    Matt wants to turn on the output buffer and drive the pin
    You need to tell him how to set the GPIO associated with this pin to output mode with a high logic state via Linux.

    This can only be done in user space after Linux is booted. But What Matt asked is to see the GPIO default to high level "during" Linux starting up. I think using the internal pull-up is the only option.

    Matt,

    Or you can try to use "gpio-hog". I never tried it this myself, am not sure how soon kernel will parse this device tree node and set the GPIO pin output level accordingly.

    Please refer to the kernel documentation: <kernel-source>/Documentation/devicetree/bindings/gpio/gpio.txt for the usage of gpio-hog.

  • Hi Bin,

    Thank you for the suggestion. I saw gpio-hog from web searches previously. Some said if gpio-hog is used, the gpio cannot be exported and set in user space. If this is the case, it will not work my application. The only option left to achieve this is to set the gpio value in u-boot, but still set the gpio to be PIN_OUTPUT in Linux device tree. Is this correct?

    I will try gpio-hog anyway, but just want to know what other options I have.

    Thank you for your help!

  • Hi BIn,

    I can confirm that I was able to set the gpio value using gpio-hog. However, the user space application is unable to control the value after the gpio is "hogged" by the kernel... :(  This won't work for my application.

    Is setting the gpio value in u-boot the only option? Please confirm or elaborate if there are other solutions.

    Thank you.