GPIO Number
This document describes how to find the Linux GPIO number corresponding to Tegra GPIO ID.
Using GPIO Number
GPIO number is required to set GPIO to high/low through sysfs commands. For example:
$ echo 260 > /sys/class/gpio/export
$ echo out > /sys/class/gpio/gpio260/direction
$ cat /sys/class/gpio/gpio260/value
$ echo 1 > /sys/class/gpio/gpio260/value
$ echo 0 > /sys/class/gpio/gpio260/value
Getting GPIO Number
You can find the GPIO base number in kernel log. In the log shown below for board t186, tegra-gpio base is 320 and tegra-gpio-aon base is 256.
[ 0.969548] gpiochip_add_data: registered GPIOs 320 to 511 on device: tegra-gpio
[ 0.978782] gpiochip_add_data: registered GPIOs 256 to 319 on device: tegra-gpio-aon
[ 1.406190] gpiochip_add_data: registered GPIOs 248 to 255 on device: max20024-gpio
You can calculate the GPIO number as shown in the examples below:
• Calculate GPIO number of GPIO_PN4 on tegra-gpio for t186.
gpio-tegra186.c
static struct tegra_gpio_port_soc_info tegra186_gpio_cinfo[] = { // Offset
TEGRA_MAIN_GPIO_PORT_INFO(A, 2, 0, 7), // 0~7
TEGRA_MAIN_GPIO_PORT_INFO(B, 3, 0, 7), // 8~15
TEGRA_MAIN_GPIO_PORT_INFO(C, 3, 1, 7), //16~
TEGRA_MAIN_GPIO_PORT_INFO(D, 3, 2, 6), //24
TEGRA_MAIN_GPIO_PORT_INFO(E, 2, 1, 8), //32
TEGRA_MAIN_GPIO_PORT_INFO(F, 2, 2, 6), //40
TEGRA_MAIN_GPIO_PORT_INFO(G, 4, 1, 6), //48
TEGRA_MAIN_GPIO_PORT_INFO(H, 1, 0, 7), //56
TEGRA_MAIN_GPIO_PORT_INFO(I, 0, 4, 8), //64
TEGRA_MAIN_GPIO_PORT_INFO(J, 5, 0, 8), //72
TEGRA_MAIN_GPIO_PORT_INFO(K, 5, 1, 1), //80
TEGRA_MAIN_GPIO_PORT_INFO(L, 1, 1, 8), //88
TEGRA_MAIN_GPIO_PORT_INFO(M, 5, 3, 6), //96
TEGRA_MAIN_GPIO_PORT_INFO(N, 0, 0, 7), //104
TEGRA_MAIN_GPIO_PORT_INFO(O, 0, 1, 4), //112
TEGRA_MAIN_GPIO_PORT_INFO(P, 4, 0, 7), //120
TEGRA_MAIN_GPIO_PORT_INFO(Q, 0, 2, 6), //128
TEGRA_MAIN_GPIO_PORT_INFO(R, 0, 5, 6), //136
TEGRA_MAIN_GPIO_PORT_INFO(T, 0, 3, 4), //144
TEGRA_MAIN_GPIO_PORT_INFO(X, 1, 2, 8), //152
TEGRA_MAIN_GPIO_PORT_INFO(Y, 1, 3, 7), //160
TEGRA_MAIN_GPIO_PORT_INFO(BB, 2, 3, 2), //168
TEGRA_MAIN_GPIO_PORT_INFO(CC, 5, 2, 4), //176
TEGRA_MAIN_GPIO_PORT_INFO(DD, -1, -1, 0), //184
};
PN4 is 428 = 320(tegra-gpio base) + 104(PN0) + 4(offset)
• Calculate GPIO number of GPIO_PS4 on tegra-gpio-aon for t186.
gpio-tegra186.c
static struct tegra_gpio_port_soc_info tegra186_aon_gpio_cinfo[] = { // Offset
TEGRA_AON_GPIO_PORT_INFO(S, 0, 1, 5), // 0~7
TEGRA_AON_GPIO_PORT_INFO(U, 0, 2, 6), // 8~15
TEGRA_AON_GPIO_PORT_INFO(V, 0, 4, 8), //16
TEGRA_AON_GPIO_PORT_INFO(W, 0, 5, 8), //32
TEGRA_AON_GPIO_PORT_INFO(Z, 0, 7, 4), //40
TEGRA_AON_GPIO_PORT_INFO(AA, 0, 6, 8), //48
TEGRA_AON_GPIO_PORT_INFO(EE, 0, 3, 3), //56
TEGRA_AON_GPIO_PORT_INFO(FF, 0, 0, 5), //64
};
PS4 is 260 = 256(tegra-gpio-aon base) + 0(PS0) + 4(offset)
You can find the GPIO number for other boards in a similar way using the following steps:
• Check GPIO base number in kernel log.
• From GPIO file for the board, identify start number for the GPIO group.
• Add offset to the above two numbers.