1 /* $NetBSD: if_wi_obio.c,v 1.1 2001/05/16 10:56:43 tsubai 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 struct cfattach wi_obio_ca = { 65 sizeof(struct wi_obio_softc), wi_obio_match, wi_obio_attach 66 }; 67 68 int 69 wi_obio_match(parent, match, aux) 70 struct device *parent; 71 struct cfdata *match; 72 void *aux; 73 { 74 struct confargs *ca = aux; 75 76 if (ca->ca_nintr < 4 || ca->ca_nreg < 8) 77 return 0; 78 79 if (strcmp(ca->ca_name, "radio") != 0) 80 return 0; 81 82 return 1; 83 } 84 85 void 86 wi_obio_attach(parent, self, aux) 87 struct device *parent, *self; 88 void *aux; 89 { 90 struct wi_obio_softc *sc = (void *)self; 91 struct wi_softc *wisc = &sc->sc_wi; 92 struct confargs *ca = aux; 93 94 printf(" irq %d:", ca->ca_intr[0]); 95 intr_establish(ca->ca_intr[0], IST_LEVEL, IPL_NET, wi_intr, sc); 96 97 wisc->sc_iot = 98 macppc_make_bus_space_tag(ca->ca_baseaddr + ca->ca_reg[0], 0); 99 if (bus_space_map(wisc->sc_iot, 0, ca->ca_reg[1], 0, &wisc->sc_ioh)) { 100 printf(" can't map i/o space\n"); 101 return; 102 } 103 104 wisc->sc_enabled = 1; 105 wisc->sc_enable = wi_obio_enable; 106 wisc->sc_disable = wi_obio_disable; 107 108 wisc->sc_ifp = &wisc->sc_ethercom.ec_if; 109 if (wi_attach(wisc)) { 110 printf("%s: failed to attach controller\n", self->dv_xname); 111 return; 112 } 113 114 sc->sc_sdhook = shutdownhook_establish(wi_obio_shutdown, sc); 115 sc->sc_powerhook = powerhook_establish(wi_obio_powerhook, sc); 116 117 /* Disable the card. */ 118 wisc->sc_enabled = 0; 119 wi_obio_disable(wisc); 120 } 121 122 int 123 wi_obio_enable(sc) 124 struct wi_softc *sc; 125 { 126 const u_int keywest = 0x80000000; /* XXX */ 127 const u_int fcr2 = keywest + 0x40; 128 const u_int gpio = keywest + 0x6a; 129 const u_int extint_gpio = keywest + 0x58; 130 u_int x; 131 132 x = in32rb(fcr2); 133 x |= 0x4; 134 out32rb(fcr2, x); 135 136 /* Enable card slot. */ 137 out8(gpio + 0x0f, 5); 138 delay(1000); 139 out8(gpio + 0x0f, 4); 140 delay(1000); 141 142 x = in32rb(fcr2); 143 x &= ~0x8000000; 144 145 out32rb(fcr2, x); 146 /* out8(gpio + 0x10, 4); */ 147 148 out8(extint_gpio + 0x0b, 0); 149 out8(extint_gpio + 0x0a, 0x28); 150 out8(extint_gpio + 0x0d, 0x28); 151 out8(gpio + 0x0d, 0x28); 152 out8(gpio + 0x0e, 0x28); 153 out32rb(keywest + 0x1c000, 0); 154 155 /* Initialize the card. */ 156 out32rb(keywest + 0x1a3e0, 0x41); 157 x = in32rb(fcr2); 158 x |= 0x8000000; 159 out32rb(fcr2, x); 160 161 return 0; 162 } 163 164 void 165 wi_obio_disable(sc) 166 struct wi_softc *sc; 167 { 168 const u_int keywest = 0x80000000; /* XXX */ 169 const u_int fcr2 = keywest + 0x40; 170 u_int x; 171 172 x = in32rb(fcr2); 173 x &= ~0x4; 174 out32rb(fcr2, x); 175 /* out8(gpio + 0x10, 0); */ 176 } 177 178 void 179 wi_obio_powerhook(why, arg) 180 int why; 181 void *arg; 182 { 183 struct wi_softc *sc = arg; 184 185 wi_power(sc, why); 186 } 187 188 void 189 wi_obio_shutdown(arg) 190 void *arg; 191 { 192 struct wi_softc *sc = arg; 193 194 wi_shutdown(sc); 195 } 196