ehci-pci.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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_quirk_pll_check())
  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_quirk_pll_check())
  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. case PCI_VENDOR_ID_HUAWEI:
  198. /* Synopsys HC bug */
  199. if (pdev->device == 0xa239) {
  200. ehci_info(ehci, "applying Synopsys HC workaround\n");
  201. ehci->has_synopsys_hc_bug = 1;
  202. }
  203. break;
  204. }
  205. /* optional debug port, normally in the first BAR */
  206. temp = pci_find_capability(pdev, PCI_CAP_ID_DBG);
  207. if (temp) {
  208. pci_read_config_dword(pdev, temp, &temp);
  209. temp >>= 16;
  210. if (((temp >> 13) & 7) == 1) {
  211. u32 hcs_params = ehci_readl(ehci,
  212. &ehci->caps->hcs_params);
  213. temp &= 0x1fff;
  214. ehci->debug = hcd->regs + temp;
  215. temp = ehci_readl(ehci, &ehci->debug->control);
  216. ehci_info(ehci, "debug port %d%s\n",
  217. HCS_DEBUG_PORT(hcs_params),
  218. (temp & DBGP_ENABLED) ? " IN USE" : "");
  219. if (!(temp & DBGP_ENABLED))
  220. ehci->debug = NULL;
  221. }
  222. }
  223. retval = ehci_setup(hcd);
  224. if (retval)
  225. return retval;
  226. /* These workarounds need to be applied after ehci_setup() */
  227. switch (pdev->vendor) {
  228. case PCI_VENDOR_ID_NEC:
  229. case PCI_VENDOR_ID_INTEL:
  230. case PCI_VENDOR_ID_AMD:
  231. ehci->need_io_watchdog = 0;
  232. break;
  233. case PCI_VENDOR_ID_NVIDIA:
  234. switch (pdev->device) {
  235. /* MCP89 chips on the MacBookAir3,1 give EPROTO when
  236. * fetching device descriptors unless LPM is disabled.
  237. * There are also intermittent problems enumerating
  238. * devices with PPCD enabled.
  239. */
  240. case 0x0d9d:
  241. ehci_info(ehci, "disable ppcd for nvidia mcp89\n");
  242. ehci->has_ppcd = 0;
  243. ehci->command &= ~CMD_PPCEE;
  244. break;
  245. }
  246. break;
  247. }
  248. /* at least the Genesys GL880S needs fixup here */
  249. temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params);
  250. temp &= 0x0f;
  251. if (temp && HCS_N_PORTS(ehci->hcs_params) > temp) {
  252. ehci_dbg(ehci, "bogus port configuration: "
  253. "cc=%d x pcc=%d < ports=%d\n",
  254. HCS_N_CC(ehci->hcs_params),
  255. HCS_N_PCC(ehci->hcs_params),
  256. HCS_N_PORTS(ehci->hcs_params));
  257. switch (pdev->vendor) {
  258. case 0x17a0: /* GENESYS */
  259. /* GL880S: should be PORTS=2 */
  260. temp |= (ehci->hcs_params & ~0xf);
  261. ehci->hcs_params = temp;
  262. break;
  263. case PCI_VENDOR_ID_NVIDIA:
  264. /* NF4: should be PCC=10 */
  265. break;
  266. }
  267. }
  268. /* Serial Bus Release Number is at PCI 0x60 offset */
  269. if (pdev->vendor == PCI_VENDOR_ID_STMICRO
  270. && pdev->device == PCI_DEVICE_ID_STMICRO_USB_HOST)
  271. ; /* ConneXT has no sbrn register */
  272. else if (pdev->vendor == PCI_VENDOR_ID_HUAWEI
  273. && pdev->device == 0xa239)
  274. ; /* HUAWEI Kunpeng920 USB EHCI has no sbrn register */
  275. else
  276. pci_read_config_byte(pdev, 0x60, &ehci->sbrn);
  277. /* Keep this around for a while just in case some EHCI
  278. * implementation uses legacy PCI PM support. This test
  279. * can be removed on 17 Dec 2009 if the dev_warn() hasn't
  280. * been triggered by then.
  281. */
  282. if (!device_can_wakeup(&pdev->dev)) {
  283. u16 port_wake;
  284. pci_read_config_word(pdev, 0x62, &port_wake);
  285. if (port_wake & 0x0001) {
  286. dev_warn(&pdev->dev, "Enabling legacy PCI PM\n");
  287. device_set_wakeup_capable(&pdev->dev, 1);
  288. }
  289. }
  290. #ifdef CONFIG_PM
  291. if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev))
  292. ehci_warn(ehci, "selective suspend/wakeup unavailable\n");
  293. #endif
  294. retval = ehci_pci_reinit(ehci, pdev);
  295. done:
  296. return retval;
  297. }
  298. /*-------------------------------------------------------------------------*/
  299. #ifdef CONFIG_PM
  300. /* suspend/resume, section 4.3 */
  301. /* These routines rely on the PCI bus glue
  302. * to handle powerdown and wakeup, and currently also on
  303. * transceivers that don't need any software attention to set up
  304. * the right sort of wakeup.
  305. * Also they depend on separate root hub suspend/resume.
  306. */
  307. static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
  308. {
  309. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  310. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  311. if (ehci_resume(hcd, hibernated) != 0)
  312. (void) ehci_pci_reinit(ehci, pdev);
  313. return 0;
  314. }
  315. #else
  316. #define ehci_suspend NULL
  317. #define ehci_pci_resume NULL
  318. #endif /* CONFIG_PM */
  319. static struct hc_driver __read_mostly ehci_pci_hc_driver;
  320. static const struct ehci_driver_overrides pci_overrides __initconst = {
  321. .reset = ehci_pci_setup,
  322. };
  323. /*-------------------------------------------------------------------------*/
  324. static int ehci_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  325. {
  326. if (is_bypassed_id(pdev))
  327. return -ENODEV;
  328. return usb_hcd_pci_probe(pdev, id);
  329. }
  330. static void ehci_pci_remove(struct pci_dev *pdev)
  331. {
  332. pci_clear_mwi(pdev);
  333. usb_hcd_pci_remove(pdev);
  334. }
  335. /* PCI driver selection metadata; PCI hotplugging uses this */
  336. static const struct pci_device_id pci_ids [] = { {
  337. /* handle any USB 2.0 EHCI controller */
  338. PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0),
  339. .driver_data = (unsigned long) &ehci_pci_hc_driver,
  340. }, {
  341. PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_USB_HOST),
  342. .driver_data = (unsigned long) &ehci_pci_hc_driver,
  343. },
  344. { /* end: all zeroes */ }
  345. };
  346. MODULE_DEVICE_TABLE(pci, pci_ids);
  347. /* pci driver glue; this is a "new style" PCI driver module */
  348. static struct pci_driver ehci_pci_driver = {
  349. .name = (char *) hcd_name,
  350. .id_table = pci_ids,
  351. .probe = ehci_pci_probe,
  352. .remove = ehci_pci_remove,
  353. .shutdown = usb_hcd_pci_shutdown,
  354. #ifdef CONFIG_PM
  355. .driver = {
  356. .pm = &usb_hcd_pci_pm_ops
  357. },
  358. #endif
  359. };
  360. static int __init ehci_pci_init(void)
  361. {
  362. if (usb_disabled())
  363. return -ENODEV;
  364. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  365. ehci_init_driver(&ehci_pci_hc_driver, &pci_overrides);
  366. /* Entries for the PCI suspend/resume callbacks are special */
  367. ehci_pci_hc_driver.pci_suspend = ehci_suspend;
  368. ehci_pci_hc_driver.pci_resume = ehci_pci_resume;
  369. return pci_register_driver(&ehci_pci_driver);
  370. }
  371. module_init(ehci_pci_init);
  372. static void __exit ehci_pci_cleanup(void)
  373. {
  374. pci_unregister_driver(&ehci_pci_driver);
  375. }
  376. module_exit(ehci_pci_cleanup);
  377. MODULE_DESCRIPTION(DRIVER_DESC);
  378. MODULE_AUTHOR("David Brownell");
  379. MODULE_AUTHOR("Alan Stern");
  380. MODULE_LICENSE("GPL");