uhci-pci.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * UHCI HCD (Host Controller Driver) PCI Bus Glue.
  3. *
  4. * Extracted from uhci-hcd.c:
  5. * Maintainer: Alan Stern <stern@rowland.harvard.edu>
  6. *
  7. * (C) Copyright 1999 Linus Torvalds
  8. * (C) Copyright 1999-2002 Johannes Erdfelt, johannes@erdfelt.com
  9. * (C) Copyright 1999 Randy Dunlap
  10. * (C) Copyright 1999 Georg Acher, acher@in.tum.de
  11. * (C) Copyright 1999 Deti Fliegl, deti@fliegl.de
  12. * (C) Copyright 1999 Thomas Sailer, sailer@ife.ee.ethz.ch
  13. * (C) Copyright 1999 Roman Weissgaerber, weissg@vienna.at
  14. * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface
  15. * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com).
  16. * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c)
  17. * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu
  18. */
  19. #include "pci-quirks.h"
  20. /*
  21. * Make sure the controller is completely inactive, unable to
  22. * generate interrupts or do DMA.
  23. */
  24. static void uhci_pci_reset_hc(struct uhci_hcd *uhci)
  25. {
  26. uhci_reset_hc(to_pci_dev(uhci_dev(uhci)), uhci->io_addr);
  27. }
  28. /*
  29. * Initialize a controller that was newly discovered or has just been
  30. * resumed. In either case we can't be sure of its previous state.
  31. *
  32. * Returns: 1 if the controller was reset, 0 otherwise.
  33. */
  34. static int uhci_pci_check_and_reset_hc(struct uhci_hcd *uhci)
  35. {
  36. return uhci_check_and_reset_hc(to_pci_dev(uhci_dev(uhci)),
  37. uhci->io_addr);
  38. }
  39. /*
  40. * Store the basic register settings needed by the controller.
  41. * This function is called at the end of configure_hc in uhci-hcd.c.
  42. */
  43. static void uhci_pci_configure_hc(struct uhci_hcd *uhci)
  44. {
  45. struct pci_dev *pdev = to_pci_dev(uhci_dev(uhci));
  46. /* Enable PIRQ */
  47. pci_write_config_word(pdev, USBLEGSUP, USBLEGSUP_DEFAULT);
  48. /* Disable platform-specific non-PME# wakeup */
  49. if (pdev->vendor == PCI_VENDOR_ID_INTEL)
  50. pci_write_config_byte(pdev, USBRES_INTEL, 0);
  51. }
  52. static int uhci_pci_resume_detect_interrupts_are_broken(struct uhci_hcd *uhci)
  53. {
  54. int port;
  55. switch (to_pci_dev(uhci_dev(uhci))->vendor) {
  56. default:
  57. break;
  58. case PCI_VENDOR_ID_GENESYS:
  59. /* Genesys Logic's GL880S controllers don't generate
  60. * resume-detect interrupts.
  61. */
  62. return 1;
  63. case PCI_VENDOR_ID_INTEL:
  64. /* Some of Intel's USB controllers have a bug that causes
  65. * resume-detect interrupts if any port has an over-current
  66. * condition. To make matters worse, some motherboards
  67. * hardwire unused USB ports' over-current inputs active!
  68. * To prevent problems, we will not enable resume-detect
  69. * interrupts if any ports are OC.
  70. */
  71. for (port = 0; port < uhci->rh_numports; ++port) {
  72. if (inw(uhci->io_addr + USBPORTSC1 + port * 2) &
  73. USBPORTSC_OC)
  74. return 1;
  75. }
  76. break;
  77. }
  78. return 0;
  79. }
  80. static int uhci_pci_global_suspend_mode_is_broken(struct uhci_hcd *uhci)
  81. {
  82. int port;
  83. const char *sys_info;
  84. static const char bad_Asus_board[] = "A7V8X";
  85. /* One of Asus's motherboards has a bug which causes it to
  86. * wake up immediately from suspend-to-RAM if any of the ports
  87. * are connected. In such cases we will not set EGSM.
  88. */
  89. sys_info = dmi_get_system_info(DMI_BOARD_NAME);
  90. if (sys_info && !strcmp(sys_info, bad_Asus_board)) {
  91. for (port = 0; port < uhci->rh_numports; ++port) {
  92. if (inw(uhci->io_addr + USBPORTSC1 + port * 2) &
  93. USBPORTSC_CCS)
  94. return 1;
  95. }
  96. }
  97. return 0;
  98. }
  99. static int uhci_pci_init(struct usb_hcd *hcd)
  100. {
  101. struct uhci_hcd *uhci = hcd_to_uhci(hcd);
  102. uhci->io_addr = (unsigned long) hcd->rsrc_start;
  103. uhci->rh_numports = uhci_count_ports(hcd);
  104. /* Intel controllers report the OverCurrent bit active on.
  105. * VIA controllers report it active off, so we'll adjust the
  106. * bit value. (It's not standardized in the UHCI spec.)
  107. */
  108. if (to_pci_dev(uhci_dev(uhci))->vendor == PCI_VENDOR_ID_VIA)
  109. uhci->oc_low = 1;
  110. /* HP's server management chip requires a longer port reset delay. */
  111. if (to_pci_dev(uhci_dev(uhci))->vendor == PCI_VENDOR_ID_HP)
  112. uhci->wait_for_hp = 1;
  113. /* Set up pointers to PCI-specific functions */
  114. uhci->reset_hc = uhci_pci_reset_hc;
  115. uhci->check_and_reset_hc = uhci_pci_check_and_reset_hc;
  116. uhci->configure_hc = uhci_pci_configure_hc;
  117. uhci->resume_detect_interrupts_are_broken =
  118. uhci_pci_resume_detect_interrupts_are_broken;
  119. uhci->global_suspend_mode_is_broken =
  120. uhci_pci_global_suspend_mode_is_broken;
  121. /* Kick BIOS off this hardware and reset if the controller
  122. * isn't already safely quiescent.
  123. */
  124. check_and_reset_hc(uhci);
  125. return 0;
  126. }
  127. /* Make sure the controller is quiescent and that we're not using it
  128. * any more. This is mainly for the benefit of programs which, like kexec,
  129. * expect the hardware to be idle: not doing DMA or generating IRQs.
  130. *
  131. * This routine may be called in a damaged or failing kernel. Hence we
  132. * do not acquire the spinlock before shutting down the controller.
  133. */
  134. static void uhci_shutdown(struct pci_dev *pdev)
  135. {
  136. struct usb_hcd *hcd = pci_get_drvdata(pdev);
  137. uhci_hc_died(hcd_to_uhci(hcd));
  138. }
  139. #ifdef CONFIG_PM
  140. static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
  141. {
  142. struct uhci_hcd *uhci = hcd_to_uhci(hcd);
  143. struct pci_dev *pdev = to_pci_dev(uhci_dev(uhci));
  144. int rc = 0;
  145. dev_dbg(uhci_dev(uhci), "%s\n", __func__);
  146. spin_lock_irq(&uhci->lock);
  147. if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead)
  148. goto done_okay; /* Already suspended or dead */
  149. if (uhci->rh_state > UHCI_RH_SUSPENDED) {
  150. dev_warn(uhci_dev(uhci), "Root hub isn't suspended!\n");
  151. rc = -EBUSY;
  152. goto done;
  153. };
  154. /* All PCI host controllers are required to disable IRQ generation
  155. * at the source, so we must turn off PIRQ.
  156. */
  157. pci_write_config_word(pdev, USBLEGSUP, 0);
  158. clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
  159. /* Enable platform-specific non-PME# wakeup */
  160. if (do_wakeup) {
  161. if (pdev->vendor == PCI_VENDOR_ID_INTEL)
  162. pci_write_config_byte(pdev, USBRES_INTEL,
  163. USBPORT1EN | USBPORT2EN);
  164. }
  165. done_okay:
  166. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  167. done:
  168. spin_unlock_irq(&uhci->lock);
  169. return rc;
  170. }
  171. static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
  172. {
  173. struct uhci_hcd *uhci = hcd_to_uhci(hcd);
  174. dev_dbg(uhci_dev(uhci), "%s\n", __func__);
  175. /* Since we aren't in D3 any more, it's safe to set this flag
  176. * even if the controller was dead.
  177. */
  178. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  179. spin_lock_irq(&uhci->lock);
  180. /* Make sure resume from hibernation re-enumerates everything */
  181. if (hibernated) {
  182. uhci->reset_hc(uhci);
  183. finish_reset(uhci);
  184. }
  185. /* The firmware may have changed the controller settings during
  186. * a system wakeup. Check it and reconfigure to avoid problems.
  187. */
  188. else {
  189. check_and_reset_hc(uhci);
  190. }
  191. configure_hc(uhci);
  192. /* Tell the core if the controller had to be reset */
  193. if (uhci->rh_state == UHCI_RH_RESET)
  194. usb_root_hub_lost_power(hcd->self.root_hub);
  195. spin_unlock_irq(&uhci->lock);
  196. /* If interrupts don't work and remote wakeup is enabled then
  197. * the suspended root hub needs to be polled.
  198. */
  199. if (!uhci->RD_enable && hcd->self.root_hub->do_remote_wakeup)
  200. set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
  201. /* Does the root hub have a port wakeup pending? */
  202. usb_hcd_poll_rh_status(hcd);
  203. return 0;
  204. }
  205. #endif
  206. static const struct hc_driver uhci_driver = {
  207. .description = hcd_name,
  208. .product_desc = "UHCI Host Controller",
  209. .hcd_priv_size = sizeof(struct uhci_hcd),
  210. /* Generic hardware linkage */
  211. .irq = uhci_irq,
  212. .flags = HCD_USB11,
  213. /* Basic lifecycle operations */
  214. .reset = uhci_pci_init,
  215. .start = uhci_start,
  216. #ifdef CONFIG_PM
  217. .pci_suspend = uhci_pci_suspend,
  218. .pci_resume = uhci_pci_resume,
  219. .bus_suspend = uhci_rh_suspend,
  220. .bus_resume = uhci_rh_resume,
  221. #endif
  222. .stop = uhci_stop,
  223. .urb_enqueue = uhci_urb_enqueue,
  224. .urb_dequeue = uhci_urb_dequeue,
  225. .endpoint_disable = uhci_hcd_endpoint_disable,
  226. .get_frame_number = uhci_hcd_get_frame_number,
  227. .hub_status_data = uhci_hub_status_data,
  228. .hub_control = uhci_hub_control,
  229. };
  230. static DEFINE_PCI_DEVICE_TABLE(uhci_pci_ids) = { {
  231. /* handle any USB UHCI controller */
  232. PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_UHCI, ~0),
  233. .driver_data = (unsigned long) &uhci_driver,
  234. }, { /* end: all zeroes */ }
  235. };
  236. MODULE_DEVICE_TABLE(pci, uhci_pci_ids);
  237. static struct pci_driver uhci_pci_driver = {
  238. .name = (char *)hcd_name,
  239. .id_table = uhci_pci_ids,
  240. .probe = usb_hcd_pci_probe,
  241. .remove = usb_hcd_pci_remove,
  242. .shutdown = uhci_shutdown,
  243. #ifdef CONFIG_PM_SLEEP
  244. .driver = {
  245. .pm = &usb_hcd_pci_pm_ops
  246. },
  247. #endif
  248. };