2 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * This code is derived from software contributed to The NetBSD Foundation
6 * by Lennart Augustsson (augustss@carlstedt.se) at
7 * Carlstedt Research & Technology.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the NetBSD
20 * Foundation, Inc. and its contributors.
21 * 4. Neither the name of The NetBSD Foundation nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
41 /* Universal Host Controller Interface
43 * UHCI spec: http://www.intel.com/
46 /* The low level controller code for UHCI has been split into
47 * PCI probes and UHCI specific code. This was done to facilitate the
48 * sharing of code between *BSD's
51 #include <dev/usb/usb_mfunc.h>
52 #include <dev/usb/usb.h>
54 #include <dev/usb/usb_core.h>
55 #include <dev/usb/usb_busdma.h>
56 #include <dev/usb/usb_process.h>
57 #include <dev/usb/usb_util.h>
58 #include <dev/usb/usb_debug.h>
60 #include <dev/usb/usb_controller.h>
61 #include <dev/usb/usb_bus.h>
62 #include <dev/usb/usb_pci.h>
63 #include <dev/usb/controller/uhci.h>
65 #define PCI_UHCI_VENDORID_INTEL 0x8086
66 #define PCI_UHCI_VENDORID_VIA 0x1106
68 /* PIIX4E has no separate stepping */
70 #define PCI_UHCI_BASE_REG 0x20
72 static device_probe_t uhci_pci_probe;
73 static device_attach_t uhci_pci_attach;
74 static device_detach_t uhci_pci_detach;
75 static device_suspend_t uhci_pci_suspend;
76 static device_resume_t uhci_pci_resume;
79 uhci_pci_suspend(device_t self)
81 uhci_softc_t *sc = device_get_softc(self);
84 err = bus_generic_suspend(self);
93 uhci_pci_resume(device_t self)
95 uhci_softc_t *sc = device_get_softc(self);
97 pci_write_config(self, PCI_LEGSUP, PCI_LEGSUP_USBPIRQDEN, 2);
101 bus_generic_resume(self);
106 uhci_pci_match(device_t self)
108 uint32_t device_id = pci_get_devid(self);
112 return ("Intel 631XESB/632XESB/3100 USB controller USB-1");
115 return ("Intel 631XESB/632XESB/3100 USB controller USB-2");
118 return ("Intel 631XESB/632XESB/3100 USB controller USB-3");
121 return ("Intel 631XESB/632XESB/3100 USB controller USB-4");
124 return ("Intel 82371SB (PIIX3) USB controller");
127 return ("Intel 82371AB/EB (PIIX4) USB controller");
130 return ("Intel 82801AA (ICH) USB controller");
133 return ("Intel 82801AB (ICH0) USB controller");
136 return ("Intel 82801BA/BAM (ICH2) USB controller USB-A");
139 return ("Intel 82801BA/BAM (ICH2) USB controller USB-B");
142 return ("Intel 82801CA/CAM (ICH3) USB controller USB-A");
145 return ("Intel 82801CA/CAM (ICH3) USB controller USB-B");
148 return ("Intel 82801CA/CAM (ICH3) USB controller USB-C");
151 return ("Intel 82801DB (ICH4) USB controller USB-A");
154 return ("Intel 82801DB (ICH4) USB controller USB-B");
157 return ("Intel 82801DB (ICH4) USB controller USB-C");
160 return ("Intel 82801EB (ICH5) USB controller USB-A");
163 return ("Intel 82801EB (ICH5) USB controller USB-B");
166 return ("Intel 82801EB (ICH5) USB controller USB-C");
169 return ("Intel 82801EB (ICH5) USB controller USB-D");
172 return ("Intel 82801FB/FR/FW/FRW (ICH6) USB controller USB-A");
175 return ("Intel 82801FB/FR/FW/FRW (ICH6) USB controller USB-B");
178 return ("Intel 82801FB/FR/FW/FRW (ICH6) USB controller USB-C");
181 return ("Intel 82801FB/FR/FW/FRW (ICH6) USB controller USB-D");
184 return ("Intel 82801H (ICH8) USB controller USB-A");
186 return ("Intel 82801H (ICH8) USB controller USB-B");
188 return ("Intel 82801H (ICH8) USB controller USB-C");
190 return ("Intel 82801H (ICH8) USB controller USB-D");
192 return ("Intel 82801H (ICH8) USB controller USB-E");
194 return ("Intel 82801I (ICH9) USB controller");
196 return ("Intel 82801I (ICH9) USB controller");
198 return ("Intel 82801I (ICH9) USB controller");
200 return ("Intel 82801I (ICH9) USB controller");
202 return ("Intel 82801I (ICH9) USB controller");
204 return ("Intel 82801I (ICH9) USB controller");
207 return ("Intel 82443MX USB controller");
210 return ("Intel 82372FB/82468GX USB controller");
213 return ("VIA 83C572 USB controller");
219 if ((pci_get_class(self) == PCIC_SERIALBUS) &&
220 (pci_get_subclass(self) == PCIS_SERIALBUS_USB) &&
221 (pci_get_progif(self) == PCI_INTERFACE_UHCI)) {
222 return ("UHCI (generic) USB controller");
228 uhci_pci_probe(device_t self)
230 const char *desc = uhci_pci_match(self);
233 device_set_desc(self, desc);
241 uhci_pci_attach(device_t self)
243 uhci_softc_t *sc = device_get_softc(self);
247 /* initialise some bus fields */
248 sc->sc_bus.parent = self;
249 sc->sc_bus.devices = sc->sc_devices;
250 sc->sc_bus.devices_max = UHCI_MAX_DEVICES;
252 /* get all DMA memory */
253 if (usb2_bus_mem_alloc_all(&sc->sc_bus, USB_GET_DMA_TAG(self),
254 &uhci_iterate_hw_softc)) {
259 pci_enable_busmaster(self);
261 rid = PCI_UHCI_BASE_REG;
262 sc->sc_io_res = bus_alloc_resource_any(self, SYS_RES_IOPORT, &rid,
264 if (!sc->sc_io_res) {
265 device_printf(self, "Could not map ports\n");
268 sc->sc_io_tag = rman_get_bustag(sc->sc_io_res);
269 sc->sc_io_hdl = rman_get_bushandle(sc->sc_io_res);
270 sc->sc_io_size = rman_get_size(sc->sc_io_res);
272 /* disable interrupts */
273 bus_space_write_2(sc->sc_io_tag, sc->sc_io_hdl, UHCI_INTR, 0);
276 sc->sc_irq_res = bus_alloc_resource_any(self, SYS_RES_IRQ, &rid,
277 RF_SHAREABLE | RF_ACTIVE);
278 if (sc->sc_irq_res == NULL) {
279 device_printf(self, "Could not allocate irq\n");
282 sc->sc_bus.bdev = device_add_child(self, "usbus", -1);
283 if (!sc->sc_bus.bdev) {
284 device_printf(self, "Could not add USB device\n");
287 device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
290 * uhci_pci_match must never return NULL if uhci_pci_probe
293 device_set_desc(sc->sc_bus.bdev, uhci_pci_match(self));
294 switch (pci_get_vendor(self)) {
295 case PCI_UHCI_VENDORID_INTEL:
296 sprintf(sc->sc_vendor, "Intel");
298 case PCI_UHCI_VENDORID_VIA:
299 sprintf(sc->sc_vendor, "VIA");
303 device_printf(self, "(New UHCI DeviceId=0x%08x)\n",
304 pci_get_devid(self));
306 sprintf(sc->sc_vendor, "(0x%04x)", pci_get_vendor(self));
309 switch (pci_read_config(self, PCI_USBREV, 1) & PCI_USB_REV_MASK) {
310 case PCI_USB_REV_PRE_1_0:
311 sc->sc_bus.usbrev = USB_REV_PRE_1_0;
313 case PCI_USB_REV_1_0:
314 sc->sc_bus.usbrev = USB_REV_1_0;
317 /* Quirk for Parallels Desktop 4.0 */
318 device_printf(self, "USB revision is unknown. Assuming v1.1.\n");
319 sc->sc_bus.usbrev = USB_REV_1_1;
323 #if (__FreeBSD_version >= 700031)
324 err = bus_setup_intr(self, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
325 NULL, (driver_intr_t *)uhci_interrupt, sc, &sc->sc_intr_hdl);
327 err = bus_setup_intr(self, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
328 (driver_intr_t *)uhci_interrupt, sc, &sc->sc_intr_hdl);
332 device_printf(self, "Could not setup irq, %d\n", err);
333 sc->sc_intr_hdl = NULL;
337 * Set the PIRQD enable bit and switch off all the others. We don't
338 * want legacy support to interfere with us XXX Does this also mean
339 * that the BIOS won't touch the keyboard anymore if it is connected
340 * to the ports of the root hub?
343 if (pci_read_config(self, PCI_LEGSUP, 2) != PCI_LEGSUP_USBPIRQDEN) {
344 device_printf(self, "LegSup = 0x%04x\n",
345 pci_read_config(self, PCI_LEGSUP, 2));
348 pci_write_config(self, PCI_LEGSUP, PCI_LEGSUP_USBPIRQDEN, 2);
352 err = device_probe_and_attach(sc->sc_bus.bdev);
355 device_printf(self, "USB init failed\n");
361 uhci_pci_detach(self);
366 uhci_pci_detach(device_t self)
368 uhci_softc_t *sc = device_get_softc(self);
371 if (sc->sc_bus.bdev) {
372 bdev = sc->sc_bus.bdev;
374 device_delete_child(self, bdev);
376 /* during module unload there are lots of children leftover */
377 device_delete_all_children(self);
380 * disable interrupts that might have been switched on in
384 USB_BUS_LOCK(&sc->sc_bus);
386 /* stop the controller */
389 USB_BUS_UNLOCK(&sc->sc_bus);
391 pci_disable_busmaster(self);
393 if (sc->sc_irq_res && sc->sc_intr_hdl) {
394 int err = bus_teardown_intr(self, sc->sc_irq_res, sc->sc_intr_hdl);
397 /* XXX or should we panic? */
398 device_printf(self, "Could not tear down irq, %d\n",
401 sc->sc_intr_hdl = NULL;
403 if (sc->sc_irq_res) {
404 bus_release_resource(self, SYS_RES_IRQ, 0, sc->sc_irq_res);
405 sc->sc_irq_res = NULL;
408 bus_release_resource(self, SYS_RES_IOPORT, PCI_UHCI_BASE_REG,
410 sc->sc_io_res = NULL;
412 usb2_bus_mem_free_all(&sc->sc_bus, &uhci_iterate_hw_softc);
417 static driver_t uhci_driver =
420 .methods = (device_method_t[]){
421 /* device interface */
422 DEVMETHOD(device_probe, uhci_pci_probe),
423 DEVMETHOD(device_attach, uhci_pci_attach),
424 DEVMETHOD(device_detach, uhci_pci_detach),
426 DEVMETHOD(device_suspend, uhci_pci_suspend),
427 DEVMETHOD(device_resume, uhci_pci_resume),
428 DEVMETHOD(device_shutdown, bus_generic_shutdown),
431 DEVMETHOD(bus_print_child, bus_generic_print_child),
434 .size = sizeof(struct uhci_softc),
437 static devclass_t uhci_devclass;
439 DRIVER_MODULE(uhci, pci, uhci_driver, uhci_devclass, 0, 0);
440 MODULE_DEPEND(uhci, usb, 1, 1, 1);