ehci-pci.c 11 KB

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