ehci-pci.c 12 KB

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