diff options
author | Octavian Purdila <octavian.purdila@nxp.com> | 2017-04-14 16:18:46 +0300 |
---|---|---|
committer | Anson Huang <Anson.Huang@nxp.com> | 2017-06-09 22:19:31 +0800 |
commit | 1433ac5089b6970184b80a9f74aa5b60c069a106 (patch) | |
tree | f9c311e16dcf0f95026232bd43bc9b3c588cfce4 | |
parent | db972ca1e7d3ac8cedb4fedc21db5722c582a14e (diff) |
MLK-14609-2 ASoC: fsl: consolidate substream lock_stop/unlock_start
Add common imx_stop_lock_pcm_streams and imx_start_unlock_pcm_streams
functions to remove code duplication in fsl_asrc and fsl_esai.
Signed-off-by: Octavian Purdila <octavian.purdila@nxp.com>
-rw-r--r-- | sound/soc/fsl/fsl_asrc.c | 37 | ||||
-rw-r--r-- | sound/soc/fsl/fsl_esai.c | 36 | ||||
-rw-r--r-- | sound/soc/fsl/imx-pcm.h | 35 |
3 files changed, 46 insertions, 62 deletions
diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c index d83631dc2e23..35e53cc3bfaf 100644 --- a/sound/soc/fsl/fsl_asrc.c +++ b/sound/soc/fsl/fsl_asrc.c @@ -22,6 +22,7 @@ #include <sound/pcm_params.h> #include "fsl_asrc.h" +#include "imx-pcm.h" #define IDEAL_RATIO_DECIMAL_DEPTH 26 @@ -849,28 +850,6 @@ static bool fsl_asrc_check_xrun(struct snd_pcm_substream *substream) return ret; } -static int stop_lock_stream(struct snd_pcm_substream *substream, - unsigned long *flags) -{ - if (substream) { - snd_pcm_stream_lock_irqsave(substream, *flags); - if (substream->runtime->status->state == SNDRV_PCM_STATE_RUNNING) - substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_STOP); - } - return 0; -} - -static int start_unlock_stream(struct snd_pcm_substream *substream, - unsigned long *flags) -{ - if (substream) { - if (substream->runtime->status->state == SNDRV_PCM_STATE_RUNNING) - substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_START); - snd_pcm_stream_unlock_irqrestore(substream, *flags); - } - return 0; -} - static void fsl_asrc_reset(struct snd_pcm_substream *substream, bool stop) { struct snd_soc_pcm_runtime *rtd = substream->private_data; @@ -879,12 +858,10 @@ static void fsl_asrc_reset(struct snd_pcm_substream *substream, bool stop) struct snd_dmaengine_dai_dma_data *dma_params_be = NULL; struct snd_soc_dpcm *dpcm; struct snd_pcm_substream *be_substream; - unsigned long flags0, flags1; + unsigned long flags = 0; - if (stop) { - stop_lock_stream(asrc_priv->substream[0], &flags0); - stop_lock_stream(asrc_priv->substream[1], &flags1); - } + if (stop) + imx_stop_lock_pcm_streams(asrc_priv->substream, 2, &flags); /* find the be for this fe stream */ list_for_each_entry(dpcm, &rtd->dpcm[substream->stream].be_clients, list_be) { @@ -900,10 +877,8 @@ static void fsl_asrc_reset(struct snd_pcm_substream *substream, bool stop) break; } - if (stop) { - start_unlock_stream(asrc_priv->substream[1], &flags1); - start_unlock_stream(asrc_priv->substream[0], &flags0); - } + if (stop) + imx_start_unlock_pcm_streams(asrc_priv->substream, 2, &flags); } /** diff --git a/sound/soc/fsl/fsl_esai.c b/sound/soc/fsl/fsl_esai.c index 204e431b178a..643f782f6921 100644 --- a/sound/soc/fsl/fsl_esai.c +++ b/sound/soc/fsl/fsl_esai.c @@ -809,28 +809,6 @@ static bool fsl_esai_check_xrun(struct snd_pcm_substream *substream) return saisr & (ESAI_SAISR_TUE | ESAI_SAISR_ROE) ; } -static int stop_lock_stream(struct snd_pcm_substream *substream) -{ - if (substream) { - snd_pcm_stream_lock_irq(substream); - if (substream->runtime->status->state == SNDRV_PCM_STATE_RUNNING - && substream->ops) - substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_STOP); - } - return 0; -} - -static int start_unlock_stream(struct snd_pcm_substream *substream) -{ - if (substream) { - if (substream->runtime->status->state == SNDRV_PCM_STATE_RUNNING - && substream->ops) - substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_START); - snd_pcm_stream_unlock_irq(substream); - } - return 0; -} - /* *Here is ESAI underrun reset step: *1. Read "TUE" and got TUE=1 @@ -850,13 +828,11 @@ static void fsl_esai_reset(struct snd_pcm_substream *substream, bool stop) struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct fsl_esai *esai_priv = snd_soc_dai_get_drvdata(cpu_dai); + unsigned long flags = 0; u32 saisr; - if (stop) { - stop_lock_stream(esai_priv->substream[0]); - stop_lock_stream(esai_priv->substream[1]); - } - + if (stop) + imx_stop_lock_pcm_streams(esai_priv->substream, 2, &flags); regmap_update_bits(esai_priv->regmap, REG_ESAI_ECR, ESAI_ECR_ESAIEN_MASK | ESAI_ECR_ERST_MASK, @@ -894,10 +870,8 @@ static void fsl_esai_reset(struct snd_pcm_substream *substream, bool stop) regmap_read(esai_priv->regmap, REG_ESAI_SAISR, &saisr); - if (stop) { - start_unlock_stream(esai_priv->substream[1]); - start_unlock_stream(esai_priv->substream[0]); - } + if (stop) + imx_start_unlock_pcm_streams(esai_priv->substream, 2, &flags); } static int fsl_esai_probe(struct platform_device *pdev) diff --git a/sound/soc/fsl/imx-pcm.h b/sound/soc/fsl/imx-pcm.h index 8859a35ffdd1..e87387bd1f2b 100644 --- a/sound/soc/fsl/imx-pcm.h +++ b/sound/soc/fsl/imx-pcm.h @@ -77,4 +77,39 @@ static inline void imx_pcm_fiq_exit(struct platform_device *pdev) } #endif +static inline void imx_pcm_stream_trigger(struct snd_pcm_substream *s, int tr) +{ + if (s->runtime->status->state == SNDRV_PCM_STATE_RUNNING && s->ops) + s->ops->trigger(s, tr); +} + +static inline void imx_stop_lock_pcm_streams(struct snd_pcm_substream **s, + int count, unsigned long *flags) +{ + int i; + + local_irq_save(*flags); + for (i = 0; i < count; i++) { + if (!s[i]) + continue; + snd_pcm_stream_lock(s[i]); + imx_pcm_stream_trigger(s[i], SNDRV_PCM_TRIGGER_STOP); + } +} + +static inline void imx_start_unlock_pcm_streams(struct snd_pcm_substream **s, + int count, unsigned long *flags) +{ + int i; + + for (i = count - 1; i >= 0; i--) { + if (!s[i]) + continue; + imx_pcm_stream_trigger(s[i], SNDRV_PCM_TRIGGER_START); + snd_pcm_stream_unlock(s[i]); + } + local_irq_restore(*flags); +} + + #endif /* _IMX_PCM_H */ |