regmap: add regmap_update_bits variant to autoshift mask
PATCH 1/1 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.
--- include/linux/regmap.h | 69 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+)
include/linux/regmap.h +69 -0
@@ -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) {
Signature · 1 line
2.30.2
Mark Brown
maintainerinclude/linux/regmap.h static inline int regmap_update_bits(struct regmap *map, unsigned int reg, · line 1246
Quoted 3 lines · Brandon Cheo Fusi
include/linux/regmap.h +3
-0+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.
A message that is not in the archive (sent off-list or not yet received): CAEVJM+q5TgYr01MhKe9AUzpt4fj8SAWiQNE7SkX5wVTFeaoAvA@mail.gmail.com
PATCH 1/1 regmap: add regmap_update_bits variant to autoshift mask
---------- Forwarded message ---------
From: Brandon Cheo Fusi <[email protected]>
Date: Wed, Nov 8, 2023 at 11:18 AM
Subject: Re: [PATCH] regmap: add regmap_update_bits variant to autoshift mask
To: Mark Brown <[email protected]>
Quoted 9 lines · Mark Brown
include/linux/regmap.h static inline int regmap_update_bits(struct regmap *map, unsigned int reg, · line 1246
Quoted 3 lines · Brandon Cheo Fusi
include/linux/regmap.h +3
-0+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.
Quoted 2 lines
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.