ASoC: soc-dapm: add snd_soc_dapm_stream_stop()
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Fri, 10 Jan 2020 02:36:23 +0000 (11:36 +0900)
committerMark Brown <broonie@kernel.org>
Fri, 10 Jan 2020 13:33:53 +0000 (13:33 +0000)
When we stop stream, if it was Playback, we might need to care
about power down time. In such case, we need to use delayed work.

We have same implementation for it at soc-pcm.c and soc-compress.c,
but we don't want to have duplicate code.
This patch adds snd_soc_dapm_stream_stop(), and share same code.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-By: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/871rs8t4uw.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
include/sound/soc-dapm.h
sound/soc/soc-compress.c
sound/soc/soc-dapm.c
sound/soc/soc-pcm.c

index 6e8a312253838a9efd18879795648a9f44b89d19..1b6afbc1a4ed10676c0bc188b1065d1936c2427c 100644 (file)
@@ -434,6 +434,7 @@ void snd_soc_dapm_reset_cache(struct snd_soc_dapm_context *dapm);
 /* dapm events */
 void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
        int event);
+void snd_soc_dapm_stream_stop(struct snd_soc_pcm_runtime *rtd, int stream);
 void snd_soc_dapm_shutdown(struct snd_soc_card *card);
 
 /* external DAPM widget events */
index 72494717dde301b1803c84c27a2daa5e7bf32a39..392a1c5b15d3240e9afa17550c2bb35d100c8b36 100644 (file)
@@ -259,23 +259,7 @@ static int soc_compr_free(struct snd_compr_stream *cstream)
        if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
                cpu_dai->driver->cops->shutdown(cstream, cpu_dai);
 
-       if (cstream->direction == SND_COMPRESS_PLAYBACK) {
-               if (snd_soc_runtime_ignore_pmdown_time(rtd)) {
-                       snd_soc_dapm_stream_event(rtd,
-                                                 SNDRV_PCM_STREAM_PLAYBACK,
-                                                 SND_SOC_DAPM_STREAM_STOP);
-               } else {
-                       rtd->pop_wait = 1;
-                       queue_delayed_work(system_power_efficient_wq,
-                                          &rtd->delayed_work,
-                                          msecs_to_jiffies(rtd->pmdown_time));
-               }
-       } else {
-               /* capture streams can be powered down now */
-               snd_soc_dapm_stream_event(rtd,
-                                         SNDRV_PCM_STREAM_CAPTURE,
-                                         SND_SOC_DAPM_STREAM_STOP);
-       }
+       snd_soc_dapm_stream_stop(rtd, stream);
 
        mutex_unlock(&rtd->card->pcm_mutex);
 
index b6378f025836c6b7c91cd6c1f476afbecaa5e81e..442846f12cd4307007405567567ecada54008067 100644 (file)
@@ -4447,6 +4447,29 @@ void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
        mutex_unlock(&card->dapm_mutex);
 }
 
+void snd_soc_dapm_stream_stop(struct snd_soc_pcm_runtime *rtd, int stream)
+{
+       if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
+               if (snd_soc_runtime_ignore_pmdown_time(rtd)) {
+                       /* powered down playback stream now */
+                       snd_soc_dapm_stream_event(rtd,
+                                                 SNDRV_PCM_STREAM_PLAYBACK,
+                                                 SND_SOC_DAPM_STREAM_STOP);
+               } else {
+                       /* start delayed pop wq here for playback streams */
+                       rtd->pop_wait = 1;
+                       queue_delayed_work(system_power_efficient_wq,
+                                          &rtd->delayed_work,
+                                          msecs_to_jiffies(rtd->pmdown_time));
+               }
+       } else {
+               /* capture streams can be powered down now */
+               snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE,
+                                         SND_SOC_DAPM_STREAM_STOP);
+       }
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_stop);
+
 /**
  * snd_soc_dapm_enable_pin_unlocked - enable pin.
  * @dapm: DAPM context
index ad908e008b2fb75d9f6633419c93ea396a5d35d0..dfff2ddb469ad48ccb9dd075681c40ee36c7981e 100644 (file)
@@ -672,24 +672,7 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
 
        soc_pcm_components_close(substream, NULL);
 
-       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
-               if (snd_soc_runtime_ignore_pmdown_time(rtd)) {
-                       /* powered down playback stream now */
-                       snd_soc_dapm_stream_event(rtd,
-                                                 SNDRV_PCM_STREAM_PLAYBACK,
-                                                 SND_SOC_DAPM_STREAM_STOP);
-               } else {
-                       /* start delayed pop wq here for playback streams */
-                       rtd->pop_wait = 1;
-                       queue_delayed_work(system_power_efficient_wq,
-                                          &rtd->delayed_work,
-                                          msecs_to_jiffies(rtd->pmdown_time));
-               }
-       } else {
-               /* capture streams can be powered down now */
-               snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE,
-                                         SND_SOC_DAPM_STREAM_STOP);
-       }
+       snd_soc_dapm_stream_stop(rtd, substream->stream);
 
        mutex_unlock(&rtd->card->pcm_mutex);