ASoC: SOF: pcm: simplify sof_pcm_hw_free() with helper
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Tue, 2 Apr 2024 15:18:25 +0000 (10:18 -0500)
committerMark Brown <broonie@kernel.org>
Tue, 2 Apr 2024 16:14:55 +0000 (17:14 +0100)
The same sequence is used twice, use common helper.

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

index 33d576b1764783ab3468591703e0c97106893e9e..7b732f31f97405cfb950df93243bd65b2c52249a 100644 (file)
@@ -196,9 +196,8 @@ static int sof_pcm_hw_free(struct snd_soc_component *component,
 {
        struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
        struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
-       const struct sof_ipc_pcm_ops *pcm_ops = sof_ipc_get_ops(sdev, pcm);
        struct snd_sof_pcm *spcm;
-       int ret, err = 0;
+       int ret;
 
        /* nothing to do for BE */
        if (rtd->dai_link->no_pcm)
@@ -211,36 +210,11 @@ static int sof_pcm_hw_free(struct snd_soc_component *component,
        dev_dbg(component->dev, "pcm: free stream %d dir %d\n",
                spcm->pcm.pcm_id, substream->stream);
 
-       if (spcm->prepared[substream->stream]) {
-               /* stop DMA first if needed */
-               if (pcm_ops && pcm_ops->platform_stop_during_hw_free)
-                       snd_sof_pcm_platform_trigger(sdev, substream, SNDRV_PCM_TRIGGER_STOP);
-
-               /* free PCM in the DSP */
-               if (pcm_ops && pcm_ops->hw_free) {
-                       ret = pcm_ops->hw_free(component, substream);
-                       if (ret < 0)
-                               err = ret;
-               }
-
-               spcm->prepared[substream->stream] = false;
-       }
-
-       /* reset DMA */
-       ret = snd_sof_pcm_platform_hw_free(sdev, substream);
-       if (ret < 0) {
-               dev_err(component->dev, "error: platform hw free failed\n");
-               err = ret;
-       }
-
-       /* free the DAPM widget list */
-       ret = sof_widget_list_free(sdev, spcm, substream->stream);
-       if (ret < 0)
-               err = ret;
+       ret = sof_pcm_stream_free(sdev, substream, spcm, substream->stream, true);
 
        cancel_work_sync(&spcm->stream[substream->stream].period_elapsed_work);
 
-       return err;
+       return ret;
 }
 
 static int sof_pcm_prepare(struct snd_soc_component *component,