ASoC: SOF: pcm: reset all PCM sources in case of xruns
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Tue, 2 Apr 2024 15:18:27 +0000 (10:18 -0500)
committerMark Brown <broonie@kernel.org>
Tue, 2 Apr 2024 16:14:57 +0000 (17:14 +0100)
With the delayed stops, the xrun handling is problematic: the
applications expects everything to be reset but the firmware and DMA
are still in a PAUSED state.

This patch makes sure the prepare while pending_stop is set is
special-cased.

Reviewed-by: Rander Wang <rander.wang@intel.com>
Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com>
Co-developed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://msgid.link/r/20240402151828.175002-17-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/pcm.c

index 2e8782dddc807234922a90b31962a3e96a28f578..7b88e24b7701ee8f71f902c1a88bd5269c15ebba 100644 (file)
@@ -221,6 +221,7 @@ static int sof_pcm_prepare(struct snd_soc_component *component,
                           struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+       struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
        struct snd_sof_pcm *spcm;
        int ret;
 
@@ -232,8 +233,18 @@ static int sof_pcm_prepare(struct snd_soc_component *component,
        if (!spcm)
                return -EINVAL;
 
-       if (spcm->prepared[substream->stream])
-               return 0;
+       if (spcm->prepared[substream->stream]) {
+               if (!spcm->pending_stop[substream->stream])
+                       return 0;
+
+               /*
+                * this case should be reached in case of xruns where we absolutely
+                * want to free-up and reset all PCM/DMA resources
+                */
+               ret = sof_pcm_stream_free(sdev, substream, spcm, substream->stream, true);
+               if (ret < 0)
+                       return ret;
+       }
 
        dev_dbg(component->dev, "pcm: prepare stream %d dir %d\n",
                spcm->pcm.pcm_id, substream->stream);