xhci-pci.c 9.2 KB

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