* [RFC PATCH 1/2] regmap: Add cache_default_is_zero flag for flat cache
2026-01-06 14:08 [RFC PATCH 0/2] regmap: Add cache_default_is_zero flag for flat cache Sheetal .
@ 2026-01-06 14:08 ` Sheetal .
2026-01-06 15:12 ` Mark Brown
2026-01-06 21:19 ` Sander Vanheule
2026-01-06 14:08 ` [RFC PATCH 2/2] ASoC: tegra: Enable cache_default_is_zero for audio drivers Sheetal .
1 sibling, 2 replies; 8+ messages in thread
From: Sheetal . @ 2026-01-06 14:08 UTC (permalink / raw)
To: Mark Brown
Cc: Sander Vanheule, Greg Kroah-Hartman, Rafael J . Wysocki,
Danilo Krummrich, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
Thierry Reding, Jonathan Hunter, linux-kernel, linux-sound,
linux-tegra, Sheetal
From: Sheetal <sheetal@nvidia.com>
Commit e062bdfdd6ad ("regmap: warn users about uninitialized flat
cache") added a warning for drivers using REGCACHE_FLAT when reading
registers not present in reg_defaults.
For hardware where registers have a power-on-reset value of zero
or drivers that wish to treat zero as a valid cache default, adding
all such registers to reg_defaults has drawbacks:
1. Maintenance burden: Drivers must list every readable register
regardless of its reset value.
2. No functional benefit: Entries like { REG, 0x0 } only set the
validity bit; the cache value is already zero.
3. Code bloat: Large reg_defaults arrays increase driver size.
Add a cache_default_is_zero flag to struct regmap_config. When set,
the flat cache marks registers as valid on first read instead of
warning. This ensures only accessed registers are marked valid,
keeping sync scope minimal and avoiding writes to unused registers
or holes.
Signed-off-by: Sheetal <sheetal@nvidia.com>
---
drivers/base/regmap/internal.h | 2 ++
drivers/base/regmap/regcache-flat.c | 12 ++++++++----
drivers/base/regmap/regcache.c | 1 +
include/linux/regmap.h | 1 +
4 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h
index 1477329410ec..8e805046526a 100644
--- a/drivers/base/regmap/internal.h
+++ b/drivers/base/regmap/internal.h
@@ -157,6 +157,8 @@ struct regmap {
bool cache_dirty;
/* if set, the HW registers are known to match map->reg_defaults */
bool no_sync_defaults;
+ /* if set, zero is a valid default for registers not in reg_defaults */
+ bool cache_default_is_zero;
struct reg_sequence *patch;
int patch_regs;
diff --git a/drivers/base/regmap/regcache-flat.c b/drivers/base/regmap/regcache-flat.c
index 53cc59c84e2f..ea12e13e1365 100644
--- a/drivers/base/regmap/regcache-flat.c
+++ b/drivers/base/regmap/regcache-flat.c
@@ -88,10 +88,14 @@ static int regcache_flat_read(struct regmap *map,
struct regcache_flat_data *cache = map->cache;
unsigned int index = regcache_flat_get_index(map, reg);
- /* legacy behavior: ignore validity, but warn the user */
- if (unlikely(!test_bit(index, cache->valid)))
- dev_warn_once(map->dev,
- "using zero-initialized flat cache, this may cause unexpected behavior");
+ /* legacy behavior: ignore validity, but warn the user if zero is not a valid default */
+ if (unlikely(!test_bit(index, cache->valid))) {
+ if (map->cache_default_is_zero)
+ set_bit(index, cache->valid);
+ else
+ dev_warn_once(map->dev,
+ "using zero-initialized flat cache, this may cause unexpected behavior");
+ }
*value = cache->data[index];
diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index 319c342bf5a0..2d0e5c9ba51c 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -177,6 +177,7 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
map->reg_defaults_raw = config->reg_defaults_raw;
map->cache_word_size = BITS_TO_BYTES(config->val_bits);
map->cache_size_raw = map->cache_word_size * config->num_reg_defaults_raw;
+ map->cache_default_is_zero = config->cache_default_is_zero;
map->cache = NULL;
map->cache_ops = cache_types[i];
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index b0b9be750d93..bf918f88bfd3 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -452,6 +452,7 @@ struct regmap_config {
enum regcache_type cache_type;
const void *reg_defaults_raw;
unsigned int num_reg_defaults_raw;
+ bool cache_default_is_zero;
unsigned long read_flag_mask;
unsigned long write_flag_mask;
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [RFC PATCH 2/2] ASoC: tegra: Enable cache_default_is_zero for audio drivers
2026-01-06 14:08 [RFC PATCH 0/2] regmap: Add cache_default_is_zero flag for flat cache Sheetal .
2026-01-06 14:08 ` [RFC PATCH 1/2] " Sheetal .
@ 2026-01-06 14:08 ` Sheetal .
1 sibling, 0 replies; 8+ messages in thread
From: Sheetal . @ 2026-01-06 14:08 UTC (permalink / raw)
To: Mark Brown
Cc: Sander Vanheule, Greg Kroah-Hartman, Rafael J . Wysocki,
Danilo Krummrich, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
Thierry Reding, Jonathan Hunter, linux-kernel, linux-sound,
linux-tegra, Sheetal
From: Sheetal <sheetal@nvidia.com>
Set cache_default_is_zero flag in Tegra audio driver regmap configurations.
Tegra APE hardware has numerous registers with zero power-on-reset
values. Use cache_default_is_zero to mark cache entries as valid instead
of adding all these registers to reg_defaults arrays.
This patch depends on:
https://patchwork.ozlabs.org/project/linux-tegra/patch/20251217132524.2844499-1-sheetal@nvidia.com/
Signed-off-by: Sheetal <sheetal@nvidia.com>
---
sound/soc/tegra/tegra186_asrc.c | 1 +
sound/soc/tegra/tegra186_dspk.c | 1 +
sound/soc/tegra/tegra210_admaif.c | 3 +++
sound/soc/tegra/tegra210_adx.c | 2 ++
sound/soc/tegra/tegra210_ahub.c | 3 +++
sound/soc/tegra/tegra210_amx.c | 3 +++
sound/soc/tegra/tegra210_dmic.c | 1 +
sound/soc/tegra/tegra210_i2s.c | 2 ++
sound/soc/tegra/tegra210_mbdrc.c | 1 +
sound/soc/tegra/tegra210_mixer.c | 1 +
sound/soc/tegra/tegra210_mvc.c | 1 +
sound/soc/tegra/tegra210_ope.c | 1 +
sound/soc/tegra/tegra210_peq.c | 1 +
sound/soc/tegra/tegra210_sfc.c | 1 +
14 files changed, 22 insertions(+)
diff --git a/sound/soc/tegra/tegra186_asrc.c b/sound/soc/tegra/tegra186_asrc.c
index 2c0220e14a57..2f3382a674e7 100644
--- a/sound/soc/tegra/tegra186_asrc.c
+++ b/sound/soc/tegra/tegra186_asrc.c
@@ -951,6 +951,7 @@ static const struct regmap_config tegra186_asrc_regmap_config = {
.reg_defaults = tegra186_asrc_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(tegra186_asrc_reg_defaults),
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static const struct tegra_asrc_soc_data soc_data_tegra186 = {
diff --git a/sound/soc/tegra/tegra186_dspk.c b/sound/soc/tegra/tegra186_dspk.c
index a762150db802..84c54e710cff 100644
--- a/sound/soc/tegra/tegra186_dspk.c
+++ b/sound/soc/tegra/tegra186_dspk.c
@@ -468,6 +468,7 @@ static const struct regmap_config tegra186_dspk_regmap = {
.reg_defaults = tegra186_dspk_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(tegra186_dspk_reg_defaults),
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static const struct of_device_id tegra186_dspk_of_match[] = {
diff --git a/sound/soc/tegra/tegra210_admaif.c b/sound/soc/tegra/tegra210_admaif.c
index f9f6040c4e34..bb2f42560065 100644
--- a/sound/soc/tegra/tegra210_admaif.c
+++ b/sound/soc/tegra/tegra210_admaif.c
@@ -242,6 +242,7 @@ static const struct regmap_config tegra210_admaif_regmap_config = {
.reg_defaults = tegra210_admaif_reg_defaults,
.num_reg_defaults = TEGRA210_ADMAIF_CHANNEL_COUNT * 6 + 1,
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static const struct regmap_config tegra186_admaif_regmap_config = {
@@ -255,6 +256,7 @@ static const struct regmap_config tegra186_admaif_regmap_config = {
.reg_defaults = tegra186_admaif_reg_defaults,
.num_reg_defaults = TEGRA186_ADMAIF_CHANNEL_COUNT * 6 + 1,
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static const struct regmap_config tegra264_admaif_regmap_config = {
@@ -268,6 +270,7 @@ static const struct regmap_config tegra264_admaif_regmap_config = {
.reg_defaults = tegra264_admaif_reg_defaults,
.num_reg_defaults = TEGRA264_ADMAIF_CHANNEL_COUNT * 6 + 1,
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static int tegra_admaif_runtime_suspend(struct device *dev)
diff --git a/sound/soc/tegra/tegra210_adx.c b/sound/soc/tegra/tegra210_adx.c
index 6c9a410085bc..dd6261a0442c 100644
--- a/sound/soc/tegra/tegra210_adx.c
+++ b/sound/soc/tegra/tegra210_adx.c
@@ -626,6 +626,7 @@ static const struct regmap_config tegra210_adx_regmap_config = {
.reg_defaults = tegra210_adx_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(tegra210_adx_reg_defaults),
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static const struct regmap_config tegra264_adx_regmap_config = {
@@ -639,6 +640,7 @@ static const struct regmap_config tegra264_adx_regmap_config = {
.reg_defaults = tegra264_adx_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(tegra264_adx_reg_defaults),
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static const struct tegra210_adx_soc_data soc_data_tegra210 = {
diff --git a/sound/soc/tegra/tegra210_ahub.c b/sound/soc/tegra/tegra210_ahub.c
index e795907a3963..4cf21a9aca32 100644
--- a/sound/soc/tegra/tegra210_ahub.c
+++ b/sound/soc/tegra/tegra210_ahub.c
@@ -2078,6 +2078,7 @@ static const struct regmap_config tegra210_ahub_regmap_config = {
.reg_stride = 4,
.max_register = TEGRA210_MAX_REGISTER_ADDR,
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static const struct regmap_config tegra186_ahub_regmap_config = {
@@ -2086,6 +2087,7 @@ static const struct regmap_config tegra186_ahub_regmap_config = {
.reg_stride = 4,
.max_register = TEGRA186_MAX_REGISTER_ADDR,
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static const struct regmap_config tegra264_ahub_regmap_config = {
@@ -2095,6 +2097,7 @@ static const struct regmap_config tegra264_ahub_regmap_config = {
.writeable_reg = tegra264_ahub_wr_reg,
.max_register = TEGRA264_MAX_REGISTER_ADDR,
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static const struct tegra_ahub_soc_data soc_data_tegra210 = {
diff --git a/sound/soc/tegra/tegra210_amx.c b/sound/soc/tegra/tegra210_amx.c
index c94f8c84e04f..0a9402102ba1 100644
--- a/sound/soc/tegra/tegra210_amx.c
+++ b/sound/soc/tegra/tegra210_amx.c
@@ -655,6 +655,7 @@ static const struct regmap_config tegra210_amx_regmap_config = {
.reg_defaults = tegra210_amx_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(tegra210_amx_reg_defaults),
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static const struct regmap_config tegra194_amx_regmap_config = {
@@ -668,6 +669,7 @@ static const struct regmap_config tegra194_amx_regmap_config = {
.reg_defaults = tegra210_amx_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(tegra210_amx_reg_defaults),
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static const struct regmap_config tegra264_amx_regmap_config = {
@@ -681,6 +683,7 @@ static const struct regmap_config tegra264_amx_regmap_config = {
.reg_defaults = tegra264_amx_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(tegra264_amx_reg_defaults),
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static const struct tegra210_amx_soc_data soc_data_tegra210 = {
diff --git a/sound/soc/tegra/tegra210_dmic.c b/sound/soc/tegra/tegra210_dmic.c
index 66fff53aeaa6..d87f29ce1daa 100644
--- a/sound/soc/tegra/tegra210_dmic.c
+++ b/sound/soc/tegra/tegra210_dmic.c
@@ -484,6 +484,7 @@ static const struct regmap_config tegra210_dmic_regmap_config = {
.reg_defaults = tegra210_dmic_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(tegra210_dmic_reg_defaults),
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static int tegra210_dmic_probe(struct platform_device *pdev)
diff --git a/sound/soc/tegra/tegra210_i2s.c b/sound/soc/tegra/tegra210_i2s.c
index b91e0e6cd7fe..0dc853645905 100644
--- a/sound/soc/tegra/tegra210_i2s.c
+++ b/sound/soc/tegra/tegra210_i2s.c
@@ -998,6 +998,7 @@ static const struct regmap_config tegra210_regmap_conf = {
.reg_defaults = tegra210_i2s_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(tegra210_i2s_reg_defaults),
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
/*
@@ -1045,6 +1046,7 @@ static const struct regmap_config tegra264_regmap_conf = {
.reg_defaults = tegra264_i2s_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(tegra264_i2s_reg_defaults),
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static int tegra210_i2s_probe(struct platform_device *pdev)
diff --git a/sound/soc/tegra/tegra210_mbdrc.c b/sound/soc/tegra/tegra210_mbdrc.c
index 09fe3c5cf540..83906e484343 100644
--- a/sound/soc/tegra/tegra210_mbdrc.c
+++ b/sound/soc/tegra/tegra210_mbdrc.c
@@ -764,6 +764,7 @@ static const struct regmap_config tegra210_mbdrc_regmap_cfg = {
.reg_defaults = tegra210_mbdrc_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(tegra210_mbdrc_reg_defaults),
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
int tegra210_mbdrc_hw_params(struct snd_soc_component *cmpnt)
diff --git a/sound/soc/tegra/tegra210_mixer.c b/sound/soc/tegra/tegra210_mixer.c
index ff8e9f2d7abf..c8157388ad70 100644
--- a/sound/soc/tegra/tegra210_mixer.c
+++ b/sound/soc/tegra/tegra210_mixer.c
@@ -609,6 +609,7 @@ static const struct regmap_config tegra210_mixer_regmap_config = {
.reg_defaults = tegra210_mixer_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(tegra210_mixer_reg_defaults),
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static const struct of_device_id tegra210_mixer_of_match[] = {
diff --git a/sound/soc/tegra/tegra210_mvc.c b/sound/soc/tegra/tegra210_mvc.c
index 779d4c199da9..f3a5048dcf7a 100644
--- a/sound/soc/tegra/tegra210_mvc.c
+++ b/sound/soc/tegra/tegra210_mvc.c
@@ -700,6 +700,7 @@ static const struct regmap_config tegra210_mvc_regmap_config = {
.reg_defaults = tegra210_mvc_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(tegra210_mvc_reg_defaults),
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static const struct of_device_id tegra210_mvc_of_match[] = {
diff --git a/sound/soc/tegra/tegra210_ope.c b/sound/soc/tegra/tegra210_ope.c
index 27db70af2746..c7ac94f0a711 100644
--- a/sound/soc/tegra/tegra210_ope.c
+++ b/sound/soc/tegra/tegra210_ope.c
@@ -298,6 +298,7 @@ static const struct regmap_config tegra210_ope_regmap_config = {
.reg_defaults = tegra210_ope_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(tegra210_ope_reg_defaults),
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static int tegra210_ope_probe(struct platform_device *pdev)
diff --git a/sound/soc/tegra/tegra210_peq.c b/sound/soc/tegra/tegra210_peq.c
index 9a05e6913276..8d4821a4cc58 100644
--- a/sound/soc/tegra/tegra210_peq.c
+++ b/sound/soc/tegra/tegra210_peq.c
@@ -307,6 +307,7 @@ static const struct regmap_config tegra210_peq_regmap_config = {
.reg_defaults = tegra210_peq_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(tegra210_peq_reg_defaults),
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
void tegra210_peq_restore(struct regmap *regmap, u32 *biquad_gains,
diff --git a/sound/soc/tegra/tegra210_sfc.c b/sound/soc/tegra/tegra210_sfc.c
index d6341968bebe..89208820d451 100644
--- a/sound/soc/tegra/tegra210_sfc.c
+++ b/sound/soc/tegra/tegra210_sfc.c
@@ -3570,6 +3570,7 @@ static const struct regmap_config tegra210_sfc_regmap_config = {
.reg_defaults = tegra210_sfc_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(tegra210_sfc_reg_defaults),
.cache_type = REGCACHE_FLAT,
+ .cache_default_is_zero = true,
};
static const struct of_device_id tegra210_sfc_of_match[] = {
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread