Merge some cs42l42 patches into asoc-5.15
[sfrench/cifs-2.6.git] / sound / soc / codecs / rt5682.c
index 51ecaa2abcd1447078c0bfcfb63d3a7a2ef0b068..7dc01ae6bb66517c877dc38c9d87ff46ee675421 100644 (file)
@@ -2916,10 +2916,46 @@ static void rt5682_remove(struct snd_soc_component *component)
 static int rt5682_suspend(struct snd_soc_component *component)
 {
        struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
+       unsigned int val;
 
        if (rt5682->is_sdw)
                return 0;
 
+       cancel_delayed_work_sync(&rt5682->jack_detect_work);
+       cancel_delayed_work_sync(&rt5682->jd_check_work);
+       if (rt5682->hs_jack && rt5682->jack_type == SND_JACK_HEADSET) {
+               snd_soc_component_update_bits(component, RT5682_CBJ_CTRL_1,
+                       RT5682_MB1_PATH_MASK | RT5682_MB2_PATH_MASK,
+                       RT5682_CTRL_MB1_REG | RT5682_CTRL_MB2_REG);
+               val = snd_soc_component_read(component,
+                               RT5682_CBJ_CTRL_2) & RT5682_JACK_TYPE_MASK;
+
+               switch (val) {
+               case 0x1:
+                       snd_soc_component_update_bits(component, RT5682_SAR_IL_CMD_1,
+                               RT5682_SAR_SEL_MB1_MASK | RT5682_SAR_SEL_MB2_MASK,
+                               RT5682_SAR_SEL_MB1_NOSEL | RT5682_SAR_SEL_MB2_SEL);
+                       break;
+               case 0x2:
+                       snd_soc_component_update_bits(component, RT5682_SAR_IL_CMD_1,
+                               RT5682_SAR_SEL_MB1_MASK | RT5682_SAR_SEL_MB2_MASK,
+                               RT5682_SAR_SEL_MB1_SEL | RT5682_SAR_SEL_MB2_NOSEL);
+                       break;
+               default:
+                       break;
+               }
+
+               snd_soc_component_update_bits(component, RT5682_PWR_ANLG_3,
+                       RT5682_PWR_CBJ, 0);
+
+               /* enter SAR ADC power saving mode */
+               snd_soc_component_update_bits(component, RT5682_SAR_IL_CMD_1,
+                       RT5682_SAR_BUTT_DET_MASK | RT5682_SAR_BUTDET_MODE_MASK | RT5682_SAR_BUTDET_RST_MASK, 0);
+               snd_soc_component_update_bits(component, RT5682_SAR_IL_CMD_1,
+                       RT5682_SAR_BUTT_DET_MASK | RT5682_SAR_BUTDET_MODE_MASK | RT5682_SAR_BUTDET_RST_MASK,
+                       RT5682_SAR_BUTT_DET_EN | RT5682_SAR_BUTDET_POW_SAV | RT5682_SAR_BUTDET_RST_NORMAL);
+       }
+
        regcache_cache_only(rt5682->regmap, true);
        regcache_mark_dirty(rt5682->regmap);
        return 0;
@@ -2935,6 +2971,14 @@ static int rt5682_resume(struct snd_soc_component *component)
        regcache_cache_only(rt5682->regmap, false);
        regcache_sync(rt5682->regmap);
 
+       if (rt5682->hs_jack && rt5682->jack_type == SND_JACK_HEADSET) {
+               snd_soc_component_update_bits(component, RT5682_CBJ_CTRL_1,
+                       RT5682_MB1_PATH_MASK | RT5682_MB2_PATH_MASK,
+                       RT5682_CTRL_MB1_FSM | RT5682_CTRL_MB2_FSM);
+               snd_soc_component_update_bits(component, RT5682_PWR_ANLG_3,
+                       RT5682_PWR_CBJ, RT5682_PWR_CBJ);
+       }
+
        mod_delayed_work(system_power_efficient_wq,
                &rt5682->jack_detect_work, msecs_to_jiffies(250));