[PATCH 2/4] ASoC: add of_parse_snd_connection_with_args() for sound-dai/graph connection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




From: Kuninori Morimoto <kuninori.morimoto.gx@xxxxxxxxxxx>

Current ASoC card connection is based on "sound-dai" on DT,
but V4L2 connection is using graph base.
This patch adds common function which can detect both connection.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@xxxxxxxxxxx>
---
 include/sound/soc.h  |  2 ++
 sound/soc/soc-core.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index 02b4a21..17ddc25 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -1669,6 +1669,8 @@ unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
 				     const char *prefix,
 				     struct device_node **bitclkmaster,
 				     struct device_node **framemaster);
+int of_parse_snd_soc_connection_with_args(const struct device_node *np,
+					  struct of_phandle_args *out_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 d2e62b15..643b244 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -34,6 +34,7 @@
 #include <linux/ctype.h>
 #include <linux/slab.h>
 #include <linux/of.h>
+#include <linux/of_graph.h>
 #include <sound/core.h>
 #include <sound/jack.h>
 #include <sound/pcm.h>
@@ -3839,6 +3840,47 @@ static int snd_soc_get_dai_name(struct of_phandle_args *args,
 	return ret;
 }
 
+int of_parse_snd_soc_connection_with_args(const struct device_node *np,
+					  struct of_phandle_args *out_args)
+{
+	int ret;
+
+	ret = of_parse_phandle_with_args(np, "sound-dai",
+					 "#sound-dai-cells", 0, out_args);
+	if (ret) {
+		struct device_node *p_node = NULL;
+		struct device_node *ep_node = NULL;
+		struct of_endpoint ep;
+
+		/* try graph base parse */
+		p_node = of_graph_get_remote_port_parent(np);
+		if (!p_node)
+			return -EINVAL;
+
+		ep_node = of_graph_get_remote_port(np);
+		if (!p_node) {
+			ret = -EINVAL;
+			goto graph_err_parent;
+		}
+
+		ret = of_graph_parse_endpoint(ep_node, &ep);
+		if (ret < 0)
+			goto graph_err_endpoint;
+
+		out_args->np		= p_node;
+		out_args->args_count	= (1 != of_graph_get_endpoint_count(p_node));
+		out_args->args[0]	= ep.port;
+
+graph_err_endpoint:
+		of_node_put(ep_node);
+graph_err_parent:
+		of_node_put(p_node);
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(of_parse_snd_soc_connection_with_args);
+
 int snd_soc_of_get_dai_name(struct device_node *of_node,
 			    const char **dai_name)
 {
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]
  Powered by Linux