* [PATCH] pinctrl-mcp23s08: Reset all pins to input at probe
[not found] <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.8cb9c8b1-3ce2-4a2a-93ba-a38ee66a1643@emailsignatures365.codetwo.com>
@ 2025-03-14 15:17 ` Mike Looijmans
2025-04-15 7:21 ` Linus Walleij
0 siblings, 1 reply; 2+ messages in thread
From: Mike Looijmans @ 2025-03-14 15:17 UTC (permalink / raw)
To: linux-gpio; +Cc: Mike Looijmans, Linus Walleij, linux-kernel
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>
---
drivers/pinctrl/pinctrl-mcp23s08.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/pinctrl/pinctrl-mcp23s08.c b/drivers/pinctrl/pinctrl-mcp23s08.c
index b96e6368a956..de2147cfe83f 100644
--- a/drivers/pinctrl/pinctrl-mcp23s08.c
+++ b/drivers/pinctrl/pinctrl-mcp23s08.c
@@ -619,6 +619,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.
*/
--
2.43.0
Met vriendelijke groet / kind regards,
Mike Looijmans
System Expert
TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands
T: +31 (0) 499 33 69 69
E: mike.looijmans@topic.nl
W: www.topic.nl
Please consider the environment before printing this e-mail
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] pinctrl-mcp23s08: Reset all pins to input at probe
2025-03-14 15:17 ` [PATCH] pinctrl-mcp23s08: Reset all pins to input at probe Mike Looijmans
@ 2025-04-15 7:21 ` Linus Walleij
0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2025-04-15 7:21 UTC (permalink / raw)
To: Mike Looijmans
Cc: linux-gpio, linux-kernel, Dmitry Mastykin, Evgenii Shatokhin,
Arturas Moskvinas, Andreas Kaessens, Radim Pavlik, Thomas Preston
On Fri, Mar 14, 2025 at 4:18 PM Mike Looijmans <mike.looijmans@topic.nl> wrote:
> 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>
Patch tentatively applied for v6.16.
CC to some mcp23s08 users so they can check it out.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-04-15 7:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.8cb9c8b1-3ce2-4a2a-93ba-a38ee66a1643@emailsignatures365.codetwo.com>
2025-03-14 15:17 ` [PATCH] pinctrl-mcp23s08: Reset all pins to input at probe Mike Looijmans
2025-04-15 7:21 ` Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).