ehci-pci.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. u32 temp;
  51. int retval;
  52. ehci->caps = hcd->regs;
  53. /*
  54. * ehci_init() causes memory for DMA transfers to be
  55. * allocated. Thus, any vendor-specific workarounds based on
  56. * limiting the type of memory used for DMA transfers must
  57. * happen before ehci_setup() is called.
  58. *
  59. * Most other workarounds can be done either before or after
  60. * init and reset; they are located here too.
  61. */
  62. switch (pdev->vendor) {
  63. case PCI_VENDOR_ID_TOSHIBA_2:
  64. /* celleb's companion chip */
  65. if (pdev->device == 0x01b5) {
  66. #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
  67. ehci->big_endian_mmio = 1;
  68. #else
  69. ehci_warn(ehci,
  70. "unsupported big endian Toshiba quirk\n");
  71. #endif
  72. }
  73. break;
  74. case PCI_VENDOR_ID_NVIDIA:
  75. /* NVidia reports that certain chips don't handle
  76. * QH, ITD, or SITD addresses above 2GB. (But TD,
  77. * data buffer, and periodic schedule are normal.)
  78. */
  79. switch (pdev->device) {
  80. case 0x003c: /* MCP04 */
  81. case 0x005b: /* CK804 */
  82. case 0x00d8: /* CK8 */
  83. case 0x00e8: /* CK8S */
  84. if (pci_set_consistent_dma_mask(pdev,
  85. DMA_BIT_MASK(31)) < 0)
  86. ehci_warn(ehci, "can't enable NVidia "
  87. "workaround for >2GB RAM\n");
  88. break;
  89. /* Some NForce2 chips have problems with selective suspend;
  90. * fixed in newer silicon.
  91. */
  92. case 0x0068:
  93. if (pdev->revision < 0xa4)
  94. ehci->no_selective_suspend = 1;
  95. break;
  96. }
  97. break;
  98. case PCI_VENDOR_ID_INTEL:
  99. if (pdev->device == PCI_DEVICE_ID_INTEL_CE4100_USB)
  100. hcd->has_tt = 1;
  101. break;
  102. case PCI_VENDOR_ID_TDI:
  103. if (pdev->device == PCI_DEVICE_ID_TDI_EHCI)
  104. hcd->has_tt = 1;
  105. break;
  106. case PCI_VENDOR_ID_AMD:
  107. /* AMD PLL quirk */
  108. if (usb_amd_find_chipset_info())
  109. ehci->amd_pll_fix = 1;
  110. /* AMD8111 EHCI doesn't work, according to AMD errata */
  111. if (pdev->device == 0x7463) {
  112. ehci_info(ehci, "ignoring AMD8111 (errata)\n");
  113. retval = -EIO;
  114. goto done;
  115. }
  116. /*
  117. * EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
  118. * read/write memory space which does not belong to it when
  119. * there is NULL pointer with T-bit set to 1 in the frame list
  120. * table. To avoid the issue, the frame list link pointer
  121. * should always contain a valid pointer to a inactive qh.
  122. */
  123. if (pdev->device == 0x7808) {
  124. ehci->use_dummy_qh = 1;
  125. ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI dummy qh workaround\n");
  126. }
  127. break;
  128. case PCI_VENDOR_ID_VIA:
  129. if (pdev->device == 0x3104 && (pdev->revision & 0xf0) == 0x60) {
  130. u8 tmp;
  131. /* The VT6212 defaults to a 1 usec EHCI sleep time which
  132. * hogs the PCI bus *badly*. Setting bit 5 of 0x4B makes
  133. * that sleep time use the conventional 10 usec.
  134. */
  135. pci_read_config_byte(pdev, 0x4b, &tmp);
  136. if (tmp & 0x20)
  137. break;
  138. pci_write_config_byte(pdev, 0x4b, tmp | 0x20);
  139. }
  140. break;
  141. case PCI_VENDOR_ID_ATI:
  142. /* AMD PLL quirk */
  143. if (usb_amd_find_chipset_info())
  144. ehci->amd_pll_fix = 1;
  145. /*
  146. * EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
  147. * read/write memory space which does not belong to it when
  148. * there is NULL pointer with T-bit set to 1 in the frame list
  149. * table. To avoid the issue, the frame list link pointer
  150. * should always contain a valid pointer to a inactive qh.
  151. */
  152. if (pdev->device == 0x4396) {
  153. ehci->use_dummy_qh = 1;
  154. ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI dummy qh workaround\n");
  155. }
  156. /* SB600 and old version of SB700 have a bug in EHCI controller,
  157. * which causes usb devices lose response in some cases.
  158. */
  159. if ((pdev->device == 0x4386 || pdev->device == 0x4396) &&
  160. usb_amd_hang_symptom_quirk()) {
  161. u8 tmp;
  162. ehci_info(ehci, "applying AMD SB600/SB700 USB freeze workaround\n");
  163. pci_read_config_byte(pdev, 0x53, &tmp);
  164. pci_write_config_byte(pdev, 0x53, tmp | (1<<3));
  165. }
  166. break;
  167. case PCI_VENDOR_ID_NETMOS:
  168. /* MosChip frame-index-register bug */
  169. ehci_info(ehci, "applying MosChip frame-index workaround\n");
  170. ehci->frame_index_bug = 1;
  171. break;
  172. }
  173. /* optional debug port, normally in the first BAR */
  174. temp = pci_find_capability(pdev, PCI_CAP_ID_DBG);
  175. if (temp) {
  176. pci_read_config_dword(pdev, temp, &temp);
  177. temp >>= 16;
  178. if (((temp >> 13) & 7) == 1) {
  179. u32 hcs_params = ehci_readl(ehci,
  180. &ehci->caps->hcs_params);
  181. temp &= 0x1fff;
  182. ehci->debug = hcd->regs + temp;
  183. temp = ehci_readl(ehci, &ehci->debug->control);
  184. ehci_info(ehci, "debug port %d%s\n",
  185. HCS_DEBUG_PORT(hcs_params),
  186. (temp & DBGP_ENABLED) ? " IN USE" : "");
  187. if (!(temp & DBGP_ENABLED))
  188. ehci->debug = NULL;
  189. }
  190. }
  191. retval = ehci_setup(hcd);
  192. if (retval)
  193. return retval;
  194. /* These workarounds need to be applied after ehci_setup() */
  195. switch (pdev->vendor) {
  196. case PCI_VENDOR_ID_NEC:
  197. ehci->need_io_watchdog = 0;
  198. break;
  199. case PCI_VENDOR_ID_INTEL:
  200. ehci->need_io_watchdog = 0;
  201. break;
  202. case PCI_VENDOR_ID_NVIDIA:
  203. switch (pdev->device) {
  204. /* MCP89 chips on the MacBookAir3,1 give EPROTO when
  205. * fetching device descriptors unless LPM is disabled.
  206. * There are also intermittent problems enumerating
  207. * devices with PPCD enabled.
  208. */
  209. case 0x0d9d:
  210. ehci_info(ehci, "disable ppcd for nvidia mcp89\n");
  211. ehci->has_ppcd = 0;
  212. ehci->command &= ~CMD_PPCEE;
  213. break;
  214. }
  215. break;
  216. }
  217. /* at least the Genesys GL880S needs fixup here */
  218. temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params);
  219. temp &= 0x0f;
  220. if (temp && HCS_N_PORTS(ehci->hcs_params) > temp) {
  221. ehci_dbg(ehci, "bogus port configuration: "
  222. "cc=%d x pcc=%d < ports=%d\n",
  223. HCS_N_CC(ehci->hcs_params),
  224. HCS_N_PCC(ehci->hcs_params),
  225. HCS_N_PORTS(ehci->hcs_params));
  226. switch (pdev->vendor) {
  227. case 0x17a0: /* GENESYS */
  228. /* GL880S: should be PORTS=2 */
  229. temp |= (ehci->hcs_params & ~0xf);
  230. ehci->hcs_params = temp;
  231. break;
  232. case PCI_VENDOR_ID_NVIDIA:
  233. /* NF4: should be PCC=10 */
  234. break;
  235. }
  236. }
  237. /* Serial Bus Release Number is at PCI 0x60 offset */
  238. if (pdev->vendor == PCI_VENDOR_ID_STMICRO
  239. && pdev->device == PCI_DEVICE_ID_STMICRO_USB_HOST)
  240. ; /* ConneXT has no sbrn register */
  241. else
  242. pci_read_config_byte(pdev, 0x60, &ehci->sbrn);
  243. /* Keep this around for a while just in case some EHCI
  244. * implementation uses legacy PCI PM support. This test
  245. * can be removed on 17 Dec 2009 if the dev_warn() hasn't
  246. * been triggered by then.
  247. */
  248. if (!device_can_wakeup(&pdev->dev)) {
  249. u16 port_wake;
  250. pci_read_config_word(pdev, 0x62, &port_wake);
  251. if (port_wake & 0x0001) {
  252. dev_warn(&pdev->dev, "Enabling legacy PCI PM\n");
  253. device_set_wakeup_capable(&pdev->dev, 1);
  254. }
  255. }
  256. #ifdef CONFIG_PM_RUNTIME
  257. if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev))
  258. ehci_warn(ehci, "selective suspend/wakeup unavailable\n");
  259. #endif
  260. retval = ehci_pci_reinit(ehci, pdev);
  261. done:
  262. return retval;
  263. }
  264. /*-------------------------------------------------------------------------*/
  265. #ifdef CONFIG_PM
  266. /* suspend/resume, section 4.3 */
  267. /* These routines rely on the PCI bus glue
  268. * to handle powerdown and wakeup, and currently also on
  269. * transceivers that don't need any software attention to set up
  270. * the right sort of wakeup.
  271. * Also they depend on separate root hub suspend/resume.
  272. */
  273. static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
  274. {
  275. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  276. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  277. if (ehci_resume(hcd, hibernated) != 0)
  278. (void) ehci_pci_reinit(ehci, pdev);
  279. return 0;
  280. }
  281. #else
  282. #define ehci_suspend NULL
  283. #define ehci_pci_resume NULL
  284. #endif /* CONFIG_PM */
  285. static struct hc_driver __read_mostly ehci_pci_hc_driver;
  286. static const struct ehci_driver_overrides pci_overrides __initconst = {
  287. .reset = ehci_pci_setup,
  288. };
  289. /*-------------------------------------------------------------------------*/
  290. /* PCI driver selection metadata; PCI hotplugging uses this */
  291. static const struct pci_device_id pci_ids [] = { {
  292. /* handle any USB 2.0 EHCI controller */
  293. PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0),
  294. .driver_data = (unsigned long) &ehci_pci_hc_driver,
  295. }, {
  296. PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_USB_HOST),
  297. .driver_data = (unsigned long) &ehci_pci_hc_driver,
  298. },
  299. { /* end: all zeroes */ }
  300. };
  301. MODULE_DEVICE_TABLE(pci, pci_ids);
  302. /* pci driver glue; this is a "new style" PCI driver module */
  303. static struct pci_driver ehci_pci_driver = {
  304. .name = (char *) hcd_name,
  305. .id_table = pci_ids,
  306. .probe = usb_hcd_pci_probe,
  307. .remove = usb_hcd_pci_remove,
  308. .shutdown = usb_hcd_pci_shutdown,
  309. #ifdef CONFIG_PM
  310. .driver = {
  311. .pm = &usb_hcd_pci_pm_ops
  312. },
  313. #endif
  314. };
  315. static int __init ehci_pci_init(void)
  316. {
  317. if (usb_disabled())
  318. return -ENODEV;
  319. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  320. ehci_init_driver(&ehci_pci_hc_driver, &pci_overrides);
  321. /* Entries for the PCI suspend/resume callbacks are special */
  322. ehci_pci_hc_driver.pci_suspend = ehci_suspend;
  323. ehci_pci_hc_driver.pci_resume = ehci_pci_resume;
  324. return pci_register_driver(&ehci_pci_driver);
  325. }
  326. module_init(ehci_pci_init);
  327. static void __exit ehci_pci_cleanup(void)
  328. {
  329. pci_unregister_driver(&ehci_pci_driver);
  330. }
  331. module_exit(ehci_pci_cleanup);
  332. MODULE_DESCRIPTION(DRIVER_DESC);
  333. MODULE_AUTHOR("David Brownell");
  334. MODULE_AUTHOR("Alan Stern");
  335. MODULE_LICENSE("GPL");