All of lore.kernel.org
 help / color / mirror / Atom feed
From: Li Chen <lchen.firstlove@zohomail.com>
To: "Mark Brown" <broonie@kernel.org>,
	"linux-kernel" <linux-kernel@vger.kernel.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"linux-gpio" <linux-gpio@vger.kernel.org>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"linux-arm-kernel" <linux-arm-kernel@lists.infradead.org>,
	"Patrice Chotard" <patrice.chotard@foss.st.com>,
	"linux-sunxi" <linux-sunxi@lists.linux.dev>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>, "Chen-Yu Tsai" <wens@csie.org>,
	"Jernej Skrabec" <jernej.skrabec@gmail.com>,
	"Samuel Holland" <samuel@sholland.org>,
	"Philipp Zabel" <p.zabel@pengutronix.de>
Subject: [PATCH v3 1/4] regmap: provide regmap_field helpers for simple bit operations
Date: Sun, 22 May 2022 20:26:58 -0700	[thread overview]
Message-ID: <180eef422c3.deae9cd960729.8518395646822099769@zohomail.com> (raw)
In-Reply-To: <180eef39205.122d47c8260721.2430302798386025245@zohomail.com>

From: Li Chen <lchen@ambarella.com>

We have set/clear/test operations for regmap, but not for regmap_field yet.
So let's introduce regmap_field helpers too.

In many instances regmap_field_update_bits() is used for simple bit setting
and clearing. In these cases the last argument is redundant and we can
hide it with a static inline function.

This adds three new helpers for simple bit operations: set_bits,
clear_bits and test_bits (the last one defined as a regular function).

Signed-off-by: Li Chen <lchen@ambarella.com>
---
 drivers/base/regmap/regmap.c | 22 +++++++++++++++++++++
 include/linux/regmap.h       | 37 ++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 5e12f7cb5147..a37d6041b7bd 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -2208,6 +2208,28 @@ int regmap_field_update_bits_base(struct regmap_field *field,
 }
 EXPORT_SYMBOL_GPL(regmap_field_update_bits_base);
 
+/**
+ * regmap_field_test_bits() - Check if all specified bits are set in a
+ *                            register field.
+ *
+ * @field: Register field to operate on
+ * @bits: Bits to test
+ *
+ * Returns -1 if the underlying regmap_field_read() fails, 0 if at least one of the
+ * tested bits is not set and 1 if all tested bits are set.
+ */
+int regmap_field_test_bits(struct regmap_field *field, unsigned int bits)
+{
+	unsigned int val, ret;
+
+	ret = regmap_field_read(field, &val);
+	if (ret)
+		return ret;
+
+	return (val & bits) == bits;
+}
+EXPORT_SYMBOL_GPL(regmap_field_test_bits);
+
 /**
  * regmap_fields_update_bits_base() - Perform a read/modify/write cycle a
  *                                    register field with port ID
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index de81a94d7b30..5f317403c520 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -1324,6 +1324,22 @@ static inline int regmap_field_update_bits(struct regmap_field *field,
 					     NULL, false, false);
 }
 
+static inline int regmap_field_set_bits(struct regmap_field *field,
+					unsigned int bits)
+{
+	return regmap_field_update_bits_base(field, bits, bits, NULL, false,
+					     false);
+}
+
+static inline int regmap_field_clear_bits(struct regmap_field *field,
+					  unsigned int bits)
+{
+	return regmap_field_update_bits_base(field, bits, 0, NULL, false,
+					     false);
+}
+
+int regmap_field_test_bits(struct regmap_field *field, unsigned int bits);
+
 static inline int
 regmap_field_force_update_bits(struct regmap_field *field,
 			       unsigned int mask, unsigned int val)
@@ -1757,6 +1773,27 @@ regmap_field_force_update_bits(struct regmap_field *field,
 	return -EINVAL;
 }
 
+static inline int regmap_field_set_bits(struct regmap_field *field,
+					unsigned int bits)
+{
+	WARN_ONCE(1, "regmap API is disabled");
+	return -EINVAL;
+}
+
+static inline int regmap_field_clear_bits(struct regmap_field *field,
+					  unsigned int bits)
+{
+	WARN_ONCE(1, "regmap API is disabled");
+	return -EINVAL;
+}
+
+static inline int regmap_field_test_bits(struct regmap_field *field,
+					 unsigned int bits)
+{
+	WARN_ONCE(1, "regmap API is disabled");
+	return -EINVAL;
+}
+
 static inline int regmap_fields_write(struct regmap_field *field,
 				      unsigned int id, unsigned int val)
 {
-- 
2.36.1



WARNING: multiple messages have this Message-ID
From: Li Chen <lchen.firstlove@zohomail.com>
To: "Mark Brown" <broonie@kernel.org>,
	"linux-kernel" <linux-kernel@vger.kernel.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"linux-gpio" <linux-gpio@vger.kernel.org>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"linux-arm-kernel" <linux-arm-kernel@lists.infradead.org>,
	"Patrice Chotard" <patrice.chotard@foss.st.com>,
	"linux-sunxi" <linux-sunxi@lists.linux.dev>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>, "Chen-Yu Tsai" <wens@csie.org>,
	"Jernej Skrabec" <jernej.skrabec@gmail.com>,
	"Samuel Holland" <samuel@sholland.org>,
	"Philipp Zabel" <p.zabel@pengutronix.de>
Subject: [PATCH v3 1/4] regmap: provide regmap_field helpers for simple bit operations
Date: Sun, 22 May 2022 20:26:58 -0700	[thread overview]
Message-ID: <180eef422c3.deae9cd960729.8518395646822099769@zohomail.com> (raw)
In-Reply-To: <180eef39205.122d47c8260721.2430302798386025245@zohomail.com>

From: Li Chen <lchen@ambarella.com>

We have set/clear/test operations for regmap, but not for regmap_field yet.
So let's introduce regmap_field helpers too.

In many instances regmap_field_update_bits() is used for simple bit setting
and clearing. In these cases the last argument is redundant and we can
hide it with a static inline function.

This adds three new helpers for simple bit operations: set_bits,
clear_bits and test_bits (the last one defined as a regular function).

Signed-off-by: Li Chen <lchen@ambarella.com>
---
 drivers/base/regmap/regmap.c | 22 +++++++++++++++++++++
 include/linux/regmap.h       | 37 ++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 5e12f7cb5147..a37d6041b7bd 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -2208,6 +2208,28 @@ int regmap_field_update_bits_base(struct regmap_field *field,
 }
 EXPORT_SYMBOL_GPL(regmap_field_update_bits_base);
 
+/**
+ * regmap_field_test_bits() - Check if all specified bits are set in a
+ *                            register field.
+ *
+ * @field: Register field to operate on
+ * @bits: Bits to test
+ *
+ * Returns -1 if the underlying regmap_field_read() fails, 0 if at least one of the
+ * tested bits is not set and 1 if all tested bits are set.
+ */
+int regmap_field_test_bits(struct regmap_field *field, unsigned int bits)
+{
+	unsigned int val, ret;
+
+	ret = regmap_field_read(field, &val);
+	if (ret)
+		return ret;
+
+	return (val & bits) == bits;
+}
+EXPORT_SYMBOL_GPL(regmap_field_test_bits);
+
 /**
  * regmap_fields_update_bits_base() - Perform a read/modify/write cycle a
  *                                    register field with port ID
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index de81a94d7b30..5f317403c520 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -1324,6 +1324,22 @@ static inline int regmap_field_update_bits(struct regmap_field *field,
 					     NULL, false, false);
 }
 
+static inline int regmap_field_set_bits(struct regmap_field *field,
+					unsigned int bits)
+{
+	return regmap_field_update_bits_base(field, bits, bits, NULL, false,
+					     false);
+}
+
+static inline int regmap_field_clear_bits(struct regmap_field *field,
+					  unsigned int bits)
+{
+	return regmap_field_update_bits_base(field, bits, 0, NULL, false,
+					     false);
+}
+
+int regmap_field_test_bits(struct regmap_field *field, unsigned int bits);
+
 static inline int
 regmap_field_force_update_bits(struct regmap_field *field,
 			       unsigned int mask, unsigned int val)
@@ -1757,6 +1773,27 @@ regmap_field_force_update_bits(struct regmap_field *field,
 	return -EINVAL;
 }
 
+static inline int regmap_field_set_bits(struct regmap_field *field,
+					unsigned int bits)
+{
+	WARN_ONCE(1, "regmap API is disabled");
+	return -EINVAL;
+}
+
+static inline int regmap_field_clear_bits(struct regmap_field *field,
+					  unsigned int bits)
+{
+	WARN_ONCE(1, "regmap API is disabled");
+	return -EINVAL;
+}
+
+static inline int regmap_field_test_bits(struct regmap_field *field,
+					 unsigned int bits)
+{
+	WARN_ONCE(1, "regmap API is disabled");
+	return -EINVAL;
+}
+
 static inline int regmap_fields_write(struct regmap_field *field,
 				      unsigned int id, unsigned int val)
 {
-- 
2.36.1



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-05-23  3:28 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-21 14:25 [PATCH 0/4] Add regmap_field helpers for simple bit operations Li Chen
2022-05-21 14:25 ` Li Chen
2022-05-21 14:26 ` [PATCH 1/4] regmap: provide " Li Chen
2022-05-21 14:26   ` Li Chen
2022-05-21 14:27 ` [PATCH 2/4] ASoC: sunxi: Use {regmap/regmap_field}_{set/clear}_bits helpers Li Chen
2022-05-21 14:27   ` Li Chen
2022-05-21 14:28 ` [PATCH 3/4] pinctrl: bcm: Use regmap_field_{set/clear}_bits helpers Li Chen
2022-05-21 14:28   ` Li Chen
2022-05-21 14:29 ` [PATCH 4/4] pinctrl: st: Switch to use regmap_field_test_bits Li Chen
2022-05-21 14:29   ` Li Chen
2022-05-22 16:03   ` kernel test robot
2022-05-22 16:03     ` kernel test robot
2022-05-23  2:22 ` [PATCH v2 0/4] Add regmap_field helpers for simple bit operations Li Chen
2022-05-23  2:22   ` Li Chen
2022-05-23  2:23   ` [PATCH v2 1/4] regmap: provide " Li Chen
2022-05-23  2:23     ` Li Chen
2022-05-23  3:09     ` Samuel Holland
2022-05-23  3:09       ` Samuel Holland
2022-05-23  3:30       ` Li Chen
2022-05-23  3:30         ` Li Chen
2022-05-23  2:24   ` [PATCH v2 2/4] ASoC: sunxi: Use {regmap/regmap_field}_{set/clear}_bits helpers Li Chen
2022-05-23  2:24     ` Li Chen
2022-05-23  2:25   ` [PATCH v2 3/4] pinctrl: bcm: Use regmap_field_{set/clear}_bits helpers Li Chen
2022-05-23  2:25     ` Li Chen
2022-05-23  2:25   ` [PATCH v2 4/4] pinctrl: st: Switch to use regmap_field_test_bits Li Chen
2022-05-23  2:25     ` Li Chen
2022-05-23 11:39   ` [PATCH v2 0/4] Add regmap_field helpers for simple bit operations Mark Brown
2022-05-23 11:39     ` Mark Brown
2022-05-23 13:19     ` Li Chen
2022-05-23 13:19       ` Li Chen
2022-05-23  3:26 ` [PATCH v3 " Li Chen
2022-05-23  3:26   ` Li Chen
2022-05-23  3:26   ` Li Chen [this message]
2022-05-23  3:26     ` [PATCH v3 1/4] regmap: provide " Li Chen
2022-05-23  3:27   ` [PATCH v3 2/4] ASoC: sunxi: Use {regmap/regmap_field}_{set/clear}_bits helpers Li Chen
2022-05-23  3:27     ` Li Chen
2022-05-23  3:28   ` [PATCH v3 3/4] pinctrl: bcm: Use regmap_field_{set/clear}_bits helpers Li Chen
2022-05-23  3:28     ` Li Chen
2022-05-23  3:29   ` [PATCH v3 4/4] pinctrl: st: Switch to use regmap_field_test_bits Li Chen
2022-05-23  3:29     ` Li Chen
2022-06-15 16:59   ` [PATCH v3 0/4] Add regmap_field helpers for simple bit operations Mark Brown
2022-06-15 16:59     ` Mark Brown
2022-06-15 17:08   ` (subset) " Mark Brown
2022-06-15 17:08     ` Mark Brown

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=180eef422c3.deae9cd960729.8518395646822099769@zohomail.com \
    --to=lchen.firstlove@zohomail.com \
    --cc=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jernej.skrabec@gmail.com \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=p.zabel@pengutronix.de \
    --cc=patrice.chotard@foss.st.com \
    --cc=perex@perex.cz \
    --cc=rafael@kernel.org \
    --cc=samuel@sholland.org \
    --cc=tiwai@suse.com \
    --cc=wens@csie.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.