mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Brandon Cheo Fusi <fusibrandon13@gmail.com>
To: Mark Brown <broonie@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Brandon Cheo Fusi <fusibrandon13@gmail.com>
Subject: [PATCH] regmap: add regmap_update_bits variant to autoshift mask
Date: Mon,  6 Nov 2023 17:34:06 +0100	[thread overview]
Message-ID: <20231106163406.33952-1-fusibrandon13@gmail.com> (raw)

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


             reply	other threads:[~2023-11-06 16:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-06 16:34 Brandon Cheo Fusi [this message]
2023-11-06 16:54 ` Mark Brown
     [not found]   ` <CAEVJM+q5TgYr01MhKe9AUzpt4fj8SAWiQNE7SkX5wVTFeaoAvA@mail.gmail.com>
2023-11-08 14:33     ` Fwd: " Brandon Cheo Fusi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231106163406.33952-1-fusibrandon13@gmail.com \
    --to=fusibrandon13@gmail.com \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®