diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c index af65214836b4d0..88ceb0281ccead 100644 --- a/drivers/soundwire/intel.c +++ b/drivers/soundwire/intel.c @@ -954,9 +954,15 @@ static int intel_component_dais_suspend(struct snd_soc_component *component) struct sdw_cdns_dai_runtime *dai_runtime; dai_runtime = cdns->dai_runtime_array[dai->id]; + if (!dai_runtime) + continue; - if (dai_runtime) - dai_runtime->suspended = true; + /* the stream is kept running during the system suspend */ + if (dai_runtime->stream && + dai_runtime->stream->state == SDW_STREAM_ENABLED) + continue; + + dai_runtime->suspended = true; } return 0; diff --git a/drivers/soundwire/intel.h b/drivers/soundwire/intel.h index 7a2e7e73ad632a..87f1203e74a3b7 100644 --- a/drivers/soundwire/intel.h +++ b/drivers/soundwire/intel.h @@ -78,6 +78,7 @@ struct sdw_intel { struct sdw_intel_link_res *link_res; bool startup_done; struct sdw_intel_bpt bpt_ctx; + bool suspend_bus_retained; #ifdef CONFIG_DEBUG_FS struct dentry *debugfs; #endif diff --git a/drivers/soundwire/intel_ace2x.c b/drivers/soundwire/intel_ace2x.c index 642b33ab552606..bbbc5d7fc64ebf 100644 --- a/drivers/soundwire/intel_ace2x.c +++ b/drivers/soundwire/intel_ace2x.c @@ -953,9 +953,15 @@ static int intel_component_dais_suspend(struct snd_soc_component *component) struct sdw_cdns_dai_runtime *dai_runtime; dai_runtime = cdns->dai_runtime_array[dai->id]; + if (!dai_runtime) + continue; - if (dai_runtime) - dai_runtime->suspended = true; + /* the stream is kept running during the system suspend */ + if (dai_runtime->stream && + dai_runtime->stream->state == SDW_STREAM_ENABLED) + continue; + + dai_runtime->suspended = true; } return 0; diff --git a/drivers/soundwire/intel_auxdevice.c b/drivers/soundwire/intel_auxdevice.c index 5983fbc5725a26..8d7e8b116a4373 100644 --- a/drivers/soundwire/intel_auxdevice.c +++ b/drivers/soundwire/intel_auxdevice.c @@ -650,6 +650,20 @@ static int __maybe_unused intel_suspend(struct device *dev) return 0; } + /* + * The sound card is suspended before the SoundWire links and the + * streams which are not kept running are disabled by then: a stream + * is only enabled while it is running and the card's suspend disables + * all the running streams except the ones kept running during the + * system suspend. Do not stop the bus under an enabled stream. + */ + sdw->suspend_bus_retained = sdw_bus_has_enabled_stream(bus); + if (sdw->suspend_bus_retained) { + dev_dbg(dev, "SoundWire master %d is kept active during system suspend\n", + bus->link_id); + return 0; + } + /* Prevent runtime PM from racing with the code below. */ pm_runtime_disable(dev); @@ -737,6 +751,13 @@ static int __maybe_unused intel_resume(struct device *dev) return 0; } + if (sdw->suspend_bus_retained) { + sdw->suspend_bus_retained = false; + dev_dbg(dev, "SoundWire master %d remained active during system suspend\n", + bus->link_id); + return 0; + } + ret = sdw_intel_link_power_up(sdw); if (ret) { dev_err(dev, "%s failed: %d\n", __func__, ret); diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c index 06a0d89a944378..f7bc6f277dedaf 100644 --- a/drivers/soundwire/stream.c +++ b/drivers/soundwire/stream.c @@ -1690,6 +1690,27 @@ int sdw_enable_stream(struct sdw_stream_runtime *stream) } EXPORT_SYMBOL(sdw_enable_stream); +/** + * sdw_bus_has_enabled_stream() - Check if the bus carries an enabled stream + * + * @bus: SDW bus instance + * + * Return: true if at least one stream on the bus is in ENABLED state + */ +bool sdw_bus_has_enabled_stream(struct sdw_bus *bus) +{ + struct sdw_master_runtime *m_rt; + + guard(mutex)(&bus->bus_lock); + list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) { + if (m_rt->stream->state == SDW_STREAM_ENABLED) + return true; + } + + return false; +} +EXPORT_SYMBOL(sdw_bus_has_enabled_stream); + static int _sdw_disable_stream(struct sdw_stream_runtime *stream) { struct sdw_master_runtime *m_rt; diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h index 9e71ae68e9d927..6a049d674b3a61 100644 --- a/include/linux/soundwire/sdw.h +++ b/include/linux/soundwire/sdw.h @@ -1084,6 +1084,7 @@ int sdw_stream_remove_master(struct sdw_bus *bus, int sdw_startup_stream(void *sdw_substream); int sdw_prepare_stream(struct sdw_stream_runtime *stream); int sdw_enable_stream(struct sdw_stream_runtime *stream); +bool sdw_bus_has_enabled_stream(struct sdw_bus *bus); int sdw_disable_stream(struct sdw_stream_runtime *stream); int sdw_deprepare_stream(struct sdw_stream_runtime *stream); void sdw_shutdown_stream(void *sdw_substream); diff --git a/sound/soc/sof/core.c b/sound/soc/sof/core.c index 1f38fe03e49395..37fca4c37d59bc 100644 --- a/sound/soc/sof/core.c +++ b/sound/soc/sof/core.c @@ -690,6 +690,7 @@ int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data) INIT_LIST_HEAD(&sdev->dai_list); INIT_LIST_HEAD(&sdev->dai_link_list); INIT_LIST_HEAD(&sdev->route_list); + INIT_LIST_HEAD(&sdev->ignore_suspend_widget_list); INIT_LIST_HEAD(&sdev->ipc_client_list); INIT_LIST_HEAD(&sdev->ipc_rx_handler_list); INIT_LIST_HEAD(&sdev->fw_state_handler_list); diff --git a/sound/soc/sof/intel/hda-dai.c b/sound/soc/sof/intel/hda-dai.c index 7a8875a885ab34..c8729b6d82bd4b 100644 --- a/sound/soc/sof/intel/hda-dai.c +++ b/sound/soc/sof/intel/hda-dai.c @@ -135,9 +135,6 @@ hda_link_dma_cleanup(struct snd_pcm_substream *substream, if (!hlink) return -EINVAL; - hda_stream = hstream_to_sof_hda_stream(hext_stream); - hda_stream->suspend_ignored = false; - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { stream_tag = hdac_stream(hext_stream)->stream_tag; snd_hdac_ext_bus_link_clear_stream_id(hlink, stream_tag); @@ -160,6 +157,7 @@ hda_link_dma_cleanup(struct snd_pcm_substream *substream, hext_stream->link_prepared = 0; /* free the host DMA channel reserved by hostless streams */ + hda_stream = hstream_to_sof_hda_stream(hext_stream); hda_stream->host_reserved = 0; return 0; @@ -282,32 +280,6 @@ static int __maybe_unused hda_dai_hw_params(struct snd_pcm_substream *substream, return hda_dai_hw_params_data(substream, params, dai, &data, flags); } -static bool hda_dai_has_wov_fe(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream) -{ - struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); - struct snd_soc_dpcm *dpcm; - struct snd_sof_pcm *spcm; - - if (substream->stream != SNDRV_PCM_STREAM_CAPTURE) - return false; - - /* - * Only retain the BE for a connected WoV capture FE that is running - * or has already ignored its suspend trigger. An idle WoV FE may - * still be connected to the BE. - */ - for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_CAPTURE, dpcm) { - spcm = snd_sof_find_spcm_dai(sdev->component, dpcm->fe); - if (spcm && spcm->stream[SNDRV_PCM_STREAM_CAPTURE].d0i3_compatible && - spcm->stream[SNDRV_PCM_STREAM_CAPTURE].dsp_max_burst_size_in_ms <= 1 && - (dpcm->fe->dpcm[SNDRV_PCM_STREAM_CAPTURE].state == SND_SOC_DPCM_STATE_START || - spcm->stream[SNDRV_PCM_STREAM_CAPTURE].suspend_ignored)) - return true; - } - - return false; -} - /* * In contrast to IPC3, the dai trigger in IPC4 mixes pipeline state changes * (over IPC channel) and DMA state change (direct host register changes). @@ -317,7 +289,6 @@ static int __maybe_unused hda_dai_trigger(struct snd_pcm_substream *substream, i { const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, dai); struct hdac_ext_stream *hext_stream; - struct sof_intel_hda_stream *hda_stream; struct snd_sof_dev *sdev; int ret; @@ -334,24 +305,6 @@ static int __maybe_unused hda_dai_trigger(struct snd_pcm_substream *substream, i hext_stream = ops->get_hext_stream(sdev, dai, substream); if (!hext_stream) return -EINVAL; - hda_stream = hstream_to_sof_hda_stream(hext_stream); - - if (cmd == SNDRV_PCM_TRIGGER_RESUME && hda_stream->suspend_ignored) { - hda_stream->suspend_ignored = false; - return 0; - } - - /* - * Set the suspend_ignored flag for BE which is used with - * D0I3-compatible streams used for WoV to keep the firmware pipeline - * running. - */ - if (cmd == SNDRV_PCM_TRIGGER_SUSPEND && - sdev->system_suspend_target == SOF_SUSPEND_S0IX && - hda_dai_has_wov_fe(sdev, substream)) { - hda_stream->suspend_ignored = true; - return 0; - } if (ops->pre_trigger) { ret = ops->pre_trigger(sdev, dai, substream, cmd); diff --git a/sound/soc/sof/intel/hda-dsp.c b/sound/soc/sof/intel/hda-dsp.c index ec49aeaa9bd7af..ed4def3175f9de 100644 --- a/sound/soc/sof/intel/hda-dsp.c +++ b/sound/soc/sof/intel/hda-dsp.c @@ -793,8 +793,8 @@ EXPORT_SYMBOL_NS(hda_dsp_set_power_state_ipc4, "SND_SOC_SOF_INTEL_HDA_COMMON"); * +----------------------------+ +----------------+ * * S0IX suspend: The DSP is in D0I3 if any D0I3-compatible streams - * ignored the suspend trigger. Otherwise the DSP - * is in D3. + * are kept running during the suspend. Otherwise the + * DSP is in D3. */ static int hda_suspend(struct snd_sof_dev *sdev, bool runtime_suspend) diff --git a/sound/soc/sof/intel/hda-pcm.c b/sound/soc/sof/intel/hda-pcm.c index 70abff12fef0ee..83efc9bdf418af 100644 --- a/sound/soc/sof/intel/hda-pcm.c +++ b/sound/soc/sof/intel/hda-pcm.c @@ -352,20 +352,6 @@ int hda_dsp_pcm_open(struct snd_sof_dev *sdev, spcm->stream[substream->stream].d0i3_compatible) flags |= SOF_HDA_STREAM_DMI_L1_COMPATIBLE; - /* - * Set the RESUME supported flag for WoV streams. The core will ignore - * the trigger but applications must not try to restart the WoV stream - * due to not supported RESUME. - * WoV streams can be indetified by: - * They are capture streams and - * They have the d0i3_compatible flag set and - * They don't use Deep Buffer - */ - if (direction == SNDRV_PCM_STREAM_CAPTURE && - spcm->stream[substream->stream].d0i3_compatible && - spcm->stream[substream->stream].dsp_max_burst_size_in_ms <= 1) - runtime->hw.info |= SNDRV_PCM_INFO_RESUME; - dsp_stream = hda_dsp_stream_get(sdev, direction, flags); if (!dsp_stream) { dev_err(sdev->dev, "error: no stream available\n"); diff --git a/sound/soc/sof/intel/hda.h b/sound/soc/sof/intel/hda.h index bc11519427649f..701578ec35cf4d 100644 --- a/sound/soc/sof/intel/hda.h +++ b/sound/soc/sof/intel/hda.h @@ -601,7 +601,6 @@ struct sof_intel_hda_stream { struct hdac_ext_stream hext_stream; struct sof_intel_stream sof_intel_stream; int host_reserved; /* reserve host DMA channel */ - bool suspend_ignored; u32 flags; struct completion ioc; }; diff --git a/sound/soc/sof/pcm.c b/sound/soc/sof/pcm.c index 0161c0ae8bbdb4..db2b8744d20377 100644 --- a/sound/soc/sof/pcm.c +++ b/sound/soc/sof/pcm.c @@ -269,7 +269,11 @@ int sof_pcm_free_all_streams(struct snd_sof_dev *sdev) for_each_pcm_streams(dir) { substream = spcm->stream[dir].substream; - if (!substream || !substream->runtime || + if (!substream || !substream->runtime) + continue; + + /* skip the streams kept running during S0ix */ + if (sdev->system_suspend_target == SOF_SUSPEND_S0IX && spcm->stream[dir].suspend_ignored) continue; @@ -285,6 +289,274 @@ int sof_pcm_free_all_streams(struct snd_sof_dev *sdev) return 0; } +/* + * Check if the stream can be kept running with the DSP in D0i3 during S0ix. + * + * Only Wake-on-Voice (WoV) streams can be kept running. A WoV stream is: + * a capture stream, + * the CAPTURE_COMPATIBLE_D0I3 is set for the PCM, + * it is not a Deep Buffer stream. + * + * Historically the CAPTURE_COMPATIBLE_D0I3 token was added to mark the WoV + * stream with IPC3. With IPC4 the COMPATIBLE_D0I3 tokens are also used to mark + * the Deep Buffer streams, which can not be kept running. + */ +static bool sof_pcm_stream_can_ignore_suspend(struct snd_sof_pcm *spcm, int dir) +{ + return dir == SNDRV_PCM_STREAM_CAPTURE && + spcm->stream[dir].d0i3_compatible && + spcm->stream[dir].dsp_max_burst_size_in_ms <= 1; +} + +static bool sof_pcm_stream_is_running(struct snd_pcm_substream *substream) +{ + bool running; + + snd_pcm_stream_lock_irq(substream); + running = substream->runtime->state == SNDRV_PCM_STATE_RUNNING; + snd_pcm_stream_unlock_irq(substream); + + return running; +} + +/* DAPM widget with ignore_suspend set by sof_pcm_suspend_prepare() */ +struct sof_pcm_ignore_suspend_widget { + struct snd_soc_dapm_widget *widget; + bool initial_ignore_suspend; + struct list_head list; +}; + +/* must be called with the DAPM mutex of the card held */ +static int sof_pcm_widget_set_ignore_suspend(struct snd_sof_dev *sdev, + struct snd_soc_dapm_widget *w) +{ + struct sof_pcm_ignore_suspend_widget *isw; + + list_for_each_entry(isw, &sdev->ignore_suspend_widget_list, list) { + if (isw->widget == w) + return 0; + } + + isw = kzalloc(sizeof(*isw), GFP_KERNEL); + if (!isw) + return -ENOMEM; + + isw->widget = w; + isw->initial_ignore_suspend = w->ignore_suspend; + list_add_tail(&isw->list, &sdev->ignore_suspend_widget_list); + + w->ignore_suspend = 1; + dev_dbg(sdev->dev, "ignore suspend for widget %s\n", w->name); + + return 0; +} + +/** + * sof_pcm_dapm_restore_ignore_suspend - restore the DAPM widgets + * @sdev: SOF device + * @restore: restore the ignore_suspend flag of the widgets + * + * Restore the initial ignore_suspend flag of the widgets which was set by + * sof_pcm_dapm_set_ignore_suspend(). If @restore is false, only the tracking + * list is freed, the widgets are not touched. + */ +static void sof_pcm_dapm_restore_ignore_suspend(struct snd_sof_dev *sdev, + bool restore) +{ + struct sof_pcm_ignore_suspend_widget *isw, *tmp; + + if (list_empty(&sdev->ignore_suspend_widget_list)) + return; + + if (restore) + snd_soc_dapm_mutex_lock(sdev->component->card); + + list_for_each_entry_safe(isw, tmp, &sdev->ignore_suspend_widget_list, list) { + if (restore) + isw->widget->ignore_suspend = isw->initial_ignore_suspend; + + list_del(&isw->list); + kfree(isw); + } + + if (restore) + snd_soc_dapm_mutex_unlock(sdev->component->card); +} + +/* + * The sound card is moved to D3hot during system suspend and DAPM powers down + * all paths unless their endpoints are marked with ignore_suspend. + * Set the ignore_suspend flag for the FE DAI widget and for all the endpoints + * connected to it to keep the path of the stream powered. + */ +static int sof_pcm_dapm_set_ignore_suspend(struct snd_sof_dev *sdev, + struct snd_soc_pcm_runtime *rtd, int dir) +{ + struct snd_soc_dai *dai; + int i; + + for_each_rtd_cpu_dais(rtd, i, dai) { + struct snd_soc_dapm_widget_list *list = NULL; + struct snd_soc_dapm_widget *w; + int j, ret; + + ret = snd_soc_dapm_dai_get_connected_widgets(dai, dir, &list, NULL); + if (ret < 0) { + snd_soc_dapm_dai_free_widgets(&list); + return ret; + } + + snd_soc_dapm_mutex_lock(rtd->card); + + w = snd_soc_dai_get_widget(dai, dir); + ret = w ? sof_pcm_widget_set_ignore_suspend(sdev, w) : 0; + + for_each_dapm_widgets(list, j, w) { + if (ret) + break; + + if (w->is_ep) + ret = sof_pcm_widget_set_ignore_suspend(sdev, w); + } + + snd_soc_dapm_mutex_unlock(rtd->card); + snd_soc_dapm_dai_free_widgets(&list); + + if (ret) + return ret; + } + + return 0; +} + +/** + * sof_pcm_suspend_prepare - select the streams to keep running over suspend + * @sdev: SOF device + * + * Called from the PM prepare callback, before the sound card is suspended. + * + * When the system is entering S0ix, the running streams which can work with + * the DSP in D0i3 are kept running. The ignore_suspend flag is set for their + * FE dai_link, which makes ASoC to skip the suspend of the PCM: there is no + * SUSPEND trigger for the FE and the BEs and the stream stays in RUNNING + * state. Userspace does not need to resume or restart the stream and a stop + * or close after the system resume is handled as a normal STOP. + * + * The suspend_ignored flag of these streams tells the PM code that the DSP + * must stay in D0 and that the pipelines of the stream must not be freed. The + * flag is cleared when the stream is stopped or paused or on the next system + * suspend. + * + * The DAPM endpoints of the streams are marked with ignore_suspend to keep + * their paths powered. The widgets are restored on the next system suspend, + * the flag has no effect while the card is powered. + * + * If the DAPM path of a stream can not be kept powered, none of the streams are + * kept running and all of them are suspended normally. + */ +void sof_pcm_suspend_prepare(struct snd_sof_dev *sdev) +{ + struct snd_sof_pcm *spcm; + int dir, ret; + + /* restore the DAPM widgets from the previous system suspend */ + sof_pcm_dapm_restore_ignore_suspend(sdev, true); + + list_for_each_entry(spcm, &sdev->pcm_list, list) { + struct snd_soc_pcm_runtime *rtd = NULL; + bool keep_running = false; + bool must_suspend = false; + + for_each_pcm_streams(dir) { + struct snd_pcm_substream *substream = spcm->stream[dir].substream; + + spcm->stream[dir].suspend_ignored = false; + + if (!substream || !substream->runtime) + continue; + + rtd = snd_soc_substream_to_rtd(substream); + + if (!sof_pcm_stream_is_running(substream)) + continue; + + if (sdev->system_suspend_target == SOF_SUSPEND_S0IX && + !sdev->dspless_mode_selected && + sof_pcm_stream_can_ignore_suspend(spcm, dir)) { + spcm->stream[dir].suspend_ignored = true; + keep_running = true; + } else { + must_suspend = true; + } + } + + if (!keep_running) + continue; + + /* + * The ignore_suspend flag is per dai_link, it affects both + * directions of the PCM. + */ + if (must_suspend) { + spcm_dbg(spcm, SNDRV_PCM_STREAM_CAPTURE, + "the PCM has a stream which must be suspended\n"); + for_each_pcm_streams(dir) + spcm->stream[dir].suspend_ignored = false; + continue; + } + + for_each_pcm_streams(dir) { + if (!spcm->stream[dir].suspend_ignored) + continue; + + ret = sof_pcm_dapm_set_ignore_suspend(sdev, rtd, dir); + if (ret) { + spcm_err(spcm, dir, + "failed to keep the DAPM path powered: %d\n", + ret); + goto err; + } + } + + if (rtd->dai_link->ignore_suspend) + continue; + + rtd->dai_link->ignore_suspend = 1; + spcm->ignore_suspend_link = rtd->dai_link; + } + + return; + +err: + list_for_each_entry(spcm, &sdev->pcm_list, list) { + for_each_pcm_streams(dir) + spcm->stream[dir].suspend_ignored = false; + } + + sof_pcm_suspend_complete(sdev); + sof_pcm_dapm_restore_ignore_suspend(sdev, true); +} + +/** + * sof_pcm_suspend_complete - restore the FE dai_links after a system suspend + * @sdev: SOF device + * + * Called from the PM complete callback, clears the ignore_suspend flag of the + * dai_links which was set by sof_pcm_suspend_prepare(). + */ +void sof_pcm_suspend_complete(struct snd_sof_dev *sdev) +{ + struct snd_sof_pcm *spcm; + + list_for_each_entry(spcm, &sdev->pcm_list, list) { + if (!spcm->ignore_suspend_link) + continue; + + spcm->ignore_suspend_link->ignore_suspend = 0; + spcm->ignore_suspend_link = NULL; + } +} + static int sof_pcm_hw_free(struct snd_soc_component *component, struct snd_pcm_substream *substream) { @@ -408,6 +680,8 @@ static int sof_pcm_trigger(struct snd_soc_component *component, switch (cmd) { case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + /* the stream is paused, it is no longer kept running */ + spcm->stream[substream->stream].suspend_ignored = false; ipc_first = true; break; case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: @@ -415,48 +689,18 @@ static int sof_pcm_trigger(struct snd_soc_component *component, ipc_first = true; break; case SNDRV_PCM_TRIGGER_START: - if (spcm->stream[substream->stream].suspend_ignored) { - /* - * This case will be triggered when INFO_RESUME is - * not supported, no need to re-start streams that - * remained enabled in D0ix. - */ - spcm->stream[substream->stream].suspend_ignored = false; - return 0; - } - if (pcm_ops && pcm_ops->ipc_first_on_start) ipc_first = true; break; - case SNDRV_PCM_TRIGGER_RESUME: - if (spcm->stream[substream->stream].suspend_ignored) { - spcm->stream[substream->stream].suspend_ignored = false; - return 0; - } - spcm_err(spcm, substream->stream, "RESUME trigger is not supported\n"); - return -EINVAL; case SNDRV_PCM_TRIGGER_SUSPEND: - /* - * Set the suspend_ignored flag for D0I3-compatible streams used - * for WoV to keep the firmware pipeline running. - * WoV streams can be indetified by: - * They are capture streams and - * They have the d0i3_compatible flag set and - * They don't use Deep Buffer - */ - if (sdev->system_suspend_target == SOF_SUSPEND_S0IX && - substream->stream == SNDRV_PCM_STREAM_CAPTURE && - spcm->stream[substream->stream].d0i3_compatible && - spcm->stream[substream->stream].dsp_max_burst_size_in_ms <= 1) { - spcm->stream[substream->stream].suspend_ignored = true; - return 0; - } /* On suspend the DMA must be stopped in DSPless mode */ if (sdev->dspless_mode_selected) reset_hw_params = true; fallthrough; case SNDRV_PCM_TRIGGER_STOP: + /* the stream is stopped, it is no longer kept running */ + spcm->stream[substream->stream].suspend_ignored = false; ipc_first = true; if (pcm_ops && pcm_ops->reset_hw_params_during_stop) reset_hw_params = true; @@ -808,6 +1052,11 @@ static int sof_pcm_probe(struct snd_soc_component *component) static void sof_pcm_remove(struct snd_soc_component *component) { + struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component); + + /* the widgets might be already freed, do not restore them */ + sof_pcm_dapm_restore_ignore_suspend(sdev, false); + /* remove topology */ snd_soc_tplg_component_remove(component); } diff --git a/sound/soc/sof/pm.c b/sound/soc/sof/pm.c index b5d239b12e59d2..43011566a44787 100644 --- a/sound/soc/sof/pm.c +++ b/sound/soc/sof/pm.c @@ -38,7 +38,7 @@ static u32 snd_sof_dsp_power_target(struct snd_sof_dev *sdev) case SOF_SUSPEND_S0IX: /* * Currently, the only criterion for retaining the DSP in D0 - * is that there are streams that ignored the suspend trigger. + * is that there are streams kept running during the suspend. * Additional criteria such Soundwire clock-stop mode and * device suspend latency considerations will be added later. */ @@ -248,8 +248,7 @@ static int sof_suspend(struct device *dev, bool runtime_suspend) * suspended, it is brought back to full power and then * suspended again */ - if (tplg_ops && tplg_ops->tear_down_all_pipelines && (old_state == SOF_DSP_PM_D0) && - (target_state != SOF_DSP_PM_D0)) + if (tplg_ops && tplg_ops->tear_down_all_pipelines && (old_state == SOF_DSP_PM_D0)) tplg_ops->tear_down_all_pipelines(sdev, false); if (sdev->fw_state != SOF_FW_BOOT_COMPLETE) @@ -374,9 +373,8 @@ int snd_sof_suspend(struct device *dev) } EXPORT_SYMBOL(snd_sof_suspend); -int snd_sof_prepare(struct device *dev) +static void sof_set_system_suspend_target(struct snd_sof_dev *sdev) { - struct snd_sof_dev *sdev = dev_get_drvdata(dev); const struct sof_dev_desc *desc = sdev->pdata->desc; /* will suspend to S3 by default */ @@ -388,10 +386,10 @@ int snd_sof_prepare(struct device *dev) */ if (sdev->fw_state == SOF_FW_CRASHED || sdev->fw_state == SOF_FW_BOOT_FAILED) - return 0; + return; if (!desc->use_acpi_target_states) - return 0; + return; #if defined(CONFIG_ACPI) switch (acpi_target_system_state()) { @@ -413,6 +411,19 @@ int snd_sof_prepare(struct device *dev) break; } #endif +} + +int snd_sof_prepare(struct device *dev) +{ + struct snd_sof_dev *sdev = dev_get_drvdata(dev); + + sof_set_system_suspend_target(sdev); + + /* + * Select the streams to be kept running during the system suspend. + * This must be done before the sound card is suspended. + */ + sof_pcm_suspend_prepare(sdev); return 0; } @@ -422,6 +433,7 @@ void snd_sof_complete(struct device *dev) { struct snd_sof_dev *sdev = dev_get_drvdata(dev); + sof_pcm_suspend_complete(sdev); sdev->system_suspend_target = SOF_SUSPEND_NONE; } EXPORT_SYMBOL(snd_sof_complete); diff --git a/sound/soc/sof/sof-audio.h b/sound/soc/sof/sof-audio.h index 10b41ab18b7990..ca52c3fa8a8f6f 100644 --- a/sound/soc/sof/sof-audio.h +++ b/sound/soc/sof/sof-audio.h @@ -342,8 +342,8 @@ struct snd_sof_pcm_stream { bool pause_supported; /* PCM device supports PAUSE operation */ unsigned int dsp_max_burst_size_in_ms; /* The maximum size of the host DMA burst in ms */ /* - * flag to indicate that the DSP pipelines should be kept - * active or not while suspending the stream + * flag to indicate that the stream is kept running and the DSP + * pipelines should be kept active during system suspend */ bool suspend_ignored; struct snd_sof_pcm_stream_pipeline_list pipeline_list; @@ -364,6 +364,8 @@ struct snd_sof_pcm { bool setup_done[2]; /* the setup of the SOF PCM device is done */ bool pending_stop[2]; /* only used if (!pcm_ops->platform_stop_during_hw_free) */ bool compr_started[2]; /* compress stream has been started */ + /* FE dai_link with ignore_suspend set by sof_pcm_suspend_prepare() */ + struct snd_soc_dai_link *ignore_suspend_link; /* Must be last - ends in a flex-array member. */ struct snd_soc_tplg_pcm pcm; @@ -709,6 +711,8 @@ int sof_widget_list_free(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int int sof_pcm_dsp_pcm_free(struct snd_pcm_substream *substream, struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm); int sof_pcm_free_all_streams(struct snd_sof_dev *sdev); +void sof_pcm_suspend_prepare(struct snd_sof_dev *sdev); +void sof_pcm_suspend_complete(struct snd_sof_dev *sdev); int get_token_u32(void *elem, void *object, u32 offset); int get_token_u16(void *elem, void *object, u32 offset); int get_token_comp_format(void *elem, void *object, u32 offset); diff --git a/sound/soc/sof/sof-priv.h b/sound/soc/sof/sof-priv.h index 83e4d83cc27cbb..1987ea3e02c51a 100644 --- a/sound/soc/sof/sof-priv.h +++ b/sound/soc/sof/sof-priv.h @@ -653,6 +653,8 @@ struct snd_sof_dev { struct list_head dai_list; struct list_head dai_link_list; struct list_head route_list; + /* DAPM widgets with ignore_suspend set by sof_pcm_suspend_prepare() */ + struct list_head ignore_suspend_widget_list; struct snd_soc_component *component; u32 enabled_cores_mask; /* keep track of enabled cores */ bool led_present;