ehci-pci.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. /*
  2. * EHCI HCD (Host Controller Driver) PCI Bus Glue.
  3. *
  4. * Copyright (c) 2000-2004 by David Brownell
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  13. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. * for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/pci.h>
  23. #include <linux/usb.h>
  24. #include <linux/usb/hcd.h>
  25. #include "ehci.h"
  26. #include "pci-quirks.h"
  27. #define DRIVER_DESC "EHCI PCI platform driver"
  28. static const char hcd_name[] = "ehci-pci";
  29. /* defined here to avoid adding to pci_ids.h for single instance use */
  30. #define PCI_DEVICE_ID_INTEL_CE4100_USB 0x2e70
  31. /*-------------------------------------------------------------------------*/
  32. /* called after powerup, by probe or system-pm "wakeup" */
  33. static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev)
  34. {
  35. int retval;
  36. /* we expect static quirk code to handle the "extended capabilities"
  37. * (currently just BIOS handoff) allowed starting with EHCI 0.96
  38. */
  39. /* PCI Memory-Write-Invalidate cycle support is optional (uncommon) */
  40. retval = pci_set_mwi(pdev);
  41. if (!retval)
  42. ehci_dbg(ehci, "MWI active\n");
  43. return 0;
  44. }
  45. /* called during probe() after chip reset completes */
  46. static int ehci_pci_setup(struct usb_hcd *hcd)
  47. {
  48. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  49. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  50. struct pci_dev *p_smbus;
  51. u8 rev;
  52. u32 temp;
  53. int retval;
  54. ehci->caps = hcd->regs;
  55. /*
  56. * ehci_init() causes memory for DMA transfers to be
  57. * allocated. Thus, any vendor-specific workarounds based on
  58. * limiting the type of memory used for DMA transfers must
  59. * happen before ehci_setup() is called.
  60. *
  61. * Most other workarounds can be done either before or after
  62. * init and reset; they are located here too.
  63. */
  64. switch (pdev->vendor) {
  65. case PCI_VENDOR_ID_TOSHIBA_2:
  66. /* celleb's companion chip */
  67. if (pdev->device == 0x01b5) {
  68. #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
  69. ehci->big_endian_mmio = 1;
  70. #else
  71. ehci_warn(ehci,
  72. "unsupported big endian Toshiba quirk\n");
  73. #endif
  74. }
  75. break;
  76. case PCI_VENDOR_ID_NVIDIA:
  77. /* NVidia reports that certain chips don't handle
  78. * QH, ITD, or SITD addresses above 2GB. (But TD,
  79. * data buffer, and periodic schedule are normal.)
  80. */
  81. switch (pdev->device) {
  82. case 0x003c: /* MCP04 */
  83. case 0x005b: /* CK804 */
  84. case 0x00d8: /* CK8 */
  85. case 0x00e8: /* CK8S */
  86. if (pci_set_consistent_dma_mask(pdev,
  87. DMA_BIT_MASK(31)) < 0)
  88. ehci_warn(ehci, "can't enable NVidia "
  89. "workaround for >2GB RAM\n");
  90. break;
  91. /* Some NForce2 chips have problems with selective suspend;
  92. * fixed in newer silicon.
  93. */
  94. case 0x0068:
  95. if (pdev->revision < 0xa4)
  96. ehci->no_selective_suspend = 1;
  97. break;
  98. }
  99. break;
  100. case PCI_VENDOR_ID_INTEL:
  101. if (pdev->device == PCI_DEVICE_ID_INTEL_CE4100_USB)
  102. hcd->has_tt = 1;
  103. break;
  104. case PCI_VENDOR_ID_TDI:
  105. if (pdev->device == PCI_DEVICE_ID_TDI_EHCI)
  106. hcd->has_tt = 1;
  107. break;
  108. case PCI_VENDOR_ID_AMD:
  109. /* AMD PLL quirk */
  110. if (usb_amd_find_chipset_info())
  111. ehci->amd_pll_fix = 1;
  112. /* AMD8111 EHCI doesn't work, according to AMD errata */
  113. if (pdev->device == 0x7463) {
  114. ehci_info(ehci, "ignoring AMD8111 (errata)\n");
  115. retval = -EIO;
  116. goto done;
  117. }
  118. /*
  119. * EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
  120. * read/write memory space which does not belong to it when
  121. * there is NULL pointer with T-bit set to 1 in the frame list
  122. * table. To avoid the issue, the frame list link pointer
  123. * should always contain a valid pointer to a inactive qh.
  124. */
  125. if (pdev->device == 0x7808) {
  126. ehci->use_dummy_qh = 1;
  127. ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI dummy qh workaround\n");
  128. }
  129. break;
  130. case PCI_VENDOR_ID_VIA:
  131. if (pdev->device == 0x3104 && (pdev->revision & 0xf0) == 0x60) {
  132. u8 tmp;
  133. /* The VT6212 defaults to a 1 usec EHCI sleep time which
  134. * hogs the PCI bus *badly*. Setting bit 5 of 0x4B makes
  135. * that sleep time use the conventional 10 usec.
  136. */
  137. pci_read_config_byte(pdev, 0x4b, &tmp);
  138. if (tmp & 0x20)
  139. break;
  140. pci_write_config_byte(pdev, 0x4b, tmp | 0x20);
  141. }
  142. break;
  143. case PCI_VENDOR_ID_ATI:
  144. /* AMD PLL quirk */
  145. if (usb_amd_find_chipset_info())
  146. ehci->amd_pll_fix = 1;
  147. /*
  148. * EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
  149. * read/write memory space which does not belong to it when
  150. * there is NULL pointer with T-bit set to 1 in the frame list
  151. * table. To avoid the issue, the frame list link pointer
  152. * should always contain a valid pointer to a inactive qh.
  153. */
  154. if (pdev->device == 0x4396) {
  155. ehci->use_dummy_qh = 1;
  156. ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI dummy qh workaround\n");
  157. }
  158. /* SB600 and old version of SB700 have a bug in EHCI controller,
  159. * which causes usb devices lose response in some cases.
  160. */
  161. if ((pdev->device == 0x4386) || (pdev->device == 0x4396)) {
  162. p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
  163. PCI_DEVICE_ID_ATI_SBX00_SMBUS,
  164. NULL);
  165. if (!p_smbus)
  166. break;
  167. rev = p_smbus->revision;
  168. if ((pdev->device == 0x4386) || (rev == 0x3a)
  169. || (rev == 0x3b)) {
  170. u8 tmp;
  171. ehci_info(ehci, "applying AMD SB600/SB700 USB "
  172. "freeze workaround\n");
  173. pci_read_config_byte(pdev, 0x53, &tmp);
  174. pci_write_config_byte(pdev, 0x53, tmp | (1<<3));
  175. }
  176. pci_dev_put(p_smbus);
  177. }
  178. break;
  179. case PCI_VENDOR_ID_NETMOS:
  180. /* MosChip frame-index-register bug */
  181. ehci_info(ehci, "applying MosChip frame-index workaround\n");
  182. ehci->frame_index_bug = 1;
  183. break;
  184. }
  185. /* optional debug port, normally in the first BAR */
  186. temp = pci_find_capability(pdev, PCI_CAP_ID_DBG);
  187. if (temp) {
  188. pci_read_config_dword(pdev, temp, &temp);
  189. temp >>= 16;
  190. if (((temp >> 13) & 7) == 1) {
  191. u32 hcs_params = ehci_readl(ehci,
  192. &ehci->caps->hcs_params);
  193. temp &= 0x1fff;
  194. ehci->debug = hcd->regs + temp;
  195. temp = ehci_readl(ehci, &ehci->debug->control);
  196. ehci_info(ehci, "debug port %d%s\n",
  197. HCS_DEBUG_PORT(hcs_params),
  198. (temp & DBGP_ENABLED) ? " IN USE" : "");
  199. if (!(temp & DBGP_ENABLED))
  200. ehci->debug = NULL;
  201. }
  202. }
  203. retval = ehci_setup(hcd);
  204. if (retval)
  205. return retval;
  206. /* These workarounds need to be applied after ehci_setup() */
  207. switch (pdev->vendor) {
  208. case PCI_VENDOR_ID_NEC:
  209. ehci->need_io_watchdog = 0;
  210. break;
  211. case PCI_VENDOR_ID_INTEL:
  212. ehci->need_io_watchdog = 0;
  213. break;
  214. case PCI_VENDOR_ID_NVIDIA:
  215. switch (pdev->device) {
  216. /* MCP89 chips on the MacBookAir3,1 give EPROTO when
  217. * fetching device descriptors unless LPM is disabled.
  218. * There are also intermittent problems enumerating
  219. * devices with PPCD enabled.
  220. */
  221. case 0x0d9d:
  222. ehci_info(ehci, "disable ppcd for nvidia mcp89\n");
  223. ehci->has_ppcd = 0;
  224. ehci->command &= ~CMD_PPCEE;
  225. break;
  226. }
  227. break;
  228. }
  229. /* at least the Genesys GL880S needs fixup here */
  230. temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params);
  231. temp &= 0x0f;
  232. if (temp && HCS_N_PORTS(ehci->hcs_params) > temp) {
  233. ehci_dbg(ehci, "bogus port configuration: "
  234. "cc=%d x pcc=%d < ports=%d\n",
  235. HCS_N_CC(ehci->hcs_params),
  236. HCS_N_PCC(ehci->hcs_params),
  237. HCS_N_PORTS(ehci->hcs_params));
  238. switch (pdev->vendor) {
  239. case 0x17a0: /* GENESYS */
  240. /* GL880S: should be PORTS=2 */
  241. temp |= (ehci->hcs_params & ~0xf);
  242. ehci->hcs_params = temp;
  243. break;
  244. case PCI_VENDOR_ID_NVIDIA:
  245. /* NF4: should be PCC=10 */
  246. break;
  247. }
  248. }
  249. /* Serial Bus Release Number is at PCI 0x60 offset */
  250. if (pdev->vendor == PCI_VENDOR_ID_STMICRO
  251. && pdev->device == PCI_DEVICE_ID_STMICRO_USB_HOST)
  252. ; /* ConneXT has no sbrn register */
  253. else
  254. pci_read_config_byte(pdev, 0x60, &ehci->sbrn);
  255. /* Keep this around for a while just in case some EHCI
  256. * implementation uses legacy PCI PM support. This test
  257. * can be removed on 17 Dec 2009 if the dev_warn() hasn't
  258. * been triggered by then.
  259. */
  260. if (!device_can_wakeup(&pdev->dev)) {
  261. u16 port_wake;
  262. pci_read_config_word(pdev, 0x62, &port_wake);
  263. if (port_wake & 0x0001) {
  264. dev_warn(&pdev->dev, "Enabling legacy PCI PM\n");
  265. device_set_wakeup_capable(&pdev->dev, 1);
  266. }
  267. }
  268. #ifdef CONFIG_USB_SUSPEND
  269. /* REVISIT: the controller works fine for wakeup iff the root hub
  270. * itself is "globally" suspended, but usbcore currently doesn't
  271. * understand such things.
  272. *
  273. * System suspend currently expects to be able to suspend the entire
  274. * device tree, device-at-a-time. If we failed selective suspend
  275. * reports, system suspend would fail; so the root hub code must claim
  276. * success. That's lying to usbcore, and it matters for runtime
  277. * PM scenarios with selective suspend and remote wakeup...
  278. */
  279. if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev))
  280. ehci_warn(ehci, "selective suspend/wakeup unavailable\n");
  281. #endif
  282. retval = ehci_pci_reinit(ehci, pdev);
  283. done:
  284. return retval;
  285. }
  286. /*-------------------------------------------------------------------------*/
  287. #ifdef CONFIG_PM
  288. /* suspend/resume, section 4.3 */
  289. /* These routines rely on the PCI bus glue
  290. * to handle powerdown and wakeup, and currently also on
  291. * transceivers that don't need any software attention to set up
  292. * the right sort of wakeup.
  293. * Also they depend on separate root hub suspend/resume.
  294. */
  295. static bool usb_is_intel_switchable_ehci(struct pci_dev *pdev)
  296. {
  297. return pdev->class == PCI_CLASS_SERIAL_USB_EHCI &&
  298. pdev->vendor == PCI_VENDOR_ID_INTEL &&
  299. (pdev->device == 0x1E26 ||
  300. pdev->device == 0x8C2D ||
  301. pdev->device == 0x8C26 ||
  302. pdev->device == 0x9C26);
  303. }
  304. static void ehci_enable_xhci_companion(void)
  305. {
  306. struct pci_dev *companion = NULL;
  307. /* The xHCI and EHCI controllers are not on the same PCI slot */
  308. for_each_pci_dev(companion) {
  309. if (!usb_is_intel_switchable_xhci(companion))
  310. continue;
  311. usb_enable_xhci_ports(companion);
  312. return;
  313. }
  314. }
  315. static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
  316. {
  317. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  318. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  319. /* The BIOS on systems with the Intel Panther Point chipset may or may
  320. * not support xHCI natively. That means that during system resume, it
  321. * may switch the ports back to EHCI so that users can use their
  322. * keyboard to select a kernel from GRUB after resume from hibernate.
  323. *
  324. * The BIOS is supposed to remember whether the OS had xHCI ports
  325. * enabled before resume, and switch the ports back to xHCI when the
  326. * BIOS/OS semaphore is written, but we all know we can't trust BIOS
  327. * writers.
  328. *
  329. * Unconditionally switch the ports back to xHCI after a system resume.
  330. * We can't tell whether the EHCI or xHCI controller will be resumed
  331. * first, so we have to do the port switchover in both drivers. Writing
  332. * a '1' to the port switchover registers should have no effect if the
  333. * port was already switched over.
  334. */
  335. if (usb_is_intel_switchable_ehci(pdev))
  336. ehci_enable_xhci_companion();
  337. if (ehci_resume(hcd, hibernated) != 0)
  338. (void) ehci_pci_reinit(ehci, pdev);
  339. return 0;
  340. }
  341. #else
  342. #define ehci_suspend NULL
  343. #define ehci_pci_resume NULL
  344. #endif /* CONFIG_PM */
  345. static struct hc_driver __read_mostly ehci_pci_hc_driver;
  346. static const struct ehci_driver_overrides pci_overrides __initdata = {
  347. .reset = ehci_pci_setup,
  348. };
  349. /*-------------------------------------------------------------------------*/
  350. /* PCI driver selection metadata; PCI hotplugging uses this */
  351. static const struct pci_device_id pci_ids [] = { {
  352. /* handle any USB 2.0 EHCI controller */
  353. PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0),
  354. .driver_data = (unsigned long) &ehci_pci_hc_driver,
  355. }, {
  356. PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_USB_HOST),
  357. .driver_data = (unsigned long) &ehci_pci_hc_driver,
  358. },
  359. { /* end: all zeroes */ }
  360. };
  361. MODULE_DEVICE_TABLE(pci, pci_ids);
  362. /* pci driver glue; this is a "new style" PCI driver module */
  363. static struct pci_driver ehci_pci_driver = {
  364. .name = (char *) hcd_name,
  365. .id_table = pci_ids,
  366. .probe = usb_hcd_pci_probe,
  367. .remove = usb_hcd_pci_remove,
  368. .shutdown = usb_hcd_pci_shutdown,
  369. #ifdef CONFIG_PM_SLEEP
  370. .driver = {
  371. .pm = &usb_hcd_pci_pm_ops
  372. },
  373. #endif
  374. };
  375. static int __init ehci_pci_init(void)
  376. {
  377. if (usb_disabled())
  378. return -ENODEV;
  379. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  380. ehci_init_driver(&ehci_pci_hc_driver, &pci_overrides);
  381. /* Entries for the PCI suspend/resume callbacks are special */
  382. ehci_pci_hc_driver.pci_suspend = ehci_suspend;
  383. ehci_pci_hc_driver.pci_resume = ehci_pci_resume;
  384. return pci_register_driver(&ehci_pci_driver);
  385. }
  386. module_init(ehci_pci_init);
  387. static void __exit ehci_pci_cleanup(void)
  388. {
  389. pci_unregister_driver(&ehci_pci_driver);
  390. }
  391. module_exit(ehci_pci_cleanup);
  392. MODULE_DESCRIPTION(DRIVER_DESC);
  393. MODULE_AUTHOR("David Brownell");
  394. MODULE_AUTHOR("Alan Stern");
  395. MODULE_LICENSE("GPL");