MLK-14609-2 ASoC: fsl: consolidate substream lock_stop/unlock_start
authorOctavian Purdila <octavian.purdila@nxp.com>
Fri, 14 Apr 2017 13:18:46 +0000 (16:18 +0300)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 20:22:01 +0000 (15:22 -0500)
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>
sound/soc/fsl/fsl_asrc.c
sound/soc/fsl/fsl_esai.c
sound/soc/fsl/imx-pcm.h

index d83631d..35e53cc 100644 (file)
@@ -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);
 }
 
 /**
index 204e431..643f782 100644 (file)
@@ -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)
index 8859a35..e87387b 100644 (file)
@@ -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 */