Skip to content

Commit c2bcf62

Browse files
andy-shevbroonie
authored andcommitted
regcache: Split regcache_count_cacheable_registers() helper
The introduced helper allows to check for the non-cacheable configurations earlier during initialisation. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://patch.msgid.link/20260210161058.53093-3-andriy.shevchenko@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 1fcf171 commit c2bcf62

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

drivers/base/regmap/regcache.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,10 @@ void regcache_sort_defaults(struct reg_default *defaults, unsigned int ndefaults
4242
}
4343
EXPORT_SYMBOL_GPL(regcache_sort_defaults);
4444

45-
static int regcache_hw_init(struct regmap *map)
45+
static int regcache_count_cacheable_registers(struct regmap *map)
4646
{
47-
int i, j;
48-
int ret;
4947
int count;
50-
unsigned int reg, val;
51-
void *tmp_buf;
48+
int i;
5249

5350
/* calculate the size of reg_defaults */
5451
for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++)
@@ -57,10 +54,18 @@ static int regcache_hw_init(struct regmap *map)
5754
count++;
5855

5956
/* all registers are unreadable or volatile, so just bypass */
60-
if (!count) {
57+
if (!count)
6158
map->cache_bypass = true;
62-
return 0;
63-
}
59+
60+
return count;
61+
}
62+
63+
static int regcache_hw_init(struct regmap *map, int count)
64+
{
65+
int i, j;
66+
int ret;
67+
unsigned int reg, val;
68+
void *tmp_buf;
6469

6570
map->num_reg_defaults = count;
6671
map->reg_defaults = kmalloc_objs(struct reg_default, count);
@@ -129,6 +134,7 @@ static int regcache_hw_init(struct regmap *map)
129134

130135
int regcache_init(struct regmap *map, const struct regmap_config *config)
131136
{
137+
int count = 0;
132138
int ret;
133139
int i;
134140
void *tmp_buf;
@@ -193,15 +199,17 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
193199
return -ENOMEM;
194200
map->reg_defaults = tmp_buf;
195201
} else if (map->num_reg_defaults_raw) {
202+
count = regcache_count_cacheable_registers(map);
203+
if (map->cache_bypass)
204+
return 0;
205+
196206
/* Some devices such as PMICs don't have cache defaults,
197207
* we cope with this by reading back the HW registers and
198208
* crafting the cache defaults by hand.
199209
*/
200-
ret = regcache_hw_init(map);
210+
ret = regcache_hw_init(map, count);
201211
if (ret < 0)
202212
return ret;
203-
if (map->cache_bypass)
204-
return 0;
205213
}
206214

207215
if (!map->max_register_is_set && map->num_reg_defaults_raw) {

0 commit comments

Comments
 (0)