diff mbox series

[v4,4/9] ASoC: rcar_snd: use new of_graph functions

Message ID 875xrl2pur.wl-kuninori.morimoto.gx@renesas.com
State Superseded
Headers show
Series of: property: add of_graph_get_next_port/port_endpoint() | expand

Commit Message

Kuninori Morimoto Aug. 28, 2024, 5:11 a.m. UTC
Now we can use new port related functions for port parsing. Use it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Acked-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/sh/rcar/core.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

Comments

Rob Herring (Arm) Aug. 29, 2024, 3:41 p.m. UTC | #1
On Wed, Aug 28, 2024 at 05:11:56AM +0000, Kuninori Morimoto wrote:
> Now we can use new port related functions for port parsing. Use it.
> 
> Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> Acked-by: Mark Brown <broonie@kernel.org>
> ---
>  sound/soc/sh/rcar/core.c | 21 +++++++--------------
>  1 file changed, 7 insertions(+), 14 deletions(-)
> 
> diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c
> index 15cb5e7008f9f..281936ece760b 100644
> --- a/sound/soc/sh/rcar/core.c
> +++ b/sound/soc/sh/rcar/core.c
> @@ -1237,7 +1237,7 @@ static int rsnd_dai_of_node(struct rsnd_priv *priv, int *is_graph)
>  {
>  	struct device *dev = rsnd_priv_to_dev(priv);
>  	struct device_node *np = dev->of_node;
> -	struct device_node *ports, *node;
> +	struct device_node *node;
>  	int nr = 0;
>  	int i = 0;
>  
> @@ -1277,16 +1277,12 @@ static int rsnd_dai_of_node(struct rsnd_priv *priv, int *is_graph)
>  	/*
>  	 * Audio-Graph-Card
>  	 */
> -	for_each_child_of_node(np, ports) {
> -		if (!of_node_name_eq(ports, "ports") &&
> -		    !of_node_name_eq(ports, "port"))
> -			continue;
> -		priv->component_dais[i] = of_graph_get_endpoint_count(ports);
> +	for_each_of_graph_ports(np, ports) {
> +		priv->component_dais[i] = of_graph_get_port_count(ports);

These are not equivalent. Besides now working with multiple 'ports' 
nodes, it's possible to have a port node without an endpoint populated 
for example.

Rob
Kuninori Morimoto Aug. 29, 2024, 11:15 p.m. UTC | #2
Hi Rob

Thank you for your review

> > @@ -1277,16 +1277,12 @@ static int rsnd_dai_of_node(struct rsnd_priv *priv, int *is_graph)
> >  	/*
> >  	 * Audio-Graph-Card
> >  	 */
> > -	for_each_child_of_node(np, ports) {
> > -		if (!of_node_name_eq(ports, "ports") &&
> > -		    !of_node_name_eq(ports, "port"))
> > -			continue;
> > -		priv->component_dais[i] = of_graph_get_endpoint_count(ports);
> > +	for_each_of_graph_ports(np, ports) {
> > +		priv->component_dais[i] = of_graph_get_port_count(ports);
> 
> These are not equivalent. Besides now working with multiple 'ports' 
> nodes, it's possible to have a port node without an endpoint populated 
> for example.

This is the driver I maintain.
This code checks how many "port" node exists, because it needs to
manage data connection based on each "port".
The code was a little bit changed, but becomes more readable,
and was tested on my board.


Thank you for your help !!

Best regards
---
Kuninori Morimoto
diff mbox series

Patch

diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c
index 15cb5e7008f9f..281936ece760b 100644
--- a/sound/soc/sh/rcar/core.c
+++ b/sound/soc/sh/rcar/core.c
@@ -1237,7 +1237,7 @@  static int rsnd_dai_of_node(struct rsnd_priv *priv, int *is_graph)
 {
 	struct device *dev = rsnd_priv_to_dev(priv);
 	struct device_node *np = dev->of_node;
-	struct device_node *ports, *node;
+	struct device_node *node;
 	int nr = 0;
 	int i = 0;
 
@@ -1277,16 +1277,12 @@  static int rsnd_dai_of_node(struct rsnd_priv *priv, int *is_graph)
 	/*
 	 * Audio-Graph-Card
 	 */
-	for_each_child_of_node(np, ports) {
-		if (!of_node_name_eq(ports, "ports") &&
-		    !of_node_name_eq(ports, "port"))
-			continue;
-		priv->component_dais[i] = of_graph_get_endpoint_count(ports);
+	for_each_of_graph_ports(np, ports) {
+		priv->component_dais[i] = of_graph_get_port_count(ports);
 		nr += priv->component_dais[i];
 		i++;
 		if (i >= RSND_MAX_COMPONENT) {
 			dev_info(dev, "reach to max component\n");
-			of_node_put(ports);
 			break;
 		}
 	}
@@ -1486,14 +1482,10 @@  static int rsnd_dai_probe(struct rsnd_priv *priv)
 	 */
 	dai_i = 0;
 	if (is_graph) {
-		struct device_node *ports;
-		struct device_node *dai_np;
+		for_each_of_graph_ports(np, ports) {
+			for_each_of_graph_port(ports, port) {
+				struct device_node *dai_np = of_graph_get_next_port_endpoint(port, NULL);
 
-		for_each_child_of_node(np, ports) {
-			if (!of_node_name_eq(ports, "ports") &&
-			    !of_node_name_eq(ports, "port"))
-				continue;
-			for_each_endpoint_of_node(ports, dai_np) {
 				__rsnd_dai_probe(priv, dai_np, dai_np, 0, dai_i);
 				if (!rsnd_is_gen1(priv) && !rsnd_is_gen2(priv)) {
 					rdai = rsnd_rdai_get(priv, dai_i);
@@ -1502,6 +1494,7 @@  static int rsnd_dai_probe(struct rsnd_priv *priv)
 					rsnd_parse_connect_graph(priv, &rdai->capture,  dai_np);
 				}
 				dai_i++;
+				of_node_put(dai_np);
 			}
 		}
 	} else {