usb: dwc3: soft reset to it's own function
authorHeikki Krogerus <heikki.krogerus@linux.intel.com>
Wed, 13 May 2015 12:26:47 +0000 (15:26 +0300)
committerFelipe Balbi <balbi@ti.com>
Wed, 13 May 2015 17:06:05 +0000 (12:06 -0500)
So it can be called from other places later.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Acked-by: David Cohen <david.a.cohen@linux.intel.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/dwc3/core.c

index 104b236425484b2375cacb6159b1a7b697529319..921f181b620fc2bbcee1c3a878a4e3596f66ed0c 100644 (file)
@@ -116,6 +116,33 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
        return 0;
 }
 
+/**
+ * dwc3_soft_reset - Issue soft reset
+ * @dwc: Pointer to our controller context structure
+ */
+static int dwc3_soft_reset(struct dwc3 *dwc)
+{
+       unsigned long timeout;
+       u32 reg;
+
+       timeout = jiffies + msecs_to_jiffies(500);
+       dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST);
+       do {
+               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");
+                       return -ETIMEDOUT;
+               }
+
+               cpu_relax();
+       } while (true);
+
+       return 0;
+}
+
 /**
  * dwc3_free_one_event_buffer - Frees one event buffer
  * @dwc: Pointer to our controller context structure
@@ -438,7 +465,6 @@ static void dwc3_phy_setup(struct dwc3 *dwc)
  */
 static int dwc3_core_init(struct dwc3 *dwc)
 {
-       unsigned long           timeout;
        u32                     hwparams4 = dwc->hwparams.hwparams4;
        u32                     reg;
        int                     ret;
@@ -466,21 +492,9 @@ static int dwc3_core_init(struct dwc3 *dwc)
        }
 
        /* issue device SoftReset too */
-       timeout = jiffies + msecs_to_jiffies(500);
-       dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST);
-       do {
-               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);
+       ret = dwc3_soft_reset(dwc);
+       if (ret)
+               goto err0;
 
        ret = dwc3_core_soft_reset(dwc);
        if (ret)