Annotation of sys/arch/macppc/dev/if_wi_obio.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: if_wi_obio.c,v 1.15 2006/06/19 22:42:33 miod Exp $ */
2:
3: /*
4: * Copyright (c) 1997, 1998, 1999
5: * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by Bill Paul.
18: * 4. Neither the name of the author nor the names of any co-contributors
19: * may be used to endorse or promote products derived from this software
20: * without specific prior written permission.
21: *
22: * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
23: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25: * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
26: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32: * THE POSSIBILITY OF SUCH DAMAGE.
33: *
34: * From: if_wi.c,v 1.7 1999/07/04 14:40:22 wpaul Exp $
35: */
36:
37: /*
38: * Lucent WaveLAN/IEEE 802.11 PCMCIA driver for OpenBSD.
39: *
40: * Originally written by Bill Paul <wpaul@ctr.columbia.edu>
41: * Electrical Engineering Department
42: * Columbia University, New York City
43: */
44: /*
45: * modified for apple obio by Dale Rahn
46: */
47:
48: #include <sys/param.h>
49: #include <sys/systm.h>
50: #include <sys/timeout.h>
51: #include <sys/socket.h>
52: #include <sys/device.h>
53: #include <sys/tree.h>
54:
55: #include <net/if.h>
56: #include <net/if_dl.h>
57: #include <net/if_media.h>
58:
59: #ifdef INET
60: #include <netinet/in.h>
61: #include <netinet/if_ether.h>
62: #endif
63:
64: #include <net80211/ieee80211.h>
65: #include <net80211/ieee80211_ioctl.h>
66: #include <net80211/ieee80211_var.h>
67:
68: #include <machine/bus.h>
69: #include <machine/autoconf.h>
70:
71: #include <dev/ic/if_wireg.h>
72: #include <dev/ic/if_wi_ieee.h>
73: #include <dev/ic/if_wivar.h>
74:
75: int wi_obio_match(struct device *, void *, void *);
76: void wi_obio_attach(struct device *, struct device *, void *);
77: int wi_obio_detach(struct device *, int);
78: int wi_obio_activate(struct device *, enum devact);
79: void wi_obio_attach(struct device *, struct device *, void *);
80: int wi_obio_enable(struct wi_softc *sc);
81: void wi_obio_disable(struct wi_softc *sc);
82:
83: struct wi_obio_softc {
84: struct wi_softc sc_wi;
85: u_int keywest;
86: };
87:
88: struct cfattach wi_obio_ca = {
89: sizeof (struct wi_obio_softc), wi_obio_match, wi_obio_attach,
90: wi_obio_detach, wi_obio_activate
91: };
92:
93:
94: int
95: wi_obio_match(parent, match, aux)
96: struct device *parent;
97: void *match, *aux;
98: {
99: struct confargs *ca = aux;
100:
101: if (strcmp(ca->ca_name, "radio") == 0 &&
102: ca->ca_nintr >= 4 && ca->ca_nreg >= 8)
103: return (1);
104: return (0);
105: }
106:
107: void
108: wi_obio_attach(parent, self, aux)
109: struct device *parent, *self;
110: void *aux;
111: {
112: struct wi_obio_softc *psc = (struct wi_obio_softc *)self;
113: struct wi_softc *sc = &psc->sc_wi;
114: struct confargs *ca = aux;
115:
116: printf(" irq %d:", ca->ca_intr[0]);
117:
118: sc->wi_btag = ca->ca_iot;
119: ca->ca_reg[0] += ca->ca_baseaddr;
120: if (bus_space_map(sc->wi_btag, ca->ca_reg[0], ca->ca_reg[1], 0, &sc->wi_bhandle)) {
121: printf("can't map i/o space\n");
122: }
123: /* FSCKING hackery */
124: psc->keywest = (u_int) mapiodev(0x80000000, 0x1d000);
125:
126: /* Establish the interrupt. */
127: mac_intr_establish(parent, ca->ca_intr[0], IST_LEVEL, IPL_NET,
128: wi_intr, psc, sc->sc_dev.dv_xname);
129:
130: /* Make sure interrupts are disabled. */
131: CSR_WRITE_2(sc, WI_INT_EN, 0);
132: CSR_WRITE_2(sc, WI_EVENT_ACK, 0xffff);
133:
134: wi_obio_enable(sc);
135:
136: printf("\n");
137: wi_attach(sc, &wi_func_io);
138: }
139:
140: int
141: wi_obio_detach(dev, flags)
142: struct device *dev;
143: int flags;
144: {
145: struct wi_obio_softc *psc = (struct wi_obio_softc *)dev;
146: struct wi_softc *sc = &psc->sc_wi;
147: struct ifnet *ifp = &sc->sc_ic.ic_if;
148:
149: /*
150: obio_io_unmap(psc->sc_pf, psc->sc_io_window);
151: obio_io_free(psc->sc_pf, &psc->sc_pcioh);
152: */
153:
154: wi_obio_disable(sc);
155: ether_ifdetach(ifp);
156: if_detach(ifp);
157:
158: return (0);
159: }
160:
161: int
162: wi_obio_activate(dev, act)
163: struct device *dev;
164: enum devact act;
165: {
166: struct wi_obio_softc *psc = (struct wi_obio_softc *)dev;
167: struct wi_softc *sc = &psc->sc_wi;
168: struct ifnet *ifp = &sc->sc_ic.ic_if;
169: int s;
170:
171: s = splnet();
172: switch (act) {
173: case DVACT_ACTIVATE:
174: wi_obio_enable(sc);
175: printf("%s:", WI_PRT_ARG(sc));
176: printf("\n");
177: wi_init(sc);
178: break;
179:
180: case DVACT_DEACTIVATE:
181: ifp->if_timer = 0;
182: if (ifp->if_flags & IFF_RUNNING)
183: wi_stop(sc);
184: wi_obio_disable(sc);
185: break;
186: }
187: splx(s);
188: return (0);
189: }
190:
191: /* THIS IS CRAP */
192:
193: int
194: wi_obio_enable(sc)
195: struct wi_softc *sc;
196: {
197: struct wi_obio_softc *psc = (struct wi_obio_softc *)sc;
198: const u_int keywest = psc->keywest; /* XXX */
199: const u_int fcr2 = keywest + 0x40;
200: const u_int gpio = keywest + 0x6a;
201: const u_int extint_gpio = keywest + 0x58;
202: u_int x;
203:
204: x = in32rb(fcr2);
205: x |= 0x4;
206: out32rb(fcr2, x);
207:
208: /* Enable card slot. */
209: out8(gpio + 0x0f, 5);
210: delay(1000);
211: out8(gpio + 0x0f, 4);
212: delay(1000);
213:
214: x = in32rb(fcr2);
215: x &= ~0x8000000;
216:
217: out32rb(fcr2, x);
218: /* out8(gpio + 0x10, 4); */
219:
220: out8(extint_gpio + 0x0b, 0);
221: out8(extint_gpio + 0x0a, 0x28);
222: out8(extint_gpio + 0x0d, 0x28);
223: out8(gpio + 0x0d, 0x28);
224: out8(gpio + 0x0e, 0x28);
225: out32rb(keywest + 0x1c000, 0);
226:
227: /* Initialize the card. */
228: out32rb(keywest + 0x1a3e0, 0x41);
229: x = in32rb(fcr2);
230: x |= 0x8000000;
231: out32rb(fcr2, x);
232:
233: return 0;
234: }
235:
236: void
237: wi_obio_disable(sc)
238: struct wi_softc *sc;
239: {
240: struct wi_obio_softc *psc = (struct wi_obio_softc *)sc;
241: const u_int keywest = psc->keywest; /* XXX */
242: const u_int fcr2 = keywest + 0x40;
243: u_int x;
244:
245: x = in32rb(fcr2);
246: x &= ~0x4;
247: out32rb(fcr2, x);
248: /* out8(gpio + 0x10, 0); */
249: }
CVSweb