Skip to contentSkip to conversation

regmap: core: Provide regmap_can_raw_write() operation

PATCH New Mark Brown 1 participant 2 messages Mar 27, 2013

Subsystems (2)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/2 regmap: core: Provide regmap_can_raw_write() operation

Mainly useful internally but exported since this is a public API that's being checked for.

---
 drivers/base/regmap/regmap.c |   15 ++++++++++++---
 include/linux/regmap.h       |    1 +
 2 files changed, 13 insertions(+), 3 deletions(-)
drivers/base/regmap/regmap.c +12 -3
index 9174c9d..9ab1e1f 100644
@@ -1097,6 +1097,17 @@ int _regmap_raw_write(struct regmap *map, unsigned int reg,
 	return ret;
 }
 
+/**
+ * regmap_can_raw_write - Test if regmap_raw_write() is supported
+ *
+ * @map: Map to check.
+ */
+bool regmap_can_raw_write(struct regmap *map)
+{
+	return map->bus && map->format.format_val && map->format.format_reg;
+}
+EXPORT_SYMBOL_GPL(regmap_can_raw_write);
+
 static int _regmap_bus_formatted_write(void *context, unsigned int reg,
 				       unsigned int val)
 {
@@ -1220,12 +1231,10 @@ int regmap_raw_write(struct regmap *map, unsigned int reg,
 {
 	int ret;
 
-	if (!map->bus)
+	if (!regmap_can_raw_write(map))
 		return -EINVAL;
 	if (val_len % map->format.val_bytes)
 		return -EINVAL;
-	if (reg % map->reg_stride)
-		return -EINVAL;
 
 	map->lock(map->lock_arg);
 
include/linux/regmap.h +1 -0
index bf77dfd..02d84e2 100644
@@ -389,6 +389,7 @@ int regmap_update_bits_check(struct regmap *map, unsigned int reg,
 			     bool *change);
 int regmap_get_val_bytes(struct regmap *map);
 int regmap_async_complete(struct regmap *map);
+bool regmap_can_raw_write(struct regmap *map);
 
 int regcache_sync(struct regmap *map);
 int regcache_sync_region(struct regmap *map, unsigned int min,
Signature · 1 line
1.7.10.4
author
#1 lore raw

PATCH 2/2 regmap: cache: Use raw I/O to sync rbtrees if we can

This will bring no meaningful benefit by itself, it is done as a separate commit to aid bisection if there are problems with the following commits adding support for coalescing adjacent writes.

---
 drivers/base/regmap/regcache-rbtree.c |   19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
drivers/base/regmap/regcache-rbtree.c +18 -1
index 792a760..382a6de 100644
@@ -55,6 +55,12 @@ static unsigned int regcache_rbtree_get_register(struct regmap *map,
 	return regcache_get_val(map, rbnode->block, idx);
 }
 
+static const void *regcache_rbtree_get_reg_addr(struct regmap *map,
+	struct regcache_rbtree_node *rbnode, unsigned int idx)
+{
+	return regcache_get_val_addr(map, rbnode->block, idx);
+}
+
 static void regcache_rbtree_set_register(struct regmap *map,
 					 struct regcache_rbtree_node *rbnode,
 					 unsigned int idx, unsigned int val)
@@ -442,6 +448,7 @@ static int regcache_rbtree_sync(struct regmap *map, unsigned int min,
 	struct regcache_rbtree_node *rbnode;
 	unsigned int regtmp;
 	unsigned int val;
+	const void *addr;
 	int ret;
 	int i, base, end;
 
@@ -480,7 +487,17 @@ static int regcache_rbtree_sync(struct regmap *map, unsigned int min,
 				continue;
 
 			map->cache_bypass = 1;
-			ret = _regmap_write(map, regtmp, val);
+
+			if (regmap_can_raw_write(map)) {
+				addr = regcache_rbtree_get_reg_addr(map,
+								    rbnode, i);
+				ret = _regmap_raw_write(map, regtmp, addr,
+							map->format.val_bytes,
+							false);
+			} else {
+				ret = _regmap_write(map, regtmp, val);
+			}
+
 			map->cache_bypass = 0;
 			if (ret)
 				return ret;
Signature · 1 line
1.7.10.4