ehci-pci.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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. switch (pdev->vendor) {
  49. case PCI_VENDOR_ID_TOSHIBA_2:
  50. /* celleb's companion chip */
  51. if (pdev->device == 0x01b5) {
  52. #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
  53. ehci->big_endian_mmio = 1;
  54. #else
  55. ehci_warn(ehci,
  56. "unsupported big endian Toshiba quirk\n");
  57. #endif
  58. }
  59. break;
  60. }
  61. ehci->caps = hcd->regs;
  62. ehci->regs = hcd->regs +
  63. HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  64. dbg_hcs_params(ehci, "reset");
  65. dbg_hcc_params(ehci, "reset");
  66. /* ehci_init() causes memory for DMA transfers to be
  67. * allocated. Thus, any vendor-specific workarounds based on
  68. * limiting the type of memory used for DMA transfers must
  69. * happen before ehci_init() is called. */
  70. switch (pdev->vendor) {
  71. case PCI_VENDOR_ID_NVIDIA:
  72. /* NVidia reports that certain chips don't handle
  73. * QH, ITD, or SITD addresses above 2GB. (But TD,
  74. * data buffer, and periodic schedule are normal.)
  75. */
  76. switch (pdev->device) {
  77. case 0x003c: /* MCP04 */
  78. case 0x005b: /* CK804 */
  79. case 0x00d8: /* CK8 */
  80. case 0x00e8: /* CK8S */
  81. if (pci_set_consistent_dma_mask(pdev,
  82. DMA_BIT_MASK(31)) < 0)
  83. ehci_warn(ehci, "can't enable NVidia "
  84. "workaround for >2GB RAM\n");
  85. break;
  86. }
  87. break;
  88. }
  89. /* cache this readonly data; minimize chip reads */
  90. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  91. retval = ehci_halt(ehci);
  92. if (retval)
  93. return retval;
  94. if ((pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x7808) ||
  95. (pdev->vendor == PCI_VENDOR_ID_ATI && pdev->device == 0x4396)) {
  96. /* EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
  97. * read/write memory space which does not belong to it when
  98. * there is NULL pointer with T-bit set to 1 in the frame list
  99. * table. To avoid the issue, the frame list link pointer
  100. * should always contain a valid pointer to a inactive qh.
  101. */
  102. ehci->use_dummy_qh = 1;
  103. ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI "
  104. "dummy qh workaround\n");
  105. }
  106. /* data structure init */
  107. retval = ehci_init(hcd);
  108. if (retval)
  109. return retval;
  110. switch (pdev->vendor) {
  111. case PCI_VENDOR_ID_NEC:
  112. ehci->need_io_watchdog = 0;
  113. break;
  114. case PCI_VENDOR_ID_INTEL:
  115. ehci->need_io_watchdog = 0;
  116. ehci->fs_i_thresh = 1;
  117. if (pdev->device == 0x27cc) {
  118. ehci->broken_periodic = 1;
  119. ehci_info(ehci, "using broken periodic workaround\n");
  120. }
  121. if (pdev->device == 0x0806 || pdev->device == 0x0811
  122. || pdev->device == 0x0829) {
  123. ehci_info(ehci, "disable lpm for langwell/penwell\n");
  124. ehci->has_lpm = 0;
  125. }
  126. if (pdev->device == PCI_DEVICE_ID_INTEL_CE4100_USB) {
  127. hcd->has_tt = 1;
  128. tdi_reset(ehci);
  129. }
  130. break;
  131. case PCI_VENDOR_ID_TDI:
  132. if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) {
  133. hcd->has_tt = 1;
  134. tdi_reset(ehci);
  135. }
  136. break;
  137. case PCI_VENDOR_ID_AMD:
  138. /* AMD PLL quirk */
  139. if (usb_amd_find_chipset_info())
  140. ehci->amd_pll_fix = 1;
  141. /* AMD8111 EHCI doesn't work, according to AMD errata */
  142. if (pdev->device == 0x7463) {
  143. ehci_info(ehci, "ignoring AMD8111 (errata)\n");
  144. retval = -EIO;
  145. goto done;
  146. }
  147. break;
  148. case PCI_VENDOR_ID_NVIDIA:
  149. switch (pdev->device) {
  150. /* Some NForce2 chips have problems with selective suspend;
  151. * fixed in newer silicon.
  152. */
  153. case 0x0068:
  154. if (pdev->revision < 0xa4)
  155. ehci->no_selective_suspend = 1;
  156. break;
  157. /* MCP89 chips on the MacBookAir3,1 give EPROTO when
  158. * fetching device descriptors unless LPM is disabled.
  159. * There are also intermittent problems enumerating
  160. * devices with PPCD enabled.
  161. */
  162. case 0x0d9d:
  163. ehci_info(ehci, "disable lpm/ppcd for nvidia mcp89");
  164. ehci->has_lpm = 0;
  165. ehci->has_ppcd = 0;
  166. ehci->command &= ~CMD_PPCEE;
  167. break;
  168. }
  169. break;
  170. case PCI_VENDOR_ID_VIA:
  171. if (pdev->device == 0x3104 && (pdev->revision & 0xf0) == 0x60) {
  172. u8 tmp;
  173. /* The VT6212 defaults to a 1 usec EHCI sleep time which
  174. * hogs the PCI bus *badly*. Setting bit 5 of 0x4B makes
  175. * that sleep time use the conventional 10 usec.
  176. */
  177. pci_read_config_byte(pdev, 0x4b, &tmp);
  178. if (tmp & 0x20)
  179. break;
  180. pci_write_config_byte(pdev, 0x4b, tmp | 0x20);
  181. }
  182. break;
  183. case PCI_VENDOR_ID_ATI:
  184. /* AMD PLL quirk */
  185. if (usb_amd_find_chipset_info())
  186. ehci->amd_pll_fix = 1;
  187. /* SB600 and old version of SB700 have a bug in EHCI controller,
  188. * which causes usb devices lose response in some cases.
  189. */
  190. if ((pdev->device == 0x4386) || (pdev->device == 0x4396)) {
  191. p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
  192. PCI_DEVICE_ID_ATI_SBX00_SMBUS,
  193. NULL);
  194. if (!p_smbus)
  195. break;
  196. rev = p_smbus->revision;
  197. if ((pdev->device == 0x4386) || (rev == 0x3a)
  198. || (rev == 0x3b)) {
  199. u8 tmp;
  200. ehci_info(ehci, "applying AMD SB600/SB700 USB "
  201. "freeze workaround\n");
  202. pci_read_config_byte(pdev, 0x53, &tmp);
  203. pci_write_config_byte(pdev, 0x53, tmp | (1<<3));
  204. }
  205. pci_dev_put(p_smbus);
  206. }
  207. break;
  208. case PCI_VENDOR_ID_NETMOS:
  209. /* MosChip frame-index-register bug */
  210. ehci_info(ehci, "applying MosChip frame-index workaround\n");
  211. ehci->frame_index_bug = 1;
  212. break;
  213. }
  214. /* optional debug port, normally in the first BAR */
  215. temp = pci_find_capability(pdev, 0x0a);
  216. if (temp) {
  217. pci_read_config_dword(pdev, temp, &temp);
  218. temp >>= 16;
  219. if ((temp & (3 << 13)) == (1 << 13)) {
  220. temp &= 0x1fff;
  221. ehci->debug = ehci_to_hcd(ehci)->regs + temp;
  222. temp = ehci_readl(ehci, &ehci->debug->control);
  223. ehci_info(ehci, "debug port %d%s\n",
  224. HCS_DEBUG_PORT(ehci->hcs_params),
  225. (temp & DBGP_ENABLED)
  226. ? " IN USE"
  227. : "");
  228. if (!(temp & DBGP_ENABLED))
  229. ehci->debug = NULL;
  230. }
  231. }
  232. ehci_reset(ehci);
  233. /* at least the Genesys GL880S needs fixup here */
  234. temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params);
  235. temp &= 0x0f;
  236. if (temp && HCS_N_PORTS(ehci->hcs_params) > temp) {
  237. ehci_dbg(ehci, "bogus port configuration: "
  238. "cc=%d x pcc=%d < ports=%d\n",
  239. HCS_N_CC(ehci->hcs_params),
  240. HCS_N_PCC(ehci->hcs_params),
  241. HCS_N_PORTS(ehci->hcs_params));
  242. switch (pdev->vendor) {
  243. case 0x17a0: /* GENESYS */
  244. /* GL880S: should be PORTS=2 */
  245. temp |= (ehci->hcs_params & ~0xf);
  246. ehci->hcs_params = temp;
  247. break;
  248. case PCI_VENDOR_ID_NVIDIA:
  249. /* NF4: should be PCC=10 */
  250. break;
  251. }
  252. }
  253. /* Serial Bus Release Number is at PCI 0x60 offset */
  254. pci_read_config_byte(pdev, 0x60, &ehci->sbrn);
  255. /* Keep this around for a while just in case some EHCI
  256. * implementation uses legacy PCI PM support. This test
  257. * can be removed on 17 Dec 2009 if the dev_warn() hasn't
  258. * been triggered by then.
  259. */
  260. if (!device_can_wakeup(&pdev->dev)) {
  261. u16 port_wake;
  262. pci_read_config_word(pdev, 0x62, &port_wake);
  263. if (port_wake & 0x0001) {
  264. dev_warn(&pdev->dev, "Enabling legacy PCI PM\n");
  265. device_set_wakeup_capable(&pdev->dev, 1);
  266. }
  267. }
  268. #ifdef CONFIG_USB_SUSPEND
  269. /* REVISIT: the controller works fine for wakeup iff the root hub
  270. * itself is "globally" suspended, but usbcore currently doesn't
  271. * understand such things.
  272. *
  273. * System suspend currently expects to be able to suspend the entire
  274. * device tree, device-at-a-time. If we failed selective suspend
  275. * reports, system suspend would fail; so the root hub code must claim
  276. * success. That's lying to usbcore, and it matters for runtime
  277. * PM scenarios with selective suspend and remote wakeup...
  278. */
  279. if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev))
  280. ehci_warn(ehci, "selective suspend/wakeup unavailable\n");
  281. #endif
  282. ehci_port_power(ehci, 1);
  283. retval = ehci_pci_reinit(ehci, pdev);
  284. done:
  285. return retval;
  286. }
  287. /*-------------------------------------------------------------------------*/
  288. #ifdef CONFIG_PM
  289. /* suspend/resume, section 4.3 */
  290. /* These routines rely on the PCI bus glue
  291. * to handle powerdown and wakeup, and currently also on
  292. * transceivers that don't need any software attention to set up
  293. * the right sort of wakeup.
  294. * Also they depend on separate root hub suspend/resume.
  295. */
  296. static int ehci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
  297. {
  298. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  299. unsigned long flags;
  300. int rc = 0;
  301. if (time_before(jiffies, ehci->next_statechange))
  302. msleep(10);
  303. /* Root hub was already suspended. Disable irq emission and
  304. * mark HW unaccessible. The PM and USB cores make sure that
  305. * the root hub is either suspended or stopped.
  306. */
  307. ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup);
  308. spin_lock_irqsave (&ehci->lock, flags);
  309. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  310. (void)ehci_readl(ehci, &ehci->regs->intr_enable);
  311. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  312. spin_unlock_irqrestore (&ehci->lock, flags);
  313. // could save FLADJ in case of Vaux power loss
  314. // ... we'd only use it to handle clock skew
  315. return rc;
  316. }
  317. static bool usb_is_intel_switchable_ehci(struct pci_dev *pdev)
  318. {
  319. return pdev->class == PCI_CLASS_SERIAL_USB_EHCI &&
  320. pdev->vendor == PCI_VENDOR_ID_INTEL &&
  321. pdev->device == 0x1E26;
  322. }
  323. static void ehci_enable_xhci_companion(void)
  324. {
  325. struct pci_dev *companion = NULL;
  326. /* The xHCI and EHCI controllers are not on the same PCI slot */
  327. for_each_pci_dev(companion) {
  328. if (!usb_is_intel_switchable_xhci(companion))
  329. continue;
  330. usb_enable_xhci_ports(companion);
  331. return;
  332. }
  333. }
  334. static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
  335. {
  336. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  337. struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
  338. /* The BIOS on systems with the Intel Panther Point chipset may or may
  339. * not support xHCI natively. That means that during system resume, it
  340. * may switch the ports back to EHCI so that users can use their
  341. * keyboard to select a kernel from GRUB after resume from hibernate.
  342. *
  343. * The BIOS is supposed to remember whether the OS had xHCI ports
  344. * enabled before resume, and switch the ports back to xHCI when the
  345. * BIOS/OS semaphore is written, but we all know we can't trust BIOS
  346. * writers.
  347. *
  348. * Unconditionally switch the ports back to xHCI after a system resume.
  349. * We can't tell whether the EHCI or xHCI controller will be resumed
  350. * first, so we have to do the port switchover in both drivers. Writing
  351. * a '1' to the port switchover registers should have no effect if the
  352. * port was already switched over.
  353. */
  354. if (usb_is_intel_switchable_ehci(pdev))
  355. ehci_enable_xhci_companion();
  356. // maybe restore FLADJ
  357. if (time_before(jiffies, ehci->next_statechange))
  358. msleep(100);
  359. /* Mark hardware accessible again as we are out of D3 state by now */
  360. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  361. /* If CF is still set and we aren't resuming from hibernation
  362. * then we maintained PCI Vaux power.
  363. * Just undo the effect of ehci_pci_suspend().
  364. */
  365. if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF &&
  366. !hibernated) {
  367. int mask = INTR_MASK;
  368. ehci_prepare_ports_for_controller_resume(ehci);
  369. if (!hcd->self.root_hub->do_remote_wakeup)
  370. mask &= ~STS_PCD;
  371. ehci_writel(ehci, mask, &ehci->regs->intr_enable);
  372. ehci_readl(ehci, &ehci->regs->intr_enable);
  373. return 0;
  374. }
  375. usb_root_hub_lost_power(hcd->self.root_hub);
  376. /* Else reset, to cope with power loss or flush-to-storage
  377. * style "resume" having let BIOS kick in during reboot.
  378. */
  379. (void) ehci_halt(ehci);
  380. (void) ehci_reset(ehci);
  381. (void) ehci_pci_reinit(ehci, pdev);
  382. /* emptying the schedule aborts any urbs */
  383. spin_lock_irq(&ehci->lock);
  384. if (ehci->reclaim)
  385. end_unlink_async(ehci);
  386. ehci_work(ehci);
  387. spin_unlock_irq(&ehci->lock);
  388. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  389. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  390. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  391. /* here we "know" root ports should always stay powered */
  392. ehci_port_power(ehci, 1);
  393. ehci->rh_state = EHCI_RH_SUSPENDED;
  394. return 0;
  395. }
  396. #endif
  397. static int ehci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
  398. {
  399. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  400. int rc = 0;
  401. if (!udev->parent) /* udev is root hub itself, impossible */
  402. rc = -1;
  403. /* we only support lpm device connected to root hub yet */
  404. if (ehci->has_lpm && !udev->parent->parent) {
  405. rc = ehci_lpm_set_da(ehci, udev->devnum, udev->portnum);
  406. if (!rc)
  407. rc = ehci_lpm_check(ehci, udev->portnum);
  408. }
  409. return rc;
  410. }
  411. static const struct hc_driver ehci_pci_hc_driver = {
  412. .description = hcd_name,
  413. .product_desc = "EHCI Host Controller",
  414. .hcd_priv_size = sizeof(struct ehci_hcd),
  415. /*
  416. * generic hardware linkage
  417. */
  418. .irq = ehci_irq,
  419. .flags = HCD_MEMORY | HCD_USB2,
  420. /*
  421. * basic lifecycle operations
  422. */
  423. .reset = ehci_pci_setup,
  424. .start = ehci_run,
  425. #ifdef CONFIG_PM
  426. .pci_suspend = ehci_pci_suspend,
  427. .pci_resume = ehci_pci_resume,
  428. #endif
  429. .stop = ehci_stop,
  430. .shutdown = ehci_shutdown,
  431. /*
  432. * managing i/o requests and associated device resources
  433. */
  434. .urb_enqueue = ehci_urb_enqueue,
  435. .urb_dequeue = ehci_urb_dequeue,
  436. .endpoint_disable = ehci_endpoint_disable,
  437. .endpoint_reset = ehci_endpoint_reset,
  438. /*
  439. * scheduling support
  440. */
  441. .get_frame_number = ehci_get_frame,
  442. /*
  443. * root hub support
  444. */
  445. .hub_status_data = ehci_hub_status_data,
  446. .hub_control = ehci_hub_control,
  447. .bus_suspend = ehci_bus_suspend,
  448. .bus_resume = ehci_bus_resume,
  449. .relinquish_port = ehci_relinquish_port,
  450. .port_handed_over = ehci_port_handed_over,
  451. /*
  452. * call back when device connected and addressed
  453. */
  454. .update_device = ehci_update_device,
  455. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  456. };
  457. /*-------------------------------------------------------------------------*/
  458. /* PCI driver selection metadata; PCI hotplugging uses this */
  459. static const struct pci_device_id pci_ids [] = { {
  460. /* handle any USB 2.0 EHCI controller */
  461. PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0),
  462. .driver_data = (unsigned long) &ehci_pci_hc_driver,
  463. },
  464. { /* end: all zeroes */ }
  465. };
  466. MODULE_DEVICE_TABLE(pci, pci_ids);
  467. /* pci driver glue; this is a "new style" PCI driver module */
  468. static struct pci_driver ehci_pci_driver = {
  469. .name = (char *) hcd_name,
  470. .id_table = pci_ids,
  471. .probe = usb_hcd_pci_probe,
  472. .remove = usb_hcd_pci_remove,
  473. .shutdown = usb_hcd_pci_shutdown,
  474. #ifdef CONFIG_PM_SLEEP
  475. .driver = {
  476. .pm = &usb_hcd_pci_pm_ops
  477. },
  478. #endif
  479. };