]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
pinctrl: mcp23s08: Reset all pins to input at probe
authorMike Looijmans <mike.looijmans@topic.nl>
Fri, 14 Mar 2025 15:17:45 +0000 (16:17 +0100)
committerLinus Walleij <linus.walleij@linaro.org>
Tue, 15 Apr 2025 07:17:39 +0000 (09:17 +0200)
At startup, the driver just assumes that all registers have their
default values. But after a soft reset, the chip will just be in the
state it was, and some pins may have been configured as outputs. Any
modification of the output register will cause these pins to be driven
low, which leads to unexpected/unwanted effects. To prevent this from
happening, set the chip's IO configuration register to a known safe
mode (all inputs) before toggling any other bits.

Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
Link: https://lore.kernel.org/20250314151803.28903-1-mike.looijmans@topic.nl
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/pinctrl/pinctrl-mcp23s08.c

index 4d1f41488017e499773819288ac890f2466d7fef..c2f4b16f42d20b0dfb0e1e6c79f8336392307c70 100644 (file)
@@ -636,6 +636,14 @@ int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
 
        mcp->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
 
+       /*
+        * Reset the chip - we don't really know what state it's in, so reset
+        * all pins to input first to prevent surprises.
+        */
+       ret = mcp_write(mcp, MCP_IODIR, mcp->chip.ngpio == 16 ? 0xFFFF : 0xFF);
+       if (ret < 0)
+               return ret;
+
        /* verify MCP_IOCON.SEQOP = 0, so sequential reads work,
         * and MCP_IOCON.HAEN = 1, so we work with all chips.
         */