[U-Boot] [PATCH v2] usb: dwc3: convert to livetree

Siva Durga Prasad Paladugu sivadur at xilinx.com
Fri Sep 7 05:29:28 UTC 2018


Hi,

> -----Original Message-----
> From: Michal Simek [mailto:michal.simek at xilinx.com]
> Sent: Thursday, September 06, 2018 7:36 PM
> To: Siva Durga Prasad Paladugu <sivadur at xilinx.com>; u-
> boot at lists.denx.de
> Cc: Michal Simek <michals at xilinx.com>; marex at denx.de;
> bmeng.cn at gmail.com; sjg at chromium.org;
> yamada.masahiro at socionext.com; Vipul Kumar <vipulk at xilinx.com>
> Subject: Re: [PATCH v2] usb: dwc3: convert to livetree
> 
> On 6.9.2018 12:39, Siva Durga Prasad Paladugu wrote:
> > From: Vipul Kumar <vipul.kumar at xilinx.com>
> >
> > Update the DWC3 USB driver to support a live tree.
> >
> > Signed-off-by: Siva Durga Prasad Paladugu
> > <siva.durga.paladugu at xilinx.com>
> > Signed-off-by: Vipul Kumar <vipul.kumar at xilinx.com>
> > Tested-by: Michal Simek <michal.simek at xilinx.com>
> > ---
> > Changes in v2:
> > - Fixed travis build issues with some platforms.
> > ---
> >  drivers/usb/common/common.c      | 11 +++++------
> >  drivers/usb/dwc3/dwc3-generic.c  | 17 +++++++----------
> > drivers/usb/host/dwc3-sti-glue.c |  7 +++----
> >  drivers/usb/host/xhci-dwc3.c     |  3 ++-
> >  drivers/usb/host/xhci-zynqmp.c   |  3 +--
> >  drivers/usb/musb-new/ti-musb.c   | 11 ++++-------
> >  include/linux/usb/otg.h          |  6 ++++--
> >  7 files changed, 26 insertions(+), 32 deletions(-)
> >
> > diff --git a/drivers/usb/common/common.c
> b/drivers/usb/common/common.c
> > index a55def5..3dea79b 100644
> > --- a/drivers/usb/common/common.c
> > +++ b/drivers/usb/common/common.c
> > @@ -10,6 +10,7 @@
> >  #include <linux/libfdt.h>
> >  #include <linux/usb/otg.h>
> >  #include <linux/usb/ch9.h>
> > +#include <dm.h>
> >
> >  DECLARE_GLOBAL_DATA_PTR;
> >
> > @@ -20,13 +21,12 @@ static const char *const usb_dr_modes[] = {
> >  	[USB_DR_MODE_OTG]		= "otg",
> >  };
> >
> > -enum usb_dr_mode usb_get_dr_mode(int node)
> > +enum usb_dr_mode usb_get_dr_mode(ofnode node)
> >  {
> > -	const void *fdt = gd->fdt_blob;
> >  	const char *dr_mode;
> >  	int i;
> >
> > -	dr_mode = fdt_getprop(fdt, node, "dr_mode", NULL);
> > +	dr_mode = ofnode_get_property(node, "dr_mode", NULL);
> >  	if (!dr_mode) {
> >  		pr_err("usb dr_mode not found\n");
> >  		return USB_DR_MODE_UNKNOWN;
> > @@ -48,13 +48,12 @@ static const char *const speed_names[] = {
> >  	[USB_SPEED_SUPER] = "super-speed",
> >  };
> >
> > -enum usb_device_speed usb_get_maximum_speed(int node)
> > +enum usb_device_speed usb_get_maximum_speed(ofnode node)
> >  {
> > -	const void *fdt = gd->fdt_blob;
> >  	const char *max_speed;
> >  	int i;
> >
> > -	max_speed = fdt_getprop(fdt, node, "maximum-speed", NULL);
> > +	max_speed = ofnode_get_property(node, "maximum-speed",
> NULL);
> >  	if (!max_speed) {
> >  		pr_err("usb maximum-speed not found\n");
> >  		return USB_SPEED_UNKNOWN;
> > diff --git a/drivers/usb/dwc3/dwc3-generic.c
> > b/drivers/usb/dwc3/dwc3-generic.c index ca63eac..ef72c8c 100644
> > --- a/drivers/usb/dwc3/dwc3-generic.c
> > +++ b/drivers/usb/dwc3/dwc3-generic.c
> > @@ -61,18 +61,17 @@ static int
> dwc3_generic_peripheral_remove(struct
> > udevice *dev)  static int
> > dwc3_generic_peripheral_ofdata_to_platdata(struct udevice *dev)  {
> >  	struct dwc3 *priv = dev_get_priv(dev);
> > -	int node = dev_of_offset(dev);
> >
> > -	priv->regs = (void *)devfdt_get_addr(dev);
> > +	priv->regs = (void *)dev_read_addr(dev);
> >  	priv->regs += DWC3_GLOBALS_REGS_START;
> >
> > -	priv->maximum_speed = usb_get_maximum_speed(node);
> > +	priv->maximum_speed = usb_get_maximum_speed(dev->node);
> >  	if (priv->maximum_speed == USB_SPEED_UNKNOWN) {
> >  		pr_err("Invalid usb maximum speed\n");
> >  		return -ENODEV;
> >  	}
> >
> > -	priv->dr_mode = usb_get_dr_mode(node);
> > +	priv->dr_mode = usb_get_dr_mode(dev->node);
> >  	if (priv->dr_mode == USB_DR_MODE_UNKNOWN) {
> >  		pr_err("Invalid usb mode setup\n");
> >  		return -ENODEV;
> > @@ -100,13 +99,11 @@ U_BOOT_DRIVER(dwc3_generic_peripheral) = {
> >
> >  static int dwc3_generic_bind(struct udevice *parent)  {
> > -	const void *fdt = gd->fdt_blob;
> > -	int node;
> > +	ofnode node;
> >  	int ret;
> >
> > -	for (node = fdt_first_subnode(fdt, dev_of_offset(parent)); node > 0;
> > -	     node = fdt_next_subnode(fdt, node)) {
> > -		const char *name = fdt_get_name(fdt, node, NULL);
> > +	dev_for_each_subnode(node, parent) {
> > +		const char *name = (char *)ofnode_get_name(node);
> >  		enum usb_dr_mode dr_mode;
> >  		struct udevice *dev;
> >  		const char *driver;
> > @@ -133,7 +130,7 @@ static int dwc3_generic_bind(struct udevice
> *parent)
> >  		};
> >
> >  		ret = device_bind_driver_to_node(parent, driver, name,
> > -						 offset_to_ofnode(node),
> &dev);
> > +						 node, &dev);
> >  		if (ret) {
> >  			debug("%s: not able to bind usb device mode\n",
> >  			      __func__);
> > diff --git a/drivers/usb/host/dwc3-sti-glue.c
> > b/drivers/usb/host/dwc3-sti-glue.c
> > index ad7cf6e..de423ee 100644
> > --- a/drivers/usb/host/dwc3-sti-glue.c
> > +++ b/drivers/usb/host/dwc3-sti-glue.c
> > @@ -153,18 +153,17 @@ static int
> > sti_dwc3_glue_ofdata_to_platdata(struct udevice *dev)  static int
> > sti_dwc3_glue_bind(struct udevice *dev)  {
> >  	struct sti_dwc3_glue_platdata *plat = dev_get_platdata(dev);
> > -	int dwc3_node;
> > +	ofnode dwc3_node;
> >
> >  	/* check if one subnode is present */
> > -	dwc3_node = fdt_first_subnode(gd->fdt_blob, dev_of_offset(dev));
> > +	dwc3_node = dev_read_first_subnode(dev);
> >  	if (dwc3_node <= 0) {
> >  		pr_err("Can't find subnode for %s\n", dev->name);
> >  		return -ENODEV;
> >  	}
> >
> >  	/* check if the subnode compatible string is the dwc3 one*/
> > -	if (fdt_node_check_compatible(gd->fdt_blob, dwc3_node,
> > -				      "snps,dwc3") != 0) {
> > +	if (ofnode_device_is_compatible(dwc3_node, "snps,dwc3") != 0) {
> >  		pr_err("Can't find dwc3 subnode for %s\n", dev->name);
> >  		return -ENODEV;
> >  	}
> > diff --git a/drivers/usb/host/xhci-dwc3.c
> > b/drivers/usb/host/xhci-dwc3.c index 80754d7..cbab436 100644
> > --- a/drivers/usb/host/xhci-dwc3.c
> > +++ b/drivers/usb/host/xhci-dwc3.c
> > @@ -202,6 +202,7 @@ static int xhci_dwc3_probe(struct udevice *dev)
> >  	struct dwc3 *dwc3_reg;
> >  	enum usb_dr_mode dr_mode;
> >  	int ret;
> > +	ofnode node;
> >
> >  	hccr = (struct xhci_hccr *)((uintptr_t)dev_read_addr(dev));
> >  	hcor = (struct xhci_hcor *)((uintptr_t)hccr + @@ -215,7 +216,7 @@
> > static int xhci_dwc3_probe(struct udevice *dev)
> >
> >  	dwc3_core_init(dwc3_reg);
> >
> > -	dr_mode = usb_get_dr_mode(dev_of_offset(dev));
> > +	dr_mode = usb_get_dr_mode(node);
> >  	if (dr_mode == USB_DR_MODE_UNKNOWN)
> >  		/* by default set dual role mode to HOST */
> >  		dr_mode = USB_DR_MODE_HOST;
> > diff --git a/drivers/usb/host/xhci-zynqmp.c
> > b/drivers/usb/host/xhci-zynqmp.c index e44e1ae..5a5b870 100644
> > --- a/drivers/usb/host/xhci-zynqmp.c
> > +++ b/drivers/usb/host/xhci-zynqmp.c
> > @@ -121,10 +121,9 @@ static int xhci_usb_remove(struct udevice *dev)
> > static int xhci_usb_ofdata_to_platdata(struct udevice *dev)  {
> >  	struct zynqmp_xhci_platdata *plat = dev_get_platdata(dev);
> > -	const void *blob = gd->fdt_blob;
> >
> >  	/* Get the base address for XHCI controller from the device node */
> > -	plat->hcd_base = fdtdec_get_addr(blob, dev_of_offset(dev), "reg");
> > +	plat->hcd_base = dev_read_addr(dev);
> >  	if (plat->hcd_base == FDT_ADDR_T_NONE) {
> >  		debug("Can't get the XHCI register base address\n");
> >  		return -ENXIO;
> > diff --git a/drivers/usb/musb-new/ti-musb.c
> > b/drivers/usb/musb-new/ti-musb.c index 9fbe2d6..bdb5985 100644
> > --- a/drivers/usb/musb-new/ti-musb.c
> > +++ b/drivers/usb/musb-new/ti-musb.c
> > @@ -177,7 +177,6 @@ static int
> ti_musb_host_ofdata_to_platdata(struct
> > udevice *dev)  {
> >  	struct ti_musb_platdata *platdata = dev_get_platdata(dev);
> >  	const void *fdt = gd->fdt_blob;
> > -	int node = dev_of_offset(dev);
> >  	int ret;
> >
> >  	ret = ti_musb_ofdata_to_platdata(dev); @@ -204,14 +203,12 @@
> > U_BOOT_DRIVER(ti_musb_host) = {
> >
> >  static int ti_musb_wrapper_bind(struct udevice *parent)  {
> > -	const void *fdt = gd->fdt_blob;
> > -	int node;
> > +	ofnode node;
> >  	int ret;
> >
> > -	for (node = fdt_first_subnode(fdt, dev_of_offset(parent)); node > 0;
> > -	     node = fdt_next_subnode(fdt, node)) {
> > +	dev_for_each_subnode(node, parent) {
> >  		struct udevice *dev;
> > -		const char *name = fdt_get_name(fdt, node, NULL);
> > +		const char *name = (char *)ofnode_get_name(node);
> >  		enum usb_dr_mode dr_mode;
> >  		struct driver *drv;
> >
> > @@ -226,7 +223,7 @@ static int ti_musb_wrapper_bind(struct udevice
> *parent)
> >  		case USB_DR_MODE_HOST:
> >  			/* Bind MUSB host */
> >  			ret = device_bind_driver_to_node(parent, "ti-musb-
> host",
> > -					name, offset_to_ofnode(node),
> &dev);
> > +					name, node, &dev);
> >  			if (ret) {
> >  				pr_err("musb - not able to bind usb host
> node\n");
> >  				return ret;
> > diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h index
> > d2604c5..baf4d91 100644
> > --- a/include/linux/usb/otg.h
> > +++ b/include/linux/usb/otg.h
> > @@ -9,6 +9,8 @@
> >  #ifndef __LINUX_USB_OTG_H
> >  #define __LINUX_USB_OTG_H
> >
> > +#include <dm/ofnode.h>
> > +
> >  enum usb_dr_mode {
> >  	USB_DR_MODE_UNKNOWN,
> >  	USB_DR_MODE_HOST,
> > @@ -23,7 +25,7 @@ enum usb_dr_mode {
> >   * The function gets phy interface string from property 'dr_mode',
> >   * and returns the correspondig enum usb_dr_mode
> >   */
> > -enum usb_dr_mode usb_get_dr_mode(int node);
> > +enum usb_dr_mode usb_get_dr_mode(ofnode node);
> >
> >  /**
> >   * usb_get_maximum_speed() - Get maximum speed for given device
> @@
> > -32,6 +34,6 @@ enum usb_dr_mode usb_get_dr_mode(int node);
> >   * The function gets phy interface string from property 'maximum-speed',
> >   * and returns the correspondig enum usb_device_speed
> >   */
> > -enum usb_device_speed usb_get_maximum_speed(int node);
> > +enum usb_device_speed usb_get_maximum_speed(ofnode node);
> >
> >  #endif /* __LINUX_USB_OTG_H */
> >
> 
> I still see there one issue.
> make stih410-b2260_defconfig
> make -j
> 
>   LD      cmd/built-in.o
> drivers/usb/host/dwc3-sti-glue.c: In function ‘sti_dwc3_glue_bind’:
> drivers/usb/host/dwc3-sti-glue.c:160:16: error: invalid operands to binary
> <= (have ‘ofnode {aka union ofnode_union}’ and ‘int’)
>   if (dwc3_node <= 0) {
>                 ^~
> make[1]: *** [drivers/usb/host/dwc3-sti-glue.o] Error 1

Sorry, It's my bad that I sent wrong patch. I already fixed this issue and supposed to be part of v2.
Will anyway send v3 now. Thanks for finding it out.

Thanks,
Siva
> 
> M


More information about the U-Boot mailing list