ASoC: simple-card-utils: add asoc_simple_card_parse_graph_dai()
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Thu, 20 Apr 2017 01:35:18 +0000 (01:35 +0000)
committerMark Brown <broonie@kernel.org>
Wed, 17 May 2017 09:21:20 +0000 (10:21 +0100)
simple-card already has asoc_simple_card_parse_dai(),
but graph base parsing needs graph specific version of it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
include/sound/simple_card_utils.h
sound/soc/generic/simple-card-utils.c

index af58d236297554dc2ad87bcd9b6424fc59676d7a..efab584af11b1625c35714b18ebedfbb8bf2295e 100644 (file)
@@ -60,6 +60,16 @@ int asoc_simple_card_parse_dai(struct device_node *node,
                                  const char *cells_name,
                                  int *is_single_links);
 
+#define asoc_simple_card_parse_graph_cpu(ep, dai_link)                 \
+       asoc_simple_card_parse_graph_dai(ep, &dai_link->cpu_of_node,    \
+                                        &dai_link->cpu_dai_name)
+#define asoc_simple_card_parse_graph_codec(ep, dai_link)               \
+       asoc_simple_card_parse_graph_dai(ep, &dai_link->codec_of_node,  \
+                                        &dai_link->codec_dai_name)
+int asoc_simple_card_parse_graph_dai(struct device_node *ep,
+                                    struct device_node **endpoint_np,
+                                    const char **dai_name);
+
 int asoc_simple_card_init_dai(struct snd_soc_dai *dai,
                              struct asoc_simple_dai *simple_dai);
 
index c5ab8ad2a5ce5c52dede96348f7735b34639bcf8..5a3d51e45938ef43fcae19961f7eb48c47ba1014 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/clk.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/of_graph.h>
 #include <sound/simple_card_utils.h>
 
 int asoc_simple_card_parse_daifmt(struct device *dev,
@@ -171,6 +172,62 @@ int asoc_simple_card_parse_dai(struct device_node *node,
 }
 EXPORT_SYMBOL_GPL(asoc_simple_card_parse_dai);
 
+static int asoc_simple_card_get_dai_id(struct device_node *ep)
+{
+       struct device_node *node;
+       struct device_node *endpoint;
+       int i, id;
+
+       node = of_graph_get_port_parent(ep);
+
+       i = 0;
+       id = -1;
+       for_each_endpoint_of_node(node, endpoint) {
+               if (endpoint == ep)
+                       id = i;
+               i++;
+       }
+       if (id < 0)
+               return -ENODEV;
+
+       return id;
+}
+
+int asoc_simple_card_parse_graph_dai(struct device_node *ep,
+                                    struct device_node **dai_of_node,
+                                    const char **dai_name)
+{
+       struct device_node *node;
+       struct of_phandle_args args;
+       int ret;
+
+       if (!ep)
+               return 0;
+       if (!dai_name)
+               return 0;
+
+       /*
+        * of_graph_get_port_parent() will call
+        * of_node_put(). So, call of_node_get() here
+        */
+       of_node_get(ep);
+       node = of_graph_get_port_parent(ep);
+
+       /* Get dai->name */
+       args.np         = node;
+       args.args[0]    = asoc_simple_card_get_dai_id(ep);
+       args.args_count = (of_graph_get_endpoint_count(node) > 1);
+
+       ret = snd_soc_get_dai_name(&args, dai_name);
+       if (ret < 0)
+               return ret;
+
+       *dai_of_node = node;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(asoc_simple_card_parse_graph_dai);
+
 int asoc_simple_card_init_dai(struct snd_soc_dai *dai,
                              struct asoc_simple_dai *simple_dai)
 {