blob: d242779297ba70b9b05e295743fde0c8b8a79657 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001// SPDX-License-Identifier: GPL-2.0
2/*
3 * xHCI host controller driver PCI Bus Glue.
4 *
5 * Copyright (C) 2008 Intel Corp.
6 *
7 * Author: Sarah Sharp
8 * Some code borrowed from the Linux EHCI driver.
9 */
10
11#include <linux/pci.h>
12#include <linux/slab.h>
13#include <linux/module.h>
14#include <linux/acpi.h>
15
16#include "xhci.h"
17#include "xhci-trace.h"
18
19#define SSIC_PORT_NUM 2
20#define SSIC_PORT_CFG2 0x880c
21#define SSIC_PORT_CFG2_OFFSET 0x30
22#define PROG_DONE (1 << 30)
23#define SSIC_PORT_UNUSED (1 << 31)
Olivier Deprez0e641232021-09-23 10:07:05 +020024#define SPARSE_DISABLE_BIT 17
25#define SPARSE_CNTL_ENABLE 0xC12C
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000026
27/* Device for a quirk */
28#define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73
29#define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000
30#define PCI_DEVICE_ID_FRESCO_LOGIC_FL1009 0x1009
31#define PCI_DEVICE_ID_FRESCO_LOGIC_FL1400 0x1400
32
33#define PCI_VENDOR_ID_ETRON 0x1b6f
34#define PCI_DEVICE_ID_EJ168 0x7023
35
36#define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI 0x8c31
37#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31
38#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI 0x9cb1
39#define PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI 0x22b5
40#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI 0xa12f
41#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI 0x9d2f
42#define PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI 0x0aa8
43#define PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI 0x1aa8
44#define PCI_DEVICE_ID_INTEL_APL_XHCI 0x5aa8
45#define PCI_DEVICE_ID_INTEL_DNV_XHCI 0x19d0
David Brazdil0f672f62019-12-10 10:32:29 +000046#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_XHCI 0x15b5
47#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_XHCI 0x15b6
Olivier Deprez0e641232021-09-23 10:07:05 +020048#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_XHCI 0x15c1
David Brazdil0f672f62019-12-10 10:32:29 +000049#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_XHCI 0x15db
50#define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_XHCI 0x15d4
51#define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_XHCI 0x15e9
52#define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_XHCI 0x15ec
53#define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_XHCI 0x15f0
Olivier Deprez0e641232021-09-23 10:07:05 +020054#define PCI_DEVICE_ID_INTEL_ICE_LAKE_XHCI 0x8a13
55#define PCI_DEVICE_ID_INTEL_CML_XHCI 0xa3af
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000056
57#define PCI_DEVICE_ID_AMD_PROMONTORYA_4 0x43b9
58#define PCI_DEVICE_ID_AMD_PROMONTORYA_3 0x43ba
59#define PCI_DEVICE_ID_AMD_PROMONTORYA_2 0x43bb
60#define PCI_DEVICE_ID_AMD_PROMONTORYA_1 0x43bc
Olivier Deprez0e641232021-09-23 10:07:05 +020061#define PCI_DEVICE_ID_ASMEDIA_1042_XHCI 0x1042
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000062#define PCI_DEVICE_ID_ASMEDIA_1042A_XHCI 0x1142
Olivier Deprez0e641232021-09-23 10:07:05 +020063#define PCI_DEVICE_ID_ASMEDIA_1142_XHCI 0x1242
64#define PCI_DEVICE_ID_ASMEDIA_2142_XHCI 0x2142
65#define PCI_DEVICE_ID_ASMEDIA_3242_XHCI 0x3242
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000066
67static const char hcd_name[] = "xhci_hcd";
68
69static struct hc_driver __read_mostly xhci_pci_hc_driver;
70
71static int xhci_pci_setup(struct usb_hcd *hcd);
72
73static const struct xhci_driver_overrides xhci_pci_overrides __initconst = {
74 .reset = xhci_pci_setup,
75};
76
77/* called after powerup, by probe or system-pm "wakeup" */
78static int xhci_pci_reinit(struct xhci_hcd *xhci, struct pci_dev *pdev)
79{
80 /*
81 * TODO: Implement finding debug ports later.
82 * TODO: see if there are any quirks that need to be added to handle
83 * new extended capabilities.
84 */
85
86 /* PCI Memory-Write-Invalidate cycle support is optional (uncommon) */
87 if (!pci_set_mwi(pdev))
88 xhci_dbg(xhci, "MWI active\n");
89
90 xhci_dbg(xhci, "Finished xhci_pci_reinit\n");
91 return 0;
92}
93
94static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
95{
96 struct pci_dev *pdev = to_pci_dev(dev);
97
98 /* Look for vendor-specific quirks */
99 if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC &&
100 (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK ||
101 pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_FL1400)) {
102 if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK &&
103 pdev->revision == 0x0) {
104 xhci->quirks |= XHCI_RESET_EP_QUIRK;
105 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
106 "QUIRK: Fresco Logic xHC needs configure"
107 " endpoint cmd after reset endpoint");
108 }
109 if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK &&
110 pdev->revision == 0x4) {
111 xhci->quirks |= XHCI_SLOW_SUSPEND;
112 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
113 "QUIRK: Fresco Logic xHC revision %u"
114 "must be suspended extra slowly",
115 pdev->revision);
116 }
117 if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK)
118 xhci->quirks |= XHCI_BROKEN_STREAMS;
119 /* Fresco Logic confirms: all revisions of this chip do not
120 * support MSI, even though some of them claim to in their PCI
121 * capabilities.
122 */
123 xhci->quirks |= XHCI_BROKEN_MSI;
124 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
125 "QUIRK: Fresco Logic revision %u "
126 "has broken MSI implementation",
127 pdev->revision);
128 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
129 }
130
131 if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC &&
132 pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_FL1009)
133 xhci->quirks |= XHCI_BROKEN_STREAMS;
134
135 if (pdev->vendor == PCI_VENDOR_ID_NEC)
136 xhci->quirks |= XHCI_NEC_HOST;
137
138 if (pdev->vendor == PCI_VENDOR_ID_AMD && xhci->hci_version == 0x96)
139 xhci->quirks |= XHCI_AMD_0x96_HOST;
140
141 /* AMD PLL quirk */
David Brazdil0f672f62019-12-10 10:32:29 +0000142 if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_quirk_pll_check())
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000143 xhci->quirks |= XHCI_AMD_PLL_FIX;
144
145 if (pdev->vendor == PCI_VENDOR_ID_AMD &&
Olivier Deprez0e641232021-09-23 10:07:05 +0200146 (pdev->device == 0x145c ||
147 pdev->device == 0x15e0 ||
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000148 pdev->device == 0x15e1 ||
149 pdev->device == 0x43bb))
150 xhci->quirks |= XHCI_SUSPEND_DELAY;
151
152 if (pdev->vendor == PCI_VENDOR_ID_AMD &&
153 (pdev->device == 0x15e0 || pdev->device == 0x15e1))
154 xhci->quirks |= XHCI_SNPS_BROKEN_SUSPEND;
155
Olivier Deprez0e641232021-09-23 10:07:05 +0200156 if (pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x15e5) {
157 xhci->quirks |= XHCI_DISABLE_SPARSE;
158 xhci->quirks |= XHCI_RESET_ON_RESUME;
159 }
160
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000161 if (pdev->vendor == PCI_VENDOR_ID_AMD)
162 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
163
164 if ((pdev->vendor == PCI_VENDOR_ID_AMD) &&
165 ((pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4) ||
166 (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_3) ||
167 (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_2) ||
168 (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_1)))
169 xhci->quirks |= XHCI_U2_DISABLE_WAKE;
170
171 if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
172 xhci->quirks |= XHCI_LPM_SUPPORT;
173 xhci->quirks |= XHCI_INTEL_HOST;
174 xhci->quirks |= XHCI_AVOID_BEI;
175 }
176 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
177 pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI) {
178 xhci->quirks |= XHCI_EP_LIMIT_QUIRK;
179 xhci->limit_active_eps = 64;
180 xhci->quirks |= XHCI_SW_BW_CHECKING;
181 /*
182 * PPT desktop boards DH77EB and DH77DF will power back on after
183 * a few seconds of being shutdown. The fix for this is to
184 * switch the ports from xHCI to EHCI on shutdown. We can't use
185 * DMI information to find those particular boards (since each
186 * vendor will change the board name), so we have to key off all
187 * PPT chipsets.
188 */
189 xhci->quirks |= XHCI_SPURIOUS_REBOOT;
190 }
191 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
192 (pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI ||
193 pdev->device == PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI)) {
194 xhci->quirks |= XHCI_SPURIOUS_REBOOT;
195 xhci->quirks |= XHCI_SPURIOUS_WAKEUP;
196 }
197 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
198 (pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI ||
199 pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI ||
200 pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
201 pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI ||
202 pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI ||
203 pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI ||
Olivier Deprez0e641232021-09-23 10:07:05 +0200204 pdev->device == PCI_DEVICE_ID_INTEL_DNV_XHCI ||
205 pdev->device == PCI_DEVICE_ID_INTEL_CML_XHCI)) {
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000206 xhci->quirks |= XHCI_PME_STUCK_QUIRK;
207 }
208 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
209 pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI)
210 xhci->quirks |= XHCI_SSIC_PORT_UNUSED;
211 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
212 (pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
David Brazdil0f672f62019-12-10 10:32:29 +0000213 pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI ||
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000214 pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI))
215 xhci->quirks |= XHCI_INTEL_USB_ROLE_SW;
216 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
217 (pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
218 pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI ||
219 pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI ||
220 pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI ||
221 pdev->device == PCI_DEVICE_ID_INTEL_DNV_XHCI))
222 xhci->quirks |= XHCI_MISSING_CAS;
223
David Brazdil0f672f62019-12-10 10:32:29 +0000224 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
225 (pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_XHCI ||
226 pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_XHCI ||
Olivier Deprez0e641232021-09-23 10:07:05 +0200227 pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_XHCI ||
David Brazdil0f672f62019-12-10 10:32:29 +0000228 pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_XHCI ||
229 pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_XHCI ||
230 pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_XHCI ||
231 pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_XHCI ||
Olivier Deprez0e641232021-09-23 10:07:05 +0200232 pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_XHCI ||
233 pdev->device == PCI_DEVICE_ID_INTEL_ICE_LAKE_XHCI))
David Brazdil0f672f62019-12-10 10:32:29 +0000234 xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;
235
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000236 if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
237 pdev->device == PCI_DEVICE_ID_EJ168) {
238 xhci->quirks |= XHCI_RESET_ON_RESUME;
239 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
240 xhci->quirks |= XHCI_BROKEN_STREAMS;
241 }
242 if (pdev->vendor == PCI_VENDOR_ID_RENESAS &&
243 pdev->device == 0x0014) {
244 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
245 xhci->quirks |= XHCI_ZERO_64B_REGS;
246 }
247 if (pdev->vendor == PCI_VENDOR_ID_RENESAS &&
248 pdev->device == 0x0015) {
249 xhci->quirks |= XHCI_RESET_ON_RESUME;
250 xhci->quirks |= XHCI_ZERO_64B_REGS;
251 }
252 if (pdev->vendor == PCI_VENDOR_ID_VIA)
253 xhci->quirks |= XHCI_RESET_ON_RESUME;
254
255 /* See https://bugzilla.kernel.org/show_bug.cgi?id=79511 */
256 if (pdev->vendor == PCI_VENDOR_ID_VIA &&
257 pdev->device == 0x3432)
258 xhci->quirks |= XHCI_BROKEN_STREAMS;
259
260 if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
Olivier Deprez0e641232021-09-23 10:07:05 +0200261 pdev->device == PCI_DEVICE_ID_ASMEDIA_1042_XHCI)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000262 xhci->quirks |= XHCI_BROKEN_STREAMS;
263 if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
Olivier Deprez0e641232021-09-23 10:07:05 +0200264 pdev->device == PCI_DEVICE_ID_ASMEDIA_1042A_XHCI) {
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000265 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
Olivier Deprez0e641232021-09-23 10:07:05 +0200266 xhci->quirks |= XHCI_NO_64BIT_SUPPORT;
267 }
268 if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
269 (pdev->device == PCI_DEVICE_ID_ASMEDIA_1142_XHCI ||
270 pdev->device == PCI_DEVICE_ID_ASMEDIA_2142_XHCI ||
271 pdev->device == PCI_DEVICE_ID_ASMEDIA_3242_XHCI))
272 xhci->quirks |= XHCI_NO_64BIT_SUPPORT;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000273
274 if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
275 pdev->device == PCI_DEVICE_ID_ASMEDIA_1042A_XHCI)
276 xhci->quirks |= XHCI_ASMEDIA_MODIFY_FLOWCONTROL;
277
278 if (pdev->vendor == PCI_VENDOR_ID_TI && pdev->device == 0x8241)
279 xhci->quirks |= XHCI_LIMIT_ENDPOINT_INTERVAL_7;
280
281 if ((pdev->vendor == PCI_VENDOR_ID_BROADCOM ||
282 pdev->vendor == PCI_VENDOR_ID_CAVIUM) &&
283 pdev->device == 0x9026)
284 xhci->quirks |= XHCI_RESET_PLL_ON_DISCONNECT;
285
Olivier Deprez0e641232021-09-23 10:07:05 +0200286 if (pdev->vendor == PCI_VENDOR_ID_AMD &&
287 (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_2 ||
288 pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4))
289 xhci->quirks |= XHCI_NO_SOFT_RETRY;
290
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000291 if (xhci->quirks & XHCI_RESET_ON_RESUME)
292 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
293 "QUIRK: Resetting on resume");
294}
295
296#ifdef CONFIG_ACPI
297static void xhci_pme_acpi_rtd3_enable(struct pci_dev *dev)
298{
299 static const guid_t intel_dsm_guid =
300 GUID_INIT(0xac340cb7, 0xe901, 0x45bf,
301 0xb7, 0xe6, 0x2b, 0x34, 0xec, 0x93, 0x1e, 0x23);
302 union acpi_object *obj;
303
304 obj = acpi_evaluate_dsm(ACPI_HANDLE(&dev->dev), &intel_dsm_guid, 3, 1,
305 NULL);
306 ACPI_FREE(obj);
307}
308#else
309static void xhci_pme_acpi_rtd3_enable(struct pci_dev *dev) { }
310#endif /* CONFIG_ACPI */
311
312/* called during probe() after chip reset completes */
313static int xhci_pci_setup(struct usb_hcd *hcd)
314{
315 struct xhci_hcd *xhci;
316 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
317 int retval;
318
319 xhci = hcd_to_xhci(hcd);
320 if (!xhci->sbrn)
321 pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn);
322
323 /* imod_interval is the interrupt moderation value in nanoseconds. */
324 xhci->imod_interval = 40000;
325
326 retval = xhci_gen_setup(hcd, xhci_pci_quirks);
327 if (retval)
328 return retval;
329
330 if (!usb_hcd_is_primary_hcd(hcd))
331 return 0;
332
Olivier Deprez0e641232021-09-23 10:07:05 +0200333 if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
334 xhci_pme_acpi_rtd3_enable(pdev);
335
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000336 xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn);
337
338 /* Find any debug ports */
339 return xhci_pci_reinit(xhci, pdev);
340}
341
342/*
343 * We need to register our own PCI probe function (instead of the USB core's
344 * function) in order to create a second roothub under xHCI.
345 */
346static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
347{
348 int retval;
349 struct xhci_hcd *xhci;
350 struct hc_driver *driver;
351 struct usb_hcd *hcd;
352
353 driver = (struct hc_driver *)id->driver_data;
354
355 /* Prevent runtime suspending between USB-2 and USB-3 initialization */
356 pm_runtime_get_noresume(&dev->dev);
357
358 /* Register the USB 2.0 roothub.
359 * FIXME: USB core must know to register the USB 2.0 roothub first.
360 * This is sort of silly, because we could just set the HCD driver flags
361 * to say USB 2.0, but I'm not sure what the implications would be in
362 * the other parts of the HCD code.
363 */
364 retval = usb_hcd_pci_probe(dev, id);
365
366 if (retval)
367 goto put_runtime_pm;
368
369 /* USB 2.0 roothub is stored in the PCI device now. */
370 hcd = dev_get_drvdata(&dev->dev);
371 xhci = hcd_to_xhci(hcd);
372 xhci->shared_hcd = usb_create_shared_hcd(driver, &dev->dev,
373 pci_name(dev), hcd);
374 if (!xhci->shared_hcd) {
375 retval = -ENOMEM;
376 goto dealloc_usb2_hcd;
377 }
378
379 retval = xhci_ext_cap_init(xhci);
380 if (retval)
381 goto put_usb3_hcd;
382
383 retval = usb_add_hcd(xhci->shared_hcd, dev->irq,
384 IRQF_SHARED);
385 if (retval)
386 goto put_usb3_hcd;
387 /* Roothub already marked as USB 3.0 speed */
388
389 if (!(xhci->quirks & XHCI_BROKEN_STREAMS) &&
390 HCC_MAX_PSA(xhci->hcc_params) >= 4)
391 xhci->shared_hcd->can_do_streams = 1;
392
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000393 /* USB-2 and USB-3 roothubs initialized, allow runtime pm suspend */
394 pm_runtime_put_noidle(&dev->dev);
395
David Brazdil0f672f62019-12-10 10:32:29 +0000396 if (xhci->quirks & XHCI_DEFAULT_PM_RUNTIME_ALLOW)
397 pm_runtime_allow(&dev->dev);
398
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000399 return 0;
400
401put_usb3_hcd:
402 usb_put_hcd(xhci->shared_hcd);
403dealloc_usb2_hcd:
404 usb_hcd_pci_remove(dev);
405put_runtime_pm:
406 pm_runtime_put_noidle(&dev->dev);
407 return retval;
408}
409
410static void xhci_pci_remove(struct pci_dev *dev)
411{
412 struct xhci_hcd *xhci;
413
414 xhci = hcd_to_xhci(pci_get_drvdata(dev));
415 xhci->xhc_state |= XHCI_STATE_REMOVING;
David Brazdil0f672f62019-12-10 10:32:29 +0000416
417 if (xhci->quirks & XHCI_DEFAULT_PM_RUNTIME_ALLOW)
418 pm_runtime_forbid(&dev->dev);
419
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000420 if (xhci->shared_hcd) {
421 usb_remove_hcd(xhci->shared_hcd);
422 usb_put_hcd(xhci->shared_hcd);
423 xhci->shared_hcd = NULL;
424 }
425
426 /* Workaround for spurious wakeups at shutdown with HSW */
427 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
428 pci_set_power_state(dev, PCI_D3hot);
429
430 usb_hcd_pci_remove(dev);
431}
432
433#ifdef CONFIG_PM
434/*
435 * In some Intel xHCI controllers, in order to get D3 working,
436 * through a vendor specific SSIC CONFIG register at offset 0x883c,
437 * SSIC PORT need to be marked as "unused" before putting xHCI
438 * into D3. After D3 exit, the SSIC port need to be marked as "used".
439 * Without this change, xHCI might not enter D3 state.
440 */
441static void xhci_ssic_port_unused_quirk(struct usb_hcd *hcd, bool suspend)
442{
443 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
444 u32 val;
445 void __iomem *reg;
446 int i;
447
448 for (i = 0; i < SSIC_PORT_NUM; i++) {
449 reg = (void __iomem *) xhci->cap_regs +
450 SSIC_PORT_CFG2 +
451 i * SSIC_PORT_CFG2_OFFSET;
452
453 /* Notify SSIC that SSIC profile programming is not done. */
454 val = readl(reg) & ~PROG_DONE;
455 writel(val, reg);
456
457 /* Mark SSIC port as unused(suspend) or used(resume) */
458 val = readl(reg);
459 if (suspend)
460 val |= SSIC_PORT_UNUSED;
461 else
462 val &= ~SSIC_PORT_UNUSED;
463 writel(val, reg);
464
465 /* Notify SSIC that SSIC profile programming is done */
466 val = readl(reg) | PROG_DONE;
467 writel(val, reg);
468 readl(reg);
469 }
470}
471
472/*
473 * Make sure PME works on some Intel xHCI controllers by writing 1 to clear
474 * the Internal PME flag bit in vendor specific PMCTRL register at offset 0x80a4
475 */
476static void xhci_pme_quirk(struct usb_hcd *hcd)
477{
478 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
479 void __iomem *reg;
480 u32 val;
481
482 reg = (void __iomem *) xhci->cap_regs + 0x80a4;
483 val = readl(reg);
484 writel(val | BIT(28), reg);
485 readl(reg);
486}
487
Olivier Deprez0e641232021-09-23 10:07:05 +0200488static void xhci_sparse_control_quirk(struct usb_hcd *hcd)
489{
490 u32 reg;
491
492 reg = readl(hcd->regs + SPARSE_CNTL_ENABLE);
493 reg &= ~BIT(SPARSE_DISABLE_BIT);
494 writel(reg, hcd->regs + SPARSE_CNTL_ENABLE);
495}
496
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000497static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
498{
499 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
500 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
501 int ret;
502
503 /*
504 * Systems with the TI redriver that loses port status change events
505 * need to have the registers polled during D3, so avoid D3cold.
506 */
507 if (xhci->quirks & XHCI_COMP_MODE_QUIRK)
508 pci_d3cold_disable(pdev);
509
510 if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
511 xhci_pme_quirk(hcd);
512
513 if (xhci->quirks & XHCI_SSIC_PORT_UNUSED)
514 xhci_ssic_port_unused_quirk(hcd, true);
515
Olivier Deprez0e641232021-09-23 10:07:05 +0200516 if (xhci->quirks & XHCI_DISABLE_SPARSE)
517 xhci_sparse_control_quirk(hcd);
518
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000519 ret = xhci_suspend(xhci, do_wakeup);
520 if (ret && (xhci->quirks & XHCI_SSIC_PORT_UNUSED))
521 xhci_ssic_port_unused_quirk(hcd, false);
522
523 return ret;
524}
525
526static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
527{
528 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
529 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
530 int retval = 0;
531
532 /* The BIOS on systems with the Intel Panther Point chipset may or may
533 * not support xHCI natively. That means that during system resume, it
534 * may switch the ports back to EHCI so that users can use their
535 * keyboard to select a kernel from GRUB after resume from hibernate.
536 *
537 * The BIOS is supposed to remember whether the OS had xHCI ports
538 * enabled before resume, and switch the ports back to xHCI when the
539 * BIOS/OS semaphore is written, but we all know we can't trust BIOS
540 * writers.
541 *
542 * Unconditionally switch the ports back to xHCI after a system resume.
543 * It should not matter whether the EHCI or xHCI controller is
544 * resumed first. It's enough to do the switchover in xHCI because
545 * USB core won't notice anything as the hub driver doesn't start
546 * running again until after all the devices (including both EHCI and
547 * xHCI host controllers) have been resumed.
548 */
549
550 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
551 usb_enable_intel_xhci_ports(pdev);
552
553 if (xhci->quirks & XHCI_SSIC_PORT_UNUSED)
554 xhci_ssic_port_unused_quirk(hcd, false);
555
556 if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
557 xhci_pme_quirk(hcd);
558
559 retval = xhci_resume(xhci, hibernated);
560 return retval;
561}
Olivier Deprez0e641232021-09-23 10:07:05 +0200562
563static void xhci_pci_shutdown(struct usb_hcd *hcd)
564{
565 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
566 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
567
568 xhci_shutdown(hcd);
569
570 /* Yet another workaround for spurious wakeups at shutdown with HSW */
571 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
572 pci_set_power_state(pdev, PCI_D3hot);
573}
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000574#endif /* CONFIG_PM */
575
576/*-------------------------------------------------------------------------*/
577
578/* PCI driver selection metadata; PCI hotplugging uses this */
579static const struct pci_device_id pci_ids[] = { {
580 /* handle any USB 3.0 xHCI controller */
581 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0),
582 .driver_data = (unsigned long) &xhci_pci_hc_driver,
583 },
584 { /* end: all zeroes */ }
585};
586MODULE_DEVICE_TABLE(pci, pci_ids);
587
588/* pci driver glue; this is a "new style" PCI driver module */
589static struct pci_driver xhci_pci_driver = {
590 .name = (char *) hcd_name,
591 .id_table = pci_ids,
592
593 .probe = xhci_pci_probe,
594 .remove = xhci_pci_remove,
595 /* suspend and resume implemented later */
596
597 .shutdown = usb_hcd_pci_shutdown,
598#ifdef CONFIG_PM
599 .driver = {
600 .pm = &usb_hcd_pci_pm_ops
601 },
602#endif
603};
604
605static int __init xhci_pci_init(void)
606{
607 xhci_init_driver(&xhci_pci_hc_driver, &xhci_pci_overrides);
608#ifdef CONFIG_PM
609 xhci_pci_hc_driver.pci_suspend = xhci_pci_suspend;
610 xhci_pci_hc_driver.pci_resume = xhci_pci_resume;
Olivier Deprez0e641232021-09-23 10:07:05 +0200611 xhci_pci_hc_driver.shutdown = xhci_pci_shutdown;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000612#endif
613 return pci_register_driver(&xhci_pci_driver);
614}
615module_init(xhci_pci_init);
616
617static void __exit xhci_pci_exit(void)
618{
619 pci_unregister_driver(&xhci_pci_driver);
620}
621module_exit(xhci_pci_exit);
622
623MODULE_DESCRIPTION("xHCI PCI Host Controller Driver");
624MODULE_LICENSE("GPL");