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/usb_port.h>
51 #include <dev/usb/sl811hsvar.h>
52 #include "pccarddevs.h"
54 __FBSDID("$FreeBSD$");
56 static void slhci_pccard_intr(void *arg);
58 static const struct pccard_product slhci_pccard_products[] = {
59 PCMCIA_CARD(RATOC, REX_CFU1),
64 slhci_pccard_probe(device_t dev)
66 const struct pccard_product *pp;
67 u_int32_t fcn = PCCARD_FUNCTION_UNSPEC;
70 if ((error = pccard_get_function(dev, &fcn)))
73 /* if it says its a disk we should register it */
74 if (fcn == PCCARD_FUNCTION_DISK)
77 /* match other devices here, primarily cdrom/dvd rom */
78 if ((pp = pccard_product_lookup(dev, slhci_pccard_products,
79 sizeof(slhci_pccard_products[0]), NULL))) {
81 device_set_desc(dev, pp->pp_name);
88 slhci_pccard_detach(device_t dev)
90 struct slhci_softc *sc = device_get_softc(dev);
91 bus_generic_detach(dev);
94 bus_teardown_intr(dev, sc->irq_res, sc->ih);
96 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->io_res);
98 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
100 device_delete_child(dev, sc->sc_bus.bdev);
105 slhci_pccard_attach(device_t dev)
107 struct slhci_softc *sc = device_get_softc(dev);
110 if ((sc->io_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE)) == NULL) {
113 sc->sc_iot = rman_get_bustag(sc->io_res);
114 sc->sc_ioh = rman_get_bushandle(sc->io_res);
116 if (sl811hs_find(sc) == -1) {
122 if ((sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE)) == NULL) {
123 printf("CANNOT ALLOC IRQ\n");
127 sc->sc_iot = rman_get_bustag(sc->io_res);
128 sc->sc_ioh = rman_get_bushandle(sc->io_res);
129 sc->sc_bus.bdev = device_add_child(dev, "usb", -1);
130 if (!sc->sc_bus.bdev) {
131 device_printf(dev, "Could not add USB device\n");
133 device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
134 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_BIO, NULL, slhci_pccard_intr, sc, &sc->ih);
139 if (slhci_attach(sc) == -1) {
140 printf("MI attach NO\n");
144 error = device_probe_and_attach(sc->sc_bus.bdev);
147 printf("Probing USB bus %x\n", error);
151 printf("ATTACHED\n");
154 slhci_pccard_detach(dev);
160 slhci_pccard_enable_power(void *arg, int mode)
163 struct slhci_softc *sc = arg;
169 slhci_pccard_enable_intr(void *arg, int mode)
172 struct slhci_softc *sc = arg;
179 slhci_pccard_intr(void *arg)
182 struct slhci_softc *sc = arg;
188 static device_method_t slhci_pccard_methods[] = {
189 /* device interface */
190 DEVMETHOD(device_probe, slhci_pccard_probe),
191 DEVMETHOD(device_attach, slhci_pccard_attach),
192 DEVMETHOD(device_detach, slhci_pccard_detach),
197 static driver_t slhci_pccard_driver = {
199 slhci_pccard_methods,
200 sizeof(struct slhci_softc),
202 devclass_t slhci_devclass;
203 MODULE_DEPEND(slhci, usb, 1, 1, 1);
204 DRIVER_MODULE(slhci, pccard, slhci_pccard_driver, slhci_devclass, 0, 0);