ehci-pci.c 13 KB

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