Messages in this thread Patch in this message | | | From | Brandon Cheo Fusi <> | Subject | [PATCH] regmap: add regmap_update_bits variant to autoshift mask | Date | Mon, 6 Nov 2023 17:34:06 +0100 |
| |
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
| |