Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: pcf857x: add support for reset-gpios on (most) PCA967x

The PCA9670, PCA9671, PCA9672 and PCA9673 all have a RESETN input pin
that is used to reset the I2C GPIO expander.

One needs to hold this pin low for at least 4us and the reset should be
finished after about 100us according to the datasheet[1]. Once the reset
is done, the "registers and I2C-bus state machine will be held in their
default state until the RESET input is once again HIGH.".

Because the logic is reset, the latch values eventually provided in the
Device Tree via lines-initial-states property are inapplicable so they
are simply ignored if a reset GPIO is provided.

[1] https://www.nxp.com/docs/en/data-sheet/PCA9670.pdf 8.5 and fig 22.

Tested-by: Heiko Stuebner <heiko@sntech.de> # RK3588 Tiger Haikou Video Demo
Reviewed-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Quentin Schulz <quentin.schulz@cherry.de>
Link: https://lore.kernel.org/r/20250224-pca976x-reset-driver-v3-2-58370ef405be@cherry.de
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

authored by

Quentin Schulz and committed by
Bartosz Golaszewski
087f8a6b b28037d4

+27 -2
+27 -2
drivers/gpio/gpio-pcf857x.c
··· 5 5 * Copyright (C) 2007 David Brownell 6 6 */ 7 7 8 + #include <linux/delay.h> 9 + #include <linux/gpio/consumer.h> 8 10 #include <linux/gpio/driver.h> 9 11 #include <linux/i2c.h> 10 12 #include <linux/interrupt.h> ··· 274 272 275 273 static int pcf857x_probe(struct i2c_client *client) 276 274 { 275 + struct gpio_desc *reset_gpio; 277 276 struct pcf857x *gpio; 278 277 unsigned int n_latch = 0; 279 278 int status; 280 - 281 - device_property_read_u32(&client->dev, "lines-initial-states", &n_latch); 282 279 283 280 /* Allocate, initialize, and register this gpio_chip. */ 284 281 gpio = devm_kzalloc(&client->dev, sizeof(*gpio), GFP_KERNEL); ··· 297 296 gpio->chip.direction_input = pcf857x_input; 298 297 gpio->chip.direction_output = pcf857x_output; 299 298 gpio->chip.ngpio = (uintptr_t)i2c_get_match_data(client); 299 + 300 + reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH); 301 + if (IS_ERR(reset_gpio)) 302 + return dev_err_probe(&client->dev, PTR_ERR(reset_gpio), 303 + "failed to get reset GPIO\n"); 304 + 305 + if (reset_gpio) { 306 + /* Reset already held with devm_gpiod_get_optional with GPIOD_OUT_HIGH */ 307 + fsleep(4); /* tw(rst) > 4us */ 308 + gpiod_set_value_cansleep(reset_gpio, 0); 309 + fsleep(100); /* trst > 100uS */ 310 + 311 + /* 312 + * Performing a reset means "The PCA9670 registers and I2C-bus 313 + * state machine will be held in their default state until the 314 + * RESET input is once again HIGH". 315 + * 316 + * This is the same as writing 1 for all pins, which is the same 317 + * as n_latch=0, the default value of the variable. 318 + */ 319 + } else { 320 + device_property_read_u32(&client->dev, "lines-initial-states", 321 + &n_latch); 322 + } 300 323 301 324 /* NOTE: the OnSemi jlc1562b is also largely compatible with 302 325 * these parts, notably for output. It has a low-resolution