ASoC: wm5100: Mark register cache as dirty when regulators are disabled
[deliverable/linux.git] / sound / soc / codecs / wm5100.c
index f37d67f4058b5254c0950e150212c895c4abf93b..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);
 
@@ -2569,6 +2574,13 @@ static int wm5100_remove(struct snd_soc_codec *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,
@@ -2577,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,
@@ -2599,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)
 {
@@ -2607,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;
 
@@ -2616,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++)
@@ -2730,7 +2752,7 @@ static __devinit int wm5100_i2c_probe(struct i2c_client *i2c,
        }
 
        for (i = 0; i < ARRAY_SIZE(wm5100->pdata.in_mode); i++) {
-               regmap_update_bits(wm5100->regmap, WM5100_IN1L_CONTROL,
+               regmap_update_bits(wm5100->regmap, wm5100_mic_ctrl_reg[i],
                                   WM5100_IN1_MODE_MASK |
                                   WM5100_IN1_DMIC_SUP_MASK,
                                   (wm5100->pdata.in_mode[i] <<
@@ -2774,8 +2796,7 @@ err_core:
                            wm5100->core_supplies);
 err_regmap:
        regmap_exit(wm5100->regmap);
-err_alloc:
-       kfree(wm5100);
+err:
        return ret;
 }
 
@@ -2799,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.032102 seconds and 5 git commands to generate.