mfd: Cache tps6586x register through regmap
authorLaxman Dewangan <ldewangan@nvidia.com>
Wed, 18 Jul 2012 06:20:47 +0000 (11:50 +0530)
committerSamuel Ortiz <sameo@linux.intel.com>
Tue, 24 Jul 2012 22:36:53 +0000 (00:36 +0200)
To cache the interrupt mask register, use the regmap RB_TREE
cache-ing mechanism in place of implementing it locally.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
drivers/mfd/tps6586x.c

index 6f59594c6c11bfb40e12ea401778495d4888580b..d59bfb77326bf87c143c97321dc6f04ab671ed51 100644 (file)
@@ -104,7 +104,6 @@ struct tps6586x {
        struct mutex            irq_lock;
        int                     irq_base;
        u32                     irq_en;
-       u8                      mask_cache[5];
        u8                      mask_reg[5];
 };
 
@@ -276,12 +275,11 @@ static void tps6586x_irq_sync_unlock(struct irq_data *data)
        int i;
 
        for (i = 0; i < ARRAY_SIZE(tps6586x->mask_reg); i++) {
-               if (tps6586x->mask_reg[i] != tps6586x->mask_cache[i]) {
-                       if (!WARN_ON(tps6586x_write(tps6586x->dev,
-                                                   TPS6586X_INT_MASK1 + i,
-                                                   tps6586x->mask_reg[i])))
-                               tps6586x->mask_cache[i] = tps6586x->mask_reg[i];
-               }
+               int ret;
+               ret = tps6586x_write(tps6586x->dev,
+                                           TPS6586X_INT_MASK1 + i,
+                                           tps6586x->mask_reg[i]);
+               WARN_ON(ret);
        }
 
        mutex_unlock(&tps6586x->irq_lock);
@@ -328,7 +326,6 @@ static int __devinit tps6586x_irq_init(struct tps6586x *tps6586x, int irq,
 
        mutex_init(&tps6586x->irq_lock);
        for (i = 0; i < 5; i++) {
-               tps6586x->mask_cache[i] = 0xff;
                tps6586x->mask_reg[i] = 0xff;
                tps6586x_write(tps6586x->dev, TPS6586X_INT_MASK1 + i, 0xff);
        }
@@ -478,10 +475,21 @@ static struct tps6586x_platform_data *tps6586x_parse_dt(struct i2c_client *clien
 }
 #endif
 
+static bool is_volatile_reg(struct device *dev, unsigned int reg)
+{
+       /* Cache all interrupt mask register */
+       if ((reg >= TPS6586X_INT_MASK1) && (reg <= TPS6586X_INT_MASK5))
+               return false;
+
+       return true;
+}
+
 static const struct regmap_config tps6586x_regmap_config = {
        .reg_bits = 8,
        .val_bits = 8,
        .max_register = TPS6586X_MAX_REGISTER - 1,
+       .volatile_reg = is_volatile_reg,
+       .cache_type = REGCACHE_RBTREE,
 };
 
 static int __devinit tps6586x_i2c_probe(struct i2c_client *client,