Skip to content

Commit 2d2a334

Browse files
RanWang1gregkh
authored andcommitted
usb: dwc3: Add workaround for host mode VBUS glitch when boot
When DWC3 is set to host mode by programming register DWC3_GCTL, VBUS (or its control signal) will be turned on immediately on related Root Hub ports. Then, the VBUS is turned off for a little while(15us) when do xhci reset (conducted by xhci driver) and back to normal finally, we can observe a negative glitch of related signal happen. This VBUS glitch might cause some USB devices enumeration fail if kernel boot with them connected. Such as LS1012AFWRY/LS1043ARDB/LX2160AQDS /LS1088ARDB with Kingston 16GB USB2.0/Kingston USB3.0/JetFlash Transcend 4GB USB2.0 drives. The fail cases include enumerated as full-speed device or report wrong device descriptor, etc. One SW workaround which can fix this is by programing all xhci PORTSC[PP] to 0 to turn off VBUS immediately after setting host mode in DWC3 driver (per signal measurement result, it will be too late to do it in xhci-plat.c or xhci.c). Then, after xhci reset complete in xhci driver, PORTSC[PP]s' value will back to 1 automatically and VBUS on at that time, no glitch happen and normal enumeration process has no impact. Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com> Signed-off-by: Ran Wang <ran.wang_1@nxp.com> Reviewed-by: Peter Chen <peter.chen@nxp.com> Signed-off-by: Frank Li <Frank.Li@nxp.com> Link: https://lore.kernel.org/r/20240124152525.3910311-4-Frank.Li@nxp.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent bc83a87 commit 2d2a334

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

drivers/usb/dwc3/core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,9 @@ static void dwc3_get_properties(struct dwc3 *dwc)
16261626
dwc->dis_split_quirk = device_property_read_bool(dev,
16271627
"snps,dis-split-quirk");
16281628

1629+
dwc->host_vbus_glitches_quirk = device_property_read_bool(dev,
1630+
"snps,host-vbus-glitches-quirk");
1631+
16291632
dwc->lpm_nyet_threshold = lpm_nyet_threshold;
16301633
dwc->tx_de_emphasis = tx_de_emphasis;
16311634

drivers/usb/dwc3/core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,7 @@ struct dwc3_scratchpad_array {
11321132
* 2 - No de-emphasis
11331133
* 3 - Reserved
11341134
* @dis_metastability_quirk: set to disable metastability quirk.
1135+
* @host_vbus_glitches_quirk: set to avoid vbus glitch during xhci reset.
11351136
* @dis_split_quirk: set to disable split boundary.
11361137
* @wakeup_configured: set if the device is configured for remote wakeup.
11371138
* @suspended: set to track suspend event due to U3/L2.
@@ -1353,6 +1354,7 @@ struct dwc3 {
13531354
unsigned tx_de_emphasis:2;
13541355

13551356
unsigned dis_metastability_quirk:1;
1357+
unsigned host_vbus_glitches_quirk:1;
13561358

13571359
unsigned dis_split_quirk:1;
13581360
unsigned async_callbacks:1;

drivers/usb/dwc3/host.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,52 @@
1111
#include <linux/of.h>
1212
#include <linux/platform_device.h>
1313

14+
#include "../host/xhci-port.h"
15+
#include "../host/xhci-ext-caps.h"
16+
#include "../host/xhci-caps.h"
1417
#include "core.h"
1518

19+
#define XHCI_HCSPARAMS1 0x4
20+
#define XHCI_PORTSC_BASE 0x400
21+
22+
/**
23+
* dwc3_power_off_all_roothub_ports - Power off all Root hub ports
24+
* @dwc: Pointer to our controller context structure
25+
*/
26+
static void dwc3_power_off_all_roothub_ports(struct dwc3 *dwc)
27+
{
28+
void __iomem *xhci_regs;
29+
u32 op_regs_base;
30+
int port_num;
31+
u32 offset;
32+
u32 reg;
33+
int i;
34+
35+
/* xhci regs is not mapped yet, do it temperary here */
36+
if (dwc->xhci_resources[0].start) {
37+
xhci_regs = ioremap(dwc->xhci_resources[0].start, DWC3_XHCI_REGS_END);
38+
if (IS_ERR(xhci_regs)) {
39+
dev_err(dwc->dev, "Failed to ioremap xhci_regs\n");
40+
return;
41+
}
42+
43+
op_regs_base = HC_LENGTH(readl(xhci_regs));
44+
reg = readl(xhci_regs + XHCI_HCSPARAMS1);
45+
port_num = HCS_MAX_PORTS(reg);
46+
47+
for (i = 1; i <= port_num; i++) {
48+
offset = op_regs_base + XHCI_PORTSC_BASE + 0x10 * (i - 1);
49+
reg = readl(xhci_regs + offset);
50+
reg &= ~PORT_POWER;
51+
writel(reg, xhci_regs + offset);
52+
}
53+
54+
iounmap(xhci_regs);
55+
} else {
56+
dev_err(dwc->dev, "xhci base reg invalid\n");
57+
}
58+
}
59+
1660
static void dwc3_host_fill_xhci_irq_res(struct dwc3 *dwc,
1761
int irq, char *name)
1862
{
@@ -66,6 +110,13 @@ int dwc3_host_init(struct dwc3 *dwc)
66110
int ret, irq;
67111
int prop_idx = 0;
68112

113+
/*
114+
* Some platforms need to power off all Root hub ports immediately after DWC3 set to host
115+
* mode to avoid VBUS glitch happen when xhci get reset later.
116+
*/
117+
if (dwc->host_vbus_glitches_quirk)
118+
dwc3_power_off_all_roothub_ports(dwc);
119+
69120
irq = dwc3_host_get_irq(dwc);
70121
if (irq < 0)
71122
return irq;

0 commit comments

Comments
 (0)