Skip to content

Commit 04a646f

Browse files
Tzung-Bi Shihbroonie
authored andcommitted
ASoC: max98357a: move control of SD_MODE back to DAI ops
Partially reverts commit 128f825 ("ASoC: max98357a: move control of SD_MODE to DAPM"). In order to have mute control of max98357 from machine drivers, commit 128f825 ("ASoC: max98357a: move control of SD_MODE to DAPM") moves the control of SD_MODE from DAI ops to DAPM events. However, pop noise has been observed on rk3399-gru-kevin boards due to this commit. The commit 128f825 caused sequence of DAI clocks and SD_MODE changed on rk3399-gru-kevin boards. With the commit 128f825: - SD_MODE will be set to 1 before DAI clocks start. - SD_MODE will be set to 0 after DAI clocks stop. As a result, pop noise. Moves the control of SD_MODE back to DAI ops. In the meantime, uses an additional flag in DAPM event to provide chance of mute control for machine drivers. Signed-off-by: Tzung-Bi Shih <[email protected]> Tested-By: Alper Nebi Yasak <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 468ae35 commit 04a646f

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

sound/soc/codecs/max98357a.c

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,61 @@
2323
struct max98357a_priv {
2424
struct gpio_desc *sdmode;
2525
unsigned int sdmode_delay;
26+
int sdmode_switch;
2627
};
2728

28-
static int max98357a_sdmode_event(struct snd_soc_dapm_widget *w,
29-
struct snd_kcontrol *kcontrol, int event)
29+
static int max98357a_daiops_trigger(struct snd_pcm_substream *substream,
30+
int cmd, struct snd_soc_dai *dai)
3031
{
31-
struct snd_soc_component *component =
32-
snd_soc_dapm_to_component(w->dapm);
32+
struct snd_soc_component *component = dai->component;
3333
struct max98357a_priv *max98357a =
3434
snd_soc_component_get_drvdata(component);
3535

3636
if (!max98357a->sdmode)
3737
return 0;
3838

39-
if (event & SND_SOC_DAPM_POST_PMU) {
40-
msleep(max98357a->sdmode_delay);
41-
gpiod_set_value(max98357a->sdmode, 1);
42-
dev_dbg(component->dev, "set sdmode to 1");
43-
} else if (event & SND_SOC_DAPM_PRE_PMD) {
39+
switch (cmd) {
40+
case SNDRV_PCM_TRIGGER_START:
41+
case SNDRV_PCM_TRIGGER_RESUME:
42+
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
43+
mdelay(max98357a->sdmode_delay);
44+
if (max98357a->sdmode_switch) {
45+
gpiod_set_value(max98357a->sdmode, 1);
46+
dev_dbg(component->dev, "set sdmode to 1");
47+
}
48+
break;
49+
case SNDRV_PCM_TRIGGER_STOP:
50+
case SNDRV_PCM_TRIGGER_SUSPEND:
51+
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
4452
gpiod_set_value(max98357a->sdmode, 0);
4553
dev_dbg(component->dev, "set sdmode to 0");
54+
break;
4655
}
4756

4857
return 0;
4958
}
5059

60+
static int max98357a_sdmode_event(struct snd_soc_dapm_widget *w,
61+
struct snd_kcontrol *kcontrol, int event)
62+
{
63+
struct snd_soc_component *component =
64+
snd_soc_dapm_to_component(w->dapm);
65+
struct max98357a_priv *max98357a =
66+
snd_soc_component_get_drvdata(component);
67+
68+
if (event & SND_SOC_DAPM_POST_PMU)
69+
max98357a->sdmode_switch = 1;
70+
else if (event & SND_SOC_DAPM_POST_PMD)
71+
max98357a->sdmode_switch = 0;
72+
73+
return 0;
74+
}
75+
5176
static const struct snd_soc_dapm_widget max98357a_dapm_widgets[] = {
5277
SND_SOC_DAPM_OUTPUT("Speaker"),
5378
SND_SOC_DAPM_OUT_DRV_E("SD_MODE", SND_SOC_NOPM, 0, 0, NULL, 0,
5479
max98357a_sdmode_event,
55-
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
80+
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5681
};
5782

5883
static const struct snd_soc_dapm_route max98357a_dapm_routes[] = {
@@ -71,6 +96,10 @@ static const struct snd_soc_component_driver max98357a_component_driver = {
7196
.non_legacy_dai_naming = 1,
7297
};
7398

99+
static const struct snd_soc_dai_ops max98357a_dai_ops = {
100+
.trigger = max98357a_daiops_trigger,
101+
};
102+
74103
static struct snd_soc_dai_driver max98357a_dai_driver = {
75104
.name = "HiFi",
76105
.playback = {
@@ -90,6 +119,7 @@ static struct snd_soc_dai_driver max98357a_dai_driver = {
90119
.channels_min = 1,
91120
.channels_max = 2,
92121
},
122+
.ops = &max98357a_dai_ops,
93123
};
94124

95125
static int max98357a_platform_probe(struct platform_device *pdev)

0 commit comments

Comments
 (0)