OSDN Git Service

ASoC: tas2764: Fix mute/unmute
authorMartin Povišer <povik+lin@cutebit.org>
Thu, 25 Aug 2022 14:02:39 +0000 (16:02 +0200)
committerMark Brown <broonie@kernel.org>
Thu, 25 Aug 2022 16:59:58 +0000 (17:59 +0100)
Because the PWR_CTRL field is modeled as the power state of the DAC
widget, and at the same time it is used to implement mute/unmute, we
need some additional book-keeping to have the right end result no matter
the sequence of calls. Without this fix, one permanently mutes an
ongoing stream by toggling the associated speaker pin control.

(This mirrors commit 1e5907bcb3a3 ("ASoC: tas2770: Fix handling of
mute/unmute") which was a fix to the tas2770 driver.)

Fixes: 827ed8a0fa50 ("ASoC: tas2764: Add the driver for the TAS2764")
Signed-off-by: Martin Povišer <povik+lin@cutebit.org>
Link: https://lore.kernel.org/r/20220825140241.53963-4-povik+lin@cutebit.org
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/tas2764.c

index f4ac6ed..39902f7 100644 (file)
@@ -34,6 +34,9 @@ struct tas2764_priv {
        
        int v_sense_slot;
        int i_sense_slot;
+
+       bool dac_powered;
+       bool unmuted;
 };
 
 static void tas2764_reset(struct tas2764_priv *tas2764)
@@ -50,6 +53,26 @@ static void tas2764_reset(struct tas2764_priv *tas2764)
        usleep_range(1000, 2000);
 }
 
+static int tas2764_update_pwr_ctrl(struct tas2764_priv *tas2764)
+{
+       struct snd_soc_component *component = tas2764->component;
+       unsigned int val;
+       int ret;
+
+       if (tas2764->dac_powered)
+               val = tas2764->unmuted ?
+                       TAS2764_PWR_CTRL_ACTIVE : TAS2764_PWR_CTRL_MUTE;
+       else
+               val = TAS2764_PWR_CTRL_SHUTDOWN;
+
+       ret = snd_soc_component_update_bits(component, TAS2764_PWR_CTRL,
+                                           TAS2764_PWR_CTRL_MASK, val);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
 #ifdef CONFIG_PM
 static int tas2764_codec_suspend(struct snd_soc_component *component)
 {
@@ -82,9 +105,7 @@ static int tas2764_codec_resume(struct snd_soc_component *component)
                usleep_range(1000, 2000);
        }
 
-       ret = snd_soc_component_update_bits(component, TAS2764_PWR_CTRL,
-                                           TAS2764_PWR_CTRL_MASK,
-                                           TAS2764_PWR_CTRL_ACTIVE);
+       ret = tas2764_update_pwr_ctrl(tas2764);
 
        if (ret < 0)
                return ret;
@@ -118,14 +139,12 @@ static int tas2764_dac_event(struct snd_soc_dapm_widget *w,
 
        switch (event) {
        case SND_SOC_DAPM_POST_PMU:
-               ret = snd_soc_component_update_bits(component, TAS2764_PWR_CTRL,
-                                                   TAS2764_PWR_CTRL_MASK,
-                                                   TAS2764_PWR_CTRL_MUTE);
+               tas2764->dac_powered = true;
+               ret = tas2764_update_pwr_ctrl(tas2764);
                break;
        case SND_SOC_DAPM_PRE_PMD:
-               ret = snd_soc_component_update_bits(component, TAS2764_PWR_CTRL,
-                                                   TAS2764_PWR_CTRL_MASK,
-                                                   TAS2764_PWR_CTRL_SHUTDOWN);
+               tas2764->dac_powered = false;
+               ret = tas2764_update_pwr_ctrl(tas2764);
                break;
        default:
                dev_err(tas2764->dev, "Unsupported event\n");
@@ -170,17 +189,11 @@ static const struct snd_soc_dapm_route tas2764_audio_map[] = {
 
 static int tas2764_mute(struct snd_soc_dai *dai, int mute, int direction)
 {
-       struct snd_soc_component *component = dai->component;
-       int ret;
-
-       ret = snd_soc_component_update_bits(component, TAS2764_PWR_CTRL,
-                                           TAS2764_PWR_CTRL_MASK,
-                                           mute ? TAS2764_PWR_CTRL_MUTE : 0);
+       struct tas2764_priv *tas2764 =
+                       snd_soc_component_get_drvdata(dai->component);
 
-       if (ret < 0)
-               return ret;
-
-       return 0;
+       tas2764->unmuted = !mute;
+       return tas2764_update_pwr_ctrl(tas2764);
 }
 
 static int tas2764_set_bitwidth(struct tas2764_priv *tas2764, int bitwidth)
@@ -494,12 +507,6 @@ static int tas2764_codec_probe(struct snd_soc_component *component)
        if (ret < 0)
                return ret;
 
-       ret = snd_soc_component_update_bits(component, TAS2764_PWR_CTRL,
-                                           TAS2764_PWR_CTRL_MASK,
-                                           TAS2764_PWR_CTRL_MUTE);
-       if (ret < 0)
-               return ret;
-
        return 0;
 }