diff mbox series

[3/3] ASoC: simple-card-utils: use for_each_of_graph_port() on graph_get_dai_id()

Message ID 87o71tfrdz.wl-kuninori.morimoto.gx@renesas.com (mailing list archive)
State New
Headers show
Series ASoC: simple-card-utils: tidyup for Multi connection | expand

Commit Message

Kuninori Morimoto Dec. 3, 2024, 2:10 a.m. UTC
Because DT check when compiling become very strict in these days,
we need to add reg = <x> if it has multi port/endpoint, otherwise
it will get error or warning. But it was not so strict and/or
mandatry before.

Current code is counting "endpoint" to get DAI ID, but it should count
"port" instead, otherwise strange ID will be used for DAI if it was multi
connected case (A). There is no issue if it was not multi connected (B).

One note is that this code will be used if neither port/endpoint doesn't
have reg = <x> property on DT.

case (A)

	/* This should be handled as DAI-0 */
	port@0 {
		endpoint@0 {  }	/* It will be DAI-0 by endpoint count */
		endpoint@1 {  }	/* It will be DAI-1 by endpoint count */
	};
	/* This should be handled as DAI-1 */
	port@1 {
		endpoint {  }	/* It will be DAI-2 by endpoint count */
	};

case (B)
	/* both endpoint cound and port count are same */
	port@0 {
		endpoint { ... }
	};
	port@1 {
		endpoint { ... }
	};

It will be issue if Audio-Graph-Card is used with Multi Connection.
No issue will be happen with Audio-Graph-Card2 / Simple-Card.

This patch uses for_each_of_graph_port() instead of
for_each_endpoint_of_node(), and thus, we can use "break" to quit
from loop. Because for_each_of_graph_port() uses __free(device_node)
inside.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/generic/simple-card-utils.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index f67a1e58e821c..6c5a1c5a6b3b2 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -1026,7 +1026,6 @@  static int graph_get_dai_id(struct device_node *ep)
 {
 	struct device_node *node __free(device_node) = of_graph_get_port_parent(ep);
 	struct device_node *port __free(device_node) = of_get_parent(ep);
-	struct device_node *endpoint;
 	struct of_endpoint info;
 	int i, id;
 	int ret;
@@ -1062,9 +1061,11 @@  static int graph_get_dai_id(struct device_node *ep)
 	 */
 	i = 0;
 	id = -1;
-	for_each_endpoint_of_node(node, endpoint) {
-		if (endpoint == ep)
+	for_each_of_graph_port(node, p) {
+		if (port == p) {
 			id = i;
+			break;
+		}
 		i++;
 	}