xhci-pci.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*
  2. * xHCI host controller driver PCI Bus Glue.
  3. *
  4. * Copyright (C) 2008 Intel Corp.
  5. *
  6. * Author: Sarah Sharp
  7. * Some code borrowed from the Linux EHCI driver.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  15. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16. * for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software Foundation,
  20. * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/pci.h>
  23. #include <linux/slab.h>
  24. #include <linux/module.h>
  25. #include "xhci.h"
  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_VENDOR_ID_ETRON 0x1b6f
  30. #define PCI_DEVICE_ID_ASROCK_P67 0x7023
  31. static const char hcd_name[] = "xhci_hcd";
  32. /* called after powerup, by probe or system-pm "wakeup" */
  33. static int xhci_pci_reinit(struct xhci_hcd *xhci, struct pci_dev *pdev)
  34. {
  35. /*
  36. * TODO: Implement finding debug ports later.
  37. * TODO: see if there are any quirks that need to be added to handle
  38. * new extended capabilities.
  39. */
  40. /* PCI Memory-Write-Invalidate cycle support is optional (uncommon) */
  41. if (!pci_set_mwi(pdev))
  42. xhci_dbg(xhci, "MWI active\n");
  43. xhci_dbg(xhci, "Finished xhci_pci_reinit\n");
  44. return 0;
  45. }
  46. static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
  47. {
  48. struct pci_dev *pdev = to_pci_dev(dev);
  49. /* Look for vendor-specific quirks */
  50. if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC &&
  51. pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK) {
  52. if (pdev->revision == 0x0) {
  53. xhci->quirks |= XHCI_RESET_EP_QUIRK;
  54. xhci_dbg(xhci, "QUIRK: Fresco Logic xHC needs configure"
  55. " endpoint cmd after reset endpoint\n");
  56. }
  57. /* Fresco Logic confirms: all revisions of this chip do not
  58. * support MSI, even though some of them claim to in their PCI
  59. * capabilities.
  60. */
  61. xhci->quirks |= XHCI_BROKEN_MSI;
  62. xhci_dbg(xhci, "QUIRK: Fresco Logic revision %u "
  63. "has broken MSI implementation\n",
  64. pdev->revision);
  65. xhci->quirks |= XHCI_TRUST_TX_LENGTH;
  66. }
  67. if (pdev->vendor == PCI_VENDOR_ID_NEC)
  68. xhci->quirks |= XHCI_NEC_HOST;
  69. if (pdev->vendor == PCI_VENDOR_ID_AMD && xhci->hci_version == 0x96)
  70. xhci->quirks |= XHCI_AMD_0x96_HOST;
  71. /* AMD PLL quirk */
  72. if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info())
  73. xhci->quirks |= XHCI_AMD_PLL_FIX;
  74. if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
  75. xhci->quirks |= XHCI_LPM_SUPPORT;
  76. xhci->quirks |= XHCI_INTEL_HOST;
  77. }
  78. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  79. pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI) {
  80. xhci->quirks |= XHCI_SPURIOUS_SUCCESS;
  81. xhci->quirks |= XHCI_EP_LIMIT_QUIRK;
  82. xhci->limit_active_eps = 64;
  83. xhci->quirks |= XHCI_SW_BW_CHECKING;
  84. /*
  85. * PPT desktop boards DH77EB and DH77DF will power back on after
  86. * a few seconds of being shutdown. The fix for this is to
  87. * switch the ports from xHCI to EHCI on shutdown. We can't use
  88. * DMI information to find those particular boards (since each
  89. * vendor will change the board name), so we have to key off all
  90. * PPT chipsets.
  91. */
  92. xhci->quirks |= XHCI_SPURIOUS_REBOOT;
  93. xhci->quirks |= XHCI_AVOID_BEI;
  94. }
  95. if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
  96. pdev->device == PCI_DEVICE_ID_ASROCK_P67) {
  97. xhci->quirks |= XHCI_RESET_ON_RESUME;
  98. xhci_dbg(xhci, "QUIRK: Resetting on resume\n");
  99. xhci->quirks |= XHCI_TRUST_TX_LENGTH;
  100. }
  101. if (pdev->vendor == PCI_VENDOR_ID_VIA)
  102. xhci->quirks |= XHCI_RESET_ON_RESUME;
  103. }
  104. /* called during probe() after chip reset completes */
  105. static int xhci_pci_setup(struct usb_hcd *hcd)
  106. {
  107. struct xhci_hcd *xhci;
  108. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  109. int retval;
  110. retval = xhci_gen_setup(hcd, xhci_pci_quirks);
  111. if (retval)
  112. return retval;
  113. xhci = hcd_to_xhci(hcd);
  114. if (!usb_hcd_is_primary_hcd(hcd))
  115. return 0;
  116. pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn);
  117. xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn);
  118. /* Find any debug ports */
  119. retval = xhci_pci_reinit(xhci, pdev);
  120. if (!retval)
  121. return retval;
  122. kfree(xhci);
  123. return retval;
  124. }
  125. /*
  126. * We need to register our own PCI probe function (instead of the USB core's
  127. * function) in order to create a second roothub under xHCI.
  128. */
  129. static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
  130. {
  131. int retval;
  132. struct xhci_hcd *xhci;
  133. struct hc_driver *driver;
  134. struct usb_hcd *hcd;
  135. driver = (struct hc_driver *)id->driver_data;
  136. /* Register the USB 2.0 roothub.
  137. * FIXME: USB core must know to register the USB 2.0 roothub first.
  138. * This is sort of silly, because we could just set the HCD driver flags
  139. * to say USB 2.0, but I'm not sure what the implications would be in
  140. * the other parts of the HCD code.
  141. */
  142. retval = usb_hcd_pci_probe(dev, id);
  143. if (retval)
  144. return retval;
  145. /* USB 2.0 roothub is stored in the PCI device now. */
  146. hcd = dev_get_drvdata(&dev->dev);
  147. xhci = hcd_to_xhci(hcd);
  148. xhci->shared_hcd = usb_create_shared_hcd(driver, &dev->dev,
  149. pci_name(dev), hcd);
  150. if (!xhci->shared_hcd) {
  151. retval = -ENOMEM;
  152. goto dealloc_usb2_hcd;
  153. }
  154. /* Set the xHCI pointer before xhci_pci_setup() (aka hcd_driver.reset)
  155. * is called by usb_add_hcd().
  156. */
  157. *((struct xhci_hcd **) xhci->shared_hcd->hcd_priv) = xhci;
  158. retval = usb_add_hcd(xhci->shared_hcd, dev->irq,
  159. IRQF_SHARED);
  160. if (retval)
  161. goto put_usb3_hcd;
  162. /* Roothub already marked as USB 3.0 speed */
  163. /* We know the LPM timeout algorithms for this host, let the USB core
  164. * enable and disable LPM for devices under the USB 3.0 roothub.
  165. */
  166. if (xhci->quirks & XHCI_LPM_SUPPORT)
  167. hcd_to_bus(xhci->shared_hcd)->root_hub->lpm_capable = 1;
  168. return 0;
  169. put_usb3_hcd:
  170. usb_put_hcd(xhci->shared_hcd);
  171. dealloc_usb2_hcd:
  172. usb_hcd_pci_remove(dev);
  173. return retval;
  174. }
  175. static void xhci_pci_remove(struct pci_dev *dev)
  176. {
  177. struct xhci_hcd *xhci;
  178. xhci = hcd_to_xhci(pci_get_drvdata(dev));
  179. if (xhci->shared_hcd) {
  180. usb_remove_hcd(xhci->shared_hcd);
  181. usb_put_hcd(xhci->shared_hcd);
  182. }
  183. usb_hcd_pci_remove(dev);
  184. kfree(xhci);
  185. }
  186. #ifdef CONFIG_PM
  187. static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
  188. {
  189. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  190. int retval = 0;
  191. if (hcd->state != HC_STATE_SUSPENDED ||
  192. xhci->shared_hcd->state != HC_STATE_SUSPENDED)
  193. return -EINVAL;
  194. retval = xhci_suspend(xhci);
  195. return retval;
  196. }
  197. static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
  198. {
  199. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  200. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  201. int retval = 0;
  202. /* The BIOS on systems with the Intel Panther Point chipset may or may
  203. * not support xHCI natively. That means that during system resume, it
  204. * may switch the ports back to EHCI so that users can use their
  205. * keyboard to select a kernel from GRUB after resume from hibernate.
  206. *
  207. * The BIOS is supposed to remember whether the OS had xHCI ports
  208. * enabled before resume, and switch the ports back to xHCI when the
  209. * BIOS/OS semaphore is written, but we all know we can't trust BIOS
  210. * writers.
  211. *
  212. * Unconditionally switch the ports back to xHCI after a system resume.
  213. * We can't tell whether the EHCI or xHCI controller will be resumed
  214. * first, so we have to do the port switchover in both drivers. Writing
  215. * a '1' to the port switchover registers should have no effect if the
  216. * port was already switched over.
  217. */
  218. if (usb_is_intel_switchable_xhci(pdev))
  219. usb_enable_xhci_ports(pdev);
  220. retval = xhci_resume(xhci, hibernated);
  221. return retval;
  222. }
  223. #endif /* CONFIG_PM */
  224. static const struct hc_driver xhci_pci_hc_driver = {
  225. .description = hcd_name,
  226. .product_desc = "xHCI Host Controller",
  227. .hcd_priv_size = sizeof(struct xhci_hcd *),
  228. /*
  229. * generic hardware linkage
  230. */
  231. .irq = xhci_irq,
  232. .flags = HCD_MEMORY | HCD_USB3 | HCD_SHARED,
  233. /*
  234. * basic lifecycle operations
  235. */
  236. .reset = xhci_pci_setup,
  237. .start = xhci_run,
  238. #ifdef CONFIG_PM
  239. .pci_suspend = xhci_pci_suspend,
  240. .pci_resume = xhci_pci_resume,
  241. #endif
  242. .stop = xhci_stop,
  243. .shutdown = xhci_shutdown,
  244. /*
  245. * managing i/o requests and associated device resources
  246. */
  247. .urb_enqueue = xhci_urb_enqueue,
  248. .urb_dequeue = xhci_urb_dequeue,
  249. .alloc_dev = xhci_alloc_dev,
  250. .free_dev = xhci_free_dev,
  251. .alloc_streams = xhci_alloc_streams,
  252. .free_streams = xhci_free_streams,
  253. .add_endpoint = xhci_add_endpoint,
  254. .drop_endpoint = xhci_drop_endpoint,
  255. .endpoint_reset = xhci_endpoint_reset,
  256. .check_bandwidth = xhci_check_bandwidth,
  257. .reset_bandwidth = xhci_reset_bandwidth,
  258. .address_device = xhci_address_device,
  259. .update_hub_device = xhci_update_hub_device,
  260. .reset_device = xhci_discover_or_reset_device,
  261. /*
  262. * scheduling support
  263. */
  264. .get_frame_number = xhci_get_frame,
  265. /* Root hub support */
  266. .hub_control = xhci_hub_control,
  267. .hub_status_data = xhci_hub_status_data,
  268. .bus_suspend = xhci_bus_suspend,
  269. .bus_resume = xhci_bus_resume,
  270. /*
  271. * call back when device connected and addressed
  272. */
  273. .update_device = xhci_update_device,
  274. .set_usb2_hw_lpm = xhci_set_usb2_hardware_lpm,
  275. .enable_usb3_lpm_timeout = xhci_enable_usb3_lpm_timeout,
  276. .disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout,
  277. };
  278. /*-------------------------------------------------------------------------*/
  279. /* PCI driver selection metadata; PCI hotplugging uses this */
  280. static const struct pci_device_id pci_ids[] = { {
  281. /* handle any USB 3.0 xHCI controller */
  282. PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0),
  283. .driver_data = (unsigned long) &xhci_pci_hc_driver,
  284. },
  285. { /* end: all zeroes */ }
  286. };
  287. MODULE_DEVICE_TABLE(pci, pci_ids);
  288. /* pci driver glue; this is a "new style" PCI driver module */
  289. static struct pci_driver xhci_pci_driver = {
  290. .name = (char *) hcd_name,
  291. .id_table = pci_ids,
  292. .probe = xhci_pci_probe,
  293. .remove = xhci_pci_remove,
  294. /* suspend and resume implemented later */
  295. .shutdown = usb_hcd_pci_shutdown,
  296. #ifdef CONFIG_PM_SLEEP
  297. .driver = {
  298. .pm = &usb_hcd_pci_pm_ops
  299. },
  300. #endif
  301. };
  302. int __init xhci_register_pci(void)
  303. {
  304. return pci_register_driver(&xhci_pci_driver);
  305. }
  306. void xhci_unregister_pci(void)
  307. {
  308. pci_unregister_driver(&xhci_pci_driver);
  309. }