Commit 085d22be authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: soc-pcm: add snd_soc_dpcm_can_be() and remove duplicate code

Below functions are doing very similar things, the difference is
used state only.

	snd_soc_dpcm_can_be_free_stop()
	snd_soc_dpcm_can_be_params()

This patch adds common snd_soc_dpcm_check_state(), and use it from
snd_soc_dpcm_can_be_free_stop() / snd_soc_dpcm_can_be_params().
It can reduce duplicate code.
Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/878sl1bou2.wl-kuninori.morimoto.gx@renesas.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 289a7e64
...@@ -2954,17 +2954,17 @@ struct snd_pcm_substream * ...@@ -2954,17 +2954,17 @@ struct snd_pcm_substream *
} }
EXPORT_SYMBOL_GPL(snd_soc_dpcm_get_substream); EXPORT_SYMBOL_GPL(snd_soc_dpcm_get_substream);
/* static int snd_soc_dpcm_check_state(struct snd_soc_pcm_runtime *fe,
* We can only hw_free, stop, pause or suspend a BE DAI if any of it's FE struct snd_soc_pcm_runtime *be,
* are not running, paused or suspended for the specified stream direction. int stream,
*/ const enum snd_soc_dpcm_state *states,
int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe, int num_states)
struct snd_soc_pcm_runtime *be, int stream)
{ {
struct snd_soc_dpcm *dpcm; struct snd_soc_dpcm *dpcm;
int state; int state;
int ret = 1; int ret = 1;
unsigned long flags; unsigned long flags;
int i;
spin_lock_irqsave(&fe->card->dpcm_lock, flags); spin_lock_irqsave(&fe->card->dpcm_lock, flags);
for_each_dpcm_fe(be, stream, dpcm) { for_each_dpcm_fe(be, stream, dpcm) {
...@@ -2973,18 +2973,34 @@ int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe, ...@@ -2973,18 +2973,34 @@ int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
continue; continue;
state = dpcm->fe->dpcm[stream].state; state = dpcm->fe->dpcm[stream].state;
if (state == SND_SOC_DPCM_STATE_START || for (i = 0; i < num_states; i++) {
state == SND_SOC_DPCM_STATE_PAUSED || if (state == states[i]) {
state == SND_SOC_DPCM_STATE_SUSPEND) { ret = 0;
ret = 0; break;
break; }
} }
} }
spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
/* it's safe to free/stop this BE DAI */ /* it's safe to do this BE DAI */
return ret; return ret;
} }
/*
* We can only hw_free, stop, pause or suspend a BE DAI if any of it's FE
* are not running, paused or suspended for the specified stream direction.
*/
int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
struct snd_soc_pcm_runtime *be, int stream)
{
const enum snd_soc_dpcm_state state[] = {
SND_SOC_DPCM_STATE_START,
SND_SOC_DPCM_STATE_PAUSED,
SND_SOC_DPCM_STATE_SUSPEND,
};
return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state));
}
EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_free_stop); EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_free_stop);
/* /*
...@@ -2994,30 +3010,14 @@ EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_free_stop); ...@@ -2994,30 +3010,14 @@ EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_free_stop);
int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe, int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,
struct snd_soc_pcm_runtime *be, int stream) struct snd_soc_pcm_runtime *be, int stream)
{ {
struct snd_soc_dpcm *dpcm; const enum snd_soc_dpcm_state state[] = {
int state; SND_SOC_DPCM_STATE_START,
int ret = 1; SND_SOC_DPCM_STATE_PAUSED,
unsigned long flags; SND_SOC_DPCM_STATE_SUSPEND,
SND_SOC_DPCM_STATE_PREPARE,
spin_lock_irqsave(&fe->card->dpcm_lock, flags); };
for_each_dpcm_fe(be, stream, dpcm) {
if (dpcm->fe == fe)
continue;
state = dpcm->fe->dpcm[stream].state; return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state));
if (state == SND_SOC_DPCM_STATE_START ||
state == SND_SOC_DPCM_STATE_PAUSED ||
state == SND_SOC_DPCM_STATE_SUSPEND ||
state == SND_SOC_DPCM_STATE_PREPARE) {
ret = 0;
break;
}
}
spin_unlock_irqrestore(&fe->card->dpcm_lock, flags);
/* it's safe to change hw_params */
return ret;
} }
EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_params); EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_params);
......
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