if_wi_obio.c revision 1.16
11.16Sjmcneill/* $NetBSD: if_wi_obio.c,v 1.16 2007/12/09 20:27:48 jmcneill Exp $ */ 21.1Stsubai 31.1Stsubai/*- 41.1Stsubai * Copyright (c) 2001 Tsubai Masanari. All rights reserved. 51.1Stsubai * 61.1Stsubai * Redistribution and use in source and binary forms, with or without 71.1Stsubai * modification, are permitted provided that the following conditions 81.1Stsubai * are met: 91.1Stsubai * 1. Redistributions of source code must retain the above copyright 101.1Stsubai * notice, this list of conditions and the following disclaimer. 111.1Stsubai * 2. Redistributions in binary form must reproduce the above copyright 121.1Stsubai * notice, this list of conditions and the following disclaimer in the 131.1Stsubai * documentation and/or other materials provided with the distribution. 141.1Stsubai * 3. The name of the author may not be used to endorse or promote products 151.1Stsubai * derived from this software without specific prior written permission. 161.1Stsubai * 171.1Stsubai * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 181.1Stsubai * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 191.1Stsubai * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 201.1Stsubai * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 211.1Stsubai * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 221.1Stsubai * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231.1Stsubai * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241.1Stsubai * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251.1Stsubai * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261.1Stsubai * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 271.1Stsubai */ 281.6Slukem 291.6Slukem#include <sys/cdefs.h> 301.16Sjmcneill__KERNEL_RCSID(0, "$NetBSD: if_wi_obio.c,v 1.16 2007/12/09 20:27:48 jmcneill Exp $"); 311.1Stsubai 321.1Stsubai#include "opt_inet.h" 331.1Stsubai 341.1Stsubai#include <sys/param.h> 351.1Stsubai#include <sys/callout.h> 361.1Stsubai#include <sys/device.h> 371.1Stsubai#include <sys/socket.h> 381.1Stsubai#include <sys/systm.h> 391.1Stsubai 401.1Stsubai#ifdef INET 411.1Stsubai#include <net/if.h> 421.1Stsubai#include <net/if_ether.h> 431.5She#include <net/if_media.h> 441.7Sdyoung#include <net80211/ieee80211_var.h> 451.8Sdyoung#include <net80211/ieee80211_radiotap.h> 461.9Sdyoung#include <net80211/ieee80211_rssadapt.h> 471.1Stsubai#endif 481.1Stsubai 491.1Stsubai#include <machine/autoconf.h> 501.1Stsubai#include <machine/bus.h> 511.1Stsubai 521.1Stsubai#include <dev/ic/wi_ieee.h> 531.1Stsubai#include <dev/ic/wireg.h> 541.1Stsubai#include <dev/ic/wivar.h> 551.1Stsubai 561.14Sgarbledstatic int wi_obio_match(struct device *, struct cfdata *, void *); 571.14Sgarbledstatic void wi_obio_attach(struct device *, struct device *, void *); 581.14Sgarbledstatic int wi_obio_enable(struct wi_softc *); 591.14Sgarbledstatic void wi_obio_disable(struct wi_softc *); 601.1Stsubai 611.1Stsubaistruct wi_obio_softc { 621.1Stsubai struct wi_softc sc_wi; 631.16Sjmcneill pnp_state_t sc_state; 641.14Sgarbled bus_space_tag_t sc_tag; 651.14Sgarbled bus_space_handle_t sc_bsh; 661.14Sgarbled bus_space_handle_t sc_fcr2h; 671.14Sgarbled bus_space_handle_t sc_gpioh; 681.14Sgarbled bus_space_handle_t sc_extint_gpioh; 691.1Stsubai}; 701.1Stsubai 711.3SthorpejCFATTACH_DECL(wi_obio, sizeof(struct wi_obio_softc), 721.3Sthorpej wi_obio_match, wi_obio_attach, NULL, NULL); 731.1Stsubai 741.1Stsubaiint 751.14Sgarbledwi_obio_match(struct device *parent, struct cfdata *match, void *aux) 761.1Stsubai{ 771.1Stsubai struct confargs *ca = aux; 781.1Stsubai 791.1Stsubai if (ca->ca_nintr < 4 || ca->ca_nreg < 8) 801.1Stsubai return 0; 811.1Stsubai 821.1Stsubai if (strcmp(ca->ca_name, "radio") != 0) 831.1Stsubai return 0; 841.1Stsubai 851.1Stsubai return 1; 861.1Stsubai} 871.1Stsubai 881.1Stsubaivoid 891.14Sgarbledwi_obio_attach(struct device *parent, struct device *self, void *aux) 901.1Stsubai{ 911.14Sgarbled struct wi_obio_softc * const sc = (void *)self; 921.14Sgarbled struct wi_softc * const wisc = &sc->sc_wi; 931.14Sgarbled struct confargs * const ca = aux; 941.1Stsubai 951.14Sgarbled aprint_normal(" irq %d:", ca->ca_intr[0]); 961.1Stsubai intr_establish(ca->ca_intr[0], IST_LEVEL, IPL_NET, wi_intr, sc); 971.1Stsubai 981.15Smacallan sc->sc_tag = wisc->sc_iot = ca->ca_tag; 991.14Sgarbled bus_space_map(sc->sc_tag, 0x8000000, 0x20000, 0, &sc->sc_bsh); 1001.14Sgarbled bus_space_subregion(sc->sc_tag, sc->sc_bsh, 0x40, 4, &sc->sc_fcr2h); 1011.14Sgarbled bus_space_subregion(sc->sc_tag, sc->sc_bsh, 0x6a, 16, &sc->sc_gpioh); 1021.14Sgarbled bus_space_subregion(sc->sc_tag, sc->sc_bsh, 0x58, 16, &sc->sc_extint_gpioh); 1031.14Sgarbled 1041.15Smacallan if (bus_space_map(wisc->sc_iot, ca->ca_baseaddr + ca->ca_reg[0], 1051.15Smacallan ca->ca_reg[1], 0, &wisc->sc_ioh)) { 1061.1Stsubai printf(" can't map i/o space\n"); 1071.1Stsubai return; 1081.1Stsubai } 1091.1Stsubai 1101.1Stsubai wisc->sc_enabled = 1; 1111.1Stsubai wisc->sc_enable = wi_obio_enable; 1121.1Stsubai wisc->sc_disable = wi_obio_disable; 1131.1Stsubai 1141.10Smycroft if (wi_attach(wisc, 0)) { 1151.1Stsubai printf("%s: failed to attach controller\n", self->dv_xname); 1161.1Stsubai return; 1171.1Stsubai } 1181.1Stsubai 1191.16Sjmcneill if (!pmf_device_register(self, NULL, NULL)) 1201.16Sjmcneill aprint_error_dev(self, "couldn't establish power handler\n"); 1211.16Sjmcneill else 1221.16Sjmcneill pnp_class_network_register(self, &sc->sc_wi.sc_if); 1231.1Stsubai 1241.1Stsubai /* Disable the card. */ 1251.1Stsubai wisc->sc_enabled = 0; 1261.1Stsubai wi_obio_disable(wisc); 1271.1Stsubai} 1281.1Stsubai 1291.1Stsubaiint 1301.14Sgarbledwi_obio_enable(struct wi_softc *wisc) 1311.1Stsubai{ 1321.14Sgarbled struct wi_obio_softc * const sc = (void *)wisc; 1331.14Sgarbled uint32_t x; 1341.1Stsubai 1351.14Sgarbled x = bus_space_read_4(sc->sc_tag, sc->sc_fcr2h, 0); 1361.1Stsubai x |= 0x4; 1371.14Sgarbled bus_space_write_4(sc->sc_tag, sc->sc_fcr2h, 0, x); 1381.1Stsubai 1391.1Stsubai /* Enable card slot. */ 1401.14Sgarbled bus_space_write_1(sc->sc_tag, sc->sc_gpioh, 0x0f, 5); 1411.1Stsubai delay(1000); 1421.14Sgarbled bus_space_write_1(sc->sc_tag, sc->sc_gpioh, 0x0f, 4); 1431.1Stsubai delay(1000); 1441.14Sgarbled x = bus_space_read_4(sc->sc_tag, sc->sc_fcr2h, 0); 1451.1Stsubai x &= ~0x8000000; 1461.1Stsubai 1471.14Sgarbled bus_space_write_4(sc->sc_tag, sc->sc_fcr2h, 0, x); 1481.1Stsubai /* out8(gpio + 0x10, 4); */ 1491.1Stsubai 1501.14Sgarbled bus_space_write_1(sc->sc_tag, sc->sc_extint_gpioh, 0x0b, 0); 1511.14Sgarbled bus_space_write_1(sc->sc_tag, sc->sc_extint_gpioh, 0x0a, 0x28); 1521.14Sgarbled bus_space_write_1(sc->sc_tag, sc->sc_extint_gpioh, 0x0d, 0x28); 1531.14Sgarbled bus_space_write_1(sc->sc_tag, sc->sc_gpioh, 0x0d, 0x28); 1541.14Sgarbled bus_space_write_1(sc->sc_tag, sc->sc_gpioh, 0x0e, 0x28); 1551.14Sgarbled bus_space_write_4(sc->sc_tag, sc->sc_bsh, 0x1c000, 0); 1561.1Stsubai 1571.1Stsubai /* Initialize the card. */ 1581.14Sgarbled bus_space_write_4(sc->sc_tag, sc->sc_bsh, 0x1a3e0, 0x41); 1591.14Sgarbled x = bus_space_read_4(sc->sc_tag, sc->sc_fcr2h, 0); 1601.1Stsubai x |= 0x8000000; 1611.14Sgarbled bus_space_write_4(sc->sc_tag, sc->sc_fcr2h, 0, x); 1621.1Stsubai 1631.1Stsubai return 0; 1641.1Stsubai} 1651.1Stsubai 1661.1Stsubaivoid 1671.14Sgarbledwi_obio_disable(struct wi_softc *wisc) 1681.1Stsubai{ 1691.14Sgarbled struct wi_obio_softc * const sc = (void *)wisc; 1701.14Sgarbled uint32_t x; 1711.1Stsubai 1721.14Sgarbled x = bus_space_read_4(sc->sc_tag, sc->sc_fcr2h, 0); 1731.1Stsubai x &= ~0x4; 1741.14Sgarbled bus_space_write_4(sc->sc_tag, sc->sc_fcr2h, 0, x); 1751.1Stsubai /* out8(gpio + 0x10, 0); */ 1761.1Stsubai} 177