GPIO Indexing in Linux (T256)#

The following section describes how to calculate the GPIO index on T256 (N1 Auto).

T256 GPIO Layout#

On T256, GPIOs are under the LSIO (Low Speed I/O) main controller. There is one GPIO controller (tegra256-gpio-main) with four banks: A, B, C, and D. Each bank has 8 pins (32 GPIOs total): PA.00–PA.07, PB.00–PB.07, PC.00–PC.07, PD.00–PD.07.

GPIO is represented as X.Y, where:

* X is the bank letter: A, B, C, or D.
* Y is the pin within the bank: 0 to 7 (e.g., 0 for pin 0, 5 for pin 5).

The banks are associated to a base and can also be sequentially translated into a bank_index as shown in the table below:

T256 GPIO bank index#

Bank

bank_index

GPIO pins

A

0

PA.00–PA.07 (0–7)

B

1

PB.00–PB.07 (8–15)

C

2

PC.00–PC.07 (16–23)

D

3

PD.00–PD.07 (24–31)

Finding the Base#

The base numbering may change in cases where customization is done in the kernel and can be identified using the dmesg log or debugfs.

At boot, dmesg may show:

nvidia@tegra-ubuntu:~$ dmesg | grep gpiochip
[  9.xxxxxx] gpiochip0: registered GPIOs 2016 to 2047 on tegra256-gpio-main

Alternatively, read the current base from debugfs:

root@(none):/sys/kernel/debug# cat gpio
gpiochip0: GPIOs 2016-2047, parent: platform/36500000.gpio, tegra256-gpio-main:
 gpio-2016 (PA.00               )
 gpio-2017 (PA.01               )
 ...
 gpio-2040 (PD.00               )
 ...
 gpio-2047 (PD.07               )

In this layout, the base is 2016. GPIOs 2016–2047 map to PA.00 through PD.07. The base may differ on your system depending on kernel configuration and device tree order; use the range shown by cat /sys/kernel/debug/gpio.

Formula#

GPIO_index = base + (bank_index × 8) + pin

Where:

  • base = first GPIO number of the controller (from dmesg or /sys/kernel/debug/gpio).

  • bank_index = 0 for A, 1 for B, 2 for C, 3 for D.

  • pin = 0–7 within the bank.

Example: GPIO PC.02 (C.2)#

1. PC.02 is bank C and pin 2.
2. Bank C has bank_index 2. Base is 2016 (from /sys/kernel/debug/gpio).
3. GPIO index = 2016 + (2 × 8) + 2 = 2016 + 16 + 2 = **2034**.

So PC.02 appears as gpio-2034 in the kernel.

Example: GPIO PD.00 (D.0)#

1. PD.00 is bank D and pin 0.
2. Bank D has bank_index 3. Base is 2016.
3. GPIO index = 2016 + (3 × 8) + 0 = 2016 + 24 + 0 = **2040**.

So PD.00 appears as gpio-2040 in the kernel.

The DT macro TEGRA256_MAIN_GPIO(port, offset) in dt-bindings/gpio/tegra256-gpio.h gives the pin number within the controller (0–31). The Linux GPIO index is that value plus the controller base reported by the kernel.