From: Mark Brown <broonie@kernel.org>
To: linux-kernel@vger.kernel.org, Mark Brown <broonie@kernel.org>
Subject: [PATCH 1/2] regmap: Allow a base register to be specified for the RAM regmap
Date: Tue, 18 Aug 2026 22:50:44 +0100 [thread overview]
Message-ID: <20260818-regmap-kunit-cache-high-bit-v1-1-7e790676dea3@kernel.org> (raw)
In-Reply-To: <20260818-regmap-kunit-cache-high-bit-v1-0-7e790676dea3@kernel.org>
To allow testing of register maps with very large register values add
support for specifying base address to the RAM regmap. Since the config
struct is shared with the raw RAM regmap also update that, though we
will not use it.
Signed-off-by: Mark Brown <broonie@kernel.org>
---
drivers/base/regmap/internal.h | 1 +
drivers/base/regmap/regmap-ram.c | 26 ++++++++++++++++++++------
drivers/base/regmap/regmap-raw-ram.c | 21 +++++++++++++--------
3 files changed, 34 insertions(+), 14 deletions(-)
diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h
index 55273a6178f8..8176d91aacd1 100644
--- a/drivers/base/regmap/internal.h
+++ b/drivers/base/regmap/internal.h
@@ -322,6 +322,7 @@ static inline unsigned int regcache_get_index_by_order(const struct regmap *map,
}
struct regmap_ram_data {
+ unsigned int base_reg;
unsigned int *vals; /* Allocatd by caller */
bool *read;
bool *written;
diff --git a/drivers/base/regmap/regmap-ram.c b/drivers/base/regmap/regmap-ram.c
index c7356b0d8c83..a666bfb4d667 100644
--- a/drivers/base/regmap/regmap-ram.c
+++ b/drivers/base/regmap/regmap-ram.c
@@ -20,8 +20,11 @@ static int regmap_ram_write(void *context, unsigned int reg, unsigned int val)
{
struct regmap_ram_data *data = context;
- data->vals[reg] = val;
- data->written[reg] = true;
+ if (reg < data->base_reg)
+ return -EINVAL;
+
+ data->vals[reg - data->base_reg] = val;
+ data->written[reg - data->base_reg] = true;
return 0;
}
@@ -30,8 +33,11 @@ static int regmap_ram_read(void *context, unsigned int reg, unsigned int *val)
{
struct regmap_ram_data *data = context;
- *val = data->vals[reg];
- data->read[reg] = true;
+ if (reg < data->base_reg)
+ return -EINVAL;
+
+ *val = data->vals[reg - data->base_reg];
+ data->read[reg - data->base_reg] = true;
return 0;
}
@@ -60,17 +66,25 @@ struct regmap *__regmap_init_ram(struct device *dev,
const char *lock_name)
{
struct regmap *map;
+ unsigned int num_regs;
if (!config->max_register) {
pr_crit("No max_register specified for RAM regmap\n");
return ERR_PTR(-EINVAL);
}
- data->read = kzalloc_objs(bool, config->max_register + 1);
+ if (data->base_reg > config->max_register) {
+ pr_crit("base_reg above max_register for RAM regmap\n");
+ return ERR_PTR(-EINVAL);
+ }
+
+ num_regs = config->max_register - data->base_reg + 1;
+
+ data->read = kzalloc_objs(bool, num_regs);
if (!data->read)
return ERR_PTR(-ENOMEM);
- data->written = kzalloc_objs(bool, config->max_register + 1);
+ data->written = kzalloc_objs(bool, num_regs);
if (!data->written) {
kfree(data->read);
return ERR_PTR(-ENOMEM);
diff --git a/drivers/base/regmap/regmap-raw-ram.c b/drivers/base/regmap/regmap-raw-ram.c
index 60d6e95cdd1b..c63c464549f9 100644
--- a/drivers/base/regmap/regmap-raw-ram.c
+++ b/drivers/base/regmap/regmap-raw-ram.c
@@ -16,14 +16,17 @@
#include "internal.h"
-static unsigned int decode_reg(enum regmap_endian endian, const void *reg)
+static unsigned int decode_reg(struct regmap_ram_data *data, const void *reg)
{
const u16 *r = reg;
+ unsigned int decode;
- if (endian == REGMAP_ENDIAN_BIG)
- return be16_to_cpu(*r);
+ if (data->reg_endian == REGMAP_ENDIAN_BIG)
+ decode = be16_to_cpu(*r);
else
- return le16_to_cpu(*r);
+ decode = le16_to_cpu(*r);
+
+ return decode - data->base_reg;
}
static int regmap_raw_ram_gather_write(void *context,
@@ -40,7 +43,7 @@ static int regmap_raw_ram_gather_write(void *context,
if (val_len % 2)
return -EINVAL;
- r = decode_reg(data->reg_endian, reg);
+ r = decode_reg(data, reg);
if (data->noinc_reg && data->noinc_reg(data, r)) {
memcpy(&our_buf[r], val + val_len - 2, 2);
data->written[r] = true;
@@ -74,7 +77,7 @@ static int regmap_raw_ram_read(void *context,
if (val_len % 2)
return -EINVAL;
- r = decode_reg(data->reg_endian, reg);
+ r = decode_reg(data, reg);
if (data->noinc_reg && data->noinc_reg(data, r)) {
for (i = 0; i < val_len; i += 2)
memcpy(val + i, &our_buf[r], 2);
@@ -114,6 +117,7 @@ struct regmap *__regmap_init_raw_ram(struct device *dev,
const char *lock_name)
{
struct regmap *map;
+ unsigned int regs;
if (config->reg_bits != 16)
return ERR_PTR(-EINVAL);
@@ -123,11 +127,12 @@ struct regmap *__regmap_init_raw_ram(struct device *dev,
return ERR_PTR(-EINVAL);
}
- data->read = kzalloc_objs(bool, config->max_register + 1);
+ regs = config->max_register - data->base_reg + 1;
+ data->read = kzalloc_objs(bool, regs);
if (!data->read)
return ERR_PTR(-ENOMEM);
- data->written = kzalloc_objs(bool, config->max_register + 1);
+ data->written = kzalloc_objs(bool, regs);
if (!data->written)
return ERR_PTR(-ENOMEM);
--
2.47.3
next prev parent reply other threads:[~2026-08-18 21:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 21:50 [PATCH 0/2] regmap: Test caches for regmaps with high bits set in register numbers Mark Brown
2026-08-18 21:50 ` Mark Brown [this message]
2026-08-18 21:50 ` [PATCH 2/2] regmap: Test rbtree and maple caches for very high " Mark Brown
-- strict thread matches above, loose matches on Subject: below --
2026-08-16 22:13 [PATCH 0/2] regmap: Test caches for regmaps with high bits set in " Mark Brown
2026-08-16 22:13 ` [PATCH 1/2] regmap: Allow a base register to be specified for the RAM regmap Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260818-regmap-kunit-cache-high-bit-v1-1-7e790676dea3@kernel.org \
--to=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®