bcm53xx: use the latest XHCI doorbell patch sent for upstream
[openwrt/staging/dedeckeh.git] / target / linux / bcm53xx / patches-4.4 / 180-usb-xhci-add-support-for-performing-fake-doorbell.patch
1 From 37df205cdb69d17d5e815385fc1af3c97d1fe20b Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Sat, 1 Oct 2016 22:54:48 +0200
4 Subject: [PATCH] usb: xhci: add support for performing fake doorbell
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Broadcom's Northstar XHCI controllers seem to need a special start
10 procedure to work correctly. There isn't any official documentation on
11 this, the problem is that controller doesn't detect any connected
12 devices with default setup. Moreover connecting USB device to controller
13 that doesn't run properly can cause SoC's watchdog issues.
14
15 A workaround that was successfully tested on multiple devices is to
16 perform a fake doorbell. This patch adds code for doing that and a DT
17 binding enabling it.
18
19 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
20 ---
21 Documentation/devicetree/bindings/usb/usb-xhci.txt | 2 +
22 drivers/usb/host/xhci-plat.c | 6 +++
23 drivers/usb/host/xhci.c | 63 ++++++++++++++++++++--
24 drivers/usb/host/xhci.h | 1 +
25 4 files changed, 69 insertions(+), 3 deletions(-)
26
27 --- a/Documentation/devicetree/bindings/usb/usb-xhci.txt
28 +++ b/Documentation/devicetree/bindings/usb/usb-xhci.txt
29 @@ -12,6 +12,8 @@ Required properties:
30 Optional properties:
31 - clocks: reference to a clock
32 - usb3-lpm-capable: determines if platform is USB3 LPM capable
33 + - usb3-fake-doorbell: determines if controller requires a fake doorbell when
34 + starting it
35
36 Example:
37 usb@f0931000 {
38 --- a/drivers/usb/host/xhci-plat.c
39 +++ b/drivers/usb/host/xhci-plat.c
40 @@ -38,12 +38,18 @@ static const struct xhci_driver_override
41
42 static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
43 {
44 + struct platform_device *pdev = to_platform_device(dev);
45 + struct device_node *node = pdev->dev.of_node;
46 +
47 /*
48 * As of now platform drivers don't provide MSI support so we ensure
49 * here that the generic code does not try to make a pci_dev from our
50 * dev struct in order to setup MSI
51 */
52 xhci->quirks |= XHCI_PLAT;
53 +
54 + if (node && of_property_read_bool(node, "usb3-fake-doorbell"))
55 + xhci->quirks |= XHCI_FAKE_DOORBELL;
56 }
57
58 /* called during probe() after chip reset completes */
59 --- a/drivers/usb/host/xhci.c
60 +++ b/drivers/usb/host/xhci.c
61 @@ -152,6 +152,49 @@ static int xhci_start(struct xhci_hcd *x
62 return ret;
63 }
64
65 +/**
66 + * xhci_fake_doorbell - Perform a fake doorbell on a specified slot
67 + *
68 + * Some controllers require a fake doorbell to start correctly. Without that
69 + * they simply don't detect any devices.
70 + */
71 +static int xhci_fake_doorbell(struct xhci_hcd *xhci, int slot_id)
72 +{
73 + u32 temp;
74 +
75 + /* Alloc a virt device for that slot */
76 + if (!xhci_alloc_virt_device(xhci, slot_id, NULL, GFP_NOIO)) {
77 + xhci_warn(xhci, "Could not allocate xHCI USB device data structures\n");
78 + return -ENOMEM;
79 + }
80 +
81 + /* Ring fake doorbell for slot_id ep 0 */
82 + xhci_ring_ep_doorbell(xhci, slot_id, 0, 0);
83 + usleep_range(1000, 1500);
84 +
85 + /* Read the status to check if HSE is set or not */
86 + temp = readl(&xhci->op_regs->status);
87 +
88 + /* Clear HSE if set */
89 + if (temp & STS_FATAL) {
90 + xhci_dbg(xhci, "HSE problem detected, status: 0x%08x\n", temp);
91 + temp &= ~0x1fff;
92 + temp |= STS_FATAL;
93 + writel(temp, &xhci->op_regs->status);
94 + usleep_range(1000, 1500);
95 + readl(&xhci->op_regs->status);
96 + }
97 +
98 + /* Free virt device */
99 + xhci_free_virt_device(xhci, slot_id);
100 +
101 + /* We're done if controller is already running */
102 + if (readl(&xhci->op_regs->command) & CMD_RUN)
103 + return 0;
104 +
105 + return xhci_start(xhci);
106 +}
107 +
108 /*
109 * Reset a halted HC.
110 *
111 @@ -568,10 +611,20 @@ int xhci_init(struct usb_hcd *hcd)
112
113 static int xhci_run_finished(struct xhci_hcd *xhci)
114 {
115 - if (xhci_start(xhci)) {
116 - xhci_halt(xhci);
117 - return -ENODEV;
118 + int err;
119 +
120 + err = xhci_start(xhci);
121 + if (err) {
122 + err = -ENODEV;
123 + goto err_halt;
124 + }
125 +
126 + if (xhci->quirks & XHCI_FAKE_DOORBELL) {
127 + err = xhci_fake_doorbell(xhci, 1);
128 + if (err)
129 + goto err_halt;
130 }
131 +
132 xhci->shared_hcd->state = HC_STATE_RUNNING;
133 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING;
134
135 @@ -581,6 +634,10 @@ static int xhci_run_finished(struct xhci
136 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
137 "Finished xhci_run for USB3 roothub");
138 return 0;
139 +
140 +err_halt:
141 + xhci_halt(xhci);
142 + return err;
143 }
144
145 /*
146 --- a/drivers/usb/host/xhci.h
147 +++ b/drivers/usb/host/xhci.h
148 @@ -1631,6 +1631,7 @@ struct xhci_hcd {
149 /* For controllers with a broken beyond repair streams implementation */
150 #define XHCI_BROKEN_STREAMS (1 << 19)
151 #define XHCI_PME_STUCK_QUIRK (1 << 20)
152 +#define XHCI_FAKE_DOORBELL (1 << 24)
153 unsigned int num_active_eps;
154 unsigned int limit_active_eps;
155 /* There are two roothubs to keep track of bus suspend info for */