* [PATCH] regmap: add regmap_update_bits variant to autoshift mask
@ 2023-11-06 16:34 Brandon Cheo Fusi
2023-11-06 16:54 ` Mark Brown
0 siblings, 1 reply; 3+ messages in thread
From: Brandon Cheo Fusi @ 2023-11-06 16:34 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-kernel, Brandon Cheo Fusi
This is both trivial and very handy in cases where the mask contains a single
contiguous group (GENMASK(hi, lo)), so users don't have to always adjust val.
Signed-off-by: Brandon Cheo Fusi <fusibrandon13@gmail.com>
---
include/linux/regmap.h | 69 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index c9182a477..373f00f30 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -1241,12 +1241,28 @@ static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
return regmap_update_bits_base(map, reg, mask, val, NULL, false, false);
}
+static inline int regmap_update_bits_autoshift_val(struct regmap *map, unsigned int reg,
+ unsigned int mask, unsigned int val)
+{
+ val <<= (ffs(mask) - 1);
+
+ return regmap_update_bits_base(map, reg, mask, val, NULL, false, false);
+}
+
static inline int regmap_update_bits_async(struct regmap *map, unsigned int reg,
unsigned int mask, unsigned int val)
{
return regmap_update_bits_base(map, reg, mask, val, NULL, true, false);
}
+static inline int regmap_update_bits_autoshift_val_async(struct regmap *map,
+ unsigned int reg, unsigned int mask, unsigned int val)
+{
+ val <<= (ffs(mask) - 1);
+
+ return regmap_update_bits_base(map, reg, mask, val, NULL, true, false);
+}
+
static inline int regmap_update_bits_check(struct regmap *map, unsigned int reg,
unsigned int mask, unsigned int val,
bool *change)
@@ -1255,6 +1271,16 @@ static inline int regmap_update_bits_check(struct regmap *map, unsigned int reg,
change, false, false);
}
+static inline int regmap_update_bits_autoshift_val_check(struct regmap *map,
+ unsigned int reg, unsigned int mask, unsigned int val,
+ bool *change)
+{
+ val <<= (ffs(mask) - 1);
+
+ return regmap_update_bits_base(map, reg, mask, val,
+ change, false, false);
+}
+
static inline int
regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
unsigned int mask, unsigned int val,
@@ -1264,6 +1290,17 @@ regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
change, true, false);
}
+static inline int
+regmap_update_bits_autoshift_val_check_async(struct regmap *map,
+ unsigned int reg, unsigned int mask, unsigned int val,
+ bool *change)
+{
+ val <<= (ffs(mask) - 1);
+
+ return regmap_update_bits_base(map, reg, mask, val,
+ change, true, false);
+}
+
static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
unsigned int mask, unsigned int val)
{
@@ -1808,6 +1845,13 @@ static inline int regmap_update_bits(struct regmap *map, unsigned int reg,
return -EINVAL;
}
+static inline int regmap_update_bits_autoshift_val(struct regmap *map,
+ unsigned int reg, unsigned int mask, unsigned int val)
+{
+ WARN_ONCE(1, "regmap API is disabled");
+ return -EINVAL;
+}
+
static inline int regmap_update_bits_async(struct regmap *map, unsigned int reg,
unsigned int mask, unsigned int val)
{
@@ -1815,6 +1859,14 @@ static inline int regmap_update_bits_async(struct regmap *map, unsigned int reg,
return -EINVAL;
}
+static inline int regmap_update_bits_autoshift_val_async(struct regmap *map,
+ unsigned int reg, unsigned int mask, unsigned int val)
+{
+ WARN_ONCE(1, "regmap API is disabled");
+ return -EINVAL;
+}
+
+
static inline int regmap_update_bits_check(struct regmap *map, unsigned int reg,
unsigned int mask, unsigned int val,
bool *change)
@@ -1823,6 +1875,14 @@ static inline int regmap_update_bits_check(struct regmap *map, unsigned int reg,
return -EINVAL;
}
+static inline int regmap_update_bits_autoshift_val_check(struct regmap *map,
+ unsigned int reg, unsigned int mask, unsigned int val,
+ bool *change)
+{
+ WARN_ONCE(1, "regmap API is disabled");
+ return -EINVAL;
+}
+
static inline int
regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
unsigned int mask, unsigned int val,
@@ -1832,6 +1892,15 @@ regmap_update_bits_check_async(struct regmap *map, unsigned int reg,
return -EINVAL;
}
+static inline int
+regmap_update_bits_autoshift_val_check_async(struct regmap *map,
+ unsigned int reg, unsigned int mask, unsigned int val,
+ bool *change)
+{
+ WARN_ONCE(1, "regmap API is disabled");
+ return -EINVAL;
+}
+
static inline int regmap_write_bits(struct regmap *map, unsigned int reg,
unsigned int mask, unsigned int val)
{
--
2.30.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] regmap: add regmap_update_bits variant to autoshift mask
2023-11-06 16:34 [PATCH] regmap: add regmap_update_bits variant to autoshift mask Brandon Cheo Fusi
@ 2023-11-06 16:54 ` Mark Brown
[not found] ` <CAEVJM+q5TgYr01MhKe9AUzpt4fj8SAWiQNE7SkX5wVTFeaoAvA@mail.gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2023-11-06 16:54 UTC (permalink / raw)
To: Brandon Cheo Fusi; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 402 bytes --]
On Mon, Nov 06, 2023 at 05:34:06PM +0100, Brandon Cheo Fusi wrote:
> +static inline int regmap_update_bits_autoshift_val(struct regmap *map, unsigned int reg,
> + unsigned int mask, unsigned int val)
> +{
Really not a fan of the name here, and in any case if the shifting of
the value is an issue wouldn't this be a good case for using a field?
Please also add kunit testcases for new APIs.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Fwd: [PATCH] regmap: add regmap_update_bits variant to autoshift mask
[not found] ` <CAEVJM+q5TgYr01MhKe9AUzpt4fj8SAWiQNE7SkX5wVTFeaoAvA@mail.gmail.com>
@ 2023-11-08 14:33 ` Brandon Cheo Fusi
0 siblings, 0 replies; 3+ messages in thread
From: Brandon Cheo Fusi @ 2023-11-08 14:33 UTC (permalink / raw)
To: linux-kernel
---------- Forwarded message ---------
From: Brandon Cheo Fusi <fusibrandon13@gmail.com>
Date: Wed, Nov 8, 2023 at 11:18 AM
Subject: Re: [PATCH] regmap: add regmap_update_bits variant to autoshift mask
To: Mark Brown <broonie@kernel.org>
On Mon, Nov 6, 2023 at 5:54 PM Mark Brown <broonie@kernel.org> wrote:
>
> On Mon, Nov 06, 2023 at 05:34:06PM +0100, Brandon Cheo Fusi wrote:
>
> > +static inline int regmap_update_bits_autoshift_val(struct regmap *map, unsigned int reg,
> > + unsigned int mask, unsigned int val)
> > +{
>
> Really not a fan of the name here, and in any case if the shifting of
> the value is an issue wouldn't this be a good case for using a field?
True. But all this does is handle the special and very common case of
'regmap_update_bits(regmap, reg, GENMASK(hi,lo), val)' where [hi,lo]
isn't at the bottom of reg. Most drivers don't resort to allocating
regmap_fields for each bit range they manipulate.
>
> Please also add kunit testcases for new APIs.
I'd be happy to send a v2 with kunit testcases, if you think the API is
worthwhile.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-11-08 14:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-06 16:34 [PATCH] regmap: add regmap_update_bits variant to autoshift mask Brandon Cheo Fusi
2023-11-06 16:54 ` Mark Brown
[not found] ` <CAEVJM+q5TgYr01MhKe9AUzpt4fj8SAWiQNE7SkX5wVTFeaoAvA@mail.gmail.com>
2023-11-08 14:33 ` Fwd: " Brandon Cheo Fusi
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®