From 208a1589db3e30767223d97e39e13237328e8a6e Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 5 Mar 2014 13:17:42 +0100 Subject: ASoC: Handle ignore_pmdown_time for CODEC to CODEC links For CODEC to CODEC links we should only immediately power down if both CODECs are configured to ignore the power down delay. Factor the logic for this into a helper function that can be used for both compressed and normal PCMs. Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- sound/soc/soc-pcm.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'sound/soc/soc-pcm.c') diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 47e1ce771e65..f098c8007cbe 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -34,6 +34,30 @@ #define DPCM_MAX_BE_USERS 8 +/** + * snd_soc_runtime_ignore_pmdown_time() - Check whether to ignore the power down delay + * @rtd: The ASoC PCM runtime that should be checked. + * + * This function checks whether the power down delay should be ignored for a + * specific PCM runtime. Returns true if the delay is 0, if it the DAI link has + * been configured to ignore the delay, or if none of the components benefits + * from having the delay. + */ +bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd) +{ + bool ignore = true; + + if (!rtd->pmdown_time || rtd->dai_link->ignore_pmdown_time) + return true; + + if (rtd->cpu_dai->codec) + ignore &= rtd->cpu_dai->codec->ignore_pmdown_time; + + ignore &= rtd->codec_dai->codec->ignore_pmdown_time; + + return ignore; +} + /** * snd_soc_set_runtime_hwparams - set the runtime hardware parameters * @substream: the pcm substream @@ -496,8 +520,7 @@ static int soc_pcm_close(struct snd_pcm_substream *substream) cpu_dai->runtime = NULL; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { - if (!rtd->pmdown_time || codec->ignore_pmdown_time || - rtd->dai_link->ignore_pmdown_time) { + if (snd_soc_runtime_ignore_pmdown_time(rtd)) { /* powered down playback stream now */ snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK, -- cgit v1.2.3 From 24894b76468ed250d03f9718ddfe77b902995cbd Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 5 Mar 2014 13:17:43 +0100 Subject: ASoC: Add helper functions for PCM runtime 'active' management We have the same code that increments and decrements the active field of the various PCM runtime components (all with the same bugs). Factor this out into common helper functions. Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- sound/soc/soc-pcm.c | 86 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 22 deletions(-) (limited to 'sound/soc/soc-pcm.c') diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index f098c8007cbe..1a9857519d65 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -34,6 +34,66 @@ #define DPCM_MAX_BE_USERS 8 +/** + * snd_soc_runtime_activate() - Increment active count for PCM runtime components + * @rtd: ASoC PCM runtime that is activated + * @stream: Direction of the PCM stream + * + * Increments the active count for all the DAIs and components attached to a PCM + * runtime. Should typically be called when a stream is opened. + * + * Must be called with the rtd->pcm_mutex being held + */ +void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream) +{ + struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + struct snd_soc_dai *codec_dai = rtd->codec_dai; + + lockdep_assert_held(&rtd->pcm_mutex); + + if (stream == SNDRV_PCM_STREAM_PLAYBACK) { + cpu_dai->playback_active++; + codec_dai->playback_active++; + } else { + cpu_dai->capture_active++; + codec_dai->capture_active++; + } + + cpu_dai->active++; + codec_dai->active++; + rtd->codec->active++; +} + +/** + * snd_soc_runtime_deactivate() - Decrement active count for PCM runtime components + * @rtd: ASoC PCM runtime that is deactivated + * @stream: Direction of the PCM stream + * + * Decrements the active count for all the DAIs and components attached to a PCM + * runtime. Should typically be called when a stream is closed. + * + * Must be called with the rtd->pcm_mutex being held + */ +void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream) +{ + struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + struct snd_soc_dai *codec_dai = rtd->codec_dai; + + lockdep_assert_held(&rtd->pcm_mutex); + + if (stream == SNDRV_PCM_STREAM_PLAYBACK) { + cpu_dai->playback_active--; + codec_dai->playback_active--; + } else { + cpu_dai->capture_active--; + codec_dai->capture_active--; + } + + cpu_dai->active--; + codec_dai->active--; + rtd->codec->active--; +} + /** * snd_soc_runtime_ignore_pmdown_time() - Check whether to ignore the power down delay * @rtd: The ASoC PCM runtime that should be checked. @@ -402,16 +462,9 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) runtime->hw.rate_max); dynamic: - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { - cpu_dai->playback_active++; - codec_dai->playback_active++; - } else { - cpu_dai->capture_active++; - codec_dai->capture_active++; - } - cpu_dai->active++; - codec_dai->active++; - rtd->codec->active++; + + snd_soc_runtime_activate(rtd, substream->stream); + mutex_unlock(&rtd->pcm_mutex); return 0; @@ -483,21 +536,10 @@ static int soc_pcm_close(struct snd_pcm_substream *substream) struct snd_soc_platform *platform = rtd->platform; struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *codec_dai = rtd->codec_dai; - struct snd_soc_codec *codec = rtd->codec; mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { - cpu_dai->playback_active--; - codec_dai->playback_active--; - } else { - cpu_dai->capture_active--; - codec_dai->capture_active--; - } - - cpu_dai->active--; - codec_dai->active--; - codec->active--; + snd_soc_runtime_deactivate(rtd, substream->stream); /* clear the corresponding DAIs rate when inactive */ if (!cpu_dai->active) -- cgit v1.2.3 From a1a0cc0646e38b41bfaac94f2b84422bb1df40e0 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 5 Mar 2014 13:17:44 +0100 Subject: ASoC: Fix active count tracking for CODEC to CODEC links For CODEC to CODEC links we need to make sure to also manage the 'active' field of the cpu_dai CODEC. Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- sound/soc/soc-pcm.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'sound/soc/soc-pcm.c') diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 1a9857519d65..71a01dda1867 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -61,7 +61,9 @@ void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream) cpu_dai->active++; codec_dai->active++; - rtd->codec->active++; + if (cpu_dai->codec) + cpu_dai->codec->active++; + codec_dai->codec->active++; } /** @@ -91,7 +93,9 @@ void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream) cpu_dai->active--; codec_dai->active--; - rtd->codec->active--; + if (cpu_dai->codec) + cpu_dai->codec->active--; + codec_dai->codec->active--; } /** -- cgit v1.2.3 From cdde4ccb14b4959bd1c96a07367bf02b746328d3 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 5 Mar 2014 13:17:47 +0100 Subject: ASoC: Move active count from CODEC to component There is no reason why active count tracking should only be done for CODECs but not for other components. Moving the active count from the snd_soc_codec struct to the snd_soc_component struct reduces the differences between CODECs and other components and will eventually allow component to component DAI links (Which is a prerequisite for converting CODECs to components). Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- sound/soc/soc-pcm.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'sound/soc/soc-pcm.c') diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 71a01dda1867..98b46295785d 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -61,9 +61,8 @@ void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream) cpu_dai->active++; codec_dai->active++; - if (cpu_dai->codec) - cpu_dai->codec->active++; - codec_dai->codec->active++; + cpu_dai->component->active++; + codec_dai->component->active++; } /** @@ -93,9 +92,8 @@ void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream) cpu_dai->active--; codec_dai->active--; - if (cpu_dai->codec) - cpu_dai->codec->active--; - codec_dai->codec->active--; + cpu_dai->component->active--; + codec_dai->component->active--; } /** -- cgit v1.2.3 From 3d59400fe47e7e8bfb024cd1651433bef42e268e Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 5 Mar 2014 13:17:48 +0100 Subject: ASoC: Move ignore_pmdown_time from CODEC to component In preparation for componentization move the ignore_pmdown_time field from the snd_soc_codec struct to the snd_soc_component struct. Set it to true for non CODEC components for now. Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- sound/soc/soc-pcm.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'sound/soc/soc-pcm.c') diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 98b46295785d..2cedf09f6d96 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -107,17 +107,11 @@ void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream) */ bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd) { - bool ignore = true; - if (!rtd->pmdown_time || rtd->dai_link->ignore_pmdown_time) return true; - if (rtd->cpu_dai->codec) - ignore &= rtd->cpu_dai->codec->ignore_pmdown_time; - - ignore &= rtd->codec_dai->codec->ignore_pmdown_time; - - return ignore; + return rtd->cpu_dai->component->ignore_pmdown_time && + rtd->codec_dai->component->ignore_pmdown_time; } /** -- cgit v1.2.3