if_ep_pccard.c revision 119418
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 119418 2003-08-24 17:55:58Z obrien $"); 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 119418 2003-08-24 17:55:58Z obrien $"); 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 94112822Smdodd error = get_e(sc, EEPROM_PROD_ID, &result); /* XXX check return */ 95112822Smdodd epb->prod_id = result; 96112822Smdodd 9752472Simp if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 98117700Smarkm if (bootverbose) 9952472Simp device_printf(dev, "Pass 1 of 2 detection " 10065794Simp "failed (nonfatal) id 0x%x\n", epb->prod_id); 10152472Simp epb->cmd_off = 2; 102112822Smdodd error = get_e(sc, EEPROM_PROD_ID, &result); /* XXX check return */ 103112822Smdodd epb->prod_id = result; 10452589Simp if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 10552472Simp device_printf(dev, "Unit failed to come ready or " 10652472Simp "product ID unknown! (id 0x%x)\n", epb->prod_id); 10752589Simp ep_free(dev); 10852472Simp return (ENXIO); 10952472Simp } 11051673Smdodd } 11152589Simp device_set_desc(dev, desc); 11256017Smdodd 11356017Smdodd /* 11456017Smdodd * For some reason the 3c574 needs this. 11556017Smdodd */ 116112822Smdodd error = ep_get_macaddr(sc, (u_char *)&sc->arpcom.ac_enaddr); 11756017Smdodd 11852589Simp ep_free(dev); 11952472Simp return (0); 12052472Simp} 12151673Smdodd 12252472Simpstatic const char * 12352472Simpep_pccard_identify(u_short id) 12452472Simp{ 12552472Simp /* Determine device type and associated MII capabilities */ 12652472Simp switch (id) { 127117700Smarkm case 0x6055: /* 3C556 */ 12852472Simp return ("3Com 3C556"); 129117700Smarkm case 0x4057: /* 3C574 */ 13052589Simp return ("3Com 3C574"); 131117700Smarkm case 0x4b57: /* 3C574B */ 13252589Simp return ("3Com 3C574B, Megahertz 3CCFE574BT or " 13352472Simp "Fast Etherlink 3C574-TX"); 134117700Smarkm case 0x2b57: /* 3CXSH572BT */ 13555702Simp return ("3Com OfficeConnect 572BT"); 136117700Smarkm case 0x9058: /* 3C589 */ 13752589Simp return ("3Com Etherlink III 3C589"); 138117700Smarkm case 0x2056: /* 3C562/3C563 */ 13952621Simp return ("3Com 3C562D/3C563D"); 140117700Smarkm case 0x0010: /* 3C1 */ 14165794Simp return ("3Com Megahertz C1"); 142117700Smarkm default: 143117700Smarkm return (NULL); 14452472Simp } 14551673Smdodd} 14651673Smdodd 14751673Smdoddstatic int 148117700Smarkmep_pccard_card_attach(struct ep_board * epb) 14951673Smdodd{ 15052472Simp /* Determine device type and associated MII capabilities */ 15152472Simp switch (epb->prod_id) { 152117700Smarkm case 0x6055: /* 3C556 */ 153117700Smarkm case 0x2b57: /* 3C572BT */ 154117700Smarkm case 0x4057: /* 3C574 */ 155117700Smarkm case 0x4b57: /* 3C574B */ 156117700Smarkm case 0x0010: /* 3C1 */ 15752472Simp epb->mii_trans = 1; 15852472Simp return (1); 159117700Smarkm case 0x2056: /* 3C562D/3C563D */ 160117700Smarkm case 0x9058: /* 3C589 */ 16152472Simp epb->mii_trans = 0; 16252472Simp return (1); 163117700Smarkm default: 164117700Smarkm return (0); 16552472Simp } 16651673Smdodd} 16751673Smdodd 16851673Smdoddstatic int 16952472Simpep_pccard_attach(device_t dev) 17051673Smdodd{ 171117700Smarkm struct ep_softc *sc = device_get_softc(dev); 172117700Smarkm u_int16_t result; 173117700Smarkm int error = 0; 17451673Smdodd 17552585Simp if ((error = ep_alloc(dev))) { 17652549Smdodd device_printf(dev, "ep_alloc() failed! (%d)\n", error); 17752472Simp goto bad; 17852472Simp } 17952589Simp sc->epb.cmd_off = 0; 180112822Smdodd 181112822Smdodd error = get_e(sc, EEPROM_PROD_ID, &result); /* XXX check return */ 182112822Smdodd sc->epb.prod_id = result; 183112822Smdodd 18452549Smdodd if (!ep_pccard_card_attach(&sc->epb)) { 18552549Smdodd sc->epb.cmd_off = 2; 186112822Smdodd error = get_e(sc, EEPROM_PROD_ID, &result); 187112822Smdodd sc->epb.prod_id = result; 188112822Smdodd error = get_e(sc, EEPROM_RESOURCE_CFG, &result); 189112822Smdodd sc->epb.res_cfg = result; 19052549Smdodd if (!ep_pccard_card_attach(&sc->epb)) { 19152472Simp device_printf(dev, 19252472Simp "Probe found ID, attach failed so ignore card!\n"); 19352549Smdodd error = ENXIO; 19452549Smdodd goto bad; 19552472Simp } 19652472Simp } 197112822Smdodd error = get_e(sc, EEPROM_ADDR_CFG, &result); 198112822Smdodd 19952472Simp /* ROM size = 0, ROM base = 0 */ 20052472Simp /* For now, ignore AUTO SELECT feature of 3C589B and later. */ 201112822Smdodd outw(BASE + EP_W0_ADDRESS_CFG, result & 0xc000); 20252472Simp 20352472Simp /* Fake IRQ must be 3 */ 20452549Smdodd outw(BASE + EP_W0_RESOURCE_CFG, (sc->epb.res_cfg & 0x0fff) | 0x3000); 20552472Simp 20652549Smdodd outw(BASE + EP_W0_PRODUCT_ID, sc->epb.prod_id); 20752472Simp 20852549Smdodd if (sc->epb.mii_trans) { 20952472Simp /* 21052472Simp * turn on the MII transciever 21152472Simp */ 21252472Simp GO_WINDOW(3); 21352472Simp outw(BASE + EP_W3_OPTIONS, 0x8040); 21452472Simp DELAY(1000); 21552472Simp outw(BASE + EP_W3_OPTIONS, 0xc040); 21652472Simp outw(BASE + EP_COMMAND, RX_RESET); 21752472Simp outw(BASE + EP_COMMAND, TX_RESET); 21852472Simp while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS); 21952472Simp DELAY(1000); 22052472Simp outw(BASE + EP_W3_OPTIONS, 0x8040); 221117700Smarkm } else 22252549Smdodd ep_get_media(sc); 22352472Simp 22452549Smdodd if ((error = ep_attach(sc))) { 22552549Smdodd device_printf(dev, "ep_attach() failed! (%d)\n", error); 22652472Simp goto bad; 22752472Simp } 22852585Simp if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, ep_intr, 229117700Smarkm sc, &sc->ep_intrhand))) { 23052549Smdodd device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); 23152472Simp goto bad; 23252472Simp } 23352549Smdodd return (0); 23452472Simpbad: 23552585Simp ep_free(dev); 23652549Smdodd return (error); 23751673Smdodd} 23851673Smdodd 23970765Speterstatic const struct pccard_product ep_pccard_products[] = { 24086395Simp PCMCIA_CARD(3COM, 3C1, 0), 24186395Simp PCMCIA_CARD(3COM, 3C562, 0), 242117700Smarkm PCMCIA_CARD(3COM, 3C574, 0), /* ROADRUNNER */ 24386394Simp PCMCIA_CARD(3COM, 3C589, 0), 24486395Simp PCMCIA_CARD(3COM, 3CCFEM556BI, 0), /* ROADRUNNER */ 24586394Simp PCMCIA_CARD(3COM, 3CXEM556, 0), 24686394Simp PCMCIA_CARD(3COM, 3CXEM556INT, 0), 247117700Smarkm {NULL} 24870765Speter}; 24970765Speter 25066058Simpstatic int 25166058Simpep_pccard_match(device_t dev) 25266058Simp{ 25370765Speter const struct pccard_product *pp; 25470765Speter 25570765Speter if ((pp = pccard_product_lookup(dev, ep_pccard_products, 256117700Smarkm sizeof(ep_pccard_products[0]), NULL)) != NULL) { 257113315Simp if (pp->pp_name != NULL) 258113315Simp device_set_desc(dev, pp->pp_name); 25970765Speter return 0; 26070765Speter } 26166058Simp return EIO; 26266058Simp} 26366058Simp 26452472Simpstatic device_method_t ep_pccard_methods[] = { 26552472Simp /* Device interface */ 266117700Smarkm DEVMETHOD(device_probe, pccard_compat_probe), 267117700Smarkm DEVMETHOD(device_attach, pccard_compat_attach), 268117700Smarkm DEVMETHOD(device_detach, ep_detach), 26951673Smdodd 27066058Simp /* Card interface */ 271117700Smarkm DEVMETHOD(card_compat_match, ep_pccard_match), 272117700Smarkm DEVMETHOD(card_compat_probe, ep_pccard_probe), 273117700Smarkm DEVMETHOD(card_compat_attach, ep_pccard_attach), 27466058Simp 275117700Smarkm {0, 0} 27652472Simp}; 27751673Smdodd 27852472Simpstatic driver_t ep_pccard_driver = { 27952472Simp "ep", 28052472Simp ep_pccard_methods, 28152549Smdodd sizeof(struct ep_softc), 28252472Simp}; 28351673Smdodd 28452472Simpextern devclass_t ep_devclass; 28552472Simp 28652472SimpDRIVER_MODULE(ep, pccard, ep_pccard_driver, ep_devclass, 0, 0); 287