xhci-pci.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  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 <linux/reset.h>
  15. #include <linux/suspend.h>
  16. #include "xhci.h"
  17. #include "xhci-trace.h"
  18. #include "xhci-pci.h"
  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)
  24. #define SPARSE_DISABLE_BIT 17
  25. #define SPARSE_CNTL_ENABLE 0xC12C
  26. /* Device for a quirk */
  27. #define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73
  28. #define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000
  29. #define PCI_DEVICE_ID_FRESCO_LOGIC_FL1009 0x1009
  30. #define PCI_DEVICE_ID_FRESCO_LOGIC_FL1100 0x1100
  31. #define PCI_DEVICE_ID_FRESCO_LOGIC_FL1400 0x1400
  32. #define PCI_VENDOR_ID_ETRON 0x1b6f
  33. #define PCI_DEVICE_ID_EJ168 0x7023
  34. #define PCI_DEVICE_ID_EJ188 0x7052
  35. #define PCI_DEVICE_ID_VIA_VL805 0x3483
  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_APOLLO_LAKE_XHCI 0x5aa8
  45. #define PCI_DEVICE_ID_INTEL_DENVERTON_XHCI 0x19d0
  46. #define PCI_DEVICE_ID_INTEL_ICE_LAKE_XHCI 0x8a13
  47. #define PCI_DEVICE_ID_INTEL_TIGER_LAKE_XHCI 0x9a13
  48. #define PCI_DEVICE_ID_INTEL_TIGER_LAKE_PCH_XHCI 0xa0ed
  49. #define PCI_DEVICE_ID_INTEL_COMET_LAKE_XHCI 0xa3af
  50. #define PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI 0x51ed
  51. #define PCI_DEVICE_ID_INTEL_ALDER_LAKE_N_PCH_XHCI 0x54ed
  52. #define PCI_VENDOR_ID_PHYTIUM 0x1db7
  53. #define PCI_DEVICE_ID_PHYTIUM_XHCI 0xdc27
  54. /* Thunderbolt */
  55. #define PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_XHCI 0x1138
  56. #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_XHCI 0x15b5
  57. #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_XHCI 0x15b6
  58. #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_XHCI 0x15c1
  59. #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_XHCI 0x15db
  60. #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_XHCI 0x15d4
  61. #define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_XHCI 0x15e9
  62. #define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_XHCI 0x15ec
  63. #define PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_XHCI 0x15f0
  64. #define PCI_DEVICE_ID_AMD_ARIEL_TYPEC_XHCI 0x13ed
  65. #define PCI_DEVICE_ID_AMD_ARIEL_TYPEA_XHCI 0x13ee
  66. #define PCI_DEVICE_ID_AMD_STARSHIP_XHCI 0x148c
  67. #define PCI_DEVICE_ID_AMD_FIREFLIGHT_15D4_XHCI 0x15d4
  68. #define PCI_DEVICE_ID_AMD_FIREFLIGHT_15D5_XHCI 0x15d5
  69. #define PCI_DEVICE_ID_AMD_RAVEN_15E0_XHCI 0x15e0
  70. #define PCI_DEVICE_ID_AMD_RAVEN_15E1_XHCI 0x15e1
  71. #define PCI_DEVICE_ID_AMD_RAVEN2_XHCI 0x15e5
  72. #define PCI_DEVICE_ID_AMD_RENOIR_XHCI 0x1639
  73. #define PCI_DEVICE_ID_AMD_PROMONTORYA_4 0x43b9
  74. #define PCI_DEVICE_ID_AMD_PROMONTORYA_3 0x43ba
  75. #define PCI_DEVICE_ID_AMD_PROMONTORYA_2 0x43bb
  76. #define PCI_DEVICE_ID_AMD_PROMONTORYA_1 0x43bc
  77. #define PCI_DEVICE_ID_ATI_NAVI10_7316_XHCI 0x7316
  78. #define PCI_DEVICE_ID_ASMEDIA_1042_XHCI 0x1042
  79. #define PCI_DEVICE_ID_ASMEDIA_1042A_XHCI 0x1142
  80. #define PCI_DEVICE_ID_ASMEDIA_1142_XHCI 0x1242
  81. #define PCI_DEVICE_ID_ASMEDIA_2142_XHCI 0x2142
  82. #define PCI_DEVICE_ID_ASMEDIA_3042_XHCI 0x3042
  83. #define PCI_DEVICE_ID_ASMEDIA_3242_XHCI 0x3242
  84. #define PCI_DEVICE_ID_CADENCE 0x17CD
  85. #define PCI_DEVICE_ID_CADENCE_SSP 0x0200
  86. static const char hcd_name[] = "xhci_hcd";
  87. static struct hc_driver __read_mostly xhci_pci_hc_driver;
  88. static int xhci_pci_setup(struct usb_hcd *hcd);
  89. static int xhci_pci_run(struct usb_hcd *hcd);
  90. static int xhci_pci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev,
  91. struct usb_tt *tt, gfp_t mem_flags);
  92. static const struct xhci_driver_overrides xhci_pci_overrides __initconst = {
  93. .reset = xhci_pci_setup,
  94. .start = xhci_pci_run,
  95. .update_hub_device = xhci_pci_update_hub_device,
  96. };
  97. /*
  98. * Primary Legacy and MSI IRQ are synced in suspend_common().
  99. * All MSI-X IRQs and secondary MSI IRQs should be synced here.
  100. */
  101. static void xhci_msix_sync_irqs(struct xhci_hcd *xhci)
  102. {
  103. struct usb_hcd *hcd = xhci_to_hcd(xhci);
  104. if (hcd->msix_enabled) {
  105. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  106. /* for now, the driver only supports one primary interrupter */
  107. synchronize_irq(pci_irq_vector(pdev, 0));
  108. }
  109. }
  110. /* Legacy IRQ is freed by usb_remove_hcd() or usb_hcd_pci_shutdown() */
  111. static void xhci_cleanup_msix(struct xhci_hcd *xhci)
  112. {
  113. struct usb_hcd *hcd = xhci_to_hcd(xhci);
  114. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  115. if (hcd->irq > 0)
  116. return;
  117. free_irq(pci_irq_vector(pdev, 0), xhci_to_hcd(xhci));
  118. pci_free_irq_vectors(pdev);
  119. hcd->msix_enabled = 0;
  120. }
  121. /* Try enabling MSI-X with MSI and legacy IRQ as fallback */
  122. static int xhci_try_enable_msi(struct usb_hcd *hcd)
  123. {
  124. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  125. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  126. int ret;
  127. /*
  128. * Some Fresco Logic host controllers advertise MSI, but fail to
  129. * generate interrupts. Don't even try to enable MSI.
  130. */
  131. if (xhci->quirks & XHCI_BROKEN_MSI)
  132. goto legacy_irq;
  133. /* unregister the legacy interrupt */
  134. if (hcd->irq)
  135. free_irq(hcd->irq, hcd);
  136. hcd->irq = 0;
  137. /*
  138. * calculate number of MSI-X vectors supported.
  139. * - HCS_MAX_INTRS: the max number of interrupts the host can handle,
  140. * with max number of interrupters based on the xhci HCSPARAMS1.
  141. * - num_online_cpus: maximum MSI-X vectors per CPUs core.
  142. * Add additional 1 vector to ensure always available interrupt.
  143. */
  144. xhci->nvecs = min(num_online_cpus() + 1,
  145. HCS_MAX_INTRS(xhci->hcs_params1));
  146. /* TODO: Check with MSI Soc for sysdev */
  147. xhci->nvecs = pci_alloc_irq_vectors(pdev, 1, xhci->nvecs,
  148. PCI_IRQ_MSIX | PCI_IRQ_MSI);
  149. if (xhci->nvecs < 0) {
  150. xhci_dbg_trace(xhci, trace_xhci_dbg_init,
  151. "failed to allocate IRQ vectors");
  152. goto legacy_irq;
  153. }
  154. ret = request_irq(pci_irq_vector(pdev, 0), xhci_msi_irq, 0, "xhci_hcd",
  155. xhci_to_hcd(xhci));
  156. if (ret)
  157. goto free_irq_vectors;
  158. hcd->msi_enabled = 1;
  159. hcd->msix_enabled = pdev->msix_enabled;
  160. return 0;
  161. free_irq_vectors:
  162. xhci_dbg_trace(xhci, trace_xhci_dbg_init, "disable %s interrupt",
  163. pdev->msix_enabled ? "MSI-X" : "MSI");
  164. pci_free_irq_vectors(pdev);
  165. legacy_irq:
  166. if (!pdev->irq) {
  167. xhci_err(xhci, "No msi-x/msi found and no IRQ in BIOS\n");
  168. return -EINVAL;
  169. }
  170. if (!strlen(hcd->irq_descr))
  171. snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d",
  172. hcd->driver->description, hcd->self.busnum);
  173. /* fall back to legacy interrupt */
  174. ret = request_irq(pdev->irq, &usb_hcd_irq, IRQF_SHARED, hcd->irq_descr, hcd);
  175. if (ret) {
  176. xhci_err(xhci, "request interrupt %d failed\n", pdev->irq);
  177. return ret;
  178. }
  179. hcd->irq = pdev->irq;
  180. return 0;
  181. }
  182. static int xhci_pci_run(struct usb_hcd *hcd)
  183. {
  184. int ret;
  185. if (usb_hcd_is_primary_hcd(hcd)) {
  186. ret = xhci_try_enable_msi(hcd);
  187. if (ret)
  188. return ret;
  189. }
  190. return xhci_run(hcd);
  191. }
  192. static void xhci_pci_stop(struct usb_hcd *hcd)
  193. {
  194. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  195. xhci_stop(hcd);
  196. if (usb_hcd_is_primary_hcd(hcd))
  197. xhci_cleanup_msix(xhci);
  198. }
  199. /* called after powerup, by probe or system-pm "wakeup" */
  200. static int xhci_pci_reinit(struct xhci_hcd *xhci, struct pci_dev *pdev)
  201. {
  202. /*
  203. * TODO: Implement finding debug ports later.
  204. * TODO: see if there are any quirks that need to be added to handle
  205. * new extended capabilities.
  206. */
  207. /* PCI Memory-Write-Invalidate cycle support is optional (uncommon) */
  208. if (!pci_set_mwi(pdev))
  209. xhci_dbg(xhci, "MWI active\n");
  210. xhci_dbg(xhci, "Finished xhci_pci_reinit\n");
  211. return 0;
  212. }
  213. static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
  214. {
  215. struct pci_dev *pdev = to_pci_dev(dev);
  216. /* Look for vendor-specific quirks */
  217. if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC &&
  218. (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK ||
  219. pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_FL1400)) {
  220. if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK &&
  221. pdev->revision == 0x0) {
  222. xhci->quirks |= XHCI_RESET_EP_QUIRK;
  223. xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
  224. "XHCI_RESET_EP_QUIRK for this evaluation HW is deprecated");
  225. }
  226. if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK &&
  227. pdev->revision == 0x4) {
  228. xhci->quirks |= XHCI_SLOW_SUSPEND;
  229. xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
  230. "QUIRK: Fresco Logic xHC revision %u"
  231. "must be suspended extra slowly",
  232. pdev->revision);
  233. }
  234. if (pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK)
  235. xhci->quirks |= XHCI_BROKEN_STREAMS;
  236. /* Fresco Logic confirms: all revisions of this chip do not
  237. * support MSI, even though some of them claim to in their PCI
  238. * capabilities.
  239. */
  240. xhci->quirks |= XHCI_BROKEN_MSI;
  241. xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
  242. "QUIRK: Fresco Logic revision %u "
  243. "has broken MSI implementation",
  244. pdev->revision);
  245. }
  246. if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC &&
  247. pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_FL1009)
  248. xhci->quirks |= XHCI_BROKEN_STREAMS;
  249. if (pdev->vendor == PCI_VENDOR_ID_NEC)
  250. xhci->quirks |= XHCI_NEC_HOST;
  251. if (pdev->vendor == PCI_VENDOR_ID_AMD &&
  252. (pdev->device == PCI_DEVICE_ID_AMD_ARIEL_TYPEC_XHCI ||
  253. pdev->device == PCI_DEVICE_ID_AMD_ARIEL_TYPEA_XHCI ||
  254. pdev->device == PCI_DEVICE_ID_AMD_STARSHIP_XHCI ||
  255. pdev->device == PCI_DEVICE_ID_AMD_FIREFLIGHT_15D4_XHCI ||
  256. pdev->device == PCI_DEVICE_ID_AMD_FIREFLIGHT_15D5_XHCI ||
  257. pdev->device == PCI_DEVICE_ID_AMD_RAVEN_15E0_XHCI ||
  258. pdev->device == PCI_DEVICE_ID_AMD_RAVEN_15E1_XHCI ||
  259. pdev->device == PCI_DEVICE_ID_AMD_RAVEN2_XHCI))
  260. xhci->quirks |= XHCI_LIMIT_ENDPOINT_INTERVAL_9;
  261. if (pdev->vendor == PCI_VENDOR_ID_ATI &&
  262. pdev->device == PCI_DEVICE_ID_ATI_NAVI10_7316_XHCI)
  263. xhci->quirks |= XHCI_LIMIT_ENDPOINT_INTERVAL_9;
  264. if (pdev->vendor == PCI_VENDOR_ID_AMD && xhci->hci_version == 0x96)
  265. xhci->quirks |= XHCI_AMD_0x96_HOST;
  266. /* AMD PLL quirk */
  267. if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_quirk_pll_check())
  268. xhci->quirks |= XHCI_AMD_PLL_FIX;
  269. if (pdev->vendor == PCI_VENDOR_ID_AMD &&
  270. (pdev->device == 0x145c ||
  271. pdev->device == 0x15e0 ||
  272. pdev->device == 0x15e1 ||
  273. pdev->device == 0x43bb))
  274. xhci->quirks |= XHCI_SUSPEND_DELAY;
  275. if (pdev->vendor == PCI_VENDOR_ID_AMD &&
  276. (pdev->device == 0x15e0 || pdev->device == 0x15e1))
  277. xhci->quirks |= XHCI_SNPS_BROKEN_SUSPEND;
  278. if (pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x15e5) {
  279. xhci->quirks |= XHCI_DISABLE_SPARSE;
  280. xhci->quirks |= XHCI_RESET_ON_RESUME;
  281. }
  282. if (pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x43f7)
  283. xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;
  284. if ((pdev->vendor == PCI_VENDOR_ID_AMD) &&
  285. ((pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4) ||
  286. (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_3) ||
  287. (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_2) ||
  288. (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_1)))
  289. xhci->quirks |= XHCI_U2_DISABLE_WAKE;
  290. if (pdev->vendor == PCI_VENDOR_ID_AMD &&
  291. pdev->device == PCI_DEVICE_ID_AMD_RENOIR_XHCI)
  292. xhci->quirks |= XHCI_BROKEN_D3COLD_S2I;
  293. if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
  294. xhci->quirks |= XHCI_LPM_SUPPORT;
  295. xhci->quirks |= XHCI_INTEL_HOST;
  296. xhci->quirks |= XHCI_AVOID_BEI;
  297. }
  298. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  299. pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI) {
  300. xhci->quirks |= XHCI_EP_LIMIT_QUIRK;
  301. xhci->limit_active_eps = 64;
  302. xhci->quirks |= XHCI_SW_BW_CHECKING;
  303. /*
  304. * PPT desktop boards DH77EB and DH77DF will power back on after
  305. * a few seconds of being shutdown. The fix for this is to
  306. * switch the ports from xHCI to EHCI on shutdown. We can't use
  307. * DMI information to find those particular boards (since each
  308. * vendor will change the board name), so we have to key off all
  309. * PPT chipsets.
  310. */
  311. xhci->quirks |= XHCI_SPURIOUS_REBOOT;
  312. }
  313. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  314. (pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI ||
  315. pdev->device == PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI)) {
  316. xhci->quirks |= XHCI_SPURIOUS_REBOOT;
  317. xhci->quirks |= XHCI_SPURIOUS_WAKEUP;
  318. }
  319. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  320. (pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI ||
  321. pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI ||
  322. pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
  323. pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI ||
  324. pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI ||
  325. pdev->device == PCI_DEVICE_ID_INTEL_APOLLO_LAKE_XHCI ||
  326. pdev->device == PCI_DEVICE_ID_INTEL_DENVERTON_XHCI ||
  327. pdev->device == PCI_DEVICE_ID_INTEL_COMET_LAKE_XHCI)) {
  328. xhci->quirks |= XHCI_PME_STUCK_QUIRK;
  329. }
  330. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  331. pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI)
  332. xhci->quirks |= XHCI_SSIC_PORT_UNUSED;
  333. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  334. (pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
  335. pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI ||
  336. pdev->device == PCI_DEVICE_ID_INTEL_APOLLO_LAKE_XHCI))
  337. xhci->quirks |= XHCI_INTEL_USB_ROLE_SW;
  338. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  339. (pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
  340. pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI ||
  341. pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI ||
  342. pdev->device == PCI_DEVICE_ID_INTEL_APOLLO_LAKE_XHCI ||
  343. pdev->device == PCI_DEVICE_ID_INTEL_DENVERTON_XHCI))
  344. xhci->quirks |= XHCI_MISSING_CAS;
  345. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  346. (pdev->device == PCI_DEVICE_ID_INTEL_TIGER_LAKE_PCH_XHCI ||
  347. pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI ||
  348. pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_N_PCH_XHCI))
  349. xhci->quirks |= XHCI_RESET_TO_DEFAULT;
  350. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  351. (pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_XHCI ||
  352. pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_XHCI ||
  353. pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_XHCI ||
  354. pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_XHCI ||
  355. pdev->device == PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_XHCI ||
  356. pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_XHCI ||
  357. pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_XHCI ||
  358. pdev->device == PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_XHCI ||
  359. pdev->device == PCI_DEVICE_ID_INTEL_ICE_LAKE_XHCI ||
  360. pdev->device == PCI_DEVICE_ID_INTEL_TIGER_LAKE_XHCI ||
  361. pdev->device == PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_XHCI))
  362. xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;
  363. if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
  364. (pdev->device == PCI_DEVICE_ID_EJ168 ||
  365. pdev->device == PCI_DEVICE_ID_EJ188)) {
  366. xhci->quirks |= XHCI_ETRON_HOST;
  367. xhci->quirks |= XHCI_RESET_ON_RESUME;
  368. xhci->quirks |= XHCI_BROKEN_STREAMS;
  369. xhci->quirks |= XHCI_NO_SOFT_RETRY;
  370. }
  371. if (pdev->vendor == PCI_VENDOR_ID_RENESAS &&
  372. pdev->device == 0x0014) {
  373. xhci->quirks |= XHCI_ZERO_64B_REGS;
  374. }
  375. if (pdev->vendor == PCI_VENDOR_ID_RENESAS &&
  376. pdev->device == 0x0015) {
  377. xhci->quirks |= XHCI_RESET_ON_RESUME;
  378. xhci->quirks |= XHCI_ZERO_64B_REGS;
  379. }
  380. if (pdev->vendor == PCI_VENDOR_ID_VIA)
  381. xhci->quirks |= XHCI_RESET_ON_RESUME;
  382. if (pdev->vendor == PCI_VENDOR_ID_PHYTIUM &&
  383. pdev->device == PCI_DEVICE_ID_PHYTIUM_XHCI)
  384. xhci->quirks |= XHCI_RESET_ON_RESUME;
  385. /* See https://bugzilla.kernel.org/show_bug.cgi?id=79511 */
  386. if (pdev->vendor == PCI_VENDOR_ID_VIA &&
  387. pdev->device == 0x3432)
  388. xhci->quirks |= XHCI_BROKEN_STREAMS;
  389. if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == PCI_DEVICE_ID_VIA_VL805) {
  390. xhci->quirks |= XHCI_LPM_SUPPORT;
  391. xhci->quirks |= XHCI_TRB_OVERFETCH;
  392. }
  393. if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
  394. pdev->device == PCI_DEVICE_ID_ASMEDIA_1042_XHCI) {
  395. /*
  396. * try to tame the ASMedia 1042 controller which reports 0.96
  397. * but appears to behave more like 1.0
  398. */
  399. xhci->quirks |= XHCI_SPURIOUS_SUCCESS;
  400. xhci->quirks |= XHCI_BROKEN_STREAMS;
  401. }
  402. if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
  403. pdev->device == PCI_DEVICE_ID_ASMEDIA_1042A_XHCI) {
  404. xhci->quirks |= XHCI_NO_64BIT_SUPPORT;
  405. }
  406. if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
  407. (pdev->device == PCI_DEVICE_ID_ASMEDIA_1142_XHCI ||
  408. pdev->device == PCI_DEVICE_ID_ASMEDIA_2142_XHCI ||
  409. pdev->device == PCI_DEVICE_ID_ASMEDIA_3242_XHCI))
  410. xhci->quirks |= XHCI_NO_64BIT_SUPPORT;
  411. if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
  412. pdev->device == PCI_DEVICE_ID_ASMEDIA_1042A_XHCI)
  413. xhci->quirks |= XHCI_ASMEDIA_MODIFY_FLOWCONTROL;
  414. if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
  415. pdev->device == PCI_DEVICE_ID_ASMEDIA_3042_XHCI)
  416. xhci->quirks |= XHCI_RESET_ON_RESUME;
  417. if (pdev->vendor == PCI_VENDOR_ID_TI && pdev->device == 0x8241)
  418. xhci->quirks |= XHCI_LIMIT_ENDPOINT_INTERVAL_7;
  419. if ((pdev->vendor == PCI_VENDOR_ID_BROADCOM ||
  420. pdev->vendor == PCI_VENDOR_ID_CAVIUM) &&
  421. pdev->device == 0x9026)
  422. xhci->quirks |= XHCI_RESET_PLL_ON_DISCONNECT;
  423. if (pdev->vendor == PCI_VENDOR_ID_AMD &&
  424. (pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_2 ||
  425. pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4))
  426. xhci->quirks |= XHCI_NO_SOFT_RETRY;
  427. if (pdev->vendor == PCI_VENDOR_ID_ZHAOXIN) {
  428. xhci->quirks |= XHCI_ZHAOXIN_HOST;
  429. xhci->quirks |= XHCI_LPM_SUPPORT;
  430. if (pdev->device == 0x9202) {
  431. xhci->quirks |= XHCI_RESET_ON_RESUME;
  432. xhci->quirks |= XHCI_TRB_OVERFETCH;
  433. }
  434. if (pdev->device == 0x9203)
  435. xhci->quirks |= XHCI_TRB_OVERFETCH;
  436. }
  437. if (pdev->vendor == PCI_DEVICE_ID_CADENCE &&
  438. pdev->device == PCI_DEVICE_ID_CADENCE_SSP)
  439. xhci->quirks |= XHCI_CDNS_SCTX_QUIRK;
  440. /* xHC spec requires PCI devices to support D3hot and D3cold */
  441. if (xhci->hci_version >= 0x120)
  442. xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;
  443. if (xhci->quirks & XHCI_RESET_ON_RESUME)
  444. xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
  445. "QUIRK: Resetting on resume");
  446. }
  447. #ifdef CONFIG_ACPI
  448. static void xhci_pme_acpi_rtd3_enable(struct pci_dev *dev)
  449. {
  450. static const guid_t intel_dsm_guid =
  451. GUID_INIT(0xac340cb7, 0xe901, 0x45bf,
  452. 0xb7, 0xe6, 0x2b, 0x34, 0xec, 0x93, 0x1e, 0x23);
  453. union acpi_object *obj;
  454. obj = acpi_evaluate_dsm(ACPI_HANDLE(&dev->dev), &intel_dsm_guid, 3, 1,
  455. NULL);
  456. ACPI_FREE(obj);
  457. }
  458. static void xhci_find_lpm_incapable_ports(struct usb_hcd *hcd, struct usb_device *hdev)
  459. {
  460. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  461. struct xhci_hub *rhub = &xhci->usb3_rhub;
  462. int ret;
  463. int i;
  464. /* This is not the usb3 roothub we are looking for */
  465. if (hcd != rhub->hcd)
  466. return;
  467. if (hdev->maxchild > rhub->num_ports) {
  468. dev_err(&hdev->dev, "USB3 roothub port number mismatch\n");
  469. return;
  470. }
  471. for (i = 0; i < hdev->maxchild; i++) {
  472. ret = usb_acpi_port_lpm_incapable(hdev, i);
  473. dev_dbg(&hdev->dev, "port-%d disable U1/U2 _DSM: %d\n", i + 1, ret);
  474. if (ret >= 0) {
  475. rhub->ports[i]->lpm_incapable = ret;
  476. continue;
  477. }
  478. }
  479. }
  480. #else
  481. static void xhci_pme_acpi_rtd3_enable(struct pci_dev *dev) { }
  482. static void xhci_find_lpm_incapable_ports(struct usb_hcd *hcd, struct usb_device *hdev) { }
  483. #endif /* CONFIG_ACPI */
  484. /* called during probe() after chip reset completes */
  485. static int xhci_pci_setup(struct usb_hcd *hcd)
  486. {
  487. struct xhci_hcd *xhci;
  488. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  489. int retval;
  490. u8 sbrn;
  491. xhci = hcd_to_xhci(hcd);
  492. /* imod_interval is the interrupt moderation value in nanoseconds. */
  493. xhci->imod_interval = 40000;
  494. retval = xhci_gen_setup(hcd, xhci_pci_quirks);
  495. if (retval)
  496. return retval;
  497. if (!usb_hcd_is_primary_hcd(hcd))
  498. return 0;
  499. if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
  500. xhci_pme_acpi_rtd3_enable(pdev);
  501. pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &sbrn);
  502. xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int)sbrn);
  503. /* Find any debug ports */
  504. return xhci_pci_reinit(xhci, pdev);
  505. }
  506. static int xhci_pci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev,
  507. struct usb_tt *tt, gfp_t mem_flags)
  508. {
  509. /* Check if acpi claims some USB3 roothub ports are lpm incapable */
  510. if (!hdev->parent)
  511. xhci_find_lpm_incapable_ports(hcd, hdev);
  512. return xhci_update_hub_device(hcd, hdev, tt, mem_flags);
  513. }
  514. /*
  515. * We need to register our own PCI probe function (instead of the USB core's
  516. * function) in order to create a second roothub under xHCI.
  517. */
  518. int xhci_pci_common_probe(struct pci_dev *dev, const struct pci_device_id *id)
  519. {
  520. int retval;
  521. struct xhci_hcd *xhci;
  522. struct usb_hcd *hcd;
  523. struct reset_control *reset;
  524. reset = devm_reset_control_get_optional_exclusive(&dev->dev, NULL);
  525. if (IS_ERR(reset))
  526. return PTR_ERR(reset);
  527. reset_control_reset(reset);
  528. /* Prevent runtime suspending between USB-2 and USB-3 initialization */
  529. pm_runtime_get_noresume(&dev->dev);
  530. /* Register the USB 2.0 roothub.
  531. * FIXME: USB core must know to register the USB 2.0 roothub first.
  532. * This is sort of silly, because we could just set the HCD driver flags
  533. * to say USB 2.0, but I'm not sure what the implications would be in
  534. * the other parts of the HCD code.
  535. */
  536. retval = usb_hcd_pci_probe(dev, &xhci_pci_hc_driver);
  537. if (retval)
  538. goto put_runtime_pm;
  539. /* USB 2.0 roothub is stored in the PCI device now. */
  540. hcd = dev_get_drvdata(&dev->dev);
  541. xhci = hcd_to_xhci(hcd);
  542. xhci->reset = reset;
  543. xhci->shared_hcd = usb_create_shared_hcd(&xhci_pci_hc_driver, &dev->dev,
  544. pci_name(dev), hcd);
  545. if (!xhci->shared_hcd) {
  546. retval = -ENOMEM;
  547. goto dealloc_usb2_hcd;
  548. }
  549. retval = xhci_ext_cap_init(xhci);
  550. if (retval)
  551. goto put_usb3_hcd;
  552. retval = usb_add_hcd(xhci->shared_hcd, dev->irq,
  553. IRQF_SHARED);
  554. if (retval)
  555. goto put_usb3_hcd;
  556. /* Roothub already marked as USB 3.0 speed */
  557. if (!(xhci->quirks & XHCI_BROKEN_STREAMS) &&
  558. HCC_MAX_PSA(xhci->hcc_params) >= 4)
  559. xhci->shared_hcd->can_do_streams = 1;
  560. /* USB-2 and USB-3 roothubs initialized, allow runtime pm suspend */
  561. pm_runtime_put_noidle(&dev->dev);
  562. if (pci_choose_state(dev, PMSG_SUSPEND) == PCI_D0)
  563. pm_runtime_get(&dev->dev);
  564. else if (xhci->quirks & XHCI_DEFAULT_PM_RUNTIME_ALLOW)
  565. pm_runtime_allow(&dev->dev);
  566. dma_set_max_seg_size(&dev->dev, UINT_MAX);
  567. return 0;
  568. put_usb3_hcd:
  569. usb_put_hcd(xhci->shared_hcd);
  570. dealloc_usb2_hcd:
  571. usb_hcd_pci_remove(dev);
  572. put_runtime_pm:
  573. pm_runtime_put_noidle(&dev->dev);
  574. return retval;
  575. }
  576. EXPORT_SYMBOL_NS_GPL(xhci_pci_common_probe, xhci);
  577. /* handled by xhci-pci-renesas if enabled */
  578. static const struct pci_device_id pci_ids_renesas[] = {
  579. { PCI_DEVICE(PCI_VENDOR_ID_RENESAS, 0x0014) },
  580. { PCI_DEVICE(PCI_VENDOR_ID_RENESAS, 0x0015) },
  581. { /* end: all zeroes */ }
  582. };
  583. static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
  584. {
  585. if (IS_ENABLED(CONFIG_USB_XHCI_PCI_RENESAS) &&
  586. pci_match_id(pci_ids_renesas, dev))
  587. return -ENODEV;
  588. return xhci_pci_common_probe(dev, id);
  589. }
  590. void xhci_pci_remove(struct pci_dev *dev)
  591. {
  592. struct xhci_hcd *xhci;
  593. bool set_power_d3;
  594. xhci = hcd_to_xhci(pci_get_drvdata(dev));
  595. set_power_d3 = xhci->quirks & XHCI_SPURIOUS_WAKEUP;
  596. xhci->xhc_state |= XHCI_STATE_REMOVING;
  597. if (pci_choose_state(dev, PMSG_SUSPEND) == PCI_D0)
  598. pm_runtime_put(&dev->dev);
  599. else if (xhci->quirks & XHCI_DEFAULT_PM_RUNTIME_ALLOW)
  600. pm_runtime_forbid(&dev->dev);
  601. if (xhci->shared_hcd) {
  602. usb_remove_hcd(xhci->shared_hcd);
  603. usb_put_hcd(xhci->shared_hcd);
  604. xhci->shared_hcd = NULL;
  605. }
  606. usb_hcd_pci_remove(dev);
  607. /* Workaround for spurious wakeups at shutdown with HSW */
  608. if (set_power_d3)
  609. pci_set_power_state(dev, PCI_D3hot);
  610. }
  611. EXPORT_SYMBOL_NS_GPL(xhci_pci_remove, xhci);
  612. /*
  613. * In some Intel xHCI controllers, in order to get D3 working,
  614. * through a vendor specific SSIC CONFIG register at offset 0x883c,
  615. * SSIC PORT need to be marked as "unused" before putting xHCI
  616. * into D3. After D3 exit, the SSIC port need to be marked as "used".
  617. * Without this change, xHCI might not enter D3 state.
  618. */
  619. static void xhci_ssic_port_unused_quirk(struct usb_hcd *hcd, bool suspend)
  620. {
  621. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  622. u32 val;
  623. void __iomem *reg;
  624. int i;
  625. for (i = 0; i < SSIC_PORT_NUM; i++) {
  626. reg = (void __iomem *) xhci->cap_regs +
  627. SSIC_PORT_CFG2 +
  628. i * SSIC_PORT_CFG2_OFFSET;
  629. /* Notify SSIC that SSIC profile programming is not done. */
  630. val = readl(reg) & ~PROG_DONE;
  631. writel(val, reg);
  632. /* Mark SSIC port as unused(suspend) or used(resume) */
  633. val = readl(reg);
  634. if (suspend)
  635. val |= SSIC_PORT_UNUSED;
  636. else
  637. val &= ~SSIC_PORT_UNUSED;
  638. writel(val, reg);
  639. /* Notify SSIC that SSIC profile programming is done */
  640. val = readl(reg) | PROG_DONE;
  641. writel(val, reg);
  642. readl(reg);
  643. }
  644. }
  645. /*
  646. * Make sure PME works on some Intel xHCI controllers by writing 1 to clear
  647. * the Internal PME flag bit in vendor specific PMCTRL register at offset 0x80a4
  648. */
  649. static void xhci_pme_quirk(struct usb_hcd *hcd)
  650. {
  651. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  652. void __iomem *reg;
  653. u32 val;
  654. reg = (void __iomem *) xhci->cap_regs + 0x80a4;
  655. val = readl(reg);
  656. writel(val | BIT(28), reg);
  657. readl(reg);
  658. }
  659. static void xhci_sparse_control_quirk(struct usb_hcd *hcd)
  660. {
  661. u32 reg;
  662. reg = readl(hcd->regs + SPARSE_CNTL_ENABLE);
  663. reg &= ~BIT(SPARSE_DISABLE_BIT);
  664. writel(reg, hcd->regs + SPARSE_CNTL_ENABLE);
  665. }
  666. static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
  667. {
  668. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  669. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  670. int ret;
  671. /*
  672. * Systems with the TI redriver that loses port status change events
  673. * need to have the registers polled during D3, so avoid D3cold.
  674. */
  675. if (xhci->quirks & XHCI_COMP_MODE_QUIRK)
  676. pci_d3cold_disable(pdev);
  677. #ifdef CONFIG_SUSPEND
  678. /* d3cold is broken, but only when s2idle is used */
  679. if (pm_suspend_target_state == PM_SUSPEND_TO_IDLE &&
  680. xhci->quirks & (XHCI_BROKEN_D3COLD_S2I))
  681. pci_d3cold_disable(pdev);
  682. #endif
  683. if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
  684. xhci_pme_quirk(hcd);
  685. if (xhci->quirks & XHCI_SSIC_PORT_UNUSED)
  686. xhci_ssic_port_unused_quirk(hcd, true);
  687. if (xhci->quirks & XHCI_DISABLE_SPARSE)
  688. xhci_sparse_control_quirk(hcd);
  689. ret = xhci_suspend(xhci, do_wakeup);
  690. /* synchronize irq when using MSI-X */
  691. xhci_msix_sync_irqs(xhci);
  692. if (ret && (xhci->quirks & XHCI_SSIC_PORT_UNUSED))
  693. xhci_ssic_port_unused_quirk(hcd, false);
  694. return ret;
  695. }
  696. static int xhci_pci_resume(struct usb_hcd *hcd, pm_message_t msg)
  697. {
  698. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  699. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  700. reset_control_reset(xhci->reset);
  701. /* The BIOS on systems with the Intel Panther Point chipset may or may
  702. * not support xHCI natively. That means that during system resume, it
  703. * may switch the ports back to EHCI so that users can use their
  704. * keyboard to select a kernel from GRUB after resume from hibernate.
  705. *
  706. * The BIOS is supposed to remember whether the OS had xHCI ports
  707. * enabled before resume, and switch the ports back to xHCI when the
  708. * BIOS/OS semaphore is written, but we all know we can't trust BIOS
  709. * writers.
  710. *
  711. * Unconditionally switch the ports back to xHCI after a system resume.
  712. * It should not matter whether the EHCI or xHCI controller is
  713. * resumed first. It's enough to do the switchover in xHCI because
  714. * USB core won't notice anything as the hub driver doesn't start
  715. * running again until after all the devices (including both EHCI and
  716. * xHCI host controllers) have been resumed.
  717. */
  718. if (pdev->vendor == PCI_VENDOR_ID_INTEL)
  719. usb_enable_intel_xhci_ports(pdev);
  720. if (xhci->quirks & XHCI_SSIC_PORT_UNUSED)
  721. xhci_ssic_port_unused_quirk(hcd, false);
  722. if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
  723. xhci_pme_quirk(hcd);
  724. return xhci_resume(xhci, msg);
  725. }
  726. static int xhci_pci_poweroff_late(struct usb_hcd *hcd, bool do_wakeup)
  727. {
  728. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  729. struct xhci_port *port;
  730. struct usb_device *udev;
  731. u32 portsc;
  732. int i;
  733. /*
  734. * Systems with XHCI_RESET_TO_DEFAULT quirk have boot firmware that
  735. * cause significant boot delay if usb ports are in suspended U3 state
  736. * during boot. Some USB devices survive in U3 state over S4 hibernate
  737. *
  738. * Disable ports that are in U3 if remote wake is not enabled for either
  739. * host controller or connected device
  740. */
  741. if (!(xhci->quirks & XHCI_RESET_TO_DEFAULT))
  742. return 0;
  743. for (i = 0; i < HCS_MAX_PORTS(xhci->hcs_params1); i++) {
  744. port = &xhci->hw_ports[i];
  745. portsc = readl(port->addr);
  746. if ((portsc & PORT_PLS_MASK) != XDEV_U3)
  747. continue;
  748. if (!port->slot_id || !xhci->devs[port->slot_id]) {
  749. xhci_err(xhci, "No dev for slot_id %d for port %d-%d in U3\n",
  750. port->slot_id, port->rhub->hcd->self.busnum,
  751. port->hcd_portnum + 1);
  752. continue;
  753. }
  754. udev = xhci->devs[port->slot_id]->udev;
  755. /* if wakeup is enabled then don't disable the port */
  756. if (udev->do_remote_wakeup && do_wakeup)
  757. continue;
  758. xhci_dbg(xhci, "port %d-%d in U3 without wakeup, disable it\n",
  759. port->rhub->hcd->self.busnum, port->hcd_portnum + 1);
  760. portsc = xhci_port_state_to_neutral(portsc);
  761. writel(portsc | PORT_PE, port->addr);
  762. }
  763. return 0;
  764. }
  765. static void xhci_pci_shutdown(struct usb_hcd *hcd)
  766. {
  767. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  768. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  769. xhci_shutdown(hcd);
  770. xhci_cleanup_msix(xhci);
  771. /* Yet another workaround for spurious wakeups at shutdown with HSW */
  772. if (xhci->quirks & XHCI_SPURIOUS_WAKEUP)
  773. pci_set_power_state(pdev, PCI_D3hot);
  774. }
  775. /*-------------------------------------------------------------------------*/
  776. /* PCI driver selection metadata; PCI hotplugging uses this */
  777. static const struct pci_device_id pci_ids[] = {
  778. /* handle any USB 3.0 xHCI controller */
  779. { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0),
  780. },
  781. { /* end: all zeroes */ }
  782. };
  783. MODULE_DEVICE_TABLE(pci, pci_ids);
  784. /* pci driver glue; this is a "new style" PCI driver module */
  785. static struct pci_driver xhci_pci_driver = {
  786. .name = hcd_name,
  787. .id_table = pci_ids,
  788. .probe = xhci_pci_probe,
  789. .remove = xhci_pci_remove,
  790. /* suspend and resume implemented later */
  791. .shutdown = usb_hcd_pci_shutdown,
  792. .driver = {
  793. .pm = pm_ptr(&usb_hcd_pci_pm_ops),
  794. },
  795. };
  796. static int __init xhci_pci_init(void)
  797. {
  798. xhci_init_driver(&xhci_pci_hc_driver, &xhci_pci_overrides);
  799. xhci_pci_hc_driver.pci_suspend = pm_ptr(xhci_pci_suspend);
  800. xhci_pci_hc_driver.pci_resume = pm_ptr(xhci_pci_resume);
  801. xhci_pci_hc_driver.pci_poweroff_late = pm_ptr(xhci_pci_poweroff_late);
  802. xhci_pci_hc_driver.shutdown = pm_ptr(xhci_pci_shutdown);
  803. xhci_pci_hc_driver.stop = xhci_pci_stop;
  804. return pci_register_driver(&xhci_pci_driver);
  805. }
  806. module_init(xhci_pci_init);
  807. static void __exit xhci_pci_exit(void)
  808. {
  809. pci_unregister_driver(&xhci_pci_driver);
  810. }
  811. module_exit(xhci_pci_exit);
  812. MODULE_DESCRIPTION("xHCI PCI Host Controller Driver");
  813. MODULE_LICENSE("GPL");