ASoC: add snd_soc_of_get_dai_name() default of_xlate
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Thu, 17 Oct 2013 05:05:26 +0000 (22:05 -0700)
committerMark Brown <broonie@linaro.org>
Thu, 17 Oct 2013 23:43:32 +0000 (00:43 +0100)
Current snd_soc_of_get_dai_name() needs .of_xlate_dai_name()
callback on each component drivers.
But required behavior on almost all these drivers is
just returns its indexed driver's name.

This patch adds this feature as default behavior.
.of_xlate_dai_name() can overwrite it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
include/sound/soc.h
sound/soc/soc-core.c

index b13eecbaea7873e889177801490c413c4bef9435..6ed3dc0773cc74a4912f4e7637ea4d1d74b629e1 100644 (file)
@@ -644,10 +644,12 @@ struct snd_soc_component_driver {
 struct snd_soc_component {
        const char *name;
        int id;
-       int num_dai;
        struct device *dev;
        struct list_head list;
 
+       struct snd_soc_dai_driver *dai_drv;
+       int num_dai;
+
        const struct snd_soc_component_driver *driver;
 };
 
index 67cfb5f5ca96bec31ef1975c230dd966b8072857..0860a7f112992caee60f3cf0498256ee7a46d96d 100644 (file)
@@ -4023,6 +4023,7 @@ __snd_soc_register_component(struct device *dev,
 
        cmpnt->dev      = dev;
        cmpnt->driver   = cmpnt_drv;
+       cmpnt->dai_drv  = dai_drv;
        cmpnt->num_dai  = num_dai;
 
        /*
@@ -4548,12 +4549,31 @@ int snd_soc_of_get_dai_name(struct device_node *of_node,
                if (pos->dev->of_node != args.np)
                        continue;
 
-               if (!pos->driver->of_xlate_dai_name) {
-                       ret = -ENOSYS;
-                       break;
+               if (pos->driver->of_xlate_dai_name) {
+                       ret = pos->driver->of_xlate_dai_name(pos, &args, dai_name);
+               } else {
+                       int id = -1;
+
+                       switch (args.args_count) {
+                       case 0:
+                               id = 0; /* same as dai_drv[0] */
+                               break;
+                       case 1:
+                               id = args.args[0];
+                               break;
+                       default:
+                               /* not supported */
+                               break;
+                       }
+
+                       if (id < 0 || id >= pos->num_dai) {
+                               ret = -EINVAL;
+                       } else {
+                               *dai_name = pos->dai_drv[id].name;
+                               ret = 0;
+                       }
                }
 
-               ret = pos->driver->of_xlate_dai_name(pos, &args, dai_name);
                break;
        }
        mutex_unlock(&client_mutex);