xref: /freebsd/sys/dev/usb/controller/ohci_pci.c (revision ca48e43ba9ee73a07cdbad8365117793b01273bb)
102ac6454SAndrew Thompson /*-
2b61a5730SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
402ac6454SAndrew Thompson  * Copyright (c) 1998 The NetBSD Foundation, Inc.
502ac6454SAndrew Thompson  * All rights reserved.
602ac6454SAndrew Thompson  *
702ac6454SAndrew Thompson  * This code is derived from software contributed to The NetBSD Foundation
802ac6454SAndrew Thompson  * by Lennart Augustsson (augustss@carlstedt.se) at
902ac6454SAndrew Thompson  * Carlstedt Research & Technology.
1002ac6454SAndrew Thompson  *
1102ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
1202ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
1302ac6454SAndrew Thompson  * are met:
1402ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
1502ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1602ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1702ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1802ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
1902ac6454SAndrew Thompson  *
2002ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2102ac6454SAndrew Thompson  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2202ac6454SAndrew Thompson  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2302ac6454SAndrew Thompson  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2402ac6454SAndrew Thompson  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2502ac6454SAndrew Thompson  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2602ac6454SAndrew Thompson  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2702ac6454SAndrew Thompson  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2802ac6454SAndrew Thompson  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2902ac6454SAndrew Thompson  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3002ac6454SAndrew Thompson  * POSSIBILITY OF SUCH DAMAGE.
3102ac6454SAndrew Thompson  */
3202ac6454SAndrew Thompson 
3302ac6454SAndrew Thompson /*
3402ac6454SAndrew Thompson  * USB Open Host Controller driver.
3502ac6454SAndrew Thompson  *
3602ac6454SAndrew Thompson  * OHCI spec: http://www.intel.com/design/usb/ohci11d.pdf
3702ac6454SAndrew Thompson  */
3802ac6454SAndrew Thompson 
3902ac6454SAndrew Thompson /* The low level controller code for OHCI has been split into
4002ac6454SAndrew Thompson  * PCI probes and OHCI specific code. This was done to facilitate the
4102ac6454SAndrew Thompson  * sharing of code between *BSD's
4202ac6454SAndrew Thompson  */
4302ac6454SAndrew Thompson 
44ed6d949aSAndrew Thompson #include <sys/stdint.h>
45ed6d949aSAndrew Thompson #include <sys/stddef.h>
46ed6d949aSAndrew Thompson #include <sys/param.h>
47ed6d949aSAndrew Thompson #include <sys/queue.h>
48ed6d949aSAndrew Thompson #include <sys/types.h>
49ed6d949aSAndrew Thompson #include <sys/systm.h>
50ed6d949aSAndrew Thompson #include <sys/kernel.h>
51ed6d949aSAndrew Thompson #include <sys/bus.h>
52ed6d949aSAndrew Thompson #include <sys/module.h>
53ed6d949aSAndrew Thompson #include <sys/lock.h>
54ed6d949aSAndrew Thompson #include <sys/mutex.h>
55ed6d949aSAndrew Thompson #include <sys/condvar.h>
56ed6d949aSAndrew Thompson #include <sys/sysctl.h>
57ed6d949aSAndrew Thompson #include <sys/sx.h>
58ed6d949aSAndrew Thompson #include <sys/unistd.h>
59ed6d949aSAndrew Thompson #include <sys/callout.h>
60ed6d949aSAndrew Thompson #include <sys/malloc.h>
61ed6d949aSAndrew Thompson #include <sys/priv.h>
62ed6d949aSAndrew Thompson 
6302ac6454SAndrew Thompson #include <dev/usb/usb.h>
64ed6d949aSAndrew Thompson #include <dev/usb/usbdi.h>
6502ac6454SAndrew Thompson 
6602ac6454SAndrew Thompson #include <dev/usb/usb_core.h>
6702ac6454SAndrew Thompson #include <dev/usb/usb_busdma.h>
6802ac6454SAndrew Thompson #include <dev/usb/usb_process.h>
6902ac6454SAndrew Thompson #include <dev/usb/usb_util.h>
7002ac6454SAndrew Thompson 
7102ac6454SAndrew Thompson #include <dev/usb/usb_controller.h>
7202ac6454SAndrew Thompson #include <dev/usb/usb_bus.h>
7302ac6454SAndrew Thompson #include <dev/usb/usb_pci.h>
7402ac6454SAndrew Thompson #include <dev/usb/controller/ohci.h>
751def609aSAndrew Thompson #include <dev/usb/controller/ohcireg.h>
762e141748SHans Petter Selasky #include "usb_if.h"
7702ac6454SAndrew Thompson 
7802ac6454SAndrew Thompson #define	PCI_OHCI_VENDORID_ACERLABS	0x10b9
7902ac6454SAndrew Thompson #define	PCI_OHCI_VENDORID_AMD		0x1022
8002ac6454SAndrew Thompson #define	PCI_OHCI_VENDORID_APPLE		0x106b
8102ac6454SAndrew Thompson #define	PCI_OHCI_VENDORID_ATI		0x1002
8202ac6454SAndrew Thompson #define	PCI_OHCI_VENDORID_CMDTECH	0x1095
83d82c0ebcSHans Petter Selasky #define	PCI_OHCI_VENDORID_HYGON		0x1d94
8402ac6454SAndrew Thompson #define	PCI_OHCI_VENDORID_NEC		0x1033
8502ac6454SAndrew Thompson #define	PCI_OHCI_VENDORID_NVIDIA	0x12D2
8602ac6454SAndrew Thompson #define	PCI_OHCI_VENDORID_NVIDIA2	0x10DE
8702ac6454SAndrew Thompson #define	PCI_OHCI_VENDORID_OPTI		0x1045
8802ac6454SAndrew Thompson #define	PCI_OHCI_VENDORID_SIS		0x1039
8902ac6454SAndrew Thompson 
9002ac6454SAndrew Thompson #define	PCI_OHCI_BASE_REG	0x10
9102ac6454SAndrew Thompson 
9202ac6454SAndrew Thompson static device_probe_t ohci_pci_probe;
9302ac6454SAndrew Thompson static device_attach_t ohci_pci_attach;
9402ac6454SAndrew Thompson static device_detach_t ohci_pci_detach;
952e141748SHans Petter Selasky static usb_take_controller_t ohci_pci_take_controller;
9602ac6454SAndrew Thompson 
9702ac6454SAndrew Thompson static int
ohci_pci_take_controller(device_t self)982e141748SHans Petter Selasky ohci_pci_take_controller(device_t self)
9902ac6454SAndrew Thompson {
1002e141748SHans Petter Selasky 	uint32_t reg;
1012e141748SHans Petter Selasky 	uint32_t int_line;
10202ac6454SAndrew Thompson 
10302ac6454SAndrew Thompson 	if (pci_get_powerstate(self) != PCI_POWERSTATE_D0) {
10402ac6454SAndrew Thompson 		device_printf(self, "chip is in D%d mode "
10502ac6454SAndrew Thompson 		    "-- setting to D0\n", pci_get_powerstate(self));
10602ac6454SAndrew Thompson 		reg = pci_read_config(self, PCI_CBMEM, 4);
10702ac6454SAndrew Thompson 		int_line = pci_read_config(self, PCIR_INTLINE, 4);
10802ac6454SAndrew Thompson 		pci_set_powerstate(self, PCI_POWERSTATE_D0);
10902ac6454SAndrew Thompson 		pci_write_config(self, PCI_CBMEM, reg, 4);
11002ac6454SAndrew Thompson 		pci_write_config(self, PCIR_INTLINE, int_line, 4);
11102ac6454SAndrew Thompson 	}
11202ac6454SAndrew Thompson 	return (0);
11302ac6454SAndrew Thompson }
11402ac6454SAndrew Thompson 
11502ac6454SAndrew Thompson static const char *
ohci_pci_match(device_t self)11602ac6454SAndrew Thompson ohci_pci_match(device_t self)
11702ac6454SAndrew Thompson {
11802ac6454SAndrew Thompson 	uint32_t device_id = pci_get_devid(self);
11902ac6454SAndrew Thompson 
12002ac6454SAndrew Thompson 	switch (device_id) {
12102ac6454SAndrew Thompson 	case 0x523710b9:
12202ac6454SAndrew Thompson 		return ("AcerLabs M5237 (Aladdin-V) USB controller");
12302ac6454SAndrew Thompson 
12402ac6454SAndrew Thompson 	case 0x740c1022:
12502ac6454SAndrew Thompson 		return ("AMD-756 USB Controller");
12602ac6454SAndrew Thompson 	case 0x74141022:
12702ac6454SAndrew Thompson 		return ("AMD-766 USB Controller");
12815e01a35SAlexander Motin 	case 0x78071022:
12915e01a35SAlexander Motin 		return ("AMD FCH USB Controller");
13002ac6454SAndrew Thompson 
13102ac6454SAndrew Thompson 	case 0x43741002:
13202ac6454SAndrew Thompson 		return "ATI SB400 USB Controller";
13302ac6454SAndrew Thompson 	case 0x43751002:
13402ac6454SAndrew Thompson 		return "ATI SB400 USB Controller";
135f0d0cee0SAlexander Motin 	case 0x43971002:
136f0d0cee0SAlexander Motin 		return ("AMD SB7x0/SB8x0/SB9x0 USB controller");
137d81b160aSHans Petter Selasky 	case 0x43981002:
138d81b160aSHans Petter Selasky 		return ("AMD SB7x0/SB8x0/SB9x0 USB controller");
139f0d0cee0SAlexander Motin 	case 0x43991002:
140f0d0cee0SAlexander Motin 		return ("AMD SB7x0/SB8x0/SB9x0 USB controller");
14102ac6454SAndrew Thompson 
14202ac6454SAndrew Thompson 	case 0x06701095:
14302ac6454SAndrew Thompson 		return ("CMD Tech 670 (USB0670) USB controller");
14402ac6454SAndrew Thompson 
14502ac6454SAndrew Thompson 	case 0x06731095:
14602ac6454SAndrew Thompson 		return ("CMD Tech 673 (USB0673) USB controller");
14702ac6454SAndrew Thompson 
14802ac6454SAndrew Thompson 	case 0xc8611045:
14902ac6454SAndrew Thompson 		return ("OPTi 82C861 (FireLink) USB controller");
15002ac6454SAndrew Thompson 
15102ac6454SAndrew Thompson 	case 0x00351033:
15202ac6454SAndrew Thompson 		return ("NEC uPD 9210 USB controller");
15302ac6454SAndrew Thompson 
15402ac6454SAndrew Thompson 	case 0x00d710de:
15502ac6454SAndrew Thompson 		return ("nVidia nForce3 USB Controller");
15602ac6454SAndrew Thompson 
1573147331eSHans Petter Selasky 	case 0x005a10de:
1583147331eSHans Petter Selasky 		return ("nVidia nForce CK804 USB Controller");
1594a4bd31bSAndrew Thompson 	case 0x036c10de:
1604a4bd31bSAndrew Thompson 		return ("nVidia nForce MCP55 USB Controller");
161f724bcecSAlfred Perlstein 	case 0x03f110de:
162f724bcecSAlfred Perlstein 		return ("nVidia nForce MCP61 USB Controller");
163725f67adSAndrew Thompson 	case 0x0aa510de:
164725f67adSAndrew Thompson 		return ("nVidia nForce MCP79 USB Controller");
165725f67adSAndrew Thompson 	case 0x0aa710de:
166725f67adSAndrew Thompson 		return ("nVidia nForce MCP79 USB Controller");
167725f67adSAndrew Thompson 	case 0x0aa810de:
168725f67adSAndrew Thompson 		return ("nVidia nForce MCP79 USB Controller");
169f724bcecSAlfred Perlstein 
17002ac6454SAndrew Thompson 	case 0x70011039:
17102ac6454SAndrew Thompson 		return ("SiS 5571 USB controller");
17202ac6454SAndrew Thompson 
17302ac6454SAndrew Thompson 	case 0x0019106b:
17402ac6454SAndrew Thompson 		return ("Apple KeyLargo USB controller");
1754dc34955SJustin Hibbits 	case 0x003f106b:
1764dc34955SJustin Hibbits 		return ("Apple KeyLargo/Intrepid USB controller");
17702ac6454SAndrew Thompson 
17802ac6454SAndrew Thompson 	default:
17902ac6454SAndrew Thompson 		break;
18002ac6454SAndrew Thompson 	}
18102ac6454SAndrew Thompson 	if ((pci_get_class(self) == PCIC_SERIALBUS) &&
18202ac6454SAndrew Thompson 	    (pci_get_subclass(self) == PCIS_SERIALBUS_USB) &&
18302ac6454SAndrew Thompson 	    (pci_get_progif(self) == PCI_INTERFACE_OHCI)) {
18402ac6454SAndrew Thompson 		return ("OHCI (generic) USB controller");
18502ac6454SAndrew Thompson 	}
18602ac6454SAndrew Thompson 	return (NULL);
18702ac6454SAndrew Thompson }
18802ac6454SAndrew Thompson 
18902ac6454SAndrew Thompson static int
ohci_pci_probe(device_t self)19002ac6454SAndrew Thompson ohci_pci_probe(device_t self)
19102ac6454SAndrew Thompson {
19202ac6454SAndrew Thompson 	const char *desc = ohci_pci_match(self);
19302ac6454SAndrew Thompson 
19402ac6454SAndrew Thompson 	if (desc) {
19502ac6454SAndrew Thompson 		device_set_desc(self, desc);
19602ac6454SAndrew Thompson 		return (0);
19702ac6454SAndrew Thompson 	} else {
19802ac6454SAndrew Thompson 		return (ENXIO);
19902ac6454SAndrew Thompson 	}
20002ac6454SAndrew Thompson }
20102ac6454SAndrew Thompson 
20202ac6454SAndrew Thompson static int
ohci_pci_attach(device_t self)20302ac6454SAndrew Thompson ohci_pci_attach(device_t self)
20402ac6454SAndrew Thompson {
20502ac6454SAndrew Thompson 	ohci_softc_t *sc = device_get_softc(self);
20602ac6454SAndrew Thompson 	int rid;
20702ac6454SAndrew Thompson 	int err;
20802ac6454SAndrew Thompson 
20902ac6454SAndrew Thompson 	/* initialise some bus fields */
21002ac6454SAndrew Thompson 	sc->sc_bus.parent = self;
21102ac6454SAndrew Thompson 	sc->sc_bus.devices = sc->sc_devices;
21202ac6454SAndrew Thompson 	sc->sc_bus.devices_max = OHCI_MAX_DEVICES;
213b217d184SHans Petter Selasky 	sc->sc_bus.dma_bits = 32;
21402ac6454SAndrew Thompson 
21502ac6454SAndrew Thompson 	/* get all DMA memory */
216a593f6b8SAndrew Thompson 	if (usb_bus_mem_alloc_all(&sc->sc_bus, USB_GET_DMA_TAG(self),
21702ac6454SAndrew Thompson 	    &ohci_iterate_hw_softc)) {
21802ac6454SAndrew Thompson 		return (ENOMEM);
21902ac6454SAndrew Thompson 	}
22002ac6454SAndrew Thompson 	sc->sc_dev = self;
22102ac6454SAndrew Thompson 
22202ac6454SAndrew Thompson 	pci_enable_busmaster(self);
22302ac6454SAndrew Thompson 
22402ac6454SAndrew Thompson 	rid = PCI_CBMEM;
22502ac6454SAndrew Thompson 	sc->sc_io_res = bus_alloc_resource_any(self, SYS_RES_MEMORY, &rid,
22602ac6454SAndrew Thompson 	    RF_ACTIVE);
22702ac6454SAndrew Thompson 	if (!sc->sc_io_res) {
22802ac6454SAndrew Thompson 		device_printf(self, "Could not map memory\n");
22902ac6454SAndrew Thompson 		goto error;
23002ac6454SAndrew Thompson 	}
23102ac6454SAndrew Thompson 	sc->sc_io_tag = rman_get_bustag(sc->sc_io_res);
23202ac6454SAndrew Thompson 	sc->sc_io_hdl = rman_get_bushandle(sc->sc_io_res);
23302ac6454SAndrew Thompson 	sc->sc_io_size = rman_get_size(sc->sc_io_res);
23402ac6454SAndrew Thompson 
23502ac6454SAndrew Thompson 	rid = 0;
23602ac6454SAndrew Thompson 	sc->sc_irq_res = bus_alloc_resource_any(self, SYS_RES_IRQ, &rid,
23702ac6454SAndrew Thompson 	    RF_SHAREABLE | RF_ACTIVE);
23802ac6454SAndrew Thompson 	if (sc->sc_irq_res == NULL) {
23902ac6454SAndrew Thompson 		device_printf(self, "Could not allocate irq\n");
24002ac6454SAndrew Thompson 		goto error;
24102ac6454SAndrew Thompson 	}
2425b56413dSWarner Losh 	sc->sc_bus.bdev = device_add_child(self, "usbus", DEVICE_UNIT_ANY);
24302ac6454SAndrew Thompson 	if (!sc->sc_bus.bdev) {
24402ac6454SAndrew Thompson 		device_printf(self, "Could not add USB device\n");
24502ac6454SAndrew Thompson 		goto error;
24602ac6454SAndrew Thompson 	}
24702ac6454SAndrew Thompson 	device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
24802ac6454SAndrew Thompson 
24902ac6454SAndrew Thompson 	/*
25002ac6454SAndrew Thompson 	 * ohci_pci_match will never return NULL if ohci_pci_probe
25102ac6454SAndrew Thompson 	 * succeeded
25202ac6454SAndrew Thompson 	 */
25302ac6454SAndrew Thompson 	device_set_desc(sc->sc_bus.bdev, ohci_pci_match(self));
25402ac6454SAndrew Thompson 	switch (pci_get_vendor(self)) {
25502ac6454SAndrew Thompson 	case PCI_OHCI_VENDORID_ACERLABS:
25602ac6454SAndrew Thompson 		sprintf(sc->sc_vendor, "AcerLabs");
25702ac6454SAndrew Thompson 		break;
25802ac6454SAndrew Thompson 	case PCI_OHCI_VENDORID_AMD:
25902ac6454SAndrew Thompson 		sprintf(sc->sc_vendor, "AMD");
26002ac6454SAndrew Thompson 		break;
26102ac6454SAndrew Thompson 	case PCI_OHCI_VENDORID_APPLE:
26202ac6454SAndrew Thompson 		sprintf(sc->sc_vendor, "Apple");
26302ac6454SAndrew Thompson 		break;
26402ac6454SAndrew Thompson 	case PCI_OHCI_VENDORID_ATI:
26502ac6454SAndrew Thompson 		sprintf(sc->sc_vendor, "ATI");
26602ac6454SAndrew Thompson 		break;
26702ac6454SAndrew Thompson 	case PCI_OHCI_VENDORID_CMDTECH:
26802ac6454SAndrew Thompson 		sprintf(sc->sc_vendor, "CMDTECH");
26902ac6454SAndrew Thompson 		break;
270d82c0ebcSHans Petter Selasky 	case PCI_OHCI_VENDORID_HYGON:
271d82c0ebcSHans Petter Selasky 		sprintf(sc->sc_vendor, "Hygon");
272d82c0ebcSHans Petter Selasky 		break;
27302ac6454SAndrew Thompson 	case PCI_OHCI_VENDORID_NEC:
27402ac6454SAndrew Thompson 		sprintf(sc->sc_vendor, "NEC");
27502ac6454SAndrew Thompson 		break;
27602ac6454SAndrew Thompson 	case PCI_OHCI_VENDORID_NVIDIA:
27702ac6454SAndrew Thompson 	case PCI_OHCI_VENDORID_NVIDIA2:
27802ac6454SAndrew Thompson 		sprintf(sc->sc_vendor, "nVidia");
27902ac6454SAndrew Thompson 		break;
28002ac6454SAndrew Thompson 	case PCI_OHCI_VENDORID_OPTI:
28102ac6454SAndrew Thompson 		sprintf(sc->sc_vendor, "OPTi");
28202ac6454SAndrew Thompson 		break;
28302ac6454SAndrew Thompson 	case PCI_OHCI_VENDORID_SIS:
28402ac6454SAndrew Thompson 		sprintf(sc->sc_vendor, "SiS");
28502ac6454SAndrew Thompson 		break;
28602ac6454SAndrew Thompson 	default:
28702ac6454SAndrew Thompson 		if (bootverbose) {
28802ac6454SAndrew Thompson 			device_printf(self, "(New OHCI DeviceId=0x%08x)\n",
28902ac6454SAndrew Thompson 			    pci_get_devid(self));
29002ac6454SAndrew Thompson 		}
29102ac6454SAndrew Thompson 		sprintf(sc->sc_vendor, "(0x%04x)", pci_get_vendor(self));
29202ac6454SAndrew Thompson 	}
29302ac6454SAndrew Thompson 
29402ac6454SAndrew Thompson 	/* sc->sc_bus.usbrev; set by ohci_init() */
29502ac6454SAndrew Thompson 
29602ac6454SAndrew Thompson 	err = bus_setup_intr(self, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
2970f7d4548SAndrew Thompson 	    NULL, (driver_intr_t *)ohci_interrupt, sc, &sc->sc_intr_hdl);
29802ac6454SAndrew Thompson 	if (err) {
29902ac6454SAndrew Thompson 		device_printf(self, "Could not setup irq, %d\n", err);
30002ac6454SAndrew Thompson 		sc->sc_intr_hdl = NULL;
30102ac6454SAndrew Thompson 		goto error;
30202ac6454SAndrew Thompson 	}
30302ac6454SAndrew Thompson 	err = ohci_init(sc);
30402ac6454SAndrew Thompson 	if (!err) {
30502ac6454SAndrew Thompson 		err = device_probe_and_attach(sc->sc_bus.bdev);
30602ac6454SAndrew Thompson 	}
30702ac6454SAndrew Thompson 	if (err) {
30802ac6454SAndrew Thompson 		device_printf(self, "USB init failed\n");
30902ac6454SAndrew Thompson 		goto error;
31002ac6454SAndrew Thompson 	}
31102ac6454SAndrew Thompson 	return (0);
31202ac6454SAndrew Thompson 
31302ac6454SAndrew Thompson error:
31402ac6454SAndrew Thompson 	ohci_pci_detach(self);
31502ac6454SAndrew Thompson 	return (ENXIO);
31602ac6454SAndrew Thompson }
31702ac6454SAndrew Thompson 
31802ac6454SAndrew Thompson static int
ohci_pci_detach(device_t self)31902ac6454SAndrew Thompson ohci_pci_detach(device_t self)
32002ac6454SAndrew Thompson {
32102ac6454SAndrew Thompson 	ohci_softc_t *sc = device_get_softc(self);
322*3ddaf820SJohn Baldwin 	int error;
32302ac6454SAndrew Thompson 
32402ac6454SAndrew Thompson 	/* during module unload there are lots of children leftover */
325*3ddaf820SJohn Baldwin 	error = bus_generic_detach(self);
326*3ddaf820SJohn Baldwin 	if (error != 0)
327*3ddaf820SJohn Baldwin 		return (error);
32802ac6454SAndrew Thompson 
32902ac6454SAndrew Thompson 	pci_disable_busmaster(self);
33002ac6454SAndrew Thompson 
33102ac6454SAndrew Thompson 	if (sc->sc_irq_res && sc->sc_intr_hdl) {
33202ac6454SAndrew Thompson 		/*
33302ac6454SAndrew Thompson 		 * only call ohci_detach() after ohci_init()
33402ac6454SAndrew Thompson 		 */
33502ac6454SAndrew Thompson 		ohci_detach(sc);
33602ac6454SAndrew Thompson 
33702ac6454SAndrew Thompson 		int err = bus_teardown_intr(self, sc->sc_irq_res, sc->sc_intr_hdl);
33802ac6454SAndrew Thompson 
33902ac6454SAndrew Thompson 		if (err) {
34002ac6454SAndrew Thompson 			/* XXX or should we panic? */
34102ac6454SAndrew Thompson 			device_printf(self, "Could not tear down irq, %d\n",
34202ac6454SAndrew Thompson 			    err);
34302ac6454SAndrew Thompson 		}
34402ac6454SAndrew Thompson 		sc->sc_intr_hdl = NULL;
34502ac6454SAndrew Thompson 	}
34602ac6454SAndrew Thompson 	if (sc->sc_irq_res) {
34702ac6454SAndrew Thompson 		bus_release_resource(self, SYS_RES_IRQ, 0, sc->sc_irq_res);
34802ac6454SAndrew Thompson 		sc->sc_irq_res = NULL;
34902ac6454SAndrew Thompson 	}
35002ac6454SAndrew Thompson 	if (sc->sc_io_res) {
35102ac6454SAndrew Thompson 		bus_release_resource(self, SYS_RES_MEMORY, PCI_CBMEM,
35202ac6454SAndrew Thompson 		    sc->sc_io_res);
35302ac6454SAndrew Thompson 		sc->sc_io_res = NULL;
35402ac6454SAndrew Thompson 	}
355a593f6b8SAndrew Thompson 	usb_bus_mem_free_all(&sc->sc_bus, &ohci_iterate_hw_softc);
35602ac6454SAndrew Thompson 
35702ac6454SAndrew Thompson 	return (0);
35802ac6454SAndrew Thompson }
35902ac6454SAndrew Thompson 
3602e141748SHans Petter Selasky static device_method_t ohci_pci_methods[] = {
3612e141748SHans Petter Selasky 	/* Device interface */
36202ac6454SAndrew Thompson 	DEVMETHOD(device_probe, ohci_pci_probe),
36302ac6454SAndrew Thompson 	DEVMETHOD(device_attach, ohci_pci_attach),
36402ac6454SAndrew Thompson 	DEVMETHOD(device_detach, ohci_pci_detach),
3652e141748SHans Petter Selasky 	DEVMETHOD(device_suspend, bus_generic_suspend),
3662e141748SHans Petter Selasky 	DEVMETHOD(device_resume, bus_generic_resume),
36702ac6454SAndrew Thompson 	DEVMETHOD(device_shutdown, bus_generic_shutdown),
3682e141748SHans Petter Selasky 	DEVMETHOD(usb_take_controller, ohci_pci_take_controller),
36902ac6454SAndrew Thompson 
3704b7ec270SMarius Strobl 	DEVMETHOD_END
3712e141748SHans Petter Selasky };
3722e141748SHans Petter Selasky 
3732e141748SHans Petter Selasky static driver_t ohci_driver = {
3742e141748SHans Petter Selasky 	.name = "ohci",
3752e141748SHans Petter Selasky 	.methods = ohci_pci_methods,
37602ac6454SAndrew Thompson 	.size = sizeof(struct ohci_softc),
37702ac6454SAndrew Thompson };
37802ac6454SAndrew Thompson 
379bc9372d7SJohn Baldwin DRIVER_MODULE(ohci, pci, ohci_driver, 0, 0);
38002ac6454SAndrew Thompson MODULE_DEPEND(ohci, usb, 1, 1, 1);
381