* [RFC PATCH 0/2] regmap: Add cache_default_is_zero flag for flat cache
@ 2026-01-06 14:08 Sheetal .
2026-01-06 14:08 ` [RFC PATCH 1/2] " Sheetal .
2026-01-06 14:08 ` [RFC PATCH 2/2] ASoC: tegra: Enable cache_default_is_zero for audio drivers Sheetal .
0 siblings, 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>
This patch series adds a cache_default_is_zero flag for REGCACHE_FLAT that
marks cache entries as valid on first read.
For hardware with zero power-on-reset registers, this avoids the need
to add all such registers to reg_defaults (maintenance burden, code
bloat, no functional benefit) just to set the validity bits.
Sheetal (2):
regmap: Add cache_default_is_zero flag for flat cache
ASoC: tegra: Enable cache_default_is_zero for audio drivers
drivers/base/regmap/internal.h | 2 ++
drivers/base/regmap/regcache-flat.c | 11 +++++++----
drivers/base/regmap/regcache.c | 1 +
include/linux/regmap.h | 3 +++
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 +
18 files changed, 35 insertions(+), 4 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [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
* Re: [RFC PATCH 1/2] regmap: Add cache_default_is_zero flag for flat cache
2026-01-06 14:08 ` [RFC PATCH 1/2] " Sheetal .
@ 2026-01-06 15:12 ` Mark Brown
2026-01-07 6:55 ` Sheetal .
2026-01-06 21:19 ` Sander Vanheule
1 sibling, 1 reply; 8+ messages in thread
From: Mark Brown @ 2026-01-06 15:12 UTC (permalink / raw)
To: Sheetal .
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
[-- Attachment #1: Type: text/plain, Size: 990 bytes --]
On Tue, Jan 06, 2026 at 07:38:26PM +0530, Sheetal . wrote:
> 2. No functional benefit: Entries like { REG, 0x0 } only set the
> validity bit; the cache value is already zero.
For sparse caches specifying the register also allocates the cache
entry.
> 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,
Why do this on first read rather than than just fill the valid flags
during initialisation?
> 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;
It would be better if this were something specific to the flat cache
since otherwise we have to consider what this means for the other cache
types.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFC PATCH 1/2] regmap: Add cache_default_is_zero flag for flat cache
2026-01-06 14:08 ` [RFC PATCH 1/2] " Sheetal .
2026-01-06 15:12 ` Mark Brown
@ 2026-01-06 21:19 ` Sander Vanheule
2026-01-07 7:30 ` Sheetal .
1 sibling, 1 reply; 8+ messages in thread
From: Sander Vanheule @ 2026-01-06 21:19 UTC (permalink / raw)
To: Sheetal ., Mark Brown
Cc: Greg Kroah-Hartman, Rafael J . Wysocki, Danilo Krummrich,
Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Thierry Reding,
Jonathan Hunter, linux-kernel, linux-sound, linux-tegra
Hi Sheetal,
On Tue, 2026-01-06 at 19:38 +0530, Sheetal . wrote:
> 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.
This is only true because REGCACHE_FLAT just so happens to zero-initialize its
cache, which IMHO should be considered an implementation detail. If you were to
switch to another cache type, you would also need these defaults to maintain the
current behavior.
> 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.
A special flag only used in the flat cache is exactly the type of config I think
is non-intuitive and should be avoided. It needs an explanation, which implies
documentation that may go out of sync.
If your device has a single contiguous register space that you want to
initialize to zero, all you really need to provide is something like the ranges
used for readable/writable/... registers:
(struct regcache_defaults_range) {
.range_min = REG_MIN,
.range_max = REG_MAX,
.value = 0,
}
Instead of a bool, you could add a pointer to a defaults table in the config
(which can be loaded together with the current flat list), just like how
rd_table works.
This would allow others to use the same table for multiple contiguous block,
with zero or non-zero default values. It would work the same for all cache
types, thus avoiding potential confusion, and limit the size increase of your
drivers. Then you could even safely switch to REGCACHE_FLAT_S.
Best,
Sander
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFC PATCH 1/2] regmap: Add cache_default_is_zero flag for flat cache
2026-01-06 15:12 ` Mark Brown
@ 2026-01-07 6:55 ` Sheetal .
2026-01-07 11:20 ` Mark Brown
0 siblings, 1 reply; 8+ messages in thread
From: Sheetal . @ 2026-01-07 6:55 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
On 06-01-2026 20:42, Mark Brown wrote:
> On Tue, Jan 06, 2026 at 07:38:26PM +0530, Sheetal . wrote:
>
>> 2. No functional benefit: Entries like { REG, 0x0 } only set the
>> validity bit; the cache value is already zero.
>
> For sparse caches specifying the register also allocates the cache
> entry.
ACK
>
>> 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,
>
> Why do this on first read rather than than just fill the valid flags
> during initialisation?
>
Setting valid bits on first read rather than bitmap_fill() at init ensures:
- Only accessed registers are marked valid
- regcache_sync() only syncs registers that were actually used
- Avoids writes to holes or unused registers during sync
- Safer for drivers without writeable_reg callback
>> 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;
>
> It would be better if this were something specific to the flat cache
> since otherwise we have to consider what this means for the other cache
> types.
I can address this by rename to flat_cache_default_is_zero.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFC PATCH 1/2] regmap: Add cache_default_is_zero flag for flat cache
2026-01-06 21:19 ` Sander Vanheule
@ 2026-01-07 7:30 ` Sheetal .
0 siblings, 0 replies; 8+ messages in thread
From: Sheetal . @ 2026-01-07 7:30 UTC (permalink / raw)
To: Sander Vanheule, Mark Brown
Cc: Greg Kroah-Hartman, Rafael J . Wysocki, Danilo Krummrich,
Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Thierry Reding,
Jonathan Hunter, linux-kernel, linux-sound, linux-tegra
On 07-01-2026 02:49, Sander Vanheule wrote:
> External email: Use caution opening links or attachments
>
>
> Hi Sheetal,
>
> On Tue, 2026-01-06 at 19:38 +0530, Sheetal . wrote:
>> 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.
>
> This is only true because REGCACHE_FLAT just so happens to zero-initialize its
> cache, which IMHO should be considered an implementation detail. If you were to
> switch to another cache type, you would also need these defaults to maintain the
> current behavior.
The warning itself only exists in REGCACHE_FLAT not in other cache
types. So this fix addresses a REGCACHE_FLAT specific warning with a
REGCACHE_FLAT-specific flag.
I feel that perhaps we could avoid warning the user when they have
explicitly indicated that zero is a valid default for their hardware.
Since the driver author understands their device requirements, this
flag would allow them to opt out of the warning for cases where it
may not be helpful.
>
>> 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.
>
> A special flag only used in the flat cache is exactly the type of config I think
> is non-intuitive and should be avoided. It needs an explanation, which implies
> documentation that may go out of sync.
>
> If your device has a single contiguous register space that you want to
> initialize to zero, all you really need to provide is something like the ranges
> used for readable/writable/... registers:
>
> (struct regcache_defaults_range) {
> .range_min = REG_MIN,
> .range_max = REG_MAX,
> .value = 0,
> }
>
> Instead of a bool, you could add a pointer to a defaults table in the config
> (which can be loaded together with the current flat list), just like how
> rd_table works.
>
> This would allow others to use the same table for multiple contiguous block,
> with zero or non-zero default values. It would work the same for all cache
> types, thus avoiding potential confusion, and limit the size increase of your
> drivers. Then you could even safely switch to REGCACHE_FLAT_S.
>
The range-based approach is a good idea for contiguous register
blocks. However, if registers with zero defaults are not contiguous
(scattered across the address space), it would need multiple range
entries or multiple reg default entries.
> Best,
> Sander
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFC PATCH 1/2] regmap: Add cache_default_is_zero flag for flat cache
2026-01-07 6:55 ` Sheetal .
@ 2026-01-07 11:20 ` Mark Brown
0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2026-01-07 11:20 UTC (permalink / raw)
To: Sheetal .
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
[-- Attachment #1: Type: text/plain, Size: 673 bytes --]
On Wed, Jan 07, 2026 at 12:25:01PM +0530, Sheetal . wrote:
> On 06-01-2026 20:42, Mark Brown wrote:
> > Why do this on first read rather than than just fill the valid flags
> > during initialisation?
> Setting valid bits on first read rather than bitmap_fill() at init ensures:
> - Only accessed registers are marked valid
> - regcache_sync() only syncs registers that were actually used
> - Avoids writes to holes or unused registers during sync
> - Safer for drivers without writeable_reg callback
Seems reasonable, put that in the changelog please.
BTW I forgot in my initial review but please add KUnit coverage for
this, we've got good coverage of the cache code.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-01-07 11:20 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 15:12 ` Mark Brown
2026-01-07 6:55 ` Sheetal .
2026-01-07 11:20 ` Mark Brown
2026-01-06 21:19 ` Sander Vanheule
2026-01-07 7:30 ` Sheetal .
2026-01-06 14:08 ` [RFC PATCH 2/2] ASoC: tegra: Enable cache_default_is_zero for audio drivers Sheetal .
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox