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