ehci-pci.c 13 KB

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