xref: /openbsd/sys/arch/macppc/dev/if_wi_obio.c (revision 898184e3)
1 /*	$OpenBSD: if_wi_obio.c,v 1.17 2011/07/03 15:47:16 matthew 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 *, int);
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 	int 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_DEACTIVATE:
174 		ifp->if_timer = 0;
175 		if (ifp->if_flags & IFF_RUNNING)
176 			wi_stop(sc);
177 		wi_obio_disable(sc);
178 		break;
179 	}
180 	splx(s);
181 	return (0);
182 }
183 
184 /* THIS IS CRAP */
185 
186 int
187 wi_obio_enable(sc)
188 	struct wi_softc *sc;
189 {
190 	struct wi_obio_softc *psc = (struct wi_obio_softc *)sc;
191 	const u_int keywest = psc->keywest;	/* XXX */
192 	const u_int fcr2 = keywest + 0x40;
193 	const u_int gpio = keywest + 0x6a;
194 	const u_int extint_gpio = keywest + 0x58;
195 	u_int x;
196 
197 	x = in32rb(fcr2);
198 	x |= 0x4;
199 	out32rb(fcr2, x);
200 
201 	/* Enable card slot. */
202 	out8(gpio + 0x0f, 5);
203 	delay(1000);
204 	out8(gpio + 0x0f, 4);
205 	delay(1000);
206 
207 	x = in32rb(fcr2);
208 	x &= ~0x8000000;
209 
210 	out32rb(fcr2, x);
211 	/* out8(gpio + 0x10, 4); */
212 
213 	out8(extint_gpio + 0x0b, 0);
214 	out8(extint_gpio + 0x0a, 0x28);
215 	out8(extint_gpio + 0x0d, 0x28);
216 	out8(gpio + 0x0d, 0x28);
217 	out8(gpio + 0x0e, 0x28);
218 	out32rb(keywest + 0x1c000, 0);
219 
220 	/* Initialize the card. */
221 	out32rb(keywest + 0x1a3e0, 0x41);
222 	x = in32rb(fcr2);
223 	x |= 0x8000000;
224 	out32rb(fcr2, x);
225 
226 	return 0;
227 }
228 
229 void
230 wi_obio_disable(sc)
231 	struct wi_softc *sc;
232 {
233 	struct wi_obio_softc *psc = (struct wi_obio_softc *)sc;
234 	const u_int keywest = psc->keywest;	/* XXX */
235 	const u_int fcr2 = keywest + 0x40;
236 	u_int x;
237 
238 	x = in32rb(fcr2);
239 	x &= ~0x4;
240 	out32rb(fcr2, x);
241 	/* out8(gpio + 0x10, 0); */
242 }
243