ehci-pci.c 15 KB

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