ASoC: rt5677: Stop and restart DSP over suspend/resume
authorBen Zhang <benzh@chromium.org>
Wed, 6 Nov 2019 01:13:31 +0000 (17:13 -0800)
committerMark Brown <broonie@kernel.org>
Mon, 11 Nov 2019 13:02:03 +0000 (13:02 +0000)
MCLK1 gets disabled at suspend and re-enabled at resume. Before
MCLK1 is re-enabled, if the DSP is already on (either the DSP was
left on during suspend, or the DSP is turned on early at resume),
i2c register read returns garbage and corrupts the regmap cache.

This patch stops the DSP before suspend and restarts it after
resume with a dalay to ensure MCLK is on while loading firmware.

Signed-off-by: Ben Zhang <benzh@chromium.org>
Signed-off-by: Curtis Malainey <cujomalainey@chromium.org>
Link: https://lore.kernel.org/r/20191106011335.223061-7-cujomalainey@chromium.org
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/rt5677.c
sound/soc/codecs/rt5677.h

index e5db9dc603784f447d68648d80f6819c2251d97c..eb55d6b9d0c152ee01552fc4251e7d6eae02856b 100644 (file)
@@ -876,6 +876,7 @@ static int rt5677_load_dsp_from_file(struct rt5677_priv *rt5677)
 static int rt5677_set_dsp_vad(struct snd_soc_component *component, bool on)
 {
        struct rt5677_priv *rt5677 = snd_soc_component_get_drvdata(component);
+       rt5677->dsp_vad_en_request = on;
        rt5677->dsp_vad_en = on;
 
        if (!IS_ENABLED(CONFIG_SND_SOC_RT5677_SPI))
@@ -969,7 +970,7 @@ static int rt5677_dsp_vad_get(struct snd_kcontrol *kcontrol,
        struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
        struct rt5677_priv *rt5677 = snd_soc_component_get_drvdata(component);
 
-       ucontrol->value.integer.value[0] = rt5677->dsp_vad_en;
+       ucontrol->value.integer.value[0] = rt5677->dsp_vad_en_request;
 
        return 0;
 }
@@ -4636,14 +4637,15 @@ static int rt5677_set_bias_level(struct snd_soc_component *component,
                        enum snd_soc_bias_level level)
 {
        struct rt5677_priv *rt5677 = snd_soc_component_get_drvdata(component);
+       enum snd_soc_bias_level prev_bias =
+               snd_soc_component_get_bias_level(component);
 
        switch (level) {
        case SND_SOC_BIAS_ON:
                break;
 
        case SND_SOC_BIAS_PREPARE:
-               if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_STANDBY) {
-                       rt5677_set_dsp_vad(component, false);
+               if (prev_bias == SND_SOC_BIAS_STANDBY) {
 
                        regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG1,
                                RT5677_LDO1_SEL_MASK | RT5677_LDO2_SEL_MASK,
@@ -4667,9 +4669,25 @@ static int rt5677_set_bias_level(struct snd_soc_component *component,
                break;
 
        case SND_SOC_BIAS_STANDBY:
+               if (prev_bias == SND_SOC_BIAS_OFF &&
+                               rt5677->dsp_vad_en_request) {
+                       /* Re-enable the DSP if it was turned off at suspend */
+                       rt5677->dsp_vad_en = true;
+                       /* The delay is to wait for MCLK */
+                       schedule_delayed_work(&rt5677->dsp_work,
+                                       msecs_to_jiffies(1000));
+               }
                break;
 
        case SND_SOC_BIAS_OFF:
+               flush_delayed_work(&rt5677->dsp_work);
+               if (rt5677->is_dsp_mode) {
+                       /* Turn off the DSP before suspend */
+                       rt5677->dsp_vad_en = false;
+                       schedule_delayed_work(&rt5677->dsp_work, 0);
+                       flush_delayed_work(&rt5677->dsp_work);
+               }
+
                regmap_update_bits(rt5677->regmap, RT5677_DIG_MISC, 0x1, 0x0);
                regmap_write(rt5677->regmap, RT5677_PWR_DIG1, 0x0000);
                regmap_write(rt5677->regmap, RT5677_PWR_ANLG1,
index d18b41da1176bb8b36013749a4f4e43e9eed4e5d..046ed2ee8e31e456abc81e983ef3a7241860a148 100644 (file)
@@ -1846,7 +1846,8 @@ struct rt5677_priv {
 #ifdef CONFIG_GPIOLIB
        struct gpio_chip gpio_chip;
 #endif
-       bool dsp_vad_en; /* DSP VAD enable/disable request */
+       bool dsp_vad_en_request; /* DSP VAD enable/disable request */
+       bool dsp_vad_en; /* dsp_work parameter */
        bool is_dsp_mode;
        bool is_vref_slow;
        struct delayed_work dsp_work;