Skip to content

Commit 66ae89a

Browse files
Selvarasu Ganesangregkh
authored andcommitted
usb: dwc3: Fix timeout issue during controller enter/exit from halt state
commit d3a8c28 upstream. There is a frequent timeout during controller enter/exit from halt state after toggling the run_stop bit by SW. This timeout occurs when performing frequent role switches between host and device, causing device enumeration issues due to the timeout. This issue was not present when USB2 suspend PHY was disabled by passing the SNPS quirks (snps,dis_u2_susphy_quirk and snps,dis_enblslpm_quirk) from the DTS. However, there is a requirement to enable USB2 suspend PHY by setting of GUSB2PHYCFG.ENBLSLPM and GUSB2PHYCFG.SUSPHY bits when controller starts in gadget or host mode results in the timeout issue. This commit addresses this timeout issue by ensuring that the bits GUSB2PHYCFG.ENBLSLPM and GUSB2PHYCFG.SUSPHY are cleared before starting the dwc3_gadget_run_stop sequence and restoring them after the dwc3_gadget_run_stop sequence is completed. Fixes: 72246da ("usb: Introduce DesignWare USB3 DRD Driver") Cc: stable <stable@kernel.org> Signed-off-by: Selvarasu Ganesan <selvarasu.g@samsung.com> Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com> Link: https://lore.kernel.org/r/20250201163903.459-1-selvarasu.g@samsung.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f9929bb commit 66ae89a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

drivers/usb/dwc3/gadget.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,10 +2630,38 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on)
26302630
{
26312631
u32 reg;
26322632
u32 timeout = 2000;
2633+
u32 saved_config = 0;
26332634

26342635
if (pm_runtime_suspended(dwc->dev))
26352636
return 0;
26362637

2638+
/*
2639+
* When operating in USB 2.0 speeds (HS/FS), ensure that
2640+
* GUSB2PHYCFG.ENBLSLPM and GUSB2PHYCFG.SUSPHY are cleared before starting
2641+
* or stopping the controller. This resolves timeout issues that occur
2642+
* during frequent role switches between host and device modes.
2643+
*
2644+
* Save and clear these settings, then restore them after completing the
2645+
* controller start or stop sequence.
2646+
*
2647+
* This solution was discovered through experimentation as it is not
2648+
* mentioned in the dwc3 programming guide. It has been tested on an
2649+
* Exynos platforms.
2650+
*/
2651+
reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
2652+
if (reg & DWC3_GUSB2PHYCFG_SUSPHY) {
2653+
saved_config |= DWC3_GUSB2PHYCFG_SUSPHY;
2654+
reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
2655+
}
2656+
2657+
if (reg & DWC3_GUSB2PHYCFG_ENBLSLPM) {
2658+
saved_config |= DWC3_GUSB2PHYCFG_ENBLSLPM;
2659+
reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM;
2660+
}
2661+
2662+
if (saved_config)
2663+
dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
2664+
26372665
reg = dwc3_readl(dwc->regs, DWC3_DCTL);
26382666
if (is_on) {
26392667
if (DWC3_VER_IS_WITHIN(DWC3, ANY, 187A)) {
@@ -2661,6 +2689,12 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on)
26612689
reg &= DWC3_DSTS_DEVCTRLHLT;
26622690
} while (--timeout && !(!is_on ^ !reg));
26632691

2692+
if (saved_config) {
2693+
reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
2694+
reg |= saved_config;
2695+
dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
2696+
}
2697+
26642698
if (!timeout)
26652699
return -ETIMEDOUT;
26662700

0 commit comments

Comments
 (0)