diff options
author | Jean-Jacques Hiblot <jjhiblot@ti.com> | 2019-09-11 12:33:49 +0300 |
---|---|---|
committer | Marek Vasut <marek.vasut+renesas@gmail.com> | 2019-10-24 12:28:17 +0300 |
commit | 1af590df164f88fffb6484842eec8c8d8e500e70 (patch) | |
tree | a5bdda427bf9659b37a287fd60aa2a5ac7a63048 /drivers/usb/dwc3 | |
parent | 3a38a0adb95bfebbbd39b2bb164f04bdeb10bc03 (diff) | |
download | u-boot-1af590df164f88fffb6484842eec8c8d8e500e70.tar.xz |
usb: dwc3-generic: factorize code
Factor code for re-usability.
This is another step toward adding host support.
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Diffstat (limited to 'drivers/usb/dwc3')
-rw-r--r-- | drivers/usb/dwc3/dwc3-generic.c | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index f29b93d191..d5c71d024f 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -28,27 +28,17 @@ struct dwc3_generic_plat { enum usb_dr_mode dr_mode; }; -#if CONFIG_IS_ENABLED(DM_USB_GADGET) struct dwc3_generic_priv { + void *base; struct dwc3 dwc3; struct phy *phys; int num_phys; }; -int dm_usb_gadget_handle_interrupts(struct udevice *dev) -{ - struct dwc3_generic_priv *priv = dev_get_priv(dev); - struct dwc3 *dwc3 = &priv->dwc3; - - dwc3_gadget_uboot_handle_interrupt(dwc3); - - return 0; -} - -static int dwc3_generic_peripheral_probe(struct udevice *dev) +static int dwc3_generic_probe(struct udevice *dev, + struct dwc3_generic_priv *priv) { int rc; - struct dwc3_generic_priv *priv = dev_get_priv(dev); struct dwc3_generic_plat *plat = dev_get_platdata(dev); struct dwc3 *dwc3 = &priv->dwc3; @@ -59,22 +49,22 @@ static int dwc3_generic_peripheral_probe(struct udevice *dev) if (rc) return rc; - dwc3->regs = map_physmem(plat->base, DWC3_OTG_REGS_END, MAP_NOCACHE); - dwc3->regs += DWC3_GLOBALS_REGS_START; + priv->base = map_physmem(plat->base, DWC3_OTG_REGS_END, MAP_NOCACHE); + dwc3->regs = priv->base + DWC3_GLOBALS_REGS_START; dwc3->dev = dev; rc = dwc3_init(dwc3); if (rc) { - unmap_physmem(dwc3->regs, MAP_NOCACHE); + unmap_physmem(priv->base, MAP_NOCACHE); return rc; } return 0; } -static int dwc3_generic_peripheral_remove(struct udevice *dev) +static int dwc3_generic_remove(struct udevice *dev, + struct dwc3_generic_priv *priv) { - struct dwc3_generic_priv *priv = dev_get_priv(dev); struct dwc3 *dwc3 = &priv->dwc3; dwc3_remove(dwc3); @@ -84,7 +74,7 @@ static int dwc3_generic_peripheral_remove(struct udevice *dev) return 0; } -static int dwc3_generic_peripheral_ofdata_to_platdata(struct udevice *dev) +static int dwc3_generic_ofdata_to_platdata(struct udevice *dev) { struct dwc3_generic_plat *plat = dev_get_platdata(dev); int node = dev_of_offset(dev); @@ -106,10 +96,35 @@ static int dwc3_generic_peripheral_ofdata_to_platdata(struct udevice *dev) return 0; } +#if CONFIG_IS_ENABLED(DM_USB_GADGET) +int dm_usb_gadget_handle_interrupts(struct udevice *dev) +{ + struct dwc3_generic_priv *priv = dev_get_priv(dev); + struct dwc3 *dwc3 = &priv->dwc3; + + dwc3_gadget_uboot_handle_interrupt(dwc3); + + return 0; +} + +static int dwc3_generic_peripheral_probe(struct udevice *dev) +{ + struct dwc3_generic_priv *priv = dev_get_priv(dev); + + return dwc3_generic_probe(dev, priv); +} + +static int dwc3_generic_peripheral_remove(struct udevice *dev) +{ + struct dwc3_generic_priv *priv = dev_get_priv(dev); + + return dwc3_generic_remove(dev, priv); +} + U_BOOT_DRIVER(dwc3_generic_peripheral) = { .name = "dwc3-generic-peripheral", .id = UCLASS_USB_GADGET_GENERIC, - .ofdata_to_platdata = dwc3_generic_peripheral_ofdata_to_platdata, + .ofdata_to_platdata = dwc3_generic_ofdata_to_platdata, .probe = dwc3_generic_peripheral_probe, .remove = dwc3_generic_peripheral_remove, .priv_auto_alloc_size = sizeof(struct dwc3_generic_priv), |