ASoC: tas2562: Fix mute/unmute

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 1e5907bcb3 ("ASoC: tas2770: Fix handling of
mute/unmute") which was a fix to the tas2770 driver.)

Signed-off-by: Martin Povišer <povik+lin@cutebit.org>
Link: https://lore.kernel.org/r/20220825142226.80929-3-povik+lin@cutebit.org
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Martin Povišer 2022-08-25 16:22:26 +02:00 committed by Mark Brown
parent b6b55b2325
commit 2848d34c3b
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0

View File

@ -54,6 +54,8 @@ struct tas2562_data {
int i_sense_slot; int i_sense_slot;
int volume_lvl; int volume_lvl;
int model_id; int model_id;
bool dac_powered;
bool unmuted;
}; };
enum tas256x_model { enum tas256x_model {
@ -351,30 +353,43 @@ static int tas2562_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
return 0; return 0;
} }
static int tas2562_update_pwr_ctrl(struct tas2562_data *tas2562)
{
struct snd_soc_component *component = tas2562->component;
unsigned int val;
int ret;
if (tas2562->dac_powered)
val = tas2562->unmuted ?
TAS2562_ACTIVE : TAS2562_MUTE;
else
val = TAS2562_SHUTDOWN;
ret = snd_soc_component_update_bits(component, TAS2562_PWR_CTRL,
TAS2562_MODE_MASK, val);
if (ret < 0)
return ret;
return 0;
}
static int tas2562_mute(struct snd_soc_dai *dai, int mute, int direction) static int tas2562_mute(struct snd_soc_dai *dai, int mute, int direction)
{ {
struct snd_soc_component *component = dai->component; struct tas2562_data *tas2562 = snd_soc_component_get_drvdata(dai->component);
return snd_soc_component_update_bits(component, TAS2562_PWR_CTRL, tas2562->unmuted = !mute;
TAS2562_MODE_MASK, return tas2562_update_pwr_ctrl(tas2562);
mute ? TAS2562_MUTE : 0);
} }
static int tas2562_codec_probe(struct snd_soc_component *component) static int tas2562_codec_probe(struct snd_soc_component *component)
{ {
struct tas2562_data *tas2562 = snd_soc_component_get_drvdata(component); struct tas2562_data *tas2562 = snd_soc_component_get_drvdata(component);
int ret;
tas2562->component = component; tas2562->component = component;
if (tas2562->sdz_gpio) if (tas2562->sdz_gpio)
gpiod_set_value_cansleep(tas2562->sdz_gpio, 1); gpiod_set_value_cansleep(tas2562->sdz_gpio, 1);
ret = snd_soc_component_update_bits(component, TAS2562_PWR_CTRL,
TAS2562_MODE_MASK, TAS2562_MUTE);
if (ret < 0)
return ret;
return 0; return 0;
} }
@ -428,30 +443,18 @@ static int tas2562_dac_event(struct snd_soc_dapm_widget *w,
switch (event) { switch (event) {
case SND_SOC_DAPM_POST_PMU: case SND_SOC_DAPM_POST_PMU:
ret = snd_soc_component_update_bits(component, tas2562->dac_powered = true;
TAS2562_PWR_CTRL, ret = tas2562_update_pwr_ctrl(tas2562);
TAS2562_MODE_MASK,
TAS2562_MUTE);
if (ret)
goto end;
break; break;
case SND_SOC_DAPM_PRE_PMD: case SND_SOC_DAPM_PRE_PMD:
ret = snd_soc_component_update_bits(component, tas2562->dac_powered = false;
TAS2562_PWR_CTRL, ret = tas2562_update_pwr_ctrl(tas2562);
TAS2562_MODE_MASK,
TAS2562_SHUTDOWN);
if (ret)
goto end;
break; break;
default: default:
dev_err(tas2562->dev, "Not supported evevt\n"); dev_err(tas2562->dev, "Not supported evevt\n");
return -EINVAL; return -EINVAL;
} }
end:
if (ret < 0)
return ret;
return 0; return 0;
} }