if_wi_obio.c revision 1.22
11.22Smatt/* $NetBSD: if_wi_obio.c,v 1.22 2011/06/18 08:08:28 matt 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.22Smatt__KERNEL_RCSID(0, "$NetBSD: if_wi_obio.c,v 1.22 2011/06/18 08:08:28 matt 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.19Smacallan#include <macppc/dev/obiovar.h> 561.1Stsubai 571.22Smattstatic int wi_obio_match(device_t, cfdata_t, void *); 581.22Smattstatic void wi_obio_attach(device_t, device_t, void *); 591.20Shestatic int wi_obio_enable(device_t, int); 601.1Stsubai 611.1Stsubaistruct wi_obio_softc { 621.1Stsubai struct wi_softc sc_wi; 631.14Sgarbled bus_space_tag_t sc_tag; 641.1Stsubai}; 651.1Stsubai 661.21SmacallanCFATTACH_DECL_NEW(wi_obio, sizeof(struct wi_obio_softc), 671.3Sthorpej wi_obio_match, wi_obio_attach, NULL, NULL); 681.1Stsubai 691.1Stsubaiint 701.22Smattwi_obio_match(device_t parent, cfdata_t match, void *aux) 711.1Stsubai{ 721.1Stsubai struct confargs *ca = aux; 731.1Stsubai 741.1Stsubai if (ca->ca_nintr < 4 || ca->ca_nreg < 8) 751.1Stsubai return 0; 761.1Stsubai 771.1Stsubai if (strcmp(ca->ca_name, "radio") != 0) 781.1Stsubai return 0; 791.1Stsubai 801.1Stsubai return 1; 811.1Stsubai} 821.1Stsubai 831.19Smacallan#define OBIO_WI_FCR2 0x40 841.19Smacallan#define OBIO_WI_GPIO 0x6a 851.19Smacallan#define OBIO_WI_EXTINT 0x58 861.19Smacallan 871.1Stsubaivoid 881.21Smacallanwi_obio_attach(device_t parent, device_t self, void *aux) 891.1Stsubai{ 901.21Smacallan struct wi_obio_softc * const sc = device_private(self); 911.14Sgarbled struct wi_softc * const wisc = &sc->sc_wi; 921.14Sgarbled struct confargs * const ca = aux; 931.1Stsubai 941.14Sgarbled aprint_normal(" irq %d:", ca->ca_intr[0]); 951.1Stsubai intr_establish(ca->ca_intr[0], IST_LEVEL, IPL_NET, wi_intr, sc); 961.1Stsubai 971.21Smacallan wisc->sc_dev = self; 981.15Smacallan sc->sc_tag = wisc->sc_iot = ca->ca_tag; 991.14Sgarbled 1001.15Smacallan if (bus_space_map(wisc->sc_iot, ca->ca_baseaddr + ca->ca_reg[0], 1011.15Smacallan ca->ca_reg[1], 0, &wisc->sc_ioh)) { 1021.1Stsubai printf(" can't map i/o space\n"); 1031.1Stsubai return; 1041.1Stsubai } 1051.1Stsubai 1061.1Stsubai wisc->sc_enabled = 1; 1071.1Stsubai wisc->sc_enable = wi_obio_enable; 1081.1Stsubai 1091.10Smycroft if (wi_attach(wisc, 0)) { 1101.1Stsubai printf("%s: failed to attach controller\n", self->dv_xname); 1111.1Stsubai return; 1121.1Stsubai } 1131.1Stsubai 1141.16Sjmcneill if (!pmf_device_register(self, NULL, NULL)) 1151.16Sjmcneill aprint_error_dev(self, "couldn't establish power handler\n"); 1161.16Sjmcneill else 1171.17Smacallan pmf_class_network_register(self, &sc->sc_wi.sc_if); 1181.1Stsubai 1191.1Stsubai /* Disable the card. */ 1201.1Stsubai wisc->sc_enabled = 0; 1211.20She wi_obio_enable(self, 0); 1221.1Stsubai} 1231.1Stsubai 1241.1Stsubaiint 1251.20Shewi_obio_enable(device_t self, int enable) 1261.1Stsubai{ 1271.14Sgarbled uint32_t x; 1281.1Stsubai 1291.20She if (enable) { 1301.20She x = obio_read_4(OBIO_WI_FCR2); 1311.20She x |= 0x4; 1321.20She obio_write_4(OBIO_WI_FCR2, x); 1331.20She 1341.20She /* Enable card slot. */ 1351.20She obio_write_1(OBIO_WI_GPIO + 0x0f, 5); 1361.20She delay(1000); 1371.20She obio_write_1(OBIO_WI_GPIO + 0x0f, 4); 1381.20She delay(1000); 1391.20She x = obio_read_4(OBIO_WI_FCR2); 1401.20She x &= ~0x8000000; 1411.20She 1421.20She obio_write_4(OBIO_WI_FCR2, x); 1431.20She /* out8(gpio + 0x10, 4); */ 1441.20She 1451.20She obio_write_1(OBIO_WI_EXTINT + 0x0b, 0); 1461.20She obio_write_1(OBIO_WI_EXTINT + 0x0a, 0x28); 1471.20She obio_write_1(OBIO_WI_EXTINT + 0x0d, 0x28); 1481.20She obio_write_1(OBIO_WI_GPIO + 0x0d, 0x28); 1491.20She obio_write_1(OBIO_WI_GPIO + 0x0e, 0x28); 1501.20She obio_write_4(0x1c000, 0); 1511.20She 1521.20She /* Initialize the card. */ 1531.20She obio_write_4(0x1a3e0, 0x41); 1541.20She x = obio_read_4(OBIO_WI_FCR2); 1551.20She x |= 0x8000000; 1561.20She obio_write_4(OBIO_WI_FCR2, x); 1571.20She } else { 1581.20She x = obio_read_4(OBIO_WI_FCR2); 1591.20She x &= ~0x4; 1601.20She obio_write_4(OBIO_WI_FCR2, x); 1611.20She /* out8(gpio + 0x10, 0); */ 1621.20She } 1631.1Stsubai 1641.1Stsubai return 0; 1651.1Stsubai} 166