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