Include GPIO in device tree

Hi All,

I have been looking to configure the gpios in dts file for one of the drivers . But unable to figure out how to find the number for the gpio. Can anyone please suggest how to do this.

I already have a node like below :

&spi_9 {
status = “ok”;
custom-controller@0 {
compatible = “custom,drivername”;
reg = <0>;;
reset-gpio = < 0x13 X 0 >; //this is a gpio to be controlled
wakeup-gpio = < 0x13 X 0>; //this is a interrupt, 0x13 is phandle for gpio controller
spi-max-frequency = <5000000>;

in the kernel driver, i want to use, request_gpio( ) and control this gpio and also i want to register for the interrupt on the wakeup-gpio.

I am unable to figure out what gpio number should be assigned here.
i see an example in the present dtb file, but this node is disabled and i cannot find out which pin it corresponds to in the pinmux sheet.
below is the example i found:
gps_wake {
compatible = “gps-wake”;
gps-enable-gpio = <0xc2, 0x8, 0x0>;

in the corresponding driver , they are using the gpio exactly the way i intend to use.
But unfortunately how did they figure out the above 3 cell values for the gps-enable-gpio ?

in my case i want to use gpio11 and gpio 7 from the 40 pin header.


Generally we don’t read the hex/binary in dts.

You should check the source of this dts to find out what is the gpio.

Hello @WayneWWW,

i figured out this values :
gps-enable-gpio = <0x13, 0x8, 0x0>;
0x13 is the phandle for the GPIO controller, this can be searched in the dts file to figure out in which gpio controller, the corresponding gpio belongs. (i am using phandle, as this is the dts file converted from dtb)
Next value is the gpio number in the used gpio controller.
pin num = (port * 8) + pin (we should not add the base)
last value is the default state, like high or low.

Regarding the correct dts file, this is the most challenging part of working with nvidia stuffs. Probably in the process of making things easy by giving some on-device python tools, they made things really worst.
i could never figure out the correct dts files for the Jetson Xavier NX devkit.
This is the reason , i started modifying the dtb file /boot/compatible.dtb

And the excelsheet method for the pinctrl dts doesnt work at all.
i generated the dts file using the excel sheet. and then generated the .cfg file as per the steps given. Then i used to update only the cfg file. The flash script showed great verbose logs and there was no error. After the reboot nothing chaged.
So i am only modifying the dtb file directly.

It would be great, if u can tell me how i can figure out the correct dts files . (my device is Xavier NX devkit)
Also, can you please explain this excel sheet method clearly?

Also, i am really glad to see a response from WayneWWW , as you are the most famous solution provider in this nvidia Forum.


Hi Bala,

  1. Actually the rule of device tree(dts/dtb) is from linux but not defined by NV. NV just splits it into many dtsi files because we have too much platforms to handle (e.g. t210 for TX1/Nano, T186 for TX2 series and T194 for Xavier/NX)

You can figure out the dts file by firstly checking the board config. For example, if you are using NX devkit, then the board config is jetson-xavier-nx-devkit.conf.

Then, according to the board config, you shall see it includes another source file.

source “${LDK_DIR}/p3668.conf.common”;

So we open this p3668.conf.common too. Around line 100, you can see “DTB_FILE = tegra194-p3668-all-p3509-0000.dtb;” This is the dtb file you are using for jetson NX.

97 ODMDATA=0xB8190000;
98 CHIPID=0x19;
100 BPFDTB_FILE=tegra194-a02-bpmp-p3668-a00.dtb;
101 DTB_FILE=tegra194-p3668-all-p3509-0000.dtb;
102 TBCDTB_FILE=tegra194-p3668-all-p3509-0000.dtb;

After figuring out the dtb file, you can go to the download center and download the source.

In the source file, find the file name “tegra194-p3668-all-p3509-0000.dts”. Again, open this file and you shall see it includes other dtsi files too. You can then track it down. It is the start of your hardwork.

 16 /dts-v1/;
 17 #include "common/tegra194-p3668-common.dtsi"
 18 #include "common/tegra194-p3509-0000-a00.dtsi"
 20 / {
 21         nvidia,dtsfilename = __FILE__;
 22         nvidia,dtbbuildtime = __DATE__, __TIME__;
 24         compatible = "nvidia,p3449-0000+p3668-0000", "nvidia,p3449-0000+p3668-0001", "nvidia,p3509-0000+p3668-0000", "nvidia,p3509-0000+p3668-0001", "nvidia,tegra194";
 25 };

If you are tired of tracking this code, you can also add your change directly to tegra194-p3668-all-p3509-0000.dts. Since it is the last dts file, it won’t be override by other dtsi files anymore.

  1. i generated the dts file using the excel sheet. and then generated the .cfg file as per the steps given. Then i used to update only the cfg file. The flash script showed great verbose logs and there was no error. After the reboot nothing chaged.
    So i am only modifying the dtb file directly.

I think there are some mistakes here because AFAIK the cannot flash pinmux cfg file only. You have to do the full flash.
Also, updating the pinmux cfg only changes the pin function between SFIO and GPIO. This has nothing to do with your goal. If you want to use a GPIO in your driver, then you need to configure the pinmux and add gpio pin to “gps-enable-gpio” to dts.

As for configuring pinmux, actually there are two methods

  1. using the spreadsheet to generating dts and then use python tool to generate cfg file. You already knew this method. I also suggest to use this method.

  2. directly configuring the pin function to gpio in dts.

1 Like

Thanks for the dts file info.

I could find it inside the hardware folders inside sources.
may be earlier i was looking only inside the arch/arm64/boot/dts folder.

Thanks for clarifying the flash process also.

yes - regarding the pinmux changes in the cfg file, earlier my goal was to configure the spi pins without using the python tool as i had to deliver changes in generic way.

Hi Wayne,

Can u please provide me an example for modifying the dts file to add a input gpio with parameters to control pull up etc.

I am modifying the pin ctrl using the excel sheet and then replacing the cfg file in bootloader folder and reflashing the entire thing. Finally it looks like the pin behaviour is no different. It looks like the cfg file is never really making difference.

I cannot find a similar exaple to modify the dts file. in fact, the changes i want to do is to control the pull down , pull up behavior for the pin

if i take the example that i saw before, for gps-wakeup, how can i add the nvidia,pull property for it?

Based on the observation, irrespective of what is the configuration of the gpio pins, its always a pull down behaviour. i checked with the gpios which were by default shown as pull up. Even those input pins pull the input lines low. Any way to forcefully make it pulll up?



What is the exact usecase you want to use one this gpio?

Generally, there few ways to control the GPIO.

  1. If this gpio is not in use by any driver, you can directly use the gpio sysfs to control the value.

  2. If the gpio is written as “gps-enable-gpio = <0xc2, 0x8, 0x0>;” then it means this gpio is controlled by the driver so the behavior depends on the driver.

  3. Or you can write something similar as below under the gpio controller under the gpio contoller in the dts.

gpios = <TEGRA_GPIO(V, 0) 0 >; #V0 is just an example

Please note that pinmux configuration from the spreadsheet does not do anything equal to above 3 configurations. I would suggest you can use method 1 here to check if the gpio is really working.