ehci-pci.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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. #ifndef CONFIG_PCI
  21. #error "This file is PCI bus glue. CONFIG_PCI must be defined."
  22. #endif
  23. /* defined here to avoid adding to pci_ids.h for single instance use */
  24. #define PCI_DEVICE_ID_INTEL_CE4100_USB 0x2e70
  25. /*-------------------------------------------------------------------------*/
  26. /* called after powerup, by probe or system-pm "wakeup" */
  27. static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev)
  28. {
  29. int retval;
  30. /* we expect static quirk code to handle the "extended capabilities"
  31. * (currently just BIOS handoff) allowed starting with EHCI 0.96
  32. */
  33. /* PCI Memory-Write-Invalidate cycle support is optional (uncommon) */
  34. retval = pci_set_mwi(pdev);
  35. if (!retval)
  36. ehci_dbg(ehci, "MWI active\n");
  37. return 0;
  38. }
  39. /* called during probe() after chip reset completes */
  40. static int ehci_pci_setup(struct usb_hcd *hcd)
  41. {
  42. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  43. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  44. struct pci_dev *p_smbus;
  45. u8 rev;
  46. u32 temp;
  47. int retval;
  48. ehci->caps = hcd->regs;
  49. /*
  50. * ehci_init() causes memory for DMA transfers to be
  51. * allocated. Thus, any vendor-specific workarounds based on
  52. * limiting the type of memory used for DMA transfers must
  53. * happen before ehci_setup() is called.
  54. *
  55. * Most other workarounds can be done either before or after
  56. * init and reset; they are located here too.
  57. */
  58. switch (pdev->vendor) {
  59. case PCI_VENDOR_ID_TOSHIBA_2:
  60. /* celleb's companion chip */
  61. if (pdev->device == 0x01b5) {
  62. #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
  63. ehci->big_endian_mmio = 1;
  64. #else
  65. ehci_warn(ehci,
  66. "unsupported big endian Toshiba quirk\n");
  67. #endif
  68. }
  69. break;
  70. case PCI_VENDOR_ID_NVIDIA:
  71. /* NVidia reports that certain chips don't handle
  72. * QH, ITD, or SITD addresses above 2GB. (But TD,
  73. * data buffer, and periodic schedule are normal.)
  74. */
  75. switch (pdev->device) {
  76. case 0x003c: /* MCP04 */
  77. case 0x005b: /* CK804 */
  78. case 0x00d8: /* CK8 */
  79. case 0x00e8: /* CK8S */
  80. if (pci_set_consistent_dma_mask(pdev,
  81. DMA_BIT_MASK(31)) < 0)
  82. ehci_warn(ehci, "can't enable NVidia "
  83. "workaround for >2GB RAM\n");
  84. break;
  85. /* Some NForce2 chips have problems with selective suspend;
  86. * fixed in newer silicon.
  87. */
  88. case 0x0068:
  89. if (pdev->revision < 0xa4)
  90. ehci->no_selective_suspend = 1;
  91. break;
  92. }
  93. break;
  94. case PCI_VENDOR_ID_INTEL:
  95. ehci->fs_i_thresh = 1;
  96. if (pdev->device == PCI_DEVICE_ID_INTEL_CE4100_USB)
  97. hcd->has_tt = 1;
  98. break;
  99. case PCI_VENDOR_ID_TDI:
  100. if (pdev->device == PCI_DEVICE_ID_TDI_EHCI)
  101. hcd->has_tt = 1;
  102. break;
  103. case PCI_VENDOR_ID_AMD:
  104. /* AMD PLL quirk */
  105. if (usb_amd_find_chipset_info())
  106. ehci->amd_pll_fix = 1;
  107. /* AMD8111 EHCI doesn't work, according to AMD errata */
  108. if (pdev->device == 0x7463) {
  109. ehci_info(ehci, "ignoring AMD8111 (errata)\n");
  110. retval = -EIO;
  111. goto done;
  112. }
  113. /*
  114. * EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
  115. * read/write memory space which does not belong to it when
  116. * there is NULL pointer with T-bit set to 1 in the frame list
  117. * table. To avoid the issue, the frame list link pointer
  118. * should always contain a valid pointer to a inactive qh.
  119. */
  120. if (pdev->device == 0x7808) {
  121. ehci->use_dummy_qh = 1;
  122. ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI dummy qh workaround\n");
  123. }
  124. break;
  125. case PCI_VENDOR_ID_VIA:
  126. if (pdev->device == 0x3104 && (pdev->revision & 0xf0) == 0x60) {
  127. u8 tmp;
  128. /* The VT6212 defaults to a 1 usec EHCI sleep time which
  129. * hogs the PCI bus *badly*. Setting bit 5 of 0x4B makes
  130. * that sleep time use the conventional 10 usec.
  131. */
  132. pci_read_config_byte(pdev, 0x4b, &tmp);
  133. if (tmp & 0x20)
  134. break;
  135. pci_write_config_byte(pdev, 0x4b, tmp | 0x20);
  136. }
  137. break;
  138. case PCI_VENDOR_ID_ATI:
  139. /* AMD PLL quirk */
  140. if (usb_amd_find_chipset_info())
  141. ehci->amd_pll_fix = 1;
  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 == 0x4396) {
  150. ehci->use_dummy_qh = 1;
  151. ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI dummy qh workaround\n");
  152. }
  153. /* SB600 and old version of SB700 have a bug in EHCI controller,
  154. * which causes usb devices lose response in some cases.
  155. */
  156. if ((pdev->device == 0x4386) || (pdev->device == 0x4396)) {
  157. p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
  158. PCI_DEVICE_ID_ATI_SBX00_SMBUS,
  159. NULL);
  160. if (!p_smbus)
  161. break;
  162. rev = p_smbus->revision;
  163. if ((pdev->device == 0x4386) || (rev == 0x3a)
  164. || (rev == 0x3b)) {
  165. u8 tmp;
  166. ehci_info(ehci, "applying AMD SB600/SB700 USB "
  167. "freeze workaround\n");
  168. pci_read_config_byte(pdev, 0x53, &tmp);
  169. pci_write_config_byte(pdev, 0x53, tmp | (1<<3));
  170. }
  171. pci_dev_put(p_smbus);
  172. }
  173. break;
  174. case PCI_VENDOR_ID_NETMOS:
  175. /* MosChip frame-index-register bug */
  176. ehci_info(ehci, "applying MosChip frame-index workaround\n");
  177. ehci->frame_index_bug = 1;
  178. break;
  179. }
  180. retval = ehci_setup(hcd);
  181. if (retval)
  182. return retval;
  183. /* These workarounds need to be applied after ehci_setup() */
  184. switch (pdev->vendor) {
  185. case PCI_VENDOR_ID_NEC:
  186. ehci->need_io_watchdog = 0;
  187. break;
  188. case PCI_VENDOR_ID_INTEL:
  189. ehci->need_io_watchdog = 0;
  190. if (pdev->device == 0x0806 || pdev->device == 0x0811
  191. || pdev->device == 0x0829) {
  192. ehci_info(ehci, "disable lpm for langwell/penwell\n");
  193. ehci->has_lpm = 0;
  194. }
  195. break;
  196. case PCI_VENDOR_ID_NVIDIA:
  197. switch (pdev->device) {
  198. /* MCP89 chips on the MacBookAir3,1 give EPROTO when
  199. * fetching device descriptors unless LPM is disabled.
  200. * There are also intermittent problems enumerating
  201. * devices with PPCD enabled.
  202. */
  203. case 0x0d9d:
  204. ehci_info(ehci, "disable lpm/ppcd for nvidia mcp89");
  205. ehci->has_lpm = 0;
  206. ehci->has_ppcd = 0;
  207. ehci->command &= ~CMD_PPCEE;
  208. break;
  209. }
  210. break;
  211. }
  212. /* optional debug port, normally in the first BAR */
  213. temp = pci_find_capability(pdev, 0x0a);
  214. if (temp) {
  215. pci_read_config_dword(pdev, temp, &temp);
  216. temp >>= 16;
  217. if ((temp & (3 << 13)) == (1 << 13)) {
  218. temp &= 0x1fff;
  219. ehci->debug = hcd->regs + temp;
  220. temp = ehci_readl(ehci, &ehci->debug->control);
  221. ehci_info(ehci, "debug port %d%s\n",
  222. HCS_DEBUG_PORT(ehci->hcs_params),
  223. (temp & DBGP_ENABLED)
  224. ? " IN USE"
  225. : "");
  226. if (!(temp & DBGP_ENABLED))
  227. ehci->debug = NULL;
  228. }
  229. }
  230. /* at least the Genesys GL880S needs fixup here */
  231. temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params);
  232. temp &= 0x0f;
  233. if (temp && HCS_N_PORTS(ehci->hcs_params) > temp) {
  234. ehci_dbg(ehci, "bogus port configuration: "
  235. "cc=%d x pcc=%d < ports=%d\n",
  236. HCS_N_CC(ehci->hcs_params),
  237. HCS_N_PCC(ehci->hcs_params),
  238. HCS_N_PORTS(ehci->hcs_params));
  239. switch (pdev->vendor) {
  240. case 0x17a0: /* GENESYS */
  241. /* GL880S: should be PORTS=2 */
  242. temp |= (ehci->hcs_params & ~0xf);
  243. ehci->hcs_params = temp;
  244. break;
  245. case PCI_VENDOR_ID_NVIDIA:
  246. /* NF4: should be PCC=10 */
  247. break;
  248. }
  249. }
  250. /* Serial Bus Release Number is at PCI 0x60 offset */
  251. if (pdev->vendor == PCI_VENDOR_ID_STMICRO
  252. && pdev->device == PCI_DEVICE_ID_STMICRO_USB_HOST)
  253. ; /* ConneXT has no sbrn register */
  254. else
  255. pci_read_config_byte(pdev, 0x60, &ehci->sbrn);
  256. /* Keep this around for a while just in case some EHCI
  257. * implementation uses legacy PCI PM support. This test
  258. * can be removed on 17 Dec 2009 if the dev_warn() hasn't
  259. * been triggered by then.
  260. */
  261. if (!device_can_wakeup(&pdev->dev)) {
  262. u16 port_wake;
  263. pci_read_config_word(pdev, 0x62, &port_wake);
  264. if (port_wake & 0x0001) {
  265. dev_warn(&pdev->dev, "Enabling legacy PCI PM\n");
  266. device_set_wakeup_capable(&pdev->dev, 1);
  267. }
  268. }
  269. #ifdef CONFIG_USB_SUSPEND
  270. /* REVISIT: the controller works fine for wakeup iff the root hub
  271. * itself is "globally" suspended, but usbcore currently doesn't
  272. * understand such things.
  273. *
  274. * System suspend currently expects to be able to suspend the entire
  275. * device tree, device-at-a-time. If we failed selective suspend
  276. * reports, system suspend would fail; so the root hub code must claim
  277. * success. That's lying to usbcore, and it matters for runtime
  278. * PM scenarios with selective suspend and remote wakeup...
  279. */
  280. if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev))
  281. ehci_warn(ehci, "selective suspend/wakeup unavailable\n");
  282. #endif
  283. ehci_port_power(ehci, 1);
  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_suspend(struct usb_hcd *hcd, bool do_wakeup)
  298. {
  299. return ehci_suspend(hcd, do_wakeup);
  300. }
  301. static bool usb_is_intel_switchable_ehci(struct pci_dev *pdev)
  302. {
  303. return pdev->class == PCI_CLASS_SERIAL_USB_EHCI &&
  304. pdev->vendor == PCI_VENDOR_ID_INTEL &&
  305. (pdev->device == 0x1E26 ||
  306. pdev->device == 0x8C2D ||
  307. pdev->device == 0x8C26);
  308. }
  309. static void ehci_enable_xhci_companion(void)
  310. {
  311. struct pci_dev *companion = NULL;
  312. /* The xHCI and EHCI controllers are not on the same PCI slot */
  313. for_each_pci_dev(companion) {
  314. if (!usb_is_intel_switchable_xhci(companion))
  315. continue;
  316. usb_enable_xhci_ports(companion);
  317. return;
  318. }
  319. }
  320. static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
  321. {
  322. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  323. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  324. /* The BIOS on systems with the Intel Panther Point chipset may or may
  325. * not support xHCI natively. That means that during system resume, it
  326. * may switch the ports back to EHCI so that users can use their
  327. * keyboard to select a kernel from GRUB after resume from hibernate.
  328. *
  329. * The BIOS is supposed to remember whether the OS had xHCI ports
  330. * enabled before resume, and switch the ports back to xHCI when the
  331. * BIOS/OS semaphore is written, but we all know we can't trust BIOS
  332. * writers.
  333. *
  334. * Unconditionally switch the ports back to xHCI after a system resume.
  335. * We can't tell whether the EHCI or xHCI controller will be resumed
  336. * first, so we have to do the port switchover in both drivers. Writing
  337. * a '1' to the port switchover registers should have no effect if the
  338. * port was already switched over.
  339. */
  340. if (usb_is_intel_switchable_ehci(pdev))
  341. ehci_enable_xhci_companion();
  342. if (ehci_resume(hcd, hibernated) != 0)
  343. (void) ehci_pci_reinit(ehci, pdev);
  344. return 0;
  345. }
  346. #endif
  347. static int ehci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
  348. {
  349. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  350. int rc = 0;
  351. if (!udev->parent) /* udev is root hub itself, impossible */
  352. rc = -1;
  353. /* we only support lpm device connected to root hub yet */
  354. if (ehci->has_lpm && !udev->parent->parent) {
  355. rc = ehci_lpm_set_da(ehci, udev->devnum, udev->portnum);
  356. if (!rc)
  357. rc = ehci_lpm_check(ehci, udev->portnum);
  358. }
  359. return rc;
  360. }
  361. static const struct hc_driver ehci_pci_hc_driver = {
  362. .description = hcd_name,
  363. .product_desc = "EHCI Host Controller",
  364. .hcd_priv_size = sizeof(struct ehci_hcd),
  365. /*
  366. * generic hardware linkage
  367. */
  368. .irq = ehci_irq,
  369. .flags = HCD_MEMORY | HCD_USB2,
  370. /*
  371. * basic lifecycle operations
  372. */
  373. .reset = ehci_pci_setup,
  374. .start = ehci_run,
  375. #ifdef CONFIG_PM
  376. .pci_suspend = ehci_pci_suspend,
  377. .pci_resume = ehci_pci_resume,
  378. #endif
  379. .stop = ehci_stop,
  380. .shutdown = ehci_shutdown,
  381. /*
  382. * managing i/o requests and associated device resources
  383. */
  384. .urb_enqueue = ehci_urb_enqueue,
  385. .urb_dequeue = ehci_urb_dequeue,
  386. .endpoint_disable = ehci_endpoint_disable,
  387. .endpoint_reset = ehci_endpoint_reset,
  388. /*
  389. * scheduling support
  390. */
  391. .get_frame_number = ehci_get_frame,
  392. /*
  393. * root hub support
  394. */
  395. .hub_status_data = ehci_hub_status_data,
  396. .hub_control = ehci_hub_control,
  397. .bus_suspend = ehci_bus_suspend,
  398. .bus_resume = ehci_bus_resume,
  399. .relinquish_port = ehci_relinquish_port,
  400. .port_handed_over = ehci_port_handed_over,
  401. /*
  402. * call back when device connected and addressed
  403. */
  404. .update_device = ehci_update_device,
  405. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  406. };
  407. /*-------------------------------------------------------------------------*/
  408. /* PCI driver selection metadata; PCI hotplugging uses this */
  409. static const struct pci_device_id pci_ids [] = { {
  410. /* handle any USB 2.0 EHCI controller */
  411. PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0),
  412. .driver_data = (unsigned long) &ehci_pci_hc_driver,
  413. }, {
  414. PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_USB_HOST),
  415. .driver_data = (unsigned long) &ehci_pci_hc_driver,
  416. },
  417. { /* end: all zeroes */ }
  418. };
  419. MODULE_DEVICE_TABLE(pci, pci_ids);
  420. /* pci driver glue; this is a "new style" PCI driver module */
  421. static struct pci_driver ehci_pci_driver = {
  422. .name = (char *) hcd_name,
  423. .id_table = pci_ids,
  424. .probe = usb_hcd_pci_probe,
  425. .remove = usb_hcd_pci_remove,
  426. .shutdown = usb_hcd_pci_shutdown,
  427. #ifdef CONFIG_PM_SLEEP
  428. .driver = {
  429. .pm = &usb_hcd_pci_pm_ops
  430. },
  431. #endif
  432. };