All of lore.kernel.org
 help / color / mirror / Atom feed
From: bigunclemax@gmail.com
Cc: bigunclemax@gmail.com, Linus Walleij <linus.walleij@linaro.org>,
	Mike Looijmans <mike.looijmans@topic.nl>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v1] pinctrl: mcp23s08: Reset all output latches to default at probe
Date: Mon,  6 Oct 2025 10:49:29 +0300	[thread overview]
Message-ID: <20251006074934.27180-1-bigunclemax@gmail.com> (raw)

From: "Maksim Kiselev" <bigunclemax@gmail.com>

It appears that resetting only the direction register is not sufficient,
it's also necessary to reset the OLAT register to its default values.

Otherwise, the following situation can occur:

If a pin was configured as OUT=1 before driver probe(Ex: IODIR=1,IOLAT=1),
then after loading the MCP driver, the cache will be populated from
reg_defaults with IOLAT=0 (while the actual value in the chip is 1).
A subsequent setting OUT=0 will fail because
mcp_update_bits(mcp, MCP_OLAT, ...) calls regmap_update_bits(),
which will check that the value to be set (0) matches the cached value (0)
and thus skip writing actual value to the MCP chip.

To avoid this, the OLAT register must be explicitly reset at probe.

Fixes: 3ede3f8b4b4b ("pinctrl: mcp23s08: Reset all pins to input at probe")
Signed-off-by: Maksim Kiselev <bigunclemax@gmail.com>
---
 drivers/pinctrl/pinctrl-mcp23s08.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/pinctrl/pinctrl-mcp23s08.c b/drivers/pinctrl/pinctrl-mcp23s08.c
index 78ff7930649d..23af441aa468 100644
--- a/drivers/pinctrl/pinctrl-mcp23s08.c
+++ b/drivers/pinctrl/pinctrl-mcp23s08.c
@@ -622,6 +622,11 @@ int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
 	if (ret < 0)
 		return ret;
 
+	/* Also reset all out latches to default values */
+	ret = mcp_write(mcp, MCP_OLAT, 0x0);
+	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.48.1


             reply	other threads:[~2025-10-06  7:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-06  7:49 bigunclemax [this message]
2025-10-06  8:04 ` [PATCH v1] pinctrl: mcp23s08: Reset all output latches to default at probe Mike Looijmans
2025-10-06 10:18   ` Maxim Kiselev
2025-10-06 12:18     ` Mike Looijmans

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251006074934.27180-1-bigunclemax@gmail.com \
    --to=bigunclemax@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mike.looijmans@topic.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.