To determine the device tree mapping from the physical pin number or signal side, look at the pinmux table, look for the Jetson Nano signal name that corresponds to the physical pin number then look at the GPIO column and the values after “GPIO#_P” should give you the (port, offset).
there’s GPIO header file to define the port numbers, it’s tegra-gpio.h for Nano series,
note, TX2 and Xavier were using different header file, they’re tegra186-gpio.h and tegra194-gpio.h respectively.
btw,
when calculate the GPIO numbers, you should also check the kernel messages for the allocate ranges.
Nano series is allocate gpiochip0 from 0-255.
for example,
$ dmesg | grep "registered GPIOs"
[ 0.559180] gpiochip_setup_dev: registered GPIOs 0 to 255 on device: gpiochip0 (tegra-gpio)
[ 0.611064] gpiochip_setup_dev: registered GPIOs 504 to 511 on device: gpiochip1 (max77620-gpio)
therefore, you don’t need to add offset for your GPIO pins,
so, the number of TEGRA_GPIO(J, 7) is… ((9 * 8) + 7) + 0 = 79
for your reference,
here’s another case on Jetson AGX Xavier.
for example,
the gpiochip0 is allocated from 288-511; gpiochip1 from 248-287.
you’ll need to add the allocate offsets if you’re calculating the GPIO number on Xavier series.
$ dmesg | grep "registered GPIOs"
[ 0.891870] gpiochip_setup_dev: registered GPIOs 288 to 511 on device: gpiochip0 (tegra-gpio)
[ 0.900348] gpiochip_setup_dev: registered GPIOs 248 to 287 on device: gpiochip1 (tegra-gpio-aon)
[ 1.091072] gpiochip_setup_dev: registered GPIOs 240 to 247 on device: gpiochip2 (max77620-gpio)