Commit 24894b76 authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Mark Brown

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: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent 208a1589
...@@ -414,6 +414,8 @@ struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card, ...@@ -414,6 +414,8 @@ struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
const char *dai_link); const char *dai_link);
bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd); bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd);
void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream);
void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream);
/* Utility functions to get clock rates from various things */ /* Utility functions to get clock rates from various things */
int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots); int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
......
...@@ -30,8 +30,6 @@ static int soc_compr_open(struct snd_compr_stream *cstream) ...@@ -30,8 +30,6 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
{ {
struct snd_soc_pcm_runtime *rtd = cstream->private_data; struct snd_soc_pcm_runtime *rtd = cstream->private_data;
struct snd_soc_platform *platform = rtd->platform; 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;
int ret = 0; int ret = 0;
mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
...@@ -52,17 +50,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream) ...@@ -52,17 +50,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
} }
} }
if (cstream->direction == SND_COMPRESS_PLAYBACK) { snd_soc_runtime_activate(rtd, cstream->direction);
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++;
mutex_unlock(&rtd->pcm_mutex); mutex_unlock(&rtd->pcm_mutex);
...@@ -81,8 +69,6 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) ...@@ -81,8 +69,6 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
struct snd_soc_pcm_runtime *fe = cstream->private_data; struct snd_soc_pcm_runtime *fe = cstream->private_data;
struct snd_pcm_substream *fe_substream = fe->pcm->streams[0].substream; struct snd_pcm_substream *fe_substream = fe->pcm->streams[0].substream;
struct snd_soc_platform *platform = fe->platform; struct snd_soc_platform *platform = fe->platform;
struct snd_soc_dai *cpu_dai = fe->cpu_dai;
struct snd_soc_dai *codec_dai = fe->codec_dai;
struct snd_soc_dpcm *dpcm; struct snd_soc_dpcm *dpcm;
struct snd_soc_dapm_widget_list *list; struct snd_soc_dapm_widget_list *list;
int stream; int stream;
...@@ -140,17 +126,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) ...@@ -140,17 +126,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN; fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
if (cstream->direction == SND_COMPRESS_PLAYBACK) { snd_soc_runtime_activate(fe, stream);
cpu_dai->playback_active++;
codec_dai->playback_active++;
} else {
cpu_dai->capture_active++;
codec_dai->capture_active++;
}
cpu_dai->active++;
codec_dai->active++;
fe->codec->active++;
mutex_unlock(&fe->card->mutex); mutex_unlock(&fe->card->mutex);
...@@ -202,23 +178,18 @@ static int soc_compr_free(struct snd_compr_stream *cstream) ...@@ -202,23 +178,18 @@ static int soc_compr_free(struct snd_compr_stream *cstream)
struct snd_soc_platform *platform = rtd->platform; struct snd_soc_platform *platform = rtd->platform;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_dai *codec_dai = rtd->codec_dai;
struct snd_soc_codec *codec = rtd->codec; int stream;
mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
if (cstream->direction == SND_COMPRESS_PLAYBACK) { if (cstream->direction == SND_COMPRESS_PLAYBACK)
cpu_dai->playback_active--; stream = SNDRV_PCM_STREAM_PLAYBACK;
codec_dai->playback_active--; else
} else { stream = SNDRV_PCM_STREAM_CAPTURE;
cpu_dai->capture_active--;
codec_dai->capture_active--;
}
snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction); snd_soc_runtime_deactivate(rtd, stream);
cpu_dai->active--; snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction);
codec_dai->active--;
codec->active--;
if (!cpu_dai->active) if (!cpu_dai->active)
cpu_dai->rate = 0; cpu_dai->rate = 0;
...@@ -260,26 +231,17 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream) ...@@ -260,26 +231,17 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
{ {
struct snd_soc_pcm_runtime *fe = cstream->private_data; struct snd_soc_pcm_runtime *fe = cstream->private_data;
struct snd_soc_platform *platform = fe->platform; struct snd_soc_platform *platform = fe->platform;
struct snd_soc_dai *cpu_dai = fe->cpu_dai;
struct snd_soc_dai *codec_dai = fe->codec_dai;
struct snd_soc_dpcm *dpcm; struct snd_soc_dpcm *dpcm;
int stream, ret; int stream, ret;
mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
if (cstream->direction == SND_COMPRESS_PLAYBACK) { if (cstream->direction == SND_COMPRESS_PLAYBACK)
stream = SNDRV_PCM_STREAM_PLAYBACK; stream = SNDRV_PCM_STREAM_PLAYBACK;
cpu_dai->playback_active--; else
codec_dai->playback_active--;
} else {
stream = SNDRV_PCM_STREAM_CAPTURE; stream = SNDRV_PCM_STREAM_CAPTURE;
cpu_dai->capture_active--;
codec_dai->capture_active--;
}
cpu_dai->active--; snd_soc_runtime_deactivate(fe, stream);
codec_dai->active--;
fe->codec->active--;
fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
......
...@@ -34,6 +34,66 @@ ...@@ -34,6 +34,66 @@
#define DPCM_MAX_BE_USERS 8 #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 * snd_soc_runtime_ignore_pmdown_time() - Check whether to ignore the power down delay
* @rtd: The ASoC PCM runtime that should be checked. * @rtd: The ASoC PCM runtime that should be checked.
...@@ -402,16 +462,9 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) ...@@ -402,16 +462,9 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
runtime->hw.rate_max); runtime->hw.rate_max);
dynamic: dynamic:
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
cpu_dai->playback_active++; snd_soc_runtime_activate(rtd, substream->stream);
codec_dai->playback_active++;
} else {
cpu_dai->capture_active++;
codec_dai->capture_active++;
}
cpu_dai->active++;
codec_dai->active++;
rtd->codec->active++;
mutex_unlock(&rtd->pcm_mutex); mutex_unlock(&rtd->pcm_mutex);
return 0; return 0;
...@@ -483,21 +536,10 @@ static int soc_pcm_close(struct snd_pcm_substream *substream) ...@@ -483,21 +536,10 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
struct snd_soc_platform *platform = rtd->platform; struct snd_soc_platform *platform = rtd->platform;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai = rtd->codec_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); mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { snd_soc_runtime_deactivate(rtd, substream->stream);
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--;
/* clear the corresponding DAIs rate when inactive */ /* clear the corresponding DAIs rate when inactive */
if (!cpu_dai->active) if (!cpu_dai->active)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment