mbox series

[v4,0/9] of: property: add of_graph_get_next_port/port_endpoint()

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

Message

Kuninori Morimoto Aug. 28, 2024, 5:11 a.m. UTC
Hi Rob, Saravana, Tomi, Laurent, Sakari

This is v4 patch-set

Current Of-graph has "endpoint base" for loop, but doesn't have
"port base" loop. "endpoint base" loop only is not enough.
This patch-set add new "port base" for loop, and use it.

v3 -> v4
	- new for_each loop includes __free()
	 - comment indicates to use return_ptr() or no_free_ptr() if
	   it need to continue to use node
	 - each driver based on it
	- care "prev" leak on of_graph_get_next_ports()
	- of_graph_get_next_port_endpoint() indicates WARN() if port
	  has non-endpoint node
	- tidyup each git-log

v2 -> v3
	- return NULL if it it doesn't have ports / port
	- add visible comment on of_graph_get_next_ports()

v1 -> v2
	- add each Reviewed-by / Acked-by
	- tidyup/update Kernel Docs
	- use prev as parameter
	- update git-log explanation
	- remove extra changes

Kuninori Morimoto (9):
  of: property: add of_graph_get_next_port()
  of: property: add of_graph_get_next_port_endpoint()
  ASoC: test-component: use new of_graph functions
  ASoC: rcar_snd: use new of_graph functions
  ASoC: audio-graph-card: use new of_graph functions
  ASoC: audio-graph-card2: use new of_graph functions
  gpu: drm: omapdrm: use new of_graph functions
  fbdev: omapfb: use new of_graph functions
  media: xilinx-tpg: use new of_graph functions

 drivers/gpu/drm/omapdrm/dss/dpi.c             |   3 +-
 drivers/gpu/drm/omapdrm/dss/sdi.c             |   3 +-
 drivers/media/platform/xilinx/xilinx-tpg.c    |   3 +-
 drivers/of/property.c                         | 140 ++++++++++++++++++
 drivers/video/fbdev/omap2/omapfb/dss/dpi.c    |   3 +-
 drivers/video/fbdev/omap2/omapfb/dss/dss-of.c |  66 ---------
 drivers/video/fbdev/omap2/omapfb/dss/dss.c    |   9 +-
 drivers/video/fbdev/omap2/omapfb/dss/sdi.c    |   3 +-
 include/linux/of_graph.h                      |  70 +++++++++
 include/video/omapfb_dss.h                    |   8 -
 sound/soc/generic/audio-graph-card.c          |  11 +-
 sound/soc/generic/audio-graph-card2.c         | 113 ++++++--------
 sound/soc/generic/test-component.c            |   3 +-
 sound/soc/sh/rcar/core.c                      |  21 +--
 14 files changed, 283 insertions(+), 173 deletions(-)

Comments

Rob Herring (Arm) Aug. 29, 2024, 2:54 p.m. UTC | #1
On Wed, Aug 28, 2024 at 05:12:28AM +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>
> Reviewed-by: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
> ---
>  drivers/media/platform/xilinx/xilinx-tpg.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/xilinx/xilinx-tpg.c b/drivers/media/platform/xilinx/xilinx-tpg.c
> index e05e528ffc6f7..a25f216b2513c 100644
> --- a/drivers/media/platform/xilinx/xilinx-tpg.c
> +++ b/drivers/media/platform/xilinx/xilinx-tpg.c
> @@ -13,6 +13,7 @@
>  #include <linux/gpio/consumer.h>
>  #include <linux/module.h>
>  #include <linux/of.h>
> +#include <linux/of_graph.h>
>  #include <linux/platform_device.h>
>  #include <linux/xilinx-v4l2-controls.h>
>  
> @@ -744,7 +745,7 @@ static int xtpg_parse_of(struct xtpg_device *xtpg)
>  		}
>  

This function is looping over port nodes, why don't you make it use 
for_each_of_graph_port()?

>  		if (nports == 0) {
> -			endpoint = of_get_next_child(port, NULL);
> +			endpoint = of_graph_get_next_port_endpoint(port, NULL);
>  			if (endpoint)
>  				has_endpoint = true;
>  			of_node_put(endpoint);
> -- 
> 2.43.0
>
Rob Herring (Arm) Aug. 29, 2024, 3:45 p.m. UTC | #2
On Wed, Aug 28, 2024 at 05:11:37AM +0000, Kuninori Morimoto wrote:
> We have endpoint base functions
> 	- of_graph_get_next_device_endpoint()
> 	- of_graph_get_device_endpoint_count()
> 	- for_each_of_graph_device_endpoint()
> 
> Here, for_each_of_graph_device_endpoint() loop finds each endpoints
> 
> 	ports {
> 		port@0 {
> (1)			endpoint {...};
> 		};
> 		port@1 {
> (2)			endpoint {...};
> 		};
> 		...
> 	};
> 
> In above case, it finds endpoint as (1) -> (2) -> ...
> 
> Basically, user/driver knows which port is used for what, but not in
> all cases. For example on flexible/generic driver case, how many ports
> are used is not fixed.
> 
> For example Sound Generic Card driver which is used from many venders
> can't know how many ports are used. Because the driver is very
> flexible/generic, it is impossible to know how many ports are used,
> it depends on each vender SoC and/or its used board.
> 
> And more, the port can have multi endpoints. For example Generic Sound
> Card case, it supports many type of connection between CPU / Codec, and
> some of them uses multi endpoint in one port.
> Then, Generic Sound Card want to handle each connection via "port"
> instead of "endpoint".
> But, it is very difficult to handle each "port" via existing
> for_each_of_graph_device_endpoint(). Getting "port" via of_get_parent()
> from "endpoint" doesn't work. see below.
> 
> 	ports {
> 		port@0 {
> (1)			endpoint@0 {...};
> (2)			endpoint@1 {...};
> 		};
> 		port@1 {
> (3)			endpoint {...};
> 		};
> 		...
> 	};
> 
> In other case, we want to handle "ports" same as "port" for some reasons.
> 
> 	node {
> =>		ports@0 {
> 			port@0 { ... };
> 			port@1 { ... };
> 			...
> 		};
> =>		ports@1 {
> 			...
> 		};
> 	};

There is no schema that supports this structure. The closest thing we 
have is in-ports and out-ports in Coresight bindings.

In any case, it should be a separate patch, not buried in here.

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

Thank you for your review

> > index e05e528ffc6f7..a25f216b2513c 100644
> > --- a/drivers/media/platform/xilinx/xilinx-tpg.c
> > +++ b/drivers/media/platform/xilinx/xilinx-tpg.c
> > @@ -13,6 +13,7 @@
> >  #include <linux/gpio/consumer.h>
> >  #include <linux/module.h>
> >  #include <linux/of.h>
> > +#include <linux/of_graph.h>
> >  #include <linux/platform_device.h>
> >  #include <linux/xilinx-v4l2-controls.h>
> >  
> > @@ -744,7 +745,7 @@ static int xtpg_parse_of(struct xtpg_device *xtpg)
> >  		}
> >  
> 
> This function is looping over port nodes, why don't you make it use 
> for_each_of_graph_port()?

Yes, indeed.
Will fix in v5

Thank you for your help !!

Best regards
---
Kuninori Morimoto
Kuninori Morimoto Aug. 29, 2024, 11:29 p.m. UTC | #4
Hi Rob

> > 	node {
> > =>		ports@0 {
> > 			port@0 { ... };
> > 			port@1 { ... };
> > 			...
> > 		};
> > =>		ports@1 {
> > 			...
> > 		};
> > 	};
> 
> There is no schema that supports this structure. The closest thing we 
> have is in-ports and out-ports in Coresight bindings.
> 
> In any case, it should be a separate patch, not buried in here.

Oops, my driver is using multi ports already.
it is handling like below

	+-- Board  -------------+
	|+--------+     +------+|
	||SoC  (A)|<--->|Codec1|| Sound Card0
	||        |     +------+|
	||     (B)|<-+          |
	|+--------+  |          |
	+------------|----------+
	+-- Expansion board ----+
	|            |  +------+|
	|            +->|Codec2|| Sound Card1
	|               +------+|
	+-----------------------+

Here (A) is handled by ports0, and (B) is handled by ports1,
and each ports has many port nodes.


Thank you for your help !!

Best regards
---
Kuninori Morimoto
Kuninori Morimoto Aug. 29, 2024, 11:41 p.m. UTC | #5
Hi Rob

> > +EXPORT_SYMBOL(of_graph_get_next_port);
> 
> of_graph_is_present should be reimplemented using this function. So 
> should part of of_graph_get_next_endpoint().

I didn't notice about of_graph_is_present()... but unfortunately, we can't.
The biggest reason is "const".

This is because of_graph_get_next_ports() needs to use of_node_get() for
"parent", in case of if it doesn't have "ports" node ("parent" node will be
handled as "ports" node, in this case).
So, it can't use "const" for "parent", but above 2 functions are based on
"const". Thus we can't replace these by new helper functions.

	struct device_node *of_graph_get_next_ports(struct device_node *parent,
						    ...)
	{
		...
=>		prev = of_node_get(parent);
		...
	}

Or I can do it if we can remove "const" from there.

Thank you for your help !!

Best regards
---
Kuninori Morimoto