Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / sound / soc / codecs / wm8994.c
index aa94ca1..2de12eb 100644 (file)
@@ -686,14 +686,23 @@ static void wm1811_jackdet_set_mode(struct snd_soc_codec *codec, u16 mode)
 {
        struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
 
+       if (!wm8994->jackdet || !wm8994->jack_cb)
+               return;
+
        if (wm8994->active_refcount)
                mode = WM1811_JACKDET_MODE_AUDIO;
 
+       if (mode == wm8994->jackdet_mode)
+               return;
+
+       wm8994->jackdet_mode = mode;
+
+       /* Always use audio mode to detect while the system is active */
+       if (mode != WM1811_JACKDET_MODE_NONE)
+               mode = WM1811_JACKDET_MODE_AUDIO;
+
        snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
                            WM1811_JACKDET_MODE_MASK, mode);
-
-       if (mode == WM1811_JACKDET_MODE_MIC)
-               msleep(2);
 }
 
 static void active_reference(struct snd_soc_codec *codec)
@@ -707,15 +716,8 @@ static void active_reference(struct snd_soc_codec *codec)
        dev_dbg(codec->dev, "Active refcount incremented, now %d\n",
                wm8994->active_refcount);
 
-       if (wm8994->active_refcount == 1) {
-               /* If we're using jack detection go into audio mode */
-               if (wm8994->jackdet && wm8994->jack_cb) {
-                       snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
-                                           WM1811_JACKDET_MODE_MASK,
-                                           WM1811_JACKDET_MODE_AUDIO);
-                       msleep(2);
-               }
-       }
+       /* If we're using jack detection go into audio mode */
+       wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_AUDIO);
 
        mutex_unlock(&wm8994->accdet_lock);
 }
@@ -734,16 +736,12 @@ static void active_dereference(struct snd_soc_codec *codec)
 
        if (wm8994->active_refcount == 0) {
                /* Go into appropriate detection only mode */
-               if (wm8994->jackdet && wm8994->jack_cb) {
-                       if (wm8994->jack_mic || wm8994->mic_detecting)
-                               mode = WM1811_JACKDET_MODE_MIC;
-                       else
-                               mode = WM1811_JACKDET_MODE_JACK;
+               if (wm8994->jack_mic || wm8994->mic_detecting)
+                       mode = WM1811_JACKDET_MODE_MIC;
+               else
+                       mode = WM1811_JACKDET_MODE_JACK;
 
-                       snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
-                                           WM1811_JACKDET_MODE_MASK,
-                                           mode);
-               }
+               wm1811_jackdet_set_mode(codec, mode);
        }
 
        mutex_unlock(&wm8994->accdet_lock);
@@ -779,36 +777,68 @@ static void vmid_reference(struct snd_soc_codec *codec)
 
        if (wm8994->vmid_refcount == 1) {
                snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
-                                   WM8994_LINEOUT_VMID_BUF_ENA |
                                    WM8994_LINEOUT1_DISCH |
-                                   WM8994_LINEOUT2_DISCH,
-                                   WM8994_LINEOUT_VMID_BUF_ENA);
-
-               /* Startup bias, VMID ramp & buffer */
-               snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
-                                   WM8994_BIAS_SRC |
-                                   WM8994_VMID_DISCH |
-                                   WM8994_STARTUP_BIAS_ENA |
-                                   WM8994_VMID_BUF_ENA |
-                                   WM8994_VMID_RAMP_MASK,
-                                   WM8994_BIAS_SRC |
-                                   WM8994_STARTUP_BIAS_ENA |
-                                   WM8994_VMID_BUF_ENA |
-                                   (0x3 << WM8994_VMID_RAMP_SHIFT));
+                                   WM8994_LINEOUT2_DISCH, 0);
 
                wm_hubs_vmid_ena(codec);
 
-               /* Main bias enable, VMID=2x40k */
-               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
-                                   WM8994_BIAS_ENA |
-                                   WM8994_VMID_SEL_MASK,
-                                   WM8994_BIAS_ENA | 0x2);
+               switch (wm8994->vmid_mode) {
+               default:
+                       WARN_ON(0 == "Invalid VMID mode");
+               case WM8994_VMID_NORMAL:
+                       /* Startup bias, VMID ramp & buffer */
+                       snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
+                                           WM8994_BIAS_SRC |
+                                           WM8994_VMID_DISCH |
+                                           WM8994_STARTUP_BIAS_ENA |
+                                           WM8994_VMID_BUF_ENA |
+                                           WM8994_VMID_RAMP_MASK,
+                                           WM8994_BIAS_SRC |
+                                           WM8994_STARTUP_BIAS_ENA |
+                                           WM8994_VMID_BUF_ENA |
+                                           (0x3 << WM8994_VMID_RAMP_SHIFT));
+
+                       /* Main bias enable, VMID=2x40k */
+                       snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+                                           WM8994_BIAS_ENA |
+                                           WM8994_VMID_SEL_MASK,
+                                           WM8994_BIAS_ENA | 0x2);
+
+                       msleep(50);
 
-               msleep(50);
+                       snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
+                                           WM8994_VMID_RAMP_MASK |
+                                           WM8994_BIAS_SRC,
+                                           0);
+                       break;
 
-               snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
-                                   WM8994_VMID_RAMP_MASK | WM8994_BIAS_SRC,
-                                   0);
+               case WM8994_VMID_FORCE:
+                       /* Startup bias, slow VMID ramp & buffer */
+                       snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
+                                           WM8994_BIAS_SRC |
+                                           WM8994_VMID_DISCH |
+                                           WM8994_STARTUP_BIAS_ENA |
+                                           WM8994_VMID_BUF_ENA |
+                                           WM8994_VMID_RAMP_MASK,
+                                           WM8994_BIAS_SRC |
+                                           WM8994_STARTUP_BIAS_ENA |
+                                           WM8994_VMID_BUF_ENA |
+                                           (0x2 << WM8994_VMID_RAMP_SHIFT));
+
+                       /* Main bias enable, VMID=2x40k */
+                       snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
+                                           WM8994_BIAS_ENA |
+                                           WM8994_VMID_SEL_MASK,
+                                           WM8994_BIAS_ENA | 0x2);
+
+                       msleep(400);
+
+                       snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
+                                           WM8994_VMID_RAMP_MASK |
+                                           WM8994_BIAS_SRC,
+                                           0);
+                       break;
+               }
        }
 }
 
@@ -822,30 +852,55 @@ static void vmid_dereference(struct snd_soc_codec *codec)
                wm8994->vmid_refcount);
 
        if (wm8994->vmid_refcount == 0) {
-               /* Switch over to startup biases */
+               if (wm8994->hubs.lineout1_se)
+                       snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_3,
+                                           WM8994_LINEOUT1N_ENA |
+                                           WM8994_LINEOUT1P_ENA,
+                                           WM8994_LINEOUT1N_ENA |
+                                           WM8994_LINEOUT1P_ENA);
+
+               if (wm8994->hubs.lineout2_se)
+                       snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_3,
+                                           WM8994_LINEOUT2N_ENA |
+                                           WM8994_LINEOUT2P_ENA,
+                                           WM8994_LINEOUT2N_ENA |
+                                           WM8994_LINEOUT2P_ENA);
+
+               /* Start discharging VMID */
                snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
                                    WM8994_BIAS_SRC |
-                                   WM8994_STARTUP_BIAS_ENA |
-                                   WM8994_VMID_BUF_ENA |
-                                   WM8994_VMID_RAMP_MASK,
+                                   WM8994_VMID_DISCH,
                                    WM8994_BIAS_SRC |
-                                   WM8994_STARTUP_BIAS_ENA |
-                                   WM8994_VMID_BUF_ENA |
-                                   (1 << WM8994_VMID_RAMP_SHIFT));
+                                   WM8994_VMID_DISCH);
 
-               /* Disable main biases */
-               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
-                                   WM8994_BIAS_ENA |
-                                   WM8994_VMID_SEL_MASK, 0);
+               switch (wm8994->vmid_mode) {
+               case WM8994_VMID_FORCE:
+                       msleep(350);
+                       break;
+               default:
+                       break;
+               }
+
+               snd_soc_update_bits(codec, WM8994_ADDITIONAL_CONTROL,
+                                   WM8994_VROI, WM8994_VROI);
 
-               /* Discharge line */
+               /* Active discharge */
                snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
                                    WM8994_LINEOUT1_DISCH |
                                    WM8994_LINEOUT2_DISCH,
                                    WM8994_LINEOUT1_DISCH |
                                    WM8994_LINEOUT2_DISCH);
 
-               msleep(5);
+               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,
@@ -853,6 +908,12 @@ static void vmid_dereference(struct snd_soc_codec *codec)
                                    WM8994_STARTUP_BIAS_ENA |
                                    WM8994_VMID_BUF_ENA |
                                    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);
        }
 
        pm_runtime_put(codec->dev);
@@ -939,61 +1000,170 @@ static void wm8994_update_class_w(struct snd_soc_codec *codec)
        }
 }
 
-static int late_enable_ev(struct snd_soc_dapm_widget *w,
-                         struct snd_kcontrol *kcontrol, int event)
+static int aif1clk_ev(struct snd_soc_dapm_widget *w,
+                     struct snd_kcontrol *kcontrol, int event)
 {
        struct snd_soc_codec *codec = w->codec;
-       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+       struct wm8994 *control = codec->control_data;
+       int mask = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA;
+       int dac;
+       int adc;
+       int val;
+
+       switch (control->type) {
+       case WM8994:
+       case WM8958:
+               mask |= WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA;
+               break;
+       default:
+               break;
+       }
 
        switch (event) {
        case SND_SOC_DAPM_PRE_PMU:
-               if (wm8994->aif1clk_enable) {
-                       snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
-                                           WM8994_AIF1CLK_ENA_MASK,
-                                           WM8994_AIF1CLK_ENA);
-                       wm8994->aif1clk_enable = 0;
-               }
-               if (wm8994->aif2clk_enable) {
-                       snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
-                                           WM8994_AIF2CLK_ENA_MASK,
-                                           WM8994_AIF2CLK_ENA);
-                       wm8994->aif2clk_enable = 0;
-               }
+               val = snd_soc_read(codec, WM8994_AIF1_CONTROL_1);
+               if ((val & WM8994_AIF1ADCL_SRC) &&
+                   (val & WM8994_AIF1ADCR_SRC))
+                       adc = WM8994_AIF1ADC1R_ENA | WM8994_AIF1ADC2R_ENA;
+               else if (!(val & WM8994_AIF1ADCL_SRC) &&
+                        !(val & WM8994_AIF1ADCR_SRC))
+                       adc = WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC2L_ENA;
+               else
+                       adc = WM8994_AIF1ADC1R_ENA | WM8994_AIF1ADC2R_ENA |
+                               WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC2L_ENA;
+
+               val = snd_soc_read(codec, WM8994_AIF1_CONTROL_2);
+               if ((val & WM8994_AIF1DACL_SRC) &&
+                   (val & WM8994_AIF1DACR_SRC))
+                       dac = WM8994_AIF1DAC1R_ENA | WM8994_AIF1DAC2R_ENA;
+               else if (!(val & WM8994_AIF1DACL_SRC) &&
+                        !(val & WM8994_AIF1DACR_SRC))
+                       dac = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC2L_ENA;
+               else
+                       dac = WM8994_AIF1DAC1R_ENA | WM8994_AIF1DAC2R_ENA |
+                               WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC2L_ENA;
+
+               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
+                                   mask, adc);
+               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
+                                   mask, dac);
+               snd_soc_update_bits(codec, WM8994_CLOCKING_1,
+                                   WM8994_AIF1DSPCLK_ENA |
+                                   WM8994_SYSDSPCLK_ENA,
+                                   WM8994_AIF1DSPCLK_ENA |
+                                   WM8994_SYSDSPCLK_ENA);
+               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4, mask,
+                                   WM8994_AIF1ADC1R_ENA |
+                                   WM8994_AIF1ADC1L_ENA |
+                                   WM8994_AIF1ADC2R_ENA |
+                                   WM8994_AIF1ADC2L_ENA);
+               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5, mask,
+                                   WM8994_AIF1DAC1R_ENA |
+                                   WM8994_AIF1DAC1L_ENA |
+                                   WM8994_AIF1DAC2R_ENA |
+                                   WM8994_AIF1DAC2L_ENA);
                break;
-       }
 
-       /* We may also have postponed startup of DSP, handle that. */
-       wm8958_aif_ev(w, kcontrol, event);
+       case SND_SOC_DAPM_PRE_PMD:
+       case SND_SOC_DAPM_POST_PMD:
+               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
+                                   mask, 0);
+               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
+                                   mask, 0);
+
+               val = snd_soc_read(codec, WM8994_CLOCKING_1);
+               if (val & WM8994_AIF2DSPCLK_ENA)
+                       val = WM8994_SYSDSPCLK_ENA;
+               else
+                       val = 0;
+               snd_soc_update_bits(codec, WM8994_CLOCKING_1,
+                                   WM8994_SYSDSPCLK_ENA |
+                                   WM8994_AIF1DSPCLK_ENA, val);
+               break;
+       }
 
        return 0;
 }
 
-static int late_disable_ev(struct snd_soc_dapm_widget *w,
-                          struct snd_kcontrol *kcontrol, int event)
+static int aif2clk_ev(struct snd_soc_dapm_widget *w,
+                     struct snd_kcontrol *kcontrol, int event)
 {
        struct snd_soc_codec *codec = w->codec;
-       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+       int dac;
+       int adc;
+       int val;
 
        switch (event) {
+       case SND_SOC_DAPM_PRE_PMU:
+               val = snd_soc_read(codec, WM8994_AIF2_CONTROL_1);
+               if ((val & WM8994_AIF2ADCL_SRC) &&
+                   (val & WM8994_AIF2ADCR_SRC))
+                       adc = WM8994_AIF2ADCR_ENA;
+               else if (!(val & WM8994_AIF2ADCL_SRC) &&
+                        !(val & WM8994_AIF2ADCR_SRC))
+                       adc = WM8994_AIF2ADCL_ENA;
+               else
+                       adc = WM8994_AIF2ADCL_ENA | WM8994_AIF2ADCR_ENA;
+
+
+               val = snd_soc_read(codec, WM8994_AIF2_CONTROL_2);
+               if ((val & WM8994_AIF2DACL_SRC) &&
+                   (val & WM8994_AIF2DACR_SRC))
+                       dac = WM8994_AIF2DACR_ENA;
+               else if (!(val & WM8994_AIF2DACL_SRC) &&
+                        !(val & WM8994_AIF2DACR_SRC))
+                       dac = WM8994_AIF2DACL_ENA;
+               else
+                       dac = WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA;
+
+               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
+                                   WM8994_AIF2ADCL_ENA |
+                                   WM8994_AIF2ADCR_ENA, adc);
+               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
+                                   WM8994_AIF2DACL_ENA |
+                                   WM8994_AIF2DACR_ENA, dac);
+               snd_soc_update_bits(codec, WM8994_CLOCKING_1,
+                                   WM8994_AIF2DSPCLK_ENA |
+                                   WM8994_SYSDSPCLK_ENA,
+                                   WM8994_AIF2DSPCLK_ENA |
+                                   WM8994_SYSDSPCLK_ENA);
+               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
+                                   WM8994_AIF2ADCL_ENA |
+                                   WM8994_AIF2ADCR_ENA,
+                                   WM8994_AIF2ADCL_ENA |
+                                   WM8994_AIF2ADCR_ENA);
+               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
+                                   WM8994_AIF2DACL_ENA |
+                                   WM8994_AIF2DACR_ENA,
+                                   WM8994_AIF2DACL_ENA |
+                                   WM8994_AIF2DACR_ENA);
+               break;
+
+       case SND_SOC_DAPM_PRE_PMD:
        case SND_SOC_DAPM_POST_PMD:
-               if (wm8994->aif1clk_disable) {
-                       snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
-                                           WM8994_AIF1CLK_ENA_MASK, 0);
-                       wm8994->aif1clk_disable = 0;
-               }
-               if (wm8994->aif2clk_disable) {
-                       snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
-                                           WM8994_AIF2CLK_ENA_MASK, 0);
-                       wm8994->aif2clk_disable = 0;
-               }
+               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
+                                   WM8994_AIF2DACL_ENA |
+                                   WM8994_AIF2DACR_ENA, 0);
+               snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_4,
+                                   WM8994_AIF2ADCL_ENA |
+                                   WM8994_AIF2ADCR_ENA, 0);
+
+               val = snd_soc_read(codec, WM8994_CLOCKING_1);
+               if (val & WM8994_AIF1DSPCLK_ENA)
+                       val = WM8994_SYSDSPCLK_ENA;
+               else
+                       val = 0;
+               snd_soc_update_bits(codec, WM8994_CLOCKING_1,
+                                   WM8994_SYSDSPCLK_ENA |
+                                   WM8994_AIF2DSPCLK_ENA, val);
                break;
        }
 
        return 0;
 }
 
-static int aif1clk_ev(struct snd_soc_dapm_widget *w,
-                     struct snd_kcontrol *kcontrol, int event)
+static int aif1clk_late_ev(struct snd_soc_dapm_widget *w,
+                          struct snd_kcontrol *kcontrol, int event)
 {
        struct snd_soc_codec *codec = w->codec;
        struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
@@ -1010,8 +1180,8 @@ static int aif1clk_ev(struct snd_soc_dapm_widget *w,
        return 0;
 }
 
-static int aif2clk_ev(struct snd_soc_dapm_widget *w,
-                     struct snd_kcontrol *kcontrol, int event)
+static int aif2clk_late_ev(struct snd_soc_dapm_widget *w,
+                          struct snd_kcontrol *kcontrol, int event)
 {
        struct snd_soc_codec *codec = w->codec;
        struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
@@ -1028,6 +1198,63 @@ static int aif2clk_ev(struct snd_soc_dapm_widget *w,
        return 0;
 }
 
+static int late_enable_ev(struct snd_soc_dapm_widget *w,
+                         struct snd_kcontrol *kcontrol, int event)
+{
+       struct snd_soc_codec *codec = w->codec;
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+       switch (event) {
+       case SND_SOC_DAPM_PRE_PMU:
+               if (wm8994->aif1clk_enable) {
+                       aif1clk_ev(w, kcontrol, event);
+                       snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
+                                           WM8994_AIF1CLK_ENA_MASK,
+                                           WM8994_AIF1CLK_ENA);
+                       wm8994->aif1clk_enable = 0;
+               }
+               if (wm8994->aif2clk_enable) {
+                       aif2clk_ev(w, kcontrol, event);
+                       snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
+                                           WM8994_AIF2CLK_ENA_MASK,
+                                           WM8994_AIF2CLK_ENA);
+                       wm8994->aif2clk_enable = 0;
+               }
+               break;
+       }
+
+       /* We may also have postponed startup of DSP, handle that. */
+       wm8958_aif_ev(w, kcontrol, event);
+
+       return 0;
+}
+
+static int late_disable_ev(struct snd_soc_dapm_widget *w,
+                          struct snd_kcontrol *kcontrol, int event)
+{
+       struct snd_soc_codec *codec = w->codec;
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+       switch (event) {
+       case SND_SOC_DAPM_POST_PMD:
+               if (wm8994->aif1clk_disable) {
+                       snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
+                                           WM8994_AIF1CLK_ENA_MASK, 0);
+                       aif1clk_ev(w, kcontrol, event);
+                       wm8994->aif1clk_disable = 0;
+               }
+               if (wm8994->aif2clk_disable) {
+                       snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
+                                           WM8994_AIF2CLK_ENA_MASK, 0);
+                       aif2clk_ev(w, kcontrol, event);
+                       wm8994->aif2clk_disable = 0;
+               }
+               break;
+       }
+
+       return 0;
+}
+
 static int adc_mux_ev(struct snd_soc_dapm_widget *w,
                      struct snd_kcontrol *kcontrol, int event)
 {
@@ -1324,9 +1551,9 @@ static const struct snd_kcontrol_new aif2dacr_src_mux =
        SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum);
 
 static const struct snd_soc_dapm_widget wm8994_lateclk_revd_widgets[] = {
-SND_SOC_DAPM_SUPPLY("AIF1CLK", SND_SOC_NOPM, 0, 0, aif1clk_ev,
+SND_SOC_DAPM_SUPPLY("AIF1CLK", SND_SOC_NOPM, 0, 0, aif1clk_late_ev,
        SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
-SND_SOC_DAPM_SUPPLY("AIF2CLK", SND_SOC_NOPM, 0, 0, aif2clk_ev,
+SND_SOC_DAPM_SUPPLY("AIF2CLK", SND_SOC_NOPM, 0, 0, aif2clk_late_ev,
        SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
 
 SND_SOC_DAPM_PGA_E("Late DAC1L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
@@ -1355,8 +1582,10 @@ SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev)
 };
 
 static const struct snd_soc_dapm_widget wm8994_lateclk_widgets[] = {
-SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8994_AIF1_CLOCKING_1, 0, 0, NULL, 0),
-SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8994_AIF2_CLOCKING_1, 0, 0, NULL, 0),
+SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8994_AIF1_CLOCKING_1, 0, 0, aif1clk_ev,
+                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
+SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8994_AIF2_CLOCKING_1, 0, 0, aif2clk_ev,
+                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
 SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0),
 SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
                   left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)),
@@ -1409,30 +1638,30 @@ SND_SOC_DAPM_SUPPLY("VMID", SND_SOC_NOPM, 0, 0, vmid_event,
 SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
                    SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
 
-SND_SOC_DAPM_SUPPLY("DSP1CLK", WM8994_CLOCKING_1, 3, 0, NULL, 0),
-SND_SOC_DAPM_SUPPLY("DSP2CLK", WM8994_CLOCKING_1, 2, 0, NULL, 0),
-SND_SOC_DAPM_SUPPLY("DSPINTCLK", WM8994_CLOCKING_1, 1, 0, NULL, 0),
+SND_SOC_DAPM_SUPPLY("DSP1CLK", SND_SOC_NOPM, 3, 0, NULL, 0),
+SND_SOC_DAPM_SUPPLY("DSP2CLK", SND_SOC_NOPM, 2, 0, NULL, 0),
+SND_SOC_DAPM_SUPPLY("DSPINTCLK", SND_SOC_NOPM, 1, 0, NULL, 0),
 
 SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", NULL,
-                    0, WM8994_POWER_MANAGEMENT_4, 9, 0),
+                    0, SND_SOC_NOPM, 9, 0),
 SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", NULL,
-                    0, WM8994_POWER_MANAGEMENT_4, 8, 0),
+                    0, SND_SOC_NOPM, 8, 0),
 SND_SOC_DAPM_AIF_IN_E("AIF1DAC1L", NULL, 0,
-                     WM8994_POWER_MANAGEMENT_5, 9, 0, wm8958_aif_ev,
+                     SND_SOC_NOPM, 9, 0, wm8958_aif_ev,
                      SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
 SND_SOC_DAPM_AIF_IN_E("AIF1DAC1R", NULL, 0,
-                     WM8994_POWER_MANAGEMENT_5, 8, 0, wm8958_aif_ev,
+                     SND_SOC_NOPM, 8, 0, wm8958_aif_ev,
                      SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
 
 SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", NULL,
-                    0, WM8994_POWER_MANAGEMENT_4, 11, 0),
+                    0, SND_SOC_NOPM, 11, 0),
 SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", NULL,
-                    0, WM8994_POWER_MANAGEMENT_4, 10, 0),
+                    0, SND_SOC_NOPM, 10, 0),
 SND_SOC_DAPM_AIF_IN_E("AIF1DAC2L", NULL, 0,
-                     WM8994_POWER_MANAGEMENT_5, 11, 0, wm8958_aif_ev,
+                     SND_SOC_NOPM, 11, 0, wm8958_aif_ev,
                      SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
 SND_SOC_DAPM_AIF_IN_E("AIF1DAC2R", NULL, 0,
-                     WM8994_POWER_MANAGEMENT_5, 10, 0, wm8958_aif_ev,
+                     SND_SOC_NOPM, 10, 0, wm8958_aif_ev,
                      SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
 
 SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
@@ -1459,27 +1688,27 @@ SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0,
                   dac1r_mix, ARRAY_SIZE(dac1r_mix)),
 
 SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL, 0,
-                    WM8994_POWER_MANAGEMENT_4, 13, 0),
+                    SND_SOC_NOPM, 13, 0),
 SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL, 0,
-                    WM8994_POWER_MANAGEMENT_4, 12, 0),
+                    SND_SOC_NOPM, 12, 0),
 SND_SOC_DAPM_AIF_IN_E("AIF2DACL", NULL, 0,
-                     WM8994_POWER_MANAGEMENT_5, 13, 0, wm8958_aif_ev,
+                     SND_SOC_NOPM, 13, 0, wm8958_aif_ev,
                      SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
 SND_SOC_DAPM_AIF_IN_E("AIF2DACR", NULL, 0,
-                     WM8994_POWER_MANAGEMENT_5, 12, 0, wm8958_aif_ev,
+                     SND_SOC_NOPM, 12, 0, wm8958_aif_ev,
                      SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
 
-SND_SOC_DAPM_AIF_IN("AIF1DACDAT", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
-SND_SOC_DAPM_AIF_IN("AIF2DACDAT", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0),
-SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0),
-SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", "AIF2 Capture", 0, SND_SOC_NOPM, 0, 0),
+SND_SOC_DAPM_AIF_IN("AIF1DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
+SND_SOC_DAPM_AIF_IN("AIF2DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
+SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
+SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT",  NULL, 0, SND_SOC_NOPM, 0, 0),
 
 SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM, 0, 0, &aif1dac_mux),
 SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux),
 SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux),
 
-SND_SOC_DAPM_AIF_IN("AIF3DACDAT", "AIF3 Playback", 0, SND_SOC_NOPM, 0, 0),
-SND_SOC_DAPM_AIF_OUT("AIF3ADCDAT", "AIF3 Capture", 0, SND_SOC_NOPM, 0, 0),
+SND_SOC_DAPM_AIF_IN("AIF3DACDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
+SND_SOC_DAPM_AIF_OUT("AIF3ADCDAT", NULL, 0, SND_SOC_NOPM, 0, 0),
 
 SND_SOC_DAPM_SUPPLY("TOCLK", WM8994_CLOCKING_1, 4, 0, NULL, 0),
 
@@ -1594,6 +1823,14 @@ static const struct snd_soc_dapm_route intercon[] = {
 
        { "TOCLK", NULL, "CLK_SYS" },
 
+       { "AIF1DACDAT", NULL, "AIF1 Playback" },
+       { "AIF2DACDAT", NULL, "AIF2 Playback" },
+       { "AIF3DACDAT", NULL, "AIF3 Playback" },
+
+       { "AIF1 Capture", NULL, "AIF1ADCDAT" },
+       { "AIF2 Capture", NULL, "AIF2ADCDAT" },
+       { "AIF3 Capture", NULL, "AIF3ADCDAT" },
+
        /* AIF1 outputs */
        { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
        { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
@@ -1906,7 +2143,8 @@ static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
                            WM8994_FLL1_OUTDIV_MASK |
                            WM8994_FLL1_FRATIO_MASK, reg);
 
-       snd_soc_write(codec, WM8994_FLL1_CONTROL_3 + reg_offset, fll.k);
+       snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_3 + reg_offset,
+                           WM8994_FLL1_K_MASK, fll.k);
 
        snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_4 + reg_offset,
                            WM8994_FLL1_N_MASK,
@@ -2111,26 +2349,9 @@ static int wm8994_set_bias_level(struct snd_soc_codec *codec,
        case SND_SOC_BIAS_STANDBY:
                if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
                        switch (control->type) {
-                       case WM8994:
-                               if (wm8994->revision < 4) {
-                                       /* Tweak DC servo and DSP
-                                        * configuration for improved
-                                        * performance. */
-                                       snd_soc_write(codec, 0x102, 0x3);
-                                       snd_soc_write(codec, 0x56, 0x3);
-                                       snd_soc_write(codec, 0x817, 0);
-                                       snd_soc_write(codec, 0x102, 0);
-                               }
-                               break;
-
                        case WM8958:
                                if (wm8994->revision == 0) {
                                        /* Optimise performance for rev A */
-                                       snd_soc_write(codec, 0x102, 0x3);
-                                       snd_soc_write(codec, 0xcb, 0x81);
-                                       snd_soc_write(codec, 0x817, 0);
-                                       snd_soc_write(codec, 0x102, 0);
-
                                        snd_soc_update_bits(codec,
                                                            WM8958_CHARGE_PUMP_2,
                                                            WM8958_CP_DISCH,
@@ -2138,13 +2359,7 @@ static int wm8994_set_bias_level(struct snd_soc_codec *codec,
                                }
                                break;
 
-                       case WM1811:
-                               if (wm8994->revision < 2) {
-                                       snd_soc_write(codec, 0x102, 0x3);
-                                       snd_soc_write(codec, 0x5d, 0x7e);
-                                       snd_soc_write(codec, 0x5e, 0x0);
-                                       snd_soc_write(codec, 0x102, 0x0);
-                               }
+                       default:
                                break;
                        }
 
@@ -2186,6 +2401,55 @@ static int wm8994_set_bias_level(struct snd_soc_codec *codec,
        return 0;
 }
 
+int wm8994_vmid_mode(struct snd_soc_codec *codec, enum wm8994_vmid_mode mode)
+{
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+
+       switch (mode) {
+       case WM8994_VMID_NORMAL:
+               if (wm8994->hubs.lineout1_se) {
+                       snd_soc_dapm_disable_pin(&codec->dapm,
+                                                "LINEOUT1N Driver");
+                       snd_soc_dapm_disable_pin(&codec->dapm,
+                                                "LINEOUT1P Driver");
+               }
+               if (wm8994->hubs.lineout2_se) {
+                       snd_soc_dapm_disable_pin(&codec->dapm,
+                                                "LINEOUT2N Driver");
+                       snd_soc_dapm_disable_pin(&codec->dapm,
+                                                "LINEOUT2P Driver");
+               }
+
+               /* Do the sync with the old mode to allow it to clean up */
+               snd_soc_dapm_sync(&codec->dapm);
+               wm8994->vmid_mode = mode;
+               break;
+
+       case WM8994_VMID_FORCE:
+               if (wm8994->hubs.lineout1_se) {
+                       snd_soc_dapm_force_enable_pin(&codec->dapm,
+                                                     "LINEOUT1N Driver");
+                       snd_soc_dapm_force_enable_pin(&codec->dapm,
+                                                     "LINEOUT1P Driver");
+               }
+               if (wm8994->hubs.lineout2_se) {
+                       snd_soc_dapm_force_enable_pin(&codec->dapm,
+                                                     "LINEOUT2N Driver");
+                       snd_soc_dapm_force_enable_pin(&codec->dapm,
+                                                     "LINEOUT2P Driver");
+               }
+
+               wm8994->vmid_mode = mode;
+               snd_soc_dapm_sync(&codec->dapm);
+               break;
+
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 {
        struct snd_soc_codec *codec = dai->codec;
@@ -2725,7 +2989,7 @@ static struct snd_soc_dai_driver wm8994_dai[] = {
 };
 
 #ifdef CONFIG_PM
-static int wm8994_suspend(struct snd_soc_codec *codec)
+static int wm8994_codec_suspend(struct snd_soc_codec *codec)
 {
        struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
        struct wm8994 *control = wm8994->wm8994;
@@ -2759,7 +3023,7 @@ static int wm8994_suspend(struct snd_soc_codec *codec)
        return 0;
 }
 
-static int wm8994_resume(struct snd_soc_codec *codec)
+static int wm8994_codec_resume(struct snd_soc_codec *codec)
 {
        struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
        struct wm8994 *control = wm8994->wm8994;
@@ -2808,6 +3072,7 @@ static int wm8994_resume(struct snd_soc_codec *codec)
                                            WM1811_JACKDET_MODE_JACK);
                        break;
                }
+               break;
        case WM8958:
                if (wm8994->jack_cb)
                        snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
@@ -2818,8 +3083,8 @@ static int wm8994_resume(struct snd_soc_codec *codec)
        return 0;
 }
 #else
-#define wm8994_suspend NULL
-#define wm8994_resume NULL
+#define wm8994_codec_suspend NULL
+#define wm8994_codec_resume NULL
 #endif
 
 static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
@@ -3155,11 +3420,23 @@ static void wm8958_default_micdet(u16 status, void *data)
 
                /* If we have jackdet that will detect removal */
                if (wm8994->jackdet) {
+                       mutex_lock(&wm8994->accdet_lock);
+
                        snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
                                            WM8958_MICD_ENA, 0);
 
                        wm1811_jackdet_set_mode(codec,
                                                WM1811_JACKDET_MODE_JACK);
+
+                       mutex_unlock(&wm8994->accdet_lock);
+
+                       if (wm8994->pdata->jd_ext_cap) {
+                               mutex_lock(&codec->mutex);
+                               snd_soc_dapm_disable_pin(&codec->dapm,
+                                                        "MICBIAS2");
+                               snd_soc_dapm_sync(&codec->dapm);
+                               mutex_unlock(&codec->mutex);
+                       }
                }
        }
 
@@ -3194,6 +3471,7 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
        struct wm8994_priv *wm8994 = data;
        struct snd_soc_codec *codec = wm8994->codec;
        int reg;
+       bool present;
 
        mutex_lock(&wm8994->accdet_lock);
 
@@ -3206,11 +3484,17 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
 
        dev_dbg(codec->dev, "JACKDET %x\n", reg);
 
-       if (reg & WM1811_JACKDET_LVL) {
+       present = reg & WM1811_JACKDET_LVL;
+
+       if (present) {
                dev_dbg(codec->dev, "Jack detected\n");
 
-               snd_soc_jack_report(wm8994->micdet[0].jack,
-                                   SND_JACK_MECHANICAL, SND_JACK_MECHANICAL);
+               snd_soc_update_bits(codec, WM8958_MICBIAS2,
+                                   WM8958_MICB2_DISCH, 0);
+
+               /* Disable debounce while inserted */
+               snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
+                                   WM1811_JACKDET_DB, 0);
 
                /*
                 * Start off measument of microphone impedence to find
@@ -3218,14 +3502,18 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
                 */
                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);
        } else {
                dev_dbg(codec->dev, "Jack not detected\n");
 
-               snd_soc_jack_report(wm8994->micdet[0].jack, 0,
-                                   SND_JACK_MECHANICAL | SND_JACK_HEADSET |
-                                   wm8994->btn_mask);
+               snd_soc_update_bits(codec, WM8958_MICBIAS2,
+                                   WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
+
+               /* Enable debounce while removed */
+               snd_soc_update_bits(codec, WM1811_JACKDET_CTRL,
+                                   WM1811_JACKDET_DB, WM1811_JACKDET_DB);
 
                wm8994->mic_detecting = false;
                wm8994->jack_mic = false;
@@ -3236,6 +3524,28 @@ 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) {
+               mutex_lock(&codec->mutex);
+
+               if (present)
+                       snd_soc_dapm_force_enable_pin(&codec->dapm,
+                                                     "MICBIAS2");
+               else
+                       snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS2");
+
+               snd_soc_dapm_sync(&codec->dapm);
+               mutex_unlock(&codec->mutex);
+       }
+
+       if (present)
+               snd_soc_jack_report(wm8994->micdet[0].jack,
+                                   SND_JACK_MECHANICAL, SND_JACK_MECHANICAL);
+       else
+               snd_soc_jack_report(wm8994->micdet[0].jack, 0,
+                                   SND_JACK_MECHANICAL | SND_JACK_HEADSET |
+                                   wm8994->btn_mask);
+
        return IRQ_HANDLED;
 }
 
@@ -3278,6 +3588,7 @@ int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
                }
 
                snd_soc_dapm_force_enable_pin(&codec->dapm, "CLK_SYS");
+               snd_soc_dapm_sync(&codec->dapm);
 
                wm8994->micdet[0].jack = jack;
                wm8994->jack_cb = cb;
@@ -3308,6 +3619,9 @@ int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
                 * otherwise jump straight to microphone detection.
                 */
                if (wm8994->jackdet) {
+                       snd_soc_update_bits(codec, WM8958_MICBIAS2,
+                                           WM8958_MICB2_DISCH,
+                                           WM8958_MICB2_DISCH);
                        snd_soc_update_bits(codec, WM8994_LDO_1,
                                            WM8994_LDO1_DISCH, 0);
                        wm1811_jackdet_set_mode(codec,
@@ -3320,7 +3634,9 @@ int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
        } else {
                snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
                                    WM8958_MICD_ENA, 0);
+               wm1811_jackdet_set_mode(codec, WM1811_JACKDET_MODE_NONE);
                snd_soc_dapm_disable_pin(&codec->dapm, "CLK_SYS");
+               snd_soc_dapm_sync(&codec->dapm);
        }
 
        return 0;
@@ -3333,17 +3649,13 @@ static irqreturn_t wm8958_mic_irq(int irq, void *data)
        struct snd_soc_codec *codec = wm8994->codec;
        int reg, count;
 
-       mutex_lock(&wm8994->accdet_lock);
-
        /*
         * Jack detection may have detected a removal simulataneously
         * with an update of the MICDET status; if so it will have
         * stopped detection and we can ignore this interrupt.
         */
-       if (!(snd_soc_read(codec, WM8958_MIC_DETECT_1) & WM8958_MICD_ENA)) {
-               mutex_unlock(&wm8994->accdet_lock);
+       if (!(snd_soc_read(codec, WM8958_MIC_DETECT_1) & WM8958_MICD_ENA))
                return IRQ_HANDLED;
-       }
 
        /* We may occasionally read a detection without an impedence
         * range being provided - if that happens loop again.
@@ -3352,7 +3664,6 @@ static irqreturn_t wm8958_mic_irq(int irq, void *data)
        do {
                reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
                if (reg < 0) {
-                       mutex_unlock(&wm8994->accdet_lock);
                        dev_err(codec->dev,
                                "Failed to read mic detect status: %d\n",
                                reg);
@@ -3383,8 +3694,6 @@ static irqreturn_t wm8958_mic_irq(int irq, void *data)
                dev_warn(codec->dev, "Accessory detection with no callback\n");
 
 out:
-       mutex_unlock(&wm8994->accdet_lock);
-
        return IRQ_HANDLED;
 }
 
@@ -3418,23 +3727,16 @@ static irqreturn_t wm8994_temp_shut(int irq, void *data)
 static int wm8994_codec_probe(struct snd_soc_codec *codec)
 {
        struct wm8994 *control = dev_get_drvdata(codec->dev->parent);
-       struct wm8994_priv *wm8994;
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
        struct snd_soc_dapm_context *dapm = &codec->dapm;
        unsigned int reg;
        int ret, i;
 
+       wm8994->codec = codec;
        codec->control_data = control->regmap;
 
-       wm8994 = devm_kzalloc(codec->dev, sizeof(struct wm8994_priv),
-                             GFP_KERNEL);
-       if (wm8994 == NULL)
-               return -ENOMEM;
-       snd_soc_codec_set_drvdata(codec, wm8994);
-
        snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
 
-       wm8994->wm8994 = dev_get_drvdata(codec->dev->parent);
-       wm8994->pdata = dev_get_platdata(codec->dev->parent);
        wm8994->codec = codec;
 
        mutex_init(&wm8994->accdet_lock);
@@ -3480,11 +3782,14 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
 
        case WM8958:
                wm8994->hubs.dcs_readback_mode = 1;
+               wm8994->hubs.hp_startup_mode = 1;
                break;
 
        case WM1811:
                wm8994->hubs.dcs_readback_mode = 2;
                wm8994->hubs.no_series_update = 1;
+               wm8994->hubs.hp_startup_mode = 1;
+               wm8994->hubs.no_cache_class_w = true;
 
                switch (wm8994->revision) {
                case 0:
@@ -3492,7 +3797,7 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
                case 2:
                case 3:
                        wm8994->hubs.dcs_codes_l = -9;
-                       wm8994->hubs.dcs_codes_r = -5;
+                       wm8994->hubs.dcs_codes_r = -7;
                        break;
                default:
                        break;
@@ -3887,24 +4192,27 @@ static int  wm8994_codec_remove(struct snd_soc_codec *codec)
        return 0;
 }
 
-static int wm8994_soc_volatile(struct snd_soc_codec *codec,
-                              unsigned int reg)
-{
-       return true;
-}
-
 static struct snd_soc_codec_driver soc_codec_dev_wm8994 = {
        .probe =        wm8994_codec_probe,
        .remove =       wm8994_codec_remove,
-       .suspend =      wm8994_suspend,
-       .resume =       wm8994_resume,
+       .suspend =      wm8994_codec_suspend,
+       .resume =       wm8994_codec_resume,
        .set_bias_level = wm8994_set_bias_level,
-       .reg_cache_size = WM8994_MAX_REGISTER,
-       .volatile_register = wm8994_soc_volatile,
 };
 
 static int __devinit wm8994_probe(struct platform_device *pdev)
 {
+       struct wm8994_priv *wm8994;
+
+       wm8994 = devm_kzalloc(&pdev->dev, sizeof(struct wm8994_priv),
+                             GFP_KERNEL);
+       if (wm8994 == NULL)
+               return -ENOMEM;
+       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));
 }
@@ -3915,11 +4223,43 @@ static int __devexit wm8994_remove(struct platform_device *pdev)
        return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int wm8994_suspend(struct device *dev)
+{
+       struct wm8994_priv *wm8994 = dev_get_drvdata(dev);
+
+       /* Drop down to power saving mode when system is suspended */
+       if (wm8994->jackdet && !wm8994->active_refcount)
+               regmap_update_bits(wm8994->wm8994->regmap, WM8994_ANTIPOP_2,
+                                  WM1811_JACKDET_MODE_MASK,
+                                  wm8994->jackdet_mode);
+
+       return 0;
+}
+
+static int wm8994_resume(struct device *dev)
+{
+       struct wm8994_priv *wm8994 = dev_get_drvdata(dev);
+
+       if (wm8994->jackdet && wm8994->jack_cb)
+               regmap_update_bits(wm8994->wm8994->regmap, WM8994_ANTIPOP_2,
+                                  WM1811_JACKDET_MODE_MASK,
+                                  WM1811_JACKDET_MODE_AUDIO);
+
+       return 0;
+}
+#endif
+
+static const struct dev_pm_ops wm8994_pm_ops = {
+       SET_SYSTEM_SLEEP_PM_OPS(wm8994_suspend, wm8994_resume)
+};
+
 static struct platform_driver wm8994_codec_driver = {
        .driver = {
-                  .name = "wm8994-codec",
-                  .owner = THIS_MODULE,
-                  },
+               .name = "wm8994-codec",
+               .owner = THIS_MODULE,
+               .pm = &wm8994_pm_ops,
+       },
        .probe = wm8994_probe,
        .remove = __devexit_p(wm8994_remove),
 };