GPIO expander pin number

Hi all,
I have connected a gpio expander[tca6408] on jetson NX at
i2c-1 i2c c240000.i2c I2C adapter
And I add a node in device tree as below

    i2c@c240000 {
		tca6408: tca6408@20 {
			compatible = "ti,tca6408";
			status = "okay";
			reg = <0x20>;

After NX boot up, I got below dmesg
gpiochip_setup_dev: registered GPIOs 232 to 239 on device: gpiochip3(tca6408)

My question is how to get the gpio pin number before NX boot up?
As I found in Doc that the gpio pin number is dynamically assigned.
Or is there any method to specify the pin number of the gpio expander?

hello YHuang0915,

you should check the pin via pinmux spreadsheets.
please refer to Xavier NX’s GPIO header file for the port numbers.
for example, $L4T_Sources/r32.5.1/Linux_for_Tegra/source/public/kernel/nvidia/include/dt-bindings/gpio/tegra194-gpio.h

for example,
I2S0_DOUT / GPIO3_PT.06, the port after ‘P’ is the GPIO port index, and also the offset numbers.
and, you’ll see the formula in the header file to calculate the GPIO number.

#define TEGRA194_MAIN_GPIO_PORT_T 19
#define TEGRA194_MAIN_GPIO(port, offset) \
        ((TEGRA194_MAIN_GPIO_PORT_##port * 8) + offset)

the GPIO3_PT.06 gpio number before kernel dynamically allocated is… ((19 * 8) + 6) = 158, that’s what you could control in the bootloader stage.

you’ll need to check the kernel allocation ranges. here shows kernel init messages for the GPIO allocation ranges,
since GPIO3_PT.06 is within gpiochip0, you’ll also add 288 mapping to its correct GPIO number after kernel boot-up.

$ dmesg | grep gpiochip_setup_dev
[    0.776867] gpiochip_setup_dev: registered GPIOs 288 to 511 on device: gpiochip0 (tegra-gpio)
[    0.786506] gpiochip_setup_dev: registered GPIOs 248 to 287 on device: gpiochip1 (tegra-gpio-aon)
[    0.973760] gpiochip_setup_dev: registered GPIOs 240 to 247 on device: gpiochip2 (max77620-gpio)

Hi Jerry,
Thanks for your reply.
I want to confirm that is there any method to assign a base number for a gpiochip?
For example, can I set gpiochip2(max77620-gpio) base num to 200, which means gpiochip2 will be registered
from 200 to 207.

hello YHuang0915,

I’ve never change this, may I know what’s the actual use-case doing so?

Hi Jerry,
In our design, we have used two tca6408 (8 pin gpio expander).

If we set tca6408 to built-in in kernel.
The first tca6408 mapped from 240 to 247 and the second tca6408 mapped from 232 to 239.
The max77620-gpio is mapped from 224 to 231.

If we set tca6408 as a module and insmod later,
The max77620-gpio is mapped from 240 to 247.
The first tca6408 mapped from 232 to 239 and the second tca6408 mapped from 224 to 231.

So I want to assgin a base pin number to tca6408, in this way the chip pin number will not changed no matter they built-in or later insmod.

Hi YHuang,
Base numbers are dynamically assigned starting from 511 and goes lower according to registration sequence from Kernel device tree. First device will get higher base address. You cannot manually set base address.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.