]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/usb/slhci_pccard.c
Optimize PLCP length field computation for 802.11b rates.
[FreeBSD/FreeBSD.git] / sys / dev / usb / slhci_pccard.c
1 /*-
2  * Copyright (C) 2005 Takanori Watanabe. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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
23  * SUCH DAMAGE.
24  *
25  */
26
27
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/kernel.h>
32 #include <sys/module.h>
33 #include <sys/bus.h>
34 #include <sys/malloc.h>
35 #include <sys/sema.h>
36 #include <sys/taskqueue.h>
37 #include <vm/uma.h>
38 #include <machine/stdarg.h>
39 #include <machine/resource.h>
40 #include <machine/bus.h>
41 #include <sys/rman.h>
42 #include <dev/pccard/pccard_cis.h>
43 #include <dev/pccard/pccardreg.h>
44 #include <dev/pccard/pccardvar.h>
45
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"
52
53 __FBSDID("$FreeBSD$");
54
55 static void     slhci_pccard_intr(void *arg);
56
57 static const struct pccard_product slhci_pccard_products[] = {
58         PCMCIA_CARD(RATOC, REX_CFU1),
59         {NULL}
60 };
61
62 static int
63 slhci_pccard_probe(device_t dev)
64 {
65         const struct pccard_product *pp;
66         u_int32_t       fcn = PCCARD_FUNCTION_UNSPEC;
67         int             error = 0;
68
69         if ((error = pccard_get_function(dev, &fcn)))
70                 return error;
71
72         /* if it says its a disk we should register it */
73         if (fcn == PCCARD_FUNCTION_DISK)
74                 return 0;
75
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))) {
79                 if (pp->pp_name)
80                         device_set_desc(dev, pp->pp_name);
81                 return 0;
82         }
83         return ENXIO;
84 }
85
86 static int
87 slhci_pccard_detach(device_t dev)
88 {
89         struct slhci_softc *sc = device_get_softc(dev);
90         bus_generic_detach(dev);
91
92         if (sc->ih)
93                 bus_teardown_intr(dev, sc->irq_res, sc->ih);
94         if (sc->io_res)
95                 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->io_res);
96         if (sc->irq_res)
97                 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
98         if (sc->sc_bus.bdev)
99                 device_delete_child(dev, sc->sc_bus.bdev);
100         return 0;
101 }
102
103 static int
104 slhci_pccard_attach(device_t dev)
105 {
106         struct slhci_softc *sc = device_get_softc(dev);
107         int             error = ENXIO;
108         int             rid = 0;
109         if ((sc->io_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE)) == NULL) {
110                 return ENOMEM;
111         }
112         sc->sc_iot = rman_get_bustag(sc->io_res);
113         sc->sc_ioh = rman_get_bushandle(sc->io_res);
114
115         if (sl811hs_find(sc) == -1) {
116                 error = ENXIO;
117                 goto out;
118         }
119
120         rid = 0;
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");
123                 error = ENOMEM;
124                 goto out;
125         }
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");
131         }
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);
134         if (error)
135                 goto out;
136 #if 1
137
138         if (slhci_attach(sc) == -1) {
139                 printf("MI attach NO\n");
140                 goto out;
141         }
142
143         error = device_probe_and_attach(sc->sc_bus.bdev);
144
145         if (error) {
146                 printf("Probing USB bus %x\n", error);
147                 goto out;
148         }
149 #endif
150         printf("ATTACHED\n");
151         return 0;
152 out:
153         slhci_pccard_detach(dev);
154         return error;
155 }
156
157 #if 0
158 static void
159 slhci_pccard_enable_power(void *arg, int mode)
160 {
161 #if 0
162         struct slhci_softc *sc = arg;
163         u_int8_t        r;
164 #endif
165 }
166
167 static void
168 slhci_pccard_enable_intr(void *arg, int mode)
169 {
170 #if 0
171         struct slhci_softc *sc = arg;
172         u_int8_t        r;
173 #endif
174 }
175
176 #endif
177 static void
178 slhci_pccard_intr(void *arg)
179 {
180 #if 1
181         struct slhci_softc *sc = arg;
182         sc = sc;
183         slhci_intr(sc);
184 #endif
185 }
186
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),
192
193         {0, 0}
194 };
195
196 static driver_t slhci_pccard_driver = {
197         "slhci",
198         slhci_pccard_methods,
199         sizeof(struct slhci_softc),
200 };
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);