mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Baolin Wang <baolin.wang7@gmail.com>
To: lee.jones@linaro.org, arnd@arndb.de, broonie@kernel.org
Cc: orsonzhai@gmail.com, zhang.lyra@gmail.com,
	baolin.wang7@gmail.com, linux-kernel@vger.kernel.org
Subject: [RFC PATCH 2/3] regmap: Add reg_update_bits() support
Date: Thu,  9 Apr 2020 16:57:58 +0800	[thread overview]
Message-ID: <f48d3b98debe5b2c1cc9a384874d6032b051a4c5.1586422035.git.baolin.wang7@gmail.com> (raw)
In-Reply-To: <cover.1586422035.git.baolin.wang7@gmail.com>
In-Reply-To: <cover.1586422035.git.baolin.wang7@gmail.com>

Add reg_update_bits() support in case some platforms use a special method
to update bits of registers.

Signed-off-by: Baolin Wang <baolin.wang7@gmail.com>
---
 drivers/base/regmap/regmap-mmio.c | 29 ++++++++++++++++++++++++++++-
 drivers/base/regmap/regmap.c      |  1 +
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/base/regmap/regmap-mmio.c b/drivers/base/regmap/regmap-mmio.c
index af967d8..dae0d28 100644
--- a/drivers/base/regmap/regmap-mmio.c
+++ b/drivers/base/regmap/regmap-mmio.c
@@ -24,6 +24,8 @@ struct regmap_mmio_context {
 			  unsigned int reg, unsigned int val);
 	unsigned int (*reg_read)(struct regmap_mmio_context *ctx,
 			         unsigned int reg);
+	int (*reg_update_bits)(void *ctx, unsigned int reg,
+			       unsigned int mask, unsigned int val);
 };
 
 static int regmap_mmio_regbits_check(size_t reg_bits)
@@ -188,6 +190,26 @@ static int regmap_mmio_read(void *context, unsigned int reg, unsigned int *val)
 	return 0;
 }
 
+static int regmap_mmio_update_bits(void *context, unsigned int reg,
+				   unsigned int mask, unsigned int val)
+{
+	struct regmap_mmio_context *ctx = context;
+	int ret;
+
+	if (!IS_ERR(ctx->clk)) {
+		ret = clk_enable(ctx->clk);
+		if (ret < 0)
+			return ret;
+	}
+
+	ctx->reg_update_bits(ctx->regs, reg, mask, val);
+
+	if (!IS_ERR(ctx->clk))
+		clk_disable(ctx->clk);
+
+	return 0;
+}
+
 static void regmap_mmio_free_context(void *context)
 {
 	struct regmap_mmio_context *ctx = context;
@@ -200,7 +222,7 @@ static void regmap_mmio_free_context(void *context)
 	kfree(context);
 }
 
-static const struct regmap_bus regmap_mmio = {
+static struct regmap_bus regmap_mmio = {
 	.fast_io = true,
 	.reg_write = regmap_mmio_write,
 	.reg_read = regmap_mmio_read,
@@ -239,6 +261,11 @@ static struct regmap_mmio_context *regmap_mmio_gen_context(struct device *dev,
 	ctx->val_bytes = config->val_bits / 8;
 	ctx->clk = ERR_PTR(-ENODEV);
 
+	if (config->reg_update_bits) {
+		ctx->reg_update_bits = config->reg_update_bits;
+		regmap_mmio.reg_update_bits = regmap_mmio_update_bits;
+	}
+
 	switch (regmap_get_val_endian(dev, &regmap_mmio, config)) {
 	case REGMAP_ENDIAN_DEFAULT:
 	case REGMAP_ENDIAN_LITTLE:
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 59f911e..553d92a 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -827,6 +827,7 @@ struct regmap *__regmap_init(struct device *dev,
 	} else if (!bus->read || !bus->write) {
 		map->reg_read = _regmap_bus_reg_read;
 		map->reg_write = _regmap_bus_reg_write;
+		map->reg_update_bits = bus->reg_update_bits;
 
 		map->defer_caching = false;
 		goto skip_format_initialization;
-- 
1.9.1


  parent reply	other threads:[~2020-04-09  8:58 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-09  8:57 [RFC PATCH 0/3] Add new " Baolin Wang
2020-04-09  8:57 ` [RFC PATCH 1/3] mfd: syscon: Add reg_update_bits() callback support Baolin Wang
2020-04-09 10:48   ` Mark Brown
2020-04-09 14:13     ` Baolin Wang
2020-04-09 14:27       ` Mark Brown
2020-04-10  2:15         ` Baolin Wang
2020-04-09  8:57 ` Baolin Wang [this message]
2020-04-09 10:45   ` [RFC PATCH 2/3] regmap: Add reg_update_bits() support Mark Brown
2020-04-09 14:12     ` Baolin Wang
2020-04-09 14:26       ` Mark Brown
2020-04-10  2:55         ` Baolin Wang
2020-04-09  8:57 ` [RFC PATCH 3/3] soc: sprd: Add Spreadtrum special bits updating support Baolin Wang
2020-04-09  9:15 ` [RFC PATCH 0/3] Add new reg_update_bits() support Arnd Bergmann
2020-04-09  9:40   ` Baolin Wang
2020-04-09  9:52     ` Arnd Bergmann
2020-04-09  9:56       ` Baolin Wang

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=f48d3b98debe5b2c1cc9a384874d6032b051a4c5.1586422035.git.baolin.wang7@gmail.com \
    --to=baolin.wang7@gmail.com \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=orsonzhai@gmail.com \
    --cc=zhang.lyra@gmail.com \
    /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®