ehci-pci.c 12 KB

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