2 * Copyright (C) 2005 Takanori Watanabe. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/kernel.h>
32 #include <sys/module.h>
34 #include <sys/malloc.h>
36 #include <sys/taskqueue.h>
38 #include <machine/stdarg.h>
39 #include <machine/resource.h>
40 #include <machine/bus.h>
42 #include <dev/pccard/pccard_cis.h>
43 #include <dev/pccard/pccardreg.h>
44 #include <dev/pccard/pccardvar.h>
46 #include <dev/usb/usb.h>
47 #include <dev/usb/usbdi.h>
48 #include <dev/usb/usbdivar.h>
49 #include <dev/usb/usb_mem.h>
50 #include <dev/usb/sl811hsvar.h>
51 #include "pccarddevs.h"
53 __FBSDID("$FreeBSD$");
55 static void slhci_pccard_intr(void *arg);
57 static const struct pccard_product slhci_pccard_products[] = {
58 PCMCIA_CARD(RATOC, REX_CFU1),
63 slhci_pccard_probe(device_t dev)
65 const struct pccard_product *pp;
66 u_int32_t fcn = PCCARD_FUNCTION_UNSPEC;
69 if ((error = pccard_get_function(dev, &fcn)))
72 /* if it says its a disk we should register it */
73 if (fcn == PCCARD_FUNCTION_DISK)
76 /* match other devices here, primarily cdrom/dvd rom */
77 if ((pp = pccard_product_lookup(dev, slhci_pccard_products,
78 sizeof(slhci_pccard_products[0]), NULL))) {
80 device_set_desc(dev, pp->pp_name);
87 slhci_pccard_detach(device_t dev)
89 struct slhci_softc *sc = device_get_softc(dev);
90 bus_generic_detach(dev);
93 bus_teardown_intr(dev, sc->irq_res, sc->ih);
95 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->io_res);
97 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
99 device_delete_child(dev, sc->sc_bus.bdev);
104 slhci_pccard_attach(device_t dev)
106 struct slhci_softc *sc = device_get_softc(dev);
109 if ((sc->io_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE)) == NULL) {
112 sc->sc_iot = rman_get_bustag(sc->io_res);
113 sc->sc_ioh = rman_get_bushandle(sc->io_res);
115 if (sl811hs_find(sc) == -1) {
121 if ((sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE)) == NULL) {
122 printf("CANNOT ALLOC IRQ\n");
126 sc->sc_iot = rman_get_bustag(sc->io_res);
127 sc->sc_ioh = rman_get_bushandle(sc->io_res);
128 sc->sc_bus.bdev = device_add_child(dev, "usb", -1);
129 if (!sc->sc_bus.bdev) {
130 device_printf(dev, "Could not add USB device\n");
132 device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
133 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_BIO, slhci_pccard_intr, sc, &sc->ih);
138 if (slhci_attach(sc) == -1) {
139 printf("MI attach NO\n");
143 error = device_probe_and_attach(sc->sc_bus.bdev);
146 printf("Probing USB bus %x\n", error);
150 printf("ATTACHED\n");
153 slhci_pccard_detach(dev);
159 slhci_pccard_enable_power(void *arg, int mode)
162 struct slhci_softc *sc = arg;
168 slhci_pccard_enable_intr(void *arg, int mode)
171 struct slhci_softc *sc = arg;
178 slhci_pccard_intr(void *arg)
181 struct slhci_softc *sc = arg;
187 static device_method_t slhci_pccard_methods[] = {
188 /* device interface */
189 DEVMETHOD(device_probe, slhci_pccard_probe),
190 DEVMETHOD(device_attach, slhci_pccard_attach),
191 DEVMETHOD(device_detach, slhci_pccard_detach),
196 static driver_t slhci_pccard_driver = {
198 slhci_pccard_methods,
199 sizeof(struct slhci_softc),
201 devclass_t slhci_devclass;
202 MODULE_DEPEND(slhci, usb, 1, 1, 1);
203 DRIVER_MODULE(slhci, pccard, slhci_pccard_driver, slhci_devclass, 0, 0);