Merge remote-tracking branches 'asoc/topic/wm8804', 'asoc/topic/wm8904', 'asoc/topic...
[linux-2.6-block.git] / sound / soc / codecs / wm8960.c
index 031a1ae71d943f2782d08f911d24c79d38d078ab..cf8fecf97f2c7ee06fff2741bea074bd32ceb7fc 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/pm.h>
+#include <linux/clk.h>
 #include <linux/i2c.h>
 #include <linux/slab.h>
 #include <sound/core.h>
@@ -117,6 +118,7 @@ static bool wm8960_volatile(struct device *dev, unsigned int reg)
 }
 
 struct wm8960_priv {
+       struct clk *mclk;
        struct regmap *regmap;
        int (*set_bias_level)(struct snd_soc_codec *,
                              enum snd_soc_bias_level level);
@@ -556,7 +558,7 @@ static struct {
        { 22050, 2 },
        { 24000, 2 },
        { 16000, 3 },
-       { 11250, 4 },
+       { 11025, 4 },
        { 12000, 4 },
        {  8000, 5 },
 };
@@ -618,14 +620,38 @@ static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
                                      enum snd_soc_bias_level level)
 {
        struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
+       int ret;
 
        switch (level) {
        case SND_SOC_BIAS_ON:
                break;
 
        case SND_SOC_BIAS_PREPARE:
-               /* Set VMID to 2x50k */
-               snd_soc_update_bits(codec, WM8960_POWER1, 0x180, 0x80);
+               switch (codec->dapm.bias_level) {
+               case SND_SOC_BIAS_STANDBY:
+                       if (!IS_ERR(wm8960->mclk)) {
+                               ret = clk_prepare_enable(wm8960->mclk);
+                               if (ret) {
+                                       dev_err(codec->dev,
+                                               "Failed to enable MCLK: %d\n",
+                                               ret);
+                                       return ret;
+                               }
+                       }
+
+                       /* Set VMID to 2x50k */
+                       snd_soc_update_bits(codec, WM8960_POWER1, 0x180, 0x80);
+                       break;
+
+               case SND_SOC_BIAS_ON:
+                       if (!IS_ERR(wm8960->mclk))
+                               clk_disable_unprepare(wm8960->mclk);
+                       break;
+
+               default:
+                       break;
+               }
+
                break;
 
        case SND_SOC_BIAS_STANDBY:
@@ -674,7 +700,7 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
                                         enum snd_soc_bias_level level)
 {
        struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
-       int reg;
+       int reg, ret;
 
        switch (level) {
        case SND_SOC_BIAS_ON:
@@ -715,9 +741,22 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
                                            WM8960_VREF, WM8960_VREF);
 
                        msleep(100);
+
+                       if (!IS_ERR(wm8960->mclk)) {
+                               ret = clk_prepare_enable(wm8960->mclk);
+                               if (ret) {
+                                       dev_err(codec->dev,
+                                               "Failed to enable MCLK: %d\n",
+                                               ret);
+                                       return ret;
+                               }
+                       }
                        break;
 
                case SND_SOC_BIAS_ON:
+                       if (!IS_ERR(wm8960->mclk))
+                               clk_disable_unprepare(wm8960->mclk);
+
                        /* Enable anti-pop mode */
                        snd_soc_update_bits(codec, WM8960_APOP1,
                                            WM8960_POBCTRL | WM8960_SOFT_ST |
@@ -1002,6 +1041,12 @@ static int wm8960_i2c_probe(struct i2c_client *i2c,
        if (wm8960 == NULL)
                return -ENOMEM;
 
+       wm8960->mclk = devm_clk_get(&i2c->dev, "mclk");
+       if (IS_ERR(wm8960->mclk)) {
+               if (PTR_ERR(wm8960->mclk) == -EPROBE_DEFER)
+                       return -EPROBE_DEFER;
+       }
+
        wm8960->regmap = devm_regmap_init_i2c(i2c, &wm8960_regmap);
        if (IS_ERR(wm8960->regmap))
                return PTR_ERR(wm8960->regmap);