Re: arm/simplebus: externalize simplebus_attach_node

2017-02-12 Thread Patrick Wildt
On Sat, Feb 11, 2017 at 08:50:23PM -0500, Ian Sutton wrote:
> Currently, we do not have a way to iterate over child FDT nodes, which
> is a problem when you have a devices like the USB system on the am335x
> (Beaglebone Black):
> 
> https://uglyman.kremlin.cc/gitweb/gitweb.cgi?p=bbb-usb.git;a=blob;f=misc/fdt/am335x-boneblack.dts;h=8799dc1d171961d3cd9a941131a82a15bbe445d7;hb=HEAD#l1489
> 
> This patch externalizes simplebus_attach_node which probes for drivers
> to attach to individual nodes, allowing drivers matching parent nodes to
> iterate over their children and call this function on each child. It
> works.
> 
> For a driver matching parent node property compatible="ti,am33xx-usb"
> and another driver matching child node property
> compatible="ti,musb-am33xx", we do the following in the parent node
> driver's _attach:
> 
> 155: for (node = OF_child(faa->fa_node); node > 0; node = OF_peer(node))
> 156: simplebus_attach_node(parent, node);

This actually works in your case since the address cells, size cells and
ranges attribute of the parent and the node for "ti,am33xx-usb" are the
same.  Generally this cannot be assumed, so a nicer way could be to do
it like mvmbus.

The softc for mvmbus is defined as

struct mvmbus_softc {
struct simplebus_softc   sc_sbus;
[...]
}

This way we can call

/* We are simple-bus compatible, so just attach it. */
simplebus_attach(parent, >sc_sbus.sc_dev, faa);

which makes simplebus attach and retrieve the necessary information to
attach the subnodes.  This way address cells, size cells and ranges are
properly read and used.

Would this work for you?

Patrick

> 
> and get:
> 
>   amusbss0 at simplebus0: rev 0.13
>   ammusb0 at simplebus0: rev 0.0  
>   ammusb1 at simplebus0: rev 0.0
>   panic: welcome to openbsd 
> 
> This is needed for a USB OTG driver for the am335x in the works. 
> 
> Ian
> 
> Index: simplebusvar.h
> ===
> RCS file: /cvs/src/sys/arch/arm/simplebus/simplebusvar.h,v
> retrieving revision 1.1
> diff -u -p -r1.1 simplebusvar.h
> --- simplebusvar.h21 Oct 2016 20:09:49 -  1.1
> +++ simplebusvar.h12 Feb 2017 01:27:21 -
> @@ -31,3 +31,4 @@ struct simplebus_softc {
>  };
>  
>  extern void simplebus_attach(struct device *, struct device *, void *);
> +extern void simplebus_attach_node(struct device *, int);
> 
> 



arm/simplebus: externalize simplebus_attach_node

2017-02-11 Thread Ian Sutton
Currently, we do not have a way to iterate over child FDT nodes, which
is a problem when you have a devices like the USB system on the am335x
(Beaglebone Black):

https://uglyman.kremlin.cc/gitweb/gitweb.cgi?p=bbb-usb.git;a=blob;f=misc/fdt/am335x-boneblack.dts;h=8799dc1d171961d3cd9a941131a82a15bbe445d7;hb=HEAD#l1489

This patch externalizes simplebus_attach_node which probes for drivers
to attach to individual nodes, allowing drivers matching parent nodes to
iterate over their children and call this function on each child. It
works.

For a driver matching parent node property compatible="ti,am33xx-usb"
and another driver matching child node property
compatible="ti,musb-am33xx", we do the following in the parent node
driver's _attach:

155: for (node = OF_child(faa->fa_node); node > 0; node = OF_peer(node))
156: simplebus_attach_node(parent, node);

and get:

amusbss0 at simplebus0: rev 0.13
ammusb0 at simplebus0: rev 0.0  
ammusb1 at simplebus0: rev 0.0
panic: welcome to openbsd 

This is needed for a USB OTG driver for the am335x in the works. 

Ian

Index: simplebusvar.h
===
RCS file: /cvs/src/sys/arch/arm/simplebus/simplebusvar.h,v
retrieving revision 1.1
diff -u -p -r1.1 simplebusvar.h
--- simplebusvar.h  21 Oct 2016 20:09:49 -  1.1
+++ simplebusvar.h  12 Feb 2017 01:27:21 -
@@ -31,3 +31,4 @@ struct simplebus_softc {
 };
 
 extern void simplebus_attach(struct device *, struct device *, void *);
+extern void simplebus_attach_node(struct device *, int);