summaryrefslogtreecommitdiff
path: root/sys/arch/macppc/dev/if_wi_obio.c
blob: 3663d52b169c68ecd78eb69cea73a8a79dfb4a53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*	$OpenBSD: if_wi_obio.c,v 1.15 2006/06/19 22:42:33 miod Exp $	*/

/*
 * Copyright (c) 1997, 1998, 1999
 *	Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by Bill Paul.
 * 4. Neither the name of the author nor the names of any co-contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 *
 *	From: if_wi.c,v 1.7 1999/07/04 14:40:22 wpaul Exp $
 */

/*
 * Lucent WaveLAN/IEEE 802.11 PCMCIA driver for OpenBSD.
 *
 * Originally written by Bill Paul <wpaul@ctr.columbia.edu>
 * Electrical Engineering Department
 * Columbia University, New York City
 */
 /* 
  * modified for apple obio by Dale Rahn
  */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/timeout.h>
#include <sys/socket.h>
#include <sys/device.h>
#include <sys/tree.h>

#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_media.h>

#ifdef INET
#include <netinet/in.h>
#include <netinet/if_ether.h>
#endif

#include <net80211/ieee80211.h>
#include <net80211/ieee80211_ioctl.h>
#include <net80211/ieee80211_var.h>

#include <machine/bus.h>
#include <machine/autoconf.h>

#include <dev/ic/if_wireg.h>
#include <dev/ic/if_wi_ieee.h>
#include <dev/ic/if_wivar.h>

int	wi_obio_match(struct device *, void *, void *);
void	wi_obio_attach(struct device *, struct device *, void *);
int	wi_obio_detach(struct device *, int);
int	wi_obio_activate(struct device *, enum devact);
void	wi_obio_attach(struct device *, struct device *, void *);
int	wi_obio_enable(struct wi_softc *sc);
void	wi_obio_disable(struct wi_softc *sc);

struct wi_obio_softc {
	struct wi_softc sc_wi;
	u_int keywest;
};

struct cfattach wi_obio_ca = {
	sizeof (struct wi_obio_softc), wi_obio_match, wi_obio_attach,
	wi_obio_detach, wi_obio_activate
};


int
wi_obio_match(parent, match, aux)
	struct device *parent;
	void *match, *aux;
{
	struct confargs *ca = aux;

	if (strcmp(ca->ca_name, "radio") == 0 &&
	    ca->ca_nintr >= 4 && ca->ca_nreg >= 8) 
		return (1);
	return (0);
}

void
wi_obio_attach(parent, self, aux)
	struct device *parent, *self;
	void *aux;
{
	struct wi_obio_softc	*psc = (struct wi_obio_softc *)self;
	struct wi_softc		*sc = &psc->sc_wi;
	struct confargs		*ca = aux;

	printf(" irq %d:", ca->ca_intr[0]);

	sc->wi_btag = ca->ca_iot;
	ca->ca_reg[0] += ca->ca_baseaddr;
	if (bus_space_map(sc->wi_btag, ca->ca_reg[0], ca->ca_reg[1], 0, &sc->wi_bhandle)) {
		printf("can't map i/o space\n");
	}
	/* FSCKING hackery */
	psc->keywest = (u_int) mapiodev(0x80000000, 0x1d000);

	/* Establish the interrupt. */
	mac_intr_establish(parent, ca->ca_intr[0], IST_LEVEL, IPL_NET,
		wi_intr, psc, sc->sc_dev.dv_xname);

	/* Make sure interrupts are disabled. */
	CSR_WRITE_2(sc, WI_INT_EN, 0);
	CSR_WRITE_2(sc, WI_EVENT_ACK, 0xffff);

	wi_obio_enable(sc);

	printf("\n");
	wi_attach(sc, &wi_func_io);
}

int
wi_obio_detach(dev, flags)
	struct device *dev;
	int flags;
{
	struct wi_obio_softc *psc = (struct wi_obio_softc *)dev;
	struct wi_softc *sc = &psc->sc_wi;
	struct ifnet *ifp = &sc->sc_ic.ic_if;

	/*
	obio_io_unmap(psc->sc_pf, psc->sc_io_window);
	obio_io_free(psc->sc_pf, &psc->sc_pcioh);
	*/

	wi_obio_disable(sc);
	ether_ifdetach(ifp);
	if_detach(ifp);

	return (0);
}

int
wi_obio_activate(dev, act)
	struct device *dev;
	enum devact act;
{
	struct wi_obio_softc *psc = (struct wi_obio_softc *)dev;
	struct wi_softc *sc = &psc->sc_wi;
	struct ifnet *ifp = &sc->sc_ic.ic_if;
	int s;

	s = splnet();
	switch (act) {
	case DVACT_ACTIVATE:
		wi_obio_enable(sc);
		printf("%s:", WI_PRT_ARG(sc));
		printf("\n");
		wi_init(sc);
		break;

	case DVACT_DEACTIVATE:
		ifp->if_timer = 0;
		if (ifp->if_flags & IFF_RUNNING)
			wi_stop(sc);
		wi_obio_disable(sc);
		break;
	}
	splx(s);
	return (0);
}

/* THIS IS CRAP */

int
wi_obio_enable(sc)
	struct wi_softc *sc;
{
	struct wi_obio_softc *psc = (struct wi_obio_softc *)sc;
	const u_int keywest = psc->keywest;	/* XXX */
	const u_int fcr2 = keywest + 0x40;
	const u_int gpio = keywest + 0x6a;
	const u_int extint_gpio = keywest + 0x58;
	u_int x;

	x = in32rb(fcr2);
	x |= 0x4;
	out32rb(fcr2, x);

	/* Enable card slot. */
	out8(gpio + 0x0f, 5);
	delay(1000);
	out8(gpio + 0x0f, 4);
	delay(1000);

	x = in32rb(fcr2);
	x &= ~0x8000000;

	out32rb(fcr2, x);
	/* out8(gpio + 0x10, 4); */

	out8(extint_gpio + 0x0b, 0);
	out8(extint_gpio + 0x0a, 0x28);
	out8(extint_gpio + 0x0d, 0x28);
	out8(gpio + 0x0d, 0x28);
	out8(gpio + 0x0e, 0x28);
	out32rb(keywest + 0x1c000, 0);

	/* Initialize the card. */
	out32rb(keywest + 0x1a3e0, 0x41);
	x = in32rb(fcr2);
	x |= 0x8000000;
	out32rb(fcr2, x);

	return 0;
}

void
wi_obio_disable(sc)
	struct wi_softc *sc;
{
	struct wi_obio_softc *psc = (struct wi_obio_softc *)sc;
	const u_int keywest = psc->keywest;	/* XXX */
	const u_int fcr2 = keywest + 0x40;
	u_int x;

	x = in32rb(fcr2);
	x &= ~0x4;
	out32rb(fcr2, x);
	/* out8(gpio + 0x10, 0); */
}