Skip to content

Commit

Permalink
ASoC: Intel: boards: fix xrun issue on platform with max98373
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
RanderWang committed Jun 21, 2021
1 parent b7cd5a3 commit 7badced
Showing 1 changed file with 54 additions and 29 deletions.
83 changes: 54 additions & 29 deletions sound/soc/intel/boards/sof_sdw_max98373.c
Expand Up @@ -55,43 +55,68 @@ static int spk_init(struct snd_soc_pcm_runtime *rtd)
return ret;
}

static int max98373_sdw_trigger(struct snd_pcm_substream *substream, int cmd)
static int max98373_enable_spk_pin(struct snd_pcm_substream *substream, bool enable)
{
int ret;

switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
/* enable max98373 first */
ret = max_98373_trigger(substream, cmd);
if (ret < 0)
break;

ret = sdw_trigger(substream, cmd);
break;
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
ret = sdw_trigger(substream, cmd);
if (ret < 0)
break;

ret = max_98373_trigger(substream, cmd);
break;
default:
ret = -EINVAL;
break;
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
struct snd_soc_dai *codec_dai;
struct snd_soc_dai *cpu_dai;
int j;
int ret = 0;

/* set spk pin by playback only */
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
return 0;

cpu_dai = asoc_rtd_to_cpu(rtd, 0);
for_each_rtd_codec_dais(rtd, j, codec_dai) {
struct snd_soc_dapm_context *dapm =
snd_soc_component_get_dapm(cpu_dai->component);
char pin_name[16];

snprintf(pin_name, ARRAY_SIZE(pin_name), "%s Spk",
codec_dai->component->name_prefix);

if (enable)
ret = snd_soc_dapm_enable_pin(dapm, pin_name);
else
ret = snd_soc_dapm_disable_pin(dapm, pin_name);

if (!ret)
snd_soc_dapm_sync(dapm);
}

return ret;
}

static int max98373_sdw_prepare(struct snd_pcm_substream *substream)
{
int ret = 0;

/* according to soc_pcm_prepare dai link prepare is called first */
ret = sdw_prepare(substream);
if (ret < 0)
return ret;

return max98373_enable_spk_pin(substream, true);
}

static int max98373_hw_free(struct snd_pcm_substream *substream)
{
int ret = 0;

/* according to soc_pcm_hw_free dai link free is called first */
ret = sdw_hw_free(substream);
if (ret < 0)
return ret;

return max98373_enable_spk_pin(substream, false);
}

static const struct snd_soc_ops max_98373_sdw_ops = {
.startup = sdw_startup,
.prepare = sdw_prepare,
.trigger = max98373_sdw_trigger,
.hw_free = sdw_hw_free,
.prepare = max98373_sdw_prepare,
.trigger = sdw_trigger,
.hw_free = max98373_hw_free,
.shutdown = sdw_shutdown,
};

Expand Down

0 comments on commit 7badced

Please sign in to comment.