[alsa-devel] Applied "ASoC: simple-card: cleanup DAI link loop method - step2" to the asoc tree

Mark Brown broonie at kernel.org
Fri Dec 21 19:15:04 CET 2018


The patch

   ASoC: simple-card: cleanup DAI link loop method - step2

has been applied to the asoc tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 19be989eec787f4284e8f93f8a8d69b0b06a8eb1 Mon Sep 17 00:00:00 2001
From: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
Date: Thu, 20 Dec 2018 10:47:28 +0900
Subject: [PATCH] ASoC: simple-card: cleanup DAI link loop method - step2

Current simple-card is parsing DAI link for both "normal sound" and
"DPCM sound". On this driver, it needs to count and parse
DAIs/Links/Codec Conf from each links.
Then, counting/parsing link loop are very similar, but using different
implementation. Because of this background, the link loop code is very
mysterious. Mystery code will be trouble in the future.

This patch cleanups the code by using asoc_simple_card_for_each_link()
which judges normal link / DPCM link.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
Signed-off-by: Mark Brown <broonie at kernel.org>
---
 sound/soc/generic/simple-card.c | 174 +++++++++++++++-----------------
 1 file changed, 81 insertions(+), 93 deletions(-)

diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 4987db667165..e796b1516b40 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -431,6 +431,74 @@ static int asoc_simple_card_dai_link_of(struct simple_card_data *priv,
 	return ret;
 }
 
+static int asoc_simple_card_for_each_link(struct simple_card_data *priv,
+			struct link_info *li,
+			int (*func_noml)(struct simple_card_data *priv,
+					 struct device_node *np,
+					 struct device_node *codec,
+					 struct link_info *li, bool is_top),
+			int (*func_dpcm)(struct simple_card_data *priv,
+					 struct device_node *np,
+					 struct device_node *codec,
+					 struct link_info *li, bool is_top))
+{
+	struct device *dev = simple_priv_to_dev(priv);
+	struct device_node *top = dev->of_node;
+	struct device_node *node;
+	bool is_top = 0;
+
+	/* Check if it has dai-link */
+	node = of_get_child_by_name(top, PREFIX "dai-link");
+	if (!node) {
+		node = top;
+		is_top = 1;
+	}
+
+	/* loop for all dai-link */
+	do {
+		struct asoc_simple_card_data adata;
+		struct device_node *codec;
+		struct device_node *np;
+		int num = of_get_child_count(node);
+		int ret;
+
+		/* get codec */
+		codec = of_get_child_by_name(node, is_top ?
+					     PREFIX "codec" : "codec");
+		if (!codec)
+			return -ENODEV;
+
+		of_node_put(codec);
+
+		/* get convert-xxx property */
+		memset(&adata, 0, sizeof(adata));
+		for_each_child_of_node(node, np)
+			asoc_simple_card_get_conversion(dev, np, &adata);
+
+		/* loop for all CPU/Codec node */
+		for_each_child_of_node(node, np) {
+			/*
+			 * It is DPCM
+			 * if it has many CPUs,
+			 * or has convert-xxx property
+			 */
+			if (num > 2 ||
+			    adata.convert_rate || adata.convert_channels)
+				ret = func_dpcm(priv, np, codec, li, is_top);
+			/* else normal sound */
+			else
+				ret = func_noml(priv, np, codec, li, is_top);
+
+			if (ret < 0)
+				return ret;
+		}
+
+		node = of_get_next_child(top, node);
+	} while (!is_top && node);
+
+	return 0;
+}
+
 static int asoc_simple_card_parse_aux_devs(struct device_node *node,
 					   struct simple_card_data *priv)
 {
@@ -467,9 +535,8 @@ static int asoc_simple_card_parse_of(struct simple_card_data *priv)
 	struct device *dev = simple_priv_to_dev(priv);
 	struct device_node *top = dev->of_node;
 	struct snd_soc_card *card = simple_priv_to_card(priv);
-	struct device_node *node;
 	struct link_info li;
-	int ret, loop;
+	int ret;
 
 	if (!top)
 		return -EINVAL;
@@ -484,35 +551,7 @@ static int asoc_simple_card_parse_of(struct simple_card_data *priv)
 
 	/* Single/Muti DAI link(s) & New style of DT node */
 	memset(&li, 0, sizeof(li));
-
-	/* FIXME */
-	li.cpu = 1;
-parse_loop:
-	loop		= 1;
-	node = of_get_child_by_name(top, PREFIX "dai-link");
-	if (!node) {
-		node = dev->of_node;
-		loop = 0;
-	}
-
-	do  {
-		struct asoc_simple_card_data adata;
-		struct device_node *codec;
-		struct device_node *np;
-		int num = of_get_child_count(node);
-		int ret;
-
-		codec = of_get_child_by_name(node, !loop ?
-					     PREFIX "codec" : "codec");
-		if (!codec)
-			return -ENODEV;
-
-		of_node_put(codec);
-
-		memset(&adata, 0, sizeof(adata));
-		for_each_child_of_node(node, np)
-			asoc_simple_card_get_conversion(dev, np, &adata);
-
+	for (li.cpu = 1; li.cpu >= 0; li.cpu--) {
 		/*
 		 * Detect all CPU first, and Detect all Codec 2nd.
 		 *
@@ -525,29 +564,12 @@ static int asoc_simple_card_parse_of(struct simple_card_data *priv)
 		 * To avoid random sub-device numbering,
 		 * detect "dummy-Codec" in last;
 		 */
-
-		/* loop for all CPU/Codec node */
-		for_each_child_of_node(node, np) {
-			if (num > 2 ||
-			    adata.convert_rate || adata.convert_channels) {
-				ret = asoc_simple_card_dai_link_of_dpcm(
-					priv, np, codec, &li, !loop);
-				if (ret < 0)
-					return ret;
-			} else {
-				ret = asoc_simple_card_dai_link_of(
-					priv, np, codec, &li, !loop);
-				if (ret < 0)
-					return ret;
-			}
-		}
-		node = of_get_next_child(top, node);
-	} while (loop && node);
-
-	/* FIXME */
-	li.cpu--;
-	if (li.cpu >= 0)
-		goto parse_loop;
+		ret = asoc_simple_card_for_each_link(priv, &li,
+						     asoc_simple_card_dai_link_of,
+						     asoc_simple_card_dai_link_of_dpcm);
+		if (ret < 0)
+			return ret;
+	}
 
 	ret = asoc_simple_card_parse_card_name(card, PREFIX);
 	if (ret < 0)
@@ -588,12 +610,6 @@ static void asoc_simple_card_get_dais_count(struct simple_card_data *priv,
 {
 	struct device *dev = simple_priv_to_dev(priv);
 	struct device_node *top = dev->of_node;
-	struct device_node *node;
-	struct device_node *np;
-	struct device_node *codec;
-	struct asoc_simple_card_data adata;
-	int loop;
-	int num;
 
 	/*
 	 * link_num :	number of links.
@@ -648,39 +664,11 @@ static void asoc_simple_card_get_dais_count(struct simple_card_data *priv,
 		return;
 	}
 
-	loop = 1;
-	node = of_get_child_by_name(top, PREFIX "dai-link");
-	if (!node) {
-		node = top;
-		loop = 0;
-	}
-
-	do {
-		num = of_get_child_count(node);
-
-		codec = of_get_child_by_name(node, !loop ?
-					     PREFIX "codec" : "codec");
-		if (!codec)
-			return;
-
-		of_node_put(codec);
-
-		memset(&adata, 0, sizeof(adata));
-		for_each_child_of_node(node, np)
-			asoc_simple_card_get_conversion(dev, np, &adata);
-
-		for_each_child_of_node(node, np) {
-			if (num > 2 ||
-			    adata.convert_rate || adata.convert_channels) {
-				asoc_simple_card_count_dpcm(priv, np, codec,
-							    li, !loop);
-			} else {
-				asoc_simple_card_count_noml(priv, np, codec,
-							    li, !loop);
-			}
-		}
-		node = of_get_next_child(top, node);
-	} while (loop && node);
+	asoc_simple_card_for_each_link(priv, li,
+				       asoc_simple_card_count_noml,
+				       asoc_simple_card_count_dpcm);
+	dev_dbg(dev, "link %d, dais %d, ccnf %d\n",
+		li->link, li->dais, li->conf);
 }
 
 static int asoc_simple_soc_card_probe(struct snd_soc_card *card)
-- 
2.20.1



More information about the Alsa-devel mailing list