drivers/gpio/gpio-pca953x.c is a driver for tca9539 and similar TI I2C I/O expander.
In the function pca953x_probe(),
- set up the list of the callback functions (direction_output() etc), and other properties, such as base, ngpio.
- register the gpio chip via gpiochip_add_data().
In the probe function of max9286 driver,
- read the device tree line “pwdn-gpios = <&tca9539 2 0> “
sensor->pwdn_gpio = devm_gpiod_get_optional(&client->dev, “pwdn”, GPIOD_IN);
- power on max9286: gpiod_direction_output(sensor->pwdn_gpio, 1);
Note:
driver/gpio/gpiolib.c is the core of GPIO implementation.
- A new GPIO chip registers itself via calling the function gpiochip_add_data();
- the gpio calls from users, such as gpiod_get(), gpiod_direction_output(), goes here first, then the chip-registered callback functions will be invoked.
- devm_gpiod_xx() functions are resource-managed version of gpiod_xx() functions.
For more details, refer to General Purpose Input/Output (GPIO) — The Linux Kernel documentation