xref: /netbsd/sys/arch/macppc/dev/if_wi_obio.c (revision c4a72b64)
1 /*	$NetBSD: if_wi_obio.c,v 1.4 2002/10/02 20:13:48 jdolecek 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 "opt_inet.h"
30 
31 #include <sys/param.h>
32 #include <sys/callout.h>
33 #include <sys/device.h>
34 #include <sys/socket.h>
35 #include <sys/systm.h>
36 
37 #ifdef INET
38 #include <net/if.h>
39 #include <net/if_ether.h>
40 #include <net/if_ieee80211.h>
41 #include <net/if_media.h>
42 #endif
43 
44 #include <machine/autoconf.h>
45 #include <machine/bus.h>
46 
47 #include <dev/ic/wi_ieee.h>
48 #include <dev/ic/wireg.h>
49 #include <dev/ic/wivar.h>
50 
51 int wi_obio_match(struct device *, struct cfdata *, void *);
52 void wi_obio_attach(struct device *, struct device *, void *);
53 int wi_obio_enable(struct wi_softc *);
54 void wi_obio_disable(struct wi_softc *);
55 void wi_obio_powerhook(int, void *);
56 void wi_obio_shutdown(void *);
57 
58 struct wi_obio_softc {
59 	struct wi_softc sc_wi;
60 	void *sc_powerhook;
61 	void *sc_sdhook;
62 };
63 
64 CFATTACH_DECL(wi_obio, sizeof(struct wi_obio_softc),
65     wi_obio_match, wi_obio_attach, NULL, NULL);
66 
67 int
68 wi_obio_match(parent, match, aux)
69 	struct device *parent;
70 	struct cfdata *match;
71 	void *aux;
72 {
73 	struct confargs *ca = aux;
74 
75 	if (ca->ca_nintr < 4 || ca->ca_nreg < 8)
76 		return 0;
77 
78 	if (strcmp(ca->ca_name, "radio") != 0)
79 		return 0;
80 
81 	return 1;
82 }
83 
84 void
85 wi_obio_attach(parent, self, aux)
86 	struct device *parent, *self;
87 	void *aux;
88 {
89 	struct wi_obio_softc *sc = (void *)self;
90 	struct wi_softc *wisc = &sc->sc_wi;
91 	struct confargs *ca = aux;
92 
93 	printf(" irq %d:", ca->ca_intr[0]);
94 	intr_establish(ca->ca_intr[0], IST_LEVEL, IPL_NET, wi_intr, sc);
95 
96 	wisc->sc_iot =
97 	    macppc_make_bus_space_tag(ca->ca_baseaddr + ca->ca_reg[0], 0);
98 	if (bus_space_map(wisc->sc_iot, 0, ca->ca_reg[1], 0, &wisc->sc_ioh)) {
99 		printf(" can't map i/o space\n");
100 		return;
101 	}
102 
103 	wisc->sc_enabled = 1;
104 	wisc->sc_enable = wi_obio_enable;
105 	wisc->sc_disable = wi_obio_disable;
106 
107 	if (wi_attach(wisc)) {
108 		printf("%s: failed to attach controller\n", self->dv_xname);
109 		return;
110 	}
111 
112 	sc->sc_sdhook = shutdownhook_establish(wi_obio_shutdown, sc);
113 	sc->sc_powerhook = powerhook_establish(wi_obio_powerhook, sc);
114 
115 	/* Disable the card. */
116 	wisc->sc_enabled = 0;
117 	wi_obio_disable(wisc);
118 }
119 
120 int
121 wi_obio_enable(sc)
122 	struct wi_softc *sc;
123 {
124 	const u_int keywest = 0x80000000;	/* XXX */
125 	const u_int fcr2 = keywest + 0x40;
126 	const u_int gpio = keywest + 0x6a;
127 	const u_int extint_gpio = keywest + 0x58;
128 	u_int x;
129 
130 	x = in32rb(fcr2);
131 	x |= 0x4;
132 	out32rb(fcr2, x);
133 
134 	/* Enable card slot. */
135 	out8(gpio + 0x0f, 5);
136 	delay(1000);
137 	out8(gpio + 0x0f, 4);
138 	delay(1000);
139 
140 	x = in32rb(fcr2);
141 	x &= ~0x8000000;
142 
143 	out32rb(fcr2, x);
144 	/* out8(gpio + 0x10, 4); */
145 
146 	out8(extint_gpio + 0x0b, 0);
147 	out8(extint_gpio + 0x0a, 0x28);
148 	out8(extint_gpio + 0x0d, 0x28);
149 	out8(gpio + 0x0d, 0x28);
150 	out8(gpio + 0x0e, 0x28);
151 	out32rb(keywest + 0x1c000, 0);
152 
153 	/* Initialize the card. */
154 	out32rb(keywest + 0x1a3e0, 0x41);
155 	x = in32rb(fcr2);
156 	x |= 0x8000000;
157 	out32rb(fcr2, x);
158 
159 	return 0;
160 }
161 
162 void
163 wi_obio_disable(sc)
164 	struct wi_softc *sc;
165 {
166 	const u_int keywest = 0x80000000;	/* XXX */
167 	const u_int fcr2 = keywest + 0x40;
168 	u_int x;
169 
170 	x = in32rb(fcr2);
171 	x &= ~0x4;
172 	out32rb(fcr2, x);
173 	/* out8(gpio + 0x10, 0); */
174 }
175 
176 void
177 wi_obio_powerhook(why, arg)
178 	int why;
179 	void *arg;
180 {
181 	struct wi_softc *sc = arg;
182 
183 	wi_power(sc, why);
184 }
185 
186 void
187 wi_obio_shutdown(arg)
188 	void *arg;
189 {
190 	struct wi_softc *sc = arg;
191 
192 	wi_shutdown(sc);
193 }
194