a8d23623be7d39d590b67955a3c83e6aa9cb4a18
[openwrt/staging/linusw.git] /
1 From 61d471c8da972c7ebbaf63779bf8100ee1ec54eb Mon Sep 17 00:00:00 2001
2 From: Ran Wang <ran.wang_1@nxp.com>
3 Date: Wed, 16 Jan 2019 13:23:17 +0800
4 Subject: [PATCH] usb: dwc3: Add workaround for host mode VBUS glitch when boot
5
6 When DWC3 is set to host mode by programming register DWC3_GCTL, VBUS
7 (or its control signal) will be turned on immediately on related Root Hub
8 ports. Then, the VBUS is turned off for a little while(15us) when do xhci
9 reset (conducted by xhci driver) and back to normal finally, we can
10 observe a negative glitch of related signal happen.
11
12 This VBUS glitch might cause some USB devices enumeration fail if kernel
13 boot with them connected. Such as LS1012AFWRY/LS1043ARDB/LX2160AQDS
14 /LS1088ARDB with Kingston 16GB USB2.0/Kingston USB3.0/JetFlash Transcend
15 4GB USB2.0 drives. The fail cases include enumerated as full-speed device
16 or report wrong device descriptor, etc.
17
18 One SW workaround which can fix this is by programing all xhci PORTSC[PP]
19 to 0 to turn off VBUS immediately after setting host mode in DWC3 driver
20 (per signal measurement result, it will be too late to do it in
21 xhci-plat.c or xhci.c). Then, after xhci reset complete in xhci driver,
22 PORTSC[PP]s' value will back to 1 automatically and VBUS on at that time,
23 no glitch happen and normal enumeration process has no impact.
24
25 Signed-off-by: Ran Wang <ran.wang_1@nxp.com>
26 Reviewed-by: Peter Chen <peter.chen@nxp.com>
27 ---
28 drivers/usb/dwc3/core.c | 3 +++
29 drivers/usb/dwc3/core.h | 3 +++
30 drivers/usb/dwc3/host.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
31 3 files changed, 54 insertions(+)
32
33 --- a/drivers/usb/dwc3/core.c
34 +++ b/drivers/usb/dwc3/core.c
35 @@ -1364,6 +1364,9 @@ static void dwc3_get_properties(struct d
36 dwc->dis_split_quirk = device_property_read_bool(dev,
37 "snps,dis-split-quirk");
38
39 + dwc->host_vbus_glitches = device_property_read_bool(dev,
40 + "snps,host-vbus-glitches");
41 +
42 dwc->lpm_nyet_threshold = lpm_nyet_threshold;
43 dwc->tx_de_emphasis = tx_de_emphasis;
44
45 --- a/drivers/usb/dwc3/core.h
46 +++ b/drivers/usb/dwc3/core.h
47 @@ -1047,6 +1047,8 @@ struct dwc3_scratchpad_array {
48 * 3 - Reserved
49 * @dis_metastability_quirk: set to disable metastability quirk.
50 * @dis_split_quirk: set to disable split boundary.
51 + * @host_vbus_glitches: set to avoid vbus glitch during
52 + * xhci reset.
53 * @imod_interval: set the interrupt moderation interval in 250ns
54 * increments or 0 to disable.
55 */
56 @@ -1242,6 +1244,8 @@ struct dwc3 {
57
58 unsigned dis_split_quirk:1;
59
60 + unsigned host_vbus_glitches:1;
61 +
62 u16 imod_interval;
63 };
64
65 --- a/drivers/usb/dwc3/host.c
66 +++ b/drivers/usb/dwc3/host.c
67 @@ -9,8 +9,49 @@
68
69 #include <linux/platform_device.h>
70
71 +#include "../host/xhci.h"
72 +
73 #include "core.h"
74
75 +
76 +#define XHCI_HCSPARAMS1 0x4
77 +#define XHCI_PORTSC_BASE 0x400
78 +
79 +/*
80 + * dwc3_power_off_all_roothub_ports - Power off all Root hub ports
81 + * @dwc3: Pointer to our controller context structure
82 + */
83 +static void dwc3_power_off_all_roothub_ports(struct dwc3 *dwc)
84 +{
85 + int i, port_num;
86 + u32 reg, op_regs_base, offset;
87 + void __iomem *xhci_regs;
88 +
89 + /* xhci regs is not mapped yet, do it temperary here */
90 + if (dwc->xhci_resources[0].start) {
91 + xhci_regs = ioremap(dwc->xhci_resources[0].start,
92 + DWC3_XHCI_REGS_END);
93 + if (IS_ERR(xhci_regs)) {
94 + dev_err(dwc->dev, "Failed to ioremap xhci_regs\n");
95 + return;
96 + }
97 +
98 + op_regs_base = HC_LENGTH(readl(xhci_regs));
99 + reg = readl(xhci_regs + XHCI_HCSPARAMS1);
100 + port_num = HCS_MAX_PORTS(reg);
101 +
102 + for (i = 1; i <= port_num; i++) {
103 + offset = op_regs_base + XHCI_PORTSC_BASE + 0x10*(i-1);
104 + reg = readl(xhci_regs + offset);
105 + reg &= ~PORT_POWER;
106 + writel(reg, xhci_regs + offset);
107 + }
108 +
109 + iounmap(xhci_regs);
110 + } else
111 + dev_err(dwc->dev, "xhci base reg invalid\n");
112 +}
113 +
114 static int dwc3_host_get_irq(struct dwc3 *dwc)
115 {
116 struct platform_device *dwc3_pdev = to_platform_device(dwc->dev);
117 @@ -50,6 +91,13 @@ int dwc3_host_init(struct dwc3 *dwc)
118 struct platform_device *dwc3_pdev = to_platform_device(dwc->dev);
119 int prop_idx = 0;
120
121 + /*
122 + * We have to power off all Root hub ports immediately after DWC3 set
123 + * to host mode to avoid VBUS glitch happen when xhci get reset later.
124 + */
125 + if (dwc->host_vbus_glitches)
126 + dwc3_power_off_all_roothub_ports(dwc);
127 +
128 irq = dwc3_host_get_irq(dwc);
129 if (irq < 0)
130 return irq;