ehci-pci.c 12 KB

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