xhci-pci.c 17 KB

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