Merge remote-tracking branch 'asoc/topic/wm8994' into asoc-next
[pandora-kernel.git] / sound / soc / codecs / wm8994.c
index b2b2b37..302f69a 100644 (file)
@@ -110,13 +110,13 @@ static const struct wm8958_micd_rate jackdet_rates[] = {
 static void wm8958_micd_set_rate(struct snd_soc_codec *codec)
 {
        struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+       struct wm8994 *control = wm8994->wm8994;
        int best, i, sysclk, val;
        bool idle;
        const struct wm8958_micd_rate *rates;
        int num_rates;
 
-       if (!(wm8994->pdata && wm8994->pdata->micd_rates) &&
-           wm8994->jack_cb != wm8958_default_micdet)
+       if (wm8994->jack_cb != wm8958_default_micdet)
                return;
 
        idle = !wm8994->jack_mic;
@@ -127,9 +127,9 @@ static void wm8958_micd_set_rate(struct snd_soc_codec *codec)
        else
                sysclk = wm8994->aifclk[0];
 
-       if (wm8994->pdata && wm8994->pdata->micd_rates) {
-               rates = wm8994->pdata->micd_rates;
-               num_rates = wm8994->pdata->num_micd_rates;
+       if (control->pdata.micd_rates) {
+               rates = control->pdata.micd_rates;
+               num_rates = control->pdata.num_micd_rates;
        } else if (wm8994->jackdet) {
                rates = jackdet_rates;
                num_rates = ARRAY_SIZE(jackdet_rates);
@@ -326,7 +326,8 @@ static int wm8994_put_drc_sw(struct snd_kcontrol *kcontrol,
 static void wm8994_set_drc(struct snd_soc_codec *codec, int drc)
 {
        struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
-       struct wm8994_pdata *pdata = wm8994->pdata;
+       struct wm8994 *control = wm8994->wm8994;
+       struct wm8994_pdata *pdata = &control->pdata;
        int base = wm8994_drc_base[drc];
        int cfg = wm8994->drc_cfg[drc];
        int save, i;
@@ -362,7 +363,8 @@ static int wm8994_put_drc_enum(struct snd_kcontrol *kcontrol,
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
        struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
-       struct wm8994_pdata *pdata = wm8994->pdata;
+       struct wm8994 *control = wm8994->wm8994;
+       struct wm8994_pdata *pdata = &control->pdata;
        int drc = wm8994_get_drc(kcontrol->id.name);
        int value = ucontrol->value.integer.value[0];
 
@@ -394,7 +396,8 @@ static int wm8994_get_drc_enum(struct snd_kcontrol *kcontrol,
 static void wm8994_set_retune_mobile(struct snd_soc_codec *codec, int block)
 {
        struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
-       struct wm8994_pdata *pdata = wm8994->pdata;
+       struct wm8994 *control = wm8994->wm8994;
+       struct wm8994_pdata *pdata = &control->pdata;
        int base = wm8994_retune_mobile_base[block];
        int iface, best, best_val, save, i, cfg;
 
@@ -465,7 +468,8 @@ static int wm8994_put_retune_mobile_enum(struct snd_kcontrol *kcontrol,
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
        struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
-       struct wm8994_pdata *pdata = wm8994->pdata;
+       struct wm8994 *control = wm8994->wm8994;
+       struct wm8994_pdata *pdata = &control->pdata;
        int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
        int value = ucontrol->value.integer.value[0];
 
@@ -862,7 +866,7 @@ static void vmid_reference(struct snd_soc_codec *codec)
                                            WM8994_BIAS_SRC |
                                            WM8994_STARTUP_BIAS_ENA |
                                            WM8994_VMID_BUF_ENA |
-                                           (0x3 << WM8994_VMID_RAMP_SHIFT));
+                                           (0x2 << WM8994_VMID_RAMP_SHIFT));
 
                        /* Main bias enable, VMID=2x40k */
                        snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
@@ -870,7 +874,7 @@ static void vmid_reference(struct snd_soc_codec *codec)
                                            WM8994_VMID_SEL_MASK,
                                            WM8994_BIAS_ENA | 0x2);
 
-                       msleep(50);
+                       msleep(300);
 
                        snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
                                            WM8994_VMID_RAMP_MASK |
@@ -939,16 +943,10 @@ static void vmid_dereference(struct snd_soc_codec *codec)
                                    WM8994_BIAS_SRC |
                                    WM8994_VMID_DISCH);
 
-               switch (wm8994->vmid_mode) {
-               case WM8994_VMID_FORCE:
-                       msleep(350);
-                       break;
-               default:
-                       break;
-               }
+               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+                                   WM8994_VMID_SEL_MASK, 0);
 
-               snd_soc_update_bits(codec, WM8994_ADDITIONAL_CONTROL,
-                                   WM8994_VROI, WM8994_VROI);
+               msleep(400);
 
                /* Active discharge */
                snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
@@ -957,17 +955,12 @@ static void vmid_dereference(struct snd_soc_codec *codec)
                                    WM8994_LINEOUT1_DISCH |
                                    WM8994_LINEOUT2_DISCH);
 
-               msleep(150);
-
                snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_3,
                                    WM8994_LINEOUT1N_ENA |
                                    WM8994_LINEOUT1P_ENA |
                                    WM8994_LINEOUT2N_ENA |
                                    WM8994_LINEOUT2P_ENA, 0);
 
-               snd_soc_update_bits(codec, WM8994_ADDITIONAL_CONTROL,
-                                   WM8994_VROI, 0);
-
                /* Switch off startup biases */
                snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
                                    WM8994_BIAS_SRC |
@@ -976,10 +969,7 @@ static void vmid_dereference(struct snd_soc_codec *codec)
                                    WM8994_VMID_RAMP_MASK, 0);
 
                snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
-                                   WM8994_BIAS_ENA | WM8994_VMID_SEL_MASK, 0);
-
-               snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
-                                   WM8994_VMID_RAMP_MASK, 0);
+                                   WM8994_VMID_SEL_MASK, 0);
        }
 
        pm_runtime_put(codec->dev);
@@ -2277,6 +2267,18 @@ out:
 
        configure_clock(codec);
 
+       /*
+        * If SYSCLK will be less than 50kHz adjust AIFnCLK dividers
+        * for detection.
+        */
+       if (max(wm8994->aifclk[0], wm8994->aifclk[1]) < 50000) {
+               dev_dbg(codec->dev, "Configuring AIFs for 128fs\n");
+               snd_soc_update_bits(codec, WM8994_AIF1_RATE,
+                                   WM8994_AIF1CLK_RATE_MASK, 0x1);
+               snd_soc_update_bits(codec, WM8994_AIF2_RATE,
+                                   WM8994_AIF2CLK_RATE_MASK, 0x1);
+       }
+
        return 0;
 }
 
@@ -2365,6 +2367,18 @@ static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
 
        configure_clock(codec);
 
+       /*
+        * If SYSCLK will be less than 50kHz adjust AIFnCLK dividers
+        * for detection.
+        */
+       if (max(wm8994->aifclk[0], wm8994->aifclk[1]) < 50000) {
+               dev_dbg(codec->dev, "Configuring AIFs for 128fs\n");
+               snd_soc_update_bits(codec, WM8994_AIF1_RATE,
+                                   WM8994_AIF1CLK_RATE_MASK, 0x1);
+               snd_soc_update_bits(codec, WM8994_AIF2_RATE,
+                                   WM8994_AIF2CLK_RATE_MASK, 0x1);
+       }
+
        return 0;
 }
 
@@ -3082,7 +3096,8 @@ static int wm8994_codec_resume(struct snd_soc_codec *codec)
 static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
 {
        struct snd_soc_codec *codec = wm8994->hubs.codec;
-       struct wm8994_pdata *pdata = wm8994->pdata;
+       struct wm8994 *control = wm8994->wm8994;
+       struct wm8994_pdata *pdata = &control->pdata;
        struct snd_kcontrol_new controls[] = {
                SOC_ENUM_EXT("AIF1.1 EQ Mode",
                             wm8994->retune_mobile_enum,
@@ -3149,7 +3164,8 @@ static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
 static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
 {
        struct snd_soc_codec *codec = wm8994->hubs.codec;
-       struct wm8994_pdata *pdata = wm8994->pdata;
+       struct wm8994 *control = wm8994->wm8994;
+       struct wm8994_pdata *pdata = &control->pdata;
        int ret, i;
 
        if (!pdata)
@@ -3451,7 +3467,7 @@ static void wm8958_default_micdet(u16 status, void *data)
 
                        mutex_unlock(&wm8994->accdet_lock);
 
-                       if (wm8994->pdata->jd_ext_cap)
+                       if (wm8994->wm8994->pdata.jd_ext_cap)
                                snd_soc_dapm_disable_pin(&codec->dapm,
                                                         "MICBIAS2");
                }
@@ -3486,11 +3502,48 @@ static void wm8958_default_micdet(u16 status, void *data)
        }
 }
 
+/* Deferred mic detection to allow for extra settling time */
+static void wm1811_mic_work(struct work_struct *work)
+{
+       struct wm8994_priv *wm8994 = container_of(work, struct wm8994_priv,
+                                                 mic_work.work);
+       struct wm8994 *control = wm8994->wm8994;
+       struct snd_soc_codec *codec = wm8994->hubs.codec;
+
+       pm_runtime_get_sync(codec->dev);
+
+       /* If required for an external cap force MICBIAS on */
+       if (control->pdata.jd_ext_cap) {
+               snd_soc_dapm_force_enable_pin(&codec->dapm,
+                                             "MICBIAS2");
+               snd_soc_dapm_sync(&codec->dapm);
+       }
+
+       mutex_lock(&wm8994->accdet_lock);
+
+       dev_dbg(codec->dev, "Starting mic detection\n");
+
+       /*
+        * Start off measument of microphone impedence to find out
+        * what's actually there.
+        */
+       wm8994->mic_detecting = true;
+       wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_MIC);
+
+       snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
+                           WM8958_MICD_ENA, WM8958_MICD_ENA);
+
+       mutex_unlock(&wm8994->accdet_lock);
+
+       pm_runtime_put(codec->dev);
+}
+
 static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
 {
        struct wm8994_priv *wm8994 = data;
+       struct wm8994 *control = wm8994->wm8994;
        struct snd_soc_codec *codec = wm8994->hubs.codec;
-       int reg;
+       int reg, delay;
        bool present;
 
        pm_runtime_get_sync(codec->dev);
@@ -3521,18 +3574,14 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
                snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
                                    WM1811_JACKDET_DB, 0);
 
-               /*
-                * Start off measument of microphone impedence to find
-                * out what's actually there.
-                */
-               wm8994->mic_detecting = true;
-               wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_MIC);
-
-               snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
-                                   WM8958_MICD_ENA, WM8958_MICD_ENA);
+               delay = control->pdata.micdet_delay;
+               schedule_delayed_work(&wm8994->mic_work,
+                                     msecs_to_jiffies(delay));
        } else {
                dev_dbg(codec->dev, "Jack not detected\n");
 
+               cancel_delayed_work_sync(&wm8994->mic_work);
+
                snd_soc_update_bits(codec, WM8958_MICBIAS2,
                                    WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
 
@@ -3549,14 +3598,9 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
 
        mutex_unlock(&wm8994->accdet_lock);
 
-       /* If required for an external cap force MICBIAS on */
-       if (wm8994->pdata->jd_ext_cap) {
-               if (present)
-                       snd_soc_dapm_force_enable_pin(&codec->dapm,
-                                                     "MICBIAS2");
-               else
-                       snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2");
-       }
+       /* Turn off MICBIAS if it was on for an external cap */
+       if (control->pdata.jd_ext_cap && !present)
+               snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2");
 
        if (present)
                snd_soc_jack_report(wm8994->micdet[0].jack,
@@ -3633,8 +3677,8 @@ int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
                wm8958_micd_set_rate(codec);
 
                /* Detect microphones and short circuits by default */
-               if (wm8994->pdata->micd_lvl_sel)
-                       micd_lvl_sel = wm8994->pdata->micd_lvl_sel;
+               if (control->pdata.micd_lvl_sel)
+                       micd_lvl_sel = control->pdata.micd_lvl_sel;
                else
                        micd_lvl_sel = 0x41;
 
@@ -3779,15 +3823,24 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
        snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
 
        mutex_init(&wm8994->accdet_lock);
-       INIT_DELAYED_WORK(&wm8994->mic_work, wm8994_mic_work);
        INIT_DELAYED_WORK(&wm8994->jackdet_bootstrap,
                          wm1811_jackdet_bootstrap);
 
+       switch (control->type) {
+       case WM8994:
+               INIT_DELAYED_WORK(&wm8994->mic_work, wm8994_mic_work);
+               break;
+       case WM1811:
+               INIT_DELAYED_WORK(&wm8994->mic_work, wm1811_mic_work);
+               break;
+       default:
+               break;
+       }
+
        for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++)
                init_completion(&wm8994->fll_locked[i]);
 
-       if (wm8994->pdata && wm8994->pdata->micdet_irq)
-               wm8994->micdet_irq = wm8994->pdata->micdet_irq;
+       wm8994->micdet_irq = control->pdata.micdet_irq;
 
        pm_runtime_enable(codec->dev);
        pm_runtime_idle(codec->dev);
@@ -3800,8 +3853,8 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
        switch (control->type) {
        case WM8994:
                /* Single ended line outputs should have VMID on. */
-               if (!wm8994->pdata->lineout1_diff ||
-                   !wm8994->pdata->lineout2_diff)
+               if (!control->pdata.lineout1_diff ||
+                   !control->pdata.lineout2_diff)
                        codec->dapm.idle_bias_off = 0;
 
                switch (wm8994->revision) {
@@ -3839,20 +3892,8 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
                wm8994->hubs.no_cache_dac_hp_direct = true;
                wm8994->fll_byp = true;
 
-               switch (control->cust_id) {
-               case 0:
-               case 2:
-                       wm8994->hubs.dcs_codes_l = -9;
-                       wm8994->hubs.dcs_codes_r = -7;
-                       break;
-               case 1:
-               case 3:
-                       wm8994->hubs.dcs_codes_l = -8;
-                       wm8994->hubs.dcs_codes_r = -7;
-                       break;
-               default:
-                       break;
-               }
+               wm8994->hubs.dcs_codes_l = -9;
+               wm8994->hubs.dcs_codes_r = -7;
 
                snd_soc_update_bits(codec, WM8994_ANALOGUE_HP_1,
                                    WM1811_HPOUT1_ATTN, WM1811_HPOUT1_ATTN);
@@ -4236,7 +4277,6 @@ static int __devinit wm8994_probe(struct platform_device *pdev)
        platform_set_drvdata(pdev, wm8994);
 
        wm8994->wm8994 = dev_get_drvdata(pdev->dev.parent);
-       wm8994->pdata = dev_get_platdata(pdev->dev.parent);
 
        return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm8994,
                        wm8994_dai, ARRAY_SIZE(wm8994_dai));