[RFC] regmap: allow volatile register writes with cached only read maps
From: Jorge Ramirez-Ortiz
Date: Tue May 08 2018 - 18:06:27 EST
Regmap only allows volatile access to registers when the client
supports both reads and writes.
This commit bypasses that limitation and enables volatile writes to
selected registers while maintaining cached accesses on all reads. For
this, the client does not need to configure the reg_read callback.
Signed-off-by: Jorge Ramirez-Ortiz <jramirez@xxxxxxxxxxxx>
---
drivers/base/regmap/internal.h | 1 +
drivers/base/regmap/regcache.c | 10 +++++++++-
drivers/base/regmap/regmap-debugfs.c | 17 +++++++++++++++--
drivers/base/regmap/regmap.c | 11 +++++++++++
4 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h
index 53785e0..496c825 100644
--- a/drivers/base/regmap/internal.h
+++ b/drivers/base/regmap/internal.h
@@ -180,6 +180,7 @@ bool regmap_cached(struct regmap *map, unsigned int reg);
bool regmap_writeable(struct regmap *map, unsigned int reg);
bool regmap_readable(struct regmap *map, unsigned int reg);
bool regmap_volatile(struct regmap *map, unsigned int reg);
+bool regmap_volatile_writes(struct regmap *map, unsigned int reg);
bool regmap_precious(struct regmap *map, unsigned int reg);
int _regmap_write(struct regmap *map, unsigned int reg,
diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index 7735603..51cceaa 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -273,8 +273,16 @@ int regcache_write(struct regmap *map,
BUG_ON(!map->cache_ops);
- if (!regmap_volatile(map, reg))
+ if (!regmap_volatile(map, reg)) {
+
+ if (!regmap_readable(map, reg)) {
+ /* check if the client configured volatile writes */
+ if (regmap_volatile_writes(map, reg))
+ return 0;
+ }
+
return map->cache_ops->write(map, reg, value);
+ }
return 0;
}
diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index 87b562e..89fb771 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -415,20 +415,33 @@ static const struct file_operations regmap_reg_ranges_fops = {
static int regmap_access_show(struct seq_file *s, void *ignored)
{
struct regmap *map = s->private;
+ char reg_volatile;
int i, reg_len;
reg_len = regmap_calc_reg_len(map->max_register);
for (i = 0; i <= map->max_register; i += map->reg_stride) {
- /* Ignore registers which are neither readable nor writable */
+ reg_volatile = 'n';
+
+ /* Ignore registers which are neither readable nor writable */
if (!regmap_readable(map, i) && !regmap_writeable(map, i))
continue;
+ if (regmap_volatile(map, i)) {
+ reg_volatile = 'y';
+ goto done;
+ }
+
+ if (!regmap_readable(map, i)) {
+ if (regmap_volatile_writes(map, i))
+ reg_volatile = 'y';
+ }
+done:
/* Format the register */
seq_printf(s, "%.*x: %c %c %c %c\n", reg_len, i,
regmap_readable(map, i) ? 'y' : 'n',
regmap_writeable(map, i) ? 'y' : 'n',
- regmap_volatile(map, i) ? 'y' : 'n',
+ reg_volatile,
regmap_precious(map, i) ? 'y' : 'n');
}
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 3bc8488..7d4b671 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -154,6 +154,17 @@ bool regmap_volatile(struct regmap *map, unsigned int reg)
return true;
}
+bool regmap_volatile_writes(struct regmap *map, unsigned int reg)
+{
+ if (map->volatile_reg)
+ return map->volatile_reg(map->dev, reg);
+
+ if (map->volatile_table)
+ return regmap_check_range_table(map, reg, map->volatile_table);
+
+ return false;
+}
+
bool regmap_precious(struct regmap *map, unsigned int reg)
{
if (!regmap_readable(map, reg))
--
2.7.4