TX2 GPIO Number macros in tegra186-gpio.h

I was trying to figure out how to manipulate the GPIOs, and I came across the following in the Bring-up Guide:

The author seems to be saying that he offset is 320 i.e. the macro would be called like TEGRA_MAIN_GPIO(BB,320), but other posts on the forum seem to suggest that the offset is actually the port channel i.e. the macro would be called like TEGRA_MAIN_GPIO(BB,00) and we add 320 to it…somewhere.

What is the proper way to use these macros?

Answering my own question.
There’s a newer version of the guide here:
where the example is revised:

GPIO Changes

If you designed your own carrier board, to translate from SOM-connector pins to actual GPIO numbers you must understand GPIO mapping formula below. The translated GPIO numbers can be controlled by the driver.

For example, to check the GPIO number of GPIO15/AP2MDM_READY. perform the following steps.

To check the GPIO number

1.Search for GPIO15_AP2MDM_READY in Jetson_TX2_Generic_Customer_Pinmux_Release.xlsx.

2.Confirm that the Customer Usage field is applied to GPIO3_PBB.00.

3.Refer to tegra186-gpio.h to determine the GPIO group that the GPIO belongs to and the index of the GPIO in the group. For example, GPIO3_PBB.00 belongs to the main Jetson GPIO group, and its port number is 21:


4.Because the SoC device registers GPIOs dynamically, you must search kernel messages to find the base index of each GPIO group. The command and resulting output are similar to:

$ sudo grep tegra-gpio /sys/kernel/debug/gpio

gpiochip1: GPIOs 256-319, parent: platform/c2f0000.gpio, tegra-gpio-aon:

gpiochip0: GPIOs 320-511, parent: platform/2200000.gpio, tegra-gpio:

In this example the output shows that the GPIO groups and their base indices are:

•tegra-gpio, at base index 320

•tegra-gpio-aon, at base index 256

5.Because PBB00 belongs to the tegra-gpio group, its base index is 320. Use the following formula to calculate the GPIO number:

TEGRA_MAIN_GPIO(port, base) = (base + (8 * port) + pin)

Hence, the GPIO number of GPIO15/AP2MDM_READY is 320+(8*21)+0 = 488