1 // SPDX-License-Identifier: GPL-2.0
3 * xHCI host controller driver PCI Bus Glue.
5 * Copyright (C) 2008 Intel Corp.
8 * Some code borrowed from the Linux EHCI driver.
11 #include <linux/pci.h>
12 #include <linux/slab.h>
13 #include <linux/module.h>
14 #include <linux/acpi.h>
15 #include <linux/reset.h>
18 #include "xhci-trace.h"
21 #define SSIC_PORT_NUM 2
22 #define SSIC_PORT_CFG2 0x880c
23 #define SSIC_PORT_CFG2_OFFSET 0x30
24 #define PROG_DONE (1 << 30)
25 #define SSIC_PORT_UNUSED (1 << 31)
26 #define SPARSE_DISABLE_BIT 17
27 #define SPARSE_CNTL_ENABLE 0xC12C
29 /* Device for a quirk */
30 #define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73
31 #define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000
32 #define PCI_DEVICE_ID_FRESCO_LOGIC_FL1009 0x1009
33 #define PCI_DEVICE_ID_FRESCO_LOGIC_FL1400 0x1400
35 #define PCI_VENDOR_ID_ETRON 0x1b6f
36 #define PCI_DEVICE_ID_EJ168 0x7023
38 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI 0x8c31
39 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31
40 #define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI 0x9cb1
41 #define PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI 0x22b5
42 #define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI 0xa12f
43 #define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI 0x9d2f
44 #define PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI 0x0aa8
45 #define PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI 0x1aa8
46 #define PCI_DEVICE_ID_INTEL_APL_XHCI 0x5aa8
47 #define PCI_DEVICE_ID_INTEL_DNV_XHCI 0x19d0
48 #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_XHCI 0x15b5
49 #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_XHCI 0x15b6
50 #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_XHCI 0x15c1
51 #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_XHCI 0x15db
52 #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_XHCI 0x15d4
53 #define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_XHCI 0x15e9
54 #define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_XHCI 0x15ec
55 #define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_XHCI 0x15f0
56 #define PCI_DEVICE_ID_INTEL_ICE_LAKE_XHCI 0x8a13
57 #define PCI_DEVICE_ID_INTEL_CML_XHCI 0xa3af
58 #define PCI_DEVICE_ID_INTEL_TIGER_LAKE_XHCI 0x9a13
59 #define PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_XHCI 0x1138
60 #define PCI_DEVICE_ID_INTEL_ALDER_LAKE_XHCI 0x461e
62 #define PCI_DEVICE_ID_AMD_PROMONTORYA_4 0x43b9
63 #define PCI_DEVICE_ID_AMD_PROMONTORYA_3 0x43ba
64 #define PCI_DEVICE_ID_AMD_PROMONTORYA_2 0x43bb
65 #define PCI_DEVICE_ID_AMD_PROMONTORYA_1 0x43bc
66 #define PCI_DEVICE_ID_ASMEDIA_1042_XHCI 0x1042
67 #define PCI_DEVICE_ID_ASMEDIA_1042A_XHCI 0x1142
68 #define PCI_DEVICE_ID_ASMEDIA_1142_XHCI 0x1242
69 #define PCI_DEVICE_ID_ASMEDIA_2142_XHCI 0x2142
70 #define PCI_DEVICE_ID_ASMEDIA_3242_XHCI 0x3242
72 static const char hcd_name[] = "xhci_hcd";
74 static struct hc_driver __read_mostly xhci_pci_hc_driver;
76 static int xhci_pci_setup(struct usb_hcd *hcd);
78 static const struct xhci_driver_overrides xhci_pci_overrides __initconst = {
79 .reset = xhci_pci_setup,
82 /* called after powerup, by probe or system-pm "wakeup" */
83 static int xhci_pci_reinit(struct xhci_hcd *xhci, struct pci_dev *pdev)
86 * TODO: Implement finding debug ports later.
87 * TODO: see if there are any quirks that need to be added to handle
88 * new extended capabilities.
91 /* PCI Memory-Write-Invalidate cycle support is optional (uncommon) */
92 if (!pci_set_mwi(pdev))
93 xhci_dbg(xhci, "MWI active\n");
95 xhci_dbg(xhci, "Finished xhci_pci_reinit\n");
99 static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
101 struct pci_dev *pdev = to_pci_dev(dev);
102 struct xhci_driver_data *driver_data;
103 const struct pci_device_id *id;
105 id = pci_match_id(pdev->driver->id_table, pdev);
107 if (id && id->driver_data) {
108 driver_data = (struct xhci_driver_data *)id->driver_data;
109 xhci->quirks |= driver_data->quirks;
112 /* Look for vendor-specific quirks */
113 if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC &&
114 (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK ||
115 pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_FL1400)) {
116 if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK &&
117 pdev->revision == 0x0) {
118 xhci->quirks |= XHCI_RESET_EP_QUIRK;
119 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
120 "QUIRK: Fresco Logic xHC needs configure"
121 " endpoint cmd after reset endpoint");
123 if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK &&
124 pdev->revision == 0x4) {
125 xhci->quirks |= XHCI_SLOW_SUSPEND;
126 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
127 "QUIRK: Fresco Logic xHC revision %u"
128 "must be suspended extra slowly",
131 if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK)
132 xhci->quirks |= XHCI_BROKEN_STREAMS;
133 /* Fresco Logic confirms: all revisions of this chip do not
134 * support MSI, even though some of them claim to in their PCI
137 xhci->quirks |= XHCI_BROKEN_MSI;
138 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
139 "QUIRK: Fresco Logic revision %u "
140 "has broken MSI implementation",
142 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
145 if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC &&
146 pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_FL1009)
147 xhci->quirks |= XHCI_BROKEN_STREAMS;
149 if (pdev->vendor == PCI_VENDOR_ID_NEC)
150 xhci->quirks |= XHCI_NEC_HOST;
152 if (pdev->vendor == PCI_VENDOR_ID_AMD && xhci->hci_version == 0x96)
153 xhci->quirks |= XHCI_AMD_0x96_HOST;
156 if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_quirk_pll_check())
157 xhci->quirks |= XHCI_AMD_PLL_FIX;
159 if (pdev->vendor == PCI_VENDOR_ID_AMD &&
160 (pdev->device == 0x145c ||
161 pdev->device == 0x15e0 ||
162 pdev->device == 0x15e1 ||
163 pdev->device == 0x43bb))
164 xhci->quirks |= XHCI_SUSPEND_DELAY;
166 if (pdev->vendor == PCI_VENDOR_ID_AMD &&
167 (pdev->device == 0x15e0 || pdev->device == 0x15e1))
168 xhci->quirks |= XHCI_SNPS_BROKEN_SUSPEND;
170 if (pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x15e5) {
171 xhci->quirks |= XHCI_DISABLE_SPARSE;
172 xhci->quirks |= XHCI_RESET_ON_RESUME;
175 if (pdev->vendor == PCI_VENDOR_ID_AMD)
176 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
178 if ((pdev->vendor == PCI_VENDOR_ID_AMD) &&
179 ((pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4) ||
180 (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_3) ||
181 (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_2) ||
182 (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_1)))
183 xhci->quirks |= XHCI_U2_DISABLE_WAKE;
185 if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
186 xhci->quirks |= XHCI_LPM_SUPPORT;
187 xhci->quirks |= XHCI_INTEL_HOST;
188 xhci->quirks |= XHCI_AVOID_BEI;
190 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
191 pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI) {
192 xhci->quirks |= XHCI_EP_LIMIT_QUIRK;
193 xhci->limit_active_eps = 64;
194 xhci->quirks |= XHCI_SW_BW_CHECKING;
196 * PPT desktop boards DH77EB and DH77DF will power back on after
197 * a few seconds of being shutdown. The fix for this is to
198 * switch the ports from xHCI to EHCI on shutdown. We can't use
199 * DMI information to find those particular boards (since each
200 * vendor will change the board name), so we have to key off all
203 xhci->quirks |= XHCI_SPURIOUS_REBOOT;
205 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
206 (pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI ||
207 pdev->device == PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI)) {
208 xhci->quirks |= XHCI_SPURIOUS_REBOOT;
209 xhci->quirks |= XHCI_SPURIOUS_WAKEUP;
211 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
212 (pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI ||
213 pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI ||
214 pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
215 pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI ||
216 pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI ||
217 pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI ||
218 pdev->device == PCI_DEVICE_ID_INTEL_DNV_XHCI ||
219 pdev->device == PCI_DEVICE_ID_INTEL_CML_XHCI)) {
220 xhci->quirks |= XHCI_PME_STUCK_QUIRK;
222 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
223 pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI)
224 xhci->quirks |= XHCI_SSIC_PORT_UNUSED;
225 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
226 (pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
227 pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI ||
228 pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI))
229 xhci->quirks |= XHCI_INTEL_USB_ROLE_SW;
230 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
231 (pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
232 pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI ||
233 pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI ||
234 pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI ||
235 pdev->device == PCI_DEVICE_ID_INTEL_DNV_XHCI))
236 xhci->quirks |= XHCI_MISSING_CAS;
238 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
239 (pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_XHCI ||
240 pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_XHCI ||
241 pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_XHCI ||
242 pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_XHCI ||
243 pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_XHCI ||
244 pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_XHCI ||
245 pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_XHCI ||
246 pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_XHCI ||
247 pdev->device == PCI_DEVICE_ID_INTEL_ICE_LAKE_XHCI ||
248 pdev->device == PCI_DEVICE_ID_INTEL_TIGER_LAKE_XHCI ||
249 pdev->device == PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_XHCI ||
250 pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_XHCI))
251 xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;
253 if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
254 pdev->device == PCI_DEVICE_ID_EJ168) {
255 xhci->quirks |= XHCI_RESET_ON_RESUME;
256 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
257 xhci->quirks |= XHCI_BROKEN_STREAMS;
259 if (pdev->vendor == PCI_VENDOR_ID_RENESAS &&
260 pdev->device == 0x0014) {
261 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
262 xhci->quirks |= XHCI_ZERO_64B_REGS;
264 if (pdev->vendor == PCI_VENDOR_ID_RENESAS &&
265 pdev->device == 0x0015) {
266 xhci->quirks |= XHCI_RESET_ON_RESUME;
267 xhci->quirks |= XHCI_ZERO_64B_REGS;
269 if (pdev->vendor == PCI_VENDOR_ID_VIA)
270 xhci->quirks |= XHCI_RESET_ON_RESUME;
272 /* See https://bugzilla.kernel.org/show_bug.cgi?id=79511 */
273 if (pdev->vendor == PCI_VENDOR_ID_VIA &&
274 pdev->device == 0x3432)
275 xhci->quirks |= XHCI_BROKEN_STREAMS;
277 if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == 0x3483)
278 xhci->quirks |= XHCI_LPM_SUPPORT;
280 if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
281 pdev->device == PCI_DEVICE_ID_ASMEDIA_1042_XHCI)
282 xhci->quirks |= XHCI_BROKEN_STREAMS;
283 if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
284 pdev->device == PCI_DEVICE_ID_ASMEDIA_1042A_XHCI) {
285 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
286 xhci->quirks |= XHCI_NO_64BIT_SUPPORT;
288 if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
289 (pdev->device == PCI_DEVICE_ID_ASMEDIA_1142_XHCI ||
290 pdev->device == PCI_DEVICE_ID_ASMEDIA_2142_XHCI ||
291 pdev->device == PCI_DEVICE_ID_ASMEDIA_3242_XHCI))
292 xhci->quirks |= XHCI_NO_64BIT_SUPPORT;
294 if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
295 pdev->device == PCI_DEVICE_ID_ASMEDIA_1042A_XHCI)
296 xhci->quirks |= XHCI_ASMEDIA_MODIFY_FLOWCONTROL;
298 if (pdev->vendor == PCI_VENDOR_ID_TI && pdev->device == 0x8241)
299 xhci->quirks |= XHCI_LIMIT_ENDPOINT_INTERVAL_7;
301 if ((pdev->vendor == PCI_VENDOR_ID_BROADCOM ||
302 pdev->vendor == PCI_VENDOR_ID_CAVIUM) &&
303 pdev->device == 0x9026)
304 xhci->quirks |= XHCI_RESET_PLL_ON_DISCONNECT;
306 if (pdev->vendor == PCI_VENDOR_ID_AMD &&
307 (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_2 ||
308 pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4))
309 xhci->quirks |= XHCI_NO_SOFT_RETRY;
311 if (xhci->quirks & XHCI_RESET_ON_RESUME)
312 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
313 "QUIRK: Resetting on resume");
317 static void xhci_pme_acpi_rtd3_enable(struct pci_dev *dev)
319 static const guid_t intel_dsm_guid =
320 GUID_INIT(0xac340cb7, 0xe901, 0x45bf,
321 0xb7, 0xe6, 0x2b, 0x34, 0xec, 0x93, 0x1e, 0x23);
322 union acpi_object *obj;
324 obj = acpi_evaluate_dsm(ACPI_HANDLE(&dev->dev), &intel_dsm_guid, 3, 1,
329 static void xhci_pme_acpi_rtd3_enable(struct pci_dev *dev) { }
330 #endif /* CONFIG_ACPI */
332 /* called during probe() after chip reset completes */
333 static int xhci_pci_setup(struct usb_hcd *hcd)
335 struct xhci_hcd *xhci;
336 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
339 xhci = hcd_to_xhci(hcd);
341 pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn);
343 /* imod_interval is the interrupt moderation value in nanoseconds. */
344 xhci->imod_interval = 40000;
346 retval = xhci_gen_setup(hcd, xhci_pci_quirks);
350 if (!usb_hcd_is_primary_hcd(hcd))
353 if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
354 xhci_pme_acpi_rtd3_enable(pdev);
356 xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn);
358 /* Find any debug ports */
359 return xhci_pci_reinit(xhci, pdev);
363 * We need to register our own PCI probe function (instead of the USB core's
364 * function) in order to create a second roothub under xHCI.
366 static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
369 struct xhci_hcd *xhci;
371 struct xhci_driver_data *driver_data;
372 struct reset_control *reset;
374 driver_data = (struct xhci_driver_data *)id->driver_data;
375 if (driver_data && driver_data->quirks & XHCI_RENESAS_FW_QUIRK) {
376 retval = renesas_xhci_check_request_fw(dev, id);
381 reset = devm_reset_control_get_optional_exclusive(&dev->dev, NULL);
383 return PTR_ERR(reset);
384 reset_control_reset(reset);
386 /* Prevent runtime suspending between USB-2 and USB-3 initialization */
387 pm_runtime_get_noresume(&dev->dev);
389 /* Register the USB 2.0 roothub.
390 * FIXME: USB core must know to register the USB 2.0 roothub first.
391 * This is sort of silly, because we could just set the HCD driver flags
392 * to say USB 2.0, but I'm not sure what the implications would be in
393 * the other parts of the HCD code.
395 retval = usb_hcd_pci_probe(dev, id, &xhci_pci_hc_driver);
400 /* USB 2.0 roothub is stored in the PCI device now. */
401 hcd = dev_get_drvdata(&dev->dev);
402 xhci = hcd_to_xhci(hcd);
404 xhci->shared_hcd = usb_create_shared_hcd(&xhci_pci_hc_driver, &dev->dev,
406 if (!xhci->shared_hcd) {
408 goto dealloc_usb2_hcd;
411 retval = xhci_ext_cap_init(xhci);
415 retval = usb_add_hcd(xhci->shared_hcd, dev->irq,
419 /* Roothub already marked as USB 3.0 speed */
421 if (!(xhci->quirks & XHCI_BROKEN_STREAMS) &&
422 HCC_MAX_PSA(xhci->hcc_params) >= 4)
423 xhci->shared_hcd->can_do_streams = 1;
425 /* USB-2 and USB-3 roothubs initialized, allow runtime pm suspend */
426 pm_runtime_put_noidle(&dev->dev);
428 if (xhci->quirks & XHCI_DEFAULT_PM_RUNTIME_ALLOW)
429 pm_runtime_allow(&dev->dev);
434 usb_put_hcd(xhci->shared_hcd);
436 usb_hcd_pci_remove(dev);
438 pm_runtime_put_noidle(&dev->dev);
442 static void xhci_pci_remove(struct pci_dev *dev)
444 struct xhci_hcd *xhci;
446 xhci = hcd_to_xhci(pci_get_drvdata(dev));
447 if (xhci->quirks & XHCI_RENESAS_FW_QUIRK)
448 renesas_xhci_pci_exit(dev);
450 xhci->xhc_state |= XHCI_STATE_REMOVING;
452 if (xhci->quirks & XHCI_DEFAULT_PM_RUNTIME_ALLOW)
453 pm_runtime_forbid(&dev->dev);
455 if (xhci->shared_hcd) {
456 usb_remove_hcd(xhci->shared_hcd);
457 usb_put_hcd(xhci->shared_hcd);
458 xhci->shared_hcd = NULL;
461 /* Workaround for spurious wakeups at shutdown with HSW */
462 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
463 pci_set_power_state(dev, PCI_D3hot);
465 usb_hcd_pci_remove(dev);
470 * In some Intel xHCI controllers, in order to get D3 working,
471 * through a vendor specific SSIC CONFIG register at offset 0x883c,
472 * SSIC PORT need to be marked as "unused" before putting xHCI
473 * into D3. After D3 exit, the SSIC port need to be marked as "used".
474 * Without this change, xHCI might not enter D3 state.
476 static void xhci_ssic_port_unused_quirk(struct usb_hcd *hcd, bool suspend)
478 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
483 for (i = 0; i < SSIC_PORT_NUM; i++) {
484 reg = (void __iomem *) xhci->cap_regs +
486 i * SSIC_PORT_CFG2_OFFSET;
488 /* Notify SSIC that SSIC profile programming is not done. */
489 val = readl(reg) & ~PROG_DONE;
492 /* Mark SSIC port as unused(suspend) or used(resume) */
495 val |= SSIC_PORT_UNUSED;
497 val &= ~SSIC_PORT_UNUSED;
500 /* Notify SSIC that SSIC profile programming is done */
501 val = readl(reg) | PROG_DONE;
508 * Make sure PME works on some Intel xHCI controllers by writing 1 to clear
509 * the Internal PME flag bit in vendor specific PMCTRL register at offset 0x80a4
511 static void xhci_pme_quirk(struct usb_hcd *hcd)
513 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
517 reg = (void __iomem *) xhci->cap_regs + 0x80a4;
519 writel(val | BIT(28), reg);
523 static void xhci_sparse_control_quirk(struct usb_hcd *hcd)
527 reg = readl(hcd->regs + SPARSE_CNTL_ENABLE);
528 reg &= ~BIT(SPARSE_DISABLE_BIT);
529 writel(reg, hcd->regs + SPARSE_CNTL_ENABLE);
532 static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
534 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
535 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
539 * Systems with the TI redriver that loses port status change events
540 * need to have the registers polled during D3, so avoid D3cold.
542 if (xhci->quirks & XHCI_COMP_MODE_QUIRK)
543 pci_d3cold_disable(pdev);
545 if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
548 if (xhci->quirks & XHCI_SSIC_PORT_UNUSED)
549 xhci_ssic_port_unused_quirk(hcd, true);
551 if (xhci->quirks & XHCI_DISABLE_SPARSE)
552 xhci_sparse_control_quirk(hcd);
554 ret = xhci_suspend(xhci, do_wakeup);
555 if (ret && (xhci->quirks & XHCI_SSIC_PORT_UNUSED))
556 xhci_ssic_port_unused_quirk(hcd, false);
561 static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
563 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
564 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
567 reset_control_reset(xhci->reset);
569 /* The BIOS on systems with the Intel Panther Point chipset may or may
570 * not support xHCI natively. That means that during system resume, it
571 * may switch the ports back to EHCI so that users can use their
572 * keyboard to select a kernel from GRUB after resume from hibernate.
574 * The BIOS is supposed to remember whether the OS had xHCI ports
575 * enabled before resume, and switch the ports back to xHCI when the
576 * BIOS/OS semaphore is written, but we all know we can't trust BIOS
579 * Unconditionally switch the ports back to xHCI after a system resume.
580 * It should not matter whether the EHCI or xHCI controller is
581 * resumed first. It's enough to do the switchover in xHCI because
582 * USB core won't notice anything as the hub driver doesn't start
583 * running again until after all the devices (including both EHCI and
584 * xHCI host controllers) have been resumed.
587 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
588 usb_enable_intel_xhci_ports(pdev);
590 if (xhci->quirks & XHCI_SSIC_PORT_UNUSED)
591 xhci_ssic_port_unused_quirk(hcd, false);
593 if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
596 retval = xhci_resume(xhci, hibernated);
600 static void xhci_pci_shutdown(struct usb_hcd *hcd)
602 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
603 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
607 /* Yet another workaround for spurious wakeups at shutdown with HSW */
608 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
609 pci_set_power_state(pdev, PCI_D3hot);
611 #endif /* CONFIG_PM */
613 /*-------------------------------------------------------------------------*/
615 static const struct xhci_driver_data reneses_data = {
616 .quirks = XHCI_RENESAS_FW_QUIRK,
617 .firmware = "renesas_usb_fw.mem",
620 /* PCI driver selection metadata; PCI hotplugging uses this */
621 static const struct pci_device_id pci_ids[] = {
622 { PCI_DEVICE(0x1912, 0x0014),
623 .driver_data = (unsigned long)&reneses_data,
625 { PCI_DEVICE(0x1912, 0x0015),
626 .driver_data = (unsigned long)&reneses_data,
628 /* handle any USB 3.0 xHCI controller */
629 { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0),
631 { /* end: all zeroes */ }
633 MODULE_DEVICE_TABLE(pci, pci_ids);
634 MODULE_FIRMWARE("renesas_usb_fw.mem");
636 /* pci driver glue; this is a "new style" PCI driver module */
637 static struct pci_driver xhci_pci_driver = {
641 .probe = xhci_pci_probe,
642 .remove = xhci_pci_remove,
643 /* suspend and resume implemented later */
645 .shutdown = usb_hcd_pci_shutdown,
648 .pm = &usb_hcd_pci_pm_ops
653 static int __init xhci_pci_init(void)
655 xhci_init_driver(&xhci_pci_hc_driver, &xhci_pci_overrides);
657 xhci_pci_hc_driver.pci_suspend = xhci_pci_suspend;
658 xhci_pci_hc_driver.pci_resume = xhci_pci_resume;
659 xhci_pci_hc_driver.shutdown = xhci_pci_shutdown;
661 return pci_register_driver(&xhci_pci_driver);
663 module_init(xhci_pci_init);
665 static void __exit xhci_pci_exit(void)
667 pci_unregister_driver(&xhci_pci_driver);
669 module_exit(xhci_pci_exit);
671 MODULE_DESCRIPTION("xHCI PCI Host Controller Driver");
672 MODULE_LICENSE("GPL");