mfd: Add regmap cache support for wm8350
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Sun, 3 Jun 2012 12:37:22 +0000 (13:37 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Sun, 8 Jul 2012 22:16:10 +0000 (00:16 +0200)
Use the most simple possible transformation on the existing code so keep
the table sitting around, further patches in this series will delete the
existing cache code - the main purpose of this patch is to ensure that
we always have a cache for bisection.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
drivers/mfd/wm8350-core.c
drivers/mfd/wm8350-i2c.c
drivers/mfd/wm8350-regmap.c
include/linux/mfd/wm8350/core.h

index 8a9b11ca076ac3c528e914b52dd78d958b714fae..fadcbbe9e2ba38ecea12a564b06c4393c52bd5ef 100644 (file)
@@ -32,9 +32,6 @@
 #include <linux/mfd/wm8350/supply.h>
 #include <linux/mfd/wm8350/wdt.h>
 
-#define WM8350_UNLOCK_KEY              0x0013
-#define WM8350_LOCK_KEY                        0x0000
-
 #define WM8350_CLOCK_CONTROL_1         0x28
 #define WM8350_AIF_TEST                        0x74
 
@@ -295,15 +292,20 @@ EXPORT_SYMBOL_GPL(wm8350_block_write);
  */
 int wm8350_reg_lock(struct wm8350 *wm8350)
 {
-       u16 key = WM8350_LOCK_KEY;
        int ret;
 
+       mutex_lock(&reg_lock_mutex);
+
        ldbg(__func__);
-       mutex_lock(&io_mutex);
-       ret = wm8350_write(wm8350, WM8350_SECURITY, 1, &key);
+
+       ret = wm8350_reg_write(wm8350, WM8350_SECURITY, WM8350_LOCK_KEY);
        if (ret)
                dev_err(wm8350->dev, "lock failed\n");
-       mutex_unlock(&io_mutex);
+
+       wm8350->unlocked = false;
+
+       mutex_unlock(&reg_lock_mutex);
+
        return ret;
 }
 EXPORT_SYMBOL_GPL(wm8350_reg_lock);
@@ -319,15 +321,20 @@ EXPORT_SYMBOL_GPL(wm8350_reg_lock);
  */
 int wm8350_reg_unlock(struct wm8350 *wm8350)
 {
-       u16 key = WM8350_UNLOCK_KEY;
        int ret;
 
+       mutex_lock(&reg_lock_mutex);
+
        ldbg(__func__);
-       mutex_lock(&io_mutex);
-       ret = wm8350_write(wm8350, WM8350_SECURITY, 1, &key);
+
+       ret = wm8350_reg_write(wm8350, WM8350_SECURITY, WM8350_UNLOCK_KEY);
        if (ret)
                dev_err(wm8350->dev, "unlock failed\n");
-       mutex_unlock(&io_mutex);
+
+       wm8350->unlocked = true;
+
+       mutex_unlock(&reg_lock_mutex);
+
        return ret;
 }
 EXPORT_SYMBOL_GPL(wm8350_reg_unlock);
index a68aceb4e48c880fbf7b79e64459762241eeaa29..2e57101c8d3dabfc395f2bf764bddc23a411bbe5 100644 (file)
 #include <linux/regmap.h>
 #include <linux/slab.h>
 
-static const struct regmap_config wm8350_regmap = {
-       .reg_bits = 8,
-       .val_bits = 16,
-};
-
 static int wm8350_i2c_probe(struct i2c_client *i2c,
                            const struct i2c_device_id *id)
 {
index e965139e5cd5ba116369eedd05b72435621b6796..7974cadaa42275a928a57107412013e1db6f87ad 100644 (file)
@@ -3433,3 +3433,59 @@ const struct wm8350_reg_access wm8350_reg_io_map[] = {
        { 0x0000, 0x0000, 0x0000 }, /* R254 */
        { 0x0000, 0x0000, 0x0000 }, /* R255 */
 };
+
+static bool wm8350_readable(struct device *dev, unsigned int reg)
+{
+       return wm8350_reg_io_map[reg].readable;
+}
+
+static bool wm8350_writeable(struct device *dev, unsigned int reg)
+{
+       struct wm8350 *wm8350 = dev_get_drvdata(dev);
+
+       if (!wm8350->unlocked) {
+               if ((reg >= WM8350_GPIO_FUNCTION_SELECT_1 &&
+                    reg <= WM8350_GPIO_FUNCTION_SELECT_4) ||
+                   (reg >= WM8350_BATTERY_CHARGER_CONTROL_1 &&
+                    reg <= WM8350_BATTERY_CHARGER_CONTROL_3))
+                       return false;
+       }
+
+       return wm8350_reg_io_map[reg].writable;
+}
+
+static bool wm8350_volatile(struct device *dev, unsigned int reg)
+{
+       return wm8350_reg_io_map[reg].vol;
+}
+
+static bool wm8350_precious(struct device *dev, unsigned int reg)
+{
+       switch (reg) {
+       case WM8350_SYSTEM_INTERRUPTS:
+       case WM8350_INT_STATUS_1:
+       case WM8350_INT_STATUS_2:
+       case WM8350_POWER_UP_INT_STATUS:
+       case WM8350_UNDER_VOLTAGE_INT_STATUS:
+       case WM8350_OVER_CURRENT_INT_STATUS:
+       case WM8350_GPIO_INT_STATUS:
+       case WM8350_COMPARATOR_INT_STATUS:
+               return true;
+
+       default:
+               return false;
+       }
+}
+
+const struct regmap_config wm8350_regmap = {
+       .reg_bits = 8,
+       .val_bits = 16,
+
+       .cache_type = REGCACHE_RBTREE,
+
+       .max_register = WM8350_MAX_REGISTER,
+       .readable_reg = wm8350_readable,
+       .writeable_reg = wm8350_writeable,
+       .volatile_reg = wm8350_volatile,
+       .precious_reg = wm8350_precious,
+};
index 9192b6404a7347d5b6e665925a421cf1024d3c24..cba9bc8f947b5f33d63303773ab8cfd33605772f 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/mutex.h>
 #include <linux/interrupt.h>
 #include <linux/completion.h>
+#include <linux/regmap.h>
 
 #include <linux/mfd/wm8350/audio.h>
 #include <linux/mfd/wm8350/gpio.h>
@@ -66,6 +67,9 @@
 
 #define WM8350_MAX_REGISTER                     0xFF
 
+#define WM8350_UNLOCK_KEY              0x0013
+#define WM8350_LOCK_KEY                        0x0000
+
 /*
  * Field Definitions.
  */
 
 #define WM8350_NUM_IRQ_REGS 7
 
+extern const struct regmap_config wm8350_regmap;
 struct wm8350_reg_access {
        u16 readable;           /* Mask of readable bits */
        u16 writable;           /* Mask of writable bits */
@@ -602,7 +607,6 @@ extern const u16 wm8352_mode2_defaults[];
 extern const u16 wm8352_mode3_defaults[];
 
 struct wm8350;
-struct regmap;
 
 struct wm8350_hwmon {
        struct platform_device *pdev;
@@ -615,6 +619,7 @@ struct wm8350 {
        /* device IO */
        struct regmap *regmap;
        u16 *reg_cache;
+       bool unlocked;
 
        struct mutex auxadc_mutex;
        struct completion auxadc_done;