ASoC: pcm: Refactor soc_pcm_apply_msb for multicodecs
[deliverable/linux.git] / sound / soc / soc-pcm.c
index a391de05803765403fc94e989717ad7dae91db5c..320a904b6b69149a8e54a74384949b0735a667d1 100644 (file)
@@ -7,7 +7,7 @@
  * Copyright (C) 2010 Texas Instruments Inc.
  *
  * Authors: Liam Girdwood <lrg@ti.com>
- *          Mark Brown <broonie@opensource.wolfsonmicro.com>       
+ *          Mark Brown <broonie@opensource.wolfsonmicro.com>
  *
  *  This program is free software; you can redistribute  it and/or modify it
  *  under  the terms of  the GNU General  Public License as published by the
@@ -284,15 +284,10 @@ static int sample_sizes[] = {
        24, 32,
 };
 
-static void soc_pcm_apply_msb(struct snd_pcm_substream *substream,
-                             struct snd_soc_dai *dai)
+static void soc_pcm_set_msb(struct snd_pcm_substream *substream,
+                           struct snd_soc_dai *dai, int bits)
 {
-       int ret, i, bits;
-
-       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-               bits = dai->driver->playback.sig_bits;
-       else
-               bits = dai->driver->capture.sig_bits;
+       int ret, i;
 
        if (!bits)
                return;
@@ -310,6 +305,25 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream,
        }
 }
 
+static void soc_pcm_apply_msb(struct snd_pcm_substream *substream)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+       struct snd_soc_dai *codec_dai = rtd->codec_dai;
+       unsigned int bits = 0, cpu_bits;
+
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+               bits = codec_dai->driver->playback.sig_bits;
+               cpu_bits = cpu_dai->driver->playback.sig_bits;
+       } else {
+               bits = codec_dai->driver->capture.sig_bits;
+               cpu_bits = cpu_dai->driver->capture.sig_bits;
+       }
+
+       soc_pcm_set_msb(substream, codec_dai, bits);
+       soc_pcm_set_msb(substream, cpu_dai, cpu_bits);
+}
+
 static void soc_pcm_init_runtime_hw(struct snd_pcm_runtime *runtime,
        struct snd_soc_pcm_stream *codec_stream,
        struct snd_soc_pcm_stream *cpu_stream)
@@ -433,8 +447,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
                goto config_err;
        }
 
-       soc_pcm_apply_msb(substream, codec_dai);
-       soc_pcm_apply_msb(substream, cpu_dai);
+       soc_pcm_apply_msb(substream);
 
        /* Symmetry only applies if we've already got an active stream. */
        if (cpu_dai->active) {
@@ -555,7 +568,6 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
 
        if (platform->driver->ops && platform->driver->ops->close)
                platform->driver->ops->close(substream);
-       cpu_dai->runtime = NULL;
 
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
                if (snd_soc_runtime_ignore_pmdown_time(rtd)) {
@@ -819,6 +831,13 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
                if (ret < 0)
                        return ret;
        }
+
+       if (rtd->dai_link->ops && rtd->dai_link->ops->trigger) {
+               ret = rtd->dai_link->ops->trigger(substream, cmd);
+               if (ret < 0)
+                       return ret;
+       }
+
        return 0;
 }
 
@@ -1012,21 +1031,12 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card,
 }
 
 static inline struct snd_soc_dapm_widget *
-       rtd_get_cpu_widget(struct snd_soc_pcm_runtime *rtd, int stream)
-{
-       if (stream == SNDRV_PCM_STREAM_PLAYBACK)
-               return rtd->cpu_dai->playback_widget;
-       else
-               return rtd->cpu_dai->capture_widget;
-}
-
-static inline struct snd_soc_dapm_widget *
-       rtd_get_codec_widget(struct snd_soc_pcm_runtime *rtd, int stream)
+       dai_get_widget(struct snd_soc_dai *dai, int stream)
 {
        if (stream == SNDRV_PCM_STREAM_PLAYBACK)
-               return rtd->codec_dai->playback_widget;
+               return dai->playback_widget;
        else
-               return rtd->codec_dai->capture_widget;
+               return dai->capture_widget;
 }
 
 static int widget_in_list(struct snd_soc_dapm_widget_list *list,
@@ -1076,14 +1086,14 @@ static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream,
        list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
 
                /* is there a valid CPU DAI widget for this BE */
-               widget = rtd_get_cpu_widget(dpcm->be, stream);
+               widget = dai_get_widget(dpcm->be->cpu_dai, stream);
 
                /* prune the BE if it's no longer in our active list */
                if (widget && widget_in_list(list, widget))
                        continue;
 
                /* is there a valid CODEC DAI widget for this BE */
-               widget = rtd_get_codec_widget(dpcm->be, stream);
+               widget = dai_get_widget(dpcm->be->codec_dai, stream);
 
                /* prune the BE if it's no longer in our active list */
                if (widget && widget_in_list(list, widget))
This page took 0.0383 seconds and 5 git commands to generate.