Skip to content

Commit d3a8c28

Browse files
Selvarasu Ganesangregkh
authored andcommitted
usb: dwc3: Fix timeout issue during controller enter/exit from halt state
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 159daf1 commit d3a8c28

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
@@ -2629,10 +2629,38 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on)
26292629
{
26302630
u32 reg;
26312631
u32 timeout = 2000;
2632+
u32 saved_config = 0;
26322633

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

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

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

0 commit comments

Comments
 (0)