ehci-pci.c 15 KB

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