]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/kernel-video.git/commitdiff
ASoC: core: Refactor CODEC/CODEC_DAI search
authorMisael Lopez Cruz <misael.lopez@ti.com>
Wed, 5 Jun 2013 08:25:59 +0000 (03:25 -0500)
committerMisael Lopez Cruz <misael.lopez@ti.com>
Tue, 10 Mar 2015 17:33:38 +0000 (12:33 -0500)
Refactor CODEC and CODEC DAI search in preparation for DAI-multicodec.
Dedicated functions for CODEC/CODEC_DAI search are added.

Previous implementation unnecessarily kept searching for a matching CODEC
in the remaining register CODECS even if it was already found.

This patch is ported from p-ti-linux-3.8.y released kernel branch
tree.(Kernel Version:3.8).

Change-Id: Icc7c29b29e43ada4aa1353c990384f703b0d191e
Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
Signed-off-by: Charulatha Varadarajan <charu@ti.com>
Signed-off-by: Nikhil Devshatwar <nikhil.nd@ti.com>
sound/soc/soc-core.c

index e446213c6e9fb7bffee2cfcc30fd3bc464ce292b..6eedf9ac272d28fcfc54ebe521ae9abde73495f7 100644 (file)
@@ -851,13 +851,51 @@ EXPORT_SYMBOL_GPL(snd_soc_resume);
 static const struct snd_soc_dai_ops null_dai_ops = {
 };
 
+static struct snd_soc_codec *soc_find_codec(
+               const struct device_node *codec_of_node,
+               const char *codec_name)
+{
+       struct snd_soc_codec *codec;
+
+       /* Find CODEC from registered CODECs */
+       list_for_each_entry(codec, &codec_list, list) {
+               if (codec_of_node) {
+                       if (codec->dev->of_node != codec_of_node)
+                               continue;
+               } else {
+                       if (strcmp(codec->name, codec_name))
+                               continue;
+               }
+
+               /* found */
+               return codec;
+       }
+
+       return NULL;
+}
+
+static struct snd_soc_dai *soc_find_codec_dai(struct snd_soc_codec *codec,
+                                             const char *codec_dai_name)
+{
+       struct snd_soc_dai *codec_dai;
+
+       /* Find CODEC DAI from registered DAIs from this CODEC */
+       list_for_each_entry(codec_dai, &dai_list, list) {
+               if (codec->dev == codec_dai->dev &&
+                   !strcmp(codec_dai->name, codec_dai_name)) {
+                       return codec_dai;
+               }
+       }
+
+       return NULL;
+}
+
 static int soc_bind_dai_link(struct snd_soc_card *card, int num)
 {
        struct snd_soc_dai_link *dai_link = &card->dai_link[num];
        struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
-       struct snd_soc_codec *codec;
        struct snd_soc_platform *platform;
-       struct snd_soc_dai *codec_dai, *cpu_dai;
+       struct snd_soc_dai *cpu_dai;
        const char *platform_name;
 
        dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num);
@@ -883,44 +921,24 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
                return -EPROBE_DEFER;
        }
 
-       /* Find CODEC from registered CODECs */
-       list_for_each_entry(codec, &codec_list, list) {
-               if (dai_link->codec_of_node) {
-                       if (codec->dev->of_node != dai_link->codec_of_node)
-                               continue;
-               } else {
-                       if (strcmp(codec->name, dai_link->codec_name))
-                               continue;
-               }
-
-               rtd->codec = codec;
-
-               /*
-                * CODEC found, so find CODEC DAI from registered DAIs from
-                * this CODEC
-                */
-               list_for_each_entry(codec_dai, &dai_list, list) {
-                       if (codec->dev == codec_dai->dev &&
-                               !strcmp(codec_dai->name,
-                                       dai_link->codec_dai_name)) {
-
-                               rtd->codec_dai = codec_dai;
-                       }
-               }
-
-               if (!rtd->codec_dai) {
-                       dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
-                               dai_link->codec_dai_name);
-                       return -EPROBE_DEFER;
-               }
-       }
-
+       /* Find CODEC from registered list */
+       rtd->codec = soc_find_codec(dai_link->codec_of_node,
+                                   dai_link->codec_name);
        if (!rtd->codec) {
                dev_err(card->dev, "ASoC: CODEC %s not registered\n",
                        dai_link->codec_name);
                return -EPROBE_DEFER;
        }
 
+       /* Find CODEC DAI from registered list */
+       rtd->codec_dai = soc_find_codec_dai(rtd->codec,
+                                           dai_link->codec_dai_name);
+       if (!rtd->codec_dai) {
+               dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
+                       dai_link->codec_dai_name);
+               return -EPROBE_DEFER;
+       }
+
        /* if there's no platform we match on the empty platform */
        platform_name = dai_link->platform_name;
        if (!platform_name && !dai_link->platform_of_node)