Device tree GPIO default Value

Hello,

I am trying to configure a wifi card on my Jetson TK1 using the mainline kernel. I realized that by default the GPIO 191 (WF_EN) is disable, which provokes the card to be disabled. I manage to fix this using sysfs, however I would like to modify the jetson-tk1 device tree to have a cleaner fix.

Checking on internet I found that there is a propertie that should do the job (gpio-output-high) however it doesn’t seem to work on mainline… I would be really thankful if anyone could put me an example of how to modify the default state of a GPIO using the device tree…

Kind regards,
Rafa

hello lord.rafa,

you should found below settings in device tree to define default GPIO settings,
for example,

        gpio: gpio@6000d000 {
                gpio-init-names = "default";
                gpio-init-0 = <&gpio_default>;

                gpio_default: default {
                        gpio-input = <  ...>
                        gpio-output-low = <...>
                        gpio-output-high = <...>

Hello,

This is the dts that I am using, I tried adding the code that you told to the tegra124 gpio: gpio@6000d000 section at tegra124.dtsi but it doesn’t look to work. Also I cannot find any example on the main tree, would you mind to help me a litlebit more? btw I am working with Linux 5.1.1

tegra124-jetson-tk1.dts

// SPDX-License-Identifier: GPL-2.0
/dts-v1/;
#include <dt-bindings/input/input.h>
#include "tegra124.dtsi"
#include "tegra124-jetson-tk1-emc.dtsi"
/ {
...
	pinmux: pinmux@70000868 {
		pinctrl-names = "boot";
		pinctrl-0 = <&state_boot>;
		state_boot: pinmux {
...
			gpio_x7_aud_px7 {
				nvidia,pins = "gpio_x7_aud_px7";
				nvidia,pull = <TEGRA_PIN_PULL_UP>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_DISABLE>;
			};
...
		};
	};
...
};

tegra124.dtsi

	gpio: gpio@6000d000 {
		compatible = "nvidia,tegra124-gpio", "nvidia,tegra30-gpio";
		reg = <0x0 0x6000d000 0x0 0x1000>;
		interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>,
			     <GIC_SPI 33 IRQ_TYPE_LEVEL_HIGH>,
			     <GIC_SPI 34 IRQ_TYPE_LEVEL_HIGH>,
			     <GIC_SPI 35 IRQ_TYPE_LEVEL_HIGH>,
			     <GIC_SPI 55 IRQ_TYPE_LEVEL_HIGH>,
			     <GIC_SPI 87 IRQ_TYPE_LEVEL_HIGH>,
			     <GIC_SPI 89 IRQ_TYPE_LEVEL_HIGH>,
			     <GIC_SPI 125 IRQ_TYPE_LEVEL_HIGH>;
		#gpio-cells = <2>;
		gpio-controller;
		#interrupt-cells = <2>;
		interrupt-controller;
		/*
		gpio-ranges = <&pinmux 0 0 251>;
		*/
                gpio-init-names = "default";
                gpio-init-0 = <&gpio_default>;

                gpio_default: default {
                                gpio-input = <>;
                                gpio-output-low = <>;
                                gpio-output-high = <191>;
                };
	}
...
};

EDIT: After check the code I would day that this elements are only available on android line but they are not implemented on the mainline kernel. Is there any other way to configure the default GPIO state???

Hello,

Finally I solve the issue myself by writing a kernel patch myself. It just add the required code from the android line.

Not wonderful bit it just work fine for me.

For future reference in case anyone find this post. There is already a standard mechanism to set GPIOS initial status on linux mainline. By adding an element gpio-hog to the device tree it is possible to configure the GPIO as in/out high/out low. This is the patch that finally I used to solve the problem with the wifi cards.