4a206d2cc28dd4e50df435d452fd90d6e423cbf5
[openwrt/openwrt.git] / target / linux / bcm53xx / patches-4.4 / 191-usb-xhci-add-Broadcom-specific-fake-doorbell.patch
1 From dd0e5f9a6a4aed849bdb80641c2a2350476cede7 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
3 Date: Sun, 21 Jun 2015 11:10:49 +0200
4 Subject: [PATCH v3 2/6] usb: xhci: add Broadcom specific fake doorbell
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 This fixes problem with controller seeing devices only in some small
10 percentage of cold boots.
11 This quirk is also added to the platform data so we can activate it
12 when we register our platform driver.
13
14 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
15 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
16 ---
17 drivers/usb/host/xhci-plat.c | 3 +++
18 drivers/usb/host/xhci.c | 57 +++++++++++++++++++++++++++++++++++++---
19 drivers/usb/host/xhci.h | 1 +
20 include/linux/usb/xhci_pdriver.h | 1 +
21 4 files changed, 59 insertions(+), 3 deletions(-)
22
23 --- a/drivers/usb/host/xhci-plat.c
24 +++ b/drivers/usb/host/xhci-plat.c
25 @@ -38,12 +38,19 @@ static const struct xhci_driver_override
26
27 static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
28 {
29 + struct platform_device *pdev = to_platform_device(dev);
30 + struct device_node *node = pdev->dev.of_node;
31 + struct usb_xhci_pdata *pdata = dev_get_platdata(&pdev->dev);
32 +
33 /*
34 * As of now platform drivers don't provide MSI support so we ensure
35 * here that the generic code does not try to make a pci_dev from our
36 * dev struct in order to setup MSI
37 */
38 xhci->quirks |= XHCI_PLAT;
39 +
40 + if (pdata && pdata->usb3_fake_doorbell)
41 + xhci->quirks |= XHCI_FAKE_DOORBELL;
42 }
43
44 /* called during probe() after chip reset completes */
45 --- a/drivers/usb/host/xhci.c
46 +++ b/drivers/usb/host/xhci.c
47 @@ -121,6 +121,39 @@ int xhci_halt(struct xhci_hcd *xhci)
48 return ret;
49 }
50
51 +static int xhci_fake_doorbell(struct xhci_hcd *xhci, int slot_id)
52 +{
53 + u32 temp;
54 +
55 + /* alloc a virt device for slot */
56 + if (!xhci_alloc_virt_device(xhci, slot_id, NULL, GFP_NOIO)) {
57 + xhci_warn(xhci, "Could not allocate xHCI USB device data structures\n");
58 + return -ENOMEM;
59 + }
60 +
61 + /* ring fake doorbell for slot_id ep 0 */
62 + xhci_ring_ep_doorbell(xhci, slot_id, 0, 0);
63 + usleep_range(1000, 1500);
64 +
65 + /* read the status register to check if HSE is set or not? */
66 + temp = readl(&xhci->op_regs->status);
67 +
68 + /* clear HSE if set */
69 + if (temp & STS_FATAL) {
70 + xhci_dbg(xhci, "HSE problem detected, status: 0x%x\n", temp);
71 + temp &= ~(0x1fff);
72 + temp |= STS_FATAL;
73 + writel(temp, &xhci->op_regs->status);
74 + usleep_range(1000, 1500);
75 + readl(&xhci->op_regs->status);
76 + }
77 +
78 + /* Free virt device */
79 + xhci_free_virt_device(xhci, slot_id);
80 +
81 + return 0;
82 +}
83 +
84 /*
85 * Set the run bit and wait for the host to be running.
86 */
87 @@ -568,10 +601,25 @@ int xhci_init(struct usb_hcd *hcd)
88
89 static int xhci_run_finished(struct xhci_hcd *xhci)
90 {
91 - if (xhci_start(xhci)) {
92 - xhci_halt(xhci);
93 - return -ENODEV;
94 + int err;
95 +
96 + err = xhci_start(xhci);
97 + if (err) {
98 + err = -ENODEV;
99 + goto out_err;
100 + }
101 + if (xhci->quirks & XHCI_FAKE_DOORBELL) {
102 + err = xhci_fake_doorbell(xhci, 1);
103 + if (err)
104 + goto out_err;
105 +
106 + err = xhci_start(xhci);
107 + if (err) {
108 + err = -ENODEV;
109 + goto out_err;
110 + }
111 }
112 +
113 xhci->shared_hcd->state = HC_STATE_RUNNING;
114 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING;
115
116 @@ -581,6 +629,9 @@ static int xhci_run_finished(struct xhci
117 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
118 "Finished xhci_run for USB3 roothub");
119 return 0;
120 +out_err:
121 + xhci_halt(xhci);
122 + return err;
123 }
124
125 /*
126 --- a/drivers/usb/host/xhci.h
127 +++ b/drivers/usb/host/xhci.h
128 @@ -1631,6 +1631,7 @@ struct xhci_hcd {
129 /* For controllers with a broken beyond repair streams implementation */
130 #define XHCI_BROKEN_STREAMS (1 << 19)
131 #define XHCI_PME_STUCK_QUIRK (1 << 20)
132 +#define XHCI_FAKE_DOORBELL (1 << 21)
133 unsigned int num_active_eps;
134 unsigned int limit_active_eps;
135 /* There are two roothubs to keep track of bus suspend info for */
136 --- a/include/linux/usb/xhci_pdriver.h
137 +++ b/include/linux/usb/xhci_pdriver.h
138 @@ -22,6 +22,7 @@
139 */
140 struct usb_xhci_pdata {
141 unsigned usb3_lpm_capable:1;
142 + unsigned usb3_fake_doorbell:1;
143 };
144
145 #endif /* __USB_CORE_XHCI_PDRIVER_H */