xhci-pci.c 9.1 KB

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