if_wi_obio.c revision 1.9
1/*	$NetBSD: if_wi_obio.c,v 1.9 2003/12/07 05:44:49 dyoung Exp $	*/
2
3/*-
4 * Copyright (c) 2001 Tsubai Masanari.  All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 *    derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: if_wi_obio.c,v 1.9 2003/12/07 05:44:49 dyoung Exp $");
31
32#include "opt_inet.h"
33
34#include <sys/param.h>
35#include <sys/callout.h>
36#include <sys/device.h>
37#include <sys/socket.h>
38#include <sys/systm.h>
39
40#ifdef INET
41#include <net/if.h>
42#include <net/if_ether.h>
43#include <net/if_media.h>
44#include <net80211/ieee80211_var.h>
45#include <net80211/ieee80211_compat.h>
46#include <net80211/ieee80211_radiotap.h>
47#include <net80211/ieee80211_rssadapt.h>
48#endif
49
50#include <machine/autoconf.h>
51#include <machine/bus.h>
52
53#include <dev/ic/wi_ieee.h>
54#include <dev/ic/wireg.h>
55#include <dev/ic/wivar.h>
56
57int wi_obio_match(struct device *, struct cfdata *, void *);
58void wi_obio_attach(struct device *, struct device *, void *);
59int wi_obio_enable(struct wi_softc *);
60void wi_obio_disable(struct wi_softc *);
61void wi_obio_powerhook(int, void *);
62void wi_obio_shutdown(void *);
63
64struct wi_obio_softc {
65	struct wi_softc sc_wi;
66	void *sc_powerhook;
67	void *sc_sdhook;
68};
69
70CFATTACH_DECL(wi_obio, sizeof(struct wi_obio_softc),
71    wi_obio_match, wi_obio_attach, NULL, NULL);
72
73int
74wi_obio_match(parent, match, aux)
75	struct device *parent;
76	struct cfdata *match;
77	void *aux;
78{
79	struct confargs *ca = aux;
80
81	if (ca->ca_nintr < 4 || ca->ca_nreg < 8)
82		return 0;
83
84	if (strcmp(ca->ca_name, "radio") != 0)
85		return 0;
86
87	return 1;
88}
89
90void
91wi_obio_attach(parent, self, aux)
92	struct device *parent, *self;
93	void *aux;
94{
95	struct wi_obio_softc *sc = (void *)self;
96	struct wi_softc *wisc = &sc->sc_wi;
97	struct confargs *ca = aux;
98
99	printf(" irq %d:", ca->ca_intr[0]);
100	intr_establish(ca->ca_intr[0], IST_LEVEL, IPL_NET, wi_intr, sc);
101
102	wisc->sc_iot =
103	    macppc_make_bus_space_tag(ca->ca_baseaddr + ca->ca_reg[0], 0);
104	if (bus_space_map(wisc->sc_iot, 0, ca->ca_reg[1], 0, &wisc->sc_ioh)) {
105		printf(" can't map i/o space\n");
106		return;
107	}
108
109	wisc->sc_enabled = 1;
110	wisc->sc_enable = wi_obio_enable;
111	wisc->sc_disable = wi_obio_disable;
112
113	if (wi_attach(wisc)) {
114		printf("%s: failed to attach controller\n", self->dv_xname);
115		return;
116	}
117
118	sc->sc_sdhook = shutdownhook_establish(wi_obio_shutdown, sc);
119	sc->sc_powerhook = powerhook_establish(wi_obio_powerhook, sc);
120
121	/* Disable the card. */
122	wisc->sc_enabled = 0;
123	wi_obio_disable(wisc);
124}
125
126int
127wi_obio_enable(sc)
128	struct wi_softc *sc;
129{
130	const u_int keywest = 0x80000000;	/* XXX */
131	const u_int fcr2 = keywest + 0x40;
132	const u_int gpio = keywest + 0x6a;
133	const u_int extint_gpio = keywest + 0x58;
134	u_int x;
135
136	x = in32rb(fcr2);
137	x |= 0x4;
138	out32rb(fcr2, x);
139
140	/* Enable card slot. */
141	out8(gpio + 0x0f, 5);
142	delay(1000);
143	out8(gpio + 0x0f, 4);
144	delay(1000);
145
146	x = in32rb(fcr2);
147	x &= ~0x8000000;
148
149	out32rb(fcr2, x);
150	/* out8(gpio + 0x10, 4); */
151
152	out8(extint_gpio + 0x0b, 0);
153	out8(extint_gpio + 0x0a, 0x28);
154	out8(extint_gpio + 0x0d, 0x28);
155	out8(gpio + 0x0d, 0x28);
156	out8(gpio + 0x0e, 0x28);
157	out32rb(keywest + 0x1c000, 0);
158
159	/* Initialize the card. */
160	out32rb(keywest + 0x1a3e0, 0x41);
161	x = in32rb(fcr2);
162	x |= 0x8000000;
163	out32rb(fcr2, x);
164
165	return 0;
166}
167
168void
169wi_obio_disable(sc)
170	struct wi_softc *sc;
171{
172	const u_int keywest = 0x80000000;	/* XXX */
173	const u_int fcr2 = keywest + 0x40;
174	u_int x;
175
176	x = in32rb(fcr2);
177	x &= ~0x4;
178	out32rb(fcr2, x);
179	/* out8(gpio + 0x10, 0); */
180}
181
182void
183wi_obio_powerhook(why, arg)
184	int why;
185	void *arg;
186{
187	struct wi_softc *sc = arg;
188
189	wi_power(sc, why);
190}
191
192void
193wi_obio_shutdown(arg)
194	void *arg;
195{
196	struct wi_softc *sc = arg;
197
198	wi_shutdown(sc);
199}
200