1 /*-
2 * Copyright (c) 2000 Atsushi Onoe <onoe@sm.sony.co.jp>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/kernel.h>
32 #include <sys/socket.h>
33
34 #include <sys/module.h>
35 #include <sys/bus.h>
36
37 #include <machine/bus.h>
38 #include <machine/resource.h>
39 #include <sys/rman.h>
40
41 #include <net/if.h>
42 #include <net/if_arp.h>
43 #include <net/if_media.h>
44 #include <net/ethernet.h>
45
46 #include <net80211/ieee80211_var.h>
47
48 #include <dev/awi/am79c930reg.h>
49 #include <dev/awi/am79c930var.h>
50 #include <dev/awi/awireg.h>
51 #include <dev/awi/awivar.h>
52
53 #include <dev/pccard/pccardvar.h>
54
55 #include "card_if.h"
56 #include "pccarddevs.h"
57
58 struct awi_pccard_softc {
59 struct awi_softc sc_awi;
60
61 u_int8_t sc_version[AWI_BANNER_LEN];
62 int sc_intr_mask;
63 void *sc_intrhand;
64 struct resource *sc_irq_res;
65 int sc_irq_rid;
66 struct resource *sc_port_res;
67 int sc_port_rid;
68 struct resource *sc_mem_res;
69 int sc_mem_rid;
70 };
71
72 static const struct pccard_product awi_pccard_products[] = {
73 PCMCIA_CARD(AMD, AM79C930),
74 PCMCIA_CARD(BAY, STACK_650),
75 PCMCIA_CARD(BAY, STACK_660),
76 PCMCIA_CARD(BAY, SURFER_PRO),
77 PCMCIA_CARD(ICOM, SL200),
78 PCMCIA_CARD(NOKIA, C020_WLAN),
79 PCMCIA_CARD(FARALLON, SKYLINE),
80 PCMCIA_CARD(ZOOM, AIR_4000),
81 { NULL }
82 };
83
84 static int awi_pccard_probe(device_t);
85 static int awi_pccard_attach(device_t);
86 static int awi_pccard_detach(device_t);
87 static void awi_pccard_shutdown(device_t);
88 static int awi_pccard_enable(struct awi_softc *);
89 static void awi_pccard_disable(struct awi_softc *);
90
91 static int
92 awi_pccard_probe(device_t dev)
93 {
94 const struct pccard_product *pp;
95
96 if ((pp = pccard_product_lookup(dev, awi_pccard_products,
97 sizeof(awi_pccard_products[0]), NULL)) != NULL) {
98 if (pp->pp_name != NULL)
99 device_set_desc(dev, pp->pp_name);
100 return 0;
101 }
102 return ENXIO;
103 }
104
105 /*
106 * Initialize the device - called from Slot manager.
107 */
108 static int
109 awi_pccard_attach(device_t dev)
110 {
111 struct awi_pccard_softc *psc = device_get_softc(dev);
112 struct awi_softc *sc = &psc->sc_awi;
113 int error = 0;
114
115 psc->sc_port_rid = 0;
116 psc->sc_port_res = bus_alloc_resource(dev, SYS_RES_IOPORT,
117 &psc->sc_port_rid, 0, ~0, AM79C930_IO_SIZE,
118 rman_make_alignment_flags(AM79C930_IO_ALIGN) | RF_ACTIVE);
119 if (!psc->sc_port_res)
120 return ENOMEM;
121
122 sc->sc_chip.sc_iot = rman_get_bustag(psc->sc_port_res);
123 sc->sc_chip.sc_ioh = rman_get_bushandle(psc->sc_port_res);
124 am79c930_chip_init(&sc->sc_chip, 0);
125 tsleep(sc, PWAIT, "awiprb", 1);
126
127 awi_read_bytes(sc, AWI_BANNER, psc->sc_version, AWI_BANNER_LEN);
128 if (memcmp(psc->sc_version, "PCnetMobile:", 12) != 0) {
129 device_printf(dev, "awi_pccard_probe: bad banner: %12D\n",
130 psc->sc_version, " ");
131 error = ENXIO;
132 } else
133 device_set_desc(dev, psc->sc_version);
134
135 psc->sc_irq_res = 0;
136 psc->sc_mem_res = 0;
137 psc->sc_intrhand = 0;
138
139 psc->sc_port_rid = 0;
140 psc->sc_port_res = bus_alloc_resource(dev, SYS_RES_IOPORT,
141 &psc->sc_port_rid, 0, ~0, 16, RF_ACTIVE);
142 if (!psc->sc_port_res) {
143 device_printf(dev, "awi_pccard_attach: port alloc failed\n");
144 goto fail;
145 }
146 sc->sc_chip.sc_iot = rman_get_bustag(psc->sc_port_res);
147 sc->sc_chip.sc_ioh = rman_get_bushandle(psc->sc_port_res);
148
149 psc->sc_irq_rid = 0;
150 psc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ,
151 &psc->sc_irq_rid, RF_ACTIVE);
152 if (!psc->sc_irq_res) {
153 device_printf(dev, "awi_pccard_attach: irq alloc failed\n");
154 goto fail;
155 }
156
157 psc->sc_mem_rid = 0;
158 #if 1
159 /*
160 * XXX: awi needs to access memory with 8bit,
161 * but OLDCARD apparently maps memory with MDF_16BITS flag.
162 * So memory mapped access is disabled and use IO port instead.
163 * XXX: Should check to see if this is true of NEWCARD
164 */
165 psc->sc_mem_res = 0;
166 #else
167 psc->sc_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
168 &psc->sc_mem_rid, 0, ~0, 0x8000, RF_ACTIVE);
169 #endif
170 if (psc->sc_mem_res) {
171 sc->sc_chip.sc_memt = rman_get_bustag(psc->sc_mem_res);
172 sc->sc_chip.sc_memh = rman_get_bushandle(psc->sc_mem_res);
173 am79c930_chip_init(&sc->sc_chip, 1);
174 } else
175 am79c930_chip_init(&sc->sc_chip, 0);
176
177 sc->sc_dev = dev;
178 sc->sc_cansleep = 1;
179 sc->sc_enable = awi_pccard_enable;
180 sc->sc_disable = awi_pccard_disable;
181
182 if (awi_pccard_enable(sc))
183 goto fail;
184 sc->sc_enabled = 1;
185 error = awi_attach(sc);
186 sc->sc_enabled = 0; /*XXX*/
187 awi_pccard_disable(sc);
188 if (error == 0)
189 return 0;
190 device_printf(dev, "awi_pccard_attach: awi_attach failed\n");
191
192 fail:
193 awi_pccard_detach(dev);
194 if (error == 0)
195 error = ENXIO;
196 return error;
197 }
198
199 static int
200 awi_pccard_detach(device_t dev)
201 {
202 struct awi_pccard_softc *psc = device_get_softc(dev);
203 struct awi_softc *sc = &psc->sc_awi;
204
205 awi_detach(sc);
206 if (psc->sc_mem_res) {
207 bus_release_resource(dev, SYS_RES_MEMORY, psc->sc_mem_rid,
208 psc->sc_mem_res);
209 psc->sc_mem_res = 0;
210 }
211 if (psc->sc_irq_res) {
212 bus_release_resource(dev, SYS_RES_IRQ, psc->sc_irq_rid,
213 psc->sc_irq_res);
214 psc->sc_irq_res = 0;
215 }
216 if (psc->sc_port_res) {
217 bus_release_resource(dev, SYS_RES_IOPORT, psc->sc_port_rid,
218 psc->sc_port_res);
219 psc->sc_port_res = 0;
220 }
221 return 0;
222 }
223
224 static void
225 awi_pccard_shutdown(device_t dev)
226 {
227 struct awi_pccard_softc *psc = device_get_softc(dev);
228 struct awi_softc *sc = &psc->sc_awi;
229
230 awi_shutdown(sc);
231 }
232
233 static int
234 awi_pccard_enable(struct awi_softc *sc)
235 {
236 device_t dev = sc->sc_dev;
237 struct awi_pccard_softc *psc = device_get_softc(dev);
238 int error;
239
240 if (psc->sc_intrhand == 0) {
241 error = bus_setup_intr(dev, psc->sc_irq_res, INTR_TYPE_NET,
242 NULL, (void (*)(void *))awi_intr, sc, &psc->sc_intrhand);
243 if (error) {
244 device_printf(dev,
245 "couldn't establish interrupt error=%d\n", error);
246 return error;
247 }
248 }
249 return 0;
250 }
251
252 static void
253 awi_pccard_disable(struct awi_softc *sc)
254 {
255 device_t dev = sc->sc_dev;
256 struct awi_pccard_softc *psc = device_get_softc(dev);
257
258 if (psc->sc_intrhand) {
259 bus_teardown_intr(dev, psc->sc_irq_res, psc->sc_intrhand);
260 psc->sc_intrhand = 0;
261 }
262 }
263
264 static device_method_t awi_pccard_methods[] = {
265 /* Device interface */
266 DEVMETHOD(device_probe, awi_pccard_probe),
267 DEVMETHOD(device_attach, awi_pccard_attach),
268 DEVMETHOD(device_detach, awi_pccard_detach),
269 DEVMETHOD(device_shutdown, awi_pccard_shutdown),
270
271 { 0, 0 }
272 };
273
274 static driver_t awi_pccard_driver = {
275 "awi",
276 awi_pccard_methods,
277 sizeof(struct awi_pccard_softc),
278 };
279
280 extern devclass_t awi_devclass;
281
282 DRIVER_MODULE(awi, pccard, awi_pccard_driver, awi_devclass, 0, 0);
283 MODULE_DEPEND(awi, wlan, 1, 1, 1);
Cache object: 9035552491a81db0f640803d5b061c08
|