ASoC: dapm: Supply the DAI and substream when calling stream events
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Thu, 16 Feb 2012 23:03:27 +0000 (15:03 -0800)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Fri, 17 Feb 2012 16:10:01 +0000 (08:10 -0800)
In order to allow us to do something smarter than iterate through widgets
doing strcmp() to work out what to power up for stream events change the
interface used to generate them to be based on the combination of a DAI
and a stream direction rather than just a simple string identifying the
stream.

At some point we'll probably want a set of channels too.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Liam Girdwood <lrg@ti.com>
include/sound/soc-dapm.h
sound/soc/soc-core.c
sound/soc/soc-dapm.c
sound/soc/soc-pcm.c

index c28d20b45669be7696e74709986e64ddb8943d3b..c32c52167b53cbebeb71aba094e97b8527bbabfa 100644 (file)
@@ -365,8 +365,8 @@ int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
                             const struct snd_soc_dapm_route *route, int num);
 
 /* dapm events */
-int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
-       const char *stream, int event);
+int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
+                             struct snd_soc_dai *dai, int event);
 void snd_soc_dapm_shutdown(struct snd_soc_card *card);
 
 /* external DAPM widget events */
index 6bad7cd4131e11198f9acfb5e4dc512e2c61a9e2..7645b8a545cfebf7a89af589953cf5abadd0c592 100644 (file)
@@ -573,18 +573,20 @@ int snd_soc_suspend(struct device *dev)
        }
 
        for (i = 0; i < card->num_rtd; i++) {
-               struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
+               struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai;
 
                if (card->rtd[i].dai_link->ignore_suspend)
                        continue;
 
-               if (driver->playback.stream_name != NULL)
-                       snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
-                               SND_SOC_DAPM_STREAM_SUSPEND);
+               snd_soc_dapm_stream_event(&card->rtd[i],
+                                         SNDRV_PCM_STREAM_PLAYBACK,
+                                         codec_dai,
+                                         SND_SOC_DAPM_STREAM_SUSPEND);
 
-               if (driver->capture.stream_name != NULL)
-                       snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
-                               SND_SOC_DAPM_STREAM_SUSPEND);
+               snd_soc_dapm_stream_event(&card->rtd[i],
+                                         SNDRV_PCM_STREAM_CAPTURE,
+                                         codec_dai,
+                                         SND_SOC_DAPM_STREAM_SUSPEND);
        }
 
        /* suspend all CODECs */
@@ -687,18 +689,18 @@ static void soc_resume_deferred(struct work_struct *work)
        }
 
        for (i = 0; i < card->num_rtd; i++) {
-               struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
+               struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai;
 
                if (card->rtd[i].dai_link->ignore_suspend)
                        continue;
 
-               if (driver->playback.stream_name != NULL)
-                       snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
-                               SND_SOC_DAPM_STREAM_RESUME);
+               snd_soc_dapm_stream_event(&card->rtd[i],
+                                         SNDRV_PCM_STREAM_PLAYBACK, codec_dai,
+                                         SND_SOC_DAPM_STREAM_RESUME);
 
-               if (driver->capture.stream_name != NULL)
-                       snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
-                               SND_SOC_DAPM_STREAM_RESUME);
+               snd_soc_dapm_stream_event(&card->rtd[i],
+                                         SNDRV_PCM_STREAM_CAPTURE, codec_dai,
+                                         SND_SOC_DAPM_STREAM_RESUME);
        }
 
        /* unmute any active DACs */
index 295fa91d9d0360f970ae120d68025ead3c208f05..97915eb711cc80eb92ebe2749955f0618a4c7386 100644 (file)
@@ -2823,17 +2823,27 @@ int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
 
 static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
-       const char *stream, int event)
+                                 int stream, struct snd_soc_dai *dai,
+                                 int event)
 {
        struct snd_soc_dapm_widget *w;
+       const char *stream_name;
+
+       if (stream == SNDRV_PCM_STREAM_PLAYBACK)
+               stream_name = dai->driver->playback.stream_name;
+       else
+               stream_name = dai->driver->capture.stream_name;
+
+       if (!stream_name)
+               return;
 
        list_for_each_entry(w, &dapm->card->widgets, list)
        {
                if (!w->sname || w->dapm != dapm)
                        continue;
                dev_vdbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n",
-                       w->name, w->sname, stream, event);
-               if (strstr(w->sname, stream)) {
+                       w->name, w->sname, stream_name, event);
+               if (strstr(w->sname, stream_name)) {
                        dapm_mark_dirty(w, "stream event");
                        switch(event) {
                        case SND_SOC_DAPM_STREAM_START:
@@ -2865,16 +2875,13 @@ static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
  *
  * Returns 0 for success else error.
  */
-int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
-       const char *stream, int event)
+int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
+                             struct snd_soc_dai *dai, int event)
 {
        struct snd_soc_codec *codec = rtd->codec;
 
-       if (stream == NULL)
-               return 0;
-
        mutex_lock(&codec->mutex);
-       soc_dapm_stream_event(&codec->dapm, stream, event);
+       soc_dapm_stream_event(&codec->dapm, stream, dai, event);
        mutex_unlock(&codec->mutex);
        return 0;
 }
index 15816eccad34611714105413fd510a3983f505a3..0ad8dcacd2f39eefbdc434ac8bed0a4a56e3ea6f 100644 (file)
@@ -307,9 +307,8 @@ static void close_delayed_work(struct work_struct *work)
        /* are we waiting on this codec DAI stream */
        if (codec_dai->pop_wait == 1) {
                codec_dai->pop_wait = 0;
-               snd_soc_dapm_stream_event(rtd,
-                       codec_dai->driver->playback.stream_name,
-                       SND_SOC_DAPM_STREAM_STOP);
+               snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK,
+                                         codec_dai, SND_SOC_DAPM_STREAM_STOP);
        }
 
        mutex_unlock(&rtd->pcm_mutex);
@@ -373,8 +372,9 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
                    rtd->dai_link->ignore_pmdown_time) {
                        /* powered down playback stream now */
                        snd_soc_dapm_stream_event(rtd,
-                               codec_dai->driver->playback.stream_name,
-                               SND_SOC_DAPM_STREAM_STOP);
+                                                 SNDRV_PCM_STREAM_PLAYBACK,
+                                                 codec_dai,
+                                                 SND_SOC_DAPM_STREAM_STOP);
                } else {
                        /* start delayed pop wq here for playback streams */
                        codec_dai->pop_wait = 1;
@@ -383,9 +383,8 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
                }
        } else {
                /* capture streams can be powered down now */
-               snd_soc_dapm_stream_event(rtd,
-                       codec_dai->driver->capture.stream_name,
-                       SND_SOC_DAPM_STREAM_STOP);
+               snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE,
+                                         codec_dai, SND_SOC_DAPM_STREAM_STOP);
        }
 
        mutex_unlock(&rtd->pcm_mutex);
@@ -454,14 +453,8 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
                cancel_delayed_work(&rtd->delayed_work);
        }
 
-       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-               snd_soc_dapm_stream_event(rtd,
-                                         codec_dai->driver->playback.stream_name,
-                                         SND_SOC_DAPM_STREAM_START);
-       else
-               snd_soc_dapm_stream_event(rtd,
-                                         codec_dai->driver->capture.stream_name,
-                                         SND_SOC_DAPM_STREAM_START);
+       snd_soc_dapm_stream_event(rtd, substream->stream, codec_dai,
+                                 SND_SOC_DAPM_STREAM_START);
 
        snd_soc_dai_digital_mute(codec_dai, 0);