Skip to content

Commit 695d444

Browse files
RanderWangplbossart
authored andcommitted
ASoC: Intel: boards: fix xrun issue on platform with max98373
On TGL platform with max98373 codec the trigger start sequence is fe first, then codec component and sdw link is the last. Recently a delay was introduced in max98373 codec driver and this resulted to the start of sdw stream transmition was delayed and the data transmitted by fw can't be consumed by sdw controller, so xrun happened. Adding delay in trigger function is a bad idea. This patch enable spk pin in prepare function and disable it in hw_free to avoid xrun issue caused by delay in trigger. Fixes: 3a27875 (ASoC: max98373: Added 30ms turn on/off time delay) BugLink: thesofproject/sof#4066 Signed-off-by: Rander Wang <rander.wang@intel.com>
1 parent b1c762a commit 695d444

1 file changed

Lines changed: 53 additions & 28 deletions

File tree

sound/soc/intel/boards/sof_sdw_max98373.c

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -55,43 +55,68 @@ static int spk_init(struct snd_soc_pcm_runtime *rtd)
5555
return ret;
5656
}
5757

58-
static int max98373_sdw_trigger(struct snd_pcm_substream *substream, int cmd)
58+
static int mx8373_enable_spk_pin(struct snd_pcm_substream *substream, bool enable)
5959
{
60+
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
61+
struct snd_soc_dai *codec_dai;
62+
struct snd_soc_dai *cpu_dai;
6063
int ret;
64+
int j;
6165

62-
switch (cmd) {
63-
case SNDRV_PCM_TRIGGER_START:
64-
case SNDRV_PCM_TRIGGER_RESUME:
65-
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
66-
/* enable max98373 first */
67-
ret = max_98373_trigger(substream, cmd);
68-
if (ret < 0)
69-
break;
70-
71-
ret = sdw_trigger(substream, cmd);
72-
break;
73-
case SNDRV_PCM_TRIGGER_STOP:
74-
case SNDRV_PCM_TRIGGER_SUSPEND:
75-
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
76-
ret = sdw_trigger(substream, cmd);
77-
if (ret < 0)
78-
break;
79-
80-
ret = max_98373_trigger(substream, cmd);
81-
break;
82-
default:
83-
ret = -EINVAL;
84-
break;
66+
/* set spk pin by playback only */
67+
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
68+
return 0;
69+
70+
cpu_dai = asoc_rtd_to_cpu(rtd, 0);
71+
for_each_rtd_codec_dais(rtd, j, codec_dai) {
72+
struct snd_soc_dapm_context *dapm =
73+
snd_soc_component_get_dapm(cpu_dai->component);
74+
char pin_name[16];
75+
76+
snprintf(pin_name, ARRAY_SIZE(pin_name), "%s Spk",
77+
codec_dai->component->name_prefix);
78+
79+
if (enable)
80+
ret = snd_soc_dapm_enable_pin(dapm, pin_name);
81+
else
82+
ret = snd_soc_dapm_disable_pin(dapm, pin_name);
83+
84+
if (!ret)
85+
snd_soc_dapm_sync(dapm);
8586
}
8687

87-
return ret;
88+
return 0;
89+
}
90+
91+
static int mx8373_sdw_prepare(struct snd_pcm_substream *substream)
92+
{
93+
int ret = 0;
94+
95+
/* according to soc_pcm_prepare dai link prepare is called first */
96+
ret = sdw_prepare(substream);
97+
if (ret < 0)
98+
return ret;
99+
100+
return mx8373_enable_spk_pin(substream, true);
101+
}
102+
103+
static int mx8373_sdw_hw_free(struct snd_pcm_substream *substream)
104+
{
105+
int ret = 0;
106+
107+
/* according to soc_pcm_hw_free dai link free is called first */
108+
ret = sdw_hw_free(substream);
109+
if (ret < 0)
110+
return ret;
111+
112+
return mx8373_enable_spk_pin(substream, false);
88113
}
89114

90115
static const struct snd_soc_ops max_98373_sdw_ops = {
91116
.startup = sdw_startup,
92-
.prepare = sdw_prepare,
93-
.trigger = max98373_sdw_trigger,
94-
.hw_free = sdw_hw_free,
117+
.prepare = mx8373_sdw_prepare,
118+
.trigger = sdw_trigger,
119+
.hw_free = mx8373_sdw_hw_free,
95120
.shutdown = sdw_shutdown,
96121
};
97122

0 commit comments

Comments
 (0)