Since EP0 transactions need to be completed before the controller halt
sequence is finished, this may take some time depending on the host and the
enabled functions.  Increase the controller halt timeout, so that we give
the controller sufficient time to handle EP0 transfers.

Signed-off-by: Wesley Cheng <quic_wch...@quicinc.com>
Link: https://lore.kernel.org/r/20220901193625.8727-4-quic_wch...@quicinc.com
Cherry-picked from Linux: 461ee467507c ("usb: dwc3: Increase DWC3 controller 
halt timeout")
Signed-off-by: Eugen Hristev <eugen.hris...@collabora.com>
---
Not to be merged, I know Marek does not apply any patches to DWC3.

 drivers/usb/dwc3/gadget.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 24a2c455b0a4..a86680719108 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1356,7 +1356,7 @@ static int dwc3_gadget_set_selfpowered(struct usb_gadget 
*g,
 static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend)
 {
        u32                     reg;
-       u32                     timeout = 500;
+       u32                     timeout = 2000;
 
        reg = dwc3_readl(dwc->regs, DWC3_DCTL);
        if (is_on) {
@@ -1385,6 +1385,7 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int 
is_on, int suspend)
        dwc3_gadget_dctl_write_safe(dwc, reg);
 
        do {
+               mdelay(2);
                reg = dwc3_readl(dwc->regs, DWC3_DSTS);
                if (is_on) {
                        if (!(reg & DWC3_DSTS_DEVCTRLHLT))
@@ -1396,7 +1397,6 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int 
is_on, int suspend)
                timeout--;
                if (!timeout)
                        return -ETIMEDOUT;
-               udelay(1);
        } while (1);
 
        dev_vdbg(dwc->dev, "gadget %s data soft-%s\n",
-- 
2.34.1

Reply via email to