xhci-pci.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. // 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. #include <linux/pci.h>
  11. #include <linux/slab.h>
  12. #include <linux/module.h>
  13. #include <linux/acpi.h>
  14. #include "xhci.h"
  15. #include "xhci-trace.h"
  16. #define SSIC_PORT_NUM 2
  17. #define SSIC_PORT_CFG2 0x880c
  18. #define SSIC_PORT_CFG2_OFFSET 0x30
  19. #define PROG_DONE (1 << 30)
  20. #define SSIC_PORT_UNUSED (1 << 31)
  21. /* Device for a quirk */
  22. #define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73
  23. #define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000
  24. #define PCI_DEVICE_ID_FRESCO_LOGIC_FL1009 0x1009
  25. #define PCI_DEVICE_ID_FRESCO_LOGIC_FL1400 0x1400
  26. #define PCI_VENDOR_ID_ETRON 0x1b6f
  27. #define PCI_DEVICE_ID_EJ168 0x7023
  28. #define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI 0x8c31
  29. #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31
  30. #define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI 0x9cb1
  31. #define PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI 0x22b5
  32. #define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI 0xa12f
  33. #define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI 0x9d2f
  34. #define PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI 0x0aa8
  35. #define PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI 0x1aa8
  36. #define PCI_DEVICE_ID_INTEL_APL_XHCI 0x5aa8
  37. #define PCI_DEVICE_ID_INTEL_DNV_XHCI 0x19d0
  38. #define PCI_DEVICE_ID_INTEL_CML_XHCI 0xa3af
  39. #define PCI_DEVICE_ID_AMD_PROMONTORYA_4 0x43b9
  40. #define PCI_DEVICE_ID_AMD_PROMONTORYA_3 0x43ba
  41. #define PCI_DEVICE_ID_AMD_PROMONTORYA_2 0x43bb
  42. #define PCI_DEVICE_ID_AMD_PROMONTORYA_1 0x43bc
  43. #define PCI_DEVICE_ID_ASMEDIA_1042A_XHCI 0x1142
  44. static const char hcd_name[] = "xhci_hcd";
  45. static struct hc_driver __read_mostly xhci_pci_hc_driver;
  46. static int xhci_pci_setup(struct usb_hcd *hcd);
  47. static const struct xhci_driver_overrides xhci_pci_overrides __initconst = {
  48. .reset = xhci_pci_setup,
  49. };
  50. /* called after powerup, by probe or system-pm "wakeup" */
  51. static int xhci_pci_reinit(struct xhci_hcd *xhci, struct pci_dev *pdev)
  52. {
  53. /*
  54. * TODO: Implement finding debug ports later.
  55. * TODO: see if there are any quirks that need to be added to handle
  56. * new extended capabilities.
  57. */
  58. /* PCI Memory-Write-Invalidate cycle support is optional (uncommon) */
  59. if (!pci_set_mwi(pdev))
  60. xhci_dbg(xhci, "MWI active\n");
  61. xhci_dbg(xhci, "Finished xhci_pci_reinit\n");
  62. return 0;
  63. }
  64. static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
  65. {
  66. struct pci_dev *pdev = to_pci_dev(dev);
  67. /* Look for vendor-specific quirks */
  68. if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC &&
  69. (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK ||
  70. pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_FL1400)) {
  71. if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK &&
  72. pdev->revision == 0x0) {
  73. xhci->quirks |= XHCI_RESET_EP_QUIRK;
  74. xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
  75. "QUIRK: Fresco Logic xHC needs configure"
  76. " endpoint cmd after reset endpoint");
  77. }
  78. if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK &&
  79. pdev->revision == 0x4) {
  80. xhci->quirks |= XHCI_SLOW_SUSPEND;
  81. xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
  82. "QUIRK: Fresco Logic xHC revision %u"
  83. "must be suspended extra slowly",
  84. pdev->revision);
  85. }
  86. if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK)
  87. xhci->quirks |= XHCI_BROKEN_STREAMS;
  88. /* Fresco Logic confirms: all revisions of this chip do not
  89. * support MSI, even though some of them claim to in their PCI
  90. * capabilities.
  91. */
  92. xhci->quirks |= XHCI_BROKEN_MSI;
  93. xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
  94. "QUIRK: Fresco Logic revision %u "
  95. "has broken MSI implementation",
  96. pdev->revision);
  97. xhci->quirks |= XHCI_TRUST_TX_LENGTH;
  98. }
  99. if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC &&
  100. pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_FL1009)
  101. xhci->quirks |= XHCI_BROKEN_STREAMS;
  102. if (pdev->vendor == PCI_VENDOR_ID_NEC)
  103. xhci->quirks |= XHCI_NEC_HOST;
  104. if (pdev->vendor == PCI_VENDOR_ID_AMD && xhci->hci_version == 0x96)
  105. xhci->quirks |= XHCI_AMD_0x96_HOST;
  106. /* AMD PLL quirk */
  107. if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info())
  108. xhci->quirks |= XHCI_AMD_PLL_FIX;
  109. if (pdev->vendor == PCI_VENDOR_ID_AMD &&
  110. (pdev->device == 0x145c ||
  111. pdev->device == 0x15e0 ||
  112. pdev->device == 0x15e1 ||
  113. pdev->device == 0x43bb))
  114. xhci->quirks |= XHCI_SUSPEND_DELAY;
  115. if (pdev->vendor == PCI_VENDOR_ID_AMD &&
  116. (pdev->device == 0x15e0 || pdev->device == 0x15e1))
  117. xhci->quirks |= XHCI_SNPS_BROKEN_SUSPEND;
  118. if (pdev->vendor == PCI_VENDOR_ID_AMD)
  119. xhci->quirks |= XHCI_TRUST_TX_LENGTH;
  120. if ((pdev->vendor == PCI_VENDOR_ID_AMD) &&
  121. ((pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4) ||
  122. (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_3) ||
  123. (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_2) ||
  124. (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_1)))
  125. xhci->quirks |= XHCI_U2_DISABLE_WAKE;
  126. if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
  127. xhci->quirks |= XHCI_LPM_SUPPORT;
  128. xhci->quirks |= XHCI_INTEL_HOST;
  129. xhci->quirks |= XHCI_AVOID_BEI;
  130. }
  131. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  132. pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI) {
  133. xhci->quirks |= XHCI_EP_LIMIT_QUIRK;
  134. xhci->limit_active_eps = 64;
  135. xhci->quirks |= XHCI_SW_BW_CHECKING;
  136. /*
  137. * PPT desktop boards DH77EB and DH77DF will power back on after
  138. * a few seconds of being shutdown. The fix for this is to
  139. * switch the ports from xHCI to EHCI on shutdown. We can't use
  140. * DMI information to find those particular boards (since each
  141. * vendor will change the board name), so we have to key off all
  142. * PPT chipsets.
  143. */
  144. xhci->quirks |= XHCI_SPURIOUS_REBOOT;
  145. }
  146. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  147. (pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI ||
  148. pdev->device == PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI)) {
  149. xhci->quirks |= XHCI_SPURIOUS_REBOOT;
  150. xhci->quirks |= XHCI_SPURIOUS_WAKEUP;
  151. }
  152. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  153. (pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI ||
  154. pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI ||
  155. pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
  156. pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI ||
  157. pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI ||
  158. pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI ||
  159. pdev->device == PCI_DEVICE_ID_INTEL_DNV_XHCI ||
  160. pdev->device == PCI_DEVICE_ID_INTEL_CML_XHCI)) {
  161. xhci->quirks |= XHCI_PME_STUCK_QUIRK;
  162. }
  163. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  164. pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI)
  165. xhci->quirks |= XHCI_SSIC_PORT_UNUSED;
  166. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  167. (pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
  168. pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI ||
  169. pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI))
  170. xhci->quirks |= XHCI_INTEL_USB_ROLE_SW;
  171. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  172. (pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
  173. pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI ||
  174. pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI ||
  175. pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI ||
  176. pdev->device == PCI_DEVICE_ID_INTEL_DNV_XHCI))
  177. xhci->quirks |= XHCI_MISSING_CAS;
  178. if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
  179. pdev->device == PCI_DEVICE_ID_EJ168) {
  180. xhci->quirks |= XHCI_RESET_ON_RESUME;
  181. xhci->quirks |= XHCI_TRUST_TX_LENGTH;
  182. xhci->quirks |= XHCI_BROKEN_STREAMS;
  183. }
  184. if (pdev->vendor == PCI_VENDOR_ID_RENESAS &&
  185. pdev->device == 0x0014) {
  186. xhci->quirks |= XHCI_TRUST_TX_LENGTH;
  187. xhci->quirks |= XHCI_ZERO_64B_REGS;
  188. }
  189. if (pdev->vendor == PCI_VENDOR_ID_RENESAS &&
  190. pdev->device == 0x0015) {
  191. xhci->quirks |= XHCI_RESET_ON_RESUME;
  192. xhci->quirks |= XHCI_ZERO_64B_REGS;
  193. }
  194. if (pdev->vendor == PCI_VENDOR_ID_VIA)
  195. xhci->quirks |= XHCI_RESET_ON_RESUME;
  196. /* See https://bugzilla.kernel.org/show_bug.cgi?id=79511 */
  197. if (pdev->vendor == PCI_VENDOR_ID_VIA &&
  198. pdev->device == 0x3432)
  199. xhci->quirks |= XHCI_BROKEN_STREAMS;
  200. if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
  201. pdev->device == 0x1042)
  202. xhci->quirks |= XHCI_BROKEN_STREAMS;
  203. if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
  204. pdev->device == 0x1142)
  205. xhci->quirks |= XHCI_TRUST_TX_LENGTH;
  206. if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
  207. pdev->device == PCI_DEVICE_ID_ASMEDIA_1042A_XHCI)
  208. xhci->quirks |= XHCI_ASMEDIA_MODIFY_FLOWCONTROL;
  209. if (pdev->vendor == PCI_VENDOR_ID_TI && pdev->device == 0x8241)
  210. xhci->quirks |= XHCI_LIMIT_ENDPOINT_INTERVAL_7;
  211. if ((pdev->vendor == PCI_VENDOR_ID_BROADCOM ||
  212. pdev->vendor == PCI_VENDOR_ID_CAVIUM) &&
  213. pdev->device == 0x9026)
  214. xhci->quirks |= XHCI_RESET_PLL_ON_DISCONNECT;
  215. if (xhci->quirks & XHCI_RESET_ON_RESUME)
  216. xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
  217. "QUIRK: Resetting on resume");
  218. }
  219. #ifdef CONFIG_ACPI
  220. static void xhci_pme_acpi_rtd3_enable(struct pci_dev *dev)
  221. {
  222. static const guid_t intel_dsm_guid =
  223. GUID_INIT(0xac340cb7, 0xe901, 0x45bf,
  224. 0xb7, 0xe6, 0x2b, 0x34, 0xec, 0x93, 0x1e, 0x23);
  225. union acpi_object *obj;
  226. obj = acpi_evaluate_dsm(ACPI_HANDLE(&dev->dev), &intel_dsm_guid, 3, 1,
  227. NULL);
  228. ACPI_FREE(obj);
  229. }
  230. #else
  231. static void xhci_pme_acpi_rtd3_enable(struct pci_dev *dev) { }
  232. #endif /* CONFIG_ACPI */
  233. /* called during probe() after chip reset completes */
  234. static int xhci_pci_setup(struct usb_hcd *hcd)
  235. {
  236. struct xhci_hcd *xhci;
  237. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  238. int retval;
  239. xhci = hcd_to_xhci(hcd);
  240. if (!xhci->sbrn)
  241. pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn);
  242. /* imod_interval is the interrupt moderation value in nanoseconds. */
  243. xhci->imod_interval = 40000;
  244. retval = xhci_gen_setup(hcd, xhci_pci_quirks);
  245. if (retval)
  246. return retval;
  247. if (!usb_hcd_is_primary_hcd(hcd))
  248. return 0;
  249. if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
  250. xhci_pme_acpi_rtd3_enable(pdev);
  251. xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn);
  252. /* Find any debug ports */
  253. return xhci_pci_reinit(xhci, pdev);
  254. }
  255. /*
  256. * We need to register our own PCI probe function (instead of the USB core's
  257. * function) in order to create a second roothub under xHCI.
  258. */
  259. static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
  260. {
  261. int retval;
  262. struct xhci_hcd *xhci;
  263. struct hc_driver *driver;
  264. struct usb_hcd *hcd;
  265. driver = (struct hc_driver *)id->driver_data;
  266. /* Prevent runtime suspending between USB-2 and USB-3 initialization */
  267. pm_runtime_get_noresume(&dev->dev);
  268. /* Register the USB 2.0 roothub.
  269. * FIXME: USB core must know to register the USB 2.0 roothub first.
  270. * This is sort of silly, because we could just set the HCD driver flags
  271. * to say USB 2.0, but I'm not sure what the implications would be in
  272. * the other parts of the HCD code.
  273. */
  274. retval = usb_hcd_pci_probe(dev, id);
  275. if (retval)
  276. goto put_runtime_pm;
  277. /* USB 2.0 roothub is stored in the PCI device now. */
  278. hcd = dev_get_drvdata(&dev->dev);
  279. xhci = hcd_to_xhci(hcd);
  280. xhci->shared_hcd = usb_create_shared_hcd(driver, &dev->dev,
  281. pci_name(dev), hcd);
  282. if (!xhci->shared_hcd) {
  283. retval = -ENOMEM;
  284. goto dealloc_usb2_hcd;
  285. }
  286. retval = xhci_ext_cap_init(xhci);
  287. if (retval)
  288. goto put_usb3_hcd;
  289. retval = usb_add_hcd(xhci->shared_hcd, dev->irq,
  290. IRQF_SHARED);
  291. if (retval)
  292. goto put_usb3_hcd;
  293. /* Roothub already marked as USB 3.0 speed */
  294. if (!(xhci->quirks & XHCI_BROKEN_STREAMS) &&
  295. HCC_MAX_PSA(xhci->hcc_params) >= 4)
  296. xhci->shared_hcd->can_do_streams = 1;
  297. /* USB-2 and USB-3 roothubs initialized, allow runtime pm suspend */
  298. pm_runtime_put_noidle(&dev->dev);
  299. return 0;
  300. put_usb3_hcd:
  301. usb_put_hcd(xhci->shared_hcd);
  302. dealloc_usb2_hcd:
  303. usb_hcd_pci_remove(dev);
  304. put_runtime_pm:
  305. pm_runtime_put_noidle(&dev->dev);
  306. return retval;
  307. }
  308. static void xhci_pci_remove(struct pci_dev *dev)
  309. {
  310. struct xhci_hcd *xhci;
  311. xhci = hcd_to_xhci(pci_get_drvdata(dev));
  312. xhci->xhc_state |= XHCI_STATE_REMOVING;
  313. if (xhci->shared_hcd) {
  314. usb_remove_hcd(xhci->shared_hcd);
  315. usb_put_hcd(xhci->shared_hcd);
  316. xhci->shared_hcd = NULL;
  317. }
  318. /* Workaround for spurious wakeups at shutdown with HSW */
  319. if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
  320. pci_set_power_state(dev, PCI_D3hot);
  321. usb_hcd_pci_remove(dev);
  322. }
  323. #ifdef CONFIG_PM
  324. /*
  325. * In some Intel xHCI controllers, in order to get D3 working,
  326. * through a vendor specific SSIC CONFIG register at offset 0x883c,
  327. * SSIC PORT need to be marked as "unused" before putting xHCI
  328. * into D3. After D3 exit, the SSIC port need to be marked as "used".
  329. * Without this change, xHCI might not enter D3 state.
  330. */
  331. static void xhci_ssic_port_unused_quirk(struct usb_hcd *hcd, bool suspend)
  332. {
  333. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  334. u32 val;
  335. void __iomem *reg;
  336. int i;
  337. for (i = 0; i < SSIC_PORT_NUM; i++) {
  338. reg = (void __iomem *) xhci->cap_regs +
  339. SSIC_PORT_CFG2 +
  340. i * SSIC_PORT_CFG2_OFFSET;
  341. /* Notify SSIC that SSIC profile programming is not done. */
  342. val = readl(reg) & ~PROG_DONE;
  343. writel(val, reg);
  344. /* Mark SSIC port as unused(suspend) or used(resume) */
  345. val = readl(reg);
  346. if (suspend)
  347. val |= SSIC_PORT_UNUSED;
  348. else
  349. val &= ~SSIC_PORT_UNUSED;
  350. writel(val, reg);
  351. /* Notify SSIC that SSIC profile programming is done */
  352. val = readl(reg) | PROG_DONE;
  353. writel(val, reg);
  354. readl(reg);
  355. }
  356. }
  357. /*
  358. * Make sure PME works on some Intel xHCI controllers by writing 1 to clear
  359. * the Internal PME flag bit in vendor specific PMCTRL register at offset 0x80a4
  360. */
  361. static void xhci_pme_quirk(struct usb_hcd *hcd)
  362. {
  363. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  364. void __iomem *reg;
  365. u32 val;
  366. reg = (void __iomem *) xhci->cap_regs + 0x80a4;
  367. val = readl(reg);
  368. writel(val | BIT(28), reg);
  369. readl(reg);
  370. }
  371. static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
  372. {
  373. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  374. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  375. int ret;
  376. /*
  377. * Systems with the TI redriver that loses port status change events
  378. * need to have the registers polled during D3, so avoid D3cold.
  379. */
  380. if (xhci->quirks & XHCI_COMP_MODE_QUIRK)
  381. pci_d3cold_disable(pdev);
  382. if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
  383. xhci_pme_quirk(hcd);
  384. if (xhci->quirks & XHCI_SSIC_PORT_UNUSED)
  385. xhci_ssic_port_unused_quirk(hcd, true);
  386. ret = xhci_suspend(xhci, do_wakeup);
  387. if (ret && (xhci->quirks & XHCI_SSIC_PORT_UNUSED))
  388. xhci_ssic_port_unused_quirk(hcd, false);
  389. return ret;
  390. }
  391. static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
  392. {
  393. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  394. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  395. int retval = 0;
  396. /* The BIOS on systems with the Intel Panther Point chipset may or may
  397. * not support xHCI natively. That means that during system resume, it
  398. * may switch the ports back to EHCI so that users can use their
  399. * keyboard to select a kernel from GRUB after resume from hibernate.
  400. *
  401. * The BIOS is supposed to remember whether the OS had xHCI ports
  402. * enabled before resume, and switch the ports back to xHCI when the
  403. * BIOS/OS semaphore is written, but we all know we can't trust BIOS
  404. * writers.
  405. *
  406. * Unconditionally switch the ports back to xHCI after a system resume.
  407. * It should not matter whether the EHCI or xHCI controller is
  408. * resumed first. It's enough to do the switchover in xHCI because
  409. * USB core won't notice anything as the hub driver doesn't start
  410. * running again until after all the devices (including both EHCI and
  411. * xHCI host controllers) have been resumed.
  412. */
  413. if (pdev->vendor == PCI_VENDOR_ID_INTEL)
  414. usb_enable_intel_xhci_ports(pdev);
  415. if (xhci->quirks & XHCI_SSIC_PORT_UNUSED)
  416. xhci_ssic_port_unused_quirk(hcd, false);
  417. if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
  418. xhci_pme_quirk(hcd);
  419. retval = xhci_resume(xhci, hibernated);
  420. return retval;
  421. }
  422. static void xhci_pci_shutdown(struct usb_hcd *hcd)
  423. {
  424. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  425. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  426. xhci_shutdown(hcd);
  427. /* Yet another workaround for spurious wakeups at shutdown with HSW */
  428. if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
  429. pci_set_power_state(pdev, PCI_D3hot);
  430. }
  431. #endif /* CONFIG_PM */
  432. /*-------------------------------------------------------------------------*/
  433. /* PCI driver selection metadata; PCI hotplugging uses this */
  434. static const struct pci_device_id pci_ids[] = { {
  435. /* handle any USB 3.0 xHCI controller */
  436. PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0),
  437. .driver_data = (unsigned long) &xhci_pci_hc_driver,
  438. },
  439. { /* end: all zeroes */ }
  440. };
  441. MODULE_DEVICE_TABLE(pci, pci_ids);
  442. /* pci driver glue; this is a "new style" PCI driver module */
  443. static struct pci_driver xhci_pci_driver = {
  444. .name = (char *) hcd_name,
  445. .id_table = pci_ids,
  446. .probe = xhci_pci_probe,
  447. .remove = xhci_pci_remove,
  448. /* suspend and resume implemented later */
  449. .shutdown = usb_hcd_pci_shutdown,
  450. #ifdef CONFIG_PM
  451. .driver = {
  452. .pm = &usb_hcd_pci_pm_ops
  453. },
  454. #endif
  455. };
  456. static int __init xhci_pci_init(void)
  457. {
  458. xhci_init_driver(&xhci_pci_hc_driver, &xhci_pci_overrides);
  459. #ifdef CONFIG_PM
  460. xhci_pci_hc_driver.pci_suspend = xhci_pci_suspend;
  461. xhci_pci_hc_driver.pci_resume = xhci_pci_resume;
  462. xhci_pci_hc_driver.shutdown = xhci_pci_shutdown;
  463. #endif
  464. return pci_register_driver(&xhci_pci_driver);
  465. }
  466. module_init(xhci_pci_init);
  467. static void __exit xhci_pci_exit(void)
  468. {
  469. pci_unregister_driver(&xhci_pci_driver);
  470. }
  471. module_exit(xhci_pci_exit);
  472. MODULE_DESCRIPTION("xHCI PCI Host Controller Driver");
  473. MODULE_LICENSE("GPL");