usb: dwc3-generic: factorize code
authorJean-Jacques Hiblot <jjhiblot@ti.com>
Wed, 11 Sep 2019 09:33:49 +0000 (11:33 +0200)
committerMarek Vasut <marek.vasut+renesas@gmail.com>
Thu, 24 Oct 2019 09:28:17 +0000 (11:28 +0200)
Factor code for re-usability.
This is another step toward adding host support.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
drivers/usb/dwc3/dwc3-generic.c

index f29b93d191f1b4cccb26eb8f398de22e359ca712..d5c71d024f37844cf3db2c99a101cc567380a690 100644 (file)
@@ -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),