1 // SPDX-License-Identifier: GPL-2.0
3 * UHCI HCD (Host Controller Driver) PCI Bus Glue.
5 * Extracted from uhci-hcd.c:
6 * Maintainer: Alan Stern <stern@rowland.harvard.edu>
8 * (C) Copyright 1999 Linus Torvalds
9 * (C) Copyright 1999-2002 Johannes Erdfelt, johannes@erdfelt.com
10 * (C) Copyright 1999 Randy Dunlap
11 * (C) Copyright 1999 Georg Acher, acher@in.tum.de
12 * (C) Copyright 1999 Deti Fliegl, deti@fliegl.de
13 * (C) Copyright 1999 Thomas Sailer, sailer@ife.ee.ethz.ch
14 * (C) Copyright 1999 Roman Weissgaerber, weissg@vienna.at
15 * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface
16 * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com).
17 * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c)
18 * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu
21 #include "pci-quirks.h"
24 * Make sure the controller is completely inactive, unable to
25 * generate interrupts or do DMA.
27 static void uhci_pci_reset_hc(struct uhci_hcd
*uhci
)
29 uhci_reset_hc(to_pci_dev(uhci_dev(uhci
)), uhci
->io_addr
);
33 * Initialize a controller that was newly discovered or has just been
34 * resumed. In either case we can't be sure of its previous state.
36 * Returns: 1 if the controller was reset, 0 otherwise.
38 static int uhci_pci_check_and_reset_hc(struct uhci_hcd
*uhci
)
40 return uhci_check_and_reset_hc(to_pci_dev(uhci_dev(uhci
)),
45 * Store the basic register settings needed by the controller.
46 * This function is called at the end of configure_hc in uhci-hcd.c.
48 static void uhci_pci_configure_hc(struct uhci_hcd
*uhci
)
50 struct pci_dev
*pdev
= to_pci_dev(uhci_dev(uhci
));
53 pci_write_config_word(pdev
, USBLEGSUP
, USBLEGSUP_DEFAULT
);
55 /* Disable platform-specific non-PME# wakeup */
56 if (pdev
->vendor
== PCI_VENDOR_ID_INTEL
)
57 pci_write_config_byte(pdev
, USBRES_INTEL
, 0);
60 static int uhci_pci_resume_detect_interrupts_are_broken(struct uhci_hcd
*uhci
)
64 switch (to_pci_dev(uhci_dev(uhci
))->vendor
) {
68 case PCI_VENDOR_ID_GENESYS
:
69 /* Genesys Logic's GL880S controllers don't generate
70 * resume-detect interrupts.
74 case PCI_VENDOR_ID_INTEL
:
75 /* Some of Intel's USB controllers have a bug that causes
76 * resume-detect interrupts if any port has an over-current
77 * condition. To make matters worse, some motherboards
78 * hardwire unused USB ports' over-current inputs active!
79 * To prevent problems, we will not enable resume-detect
80 * interrupts if any ports are OC.
82 for (port
= 0; port
< uhci
->rh_numports
; ++port
) {
83 if (inw(uhci
->io_addr
+ USBPORTSC1
+ port
* 2) &
92 static int uhci_pci_global_suspend_mode_is_broken(struct uhci_hcd
*uhci
)
96 static const char bad_Asus_board
[] = "A7V8X";
98 /* One of Asus's motherboards has a bug which causes it to
99 * wake up immediately from suspend-to-RAM if any of the ports
100 * are connected. In such cases we will not set EGSM.
102 sys_info
= dmi_get_system_info(DMI_BOARD_NAME
);
103 if (sys_info
&& !strcmp(sys_info
, bad_Asus_board
)) {
104 for (port
= 0; port
< uhci
->rh_numports
; ++port
) {
105 if (inw(uhci
->io_addr
+ USBPORTSC1
+ port
* 2) &
114 static int uhci_pci_init(struct usb_hcd
*hcd
)
116 struct uhci_hcd
*uhci
= hcd_to_uhci(hcd
);
118 uhci
->io_addr
= (unsigned long) hcd
->rsrc_start
;
120 uhci
->rh_numports
= uhci_count_ports(hcd
);
122 /* Intel controllers report the OverCurrent bit active on.
123 * VIA controllers report it active off, so we'll adjust the
124 * bit value. (It's not standardized in the UHCI spec.)
126 if (to_pci_dev(uhci_dev(uhci
))->vendor
== PCI_VENDOR_ID_VIA
)
129 /* HP's server management chip requires a longer port reset delay. */
130 if (to_pci_dev(uhci_dev(uhci
))->vendor
== PCI_VENDOR_ID_HP
)
131 uhci
->wait_for_hp
= 1;
133 /* Intel controllers use non-PME wakeup signalling */
134 if (to_pci_dev(uhci_dev(uhci
))->vendor
== PCI_VENDOR_ID_INTEL
)
135 device_set_wakeup_capable(uhci_dev(uhci
), true);
137 /* Set up pointers to PCI-specific functions */
138 uhci
->reset_hc
= uhci_pci_reset_hc
;
139 uhci
->check_and_reset_hc
= uhci_pci_check_and_reset_hc
;
140 uhci
->configure_hc
= uhci_pci_configure_hc
;
141 uhci
->resume_detect_interrupts_are_broken
=
142 uhci_pci_resume_detect_interrupts_are_broken
;
143 uhci
->global_suspend_mode_is_broken
=
144 uhci_pci_global_suspend_mode_is_broken
;
147 /* Kick BIOS off this hardware and reset if the controller
148 * isn't already safely quiescent.
150 check_and_reset_hc(uhci
);
154 /* Make sure the controller is quiescent and that we're not using it
155 * any more. This is mainly for the benefit of programs which, like kexec,
156 * expect the hardware to be idle: not doing DMA or generating IRQs.
158 * This routine may be called in a damaged or failing kernel. Hence we
159 * do not acquire the spinlock before shutting down the controller.
161 static void uhci_shutdown(struct pci_dev
*pdev
)
163 struct usb_hcd
*hcd
= pci_get_drvdata(pdev
);
165 uhci_hc_died(hcd_to_uhci(hcd
));
170 static int uhci_pci_resume(struct usb_hcd
*hcd
, bool hibernated
);
172 static int uhci_pci_suspend(struct usb_hcd
*hcd
, bool do_wakeup
)
174 struct uhci_hcd
*uhci
= hcd_to_uhci(hcd
);
175 struct pci_dev
*pdev
= to_pci_dev(uhci_dev(uhci
));
178 dev_dbg(uhci_dev(uhci
), "%s\n", __func__
);
180 spin_lock_irq(&uhci
->lock
);
181 if (!HCD_HW_ACCESSIBLE(hcd
) || uhci
->dead
)
182 goto done_okay
; /* Already suspended or dead */
184 /* All PCI host controllers are required to disable IRQ generation
185 * at the source, so we must turn off PIRQ.
187 pci_write_config_word(pdev
, USBLEGSUP
, 0);
188 clear_bit(HCD_FLAG_POLL_RH
, &hcd
->flags
);
190 /* Enable platform-specific non-PME# wakeup */
192 if (pdev
->vendor
== PCI_VENDOR_ID_INTEL
)
193 pci_write_config_byte(pdev
, USBRES_INTEL
,
194 USBPORT1EN
| USBPORT2EN
);
198 clear_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
);
199 spin_unlock_irq(&uhci
->lock
);
201 synchronize_irq(hcd
->irq
);
203 /* Check for race with a wakeup request */
204 if (do_wakeup
&& HCD_WAKEUP_PENDING(hcd
)) {
205 uhci_pci_resume(hcd
, false);
211 static int uhci_pci_resume(struct usb_hcd
*hcd
, bool hibernated
)
213 struct uhci_hcd
*uhci
= hcd_to_uhci(hcd
);
215 dev_dbg(uhci_dev(uhci
), "%s\n", __func__
);
217 /* Since we aren't in D3 any more, it's safe to set this flag
218 * even if the controller was dead.
220 set_bit(HCD_FLAG_HW_ACCESSIBLE
, &hcd
->flags
);
222 spin_lock_irq(&uhci
->lock
);
224 /* Make sure resume from hibernation re-enumerates everything */
226 uhci
->reset_hc(uhci
);
230 /* The firmware may have changed the controller settings during
231 * a system wakeup. Check it and reconfigure to avoid problems.
234 check_and_reset_hc(uhci
);
238 /* Tell the core if the controller had to be reset */
239 if (uhci
->rh_state
== UHCI_RH_RESET
)
240 usb_root_hub_lost_power(hcd
->self
.root_hub
);
242 spin_unlock_irq(&uhci
->lock
);
244 /* If interrupts don't work and remote wakeup is enabled then
245 * the suspended root hub needs to be polled.
247 if (!uhci
->RD_enable
&& hcd
->self
.root_hub
->do_remote_wakeup
)
248 set_bit(HCD_FLAG_POLL_RH
, &hcd
->flags
);
250 /* Does the root hub have a port wakeup pending? */
251 usb_hcd_poll_rh_status(hcd
);
257 static const struct hc_driver uhci_driver
= {
258 .description
= hcd_name
,
259 .product_desc
= "UHCI Host Controller",
260 .hcd_priv_size
= sizeof(struct uhci_hcd
),
262 /* Generic hardware linkage */
266 /* Basic lifecycle operations */
267 .reset
= uhci_pci_init
,
270 .pci_suspend
= uhci_pci_suspend
,
271 .pci_resume
= uhci_pci_resume
,
272 .bus_suspend
= uhci_rh_suspend
,
273 .bus_resume
= uhci_rh_resume
,
277 .urb_enqueue
= uhci_urb_enqueue
,
278 .urb_dequeue
= uhci_urb_dequeue
,
280 .endpoint_disable
= uhci_hcd_endpoint_disable
,
281 .get_frame_number
= uhci_hcd_get_frame_number
,
283 .hub_status_data
= uhci_hub_status_data
,
284 .hub_control
= uhci_hub_control
,
287 static const struct pci_device_id uhci_pci_ids
[] = { {
288 /* handle any USB UHCI controller */
289 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_UHCI
, ~0),
290 .driver_data
= (unsigned long) &uhci_driver
,
291 }, { /* end: all zeroes */ }
294 MODULE_DEVICE_TABLE(pci
, uhci_pci_ids
);
296 static struct pci_driver uhci_pci_driver
= {
297 .name
= (char *)hcd_name
,
298 .id_table
= uhci_pci_ids
,
300 .probe
= usb_hcd_pci_probe
,
301 .remove
= usb_hcd_pci_remove
,
302 .shutdown
= uhci_shutdown
,
306 .pm
= &usb_hcd_pci_pm_ops
311 MODULE_SOFTDEP("pre: ehci_pci");