ehci-pci.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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_PM_RUNTIME
  269. if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev))
  270. ehci_warn(ehci, "selective suspend/wakeup unavailable\n");
  271. #endif
  272. retval = ehci_pci_reinit(ehci, pdev);
  273. done:
  274. return retval;
  275. }
  276. /*-------------------------------------------------------------------------*/
  277. #ifdef CONFIG_PM
  278. /* suspend/resume, section 4.3 */
  279. /* These routines rely on the PCI bus glue
  280. * to handle powerdown and wakeup, and currently also on
  281. * transceivers that don't need any software attention to set up
  282. * the right sort of wakeup.
  283. * Also they depend on separate root hub suspend/resume.
  284. */
  285. static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
  286. {
  287. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  288. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  289. if (ehci_resume(hcd, hibernated) != 0)
  290. (void) ehci_pci_reinit(ehci, pdev);
  291. return 0;
  292. }
  293. #else
  294. #define ehci_suspend NULL
  295. #define ehci_pci_resume NULL
  296. #endif /* CONFIG_PM */
  297. static struct hc_driver __read_mostly ehci_pci_hc_driver;
  298. static const struct ehci_driver_overrides pci_overrides __initconst = {
  299. .reset = ehci_pci_setup,
  300. };
  301. /*-------------------------------------------------------------------------*/
  302. /* PCI driver selection metadata; PCI hotplugging uses this */
  303. static const struct pci_device_id pci_ids [] = { {
  304. /* handle any USB 2.0 EHCI controller */
  305. PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0),
  306. .driver_data = (unsigned long) &ehci_pci_hc_driver,
  307. }, {
  308. PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_USB_HOST),
  309. .driver_data = (unsigned long) &ehci_pci_hc_driver,
  310. },
  311. { /* end: all zeroes */ }
  312. };
  313. MODULE_DEVICE_TABLE(pci, pci_ids);
  314. /* pci driver glue; this is a "new style" PCI driver module */
  315. static struct pci_driver ehci_pci_driver = {
  316. .name = (char *) hcd_name,
  317. .id_table = pci_ids,
  318. .probe = usb_hcd_pci_probe,
  319. .remove = usb_hcd_pci_remove,
  320. .shutdown = usb_hcd_pci_shutdown,
  321. #ifdef CONFIG_PM_SLEEP
  322. .driver = {
  323. .pm = &usb_hcd_pci_pm_ops
  324. },
  325. #endif
  326. };
  327. static int __init ehci_pci_init(void)
  328. {
  329. if (usb_disabled())
  330. return -ENODEV;
  331. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  332. ehci_init_driver(&ehci_pci_hc_driver, &pci_overrides);
  333. /* Entries for the PCI suspend/resume callbacks are special */
  334. ehci_pci_hc_driver.pci_suspend = ehci_suspend;
  335. ehci_pci_hc_driver.pci_resume = ehci_pci_resume;
  336. return pci_register_driver(&ehci_pci_driver);
  337. }
  338. module_init(ehci_pci_init);
  339. static void __exit ehci_pci_cleanup(void)
  340. {
  341. pci_unregister_driver(&ehci_pci_driver);
  342. }
  343. module_exit(ehci_pci_cleanup);
  344. MODULE_DESCRIPTION(DRIVER_DESC);
  345. MODULE_AUTHOR("David Brownell");
  346. MODULE_AUTHOR("Alan Stern");
  347. MODULE_LICENSE("GPL");