Enable GPIO as output during boot

I am looking for a way to set up a GPIO as output during boot or any other permanent alternative.

My initial solution consisted in running a cronjob @startup executing the following commands:

echo 298 /sys/class/gpio/export
echo out > /sys/class/gpio/gpio298/direction

The previous approach works fine, however, it takes a couple of seconds for this to be executed.

I’ve looked into other alternatives such as pinmax and device trees, but I can’t seem to fully understand the procedure.

Based on the GPIO TX2 Reference Table, the device tree name of the GPIO I am trying to control is can_gpio2_paa2. http://connecttech.com/resource-center/kdb342-using-gpio-connect-tech-jetson-tx1-carriers/

Also, (when exported) it is listed under

GPIOs 256-319, platform/c2f0000.gpio, tegra-gpio-aon:
 gpio-298 (                    |sysfs               ) in hi

I am using JetPack 3.3 and TEGRA 28.2.1

Any advice would be greatly appreciated!
Kevin Serrano

UPDATE: setting the default value to low for this specific GPIO would be enough to solve my problem.

Hi kserranov,

In order to set that GPIO during boot, you can apply the following patch to the device-tree:

diff --git a/hardware/nvidia/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-quill-comms.dtsi b/hardware/nvidia/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-quill-comms.dtsi
index 11c4331..1a3fc5d 100644
--- a/hardware/nvidia/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-quill-comms.dtsi
+++ b/hardware/nvidia/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-quill-comms.dtsi
@@ -42,6 +42,12 @@
 			input;
 			label = "wifi-wake-ap";
 		};
+		can-gpio2-paa2 {
+			gpio-hog;
+			gpios = <TEGRA_AON_GPIO(AA, 2) 0>;
+			output-low;
+			label = "can-gpio2-paa2";
+		};
 	};
 
 	bluedroid_pm {

To apply this change, you need to get and compile L4T sources and then update the device-tree. You can follow this guide to install dependencies, toolchain, get and compile sources:
https://developer.ridgerun.com/wiki/index.php?title=Compiling_Jetson_TX1/TX2_source_code

As you need to update only the device-tree, you could try updating the device-tree without flashing the system by following this procedure:
https://developer.ridgerun.com/wiki/index.php?title=Compiling_Jetson_TX1/TX2_source_code#Flash_DTB_from_the_Jetson_device_itself

Regards,
-Enrique

Hi Enrique,

Thank you for the fast reply! (and sorry for my late feedback)

I’ve patched the device tree file as mentioned and performed all the steps necessary to flash the DTB into the Jetson. However, the changes to the GPIO did not take effect.

After examining the output from the flashing procedure I noticed the DTB file being loaded is a different one than “tegra186-quill-p3310-1000-c03-00-base.dtb”.

populating $DEVDIR/kernel/dtb/tegra186-tx2-cti-ASG002-USB3.dtb to rootfs... done.

And the mistake was mine since I forgot to mention that I am using an elroy carrier board. Therefore I am guessing the device-tree patch should be a different one.

Below I include the flashing command I used as well as the final output. I would really appreciate if you could help me figuring out which DTB file should I modify now. Thanks in advance!

sudo ./flash.sh -r -k kernel-dtb elroy-usb3 mmcblk1p1
[   5.3892 ] Writing partition
[   5.3922 ] tegradevflash_v2 --write kernel-dtb $DEVDIR/bootloader/signed/tegra186-tx2-cti-ASG002-USB3_sigheader.dtb.encrypt
[   5.3945 ] Bootloader version 01.00.0000
[   5.3963 ] Writing partition kernel-dtb with $DEVDIR/bootloader/signed/tegra186-tx2-cti-ASG002-USB3_sigheader.dtb.encrypt
[   5.3969 ] [................................................] 100%
[   5.4330 ] 
[   5.4331 ] Coldbooting the device
[   5.4340 ] tegradevflash_v2 --reboot coldboot
[   5.4347 ] Bootloader version 01.00.0000
[   5.4409 ] 
*** The [kernel-dtb] has been updated successfully. ***

hello kserranov,

not sure what’s the modification you had done to adapt the carrier board.
suggest you disassembler the your dtb file into txt file, checking the change in comment #2 has applied correctly.
for example,

$ dtc -I dtb -O dts -o output.txt tegra.dtb