Merge tag 'device-for-3.4' of git://git.kernel.org/pub/scm/linux/kernel/git/paulg...
[linux-2.6.git] / drivers / base / regmap / regcache-rbtree.c
index b487c29..5157fa0 100644 (file)
@@ -358,7 +358,8 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
        return 0;
 }
 
-static int regcache_rbtree_sync(struct regmap *map)
+static int regcache_rbtree_sync(struct regmap *map, unsigned int min,
+                               unsigned int max)
 {
        struct regcache_rbtree_ctx *rbtree_ctx;
        struct rb_node *node;
@@ -366,19 +367,37 @@ static int regcache_rbtree_sync(struct regmap *map)
        unsigned int regtmp;
        unsigned int val;
        int ret;
-       int i;
+       int i, base, end;
 
        rbtree_ctx = map->cache;
        for (node = rb_first(&rbtree_ctx->root); node; node = rb_next(node)) {
                rbnode = rb_entry(node, struct regcache_rbtree_node, node);
-               for (i = 0; i < rbnode->blklen; i++) {
+
+               if (rbnode->base_reg < min)
+                       continue;
+               if (rbnode->base_reg > max)
+                       break;
+               if (rbnode->base_reg + rbnode->blklen < min)
+                       continue;
+
+               if (min > rbnode->base_reg)
+                       base = min - rbnode->base_reg;
+               else
+                       base = 0;
+
+               if (max < rbnode->base_reg + rbnode->blklen)
+                       end = rbnode->base_reg + rbnode->blklen - max;
+               else
+                       end = rbnode->blklen;
+
+               for (i = base; i < end; i++) {
                        regtmp = rbnode->base_reg + i;
                        val = regcache_rbtree_get_register(rbnode, i,
                                                           map->cache_word_size);
 
                        /* Is this the hardware default?  If so skip. */
                        ret = regcache_lookup_reg(map, i);
-                       if (ret > 0 && val == map->reg_defaults[ret].def)
+                       if (ret >= 0 && val == map->reg_defaults[ret].def)
                                continue;
 
                        map->cache_bypass = 1;