[PATCH] gpio: pca953x: restore output registers before direction on resume
From: Dean Sellers
Date: Wed Nov 18 2026 - 02:03:40 EST
pca953x_regcache_sync() restores the direction registers before the
output registers. If the chip lost power across suspend, it comes back
with every line an input and its output registers at their power-on
value, which is all-high on most of these parts. Restoring direction
first turns the configured lines back into outputs while the output
registers still hold that value. Every line programmed low is then
driven high for the duration of the direction write and the output write
that follows. Where those lines drive a load, there is potential for a
spurious output.
Restore output first, while the lines are still inputs, and direction
second. This matches device_pca95xx_init(), which already writes
output before direction when bringing the chip up at probe.
Fixes: b76574300504 ("gpio: pca953x: Restore registers after suspend/resume cycle")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Dean Sellers <dean@xxxxxxxxxxxxx>
---
Testing: developed and tested on a TCA6408 on a 5.15-based kernel; the
reorder was exercised through a configuration-restore path there, not
through suspend/resume itself. I no longer have that hardware, so this
version, rebased onto gpio/for-next, is compile-tested only (x86_64
allmodconfig, W=1).
The rebase onto mainline and the changelog were prepared with help from
Claude (Anthropic); the code change is my original work.
drivers/gpio/gpio-pca953x.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 3b2407690281..270cea8b4b49 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -1337,20 +1337,23 @@ static int pca953x_regcache_sync(struct pca953x_chip *chip)
u8 regaddr;
/*
- * The ordering between direction and output is important,
- * sync these registers first and only then sync the rest.
+ * The ordering between output and direction is important: restore
+ * the output levels while the lines are still inputs, and only then
+ * turn them into outputs. Restoring direction first would drive
+ * every output at the power-on output value until the output
+ * registers are written. Sync these first, then the rest.
*/
- regaddr = chip->recalc_addr(chip, chip->regs->direction, 0);
+ regaddr = chip->recalc_addr(chip, chip->regs->output, 0);
ret = regcache_sync_region(chip->regmap, regaddr, regaddr + NBANK(chip) - 1);
if (ret) {
- dev_err(dev, "Failed to sync GPIO dir registers: %d\n", ret);
+ dev_err(dev, "Failed to sync GPIO out registers: %d\n", ret);
return ret;
}
- regaddr = chip->recalc_addr(chip, chip->regs->output, 0);
+ regaddr = chip->recalc_addr(chip, chip->regs->direction, 0);
ret = regcache_sync_region(chip->regmap, regaddr, regaddr + NBANK(chip) - 1);
if (ret) {
- dev_err(dev, "Failed to sync GPIO out registers: %d\n", ret);
+ dev_err(dev, "Failed to sync GPIO dir registers: %d\n", ret);
return ret;
}
base-commit: 90000c03a9f6c74759f773a5078088db81514347
--
2.43.0