1 /* $OpenBSD: if_wi_obio.c,v 1.19 2015/11/24 17:11:38 mpi 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_media.h> 57 58 #include <netinet/in.h> 59 #include <netinet/if_ether.h> 60 61 #include <net80211/ieee80211.h> 62 #include <net80211/ieee80211_ioctl.h> 63 #include <net80211/ieee80211_var.h> 64 65 #include <machine/bus.h> 66 #include <machine/autoconf.h> 67 68 #include <dev/ic/if_wireg.h> 69 #include <dev/ic/if_wi_ieee.h> 70 #include <dev/ic/if_wivar.h> 71 72 int wi_obio_match(struct device *, void *, void *); 73 void wi_obio_attach(struct device *, struct device *, void *); 74 int wi_obio_detach(struct device *, int); 75 int wi_obio_activate(struct device *, int); 76 void wi_obio_attach(struct device *, struct device *, void *); 77 int wi_obio_enable(struct wi_softc *sc); 78 void wi_obio_disable(struct wi_softc *sc); 79 80 struct wi_obio_softc { 81 struct wi_softc sc_wi; 82 u_int keywest; 83 }; 84 85 struct cfattach wi_obio_ca = { 86 sizeof (struct wi_obio_softc), wi_obio_match, wi_obio_attach, 87 wi_obio_detach, wi_obio_activate 88 }; 89 90 91 int 92 wi_obio_match(parent, match, aux) 93 struct device *parent; 94 void *match, *aux; 95 { 96 struct confargs *ca = aux; 97 98 if (strcmp(ca->ca_name, "radio") == 0 && 99 ca->ca_nintr >= 4 && ca->ca_nreg >= 8) 100 return (1); 101 return (0); 102 } 103 104 void 105 wi_obio_attach(parent, self, aux) 106 struct device *parent, *self; 107 void *aux; 108 { 109 struct wi_obio_softc *psc = (struct wi_obio_softc *)self; 110 struct wi_softc *sc = &psc->sc_wi; 111 struct confargs *ca = aux; 112 113 printf(" irq %d:", ca->ca_intr[0]); 114 115 sc->wi_btag = ca->ca_iot; 116 ca->ca_reg[0] += ca->ca_baseaddr; 117 if (bus_space_map(sc->wi_btag, ca->ca_reg[0], ca->ca_reg[1], 0, &sc->wi_bhandle)) { 118 printf("can't map i/o space\n"); 119 } 120 /* FSCKING hackery */ 121 psc->keywest = (u_int) mapiodev(0x80000000, 0x1d000); 122 123 /* Establish the interrupt. */ 124 mac_intr_establish(parent, ca->ca_intr[0], IST_LEVEL, IPL_NET, 125 wi_intr, psc, sc->sc_dev.dv_xname); 126 127 /* Make sure interrupts are disabled. */ 128 CSR_WRITE_2(sc, WI_INT_EN, 0); 129 CSR_WRITE_2(sc, WI_EVENT_ACK, 0xffff); 130 131 wi_obio_enable(sc); 132 133 printf("\n"); 134 wi_attach(sc, &wi_func_io); 135 } 136 137 int 138 wi_obio_detach(dev, flags) 139 struct device *dev; 140 int flags; 141 { 142 struct wi_obio_softc *psc = (struct wi_obio_softc *)dev; 143 struct wi_softc *sc = &psc->sc_wi; 144 struct ifnet *ifp = &sc->sc_ic.ic_if; 145 146 /* 147 obio_io_unmap(psc->sc_pf, psc->sc_io_window); 148 obio_io_free(psc->sc_pf, &psc->sc_pcioh); 149 */ 150 151 wi_obio_disable(sc); 152 ether_ifdetach(ifp); 153 if_detach(ifp); 154 155 return (0); 156 } 157 158 int 159 wi_obio_activate(dev, act) 160 struct device *dev; 161 int act; 162 { 163 struct wi_obio_softc *psc = (struct wi_obio_softc *)dev; 164 struct wi_softc *sc = &psc->sc_wi; 165 struct ifnet *ifp = &sc->sc_ic.ic_if; 166 int s; 167 168 s = splnet(); 169 switch (act) { 170 case DVACT_DEACTIVATE: 171 ifp->if_timer = 0; 172 if (ifp->if_flags & IFF_RUNNING) 173 wi_stop(sc); 174 wi_obio_disable(sc); 175 break; 176 } 177 splx(s); 178 return (0); 179 } 180 181 /* THIS IS CRAP */ 182 183 int 184 wi_obio_enable(sc) 185 struct wi_softc *sc; 186 { 187 struct wi_obio_softc *psc = (struct wi_obio_softc *)sc; 188 const u_int keywest = psc->keywest; /* XXX */ 189 const u_int fcr2 = keywest + 0x40; 190 const u_int gpio = keywest + 0x6a; 191 const u_int extint_gpio = keywest + 0x58; 192 u_int x; 193 194 x = in32rb(fcr2); 195 x |= 0x4; 196 out32rb(fcr2, x); 197 198 /* Enable card slot. */ 199 out8(gpio + 0x0f, 5); 200 delay(1000); 201 out8(gpio + 0x0f, 4); 202 delay(1000); 203 204 x = in32rb(fcr2); 205 x &= ~0x8000000; 206 207 out32rb(fcr2, x); 208 /* out8(gpio + 0x10, 4); */ 209 210 out8(extint_gpio + 0x0b, 0); 211 out8(extint_gpio + 0x0a, 0x28); 212 out8(extint_gpio + 0x0d, 0x28); 213 out8(gpio + 0x0d, 0x28); 214 out8(gpio + 0x0e, 0x28); 215 out32rb(keywest + 0x1c000, 0); 216 217 /* Initialize the card. */ 218 out32rb(keywest + 0x1a3e0, 0x41); 219 x = in32rb(fcr2); 220 x |= 0x8000000; 221 out32rb(fcr2, x); 222 223 return 0; 224 } 225 226 void 227 wi_obio_disable(sc) 228 struct wi_softc *sc; 229 { 230 struct wi_obio_softc *psc = (struct wi_obio_softc *)sc; 231 const u_int keywest = psc->keywest; /* XXX */ 232 const u_int fcr2 = keywest + 0x40; 233 u_int x; 234 235 x = in32rb(fcr2); 236 x &= ~0x4; 237 out32rb(fcr2, x); 238 /* out8(gpio + 0x10, 0); */ 239 } 240