2 * Copyright (c) 2000 Atsushi Onoe <onoe@sm.sony.co.jp>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
25 * $FreeBSD: src/sys/dev/awi/if_awi_pccard.c,v 1.5.2.1 2000/12/07 04:09:39 imp Exp $
26 * $DragonFly: src/sys/dev/netif/awi/Attic/if_awi_pccard.c,v 1.8 2004/03/14 15:36:48 joerg Exp $
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/kernel.h>
32 #include <sys/socket.h>
34 #include <sys/module.h>
37 #include <machine/bus.h>
38 #include <machine/resource.h>
42 #include <net/if_arp.h>
43 #include <net/if_media.h>
44 #include <net/ethernet.h>
45 #include <net/if_ieee80211.h>
47 #include <machine/clock.h>
49 #include "am79c930reg.h"
50 #include "am79c930var.h"
54 #include <bus/pccard/pccardvar.h>
55 #include <bus/pccard/pccarddevs.h>
58 struct awi_pccard_softc {
59 struct awi_softc sc_awi;
61 u_int8_t sc_version[AWI_BANNER_LEN];
64 struct resource *sc_irq_res;
66 struct resource *sc_port_res;
68 struct resource *sc_mem_res;
72 static const struct pccard_product awi_pccard_products[] = {
73 PCMCIA_CARD(AMD, AM79C930, 0),
74 PCMCIA_CARD(BAY, STACK_650, 0),
75 PCMCIA_CARD(BAY, STACK_660, 0),
76 PCMCIA_CARD(BAY, SURFER_PRO, 0),
77 PCMCIA_CARD(ICOM, SL200, 0),
78 PCMCIA_CARD(NOKIA, C020_WLAN, 0),
79 PCMCIA_CARD(FARALLON, SKYLINE, 0),
80 PCMCIA_CARD(ZOOM, AIR_4000, 0),
84 static int awi_pccard_match(device_t);
85 static int awi_pccard_probe(device_t);
86 static int awi_pccard_attach(device_t);
87 static int awi_pccard_detach(device_t);
90 awi_pccard_match(device_t dev)
92 const struct pccard_product *pp;
94 if ((pp = pccard_product_lookup(dev, awi_pccard_products,
95 sizeof(awi_pccard_products[0]), NULL)) != NULL) {
96 if (pp->pp_name != NULL)
97 device_set_desc(dev, pp->pp_name);
104 * Initialize the device - called from Slot manager.
107 awi_pccard_probe(device_t dev)
109 struct awi_pccard_softc *psc = device_get_softc(dev);
110 struct awi_softc *sc = &psc->sc_awi;
113 psc->sc_port_rid = 0;
114 psc->sc_port_res = bus_alloc_resource(dev, SYS_RES_IOPORT,
115 &psc->sc_port_rid, 0, ~0, 16, RF_ACTIVE);
116 if (!psc->sc_port_res)
119 sc->sc_chip.sc_iot = rman_get_bustag(psc->sc_port_res);
120 sc->sc_chip.sc_ioh = rman_get_bushandle(psc->sc_port_res);
121 am79c930_chip_init(&sc->sc_chip, 0);
124 awi_read_bytes(sc, AWI_BANNER, psc->sc_version, AWI_BANNER_LEN);
125 if (memcmp(psc->sc_version, "PCnetMobile:", 12) != 0) {
126 device_printf(dev, "awi_pccard_probe: bad banner: %12D\n",
127 psc->sc_version, " ");
130 device_set_desc(dev, psc->sc_version);
131 bus_release_resource(dev, SYS_RES_IOPORT, psc->sc_port_rid,
138 awi_pccard_attach(device_t dev)
140 struct awi_pccard_softc *psc = device_get_softc(dev);
141 struct awi_softc *sc = &psc->sc_awi;
142 struct ifnet *ifp = &sc->sc_ec.ac_if;
145 psc->sc_port_res = 0;
148 psc->sc_intrhand = 0;
150 ifp->if_dname = device_get_name(dev);
151 if (ifp->if_dname == NULL) {
152 printf("awi%d: awi_pccard_attach: cannot get device name\n",
153 device_get_unit(dev));
156 if_initname(ifp, ifp->if_dname, device_get_unit(dev));
157 strlcpy(sc->sc_dev.dv_xname, ifp->if_xname,
158 sizeof(sc->sc_dev.dv_xname));
160 psc->sc_port_rid = 0;
161 psc->sc_port_res = bus_alloc_resource(dev, SYS_RES_IOPORT,
162 &psc->sc_port_rid, 0, ~0, 16, RF_ACTIVE);
163 if (!psc->sc_port_res) {
164 device_printf(dev, "awi_pccard_attach: port alloc failed\n");
167 sc->sc_chip.sc_iot = rman_get_bustag(psc->sc_port_res);
168 sc->sc_chip.sc_ioh = rman_get_bushandle(psc->sc_port_res);
171 psc->sc_irq_res = bus_alloc_resource(dev, SYS_RES_IRQ,
172 &psc->sc_irq_rid, 0, ~0, 1, RF_ACTIVE);
173 if (!psc->sc_irq_res) {
174 device_printf(dev, "awi_pccard_attach: irq alloc failed\n");
181 * XXX: awi needs to access memory with 8bit,
182 * but pccardd apparently maps memory with MDF_16BITS flag.
183 * So memory mapped access is disabled and use IO port instead.
187 psc->sc_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
188 &psc->sc_mem_rid, 0, ~0, 0x8000, RF_ACTIVE);
190 if (psc->sc_mem_res) {
191 sc->sc_chip.sc_memt = rman_get_bustag(psc->sc_mem_res);
192 sc->sc_chip.sc_memh = rman_get_bushandle(psc->sc_mem_res);
193 am79c930_chip_init(&sc->sc_chip, 1);
195 am79c930_chip_init(&sc->sc_chip, 0);
197 error = bus_setup_intr(dev, psc->sc_irq_res, INTR_TYPE_NET,
198 (void (*)(void *))awi_intr, sc, &psc->sc_intrhand);
200 device_printf(dev, "awi_pccard_attach: intr setup failed\n");
206 sc->sc_ifp = &sc->sc_ec.ac_if;
208 error = awi_attach(sc);
209 sc->sc_enabled = 0; /*XXX*/
212 device_printf(dev, "awi_pccard_attach: awi_attach failed\n");
215 if (psc->sc_intrhand) {
216 bus_teardown_intr(dev, psc->sc_irq_res, psc->sc_intrhand);
217 psc->sc_intrhand = 0;
219 if (psc->sc_port_res) {
220 bus_release_resource(dev, SYS_RES_IOPORT, psc->sc_port_rid,
222 psc->sc_port_res = 0;
224 if (psc->sc_irq_res) {
225 bus_release_resource(dev, SYS_RES_IRQ, psc->sc_irq_rid,
229 if (psc->sc_mem_res) {
230 bus_release_resource(dev, SYS_RES_MEMORY, psc->sc_mem_rid,
240 awi_pccard_detach(device_t dev)
242 struct awi_pccard_softc *psc = device_get_softc(dev);
243 struct awi_softc *sc = &psc->sc_awi;
244 struct ifnet *ifp = &sc->sc_ec.ac_if;
247 ifp->if_flags &= ~IFF_RUNNING;
248 if (psc->sc_intrhand) {
249 bus_teardown_intr(dev, psc->sc_irq_res, psc->sc_intrhand);
250 psc->sc_intrhand = 0;
252 if (psc->sc_port_res) {
253 bus_release_resource(dev, SYS_RES_IOPORT, psc->sc_port_rid,
255 psc->sc_port_res = 0;
257 if (psc->sc_irq_res) {
258 bus_release_resource(dev, SYS_RES_IRQ, psc->sc_irq_rid,
262 if (psc->sc_mem_res) {
263 bus_release_resource(dev, SYS_RES_MEMORY, psc->sc_mem_rid,
270 static device_method_t awi_pccard_methods[] = {
271 /* Device interface */
272 DEVMETHOD(device_probe, pccard_compat_probe),
273 DEVMETHOD(device_attach, pccard_compat_attach),
274 DEVMETHOD(device_detach, awi_pccard_detach),
277 DEVMETHOD(card_compat_match, awi_pccard_match),
278 DEVMETHOD(card_compat_probe, awi_pccard_probe),
279 DEVMETHOD(card_compat_attach, awi_pccard_attach),
284 static driver_t awi_pccard_driver = {
287 sizeof(struct awi_pccard_softc),
290 extern devclass_t awi_devclass;
292 DRIVER_MODULE(if_awi, pccard, awi_pccard_driver, awi_devclass, 0, 0);