[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <f48d3b98debe5b2c1cc9a384874d6032b051a4c5.1586422035.git.baolin.wang7@gmail.com>
Date: Thu, 9 Apr 2020 16:57:58 +0800
From: Baolin Wang <baolin.wang7@...il.com>
To: lee.jones@...aro.org, arnd@...db.de, broonie@...nel.org
Cc: orsonzhai@...il.com, zhang.lyra@...il.com, baolin.wang7@...il.com,
linux-kernel@...r.kernel.org
Subject: [RFC PATCH 2/3] regmap: Add reg_update_bits() support
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@...il.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, ®map_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
Powered by blists - more mailing lists