ehci-pci.c 12 KB

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