* [PATCH v1 0/4] regcache: Split out ->populate()
@ 2025-10-29 7:28 Andy Shevchenko
2025-10-29 7:28 ` [PATCH v1 1/4] regcache: Add ->populate() callback to separate from ->init() Andy Shevchenko
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Andy Shevchenko @ 2025-10-29 7:28 UTC (permalink / raw)
To: Christophe JAILLET, Andy Shevchenko, linux-kernel
Cc: Mark Brown, Greg Kroah-Hartman, Rafael J. Wysocki,
Danilo Krummrich
This is a refactoring series to decouple cache initialisation and population.
On its own it has no functional impact but will be used in the further
development. Besides that I found this split useful on its own (from the design
perspective). That's why I decided to send it out as is separately from a bigger
(and ongoing) work.
Andy Shevchenko (4):
regcache: Add ->populate() callback to separate from ->init()
regcache: rbtree: Split ->populate() from ->init()
regcache: flat: Split ->populate() from ->init()
regcache: maple: Split ->populate() from ->init()
drivers/base/regmap/internal.h | 1 +
drivers/base/regmap/regcache-flat.c | 28 +++++++++-------
drivers/base/regmap/regcache-maple.c | 47 ++++++++++++---------------
drivers/base/regmap/regcache-rbtree.c | 31 ++++++++++--------
drivers/base/regmap/regcache.c | 16 +++++++++
5 files changed, 71 insertions(+), 52 deletions(-)
--
2.50.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v1 1/4] regcache: Add ->populate() callback to separate from ->init()
2025-10-29 7:28 [PATCH v1 0/4] regcache: Split out ->populate() Andy Shevchenko
@ 2025-10-29 7:28 ` Andy Shevchenko
2025-10-29 7:28 ` [PATCH v1 2/4] regcache: rbtree: Split ->populate() " Andy Shevchenko
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2025-10-29 7:28 UTC (permalink / raw)
To: Christophe JAILLET, Andy Shevchenko, linux-kernel
Cc: Mark Brown, Greg Kroah-Hartman, Rafael J. Wysocki,
Danilo Krummrich
In the future changes we would like to change the flow of the cache handling.
Add ->populate() callback in order to prepare for that.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/base/regmap/internal.h | 1 +
drivers/base/regmap/regcache.c | 16 ++++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h
index 6f31240ee4a9..6efed02c21c5 100644
--- a/drivers/base/regmap/internal.h
+++ b/drivers/base/regmap/internal.h
@@ -186,6 +186,7 @@ struct regcache_ops {
enum regcache_type type;
int (*init)(struct regmap *map);
int (*exit)(struct regmap *map);
+ int (*populate)(struct regmap *map);
#ifdef CONFIG_DEBUG_FS
void (*debugfs_init)(struct regmap *map);
#endif
diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index c7650fa434ad..149945690cdf 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -221,8 +221,24 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
if (ret)
goto err_free;
}
+
+ if (map->num_reg_defaults && map->cache_ops->populate) {
+ dev_dbg(map->dev, "Populating %s cache\n", map->cache_ops->name);
+ map->lock(map->lock_arg);
+ ret = map->cache_ops->populate(map);
+ map->unlock(map->lock_arg);
+ if (ret)
+ goto err_exit;
+ }
return 0;
+err_exit:
+ if (map->cache_ops->exit) {
+ dev_dbg(map->dev, "Destroying %s cache\n", map->cache_ops->name);
+ map->lock(map->lock_arg);
+ ret = map->cache_ops->exit(map);
+ map->unlock(map->lock_arg);
+ }
err_free:
kfree(map->reg_defaults);
if (map->cache_free)
--
2.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v1 2/4] regcache: rbtree: Split ->populate() from ->init()
2025-10-29 7:28 [PATCH v1 0/4] regcache: Split out ->populate() Andy Shevchenko
2025-10-29 7:28 ` [PATCH v1 1/4] regcache: Add ->populate() callback to separate from ->init() Andy Shevchenko
@ 2025-10-29 7:28 ` Andy Shevchenko
2025-10-29 7:29 ` [PATCH v1 3/4] regcache: flat: " Andy Shevchenko
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2025-10-29 7:28 UTC (permalink / raw)
To: Christophe JAILLET, Andy Shevchenko, linux-kernel
Cc: Mark Brown, Greg Kroah-Hartman, Rafael J. Wysocki,
Danilo Krummrich
Split ->populate() implementation from ->init() code.
This decoupling will help for the further changes.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/base/regmap/regcache-rbtree.c | 31 +++++++++++++++------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/drivers/base/regmap/regcache-rbtree.c b/drivers/base/regmap/regcache-rbtree.c
index a9d17f316e55..2751714d52ea 100644
--- a/drivers/base/regmap/regcache-rbtree.c
+++ b/drivers/base/regmap/regcache-rbtree.c
@@ -184,8 +184,6 @@ static void rbtree_debugfs_init(struct regmap *map)
static int regcache_rbtree_init(struct regmap *map)
{
struct regcache_rbtree_ctx *rbtree_ctx;
- int i;
- int ret;
map->cache = kmalloc(sizeof *rbtree_ctx, map->alloc_flags);
if (!map->cache)
@@ -195,19 +193,7 @@ static int regcache_rbtree_init(struct regmap *map)
rbtree_ctx->root = RB_ROOT;
rbtree_ctx->cached_rbnode = NULL;
- for (i = 0; i < map->num_reg_defaults; i++) {
- ret = regcache_rbtree_write(map,
- map->reg_defaults[i].reg,
- map->reg_defaults[i].def);
- if (ret)
- goto err;
- }
-
return 0;
-
-err:
- regcache_rbtree_exit(map);
- return ret;
}
static int regcache_rbtree_exit(struct regmap *map)
@@ -239,6 +225,22 @@ static int regcache_rbtree_exit(struct regmap *map)
return 0;
}
+static int regcache_rbtree_populate(struct regmap *map)
+{
+ unsigned int i;
+ int ret;
+
+ for (i = 0; i < map->num_reg_defaults; i++) {
+ ret = regcache_rbtree_write(map,
+ map->reg_defaults[i].reg,
+ map->reg_defaults[i].def);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
static int regcache_rbtree_read(struct regmap *map,
unsigned int reg, unsigned int *value)
{
@@ -546,6 +548,7 @@ struct regcache_ops regcache_rbtree_ops = {
.name = "rbtree",
.init = regcache_rbtree_init,
.exit = regcache_rbtree_exit,
+ .populate= regcache_rbtree_populate,
#ifdef CONFIG_DEBUG_FS
.debugfs_init = rbtree_debugfs_init,
#endif
--
2.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v1 3/4] regcache: flat: Split ->populate() from ->init()
2025-10-29 7:28 [PATCH v1 0/4] regcache: Split out ->populate() Andy Shevchenko
2025-10-29 7:28 ` [PATCH v1 1/4] regcache: Add ->populate() callback to separate from ->init() Andy Shevchenko
2025-10-29 7:28 ` [PATCH v1 2/4] regcache: rbtree: Split ->populate() " Andy Shevchenko
@ 2025-10-29 7:29 ` Andy Shevchenko
2025-10-29 7:29 ` [PATCH v1 4/4] regcache: maple: " Andy Shevchenko
2025-10-30 11:36 ` [PATCH v1 0/4] regcache: Split out ->populate() Mark Brown
4 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2025-10-29 7:29 UTC (permalink / raw)
To: Christophe JAILLET, Andy Shevchenko, linux-kernel
Cc: Mark Brown, Greg Kroah-Hartman, Rafael J. Wysocki,
Danilo Krummrich
Split ->populate() implementation from ->init() code.
This decoupling will help for the further changes.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/base/regmap/regcache-flat.c | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/drivers/base/regmap/regcache-flat.c b/drivers/base/regmap/regcache-flat.c
index f36d3618b67c..adcfde75f2b3 100644
--- a/drivers/base/regmap/regcache-flat.c
+++ b/drivers/base/regmap/regcache-flat.c
@@ -20,9 +20,6 @@ static inline unsigned int regcache_flat_get_index(const struct regmap *map,
static int regcache_flat_init(struct regmap *map)
{
- int i;
- unsigned int *cache;
-
if (!map || map->reg_stride_order < 0 || !map->max_register_is_set)
return -EINVAL;
@@ -31,15 +28,6 @@ static int regcache_flat_init(struct regmap *map)
if (!map->cache)
return -ENOMEM;
- cache = map->cache;
-
- for (i = 0; i < map->num_reg_defaults; i++) {
- unsigned int reg = map->reg_defaults[i].reg;
- unsigned int index = regcache_flat_get_index(map, reg);
-
- cache[index] = map->reg_defaults[i].def;
- }
-
return 0;
}
@@ -51,6 +39,21 @@ static int regcache_flat_exit(struct regmap *map)
return 0;
}
+static int regcache_flat_populate(struct regmap *map)
+{
+ unsigned int *cache = map->cache;
+ unsigned int i;
+
+ for (i = 0; i < map->num_reg_defaults; i++) {
+ unsigned int reg = map->reg_defaults[i].reg;
+ unsigned int index = regcache_flat_get_index(map, reg);
+
+ cache[index] = map->reg_defaults[i].def;
+ }
+
+ return 0;
+}
+
static int regcache_flat_read(struct regmap *map,
unsigned int reg, unsigned int *value)
{
@@ -78,6 +81,7 @@ struct regcache_ops regcache_flat_ops = {
.name = "flat",
.init = regcache_flat_init,
.exit = regcache_flat_exit,
+ .populate = regcache_flat_populate,
.read = regcache_flat_read,
.write = regcache_flat_write,
};
--
2.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v1 4/4] regcache: maple: Split ->populate() from ->init()
2025-10-29 7:28 [PATCH v1 0/4] regcache: Split out ->populate() Andy Shevchenko
` (2 preceding siblings ...)
2025-10-29 7:29 ` [PATCH v1 3/4] regcache: flat: " Andy Shevchenko
@ 2025-10-29 7:29 ` Andy Shevchenko
2025-10-30 11:36 ` [PATCH v1 0/4] regcache: Split out ->populate() Mark Brown
4 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2025-10-29 7:29 UTC (permalink / raw)
To: Christophe JAILLET, Andy Shevchenko, linux-kernel
Cc: Mark Brown, Greg Kroah-Hartman, Rafael J. Wysocki,
Danilo Krummrich
Split ->populate() implementation from ->init() code.
This decoupling will help for the further changes.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/base/regmap/regcache-maple.c | 47 +++++++++++++---------------
1 file changed, 21 insertions(+), 26 deletions(-)
diff --git a/drivers/base/regmap/regcache-maple.c b/drivers/base/regmap/regcache-maple.c
index 2319c30283a6..ca1c72b68f31 100644
--- a/drivers/base/regmap/regcache-maple.c
+++ b/drivers/base/regmap/regcache-maple.c
@@ -289,6 +289,23 @@ static int regcache_maple_sync(struct regmap *map, unsigned int min,
return ret;
}
+static int regcache_maple_init(struct regmap *map)
+{
+ struct maple_tree *mt;
+
+ mt = kmalloc(sizeof(*mt), map->alloc_flags);
+ if (!mt)
+ return -ENOMEM;
+ map->cache = mt;
+
+ mt_init(mt);
+
+ if (!mt_external_lock(mt) && map->lock_key)
+ lockdep_set_class_and_subclass(&mt->ma_lock, map->lock_key, 1);
+
+ return 0;
+}
+
static int regcache_maple_exit(struct regmap *map)
{
struct maple_tree *mt = map->cache;
@@ -340,26 +357,12 @@ static int regcache_maple_insert_block(struct regmap *map, int first,
return ret;
}
-static int regcache_maple_init(struct regmap *map)
+static int regcache_maple_populate(struct regmap *map)
{
- struct maple_tree *mt;
int i;
int ret;
int range_start;
- mt = kmalloc(sizeof(*mt), map->alloc_flags);
- if (!mt)
- return -ENOMEM;
- map->cache = mt;
-
- mt_init(mt);
-
- if (!mt_external_lock(mt) && map->lock_key)
- lockdep_set_class_and_subclass(&mt->ma_lock, map->lock_key, 1);
-
- if (!map->num_reg_defaults)
- return 0;
-
range_start = 0;
/* Scan for ranges of contiguous registers */
@@ -369,23 +372,14 @@ static int regcache_maple_init(struct regmap *map)
ret = regcache_maple_insert_block(map, range_start,
i - 1);
if (ret != 0)
- goto err;
+ return ret;
range_start = i;
}
}
/* Add the last block */
- ret = regcache_maple_insert_block(map, range_start,
- map->num_reg_defaults - 1);
- if (ret != 0)
- goto err;
-
- return 0;
-
-err:
- regcache_maple_exit(map);
- return ret;
+ return regcache_maple_insert_block(map, range_start, map->num_reg_defaults - 1);
}
struct regcache_ops regcache_maple_ops = {
@@ -393,6 +387,7 @@ struct regcache_ops regcache_maple_ops = {
.name = "maple",
.init = regcache_maple_init,
.exit = regcache_maple_exit,
+ .populate = regcache_maple_populate,
.read = regcache_maple_read,
.write = regcache_maple_write,
.drop = regcache_maple_drop,
--
2.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v1 0/4] regcache: Split out ->populate()
2025-10-29 7:28 [PATCH v1 0/4] regcache: Split out ->populate() Andy Shevchenko
` (3 preceding siblings ...)
2025-10-29 7:29 ` [PATCH v1 4/4] regcache: maple: " Andy Shevchenko
@ 2025-10-30 11:36 ` Mark Brown
2025-10-30 11:43 ` Andy Shevchenko
4 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2025-10-30 11:36 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Christophe JAILLET, linux-kernel, Greg Kroah-Hartman,
Rafael J. Wysocki, Danilo Krummrich
[-- Attachment #1: Type: text/plain, Size: 463 bytes --]
On Wed, Oct 29, 2025 at 08:28:57AM +0100, Andy Shevchenko wrote:
> This is a refactoring series to decouple cache initialisation and population.
> On its own it has no functional impact but will be used in the further
> development. Besides that I found this split useful on its own (from the design
> perspective). That's why I decided to send it out as is separately from a bigger
> (and ongoing) work.
This looks fine but needs a rebase onto the latest code.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 0/4] regcache: Split out ->populate()
2025-10-30 11:36 ` [PATCH v1 0/4] regcache: Split out ->populate() Mark Brown
@ 2025-10-30 11:43 ` Andy Shevchenko
0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2025-10-30 11:43 UTC (permalink / raw)
To: Mark Brown
Cc: Christophe JAILLET, linux-kernel, Greg Kroah-Hartman,
Rafael J. Wysocki, Danilo Krummrich
On Thu, Oct 30, 2025 at 11:36:27AM +0000, Mark Brown wrote:
> On Wed, Oct 29, 2025 at 08:28:57AM +0100, Andy Shevchenko wrote:
> > This is a refactoring series to decouple cache initialisation and population.
> > On its own it has no functional impact but will be used in the further
> > development. Besides that I found this split useful on its own (from the design
> > perspective). That's why I decided to send it out as is separately from a bigger
> > (and ongoing) work.
>
> This looks fine but needs a rebase onto the latest code.
Will do, thanks!
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-10-30 11:43 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-29 7:28 [PATCH v1 0/4] regcache: Split out ->populate() Andy Shevchenko
2025-10-29 7:28 ` [PATCH v1 1/4] regcache: Add ->populate() callback to separate from ->init() Andy Shevchenko
2025-10-29 7:28 ` [PATCH v1 2/4] regcache: rbtree: Split ->populate() " Andy Shevchenko
2025-10-29 7:29 ` [PATCH v1 3/4] regcache: flat: " Andy Shevchenko
2025-10-29 7:29 ` [PATCH v1 4/4] regcache: maple: " Andy Shevchenko
2025-10-30 11:36 ` [PATCH v1 0/4] regcache: Split out ->populate() Mark Brown
2025-10-30 11:43 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox