summaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorOleksandr Suvorov <oleksandr.suvorov@toradex.com>2019-05-20 10:42:32 +0300
committerMarcel Ziswiler <marcel.ziswiler@toradex.com>2020-02-12 11:06:00 +0100
commit7a2d0057ac90dc14137a1e1e008166c4ff1b7749 (patch)
treef8abafe333549fc65324c415784d896023adeda4 /sound
parent76b83ffb070d81adcfbb0f36f4f4bf51cd3e51c0 (diff)
ASoC: sgtl5000: Improve VAG power and mute control
VAG power control is improved to fit the manual [1]. This patch fixes as minimum one bug: if customer muxes Headphone to Line-In right after boot, the VAG power remains off that leads to poor sound quality from line-in. I.e. after boot: - Connect sound source to Line-In jack; - Connect headphone to HP jack; - Run following commands: $ amixer set 'Headphone' 80% $ amixer set 'Headphone Mux' LINE_IN Change VAG power on/off control according to the following algorithm: - turn VAG power ON on the 1st incoming event. - keep it ON if there is any active VAG consumer (ADC/DAC/HP/Line-In). - turn VAG power OFF when there is the latest consumer's pre-down event come. - always delay after VAG power OFF to avoid pop. - delay after VAG power ON if the initiative consumer is Line-In, this prevents pop during line-in muxing. According to the data sheet [1], to avoid any pops/clicks, the outputs should be muted during input/output routing changes. [1] https://www.nxp.com/docs/en/data-sheet/SGTL5000.pdf Cc: stable@vger.kernel.org Fixes: 9b34e6cc3bc2 ("ASoC: Add Freescale SGTL5000 codec support") Signed-off-by: Oleksandr Suvorov <oleksandr.suvorov@toradex.com> Reviewed-by: Marcel Ziswiler <marcel.ziswiler@toradex.com> Reviewed-by: Fabio Estevam <festevam@gmail.com>
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/codecs/sgtl5000.c81
1 files changed, 35 insertions, 46 deletions
diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
index 73a7aeaed6ed..ca8a70ab22a8 100644
--- a/sound/soc/codecs/sgtl5000.c
+++ b/sound/soc/codecs/sgtl5000.c
@@ -322,24 +322,13 @@ static int vag_and_mute_control(struct snd_soc_component *component,
sgtl5000->mute_state[event_source]);
break;
case SND_SOC_DAPM_PRE_PMD:
- /*
- * Don't clear VAG_POWERUP when there is a local loop
- * from LINE_IN to the HP.
- */
- if (snd_soc_read(codec, SGTL5000_CHIP_ANA_CTRL) &
- SGTL5000_HP_SEL_MASK)
- break;
- /*
- * Don't clear VAG_POWERUP, when both DAC and ADC are
- * operational to prevent inadvertently starving the
- * other one of them.
- */
- if ((snd_soc_read(codec, SGTL5000_CHIP_ANA_POWER) &
- mask) != mask) {
- snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER,
- SGTL5000_VAG_POWERUP, 0);
- msleep(400);
- }
+ sgtl5000->mute_state[event_source] =
+ mute_output(component, mute_mask[event_source]);
+ vag_power_off(component, event_source);
+ break;
+ case SND_SOC_DAPM_POST_PMD:
+ restore_output(component, mute_mask[event_source],
+ sgtl5000->mute_state[event_source]);
break;
default:
break;
@@ -349,36 +338,38 @@ static int vag_and_mute_control(struct snd_soc_component *component,
}
/*
- * If we mux a direct path from LINE_IN to HP, VAG must be powered up.
- * With the SND_SOC_DAPM_POST_REG event the new state of the headphone mux is
- * available.
+ * Mute Headphone when power it up/down.
+ * Control VAG power on HP power path.
*/
-static int headphone_mux_event(struct snd_soc_dapm_widget *w,
+static int headphone_pga_event(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *kcontrol, int event)
{
- struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
+ struct snd_soc_component *component =
+ snd_soc_dapm_to_component(w->dapm);
- /*
- * switch on VAG unconditionally on any change of the headphone muxer
- * early to lessen pop.
- */
- switch (event) {
- case SND_SOC_DAPM_PRE_REG:
- snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER,
- SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
- break;
- /*
- * The call to power_vag_event() switches VAG off again, if VAG need
- * not be switched on.
- */
- case SND_SOC_DAPM_POST_REG:
- power_vag_event(w, kcontrol, SND_SOC_DAPM_PRE_PMD);
- break;
- default:
- break;
- }
+ return vag_and_mute_control(component, event, HP_POWER_EVENT);
+}
- return 0;
+/* As manual describes, ADC/DAC powering up/down requires
+ * to mute outputs to avoid pops.
+ * Control VAG power on ADC/DAC power path.
+ */
+static int adc_updown_depop(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_component *component =
+ snd_soc_dapm_to_component(w->dapm);
+
+ return vag_and_mute_control(component, event, ADC_POWER_EVENT);
+}
+
+static int dac_updown_depop(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_component *component =
+ snd_soc_dapm_to_component(w->dapm);
+
+ return vag_and_mute_control(component, event, DAC_POWER_EVENT);
}
/* input sources for ADC */
@@ -423,9 +414,7 @@ static const struct snd_soc_dapm_widget sgtl5000_dapm_widgets[] = {
SND_SOC_DAPM_PGA("LO", SGTL5000_CHIP_ANA_POWER, 0, 0, NULL, 0),
SND_SOC_DAPM_MUX("Capture Mux", SND_SOC_NOPM, 0, 0, &adc_mux),
- SND_SOC_DAPM_MUX_E("Headphone Mux", SND_SOC_NOPM, 0, 0, &dac_mux,
- headphone_mux_event,
- SND_SOC_DAPM_PRE_REG | SND_SOC_DAPM_POST_REG),
+ SND_SOC_DAPM_MUX("Headphone Mux", SND_SOC_NOPM, 0, 0, &dac_mux),
/* aif for i2s input */
SND_SOC_DAPM_AIF_IN("AIFIN", "Playback",