ehci-pci.c 16 KB

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