2023-11-06 16:34:28

by Brandon Cheo Fusi

[permalink] [raw]
Subject: [PATCH] regmap: add regmap_update_bits variant to autoshift mask

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 <[email protected]>
---
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


2023-11-06 16:56:07

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] regmap: add regmap_update_bits variant to autoshift mask

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.


Attachments:
(No filename) (412.00 B)
signature.asc (499.00 B)
Download all attachments