Merge series "ASoC: Intel: machine driver updates for 5.9" from Pierre-Louis Bossart...
[linux-block.git] / sound / soc / codecs / rt5682.c
index fab066a75ce0254772709024cc747697a9540509..a4713bd6508d52bfed3087a97d96bd1e425fa202 100644 (file)
@@ -970,13 +970,12 @@ int rt5682_headset_detect(struct snd_soc_component *component, int jack_insert)
                rt5682_enable_push_button_irq(component, false);
                snd_soc_component_update_bits(component, RT5682_CBJ_CTRL_1,
                        RT5682_TRIG_JD_MASK, RT5682_TRIG_JD_LOW);
-               if (snd_soc_dapm_get_pin_status(dapm, "MICBIAS"))
+               if (!snd_soc_dapm_get_pin_status(dapm, "MICBIAS"))
                        snd_soc_component_update_bits(component,
-                               RT5682_PWR_ANLG_1, RT5682_PWR_VREF2, 0);
-               else
+                               RT5682_PWR_ANLG_1, RT5682_PWR_MB, 0);
+               if (!snd_soc_dapm_get_pin_status(dapm, "Vref2"))
                        snd_soc_component_update_bits(component,
-                               RT5682_PWR_ANLG_1,
-                               RT5682_PWR_VREF2 | RT5682_PWR_MB, 0);
+                               RT5682_PWR_ANLG_1, RT5682_PWR_VREF2, 0);
                snd_soc_component_update_bits(component, RT5682_PWR_ANLG_3,
                        RT5682_PWR_CBJ, 0);
                snd_soc_component_update_bits(component, RT5682_MICBIAS_2,
@@ -1088,7 +1087,8 @@ void rt5682_jack_detect_handler(struct work_struct *work)
                        /* jack was out, report jack type */
                        rt5682->jack_type =
                                rt5682_headset_detect(rt5682->component, 1);
-               } else {
+               } else if ((rt5682->jack_type & SND_JACK_HEADSET) ==
+                       SND_JACK_HEADSET) {
                        /* jack is already in, report button event */
                        rt5682->jack_type = SND_JACK_HEADSET;
                        btn_type = rt5682_button_detect(rt5682->component);
@@ -1614,8 +1614,7 @@ static const struct snd_soc_dapm_widget rt5682_dapm_widgets[] = {
                0, set_filter_clk, SND_SOC_DAPM_PRE_PMU),
        SND_SOC_DAPM_SUPPLY("Vref1", RT5682_PWR_ANLG_1, RT5682_PWR_VREF1_BIT, 0,
                rt5682_set_verf, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
-       SND_SOC_DAPM_SUPPLY("Vref2", RT5682_PWR_ANLG_1, RT5682_PWR_VREF2_BIT, 0,
-               NULL, 0),
+       SND_SOC_DAPM_SUPPLY("Vref2", SND_SOC_NOPM, 0, 0, NULL, 0),
        SND_SOC_DAPM_SUPPLY("MICBIAS", SND_SOC_NOPM, 0, 0, NULL, 0),
 
        /* ASRC */
@@ -2505,6 +2504,15 @@ static int rt5682_wclk_prepare(struct clk_hw *hw)
        snd_soc_dapm_force_enable_pin_unlocked(dapm, "MICBIAS");
        snd_soc_component_update_bits(component, RT5682_PWR_ANLG_1,
                                RT5682_PWR_MB, RT5682_PWR_MB);
+
+       snd_soc_dapm_force_enable_pin_unlocked(dapm, "Vref2");
+       snd_soc_component_update_bits(component, RT5682_PWR_ANLG_1,
+                       RT5682_PWR_VREF2 | RT5682_PWR_FV2,
+                       RT5682_PWR_VREF2);
+       usleep_range(55000, 60000);
+       snd_soc_component_update_bits(component, RT5682_PWR_ANLG_1,
+                       RT5682_PWR_FV2, RT5682_PWR_FV2);
+
        snd_soc_dapm_force_enable_pin_unlocked(dapm, "I2S1");
        snd_soc_dapm_force_enable_pin_unlocked(dapm, "PLL2F");
        snd_soc_dapm_force_enable_pin_unlocked(dapm, "PLL2B");
@@ -2530,9 +2538,12 @@ static void rt5682_wclk_unprepare(struct clk_hw *hw)
        snd_soc_dapm_mutex_lock(dapm);
 
        snd_soc_dapm_disable_pin_unlocked(dapm, "MICBIAS");
+       snd_soc_dapm_disable_pin_unlocked(dapm, "Vref2");
        if (!rt5682->jack_type)
                snd_soc_component_update_bits(component, RT5682_PWR_ANLG_1,
+                               RT5682_PWR_VREF2 | RT5682_PWR_FV2 |
                                RT5682_PWR_MB, 0);
+
        snd_soc_dapm_disable_pin_unlocked(dapm, "I2S1");
        snd_soc_dapm_disable_pin_unlocked(dapm, "PLL2F");
        snd_soc_dapm_disable_pin_unlocked(dapm, "PLL2B");