]> rtime.felk.cvut.cz Git - linux-imx.git/commitdiff
ASoC: core: Add helper function to initialize the runtime pcm
authorLars-Peter Clausen <lars@metafoo.de>
Tue, 14 May 2013 09:05:31 +0000 (11:05 +0200)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Tue, 14 May 2013 12:52:48 +0000 (16:52 +0400)
We use the same code to initialize the runtime pcm based on the
snd_soc_pcm_stream struct on both the playback and capture path. Factor this
code into a helper function to make things a bit more tidy.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
sound/soc/soc-pcm.c

index 058b4037845150debc27effb1ee8be24a791d0f8..2f6f545f4ee88eac4d203b78655fca04f9c1af57 100644 (file)
@@ -147,6 +147,26 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream,
        }
 }
 
+static void soc_pcm_init_runtime_hw(struct snd_pcm_hardware *hw,
+       struct snd_soc_pcm_stream *codec_stream,
+       struct snd_soc_pcm_stream *cpu_stream)
+{
+       hw->rate_min = max(codec_stream->rate_min, cpu_stream->rate_min);
+       hw->rate_max = max(codec_stream->rate_max, cpu_stream->rate_max);
+       hw->channels_min = max(codec_stream->channels_min,
+               cpu_stream->channels_min);
+       hw->channels_max = min(codec_stream->channels_max,
+               cpu_stream->channels_max);
+       hw->formats = codec_stream->formats & cpu_stream->formats;
+       hw->rates = codec_stream->rates & cpu_stream->rates;
+       if (codec_stream->rates
+               & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
+               hw->rates |= cpu_stream->rates;
+       if (cpu_stream->rates
+               & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
+               hw->rates |= codec_stream->rates;
+}
+
 /*
  * Called by ALSA when a PCM substream is opened, the runtime->hw record is
  * then initialized and any private data can be allocated. This also calls
@@ -212,51 +232,11 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
 
        /* Check that the codec and cpu DAIs are compatible */
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
-               runtime->hw.rate_min =
-                       max(codec_dai_drv->playback.rate_min,
-                           cpu_dai_drv->playback.rate_min);
-               runtime->hw.rate_max =
-                       min(codec_dai_drv->playback.rate_max,
-                           cpu_dai_drv->playback.rate_max);
-               runtime->hw.channels_min =
-                       max(codec_dai_drv->playback.channels_min,
-                               cpu_dai_drv->playback.channels_min);
-               runtime->hw.channels_max =
-                       min(codec_dai_drv->playback.channels_max,
-                               cpu_dai_drv->playback.channels_max);
-               runtime->hw.formats =
-                       codec_dai_drv->playback.formats & cpu_dai_drv->playback.formats;
-               runtime->hw.rates =
-                       codec_dai_drv->playback.rates & cpu_dai_drv->playback.rates;
-               if (codec_dai_drv->playback.rates
-                          & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
-                       runtime->hw.rates |= cpu_dai_drv->playback.rates;
-               if (cpu_dai_drv->playback.rates
-                          & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
-                       runtime->hw.rates |= codec_dai_drv->playback.rates;
+               soc_pcm_init_runtime_hw(&runtime->hw, &codec_dai_drv->playback,
+                       &cpu_dai_drv->playback);
        } else {
-               runtime->hw.rate_min =
-                       max(codec_dai_drv->capture.rate_min,
-                           cpu_dai_drv->capture.rate_min);
-               runtime->hw.rate_max =
-                       min(codec_dai_drv->capture.rate_max,
-                           cpu_dai_drv->capture.rate_max);
-               runtime->hw.channels_min =
-                       max(codec_dai_drv->capture.channels_min,
-                               cpu_dai_drv->capture.channels_min);
-               runtime->hw.channels_max =
-                       min(codec_dai_drv->capture.channels_max,
-                               cpu_dai_drv->capture.channels_max);
-               runtime->hw.formats =
-                       codec_dai_drv->capture.formats & cpu_dai_drv->capture.formats;
-               runtime->hw.rates =
-                       codec_dai_drv->capture.rates & cpu_dai_drv->capture.rates;
-               if (codec_dai_drv->capture.rates
-                          & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
-                       runtime->hw.rates |= cpu_dai_drv->capture.rates;
-               if (cpu_dai_drv->capture.rates
-                          & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
-                       runtime->hw.rates |= codec_dai_drv->capture.rates;
+               soc_pcm_init_runtime_hw(&runtime->hw, &codec_dai_drv->capture,
+                       &cpu_dai_drv->capture);
        }
 
        ret = -EINVAL;