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$");
43 #include <sys/stdint.h>
44 #include <sys/stddef.h>
45 #include <sys/param.h>
46 #include <sys/queue.h>
47 #include <sys/types.h>
48 #include <sys/systm.h>
49 #include <sys/kernel.h>
51 #include <sys/module.h>
53 #include <sys/mutex.h>
54 #include <sys/condvar.h>
55 #include <sys/sysctl.h>
57 #include <sys/unistd.h>
58 #include <sys/callout.h>
59 #include <sys/malloc.h>
63 #include <machine/resource.h>
65 #include <dev/usb/usb.h>
66 #include <dev/usb/usbdi.h>
68 #include <dev/usb/usb_core.h>
69 #include <dev/usb/usb_busdma.h>
70 #include <dev/usb/usb_process.h>
71 #include <dev/usb/usb_util.h>
73 #include <dev/usb/usb_controller.h>
74 #include <dev/usb/usb_bus.h>
75 #include <dev/usb/controller/ehci.h>
76 #include <dev/usb/controller/ehcireg.h>
77 #include <mips/rmi/pic.h>
79 static device_attach_t ehci_xls_attach;
80 static device_detach_t ehci_xls_detach;
82 static const char *xlr_usb_dev_desc = "RMI XLR USB 2.0 controller";
83 static const char *xlr_vendor_desc = "RMI Corp";
86 ehci_xls_probe(device_t self)
88 /* TODO see if usb is enabled on the board */
89 device_set_desc(self, xlr_usb_dev_desc);
90 return BUS_PROBE_DEFAULT;
94 ehci_xls_attach(device_t self)
96 ehci_softc_t *sc = device_get_softc(self);
100 sc->sc_bus.parent = self;
101 sc->sc_bus.devices = sc->sc_devices;
102 sc->sc_bus.devices_max = EHCI_MAX_DEVICES;
104 /* get all DMA memory */
105 if (usb_bus_mem_alloc_all(&sc->sc_bus,
106 USB_GET_DMA_TAG(self), &ehci_iterate_hw_softc)) {
111 sc->sc_io_res = bus_alloc_resource_any(self, SYS_RES_MEMORY, &rid,
113 if (!sc->sc_io_res) {
114 device_printf(self, "Could not map memory\n");
117 sc->sc_io_tag = rman_get_bustag(sc->sc_io_res);
118 sc->sc_io_hdl = rman_get_bushandle(sc->sc_io_res);
119 printf("IO Resource tag %lx, hdl %lx, size %lx\n",
120 (u_long)sc->sc_io_tag, (u_long)sc->sc_io_hdl,
121 (u_long)sc->sc_io_size);
124 sc->sc_irq_res = bus_alloc_resource(self, SYS_RES_IRQ, &rid,
125 PIC_USB_IRQ, PIC_USB_IRQ, 1, RF_SHAREABLE | RF_ACTIVE);
126 if (sc->sc_irq_res == NULL) {
127 device_printf(self, "Could not allocate irq\n");
131 sc->sc_bus.bdev = device_add_child(self, "usbus", -1);
132 if (!sc->sc_bus.bdev) {
133 device_printf(self, "Could not add USB device\n");
136 device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
137 device_set_desc(sc->sc_bus.bdev, xlr_usb_dev_desc);
139 sprintf(sc->sc_vendor, xlr_vendor_desc);
141 err = bus_setup_intr(self, sc->sc_irq_res,
142 INTR_TYPE_BIO | INTR_MPSAFE, NULL,
143 (driver_intr_t *) ehci_interrupt, sc, &sc->sc_intr_hdl);
145 device_printf(self, "Could not setup irq, %d\n", err);
146 sc->sc_intr_hdl = NULL;
152 device_printf(self, "USB init failed err=%d\n", err);
156 err = device_probe_and_attach(sc->sc_bus.bdev);
158 device_printf(self, "USB probe and attach failed err=%d\n", err);
165 ehci_xls_detach(self);
170 ehci_xls_detach(device_t self)
172 ehci_softc_t *sc = device_get_softc(self);
175 /* during module unload there are lots of children leftover */
176 device_delete_all_children(self);
178 if (sc->sc_irq_res && sc->sc_intr_hdl) {
181 err = bus_teardown_intr(self, sc->sc_irq_res, sc->sc_intr_hdl);
183 device_printf(self, "Could not tear down irq, %d\n",
188 if (sc->sc_irq_res) {
189 bus_release_resource(self, SYS_RES_IRQ, 0, sc->sc_irq_res);
190 sc->sc_irq_res = NULL;
193 bus_release_resource(self, SYS_RES_MEMORY, 0,
195 sc->sc_io_res = NULL;
200 usb_bus_mem_free_all(&sc->sc_bus, &ehci_iterate_hw_softc);
205 static device_method_t ehci_methods[] = {
206 /* Device interface */
207 DEVMETHOD(device_probe, ehci_xls_probe),
208 DEVMETHOD(device_attach, ehci_xls_attach),
209 DEVMETHOD(device_detach, ehci_xls_detach),
210 DEVMETHOD(device_suspend, bus_generic_suspend),
211 DEVMETHOD(device_resume, bus_generic_resume),
212 DEVMETHOD(device_shutdown, bus_generic_shutdown),
217 static driver_t ehci_driver = {
219 .methods = ehci_methods,
220 .size = sizeof(struct ehci_softc),
223 static devclass_t ehci_devclass;
225 DRIVER_MODULE(ehci, iodi, ehci_driver, ehci_devclass, 0, 0);
226 MODULE_DEPEND(ehci, usb, 1, 1, 1);