]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/dev/usb/slhci_pccard.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.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/usb_port.h>
51 #include <dev/usb/sl811hsvar.h>
52 #include "pccarddevs.h"
53
54 __FBSDID("$FreeBSD$");
55
56 static void     slhci_pccard_intr(void *arg);
57
58 static const struct pccard_product slhci_pccard_products[] = {
59         PCMCIA_CARD(RATOC, REX_CFU1),
60         {NULL}
61 };
62
63 static int
64 slhci_pccard_probe(device_t dev)
65 {
66         const struct pccard_product *pp;
67         u_int32_t       fcn = PCCARD_FUNCTION_UNSPEC;
68         int             error = 0;
69
70         if ((error = pccard_get_function(dev, &fcn)))
71                 return error;
72
73         /* if it says its a disk we should register it */
74         if (fcn == PCCARD_FUNCTION_DISK)
75                 return 0;
76
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))) {
80                 if (pp->pp_name)
81                         device_set_desc(dev, pp->pp_name);
82                 return 0;
83         }
84         return ENXIO;
85 }
86
87 static int
88 slhci_pccard_detach(device_t dev)
89 {
90         struct slhci_softc *sc = device_get_softc(dev);
91         bus_generic_detach(dev);
92
93         if (sc->ih)
94                 bus_teardown_intr(dev, sc->irq_res, sc->ih);
95         if (sc->io_res)
96                 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->io_res);
97         if (sc->irq_res)
98                 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
99         if (sc->sc_bus.bdev)
100                 device_delete_child(dev, sc->sc_bus.bdev);
101         return 0;
102 }
103
104 static int
105 slhci_pccard_attach(device_t dev)
106 {
107         struct slhci_softc *sc = device_get_softc(dev);
108         int             error = ENXIO;
109         int             rid = 0;
110         if ((sc->io_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE)) == NULL) {
111                 return ENOMEM;
112         }
113         sc->sc_iot = rman_get_bustag(sc->io_res);
114         sc->sc_ioh = rman_get_bushandle(sc->io_res);
115
116         if (sl811hs_find(sc) == -1) {
117                 error = ENXIO;
118                 goto out;
119         }
120
121         rid = 0;
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");
124                 error = ENOMEM;
125                 goto out;
126         }
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");
132         }
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);
135         if (error)
136                 goto out;
137 #if 1
138
139         if (slhci_attach(sc) == -1) {
140                 printf("MI attach NO\n");
141                 goto out;
142         }
143
144         error = device_probe_and_attach(sc->sc_bus.bdev);
145
146         if (error) {
147                 printf("Probing USB bus %x\n", error);
148                 goto out;
149         }
150 #endif
151         printf("ATTACHED\n");
152         return 0;
153 out:
154         slhci_pccard_detach(dev);
155         return error;
156 }
157
158 #if 0
159 static void
160 slhci_pccard_enable_power(void *arg, int mode)
161 {
162 #if 0
163         struct slhci_softc *sc = arg;
164         u_int8_t        r;
165 #endif
166 }
167
168 static void
169 slhci_pccard_enable_intr(void *arg, int mode)
170 {
171 #if 0
172         struct slhci_softc *sc = arg;
173         u_int8_t        r;
174 #endif
175 }
176
177 #endif
178 static void
179 slhci_pccard_intr(void *arg)
180 {
181 #if 1
182         struct slhci_softc *sc = arg;
183         sc = sc;
184         slhci_intr(sc);
185 #endif
186 }
187
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),
193
194         {0, 0}
195 };
196
197 static driver_t slhci_pccard_driver = {
198         "slhci",
199         slhci_pccard_methods,
200         sizeof(struct slhci_softc),
201 };
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);