All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] ASoC: simple-card: cleanup and prepare for Multi CPU/Codec support
@ 2021-03-26  3:25 Kuninori Morimoto
  2021-03-26  3:25 ` [PATCH 1/6] ASoC: simple-card-utils.c: remove old comment Kuninori Morimoto
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Kuninori Morimoto @ 2021-03-26  3:25 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA


Hi Mark

I want to add new audio-graph-card2 driver which can support
not only DPCM, but also Multi-CPU/Codec, and Codec2Codec.
And it is also supporting user customization.

But before supporting such driver, we need to cleanup existing
simple-card / audio-graph, because these and new driver are
sharing code.

This patch-set are cleanup and prepare for Multi-CPU/Codec support.

Kuninori Morimoto (6):
  ASoC: simple-card-utils.c: remove old comment
  ASoC: simple-card-utils: alloc dai_link information for CPU/Codec/Platform
  ASoC: audio-graph: count DAI / link numbers as in order
  ASoC: audio-graph: cleanup graph_for_each_link()
  ASoC: simple-card: count DAI / link numbers as in order
  ASoC: simple-card: cleanup graph_for_each_link()

 include/sound/simple_card_utils.h     |   7 +-
 sound/soc/generic/audio-graph-card.c  | 112 +++++++++++++------------
 sound/soc/generic/simple-card-utils.c |  20 +++--
 sound/soc/generic/simple-card.c       | 115 +++++++++++++++-----------
 4 files changed, 143 insertions(+), 111 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/6] ASoC: simple-card-utils.c: remove old comment
  2021-03-26  3:25 [PATCH 0/6] ASoC: simple-card: cleanup and prepare for Multi CPU/Codec support Kuninori Morimoto
@ 2021-03-26  3:25 ` Kuninori Morimoto
  2021-03-26  3:26 ` [PATCH 2/6] ASoC: simple-card-utils: alloc dai_link information for CPU/Codec/Platform Kuninori Morimoto
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Kuninori Morimoto @ 2021-03-26  3:25 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA


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

commit adb76b5b9c474 ("ASoC: soc-core: remove legacy style dai_link")
removed snd_soc_init_multicodec(). The comment on asoc_simple_init_priv()
is no longer needed. This patch removes it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/generic/simple-card-utils.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index 06c2512b6f2d..6897455219d1 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -617,11 +617,6 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv,
 	}
 
 	/*
-	 * Use snd_soc_dai_link_component instead of legacy style
-	 * It is codec only. but cpu/platform will be supported in the future.
-	 * see
-	 *	soc-core.c :: snd_soc_init_multicodec()
-	 *
 	 * "platform" might be removed
 	 * see
 	 *	simple-card-utils.c :: asoc_simple_canonicalize_platform()
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/6] ASoC: simple-card-utils: alloc dai_link information for CPU/Codec/Platform
  2021-03-26  3:25 [PATCH 0/6] ASoC: simple-card: cleanup and prepare for Multi CPU/Codec support Kuninori Morimoto
  2021-03-26  3:25 ` [PATCH 1/6] ASoC: simple-card-utils.c: remove old comment Kuninori Morimoto
@ 2021-03-26  3:26 ` Kuninori Morimoto
  2021-03-26  3:26 ` [PATCH 3/6] ASoC: audio-graph: count DAI / link numbers as in order Kuninori Morimoto
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Kuninori Morimoto @ 2021-03-26  3:26 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA

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

simple-card / audio-graph are assuming single CPU/Codec/Platform on
dai_link. Because of it, it is difficult to support Multi-CPU/Codec.

This patch allocs CPU/Codec/Platform dai_link imformation
instead of using existing props information. It can update to
multi-CPU/Codec, but is still assuming single-CPU/Codec for now.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 include/sound/simple_card_utils.h     |  7 ++++---
 sound/soc/generic/simple-card-utils.c | 15 +++++++++++----
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h
index ba4a3e1897b9..86e46cbf9e14 100644
--- a/include/sound/simple_card_utils.h
+++ b/include/sound/simple_card_utils.h
@@ -43,9 +43,9 @@ struct asoc_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 snd_soc_dai_link_component *cpus;
+		struct snd_soc_dai_link_component *codecs;
+		struct snd_soc_dai_link_component *platforms;
 		struct asoc_simple_data adata;
 		struct snd_soc_codec_conf *codec_conf;
 		unsigned int mclk_fs;
@@ -54,6 +54,7 @@ struct asoc_simple_priv {
 	struct asoc_simple_jack mic_jack;
 	struct snd_soc_dai_link *dai_link;
 	struct asoc_simple_dai *dais;
+	struct snd_soc_dai_link_component *dlcs;
 	struct snd_soc_codec_conf *codec_conf;
 	struct gpio_desc *pa_gpio;
 	const struct snd_soc_ops *ops;
diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index 6897455219d1..f05954529dfc 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -601,13 +601,15 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv,
 	struct snd_soc_dai_link *dai_link;
 	struct simple_dai_props *dai_props;
 	struct asoc_simple_dai *dais;
+	struct snd_soc_dai_link_component *dlcs;
 	struct snd_soc_codec_conf *cconf = NULL;
 	int i;
 
 	dai_props = devm_kcalloc(dev, li->link, sizeof(*dai_props), GFP_KERNEL);
 	dai_link  = devm_kcalloc(dev, li->link, sizeof(*dai_link),  GFP_KERNEL);
 	dais      = devm_kcalloc(dev, li->dais, sizeof(*dais),      GFP_KERNEL);
-	if (!dai_props || !dai_link || !dais)
+	dlcs      = devm_kcalloc(dev, li->link * 3, sizeof(*dai_props), GFP_KERNEL);
+	if (!dai_props || !dai_link || !dais || !dlcs)
 		return -ENOMEM;
 
 	if (li->conf) {
@@ -622,17 +624,22 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv,
 	 *	simple-card-utils.c :: asoc_simple_canonicalize_platform()
 	 */
 	for (i = 0; i < li->link; i++) {
-		dai_link[i].cpus		= &dai_props[i].cpus;
+		dai_props[i].cpus	= dlcs + (3 * i) + 0;
+		dai_props[i].codecs	= dlcs + (3 * i) + 1;
+		dai_props[i].platforms	= dlcs + (3 * i) + 2;
+
+		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].codecs		= dai_props[i].codecs;
 		dai_link[i].num_codecs		= 1;
-		dai_link[i].platforms		= &dai_props[i].platforms;
+		dai_link[i].platforms		= dai_props[i].platforms;
 		dai_link[i].num_platforms	= 1;
 	}
 
 	priv->dai_props		= dai_props;
 	priv->dai_link		= dai_link;
 	priv->dais		= dais;
+	priv->dlcs		= dlcs;
 	priv->codec_conf	= cconf;
 
 	card->dai_link		= priv->dai_link;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/6] ASoC: audio-graph: count DAI / link numbers as in order
  2021-03-26  3:25 [PATCH 0/6] ASoC: simple-card: cleanup and prepare for Multi CPU/Codec support Kuninori Morimoto
  2021-03-26  3:25 ` [PATCH 1/6] ASoC: simple-card-utils.c: remove old comment Kuninori Morimoto
  2021-03-26  3:26 ` [PATCH 2/6] ASoC: simple-card-utils: alloc dai_link information for CPU/Codec/Platform Kuninori Morimoto
@ 2021-03-26  3:26 ` Kuninori Morimoto
  2021-03-26  3:26 ` [PATCH 4/6] ASoC: audio-graph: cleanup graph_for_each_link() Kuninori Morimoto
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Kuninori Morimoto @ 2021-03-26  3:26 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA


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

audio-graph checks DT links 2 times. 1st is for counting DAIs / links
to allocating memory, 2nd is for detecting DAIs.
To detecting DAIs as CPU-dummy -> dummy-Codec order when DPCM case,
it uses loops 2 times at 2nd DT link check.
But it doesn't do it at 1st DT link check.

	for (li.cpu = 1; li.cpu >= 0; li.cpu--) {
		/*
		 * Detect all CPU first, and Detect all Codec 2n
		 *
		 * In Normal sound case, all DAIs are detected
		 * as "CPU-Codec".
		 *
		 * In DPCM sound case,
		 * all CPUs   are detected as "CPU-dummy", and
		 * all Codecs are detected as "dummy-Codec".
		 * To avoid random sub-device numbering,
		 * detect "dummy-Codec" in last;
		 */
		ret = graph_for_each_link(...);
		...
	}

To prepare supporting multi-CPU/Codec, and code cleanup,
this patch use same loop for 1st DT link check, too.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/generic/audio-graph-card.c | 29 ++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c
index 8c5cdcdc8713..3a967c520b01 100644
--- a/sound/soc/generic/audio-graph-card.c
+++ b/sound/soc/generic/audio-graph-card.c
@@ -617,6 +617,10 @@ static int graph_count_noml(struct asoc_simple_priv *priv,
 {
 	struct device *dev = simple_priv_to_dev(priv);
 
+	/* Do it only CPU turn */
+	if (!li->cpu)
+		return 0;
+
 	li->link += 1; /* 1xCPU-Codec */
 	li->dais += 2; /* 1xCPU + 1xCodec */
 
@@ -633,10 +637,22 @@ static int graph_count_dpcm(struct asoc_simple_priv *priv,
 {
 	struct device *dev = simple_priv_to_dev(priv);
 
-	li->link++; /* 1xCPU-dummy */
-	li->dais++; /* 1xCPU */
+	/*
+	 * Codec endpoint can be NULL for pluggable audio HW.
+	 * Platform DT can populate the Codec endpoint depending on the
+	 * plugged HW.
+	 */
+	if (!li->cpu && !codec_ep)
+		return 0;
+
+	/* Do it all CPU endpoint, and 1st Codec endpoint */
+	if (!li->cpu && dup_codec)
+		return 0;
 
-	if (!dup_codec && codec_ep) {
+	if (li->cpu) {
+		li->link++; /* 1xCPU-dummy */
+		li->dais++; /* 1xCPU */
+	} else if (!dup_codec && codec_ep) {
 		li->link++; /* 1xdummy-Codec */
 		li->conf++; /* 1xdummy-Codec */
 		li->dais++; /* 1xCodec */
@@ -698,9 +714,10 @@ static void graph_get_dais_count(struct asoc_simple_priv *priv,
 	 *	=> 4 DAIs  = 2xCPU + 2xCodec
 	 *	=> 1 ccnf  = 1xdummy-Codec
 	 */
-	graph_for_each_link(priv, li,
-			    graph_count_noml,
-			    graph_count_dpcm);
+	for (li->cpu = 1; li->cpu >= 0; li->cpu--)
+		graph_for_each_link(priv, li,
+				    graph_count_noml,
+				    graph_count_dpcm);
 	dev_dbg(dev, "link %d, dais %d, ccnf %d\n",
 		li->link, li->dais, li->conf);
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/6] ASoC: audio-graph: cleanup graph_for_each_link()
  2021-03-26  3:25 [PATCH 0/6] ASoC: simple-card: cleanup and prepare for Multi CPU/Codec support Kuninori Morimoto
                   ` (2 preceding siblings ...)
  2021-03-26  3:26 ` [PATCH 3/6] ASoC: audio-graph: count DAI / link numbers as in order Kuninori Morimoto
@ 2021-03-26  3:26 ` Kuninori Morimoto
  2021-03-26  3:26 ` [PATCH 5/6] ASoC: simple-card: count DAI / link numbers as in order Kuninori Morimoto
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Kuninori Morimoto @ 2021-03-26  3:26 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA


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

audio-graph checks DT links 2 times. 1st is for counting DAIs / links
to allocating memory, 2nd is for detecting DAIs.
To detecting DAIs as CPU-dummy -> dummy-Codec order when DPCM case,
it uses  loops 2 times.
Because of this kind of complex background, it needs to use local
varuable for it, and each call-back functions need to care about it.

Now, 1st and 2nd DT link check are using same order,
thus we can share same code. This patch do it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/generic/audio-graph-card.c | 129 +++++++++++++--------------
 1 file changed, 61 insertions(+), 68 deletions(-)

diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c
index 3a967c520b01..ee1d924d68e5 100644
--- a/sound/soc/generic/audio-graph-card.c
+++ b/sound/soc/generic/audio-graph-card.c
@@ -212,8 +212,7 @@ static void graph_parse_mclk_fs(struct device_node *top,
 static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv,
 				  struct device_node *cpu_ep,
 				  struct device_node *codec_ep,
-				  struct link_info *li,
-				  int dup_codec)
+				  struct link_info *li)
 {
 	struct device *dev = simple_priv_to_dev(priv);
 	struct snd_soc_card *card = simple_priv_to_card(priv);
@@ -229,18 +228,6 @@ static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv,
 	struct snd_soc_dai_link_component *codecs = dai_link->codecs;
 	int ret;
 
-	/*
-	 * Codec endpoint can be NULL for pluggable audio HW.
-	 * Platform DT can populate the Codec endpoint depending on the
-	 * plugged HW.
-	 */
-	if (!li->cpu && !codec_ep)
-		return 0;
-
-	/* Do it all CPU endpoint, and 1st Codec endpoint */
-	if (!li->cpu && dup_codec)
-		return 0;
-
 	port	= of_get_parent(ep);
 	ports	= of_get_parent(port);
 	node	= of_graph_get_port_parent(ep);
@@ -382,10 +369,6 @@ static int graph_dai_link_of(struct asoc_simple_priv *priv,
 	struct asoc_simple_dai *codec_dai;
 	int ret, single_cpu;
 
-	/* Do it only CPU turn */
-	if (!li->cpu)
-		return 0;
-
 	dev_dbg(dev, "link_of (%pOF)\n", cpu_ep);
 
 	li->link++;
@@ -466,7 +449,7 @@ static inline bool parse_as_dpcm_link(struct asoc_simple_priv *priv,
 	return false;
 }
 
-static int graph_for_each_link(struct asoc_simple_priv *priv,
+static int __graph_for_each_link(struct asoc_simple_priv *priv,
 			struct link_info *li,
 			int (*func_noml)(struct asoc_simple_priv *priv,
 					 struct device_node *cpu_ep,
@@ -475,7 +458,7 @@ static int graph_for_each_link(struct asoc_simple_priv *priv,
 			int (*func_dpcm)(struct asoc_simple_priv *priv,
 					 struct device_node *cpu_ep,
 					 struct device_node *codec_ep,
-					 struct link_info *li, int dup_codec))
+					 struct link_info *li))
 {
 	struct of_phandle_iterator it;
 	struct device *dev = simple_priv_to_dev(priv);
@@ -486,7 +469,7 @@ static int graph_for_each_link(struct asoc_simple_priv *priv,
 	struct device_node *codec_port;
 	struct device_node *codec_port_old = NULL;
 	struct asoc_simple_data adata;
-	int rc, ret;
+	int rc, ret = 0;
 
 	/* loop for all listed CPU port */
 	of_for_each_phandle(&it, rc, node, "dais", NULL, 0) {
@@ -509,12 +492,21 @@ static int graph_for_each_link(struct asoc_simple_priv *priv,
 			graph_parse_convert(dev, cpu_ep,   &adata);
 
 			/* check if link requires DPCM parsing */
-			if (parse_as_dpcm_link(priv, codec_port, &adata))
-				ret = func_dpcm(priv, cpu_ep, codec_ep, li,
-						(codec_port_old == codec_port));
+			if (parse_as_dpcm_link(priv, codec_port, &adata)) {
+				/*
+				 * Codec endpoint can be NULL for pluggable audio HW.
+				 * Platform DT can populate the Codec endpoint depending on the
+				 * plugged HW.
+				 */
+				/* Do it all CPU endpoint, and 1st Codec endpoint */
+				if (li->cpu ||
+				    ((codec_port_old != codec_port) && codec_ep))
+					ret = func_dpcm(priv, cpu_ep, codec_ep, li);
 			/* else normal sound */
-			else
-				ret = func_noml(priv, cpu_ep, codec_ep, li);
+			} else {
+				if (li->cpu)
+					ret = func_noml(priv, cpu_ep, codec_ep, li);
+			}
 
 			of_node_put(codec_ep);
 			of_node_put(codec_port);
@@ -529,6 +521,39 @@ static int graph_for_each_link(struct asoc_simple_priv *priv,
 	return 0;
 }
 
+static int graph_for_each_link(struct asoc_simple_priv *priv,
+			       struct link_info *li,
+			       int (*func_noml)(struct asoc_simple_priv *priv,
+						struct device_node *cpu_ep,
+						struct device_node *codec_ep,
+						struct link_info *li),
+			       int (*func_dpcm)(struct asoc_simple_priv *priv,
+						struct device_node *cpu_ep,
+						struct device_node *codec_ep,
+						struct link_info *li))
+{
+	int ret;
+	/*
+	 * Detect all CPU first, and Detect all Codec 2nd.
+	 *
+	 * In Normal sound case, all DAIs are detected
+	 * as "CPU-Codec".
+	 *
+	 * In DPCM sound case,
+	 * all CPUs   are detected as "CPU-dummy", and
+	 * all Codecs are detected as "dummy-Codec".
+	 * To avoid random sub-device numbering,
+	 * detect "dummy-Codec" in last;
+	 */
+	for (li->cpu = 1; li->cpu >= 0; li->cpu--) {
+		ret = __graph_for_each_link(priv, li, func_noml, func_dpcm);
+		if (ret < 0)
+			break;
+	}
+
+	return ret;
+}
+
 static void graph_get_dais_count(struct asoc_simple_priv *priv,
 				 struct link_info *li);
 
@@ -566,25 +591,11 @@ int audio_graph_parse_of(struct asoc_simple_priv *priv, struct device *dev)
 		return ret;
 
 	memset(&li, 0, sizeof(li));
-	for (li.cpu = 1; li.cpu >= 0; li.cpu--) {
-		/*
-		 * Detect all CPU first, and Detect all Codec 2nd.
-		 *
-		 * In Normal sound case, all DAIs are detected
-		 * as "CPU-Codec".
-		 *
-		 * In DPCM sound case,
-		 * all CPUs   are detected as "CPU-dummy", and
-		 * all Codecs are detected as "dummy-Codec".
-		 * To avoid random sub-device numbering,
-		 * detect "dummy-Codec" in last;
-		 */
-		ret = graph_for_each_link(priv, &li,
-					  graph_dai_link_of,
-					  graph_dai_link_of_dpcm);
-		if (ret < 0)
-			goto err;
-	}
+	ret = graph_for_each_link(priv, &li,
+				  graph_dai_link_of,
+				  graph_dai_link_of_dpcm);
+	if (ret < 0)
+		goto err;
 
 	ret = asoc_simple_parse_card_name(card, NULL);
 	if (ret < 0)
@@ -617,10 +628,6 @@ static int graph_count_noml(struct asoc_simple_priv *priv,
 {
 	struct device *dev = simple_priv_to_dev(priv);
 
-	/* Do it only CPU turn */
-	if (!li->cpu)
-		return 0;
-
 	li->link += 1; /* 1xCPU-Codec */
 	li->dais += 2; /* 1xCPU + 1xCodec */
 
@@ -632,27 +639,14 @@ static int graph_count_noml(struct asoc_simple_priv *priv,
 static int graph_count_dpcm(struct asoc_simple_priv *priv,
 			    struct device_node *cpu_ep,
 			    struct device_node *codec_ep,
-			    struct link_info *li,
-			    int dup_codec)
+			    struct link_info *li)
 {
 	struct device *dev = simple_priv_to_dev(priv);
 
-	/*
-	 * Codec endpoint can be NULL for pluggable audio HW.
-	 * Platform DT can populate the Codec endpoint depending on the
-	 * plugged HW.
-	 */
-	if (!li->cpu && !codec_ep)
-		return 0;
-
-	/* Do it all CPU endpoint, and 1st Codec endpoint */
-	if (!li->cpu && dup_codec)
-		return 0;
-
 	if (li->cpu) {
 		li->link++; /* 1xCPU-dummy */
 		li->dais++; /* 1xCPU */
-	} else if (!dup_codec && codec_ep) {
+	} else {
 		li->link++; /* 1xdummy-Codec */
 		li->conf++; /* 1xdummy-Codec */
 		li->dais++; /* 1xCodec */
@@ -714,10 +708,9 @@ static void graph_get_dais_count(struct asoc_simple_priv *priv,
 	 *	=> 4 DAIs  = 2xCPU + 2xCodec
 	 *	=> 1 ccnf  = 1xdummy-Codec
 	 */
-	for (li->cpu = 1; li->cpu >= 0; li->cpu--)
-		graph_for_each_link(priv, li,
-				    graph_count_noml,
-				    graph_count_dpcm);
+	graph_for_each_link(priv, li,
+			    graph_count_noml,
+			    graph_count_dpcm);
 	dev_dbg(dev, "link %d, dais %d, ccnf %d\n",
 		li->link, li->dais, li->conf);
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/6] ASoC: simple-card: count DAI / link numbers as in order
  2021-03-26  3:25 [PATCH 0/6] ASoC: simple-card: cleanup and prepare for Multi CPU/Codec support Kuninori Morimoto
                   ` (3 preceding siblings ...)
  2021-03-26  3:26 ` [PATCH 4/6] ASoC: audio-graph: cleanup graph_for_each_link() Kuninori Morimoto
@ 2021-03-26  3:26 ` Kuninori Morimoto
  2021-03-26  3:26 ` [PATCH 6/6] ASoC: simple-card: cleanup graph_for_each_link() Kuninori Morimoto
  2021-04-01 10:16 ` [PATCH 0/6] ASoC: simple-card: cleanup and prepare for Multi CPU/Codec support Mark Brown
  6 siblings, 0 replies; 8+ messages in thread
From: Kuninori Morimoto @ 2021-03-26  3:26 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA


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

simple-card checks DT links 2 times. 1st is for counting DAIs / links
to allocating memory, 2nd is for detecting DAIs.
To detecting DAIs as CPU-dummy -> dummy-Codec order when DPCM case,
it uses loops 2 times at 2nd DT link check.
But it doesn't do it at 1st DT link check.

	for (li.cpu = 1; li.cpu >= 0; li.cpu--) {
		/*
		 * Detect all CPU first, and Detect all Codec 2n
		 *
		 * In Normal sound case, all DAIs are detected
		 * as "CPU-Codec".
		 *
		 * In DPCM sound case,
		 * all CPUs   are detected as "CPU-dummy", and
		 * all Codecs are detected as "dummy-Codec".
		 * To avoid random sub-device numbering,
		 * detect "dummy-Codec" in last;
		 */
		ret = simple_for_each_link(...);
		...
	}

To prepare supporting multi-CPU/Codec, and code cleanup,
this patch use same loop for 1st DT link check, too.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/generic/simple-card.c | 40 +++++++++++++++++++++++++--------
 1 file changed, 31 insertions(+), 9 deletions(-)

diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 75365c7bb393..f53f76ee0a8b 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -483,9 +483,17 @@ static int simple_count_noml(struct asoc_simple_priv *priv,
 			     struct device_node *codec,
 			     struct link_info *li, bool is_top)
 {
-	li->dais++; /* CPU or Codec */
-	if (np != codec)
-		li->link++; /* CPU-Codec */
+	/*
+	 *	 |CPU   |Codec   : turn
+	 * CPU	 |Pass  |return
+	 * Codec |return|return
+	 * np
+	 */
+	if (!li->cpu || np == codec)
+		return 0;
+
+	li->link += 1;
+	li->dais += 2;
 
 	return 0;
 }
@@ -495,10 +503,23 @@ static int simple_count_dpcm(struct asoc_simple_priv *priv,
 			     struct device_node *codec,
 			     struct link_info *li, bool is_top)
 {
-	li->dais++; /* CPU or Codec */
-	li->link++; /* CPU-dummy or dummy-Codec */
-	if (np == codec)
+	/*
+	 *	 |CPU   |Codec   : turn
+	 * CPU	 |Pass  |return
+	 * Codec |return|Pass
+	 * np
+	 */
+	if (li->cpu == (np == codec))
+		return 0;
+
+	if (li->cpu) {
+		li->link++; /* CPU-dummy */
+		li->dais++;
+	} else {
+		li->link++; /* dummy-Codec */
+		li->dais++;
 		li->conf++;
+	}
 
 	return 0;
 }
@@ -562,9 +583,10 @@ static void simple_get_dais_count(struct asoc_simple_priv *priv,
 		return;
 	}
 
-	simple_for_each_link(priv, li,
-			     simple_count_noml,
-			     simple_count_dpcm);
+	for (li->cpu = 1; li->cpu >= 0; li->cpu--)
+		simple_for_each_link(priv, li,
+				     simple_count_noml,
+				     simple_count_dpcm);
 
 	dev_dbg(dev, "link %d, dais %d, ccnf %d\n",
 		li->link, li->dais, li->conf);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 6/6] ASoC: simple-card: cleanup graph_for_each_link()
  2021-03-26  3:25 [PATCH 0/6] ASoC: simple-card: cleanup and prepare for Multi CPU/Codec support Kuninori Morimoto
                   ` (4 preceding siblings ...)
  2021-03-26  3:26 ` [PATCH 5/6] ASoC: simple-card: count DAI / link numbers as in order Kuninori Morimoto
@ 2021-03-26  3:26 ` Kuninori Morimoto
  2021-04-01 10:16 ` [PATCH 0/6] ASoC: simple-card: cleanup and prepare for Multi CPU/Codec support Mark Brown
  6 siblings, 0 replies; 8+ messages in thread
From: Kuninori Morimoto @ 2021-03-26  3:26 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA


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

simple-card checks DT links 2 times. 1st is for counting DAIs / links
to allocating memory, 2nd is for detecting DAIs.
To detecting DAIs as CPU-dummy -> dummy-Codec order when DPCM case,
it uses  loops 2 times.
Because of this kind of complex background, it needs to use local
varuable for it, and each call-back functions need to care about it.

Now, 1st and 2nd DT link check are using same order,
thus we can share same code. This patch do it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/generic/simple-card.c | 125 ++++++++++++++++----------------
 1 file changed, 61 insertions(+), 64 deletions(-)

diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index f53f76ee0a8b..41aa40765a8d 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -129,15 +129,6 @@ static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
 	char *prefix = "";
 	int ret;
 
-	/*
-	 *	 |CPU   |Codec   : turn
-	 * CPU	 |Pass  |return
-	 * Codec |return|Pass
-	 * np
-	 */
-	if (li->cpu == (np == codec))
-		return 0;
-
 	dev_dbg(dev, "link_of DPCM (%pOF)\n", np);
 
 	li->link++;
@@ -260,15 +251,6 @@ static int simple_dai_link_of(struct asoc_simple_priv *priv,
 	char *prefix = "";
 	int ret, single_cpu;
 
-	/*
-	 *	 |CPU   |Codec   : turn
-	 * CPU	 |Pass  |return
-	 * Codec |return|return
-	 * np
-	 */
-	if (!li->cpu || np == codec)
-		return 0;
-
 	cpu  = np;
 	node = of_get_parent(np);
 	li->link++;
@@ -342,7 +324,7 @@ static int simple_dai_link_of(struct asoc_simple_priv *priv,
 	return ret;
 }
 
-static int simple_for_each_link(struct asoc_simple_priv *priv,
+static int __simple_for_each_link(struct asoc_simple_priv *priv,
 			struct link_info *li,
 			int (*func_noml)(struct asoc_simple_priv *priv,
 					 struct device_node *np,
@@ -402,11 +384,26 @@ static int simple_for_each_link(struct asoc_simple_priv *priv,
 			 */
 			if (dpcm_selectable &&
 			    (num > 2 ||
-			     adata.convert_rate || adata.convert_channels))
-				ret = func_dpcm(priv, np, codec, li, is_top);
+			     adata.convert_rate || adata.convert_channels)) {
+				/*
+				 * np
+				 *	 |1(CPU)|0(Codec)  li->cpu
+				 * CPU	 |Pass  |return
+				 * Codec |return|Pass
+				 */
+				if (li->cpu != (np == codec))
+					ret = func_dpcm(priv, np, codec, li, is_top);
 			/* else normal sound */
-			else
-				ret = func_noml(priv, np, codec, li, is_top);
+			} else {
+				/*
+				 * np
+				 *	 |1(CPU)|0(Codec)  li->cpu
+				 * CPU	 |Pass  |return
+				 * Codec |return|return
+				 */
+				if (li->cpu && (np != codec))
+					ret = func_noml(priv, np, codec, li, is_top);
+			}
 
 			if (ret < 0) {
 				of_node_put(codec);
@@ -424,6 +421,39 @@ static int simple_for_each_link(struct asoc_simple_priv *priv,
 	return ret;
 }
 
+static int simple_for_each_link(struct asoc_simple_priv *priv,
+				struct link_info *li,
+				int (*func_noml)(struct asoc_simple_priv *priv,
+						 struct device_node *np,
+						 struct device_node *codec,
+						 struct link_info *li, bool is_top),
+				int (*func_dpcm)(struct asoc_simple_priv *priv,
+						 struct device_node *np,
+						 struct device_node *codec,
+						 struct link_info *li, bool is_top))
+{
+	int ret;
+	/*
+	 * Detect all CPU first, and Detect all Codec 2nd.
+	 *
+	 * In Normal sound case, all DAIs are detected
+	 * as "CPU-Codec".
+	 *
+	 * In DPCM sound case,
+	 * all CPUs   are detected as "CPU-dummy", and
+	 * all Codecs are detected as "dummy-Codec".
+	 * To avoid random sub-device numbering,
+	 * detect "dummy-Codec" in last;
+	 */
+	for (li->cpu = 1; li->cpu >= 0; li->cpu--) {
+		ret = __simple_for_each_link(priv, li, func_noml, func_dpcm);
+		if (ret < 0)
+			break;
+	}
+
+	return ret;
+}
+
 static int simple_parse_of(struct asoc_simple_priv *priv)
 {
 	struct device *dev = simple_priv_to_dev(priv);
@@ -449,25 +479,11 @@ static int simple_parse_of(struct asoc_simple_priv *priv)
 
 	/* Single/Muti DAI link(s) & New style of DT node */
 	memset(&li, 0, sizeof(li));
-	for (li.cpu = 1; li.cpu >= 0; li.cpu--) {
-		/*
-		 * Detect all CPU first, and Detect all Codec 2nd.
-		 *
-		 * In Normal sound case, all DAIs are detected
-		 * as "CPU-Codec".
-		 *
-		 * In DPCM sound case,
-		 * all CPUs   are detected as "CPU-dummy", and
-		 * all Codecs are detected as "dummy-Codec".
-		 * To avoid random sub-device numbering,
-		 * detect "dummy-Codec" in last;
-		 */
-		ret = simple_for_each_link(priv, &li,
-					   simple_dai_link_of,
-					   simple_dai_link_of_dpcm);
-		if (ret < 0)
-			return ret;
-	}
+	ret = simple_for_each_link(priv, &li,
+				   simple_dai_link_of,
+				   simple_dai_link_of_dpcm);
+	if (ret < 0)
+		return ret;
 
 	ret = asoc_simple_parse_card_name(card, PREFIX);
 	if (ret < 0)
@@ -483,15 +499,6 @@ static int simple_count_noml(struct asoc_simple_priv *priv,
 			     struct device_node *codec,
 			     struct link_info *li, bool is_top)
 {
-	/*
-	 *	 |CPU   |Codec   : turn
-	 * CPU	 |Pass  |return
-	 * Codec |return|return
-	 * np
-	 */
-	if (!li->cpu || np == codec)
-		return 0;
-
 	li->link += 1;
 	li->dais += 2;
 
@@ -503,15 +510,6 @@ static int simple_count_dpcm(struct asoc_simple_priv *priv,
 			     struct device_node *codec,
 			     struct link_info *li, bool is_top)
 {
-	/*
-	 *	 |CPU   |Codec   : turn
-	 * CPU	 |Pass  |return
-	 * Codec |return|Pass
-	 * np
-	 */
-	if (li->cpu == (np == codec))
-		return 0;
-
 	if (li->cpu) {
 		li->link++; /* CPU-dummy */
 		li->dais++;
@@ -583,10 +581,9 @@ static void simple_get_dais_count(struct asoc_simple_priv *priv,
 		return;
 	}
 
-	for (li->cpu = 1; li->cpu >= 0; li->cpu--)
-		simple_for_each_link(priv, li,
-				     simple_count_noml,
-				     simple_count_dpcm);
+	simple_for_each_link(priv, li,
+			     simple_count_noml,
+			     simple_count_dpcm);
 
 	dev_dbg(dev, "link %d, dais %d, ccnf %d\n",
 		li->link, li->dais, li->conf);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/6] ASoC: simple-card: cleanup and prepare for Multi CPU/Codec support
  2021-03-26  3:25 [PATCH 0/6] ASoC: simple-card: cleanup and prepare for Multi CPU/Codec support Kuninori Morimoto
                   ` (5 preceding siblings ...)
  2021-03-26  3:26 ` [PATCH 6/6] ASoC: simple-card: cleanup graph_for_each_link() Kuninori Morimoto
@ 2021-04-01 10:16 ` Mark Brown
  6 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2021-04-01 10:16 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown

On 26 Mar 2021 12:25:24 +0900, Kuninori Morimoto wrote:
> I want to add new audio-graph-card2 driver which can support
> not only DPCM, but also Multi-CPU/Codec, and Codec2Codec.
> And it is also supporting user customization.
> 
> But before supporting such driver, we need to cleanup existing
> simple-card / audio-graph, because these and new driver are
> sharing code.
> 
> [...]

Applied to

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

Thanks!

[1/6] ASoC: simple-card-utils.c: remove old comment
      commit: 89503d736e3631bda906c627d1092dc8e76ddfd9
[2/6] ASoC: simple-card-utils: alloc dai_link information for CPU/Codec/Platform
      commit: 050c7950fd706fec229af9f30e8ce254cea9b675
[3/6] ASoC: audio-graph: count DAI / link numbers as in order
      commit: 674b9438e2d4c44f45af2a38521767c06c46eacb
[4/6] ASoC: audio-graph: cleanup graph_for_each_link()
      commit: e9cbcf23a28b41a310a13d0b1b67501948b255fb
[5/6] ASoC: simple-card: count DAI / link numbers as in order
      commit: a6e8798061bf0f33caea6fd47b0cb367309e34d0
[6/6] ASoC: simple-card: cleanup graph_for_each_link()
      commit: 39af7f7a03d007e5590f0b852b3f2fed9e703d0f

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-04-01 10:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-26  3:25 [PATCH 0/6] ASoC: simple-card: cleanup and prepare for Multi CPU/Codec support Kuninori Morimoto
2021-03-26  3:25 ` [PATCH 1/6] ASoC: simple-card-utils.c: remove old comment Kuninori Morimoto
2021-03-26  3:26 ` [PATCH 2/6] ASoC: simple-card-utils: alloc dai_link information for CPU/Codec/Platform Kuninori Morimoto
2021-03-26  3:26 ` [PATCH 3/6] ASoC: audio-graph: count DAI / link numbers as in order Kuninori Morimoto
2021-03-26  3:26 ` [PATCH 4/6] ASoC: audio-graph: cleanup graph_for_each_link() Kuninori Morimoto
2021-03-26  3:26 ` [PATCH 5/6] ASoC: simple-card: count DAI / link numbers as in order Kuninori Morimoto
2021-03-26  3:26 ` [PATCH 6/6] ASoC: simple-card: cleanup graph_for_each_link() Kuninori Morimoto
2021-04-01 10:16 ` [PATCH 0/6] ASoC: simple-card: cleanup and prepare for Multi CPU/Codec support Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.