mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [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

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®