Re: [PATCH v2] pinctrl: mcp23s08: delete regmap reg_defaults to avoid cache sync issues
From: Mike Looijmans
Date: Wed Oct 22 2025 - 10:45:59 EST
On 10/20/25 21:40, Sander Vanheule wrote:
Hi,
On Thu, 2025-10-09 at 16:26 +0300, bigunclemax@xxxxxxxxx wrote:
From: Maksim Kiselev <bigunclemax@xxxxxxxxx>As Andy mentioned, the problem you will now have to deal with is that your cache
The probe function does not guarantee that chip registers are in their
default state. Thus using reg_defaults for regmap is incorrect.
---
@@ -82,25 +71,12 @@ const struct regmap_config mcp23x08_regmap = {
.reg_stride = 1,
.volatile_table = &mcp23x08_volatile_table,
.precious_table = &mcp23x08_precious_table,
- .reg_defaults = mcp23x08_defaults,
- .num_reg_defaults = ARRAY_SIZE(mcp23x08_defaults),
.cache_type = REGCACHE_FLAT,
.max_register = MCP_OLAT,
.disable_locking = true, /* mcp->lock protects the regmap */
is not initialized at all. Unlike the other cache types, REGCACHE_FLAT will
zero-initialize its cache, perhaps making your cache sync issues worse.
Ouch...
I have access to hardware this week (boards with 2 and 3 of the I2C chips), I'll be able to do some hands-on testing, and report back.
You have two options to initialize the cache properly:
* Provide .num_reg_defaults_raw (= MCP_OLAT + 1). This will give you a warning
on probe about the cache defaults being initialized from hardware.
* Switch to another cache type (REGCACHE_MAPLE), which is aware of (in)valid
cache entries. regmap will then init the cache on the first access to a
register.
Using REGCACHE_MAPLE sounds like the obvious solution to me. That's what most other drivers use.
You could also combine the two, like the Cypress driver Andy referred to
(pinctrl-cy8c95x0.c). In that case you get cache loading at init, instead of at
first use, but without the risk of missing something.
--
Mike Looijmans