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
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
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.
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
19 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
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(-)
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:
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
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
42 static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
44 + struct platform_device *pdev = to_platform_device(dev);
45 + struct device_node *node = pdev->dev.of_node;
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
52 xhci->quirks |= XHCI_PLAT;
54 + if (node && of_property_read_bool(node, "usb3-fake-doorbell"))
55 + xhci->quirks |= XHCI_FAKE_DOORBELL;
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
66 + * xhci_fake_doorbell - Perform a fake doorbell on a specified slot
68 + * Some controllers require a fake doorbell to start correctly. Without that
69 + * they simply don't detect any devices.
71 +static int xhci_fake_doorbell(struct xhci_hcd *xhci, int slot_id)
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");
81 + /* Ring fake doorbell for slot_id ep 0 */
82 + xhci_ring_ep_doorbell(xhci, slot_id, 0, 0);
83 + usleep_range(1000, 1500);
85 + /* Read the status to check if HSE is set or not */
86 + temp = readl(&xhci->op_regs->status);
88 + /* Clear HSE if set */
89 + if (temp & STS_FATAL) {
90 + xhci_dbg(xhci, "HSE problem detected, status: 0x%08x\n", temp);
93 + writel(temp, &xhci->op_regs->status);
94 + usleep_range(1000, 1500);
95 + readl(&xhci->op_regs->status);
98 + /* Free virt device */
99 + xhci_free_virt_device(xhci, slot_id);
101 + /* We're done if controller is already running */
102 + if (readl(&xhci->op_regs->command) & CMD_RUN)
105 + return xhci_start(xhci);
111 @@ -568,10 +611,20 @@ int xhci_init(struct usb_hcd *hcd)
113 static int xhci_run_finished(struct xhci_hcd *xhci)
115 - if (xhci_start(xhci)) {
120 + err = xhci_start(xhci);
126 + if (xhci->quirks & XHCI_FAKE_DOORBELL) {
127 + err = xhci_fake_doorbell(xhci, 1);
132 xhci->shared_hcd->state = HC_STATE_RUNNING;
133 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING;
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");
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 */