Skip to content

Commit b30e41d

Browse files
RanWang1Dong Aisheng
authored and
Dong Aisheng
committed
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. Signed-off-by: Ran Wang <[email protected]> Reviewed-by: Peter Chen <[email protected]>
1 parent bca3c35 commit b30e41d

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

drivers/usb/dwc3/core.c

+3
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,9 @@ static void dwc3_get_properties(struct dwc3 *dwc)
13471347
dwc->dis_metastability_quirk = device_property_read_bool(dev,
13481348
"snps,dis_metastability_quirk");
13491349

1350+
dwc->host_vbus_glitches = device_property_read_bool(dev,
1351+
"snps,host-vbus-glitches");
1352+
13501353
dwc->lpm_nyet_threshold = lpm_nyet_threshold;
13511354
dwc->tx_de_emphasis = tx_de_emphasis;
13521355

drivers/usb/dwc3/core.h

+3
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,8 @@ struct dwc3_scratchpad_array {
10321032
* 2 - No de-emphasis
10331033
* 3 - Reserved
10341034
* @dis_metastability_quirk: set to disable metastability quirk.
1035+
* @host_vbus_glitches: set to avoid vbus glitch during
1036+
* xhci reset.
10351037
* @imod_interval: set the interrupt moderation interval in 250ns
10361038
* increments or 0 to disable.
10371039
*/
@@ -1223,6 +1225,7 @@ struct dwc3 {
12231225
unsigned tx_de_emphasis:2;
12241226

12251227
unsigned dis_metastability_quirk:1;
1228+
unsigned host_vbus_glitches:1;
12261229

12271230
u16 imod_interval;
12281231
};

drivers/usb/dwc3/host.c

+48
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,49 @@
99

1010
#include <linux/platform_device.h>
1111

12+
#include "../host/xhci.h"
13+
1214
#include "core.h"
1315

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

94+
/*
95+
* We have to power off all Root hub ports immediately after DWC3 set
96+
* to host mode to avoid VBUS glitch happen when xhci get reset later.
97+
*/
98+
if (dwc->host_vbus_glitches)
99+
dwc3_power_off_all_roothub_ports(dwc);
100+
53101
irq = dwc3_host_get_irq(dwc);
54102
if (irq < 0)
55103
return irq;

0 commit comments

Comments
 (0)