diff mbox series

[RFC] ASoC: audio-graph/simple-card: use modern style dai_link for CPU

Message ID 877ef5m2zi.wl-kuninori.morimoto.gx@renesas.com (mailing list archive)
State New, archived
Headers show
Series [RFC] ASoC: audio-graph/simple-card: use modern style dai_link for CPU | expand

Commit Message

Kuninori Morimoto Jan. 16, 2019, 8:27 a.m. UTC
Now ALSA SoC is supporting modern style (= snd_soc_dai_link_component)
dai_link for CPU, let's switch to it.

Because audio-graph/simple-card are sharing simple-card-utils,
we need to update both in the same time.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 include/sound/simple_card_utils.h     | 42 +++++++-------------
 sound/soc/generic/audio-graph-card.c  | 18 +++++----
 sound/soc/generic/simple-card-utils.c | 72 ++++++++---------------------------
 sound/soc/generic/simple-card.c       | 19 ++++++---
 4 files changed, 53 insertions(+), 98 deletions(-)
diff mbox series

Patch

diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h
index ab5a2ba..d02de45 100644
--- a/include/sound/simple_card_utils.h
+++ b/include/sound/simple_card_utils.h
@@ -50,54 +50,38 @@  int asoc_simple_card_parse_card_name(struct snd_soc_card *card,
 				     char *prefix);
 
 #define asoc_simple_card_parse_clk_cpu(dev, node, dai_link, simple_dai)		\
-	asoc_simple_card_parse_clk(dev, node, dai_link->cpu_of_node, simple_dai, \
-				   dai_link->cpu_dai_name, NULL)
+	asoc_simple_card_parse_clk(dev, node, simple_dai, dai_link->cpus)
 #define asoc_simple_card_parse_clk_codec(dev, node, dai_link, simple_dai)	\
-	asoc_simple_card_parse_clk(dev, node, dai_link->codec_of_node, simple_dai,\
-				   dai_link->codec_dai_name, dai_link->codecs)
+	asoc_simple_card_parse_clk(dev, node, simple_dai, dai_link->codecs)
 int asoc_simple_card_parse_clk(struct device *dev,
 			       struct device_node *node,
-			       struct device_node *dai_of_node,
 			       struct asoc_simple_dai *simple_dai,
-			       const char *dai_name,
 			       struct snd_soc_dai_link_component *dlc);
 int asoc_simple_card_clk_enable(struct asoc_simple_dai *dai);
 void asoc_simple_card_clk_disable(struct asoc_simple_dai *dai);
 
 #define asoc_simple_card_parse_cpu(node, dai_link,				\
 				   list_name, cells_name, is_single_link)	\
-	asoc_simple_card_parse_dai(node, NULL,					\
-		&dai_link->cpu_of_node,						\
-		&dai_link->cpu_dai_name, list_name, cells_name, is_single_link)
+	asoc_simple_card_parse_dai(node, dai_link->cpus,					\
+				   list_name, cells_name, 1, is_single_link)
 #define asoc_simple_card_parse_codec(node, dai_link, list_name, cells_name)	\
 	asoc_simple_card_parse_dai(node, dai_link->codecs,			\
-				   &dai_link->codec_of_node,			\
-				   &dai_link->codec_dai_name,			\
-				   list_name, cells_name, NULL)
+				   list_name, cells_name, 1, NULL)
 #define asoc_simple_card_parse_platform(node, dai_link, list_name, cells_name)	\
 	asoc_simple_card_parse_dai(node, dai_link->platforms,			\
-		&dai_link->platform_of_node,					\
-		NULL, list_name, cells_name, NULL)
+				   list_name, cells_name, 0, NULL)
 int asoc_simple_card_parse_dai(struct device_node *node,
-				  struct snd_soc_dai_link_component *dlc,
-				  struct device_node **endpoint_np,
-				  const char **dai_name,
-				  const char *list_name,
-				  const char *cells_name,
-				  int *is_single_links);
+			       struct snd_soc_dai_link_component *dlc,
+			       const char *list_name,
+			       const char *cells_name,
+			       int with_dai, int *is_single_links);
 
 #define asoc_simple_card_parse_graph_cpu(ep, dai_link)			\
-	asoc_simple_card_parse_graph_dai(ep, NULL,			\
-					 &dai_link->cpu_of_node,	\
-					 &dai_link->cpu_dai_name)
+	asoc_simple_card_parse_graph_dai(ep, dai_link->cpus)
 #define asoc_simple_card_parse_graph_codec(ep, dai_link)		\
-	asoc_simple_card_parse_graph_dai(ep, dai_link->codecs,		\
-					 &dai_link->codec_of_node,	\
-					 &dai_link->codec_dai_name)
+	asoc_simple_card_parse_graph_dai(ep, dai_link->codecs)
 int asoc_simple_card_parse_graph_dai(struct device_node *ep,
-				     struct snd_soc_dai_link_component *dlc,
-				     struct device_node **endpoint_np,
-				     const char **dai_name);
+				     struct snd_soc_dai_link_component *dlc);
 
 #define asoc_simple_card_of_parse_tdm(np, dai)			\
 	snd_soc_of_parse_tdm_slot(np,	&(dai)->tx_slot_mask,	\
diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c
index 42b077c..374f041 100644
--- a/sound/soc/generic/audio-graph-card.c
+++ b/sound/soc/generic/audio-graph-card.c
@@ -25,6 +25,7 @@  struct graph_priv {
 	struct graph_dai_props {
 		struct asoc_simple_dai *cpu_dai;
 		struct asoc_simple_dai *codec_dai;
+		struct snd_soc_dai_link_component cpus;   /* single cpu */
 		struct snd_soc_dai_link_component codecs; /* single codec */
 		struct snd_soc_dai_link_component platforms;
 		struct asoc_simple_card_data adata;
@@ -208,6 +209,7 @@  static int graph_dai_link_of_dpcm(struct graph_priv *priv,
 	struct device_node *node;
 	struct asoc_simple_dai *dai;
 	struct snd_soc_dai_link_component *codecs = dai_link->codecs;
+	struct snd_soc_dai_link_component *cpus   = dai_link->cpus;
 	int ret;
 
 	/* Do it all CPU endpoint, and 1st Codec endpoint */
@@ -257,20 +259,20 @@  static int graph_dai_link_of_dpcm(struct graph_priv *priv,
 
 		ret = asoc_simple_card_set_dailink_name(dev, dai_link,
 							"fe.%s",
-							dai_link->cpu_dai_name);
+							cpus->dai_name);
 		if (ret < 0)
 			return ret;
 
 		/* card->num_links includes Codec */
 		asoc_simple_card_canonicalize_cpu(dai_link,
-			of_graph_get_endpoint_count(dai_link->cpu_of_node) == 1);
+			of_graph_get_endpoint_count(cpus->of_node) == 1);
 	} else {
 		struct snd_soc_codec_conf *cconf;
 
 		/* FE is dummy */
-		dai_link->cpu_of_node		= NULL;
-		dai_link->cpu_dai_name		= "snd-soc-dummy-dai";
-		dai_link->cpu_name		= "snd-soc-dummy";
+		cpus->of_node		= NULL;
+		cpus->dai_name		= "snd-soc-dummy-dai";
+		cpus->name		= "snd-soc-dummy";
 
 		/* BE settings */
 		dai_link->no_pcm		= 1;
@@ -411,7 +413,7 @@  static int graph_dai_link_of(struct graph_priv *priv,
 
 	ret = asoc_simple_card_set_dailink_name(dev, dai_link,
 						"%s-%s",
-						dai_link->cpu_dai_name,
+						dai_link->cpus->dai_name,
 						dai_link->codecs->dai_name);
 	if (ret < 0)
 		return ret;
@@ -420,7 +422,7 @@  static int graph_dai_link_of(struct graph_priv *priv,
 	dai_link->init = graph_dai_init;
 
 	asoc_simple_card_canonicalize_cpu(dai_link,
-		of_graph_get_endpoint_count(dai_link->cpu_of_node) == 1);
+		of_graph_get_endpoint_count(dai_link->cpus->of_node) == 1);
 
 	return 0;
 }
@@ -685,6 +687,8 @@  static int graph_probe(struct platform_device *pdev)
 	 *	soc-core.c :: snd_soc_init_multicodec()
 	 */
 	for (i = 0; i < li.link; i++) {
+		dai_link[i].cpus	= &dai_props[i].cpus;
+		dai_link[i].num_cpus	= 1;
 		dai_link[i].codecs	= &dai_props[i].codecs;
 		dai_link[i].num_codecs	= 1;
 		dai_link[i].platforms	= &dai_props[i].platforms;
diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index 3c0901d..c98a074 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -170,26 +170,13 @@  EXPORT_SYMBOL_GPL(asoc_simple_card_clk_disable);
 
 int asoc_simple_card_parse_clk(struct device *dev,
 			       struct device_node *node,
-			       struct device_node *dai_of_node,
 			       struct asoc_simple_dai *simple_dai,
-			       const char *dai_name,
 			       struct snd_soc_dai_link_component *dlc)
 {
 	struct clk *clk;
 	u32 val;
 
 	/*
-	 * Use snd_soc_dai_link_component instead of legacy style.
-	 * It is only for codec, but cpu will be supported in the future.
-	 * see
-	 *	soc-core.c :: snd_soc_init_multicodec()
-	 */
-	if (dlc) {
-		dai_of_node	= dlc->of_node;
-		dai_name	= dlc->dai_name;
-	}
-
-	/*
 	 * Parse dai->sysclk come from "clocks = <&xxx>"
 	 * (if system has common clock)
 	 *  or "system-clock-frequency = <xxx>"
@@ -203,7 +190,7 @@  int asoc_simple_card_parse_clk(struct device *dev,
 	} else if (!of_property_read_u32(node, "system-clock-frequency", &val)) {
 		simple_dai->sysclk = val;
 	} else {
-		clk = devm_get_clk_from_child(dev, dai_of_node, NULL);
+		clk = devm_get_clk_from_child(dev, dlc->of_node, NULL);
 		if (!IS_ERR(clk))
 			simple_dai->sysclk = clk_get_rate(clk);
 	}
@@ -211,7 +198,7 @@  int asoc_simple_card_parse_clk(struct device *dev,
 	if (of_property_read_bool(node, "system-clock-direction-out"))
 		simple_dai->clk_direction = SND_SOC_CLOCK_OUT;
 
-	dev_dbg(dev, "%s : sysclk = %d, direction %d\n", dai_name,
+	dev_dbg(dev, "%s : sysclk = %d, direction %d\n", dlc->dai_name,
 		simple_dai->sysclk, simple_dai->clk_direction);
 
 	return 0;
@@ -219,12 +206,11 @@  int asoc_simple_card_parse_clk(struct device *dev,
 EXPORT_SYMBOL_GPL(asoc_simple_card_parse_clk);
 
 int asoc_simple_card_parse_dai(struct device_node *node,
-				    struct snd_soc_dai_link_component *dlc,
-				    struct device_node **dai_of_node,
-				    const char **dai_name,
-				    const char *list_name,
-				    const char *cells_name,
-				    int *is_single_link)
+			       struct snd_soc_dai_link_component *dlc,
+			       const char *list_name,
+			       const char *cells_name,
+			       int with_dai,
+			       int *is_single_link)
 {
 	struct of_phandle_args args;
 	int ret;
@@ -233,17 +219,6 @@  int asoc_simple_card_parse_dai(struct device_node *node,
 		return 0;
 
 	/*
-	 * Use snd_soc_dai_link_component instead of legacy style.
-	 * It is only for codec, but cpu will be supported in the future.
-	 * see
-	 *	soc-core.c :: snd_soc_init_multicodec()
-	 */
-	if (dlc) {
-		dai_name	= &dlc->dai_name;
-		dai_of_node	= &dlc->of_node;
-	}
-
-	/*
 	 * Get node via "sound-dai = <&phandle port>"
 	 * it will be used as xxx_of_node on soc_bind_dai_link()
 	 */
@@ -252,13 +227,13 @@  int asoc_simple_card_parse_dai(struct device_node *node,
 		return ret;
 
 	/* Get dai->name */
-	if (dai_name) {
-		ret = snd_soc_of_get_dai_name(node, dai_name);
+	if (with_dai) {
+		ret = snd_soc_of_get_dai_name(node, &dlc->dai_name);
 		if (ret < 0)
 			return ret;
 	}
 
-	*dai_of_node = args.np;
+	dlc->of_node = args.np;
 
 	if (is_single_link)
 		*is_single_link = !args.args_count;
@@ -320,29 +295,14 @@  static int asoc_simple_card_get_dai_id(struct device_node *ep)
 }
 
 int asoc_simple_card_parse_graph_dai(struct device_node *ep,
-				     struct snd_soc_dai_link_component *dlc,
-				     struct device_node **dai_of_node,
-				     const char **dai_name)
+				     struct snd_soc_dai_link_component *dlc)
 {
 	struct device_node *node;
 	struct of_phandle_args args;
 	int ret;
 
-	/*
-	 * Use snd_soc_dai_link_component instead of legacy style.
-	 * It is only for codec, but cpu will be supported in the future.
-	 * see
-	 *	soc-core.c :: snd_soc_init_multicodec()
-	 */
-	if (dlc) {
-		dai_name	= &dlc->dai_name;
-		dai_of_node	= &dlc->of_node;
-	}
-
 	if (!ep)
 		return 0;
-	if (!dai_name)
-		return 0;
 
 	node = of_graph_get_port_parent(ep);
 
@@ -351,11 +311,11 @@  int asoc_simple_card_parse_graph_dai(struct device_node *ep,
 	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);
+	ret = snd_soc_get_dai_name(&args, &dlc->dai_name);
 	if (ret < 0)
 		return ret;
 
-	*dai_of_node = node;
+	dlc->of_node = node;
 
 	return 0;
 }
@@ -398,7 +358,7 @@  int asoc_simple_card_canonicalize_dailink(struct snd_soc_dai_link *dai_link)
 {
 	/* Assumes platform == cpu */
 	if (!dai_link->platforms->of_node)
-		dai_link->platforms->of_node = dai_link->cpu_of_node;
+		dai_link->platforms->of_node = dai_link->cpus->of_node;
 
 	return 0;
 
@@ -418,7 +378,7 @@  void asoc_simple_card_canonicalize_cpu(struct snd_soc_dai_link *dai_link,
 	 *	fmt_multiple_name()
 	 */
 	if (is_single_links)
-		dai_link->cpu_dai_name = NULL;
+		dai_link->cpus->dai_name = NULL;
 }
 EXPORT_SYMBOL_GPL(asoc_simple_card_canonicalize_cpu);
 
@@ -428,7 +388,7 @@  int asoc_simple_card_clean_reference(struct snd_soc_card *card)
 	int i;
 
 	for_each_card_prelinks(card, i, dai_link) {
-		of_node_put(dai_link->cpu_of_node);
+		of_node_put(dai_link->cpus->of_node);
 		of_node_put(dai_link->codecs->of_node);
 	}
 	return 0;
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index d8a0d1e..1869f1f 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -20,6 +20,7 @@  struct simple_priv {
 	struct simple_dai_props {
 		struct asoc_simple_dai *cpu_dai;
 		struct asoc_simple_dai *codec_dai;
+		struct snd_soc_dai_link_component cpus;   /* single cpu */
 		struct snd_soc_dai_link_component codecs; /* single codec */
 		struct snd_soc_dai_link_component platforms;
 		struct asoc_simple_card_data adata;
@@ -198,6 +199,7 @@  static int simple_dai_link_of_dpcm(struct simple_priv *priv,
 	struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
 	struct asoc_simple_dai *dai;
 	struct snd_soc_dai_link_component *codecs = dai_link->codecs;
+	struct snd_soc_dai_link_component *cpus   = dai_link->cpus;
 	struct device_node *top = dev->of_node;
 	struct device_node *node = of_get_parent(np);
 	char prop[128];
@@ -249,7 +251,7 @@  static int simple_dai_link_of_dpcm(struct simple_priv *priv,
 
 		ret = asoc_simple_card_set_dailink_name(dev, dai_link,
 							"fe.%s",
-							dai_link->cpu_dai_name);
+							dai_link->cpus->dai_name);
 		if (ret < 0)
 			return ret;
 
@@ -258,9 +260,9 @@  static int simple_dai_link_of_dpcm(struct simple_priv *priv,
 		struct snd_soc_codec_conf *cconf;
 
 		/* FE is dummy */
-		dai_link->cpu_of_node		= NULL;
-		dai_link->cpu_dai_name		= "snd-soc-dummy-dai";
-		dai_link->cpu_name		= "snd-soc-dummy";
+		cpus->of_node		= NULL;
+		cpus->dai_name		= "snd-soc-dummy-dai";
+		cpus->name		= "snd-soc-dummy";
 
 		/* BE settings */
 		dai_link->no_pcm		= 1;
@@ -415,7 +417,7 @@  static int simple_dai_link_of(struct simple_priv *priv,
 
 	ret = asoc_simple_card_set_dailink_name(dev, dai_link,
 						"%s-%s",
-						dai_link->cpu_dai_name,
+						dai_link->cpus->dai_name,
 						dai_link->codecs->dai_name);
 	if (ret < 0)
 		goto dai_link_of_err;
@@ -730,6 +732,8 @@  static int simple_probe(struct platform_device *pdev)
 	 *	soc-core.c :: snd_soc_init_multicodec()
 	 */
 	for (i = 0; i < li.link; i++) {
+		dai_link[i].cpus	= &dai_props[i].cpus;
+		dai_link[i].num_cpus	= 1;
 		dai_link[i].codecs	= &dai_props[i].codecs;
 		dai_link[i].num_codecs	= 1;
 		dai_link[i].platforms	= &dai_props[i].platforms;
@@ -757,6 +761,7 @@  static int simple_probe(struct platform_device *pdev)
 
 	} else {
 		struct asoc_simple_card_info *cinfo;
+		struct snd_soc_dai_link_component *cpus;
 		struct snd_soc_dai_link_component *codecs;
 		struct snd_soc_dai_link_component *platform;
 		int dai_idx = 0;
@@ -779,6 +784,9 @@  static int simple_probe(struct platform_device *pdev)
 		dai_props->cpu_dai	= &priv->dais[dai_idx++];
 		dai_props->codec_dai	= &priv->dais[dai_idx++];
 
+		cpus			= dai_link->cpus;
+		cpus->dai_name		= cinfo->cpu_dai.name;
+
 		codecs			= dai_link->codecs;
 		codecs->name		= cinfo->codec;
 		codecs->dai_name	= cinfo->codec_dai.name;
@@ -789,7 +797,6 @@  static int simple_probe(struct platform_device *pdev)
 		card->name		= (cinfo->card) ? cinfo->card : cinfo->name;
 		dai_link->name		= cinfo->name;
 		dai_link->stream_name	= cinfo->name;
-		dai_link->cpu_dai_name	= cinfo->cpu_dai.name;
 		dai_link->dai_fmt	= cinfo->daifmt;
 		dai_link->init		= simple_dai_init;
 		memcpy(priv->dai_props->cpu_dai, &cinfo->cpu_dai,