How to set GPIO as an output from the device tree

I am looking for a way to set the GPIO as an output with a certain value from the device tree.

I am wondering if I can achieve this for the pinctrl node.

For example:

the documentatio for pinmux mentions this:

- nvidia,enable-input: Integer. Enable the pin's input path.
    enable :TEGRA_PIN_ENABLE0 and
    disable or output only: TEGRA_PIN_DISABLE.

Based on this information I think I have to use TEGRA_PIN_DISABLE to use this pin as a output like this:

uart5_rts_px6 {
				nvidia,pins = "uart5_rts_px6";
				nvidia,function = "rsvd2";
				nvidia,pull = <TEGRA_PIN_PULL_UP>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_DISABLE>;
				status = "okay";
			};

But when I when I see the configuration from the userspace running these commands, the direction is input.

echo 390  > /sys/class/gpio/export
cat /sys/class/gpio/gpio390/direction

Do you think is possible set a GPIO as an output with a certain value.
Do you have some suggestion to achieve this?

Thank you in advance.

hello ManuelLeiva,

may I know how you get the gpio number of 390?
please refer to the [Tegra Linux Driver Package TX2 Adaptation Guide] and check the [GPIO changes] chapter for reference.
in my calculation, the GPIO number of uart5_rts_px6 should be (19*8)+320= 472
thanks

Hi JerryChang

You are right. In fact since I am using GPIO5_CAM_FLASH_EN I think the correct number is 478:

IC Ball	              Customer Usage
Name
GPIO5_CAM_FLASH_EN    GPIO3_PX.06
GPIO name      Group   Function             GPIO#
GPIO3_PX.06    MAIN    320 + (19 * 8 + 6)   478

Using 478 I am getting out direction

root@tegra-ubuntu:/home/nvidia# echo 478  > /sys/class/gpio/export
root@tegra-ubuntu:/home/nvidia# cat /sys/class/gpio/gpio478/direction
out

Now I wondering if I can set the output value from the device tree.

I really appreciate any suggestion.

Thanks.

hello ManuelLeiva,

you’re able to configure the GPIO pin directions from device tree only if the default pin direction is Bidirectional.
please check the Pinmux Spreadsheets from Jetson Download Center,

please have device tree settings for the pin status changes as below,

#output
    nvidia,enable-input = <TEGRA_PIN_DISABLE>;

#input
    nvidia,enable-input = <TEGRA_PIN_ENABLE>;

please also refer to [TX2 Configuring Pinmux GPIO and PAD] chapter in the [Development Guide] if you wanna modify the pinmux spreadsheet.
thanks

Hello,

Is there any way to configure the default value of an output GPIO as 1 in device tree?

Thanks!

hello hecnl4o,

yes, you’re able to configure default GPIO values as high/low in sensor device tree.
for example, below sources to set reset gpio pin as 1 by default. thanks

reset-gpios = <&tegra_main_gpio CAM0_RST_L GPIO_ACTIVE_HIGH>

Thank you, Jerry! I followed your example and the output GPIO works fine now.

Hi,

The default GPIO value can be defined from the device tree using the gpio-controller node (see gpio-controller nodes https://www.kernel.org/doc/Documentation/devicetree/bindings/gpio/gpio.txt)
For example.

If you want to set the default gpio478 (GPIO3_PX.06) value as high (output) from the device tree, you should create a new device tree entry under the GPIO controller. The GPIO controller is defined in: hardware/nvidia/platformt18x/common/kernel-dts/t18x-common-plugin-manager/tegra186-quill-p3310-1000-300-plugin-manager.dtsi

gpio@2200000 {
. . .
                camera-enable-output {
                        gpio-hog;
                        gpios = <TEGRA_MAIN_GPIO(X, 6) 0>;
                        output-high;
                        label = "camera-enable-output";
                        status = "okay";
                };
        };

Where:

output-high is a property specifying to set the GPIO direction as output with the value high. Also you can use “input” or “output-low”.

https://developer.ridgerun.com/wiki/index.php?title=RidgeRun_Professional_Services
https://www.ridgerun.com/contact