Determining the gpio_base number

I am looking for some details on how the base gpio number is determined on Jetson TX2 system.

I am adding gpio expander connected to an I2C bus and made required changes to the device tree. The gpio_start is set to -1 in the driver and the GPIO subsystem is assigning gpio numbers automatically. In my case they are starting from 240-255. I would like to know how the number 240 is chosen.

i2c@31c0000 {
pca9555@20 {
compatible = “nxp,pca9555”;
reg = <0x20>;
#gpio-cells = <2>;
gpio-base = <0>; // at the moment driver is not using this as it is deprecated
ngpio = <16>;

I wanted to set gpio-base property in the device tree and use it in the driver to define the base but this property is deprecated.

Could you provide more details on how the base gpio number is calculated.

hello asiluvery,

it’s determine by the gpio driver,
you could refer to this function for more details.


int gpiochip_add_data(struct gpio_chip *chip, void *data){...}

Hi Jerry,

Thanks I understand now.
So on a given hardware configuration I should get a known gpio base.

Is this the preferred method or is it preferred to specify the desired base using device tree properties?


hello asiluvery,

may i know more details about why you need an known GPIO base?
there are GPIO allocations dynamically.
you can gather them from the kernel booting message.