Skip to contentSkip to conversation

pinctrl: mcp23s08: Reset all output latches to default at probe

PATCH In review [email protected] 2 participants 4 messages Oct 6, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: mcp23s08: Reset all output latches to default at probe

From: "Maksim Kiselev" <[email protected]>

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")
---
 drivers/pinctrl/pinctrl-mcp23s08.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/pinctrl/pinctrl-mcp23s08.c +5 -0
index 78ff7930649d..23af441aa468 100644
@@ -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.
 	 */
Signature · 1 line
2.48.1
#1 lore raw
Quoted 7 lines · On 06-10-2025 09:49, [email protected] wrote:

From: "Maksim Kiselev" <[email protected]>

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:

Quoted 7 lines

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.

Maybe it's be better to fix the underlying issue: This driver should not be using a pre-populated regmap cache. Unless it performs a hard reset, the driver has no way of knowing what the initial values are, it should just read them from the chip.

Quoted 15 lines

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

Fixes 3ede3f8b4b4b ("pinctrl: mcp23s08: Reset all pins to input at probe")
---
  drivers/pinctrl/pinctrl-mcp23s08.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/pinctrl/pinctrl-mcp23s08.c +0 -0
index 78ff7930649d..23af441aa468 100644
@@ -622,6 +622,11 @@ int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
  	if (ret < 0)

drivers/pinctrl/pinctrl-mcp23s08.c int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, · line 632

Quoted 10 lines
drivers/pinctrl/pinctrl-mcp23s08.c +5 -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.
  	 */

Mike.

#2 lore raw

Hi

пн, 6 окт. 2025 г. в 11:04, Mike Looijmans <[email protected]>:

Quoted 17 lines · On 06-10-2025 09:49, [email protected] wrote:
Quoted 7 lines

From: "Maksim Kiselev" <[email protected]>

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:

Quoted 7 lines

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.

Quoted 5 lines

Maybe it's be better to fix the underlying issue: This driver should not be using a pre-populated regmap cache. Unless it performs a hard reset, the driver has no way of knowing what the initial values are, it should just read them from the chip.

I agree with you here, thought about it, but consider such a change too radical :)

Okay, I'll remove the reg_defaults in the second version.

Quoted 30 lines
Quoted 15 lines

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

Fixes 3ede3f8b4b4b ("pinctrl: mcp23s08: Reset all pins to input at probe")
---
  drivers/pinctrl/pinctrl-mcp23s08.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/pinctrl/pinctrl-mcp23s08.c +0 -0
index 78ff7930649d..23af441aa468 100644
@@ -622,6 +622,11 @@ int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
      if (ret < 0)

drivers/pinctrl/pinctrl-mcp23s08.c int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, · line 632

Quoted 10 lines
drivers/pinctrl/pinctrl-mcp23s08.c +5 -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.
       */

Mike.

#3 lore raw
Quoted 18 lines · Maxim Kiselev

Hi

пн, 6 окт. 2025 г. в 11:04, Mike Looijmans <[email protected]>:

Quoted 15 lines · On 06-10-2025 09:49, [email protected] wrote:
Quoted 14 lines

From: "Maksim Kiselev" <[email protected]>

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.

Quoted 7 lines
Quoted 5 lines

Maybe it's be better to fix the underlying issue: This driver should not be using a pre-populated regmap cache. Unless it performs a hard reset, the driver has no way of knowing what the initial values are, it should just read them from the chip.

I agree with you here, thought about it, but consider such a change too radical :)

Yeah, I had the same thought when I created the patch that resets the direction register :)

Quoted 1 line

Okay, I'll remove the reg_defaults in the second version.

I think it's the proper solution. You should remove the direction register reset as well (basically revert my patch).

M.

Quoted 29 lines
Quoted 29 lines
Quoted 15 lines

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

Fixes 3ede3f8b4b4b ("pinctrl: mcp23s08: Reset all pins to input at probe")
---
   drivers/pinctrl/pinctrl-mcp23s08.c | 5 +++++
   1 file changed, 5 insertions(+)
drivers/pinctrl/pinctrl-mcp23s08.c +0 -0
index 78ff7930649d..23af441aa468 100644
@@ -622,6 +622,11 @@ int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
       if (ret < 0)

drivers/pinctrl/pinctrl-mcp23s08.c int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, · line 632

Quoted 10 lines
drivers/pinctrl/pinctrl-mcp23s08.c +5 -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.
        */

Mike.