MFD: twl6040: Cache the vibra control registers
authorPeter Ujfalusi <peter.ujfalusi@ti.com>
Wed, 12 Oct 2011 08:57:54 +0000 (11:57 +0300)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Wed, 12 Oct 2011 10:48:46 +0000 (11:48 +0100)
The vibra control register will be used from the ASoC codec driver as well.
In order to avoid latency issues caused by I2C read access, cache the two
control register within the core driver, so we do not need to reach out
to the chip to read it back.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
Acked-by: Samuel Ortiz <samuel.ortiz@intel.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
drivers/mfd/twl6040-core.c
include/linux/mfd/twl6040.h

index 7dc8c47150017ba64c515038258c6fe02e098b36..75987c8ca049773f7b8fabbbd3d4000d2393baa5 100644 (file)
 #include <linux/mfd/core.h>
 #include <linux/mfd/twl6040.h>
 
+#define VIBRACTRL_MEMBER(reg) ((reg == TWL6040_REG_VIBCTLL) ? 0 : 1)
+
 int twl6040_reg_read(struct twl6040 *twl6040, unsigned int reg)
 {
        int ret;
        u8 val = 0;
 
        mutex_lock(&twl6040->io_mutex);
-       ret = twl_i2c_read_u8(TWL_MODULE_AUDIO_VOICE, &val, reg);
-       if (ret < 0) {
-               mutex_unlock(&twl6040->io_mutex);
-               return ret;
+       /* Vibra control registers from cache */
+       if (unlikely(reg == TWL6040_REG_VIBCTLL ||
+                    reg == TWL6040_REG_VIBCTLR)) {
+               val = twl6040->vibra_ctrl_cache[VIBRACTRL_MEMBER(reg)];
+       } else {
+               ret = twl_i2c_read_u8(TWL_MODULE_AUDIO_VOICE, &val, reg);
+               if (ret < 0) {
+                       mutex_unlock(&twl6040->io_mutex);
+                       return ret;
+               }
        }
        mutex_unlock(&twl6040->io_mutex);
 
@@ -57,6 +65,9 @@ int twl6040_reg_write(struct twl6040 *twl6040, unsigned int reg, u8 val)
 
        mutex_lock(&twl6040->io_mutex);
        ret = twl_i2c_write_u8(TWL_MODULE_AUDIO_VOICE, val, reg);
+       /* Cache the vibra control registers */
+       if (reg == TWL6040_REG_VIBCTLL || reg == TWL6040_REG_VIBCTLR)
+               twl6040->vibra_ctrl_cache[VIBRACTRL_MEMBER(reg)] = val;
        mutex_unlock(&twl6040->io_mutex);
 
        return ret;
index e6c755db456061d358f224599eb22118717951ca..2f8585a4c74b9ed7f67db6e1bbf8da8ac725462a 100644 (file)
@@ -184,6 +184,7 @@ struct twl6040 {
        int audpwron;
        int power_count;
        int rev;
+       u8 vibra_ctrl_cache[2];
 
        int pll;
        unsigned int sysclk;