]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - drivers/usb/dwc3/core.c
dwc3: core: add support for multiple dwc3 controllers
[karo-tx-uboot.git] / drivers / usb / dwc3 / core.c
index ebfb6ca0f25c31f0af3e76608f114cbb894bc296..bd34dbd23c877e345da16daf58b73d7f31643ee1 100644 (file)
  * SPDX-License-Identifier:     GPL-2.0
  */
 
-#include <linux/version.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/spinlock.h>
-#include <linux/platform_device.h>
-#include <linux/interrupt.h>
+#include <common.h>
+#include <malloc.h>
+#include <dwc3-uboot.h>
+#include <asm/dma-mapping.h>
 #include <linux/ioport.h>
-#include <linux/io.h>
-#include <linux/list.h>
-#include <linux/delay.h>
-#include <linux/dma-mapping.h>
-#include <linux/of.h>
-#include <linux/acpi.h>
 
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
-#include <linux/usb/of.h>
-#include <linux/usb/otg.h>
 
-#include "platform_data.h"
 #include "core.h"
 #include "gadget.h"
 #include "io.h"
 
-#include "debug.h"
+#include "linux-compat.h"
 
+static LIST_HEAD(dwc3_list);
 /* -------------------------------------------------------------------------- */
 
 void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
@@ -60,7 +49,6 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
 static int dwc3_core_soft_reset(struct dwc3 *dwc)
 {
        u32             reg;
-       int             ret;
 
        /* Before Resetting PHY, put Core in Reset */
        reg = dwc3_readl(dwc->regs, DWC3_GCTL);
@@ -77,17 +65,6 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
        reg |= DWC3_GUSB2PHYCFG_PHYSOFTRST;
        dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
 
-       usb_phy_init(dwc->usb2_phy);
-       usb_phy_init(dwc->usb3_phy);
-       ret = phy_init(dwc->usb2_generic_phy);
-       if (ret < 0)
-               return ret;
-
-       ret = phy_init(dwc->usb3_generic_phy);
-       if (ret < 0) {
-               phy_exit(dwc->usb2_generic_phy);
-               return ret;
-       }
        mdelay(100);
 
        /* Clear USB3 PHY reset */
@@ -118,7 +95,7 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
 static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
                struct dwc3_event_buffer *evt)
 {
-       dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma);
+       dma_free_coherent(evt->buf);
 }
 
 /**
@@ -140,8 +117,8 @@ static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc,
 
        evt->dwc        = dwc;
        evt->length     = length;
-       evt->buf        = dma_alloc_coherent(dwc->dev, length,
-                       &evt->dma, GFP_KERNEL);
+       evt->buf        = dma_alloc_coherent(length,
+                                            (unsigned long *)&evt->dma);
        if (!evt->buf)
                return ERR_PTR(-ENOMEM);
 
@@ -276,13 +253,9 @@ static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
        if (!dwc->nr_scratch)
                return 0;
 
-        /* should never fall here */
-       if (!WARN_ON(dwc->scratchbuf))
-               return 0;
-
-       scratch_addr = dma_map_single(dwc->dev, dwc->scratchbuf,
-                       dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE,
-                       DMA_BIDIRECTIONAL);
+       scratch_addr = dma_map_single(dwc->scratchbuf,
+                                     dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE,
+                                     DMA_BIDIRECTIONAL);
        if (dma_mapping_error(dwc->dev, scratch_addr)) {
                dev_err(dwc->dev, "failed to map scratch buffer\n");
                ret = -EFAULT;
@@ -308,8 +281,8 @@ static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
        return 0;
 
 err1:
-       dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
-                       DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
+       dma_unmap_single((void *)dwc->scratch_addr, dwc->nr_scratch *
+                        DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
 
 err0:
        return ret;
@@ -323,12 +296,8 @@ static void dwc3_free_scratch_buffers(struct dwc3 *dwc)
        if (!dwc->nr_scratch)
                return;
 
-        /* should never fall here */
-       if (!WARN_ON(dwc->scratchbuf))
-               return;
-
-       dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
-                       DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
+       dma_unmap_single((void *)dwc->scratch_addr, dwc->nr_scratch *
+                        DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
        kfree(dwc->scratchbuf);
 }
 
@@ -446,12 +415,6 @@ static int dwc3_core_init(struct dwc3 *dwc)
        }
        dwc->revision = reg;
 
-       /*
-        * Write Linux Version Code to our GUID register so it's easy to figure
-        * out which kernel version a bug was found.
-        */
-       dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE);
-
        /* Handle USB2.0-only core configuration */
        if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
                        DWC3_GHWPARAMS3_SSPHY_IFC_DIS) {
@@ -460,21 +423,19 @@ static int dwc3_core_init(struct dwc3 *dwc)
        }
 
        /* issue device SoftReset too */
-       timeout = jiffies + msecs_to_jiffies(500);
+       timeout = 5000;
        dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST);
-       do {
+       while (timeout--) {
                reg = dwc3_readl(dwc->regs, DWC3_DCTL);
                if (!(reg & DWC3_DCTL_CSFTRST))
                        break;
+       };
 
-               if (time_after(jiffies, timeout)) {
-                       dev_err(dwc->dev, "Reset Timed Out\n");
-                       ret = -ETIMEDOUT;
-                       goto err0;
-               }
-
-               cpu_relax();
-       } while (true);
+       if (!timeout) {
+               dev_err(dwc->dev, "Reset Timed Out\n");
+               ret = -ETIMEDOUT;
+               goto err0;
+       }
 
        ret = dwc3_core_soft_reset(dwc);
        if (ret)
@@ -525,8 +486,9 @@ static int dwc3_core_init(struct dwc3 *dwc)
                dwc->is_fpga = true;
        }
 
-       WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga,
-                       "disable_scramble cannot be used on non-FPGA builds\n");
+       if(dwc->disable_scramble_quirk && !dwc->is_fpga)
+               WARN(true,
+                    "disable_scramble cannot be used on non-FPGA builds\n");
 
        if (dwc->disable_scramble_quirk && dwc->is_fpga)
                reg |= DWC3_GCTL_DISSCRAMBLE;
@@ -553,22 +515,16 @@ static int dwc3_core_init(struct dwc3 *dwc)
 
        ret = dwc3_alloc_scratch_buffers(dwc);
        if (ret)
-               goto err1;
+               goto err0;
 
        ret = dwc3_setup_scratch_buffers(dwc);
        if (ret)
-               goto err2;
+               goto err1;
 
        return 0;
 
-err2:
-       dwc3_free_scratch_buffers(dwc);
-
 err1:
-       usb_phy_shutdown(dwc->usb2_phy);
-       usb_phy_shutdown(dwc->usb3_phy);
-       phy_exit(dwc->usb2_generic_phy);
-       phy_exit(dwc->usb3_generic_phy);
+       dwc3_free_scratch_buffers(dwc);
 
 err0:
        return ret;
@@ -577,82 +533,10 @@ err0:
 static void dwc3_core_exit(struct dwc3 *dwc)
 {
        dwc3_free_scratch_buffers(dwc);
-       usb_phy_shutdown(dwc->usb2_phy);
-       usb_phy_shutdown(dwc->usb3_phy);
-       phy_exit(dwc->usb2_generic_phy);
-       phy_exit(dwc->usb3_generic_phy);
-}
-
-static int dwc3_core_get_phy(struct dwc3 *dwc)
-{
-       struct device           *dev = dwc->dev;
-       struct device_node      *node = dev->of_node;
-       int ret;
-
-       if (node) {
-               dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0);
-               dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1);
-       } else {
-               dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
-               dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
-       }
-
-       if (IS_ERR(dwc->usb2_phy)) {
-               ret = PTR_ERR(dwc->usb2_phy);
-               if (ret == -ENXIO || ret == -ENODEV) {
-                       dwc->usb2_phy = NULL;
-               } else if (ret == -EPROBE_DEFER) {
-                       return ret;
-               } else {
-                       dev_err(dev, "no usb2 phy configured\n");
-                       return ret;
-               }
-       }
-
-       if (IS_ERR(dwc->usb3_phy)) {
-               ret = PTR_ERR(dwc->usb3_phy);
-               if (ret == -ENXIO || ret == -ENODEV) {
-                       dwc->usb3_phy = NULL;
-               } else if (ret == -EPROBE_DEFER) {
-                       return ret;
-               } else {
-                       dev_err(dev, "no usb3 phy configured\n");
-                       return ret;
-               }
-       }
-
-       dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy");
-       if (IS_ERR(dwc->usb2_generic_phy)) {
-               ret = PTR_ERR(dwc->usb2_generic_phy);
-               if (ret == -ENOSYS || ret == -ENODEV) {
-                       dwc->usb2_generic_phy = NULL;
-               } else if (ret == -EPROBE_DEFER) {
-                       return ret;
-               } else {
-                       dev_err(dev, "no usb2 phy configured\n");
-                       return ret;
-               }
-       }
-
-       dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy");
-       if (IS_ERR(dwc->usb3_generic_phy)) {
-               ret = PTR_ERR(dwc->usb3_generic_phy);
-               if (ret == -ENOSYS || ret == -ENODEV) {
-                       dwc->usb3_generic_phy = NULL;
-               } else if (ret == -EPROBE_DEFER) {
-                       return ret;
-               } else {
-                       dev_err(dev, "no usb3 phy configured\n");
-                       return ret;
-               }
-       }
-
-       return 0;
 }
 
 static int dwc3_core_init_mode(struct dwc3 *dwc)
 {
-       struct device *dev = dwc->dev;
        int ret;
 
        switch (dwc->dr_mode) {
@@ -715,20 +599,27 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc)
 
 #define DWC3_ALIGN_MASK                (16 - 1)
 
-static int dwc3_probe(struct platform_device *pdev)
+/**
+ * dwc3_uboot_init - dwc3 core uboot initialization code
+ * @dwc3_dev: struct dwc3_device containing initialization data
+ *
+ * Entry point for dwc3 driver (equivalent to dwc3_probe in linux
+ * kernel driver). Pointer to dwc3_device should be passed containing
+ * base address and other initialization data. Returns '0' on success and
+ * a negative value on failure.
+ *
+ * Generally called from board_usb_init() implemented in board file.
+ */
+int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
 {
-       struct device           *dev = &pdev->dev;
-       struct dwc3_platform_data *pdata = dev_get_platdata(dev);
-       struct device_node      *node = dev->of_node;
-       struct resource         *res;
        struct dwc3             *dwc;
+       struct device           *dev;
        u8                      lpm_nyet_threshold;
        u8                      tx_de_emphasis;
        u8                      hird_threshold;
 
        int                     ret;
 
-       void __iomem            *regs;
        void                    *mem;
 
        mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
@@ -737,48 +628,8 @@ static int dwc3_probe(struct platform_device *pdev)
 
        dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
        dwc->mem = mem;
-       dwc->dev = dev;
-
-       res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-       if (!res) {
-               dev_err(dev, "missing IRQ\n");
-               return -ENODEV;
-       }
-       dwc->xhci_resources[1].start = res->start;
-       dwc->xhci_resources[1].end = res->end;
-       dwc->xhci_resources[1].flags = res->flags;
-       dwc->xhci_resources[1].name = res->name;
-
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       if (!res) {
-               dev_err(dev, "missing memory resource\n");
-               return -ENODEV;
-       }
-
-       dwc->xhci_resources[0].start = res->start;
-       dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
-                                       DWC3_XHCI_REGS_END;
-       dwc->xhci_resources[0].flags = res->flags;
-       dwc->xhci_resources[0].name = res->name;
-
-       res->start += DWC3_GLOBALS_REGS_START;
-
-       /*
-        * Request memory region but exclude xHCI regs,
-        * since it will be requested by the xhci-plat driver.
-        */
-       regs = devm_ioremap_resource(dev, res);
-       if (IS_ERR(regs))
-               return PTR_ERR(regs);
 
-       dwc->regs       = regs;
-       dwc->regs_size  = resource_size(res);
-       /*
-        * restore res->start back to its original value so that,
-        * in case the probe is deferred, we don't end up getting error in
-        * request the memory region the next time probe is called.
-        */
-       res->start -= DWC3_GLOBALS_REGS_START;
+       dwc->regs       = (int *)(dwc3_dev->base + DWC3_GLOBALS_REGS_START);
 
        /* default to highest possible threshold */
        lpm_nyet_threshold = 0xff;
@@ -792,73 +643,31 @@ static int dwc3_probe(struct platform_device *pdev)
         */
        hird_threshold = 12;
 
-       if (node) {
-               dwc->maximum_speed = of_usb_get_maximum_speed(node);
-               dwc->has_lpm_erratum = of_property_read_bool(node,
-                               "snps,has-lpm-erratum");
-               of_property_read_u8(node, "snps,lpm-nyet-threshold",
-                               &lpm_nyet_threshold);
-               dwc->is_utmi_l1_suspend = of_property_read_bool(node,
-                               "snps,is-utmi-l1-suspend");
-               of_property_read_u8(node, "snps,hird-threshold",
-                               &hird_threshold);
-
-               dwc->needs_fifo_resize = of_property_read_bool(node,
-                               "tx-fifo-resize");
-               dwc->dr_mode = of_usb_get_dr_mode(node);
-
-               dwc->disable_scramble_quirk = of_property_read_bool(node,
-                               "snps,disable_scramble_quirk");
-               dwc->u2exit_lfps_quirk = of_property_read_bool(node,
-                               "snps,u2exit_lfps_quirk");
-               dwc->u2ss_inp3_quirk = of_property_read_bool(node,
-                               "snps,u2ss_inp3_quirk");
-               dwc->req_p1p2p3_quirk = of_property_read_bool(node,
-                               "snps,req_p1p2p3_quirk");
-               dwc->del_p1p2p3_quirk = of_property_read_bool(node,
-                               "snps,del_p1p2p3_quirk");
-               dwc->del_phy_power_chg_quirk = of_property_read_bool(node,
-                               "snps,del_phy_power_chg_quirk");
-               dwc->lfps_filter_quirk = of_property_read_bool(node,
-                               "snps,lfps_filter_quirk");
-               dwc->rx_detect_poll_quirk = of_property_read_bool(node,
-                               "snps,rx_detect_poll_quirk");
-               dwc->dis_u3_susphy_quirk = of_property_read_bool(node,
-                               "snps,dis_u3_susphy_quirk");
-               dwc->dis_u2_susphy_quirk = of_property_read_bool(node,
-                               "snps,dis_u2_susphy_quirk");
-
-               dwc->tx_de_emphasis_quirk = of_property_read_bool(node,
-                               "snps,tx_de_emphasis_quirk");
-               of_property_read_u8(node, "snps,tx_de_emphasis",
-                               &tx_de_emphasis);
-       } else if (pdata) {
-               dwc->maximum_speed = pdata->maximum_speed;
-               dwc->has_lpm_erratum = pdata->has_lpm_erratum;
-               if (pdata->lpm_nyet_threshold)
-                       lpm_nyet_threshold = pdata->lpm_nyet_threshold;
-               dwc->is_utmi_l1_suspend = pdata->is_utmi_l1_suspend;
-               if (pdata->hird_threshold)
-                       hird_threshold = pdata->hird_threshold;
-
-               dwc->needs_fifo_resize = pdata->tx_fifo_resize;
-               dwc->dr_mode = pdata->dr_mode;
-
-               dwc->disable_scramble_quirk = pdata->disable_scramble_quirk;
-               dwc->u2exit_lfps_quirk = pdata->u2exit_lfps_quirk;
-               dwc->u2ss_inp3_quirk = pdata->u2ss_inp3_quirk;
-               dwc->req_p1p2p3_quirk = pdata->req_p1p2p3_quirk;
-               dwc->del_p1p2p3_quirk = pdata->del_p1p2p3_quirk;
-               dwc->del_phy_power_chg_quirk = pdata->del_phy_power_chg_quirk;
-               dwc->lfps_filter_quirk = pdata->lfps_filter_quirk;
-               dwc->rx_detect_poll_quirk = pdata->rx_detect_poll_quirk;
-               dwc->dis_u3_susphy_quirk = pdata->dis_u3_susphy_quirk;
-               dwc->dis_u2_susphy_quirk = pdata->dis_u2_susphy_quirk;
-
-               dwc->tx_de_emphasis_quirk = pdata->tx_de_emphasis_quirk;
-               if (pdata->tx_de_emphasis)
-                       tx_de_emphasis = pdata->tx_de_emphasis;
-       }
+       dwc->maximum_speed = dwc3_dev->maximum_speed;
+       dwc->has_lpm_erratum = dwc3_dev->has_lpm_erratum;
+       if (dwc3_dev->lpm_nyet_threshold)
+               lpm_nyet_threshold = dwc3_dev->lpm_nyet_threshold;
+       dwc->is_utmi_l1_suspend = dwc3_dev->is_utmi_l1_suspend;
+       if (dwc3_dev->hird_threshold)
+               hird_threshold = dwc3_dev->hird_threshold;
+
+       dwc->needs_fifo_resize = dwc3_dev->tx_fifo_resize;
+       dwc->dr_mode = dwc3_dev->dr_mode;
+
+       dwc->disable_scramble_quirk = dwc3_dev->disable_scramble_quirk;
+       dwc->u2exit_lfps_quirk = dwc3_dev->u2exit_lfps_quirk;
+       dwc->u2ss_inp3_quirk = dwc3_dev->u2ss_inp3_quirk;
+       dwc->req_p1p2p3_quirk = dwc3_dev->req_p1p2p3_quirk;
+       dwc->del_p1p2p3_quirk = dwc3_dev->del_p1p2p3_quirk;
+       dwc->del_phy_power_chg_quirk = dwc3_dev->del_phy_power_chg_quirk;
+       dwc->lfps_filter_quirk = dwc3_dev->lfps_filter_quirk;
+       dwc->rx_detect_poll_quirk = dwc3_dev->rx_detect_poll_quirk;
+       dwc->dis_u3_susphy_quirk = dwc3_dev->dis_u3_susphy_quirk;
+       dwc->dis_u2_susphy_quirk = dwc3_dev->dis_u2_susphy_quirk;
+
+       dwc->tx_de_emphasis_quirk = dwc3_dev->tx_de_emphasis_quirk;
+       if (dwc3_dev->tx_de_emphasis)
+               tx_de_emphasis = dwc3_dev->tx_de_emphasis;
 
        /* default to superspeed if no maximum_speed passed */
        if (dwc->maximum_speed == USB_SPEED_UNKNOWN)
@@ -870,26 +679,14 @@ static int dwc3_probe(struct platform_device *pdev)
        dwc->hird_threshold = hird_threshold
                | (dwc->is_utmi_l1_suspend << 4);
 
-       ret = dwc3_core_get_phy(dwc);
-       if (ret)
-               return ret;
-
-       spin_lock_init(&dwc->lock);
-       platform_set_drvdata(pdev, dwc);
-
-       if (!dev->dma_mask) {
-               dev->dma_mask = dev->parent->dma_mask;
-               dev->dma_parms = dev->parent->dma_parms;
-               dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask);
-       }
+       dwc->index = dwc3_dev->index;
 
        dwc3_cache_hwparams(dwc);
 
        ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
        if (ret) {
                dev_err(dwc->dev, "failed to allocate event buffers\n");
-               ret = -ENOMEM;
-               goto err0;
+               return -ENOMEM;
        }
 
        if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
@@ -906,49 +703,24 @@ static int dwc3_probe(struct platform_device *pdev)
                goto err0;
        }
 
-       usb_phy_set_suspend(dwc->usb2_phy, 0);
-       usb_phy_set_suspend(dwc->usb3_phy, 0);
-       ret = phy_power_on(dwc->usb2_generic_phy);
-       if (ret < 0)
-               goto err1;
-
-       ret = phy_power_on(dwc->usb3_generic_phy);
-       if (ret < 0)
-               goto err_usb2phy_power;
-
        ret = dwc3_event_buffers_setup(dwc);
        if (ret) {
                dev_err(dwc->dev, "failed to setup event buffers\n");
-               goto err_usb3phy_power;
+               goto err1;
        }
 
        ret = dwc3_core_init_mode(dwc);
        if (ret)
                goto err2;
 
-       ret = dwc3_debugfs_init(dwc);
-       if (ret) {
-               dev_err(dev, "failed to initialize debugfs\n");
-               goto err3;
-       }
+       list_add_tail(&dwc->list, &dwc3_list);
 
        return 0;
 
-err3:
-       dwc3_core_exit_mode(dwc);
-
 err2:
        dwc3_event_buffers_cleanup(dwc);
 
-err_usb3phy_power:
-       phy_power_off(dwc->usb3_generic_phy);
-
-err_usb2phy_power:
-       phy_power_off(dwc->usb2_generic_phy);
-
 err1:
-       usb_phy_set_suspend(dwc->usb2_phy, 1);
-       usb_phy_set_suspend(dwc->usb3_phy, 1);
        dwc3_core_exit(dwc);
 
 err0:
@@ -957,61 +729,35 @@ err0:
        return ret;
 }
 
-static int dwc3_remove(struct platform_device *pdev)
+/**
+ * dwc3_uboot_exit - dwc3 core uboot cleanup code
+ * @index: index of this controller
+ *
+ * Performs cleanup of memory allocated in dwc3_uboot_init and other misc
+ * cleanups (equivalent to dwc3_remove in linux). index of _this_ controller
+ * should be passed and should match with the index passed in
+ * dwc3_device during init.
+ *
+ * Generally called from board file.
+ */
+void dwc3_uboot_exit(int index)
 {
-       struct dwc3     *dwc = platform_get_drvdata(pdev);
-
-       dwc3_debugfs_exit(dwc);
-       dwc3_core_exit_mode(dwc);
-       dwc3_event_buffers_cleanup(dwc);
-       dwc3_free_event_buffers(dwc);
-
-       usb_phy_set_suspend(dwc->usb2_phy, 1);
-       usb_phy_set_suspend(dwc->usb3_phy, 1);
-       phy_power_off(dwc->usb2_generic_phy);
-       phy_power_off(dwc->usb3_generic_phy);
-
-       dwc3_core_exit(dwc);
-
-       return 0;
+       struct dwc3 *dwc;
+
+       list_for_each_entry(dwc, &dwc3_list, list) {
+               if (dwc->index != index)
+                       continue;
+
+               dwc3_core_exit_mode(dwc);
+               dwc3_event_buffers_cleanup(dwc);
+               dwc3_free_event_buffers(dwc);
+               dwc3_core_exit(dwc);
+               list_del(&dwc->list);
+               kfree(dwc->mem);
+               break;
+       }
 }
 
-#ifdef CONFIG_OF
-static const struct of_device_id of_dwc3_match[] = {
-       {
-               .compatible = "snps,dwc3"
-       },
-       {
-               .compatible = "synopsys,dwc3"
-       },
-       { },
-};
-MODULE_DEVICE_TABLE(of, of_dwc3_match);
-#endif
-
-#ifdef CONFIG_ACPI
-
-#define ACPI_ID_INTEL_BSW      "808622B7"
-
-static const struct acpi_device_id dwc3_acpi_match[] = {
-       { ACPI_ID_INTEL_BSW, 0 },
-       { },
-};
-MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match);
-#endif
-
-static struct platform_driver dwc3_driver = {
-       .probe          = dwc3_probe,
-       .remove         = dwc3_remove,
-       .driver         = {
-               .name   = "dwc3",
-               .of_match_table = of_match_ptr(of_dwc3_match),
-               .acpi_match_table = ACPI_PTR(dwc3_acpi_match),
-       },
-};
-
-module_platform_driver(dwc3_driver);
-
 MODULE_ALIAS("platform:dwc3");
 MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
 MODULE_LICENSE("GPL v2");