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.

Setting default GPIO pin value in device tree

I am using an am335x chip and I would like to set a gpio pin to a certain value at boot time.  It is my understanding that you can assign default values to a gpio pin in the device tree.  This would be perfect.  However, all my searching on the web has turned up 0 examples on how to do this.  Can anyone provide me an example of how to go about doing this?  I am using SDK 7 with kernel version 3.12.

  • Hi Tim,

    You can assing the GPIO pin to be active high or active low. For example see gpio-keys node in am335x-evm.dts file:
    switch@10 {
    ..............
    gpios = <&gpio0 3 GPIO_ACTIVE_LOW>;
    ..............
    }
    This defines that sw10 is on gpio0 pin 3 (GPIO0_3) and the gpio pin is active low.

    You can check the following guides for better understanding of GPIO nodes in device tree:
    https://www.kernel.org/doc/Documentation/devicetree/bindings/gpio/gpio.txt
    http://www.devicetree.org/Category:Type:gpio

    Best Regards,
    Yordan
  • Hi Tim,
    I'm not able to see setting the GPIO value in dts file but I'm not sure.
    You can add one entry (default state) for that and retrieve it in GPIO driver as like GPIO LED driver does (of_get_property) and use "gpio_direction_output" to change the value or "gpio_set_value".

    Ex:

    arch/arm/boot/dts/am335x-evmsk.dts

    led@4 {
    label = "evmsk:green:heartbeat";
    gpios = <&gpio1 7 0>;
    linux,default-trigger = "heartbeat";
    default-state = "off";
    };

    drivers/leds/leds-gpio.c

    state = of_get_property(child, "default-state", NULL);
    if (state) {
    if (!strcmp(state, "keep"))
    led.default_state = LEDS_GPIO_DEFSTATE_KEEP;
    else if (!strcmp(state, "on"))
    led.default_state = LEDS_GPIO_DEFSTATE_ON;
    else
    led.default_state = LEDS_GPIO_DEFSTATE_OFF;
    }
    -----------
    ret = gpio_direction_output(led_dat->gpio, led_dat->active_low ^ state);

    I hope it is very easy code change.
  • Hi Tim,

    Did you ever figure this out?
  • Hi Titus,

    I have this same issue. I want to use the device tree to set GPIO50 as an input, and GPIO49 as output low at startup (I will need to toggle this pin periodically during runtime)

    From what I've gathered after a day of research is that the only way to do this is to declare the output as gpio-leds and the inputs as gpio-keys. There has to be simpler way to configure this.
  • Hi Chris, I reached the same understanding... did you find a workaround ? Did you have to use the Kernel GPIO API and configure them in a similar way like in the old days of "board" files ? Best regards, Christophe