if_ep_pccard.c revision 119572
151673Smdodd/* 251673Smdodd * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca> 351673Smdodd * All rights reserved. 451673Smdodd * 551673Smdodd * Redistribution and use in source and binary forms, with or without 651673Smdodd * modification, are permitted provided that the following conditions 751673Smdodd * are met: 851673Smdodd * 1. Redistributions of source code must retain the above copyright 951673Smdodd * notice, this list of conditions and the following disclaimer. 1051673Smdodd * 2. Redistributions in binary form must reproduce the above copyright 1151673Smdodd * notice, this list of conditions and the following disclaimer in the 1251673Smdodd * documentation and/or other materials provided with the distribution. 1351673Smdodd * 3. All advertising materials mentioning features or use of this software 1451673Smdodd * must display the following acknowledgement: 1551673Smdodd * This product includes software developed by Herb Peyerl. 1651673Smdodd * 4. The name of Herb Peyerl may not be used to endorse or promote products 1751673Smdodd * derived from this software without specific prior written permission. 1851673Smdodd * 1951673Smdodd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2051673Smdodd * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2151673Smdodd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2251673Smdodd * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2351673Smdodd * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2451673Smdodd * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2551673Smdodd * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2651673Smdodd * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2751673Smdodd * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2851673Smdodd * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2951673Smdodd */ 3051673Smdodd 31119418Sobrien#include <sys/cdefs.h> 32119418Sobrien__FBSDID("$FreeBSD: head/sys/dev/ep/if_ep_pccard.c 119572 2003-08-30 08:10:58Z markm $"); 33119418Sobrien 3451673Smdodd/* 3551673Smdodd * Pccard support for 3C589 by: 3651673Smdodd * HAMADA Naoki 3751673Smdodd * nao@tom-yam.or.jp 3851673Smdodd */ 3951673Smdodd 40117700Smarkm#include <sys/cdefs.h> 41117700Smarkm__FBSDID("$FreeBSD: head/sys/dev/ep/if_ep_pccard.c 119572 2003-08-30 08:10:58Z markm $"); 42117700Smarkm 4351673Smdodd#include <sys/param.h> 4452549Smdodd#include <sys/systm.h> 4551673Smdodd#include <sys/kernel.h> 4651673Smdodd#include <sys/socket.h> 4752549Smdodd#include <sys/module.h> 4852472Simp#include <sys/bus.h> 4952549Smdodd 5052472Simp#include <machine/bus.h> 5152549Smdodd#include <machine/resource.h> 52117700Smarkm 5363090Sarchie#include <net/ethernet.h> 54117700Smarkm#include <net/if.h> 5552549Smdodd#include <net/if_arp.h> 5652549Smdodd#include <net/if_media.h> 5751673Smdodd 5852472Simp#include <dev/ep/if_epreg.h> 5952472Simp#include <dev/ep/if_epvar.h> 6052472Simp 6166058Simp#include <dev/pccard/pccardvar.h> 6270765Speter#include <dev/pccard/pccarddevs.h> 63117700Smarkm 6497645Stakawata#include "card_if.h" 6566058Simp 6652472Simpstatic const char *ep_pccard_identify(u_short id); 6751673Smdodd 6851673Smdodd/* 6951673Smdodd * Initialize the device - called from Slot manager. 7051673Smdodd */ 7151673Smdoddstatic int 7252472Simpep_pccard_probe(device_t dev) 7351673Smdodd{ 74117700Smarkm struct ep_softc *sc = device_get_softc(dev); 75117700Smarkm struct ep_board *epb = &sc->epb; 76117700Smarkm const char *desc; 77117700Smarkm u_int16_t result; 78117700Smarkm int error; 7951673Smdodd 8052589Simp error = ep_alloc(dev); 8152589Simp if (error) 82117700Smarkm return (error); 8352549Smdodd 8452472Simp /* 8552472Simp * XXX - Certain (newer?) 3Com cards need epb->cmd_off == 8652472Simp * 2. Sadly, you need to have a correct cmd_off in order to 8752472Simp * identify the card. So we have to hit it with both and 8852472Simp * cross our virtual fingers. There's got to be a better way 89117700Smarkm * to do this. jyoung@accessus.net 09/11/1999 9052472Simp */ 9151673Smdodd 9252472Simp epb->cmd_off = 0; 93112822Smdodd 94119572Smarkm /* XXX check return */ 95119572Smarkm error = get_e(sc, EEPROM_PROD_ID, &result); 96112822Smdodd epb->prod_id = result; 97112822Smdodd 9852472Simp if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 99117700Smarkm if (bootverbose) 10052472Simp device_printf(dev, "Pass 1 of 2 detection " 10165794Simp "failed (nonfatal) id 0x%x\n", epb->prod_id); 10252472Simp epb->cmd_off = 2; 103119572Smarkm /* XXX check return */ 104119572Smarkm error = get_e(sc, EEPROM_PROD_ID, &result); 105112822Smdodd epb->prod_id = result; 10652589Simp if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 10752472Simp device_printf(dev, "Unit failed to come ready or " 10852472Simp "product ID unknown! (id 0x%x)\n", epb->prod_id); 10952589Simp ep_free(dev); 11052472Simp return (ENXIO); 11152472Simp } 11251673Smdodd } 11352589Simp device_set_desc(dev, desc); 11456017Smdodd 11556017Smdodd /* 11656017Smdodd * For some reason the 3c574 needs this. 11756017Smdodd */ 118112822Smdodd error = ep_get_macaddr(sc, (u_char *)&sc->arpcom.ac_enaddr); 11956017Smdodd 12052589Simp ep_free(dev); 12152472Simp return (0); 12252472Simp} 12351673Smdodd 12452472Simpstatic const char * 12552472Simpep_pccard_identify(u_short id) 12652472Simp{ 12752472Simp /* Determine device type and associated MII capabilities */ 12852472Simp switch (id) { 129117700Smarkm case 0x6055: /* 3C556 */ 13052472Simp return ("3Com 3C556"); 131117700Smarkm case 0x4057: /* 3C574 */ 13252589Simp return ("3Com 3C574"); 133117700Smarkm case 0x4b57: /* 3C574B */ 13452589Simp return ("3Com 3C574B, Megahertz 3CCFE574BT or " 13552472Simp "Fast Etherlink 3C574-TX"); 136117700Smarkm case 0x2b57: /* 3CXSH572BT */ 13755702Simp return ("3Com OfficeConnect 572BT"); 138117700Smarkm case 0x9058: /* 3C589 */ 13952589Simp return ("3Com Etherlink III 3C589"); 140117700Smarkm case 0x2056: /* 3C562/3C563 */ 14152621Simp return ("3Com 3C562D/3C563D"); 142117700Smarkm case 0x0010: /* 3C1 */ 14365794Simp return ("3Com Megahertz C1"); 144117700Smarkm default: 145117700Smarkm return (NULL); 14652472Simp } 14751673Smdodd} 14851673Smdodd 14951673Smdoddstatic int 150117700Smarkmep_pccard_card_attach(struct ep_board * epb) 15151673Smdodd{ 15252472Simp /* Determine device type and associated MII capabilities */ 15352472Simp switch (epb->prod_id) { 154117700Smarkm case 0x6055: /* 3C556 */ 155117700Smarkm case 0x2b57: /* 3C572BT */ 156117700Smarkm case 0x4057: /* 3C574 */ 157117700Smarkm case 0x4b57: /* 3C574B */ 158117700Smarkm case 0x0010: /* 3C1 */ 15952472Simp epb->mii_trans = 1; 16052472Simp return (1); 161117700Smarkm case 0x2056: /* 3C562D/3C563D */ 162117700Smarkm case 0x9058: /* 3C589 */ 16352472Simp epb->mii_trans = 0; 16452472Simp return (1); 165117700Smarkm default: 166117700Smarkm return (0); 16752472Simp } 16851673Smdodd} 16951673Smdodd 17051673Smdoddstatic int 17152472Simpep_pccard_attach(device_t dev) 17251673Smdodd{ 173117700Smarkm struct ep_softc *sc = device_get_softc(dev); 174117700Smarkm u_int16_t result; 175117700Smarkm int error = 0; 17651673Smdodd 17752585Simp if ((error = ep_alloc(dev))) { 17852549Smdodd device_printf(dev, "ep_alloc() failed! (%d)\n", error); 17952472Simp goto bad; 18052472Simp } 18152589Simp sc->epb.cmd_off = 0; 182112822Smdodd 183119572Smarkm /* XXX check return */ 184119572Smarkm error = get_e(sc, EEPROM_PROD_ID, &result); 185112822Smdodd sc->epb.prod_id = result; 186112822Smdodd 18752549Smdodd if (!ep_pccard_card_attach(&sc->epb)) { 18852549Smdodd sc->epb.cmd_off = 2; 189112822Smdodd error = get_e(sc, EEPROM_PROD_ID, &result); 190112822Smdodd sc->epb.prod_id = result; 191112822Smdodd error = get_e(sc, EEPROM_RESOURCE_CFG, &result); 192112822Smdodd sc->epb.res_cfg = result; 19352549Smdodd if (!ep_pccard_card_attach(&sc->epb)) { 19452472Simp device_printf(dev, 19552472Simp "Probe found ID, attach failed so ignore card!\n"); 19652549Smdodd error = ENXIO; 19752549Smdodd goto bad; 19852472Simp } 19952472Simp } 200112822Smdodd error = get_e(sc, EEPROM_ADDR_CFG, &result); 201112822Smdodd 20252472Simp /* ROM size = 0, ROM base = 0 */ 20352472Simp /* For now, ignore AUTO SELECT feature of 3C589B and later. */ 204112822Smdodd outw(BASE + EP_W0_ADDRESS_CFG, result & 0xc000); 20552472Simp 20652472Simp /* Fake IRQ must be 3 */ 20752549Smdodd outw(BASE + EP_W0_RESOURCE_CFG, (sc->epb.res_cfg & 0x0fff) | 0x3000); 20852472Simp 20952549Smdodd outw(BASE + EP_W0_PRODUCT_ID, sc->epb.prod_id); 21052472Simp 21152549Smdodd if (sc->epb.mii_trans) { 21252472Simp /* 21352472Simp * turn on the MII transciever 21452472Simp */ 21552472Simp GO_WINDOW(3); 21652472Simp outw(BASE + EP_W3_OPTIONS, 0x8040); 21752472Simp DELAY(1000); 21852472Simp outw(BASE + EP_W3_OPTIONS, 0xc040); 21952472Simp outw(BASE + EP_COMMAND, RX_RESET); 22052472Simp outw(BASE + EP_COMMAND, TX_RESET); 22152472Simp while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS); 22252472Simp DELAY(1000); 22352472Simp outw(BASE + EP_W3_OPTIONS, 0x8040); 224117700Smarkm } else 22552549Smdodd ep_get_media(sc); 22652472Simp 22752549Smdodd if ((error = ep_attach(sc))) { 22852549Smdodd device_printf(dev, "ep_attach() failed! (%d)\n", error); 22952472Simp goto bad; 23052472Simp } 23152585Simp if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, ep_intr, 232117700Smarkm sc, &sc->ep_intrhand))) { 23352549Smdodd device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); 23452472Simp goto bad; 23552472Simp } 23652549Smdodd return (0); 23752472Simpbad: 23852585Simp ep_free(dev); 23952549Smdodd return (error); 24051673Smdodd} 24151673Smdodd 24270765Speterstatic const struct pccard_product ep_pccard_products[] = { 24386395Simp PCMCIA_CARD(3COM, 3C1, 0), 24486395Simp PCMCIA_CARD(3COM, 3C562, 0), 245117700Smarkm PCMCIA_CARD(3COM, 3C574, 0), /* ROADRUNNER */ 24686394Simp PCMCIA_CARD(3COM, 3C589, 0), 24786395Simp PCMCIA_CARD(3COM, 3CCFEM556BI, 0), /* ROADRUNNER */ 24886394Simp PCMCIA_CARD(3COM, 3CXEM556, 0), 24986394Simp PCMCIA_CARD(3COM, 3CXEM556INT, 0), 250117700Smarkm {NULL} 25170765Speter}; 25270765Speter 25366058Simpstatic int 25466058Simpep_pccard_match(device_t dev) 25566058Simp{ 25670765Speter const struct pccard_product *pp; 25770765Speter 25870765Speter if ((pp = pccard_product_lookup(dev, ep_pccard_products, 259117700Smarkm sizeof(ep_pccard_products[0]), NULL)) != NULL) { 260113315Simp if (pp->pp_name != NULL) 261113315Simp device_set_desc(dev, pp->pp_name); 26270765Speter return 0; 26370765Speter } 26466058Simp return EIO; 26566058Simp} 26666058Simp 26752472Simpstatic device_method_t ep_pccard_methods[] = { 26852472Simp /* Device interface */ 269117700Smarkm DEVMETHOD(device_probe, pccard_compat_probe), 270117700Smarkm DEVMETHOD(device_attach, pccard_compat_attach), 271117700Smarkm DEVMETHOD(device_detach, ep_detach), 27251673Smdodd 27366058Simp /* Card interface */ 274117700Smarkm DEVMETHOD(card_compat_match, ep_pccard_match), 275117700Smarkm DEVMETHOD(card_compat_probe, ep_pccard_probe), 276117700Smarkm DEVMETHOD(card_compat_attach, ep_pccard_attach), 27766058Simp 278117700Smarkm {0, 0} 27952472Simp}; 28051673Smdodd 28152472Simpstatic driver_t ep_pccard_driver = { 28252472Simp "ep", 28352472Simp ep_pccard_methods, 28452549Smdodd sizeof(struct ep_softc), 28552472Simp}; 28651673Smdodd 28752472Simpextern devclass_t ep_devclass; 28852472Simp 28952472SimpDRIVER_MODULE(ep, pccard, ep_pccard_driver, ep_devclass, 0, 0); 290