ASoC: SOF: handle paused streams during system suspend
authorRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Tue, 23 Nov 2021 17:16:06 +0000 (19:16 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Jan 2022 11:03:04 +0000 (12:03 +0100)
commit 96da174024b9c63bd5d3358668d0bc12677be877 upstream.

During system suspend, paused streams do not get suspended.
Therefore, we need to explicitly free these PCMs in the DSP
and free the associated DAPM widgets so that they can be set
up again during resume.

Fixes: 5fcdbb2d45df ("ASoC: SOF: Add support for dynamic pipelines")
Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Paul Olaru <paul.olaru@oss.nxp.com>
Reviewed-by: Bard Liao <bard.liao@intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Link: https://lore.kernel.org/r/20211123171606.129350-3-kai.vehmanen@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
sound/soc/sof/pcm.c
sound/soc/sof/sof-audio.c
sound/soc/sof/sof-audio.h

index fa0bfcd2474e0b9800f8ee6a4e570a540f331d4d..216a1f576fc8517f1c042e274e1aa2451c9ec613 100644 (file)
@@ -100,9 +100,8 @@ void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream)
 }
 EXPORT_SYMBOL(snd_sof_pcm_period_elapsed);
 
-static int sof_pcm_dsp_pcm_free(struct snd_pcm_substream *substream,
-                               struct snd_sof_dev *sdev,
-                               struct snd_sof_pcm *spcm)
+int sof_pcm_dsp_pcm_free(struct snd_pcm_substream *substream, struct snd_sof_dev *sdev,
+                        struct snd_sof_pcm *spcm)
 {
        struct sof_ipc_stream stream;
        struct sof_ipc_reply reply;
index a4c9806d294e3f9350fe17ee05bf2cb8e446db45..ddd993351ce143113a9963361334af18dafaf4a3 100644 (file)
@@ -122,6 +122,14 @@ int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
        case snd_soc_dapm_buffer:
                ipc_free.hdr.cmd |= SOF_IPC_TPLG_BUFFER_FREE;
                break;
+       case snd_soc_dapm_dai_in:
+       case snd_soc_dapm_dai_out:
+       {
+               struct snd_sof_dai *dai = swidget->private;
+
+               dai->configured = false;
+               fallthrough;
+       }
        default:
                ipc_free.hdr.cmd |= SOF_IPC_TPLG_COMP_FREE;
                break;
@@ -679,6 +687,55 @@ int sof_set_up_pipelines(struct snd_sof_dev *sdev, bool verify)
        return 0;
 }
 
+/*
+ * Free the PCM, its associated widgets and set the prepared flag to false for all PCMs that
+ * did not get suspended(ex: paused streams) so the widgets can be set up again during resume.
+ */
+static int sof_tear_down_left_over_pipelines(struct snd_sof_dev *sdev)
+{
+       struct snd_sof_widget *swidget;
+       struct snd_sof_pcm *spcm;
+       int dir, ret;
+
+       /*
+        * free all PCMs and their associated DAPM widgets if their connected DAPM widget
+        * list is not NULL. This should only be true for paused streams at this point.
+        * This is equivalent to the handling of FE DAI suspend trigger for running streams.
+        */
+       list_for_each_entry(spcm, &sdev->pcm_list, list)
+               for_each_pcm_streams(dir) {
+                       struct snd_pcm_substream *substream = spcm->stream[dir].substream;
+
+                       if (!substream || !substream->runtime)
+                               continue;
+
+                       if (spcm->stream[dir].list) {
+                               ret = sof_pcm_dsp_pcm_free(substream, sdev, spcm);
+                               if (ret < 0)
+                                       return ret;
+
+                               ret = sof_widget_list_free(sdev, spcm, dir);
+                               if (ret < 0) {
+                                       dev_err(sdev->dev, "failed to free widgets during suspend\n");
+                                       return ret;
+                               }
+                       }
+               }
+
+       /*
+        * free any left over DAI widgets. This is equivalent to the handling of suspend trigger
+        * for the BE DAI for running streams.
+        */
+       list_for_each_entry(swidget, &sdev->widget_list, list)
+               if (WIDGET_IS_DAI(swidget->id) && swidget->use_count == 1) {
+                       ret = sof_widget_free(sdev, swidget);
+                       if (ret < 0)
+                               return ret;
+               }
+
+       return 0;
+}
+
 /*
  * For older firmware, this function doesn't free widgets for static pipelines during suspend.
  * It only resets use_count for all widgets.
@@ -693,8 +750,8 @@ int sof_tear_down_pipelines(struct snd_sof_dev *sdev, bool verify)
        /*
         * This function is called during suspend and for one-time topology verification during
         * first boot. In both cases, there is no need to protect swidget->use_count and
-        * sroute->setup because during suspend all streams are suspended and during topology
-        * loading the sound card unavailable to open PCMs.
+        * sroute->setup because during suspend all running streams are suspended and during
+        * topology loading the sound card unavailable to open PCMs.
         */
        list_for_each_entry(swidget, &sdev->widget_list, list) {
                if (swidget->dynamic_pipeline_widget)
@@ -713,6 +770,19 @@ int sof_tear_down_pipelines(struct snd_sof_dev *sdev, bool verify)
                        return ret;
        }
 
+       /*
+        * Tear down all pipelines associated with PCMs that did not get suspended
+        * and unset the prepare flag so that they can be set up again during resume.
+        * Skip this step for older firmware.
+        */
+       if (!verify && v->abi_version >= SOF_ABI_VER(3, 19, 0)) {
+               ret = sof_tear_down_left_over_pipelines(sdev);
+               if (ret < 0) {
+                       dev_err(sdev->dev, "failed to tear down paused pipelines\n");
+                       return ret;
+               }
+       }
+
        list_for_each_entry(sroute, &sdev->route_list, list)
                sroute->setup = false;
 
index 6c591b7a531c6a94c410b693ca2340a17b2de9ef..faa4f36ef0d16f239e65a27bfcc5cd13bc3442ba 100644 (file)
@@ -267,4 +267,6 @@ int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
 /* PCM */
 int sof_widget_list_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir);
 int sof_widget_list_free(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir);
+int sof_pcm_dsp_pcm_free(struct snd_pcm_substream *substream, struct snd_sof_dev *sdev,
+                        struct snd_sof_pcm *spcm);
 #endif