[alsa-devel] [PATCH 01/10 v3] ASoC: core: add snd_soc_get_dai_drv() to get DAI driver

Kuninori Morimoto kuninori.morimoto.gx at renesas.com
Thu Mar 19 05:12:50 CET 2015


From: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>

Sometimes sound card driver want to get cpu/codec driver.
This patch adds snd_soc_get_dai_drv() and enable it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
---
v2 -> v3

 - keep .of_xlate_dai_name

 include/sound/soc.h  |  1 +
 sound/soc/soc-core.c | 69 ++++++++++++++++++++++++++++++++++++----------------
 2 files changed, 49 insertions(+), 21 deletions(-)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index bc6cfab..35f7aa5c 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -1508,6 +1508,7 @@ unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
 				     const char *prefix,
 				     struct device_node **bitclkmaster,
 				     struct device_node **framemaster);
+struct snd_soc_dai_driver *snd_soc_get_dai_drv(struct of_phandle_args *args);
 int snd_soc_of_get_dai_name(struct device_node *of_node,
 			    const char **dai_name);
 int snd_soc_of_get_dai_link_codecs(struct device *dev,
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index a85bd42..89eac2b 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -3454,6 +3454,47 @@ unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
 }
 EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt);
 
+static struct snd_soc_dai_driver
+*_snd_soc_get_dai_drv(struct of_phandle_args *args,
+		      struct snd_soc_component *pos)
+{
+	int id = -1;
+
+	switch (args->args_count) {
+	case 0:
+		id = 0; /* same as dai_drv[0] */
+		break;
+	case 1:
+		id = args->args[0];
+		break;
+	}
+
+	if (id < 0 || id >= pos->num_dai)
+		return NULL;
+
+	return  pos->dai_drv + id;
+}
+
+struct snd_soc_dai_driver
+*snd_soc_get_dai_drv(struct of_phandle_args *args)
+{
+	struct snd_soc_dai_driver *drv = NULL;
+	struct snd_soc_component *pos;
+
+	mutex_lock(&client_mutex);
+	list_for_each_entry(pos, &component_list, list) {
+		if (pos->dev->of_node != args->np)
+			continue;
+
+		drv = _snd_soc_get_dai_drv(args, pos);
+		break;
+	}
+	mutex_unlock(&client_mutex);
+
+	return drv;
+}
+EXPORT_SYMBOL_GPL(snd_soc_get_dai_drv);
+
 static int snd_soc_get_dai_name(struct of_phandle_args *args,
 				const char **dai_name)
 {
@@ -3470,30 +3511,16 @@ static int snd_soc_get_dai_name(struct of_phandle_args *args,
 							     args,
 							     dai_name);
 		} else {
-			int id = -1;
+			struct snd_soc_dai_driver *drv;
 
-			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;
-			}
+			drv = _snd_soc_get_dai_drv(args, pos);
+			if (drv) {
+				ret = 0;
 
-			if (id < 0 || id >= pos->num_dai) {
-				ret = -EINVAL;
-				continue;
+				*dai_name = drv->name;
+				if (!*dai_name)
+					*dai_name = pos->name;
 			}
-
-			ret = 0;
-
-			*dai_name = pos->dai_drv[id].name;
-			if (!*dai_name)
-				*dai_name = pos->name;
 		}
 
 		break;
-- 
1.9.1



More information about the Alsa-devel mailing list