Skip to contentSkip to conversation

regmap: Suppress noop writes in regmap_update_bits()

PATCH New Mark Brown 1 participant 1 message Nov 18, 2011

Subsystems (2)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 regmap: Suppress noop writes in regmap_update_bits()

If the new register value is identical to the original one then suppress the write to the hardware in regmap_update_bits(), saving some I/O cost.

---
 drivers/base/regmap/regmap.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
drivers/base/regmap/regmap.c +5 -4
index e533368..10ecbba3 100644
@@ -583,18 +583,19 @@ int regmap_update_bits(struct regmap *map, unsigned int reg,
 		       unsigned int mask, unsigned int val)
 {
 	int ret;
-	unsigned int tmp;
+	unsigned int tmp, orig;
 
 	mutex_lock(&map->lock);
 
-	ret = _regmap_read(map, reg, &tmp);
+	ret = _regmap_read(map, reg, &orig);
 	if (ret != 0)
 		goto out;
 
-	tmp &= ~mask;
+	tmp = orig & ~mask;
 	tmp |= val & mask;
 
-	ret = _regmap_write(map, reg, tmp);
+	if (tmp != orig)
+		ret = _regmap_write(map, reg, tmp);
 
 out:
 	mutex_unlock(&map->lock);
Signature · 1 line
1.7.7.3