usb: dwc3: core: Fix timeout check

dwc3_core_init loops 'timeout' times to check if the IP block is out
of reset using 'while (timeout--)'. If there is some issue and
the block doesn't come out of reset, the loop will run till
'timeout' becomes zero and the post decrement operator would set
timeout to 0xffffffff. Though the IP block is not out reset, the
subsequent if check 'if !timeout' would fail as timeout is not
equal to zero and the function proceeds with the initialization.

Use poll API instead to resolve this.

Signed-off-by: Varadarajan Narayanan <quic_varada@quicinc.com>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Reviewed-by: Caleb Connolly <caleb.connolly@linaro.org>
This commit is contained in:
Varadarajan Narayanan
2025-01-15 11:50:44 +05:30
committed by Marek Vasut
parent df2ed552f0
commit 068f83499c

View File

@@ -23,6 +23,7 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/iopoll.h>
#include <linux/ioport.h> #include <linux/ioport.h>
#include <dm.h> #include <dm.h>
#include <generic-phy.h> #include <generic-phy.h>
@@ -587,7 +588,6 @@ static void dwc3_set_incr_burst_type(struct dwc3 *dwc)
*/ */
static int dwc3_core_init(struct dwc3 *dwc) static int dwc3_core_init(struct dwc3 *dwc)
{ {
unsigned long timeout;
u32 hwparams4 = dwc->hwparams.hwparams4; u32 hwparams4 = dwc->hwparams.hwparams4;
u32 reg; u32 reg;
int ret; int ret;
@@ -610,15 +610,11 @@ static int dwc3_core_init(struct dwc3 *dwc)
} }
/* issue device SoftReset too */ /* issue device SoftReset too */
timeout = 5000;
dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST); dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST);
while (timeout--) { ret = read_poll_timeout(dwc3_readl, reg,
reg = dwc3_readl(dwc->regs, DWC3_DCTL); !(reg & DWC3_DCTL_CSFTRST),
if (!(reg & DWC3_DCTL_CSFTRST)) 1, 5000, dwc->regs, DWC3_DCTL);
break; if (ret) {
};
if (!timeout) {
dev_err(dwc->dev, "Reset Timed Out\n"); dev_err(dwc->dev, "Reset Timed Out\n");
ret = -ETIMEDOUT; ret = -ETIMEDOUT;
goto err0; goto err0;