ASoC: wm5100: Mark register cache as dirty when regulators are disabled
[deliverable/linux.git] / sound / soc / codecs / wm5100.c
index 08bf073ce19fa89a6af37f1ff368b475b6cc1703..89f2af77b1c3983afaa407e6ff2740ec95e0c068 100644 (file)
@@ -18,7 +18,6 @@
 #include <linux/gcd.h>
 #include <linux/gpio.h>
 #include <linux/i2c.h>
-#include <linux/platform_device.h>
 #include <linux/regulator/consumer.h>
 #include <linux/regulator/fixed.h>
 #include <linux/slab.h>
@@ -953,7 +952,7 @@ SND_SOC_DAPM_INPUT("IN3L"),
 SND_SOC_DAPM_INPUT("IN3R"),
 SND_SOC_DAPM_INPUT("IN4L"),
 SND_SOC_DAPM_INPUT("IN4R"),
-SND_SOC_DAPM_INPUT("TONE"),
+SND_SOC_DAPM_SIGGEN("TONE"),
 
 SND_SOC_DAPM_PGA_E("IN1L PGA", WM5100_INPUT_ENABLES, WM5100_IN1L_ENA_SHIFT, 0,
                   NULL, 0, wm5100_out_ev, SND_SOC_DAPM_POST_PMU),
@@ -1378,6 +1377,7 @@ static int wm5100_set_bias_level(struct snd_soc_codec *codec,
 
                        switch (wm5100->rev) {
                        case 0:
+                               regcache_cache_bypass(wm5100->regmap, true);
                                snd_soc_write(codec, 0x11, 0x3);
                                snd_soc_write(codec, 0x203, 0xc);
                                snd_soc_write(codec, 0x206, 0);
@@ -1393,6 +1393,7 @@ static int wm5100_set_bias_level(struct snd_soc_codec *codec,
                                        snd_soc_write(codec,
                                                      wm5100_reva_patches[i].reg,
                                                      wm5100_reva_patches[i].val);
+                               regcache_cache_bypass(wm5100->regmap, false);
                                break;
                        default:
                                break;
@@ -1403,6 +1404,8 @@ static int wm5100_set_bias_level(struct snd_soc_codec *codec,
                break;
 
        case SND_SOC_BIAS_OFF:
+               regcache_cache_only(wm5100->regmap, true);
+               regcache_mark_dirty(wm5100->regmap);
                if (wm5100->pdata.ldo_ena)
                        gpio_set_value_cansleep(wm5100->pdata.ldo_ena, 0);
                regulator_bulk_disable(ARRAY_SIZE(wm5100->core_supplies),
@@ -1661,7 +1664,7 @@ static int wm5100_hw_params(struct snd_pcm_substream *substream,
        return 0;
 }
 
-static struct snd_soc_dai_ops wm5100_dai_ops = {
+static const struct snd_soc_dai_ops wm5100_dai_ops = {
        .set_fmt = wm5100_set_fmt,
        .hw_params = wm5100_hw_params,
 };
@@ -2181,6 +2184,7 @@ static void wm5100_micd_irq(struct snd_soc_codec *codec)
                if (wm5100->jack_detecting) {
                        dev_dbg(codec->dev, "Microphone detected\n");
                        wm5100->jack_mic = true;
+                       wm5100->jack_detecting = false;
                        snd_soc_jack_report(wm5100->jack,
                                            SND_JACK_HEADSET,
                                            SND_JACK_HEADSET | SND_JACK_BTN_0);
@@ -2219,6 +2223,7 @@ static void wm5100_micd_irq(struct snd_soc_codec *codec)
                                            SND_JACK_BTN_0);
                } else if (wm5100->jack_detecting) {
                        dev_dbg(codec->dev, "Headphone detected\n");
+                       wm5100->jack_detecting = false;
                        snd_soc_jack_report(wm5100->jack, SND_JACK_HEADPHONE,
                                            SND_JACK_HEADPHONE);
 
@@ -2352,24 +2357,22 @@ static inline struct wm5100_priv *gpio_to_wm5100(struct gpio_chip *chip)
 static void wm5100_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
 {
        struct wm5100_priv *wm5100 = gpio_to_wm5100(chip);
-       struct snd_soc_codec *codec = wm5100->codec;
 
-       snd_soc_update_bits(codec, WM5100_GPIO_CTRL_1 + offset,
-                           WM5100_GP1_LVL, !!value << WM5100_GP1_LVL_SHIFT);
+       regmap_update_bits(wm5100->regmap, WM5100_GPIO_CTRL_1 + offset,
+                          WM5100_GP1_LVL, !!value << WM5100_GP1_LVL_SHIFT);
 }
 
 static int wm5100_gpio_direction_out(struct gpio_chip *chip,
                                     unsigned offset, int value)
 {
        struct wm5100_priv *wm5100 = gpio_to_wm5100(chip);
-       struct snd_soc_codec *codec = wm5100->codec;
        int val, ret;
 
        val = (1 << WM5100_GP1_FN_SHIFT) | (!!value << WM5100_GP1_LVL_SHIFT);
 
-       ret = snd_soc_update_bits(codec, WM5100_GPIO_CTRL_1 + offset,
-                                 WM5100_GP1_FN_MASK | WM5100_GP1_DIR |
-                                 WM5100_GP1_LVL, val);
+       ret = regmap_update_bits(wm5100->regmap, WM5100_GPIO_CTRL_1 + offset,
+                                WM5100_GP1_FN_MASK | WM5100_GP1_DIR |
+                                WM5100_GP1_LVL, val);
        if (ret < 0)
                return ret;
        else
@@ -2379,25 +2382,24 @@ static int wm5100_gpio_direction_out(struct gpio_chip *chip,
 static int wm5100_gpio_get(struct gpio_chip *chip, unsigned offset)
 {
        struct wm5100_priv *wm5100 = gpio_to_wm5100(chip);
-       struct snd_soc_codec *codec = wm5100->codec;
+       unsigned int reg;
        int ret;
 
-       ret = snd_soc_read(codec, WM5100_GPIO_CTRL_1 + offset);
+       ret = regmap_read(wm5100->regmap, WM5100_GPIO_CTRL_1 + offset, &reg);
        if (ret < 0)
                return ret;
 
-       return (ret & WM5100_GP1_LVL) != 0;
+       return (reg & WM5100_GP1_LVL) != 0;
 }
 
 static int wm5100_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
 {
        struct wm5100_priv *wm5100 = gpio_to_wm5100(chip);
-       struct snd_soc_codec *codec = wm5100->codec;
 
-       return snd_soc_update_bits(codec, WM5100_GPIO_CTRL_1 + offset,
-                                  WM5100_GP1_FN_MASK | WM5100_GP1_DIR,
-                                  (1 << WM5100_GP1_FN_SHIFT) |
-                                  (1 << WM5100_GP1_DIR_SHIFT));
+       return regmap_update_bits(wm5100->regmap, WM5100_GPIO_CTRL_1 + offset,
+                                 WM5100_GP1_FN_MASK | WM5100_GP1_DIR,
+                                 (1 << WM5100_GP1_FN_SHIFT) |
+                                 (1 << WM5100_GP1_DIR_SHIFT));
 }
 
 static struct gpio_chip wm5100_template_chip = {
@@ -2410,14 +2412,14 @@ static struct gpio_chip wm5100_template_chip = {
        .can_sleep              = 1,
 };
 
-static void wm5100_init_gpio(struct snd_soc_codec *codec)
+static void wm5100_init_gpio(struct i2c_client *i2c)
 {
-       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+       struct wm5100_priv *wm5100 = i2c_get_clientdata(i2c);
        int ret;
 
        wm5100->gpio_chip = wm5100_template_chip;
        wm5100->gpio_chip.ngpio = 6;
-       wm5100->gpio_chip.dev = codec->dev;
+       wm5100->gpio_chip.dev = &i2c->dev;
 
        if (wm5100->pdata.gpio_base)
                wm5100->gpio_chip.base = wm5100->pdata.gpio_base;
@@ -2426,24 +2428,24 @@ static void wm5100_init_gpio(struct snd_soc_codec *codec)
 
        ret = gpiochip_add(&wm5100->gpio_chip);
        if (ret != 0)
-               dev_err(codec->dev, "Failed to add GPIOs: %d\n", ret);
+               dev_err(&i2c->dev, "Failed to add GPIOs: %d\n", ret);
 }
 
-static void wm5100_free_gpio(struct snd_soc_codec *codec)
+static void wm5100_free_gpio(struct i2c_client *i2c)
 {
-       struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
+       struct wm5100_priv *wm5100 = i2c_get_clientdata(i2c);
        int ret;
 
        ret = gpiochip_remove(&wm5100->gpio_chip);
        if (ret != 0)
-               dev_err(codec->dev, "Failed to remove GPIOs: %d\n", ret);
+               dev_err(&i2c->dev, "Failed to remove GPIOs: %d\n", ret);
 }
 #else
-static void wm5100_init_gpio(struct snd_soc_codec *codec)
+static void wm5100_init_gpio(struct i2c_client *i2c)
 {
 }
 
-static void wm5100_free_gpio(struct snd_soc_codec *codec)
+static void wm5100_free_gpio(struct i2c_client *i2c)
 {
 }
 #endif
@@ -2465,30 +2467,11 @@ static int wm5100_probe(struct snd_soc_codec *codec)
 
        regcache_cache_only(wm5100->regmap, true);
 
-       wm5100_init_gpio(codec);
 
        for (i = 0; i < ARRAY_SIZE(wm5100_dig_vu); i++)
                snd_soc_update_bits(codec, wm5100_dig_vu[i], WM5100_OUT_VU,
                                    WM5100_OUT_VU);
 
-       for (i = 0; i < ARRAY_SIZE(wm5100->pdata.in_mode); i++) {
-               snd_soc_update_bits(codec, WM5100_IN1L_CONTROL,
-                                   WM5100_IN1_MODE_MASK |
-                                   WM5100_IN1_DMIC_SUP_MASK,
-                                   (wm5100->pdata.in_mode[i] <<
-                                    WM5100_IN1_MODE_SHIFT) |
-                                   (wm5100->pdata.dmic_sup[i] <<
-                                    WM5100_IN1_DMIC_SUP_SHIFT));
-       }
-
-       for (i = 0; i < ARRAY_SIZE(wm5100->pdata.gpio_defaults); i++) {
-               if (!wm5100->pdata.gpio_defaults[i])
-                       continue;
-
-               snd_soc_write(codec, WM5100_GPIO_CTRL_1 + i,
-                             wm5100->pdata.gpio_defaults[i]);
-       }
-
        /* Don't debounce interrupts to support use of SYSCLK only */
        snd_soc_write(codec, WM5100_IRQ_DEBOUNCE_1, 0);
        snd_soc_write(codec, WM5100_IRQ_DEBOUNCE_2, 0);
@@ -2573,7 +2556,6 @@ static int wm5100_probe(struct snd_soc_codec *codec)
 err_gpio:
        if (i2c->irq)
                free_irq(i2c->irq, codec);
-       wm5100_free_gpio(codec);
 
        return ret;
 }
@@ -2589,10 +2571,16 @@ static int wm5100_remove(struct snd_soc_codec *codec)
        }
        if (i2c->irq)
                free_irq(i2c->irq, codec);
-       wm5100_free_gpio(codec);
        return 0;
 }
 
+static int wm5100_soc_volatile(struct snd_soc_codec *codec,
+                              unsigned int reg)
+{
+       return true;
+}
+
+
 static struct snd_soc_codec_driver soc_codec_dev_wm5100 = {
        .probe =        wm5100_probe,
        .remove =       wm5100_remove,
@@ -2601,6 +2589,8 @@ static struct snd_soc_codec_driver soc_codec_dev_wm5100 = {
        .set_pll = wm5100_set_fll,
        .set_bias_level = wm5100_set_bias_level,
        .idle_bias_off = 1,
+       .reg_cache_size = WM5100_MAX_REGISTER,
+       .volatile_register = wm5100_soc_volatile,
 
        .seq_notifier = wm5100_seq_notifier,
        .controls = wm5100_snd_controls,
@@ -2623,6 +2613,13 @@ static const struct regmap_config wm5100_regmap = {
        .cache_type = REGCACHE_RBTREE,
 };
 
+static const unsigned int wm5100_mic_ctrl_reg[] = {
+       WM5100_IN1L_CONTROL,
+       WM5100_IN2L_CONTROL,
+       WM5100_IN3L_CONTROL,
+       WM5100_IN4L_CONTROL,
+};
+
 static __devinit int wm5100_i2c_probe(struct i2c_client *i2c,
                                      const struct i2c_device_id *id)
 {
@@ -2631,7 +2628,8 @@ static __devinit int wm5100_i2c_probe(struct i2c_client *i2c,
        unsigned int reg;
        int ret, i;
 
-       wm5100 = kzalloc(sizeof(struct wm5100_priv), GFP_KERNEL);
+       wm5100 = devm_kzalloc(&i2c->dev, sizeof(struct wm5100_priv),
+                             GFP_KERNEL);
        if (wm5100 == NULL)
                return -ENOMEM;
 
@@ -2640,7 +2638,7 @@ static __devinit int wm5100_i2c_probe(struct i2c_client *i2c,
                ret = PTR_ERR(wm5100->regmap);
                dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
                        ret);
-               goto err_alloc;
+               goto err;
        }
 
        for (i = 0; i < ARRAY_SIZE(wm5100->fll); i++)
@@ -2743,6 +2741,26 @@ static __devinit int wm5100_i2c_probe(struct i2c_client *i2c,
                goto err_reset;
        }
 
+       wm5100_init_gpio(i2c);
+
+       for (i = 0; i < ARRAY_SIZE(wm5100->pdata.gpio_defaults); i++) {
+               if (!wm5100->pdata.gpio_defaults[i])
+                       continue;
+
+               regmap_write(wm5100->regmap, WM5100_GPIO_CTRL_1 + i,
+                            wm5100->pdata.gpio_defaults[i]);
+       }
+
+       for (i = 0; i < ARRAY_SIZE(wm5100->pdata.in_mode); i++) {
+               regmap_update_bits(wm5100->regmap, wm5100_mic_ctrl_reg[i],
+                                  WM5100_IN1_MODE_MASK |
+                                  WM5100_IN1_DMIC_SUP_MASK,
+                                  (wm5100->pdata.in_mode[i] <<
+                                   WM5100_IN1_MODE_SHIFT) |
+                                  (wm5100->pdata.dmic_sup[i] <<
+                                   WM5100_IN1_DMIC_SUP_SHIFT));
+       }
+
        ret = snd_soc_register_codec(&i2c->dev,
                                     &soc_codec_dev_wm5100, wm5100_dai,
                                     ARRAY_SIZE(wm5100_dai));
@@ -2754,6 +2772,7 @@ static __devinit int wm5100_i2c_probe(struct i2c_client *i2c,
        return ret;
 
 err_reset:
+       wm5100_free_gpio(i2c);
        if (wm5100->pdata.reset) {
                gpio_set_value_cansleep(wm5100->pdata.reset, 1);
                gpio_free(wm5100->pdata.reset);
@@ -2777,8 +2796,7 @@ err_core:
                            wm5100->core_supplies);
 err_regmap:
        regmap_exit(wm5100->regmap);
-err_alloc:
-       kfree(wm5100);
+err:
        return ret;
 }
 
@@ -2787,6 +2805,7 @@ static __devexit int wm5100_i2c_remove(struct i2c_client *client)
        struct wm5100_priv *wm5100 = i2c_get_clientdata(client);
 
        snd_soc_unregister_codec(&client->dev);
+       wm5100_free_gpio(client);
        if (wm5100->pdata.reset) {
                gpio_set_value_cansleep(wm5100->pdata.reset, 1);
                gpio_free(wm5100->pdata.reset);
@@ -2801,7 +2820,6 @@ static __devexit int wm5100_i2c_remove(struct i2c_client *client)
        regulator_bulk_free(ARRAY_SIZE(wm5100->core_supplies),
                            wm5100->core_supplies);
        regmap_exit(wm5100->regmap);
-       kfree(wm5100);
 
        return 0;
 }
This page took 0.032377 seconds and 5 git commands to generate.