[PATCH] mfd: max77759: Use REGCACHE_FLAT_S regmap caches

From: André Draszik

Date: Thu Nov 26 2026 - 05:30:34 EST


Reading /sys/kernel/debug/regmap/1-0066-charger/registers triggers a
regmap warning and prints fake zero values for unreadable register
addresses:

max77759 1-0066: using zero-initialized flat cache, this may cause
unexpected behavior

The top, maxq, and charger regmaps use REGCACHE_FLAT with
.num_reg_defaults_raw, so regcache_hw_init() populates only readable,
non-volatile registers and leaves unreadable register gaps (such as
0x00-0xaf in the charger regmap) invalid in the cache bitmap. When
debugfs checks regmap_printable() across the unreadable gaps,
regmap_cached() calls regcache_flat_read(), which warns on unset
validity bits yet still returns 0; _regmap_read() then serves the
uninitialized 0 from the cache before checking regmap_readable().

Switch all three regmap configs to REGCACHE_FLAT_S so regcache_read()
returns -ENOENT for unpopulated addresses, allowing debugfs to skip
unreadable gaps and stray reads to fail with -EIO. Also drop
.num_reg_defaults_raw so cacheable entries are populated from hardware
on demand instead of triggering eager probe-time I2C reads across all
registers (including the 33-byte AP_DATAOUT command buffer).

Fixes: bb71e40db1b7 ("mfd: max77759: Add Maxim MAX77759 core driver")
Signed-off-by: André Draszik <andre.draszik@xxxxxxxxxx>
---
drivers/mfd/max77759.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/max77759.c b/drivers/mfd/max77759.c
index 5818ee2811d1..9c6b85be8289 100644
--- a/drivers/mfd/max77759.c
+++ b/drivers/mfd/max77759.c
@@ -91,8 +91,7 @@ static const struct regmap_config max77759_regmap_config_top = {
.wr_table = &max77759_top_wr_table,
.rd_table = &max77759_top_rd_table,
.volatile_table = &max77759_top_volatile_table,
- .num_reg_defaults_raw = MAX77759_PMIC_REG_CONTROL_FG + 1,
- .cache_type = REGCACHE_FLAT,
+ .cache_type = REGCACHE_FLAT_S,
};

static const struct regmap_range max77759_maxq_registers[] = {
@@ -139,8 +138,7 @@ static const struct regmap_config max77759_regmap_config_maxq = {
.wr_table = &max77759_maxq_wr_table,
.rd_table = &max77759_maxq_rd_table,
.volatile_table = &max77759_maxq_volatile_table,
- .num_reg_defaults_raw = MAX77759_MAXQ_REG_UIC_SWRST + 1,
- .cache_type = REGCACHE_FLAT,
+ .cache_type = REGCACHE_FLAT_S,
};

static const struct regmap_range max77759_charger_registers[] = {
@@ -181,8 +179,7 @@ static const struct regmap_config max77759_regmap_config_charger = {
.wr_table = &max77759_charger_wr_table,
.rd_table = &max77759_charger_rd_table,
.volatile_table = &max77759_charger_volatile_table,
- .num_reg_defaults_raw = MAX77759_CHGR_REG_CHG_CNFG_19 + 1,
- .cache_type = REGCACHE_FLAT,
+ .cache_type = REGCACHE_FLAT_S,
};

/*

---
base-commit: 3191063649dbf7c0d0b768e1f3655e4c5fc6edb5
change-id: 20261125-max77759-regcache-flat-s-041524113b64

Best regards,
--
André Draszik <andre.draszik@xxxxxxxxxx>