ehci-pci.c 12 KB

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