if_ep_pccard.c revision 121206
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 121206 2003-10-18 15:22:43Z imp $"); 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 121206 2003-10-18 15:22:43Z imp $"); 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 /* 85121206Simp * It appears that the eeprom comes in two sizes. There's 86121206Simp * a 512 byte eeprom and a 2k eeprom. Bit 13 of the eeprom 87121206Simp * command register is supposed to contain the size of the 88121206Simp * eeprom. 89121206Simp */ 90121206Simp /* 9152472Simp * XXX - Certain (newer?) 3Com cards need epb->cmd_off == 9252472Simp * 2. Sadly, you need to have a correct cmd_off in order to 9352472Simp * identify the card. So we have to hit it with both and 9452472Simp * cross our virtual fingers. There's got to be a better way 95117700Smarkm * to do this. jyoung@accessus.net 09/11/1999 9652472Simp */ 9751673Smdodd 9852472Simp epb->cmd_off = 0; 99112822Smdodd 100119572Smarkm /* XXX check return */ 101119572Smarkm error = get_e(sc, EEPROM_PROD_ID, &result); 102112822Smdodd epb->prod_id = result; 103112822Smdodd 10452472Simp if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 105117700Smarkm if (bootverbose) 10652472Simp device_printf(dev, "Pass 1 of 2 detection " 10765794Simp "failed (nonfatal) id 0x%x\n", epb->prod_id); 10852472Simp epb->cmd_off = 2; 109119572Smarkm /* XXX check return */ 110119572Smarkm error = get_e(sc, EEPROM_PROD_ID, &result); 111112822Smdodd epb->prod_id = result; 11252589Simp if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) { 11352472Simp device_printf(dev, "Unit failed to come ready or " 11452472Simp "product ID unknown! (id 0x%x)\n", epb->prod_id); 11552589Simp ep_free(dev); 11652472Simp return (ENXIO); 11752472Simp } 11851673Smdodd } 11952589Simp device_set_desc(dev, desc); 12056017Smdodd 12156017Smdodd /* 12256017Smdodd * For some reason the 3c574 needs this. 12356017Smdodd */ 124112822Smdodd error = ep_get_macaddr(sc, (u_char *)&sc->arpcom.ac_enaddr); 12556017Smdodd 12652589Simp ep_free(dev); 12752472Simp return (0); 12852472Simp} 12951673Smdodd 13052472Simpstatic const char * 13152472Simpep_pccard_identify(u_short id) 13252472Simp{ 13352472Simp /* Determine device type and associated MII capabilities */ 13452472Simp switch (id) { 135117700Smarkm case 0x6055: /* 3C556 */ 13652472Simp return ("3Com 3C556"); 137117700Smarkm case 0x4057: /* 3C574 */ 13852589Simp return ("3Com 3C574"); 139117700Smarkm case 0x4b57: /* 3C574B */ 14052589Simp return ("3Com 3C574B, Megahertz 3CCFE574BT or " 14152472Simp "Fast Etherlink 3C574-TX"); 142117700Smarkm case 0x2b57: /* 3CXSH572BT */ 14355702Simp return ("3Com OfficeConnect 572BT"); 144117700Smarkm case 0x9058: /* 3C589 */ 14552589Simp return ("3Com Etherlink III 3C589"); 146117700Smarkm case 0x2056: /* 3C562/3C563 */ 14752621Simp return ("3Com 3C562D/3C563D"); 148117700Smarkm case 0x0010: /* 3C1 */ 14965794Simp return ("3Com Megahertz C1"); 150117700Smarkm default: 151117700Smarkm return (NULL); 15252472Simp } 15351673Smdodd} 15451673Smdodd 15551673Smdoddstatic int 156117700Smarkmep_pccard_card_attach(struct ep_board * epb) 15751673Smdodd{ 15852472Simp /* Determine device type and associated MII capabilities */ 15952472Simp switch (epb->prod_id) { 160121206Simp case 0x6055: /* 3C556 */ 161121206Simp case 0x2b57: /* 3C572BT */ 162121206Simp case 0x4057: /* 3C574 */ 163121206Simp case 0x4b57: /* 3C574B */ 16452472Simp epb->mii_trans = 1; 16552472Simp return (1); 166117700Smarkm case 0x2056: /* 3C562D/3C563D */ 167117700Smarkm case 0x9058: /* 3C589 */ 168121206Simp case 0x0010: /* 3C1 */ 16952472Simp epb->mii_trans = 0; 17052472Simp return (1); 171117700Smarkm default: 172117700Smarkm return (0); 17352472Simp } 17451673Smdodd} 17551673Smdodd 17651673Smdoddstatic int 17752472Simpep_pccard_attach(device_t dev) 17851673Smdodd{ 179117700Smarkm struct ep_softc *sc = device_get_softc(dev); 180117700Smarkm u_int16_t result; 181117700Smarkm int error = 0; 18251673Smdodd 18352585Simp if ((error = ep_alloc(dev))) { 18452549Smdodd device_printf(dev, "ep_alloc() failed! (%d)\n", error); 18552472Simp goto bad; 18652472Simp } 18752589Simp sc->epb.cmd_off = 0; 188112822Smdodd 189119572Smarkm /* XXX check return */ 190119572Smarkm error = get_e(sc, EEPROM_PROD_ID, &result); 191112822Smdodd sc->epb.prod_id = result; 192112822Smdodd 19352549Smdodd if (!ep_pccard_card_attach(&sc->epb)) { 19452549Smdodd sc->epb.cmd_off = 2; 195112822Smdodd error = get_e(sc, EEPROM_PROD_ID, &result); 196112822Smdodd sc->epb.prod_id = result; 197112822Smdodd error = get_e(sc, EEPROM_RESOURCE_CFG, &result); 198112822Smdodd sc->epb.res_cfg = result; 19952549Smdodd if (!ep_pccard_card_attach(&sc->epb)) { 20052472Simp device_printf(dev, 20152472Simp "Probe found ID, attach failed so ignore card!\n"); 20252549Smdodd error = ENXIO; 20352549Smdodd goto bad; 20452472Simp } 20552472Simp } 206112822Smdodd error = get_e(sc, EEPROM_ADDR_CFG, &result); 207112822Smdodd 20852472Simp /* ROM size = 0, ROM base = 0 */ 20952472Simp /* For now, ignore AUTO SELECT feature of 3C589B and later. */ 210121206Simp EP_WRITE_2(sc, EP_W0_ADDRESS_CFG, result & 0xc000); 21152472Simp 21252472Simp /* Fake IRQ must be 3 */ 213121206Simp EP_WRITE_2(sc, EP_W0_RESOURCE_CFG, (sc->epb.res_cfg & 0x0fff) | 0x3000); 21452472Simp 215121206Simp EP_WRITE_2(sc, EP_W0_PRODUCT_ID, sc->epb.prod_id); 21652472Simp 21752549Smdodd if (sc->epb.mii_trans) { 21852472Simp /* 21952472Simp * turn on the MII transciever 22052472Simp */ 22152472Simp GO_WINDOW(3); 222121206Simp EP_WRITE_2(sc, EP_W3_OPTIONS, 0x8040); 22352472Simp DELAY(1000); 224121206Simp EP_WRITE_2(sc, EP_W3_OPTIONS, 0xc040); 225121206Simp EP_WRITE_2(sc, EP_COMMAND, RX_RESET); 226121206Simp EP_WRITE_2(sc, EP_COMMAND, TX_RESET); 227121206Simp while (EP_READ_2(sc, EP_STATUS) & S_COMMAND_IN_PROGRESS); 22852472Simp DELAY(1000); 229121206Simp EP_WRITE_2(sc, EP_W3_OPTIONS, 0x8040); 230117700Smarkm } else 23152549Smdodd ep_get_media(sc); 23252472Simp 23352549Smdodd if ((error = ep_attach(sc))) { 23452549Smdodd device_printf(dev, "ep_attach() failed! (%d)\n", error); 23552472Simp goto bad; 23652472Simp } 23752585Simp if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, ep_intr, 238117700Smarkm sc, &sc->ep_intrhand))) { 23952549Smdodd device_printf(dev, "bus_setup_intr() failed! (%d)\n", error); 24052472Simp goto bad; 24152472Simp } 24252549Smdodd return (0); 24352472Simpbad: 24452585Simp ep_free(dev); 24552549Smdodd return (error); 24651673Smdodd} 24751673Smdodd 24870765Speterstatic const struct pccard_product ep_pccard_products[] = { 24986395Simp PCMCIA_CARD(3COM, 3C1, 0), 25086395Simp PCMCIA_CARD(3COM, 3C562, 0), 251117700Smarkm PCMCIA_CARD(3COM, 3C574, 0), /* ROADRUNNER */ 25286394Simp PCMCIA_CARD(3COM, 3C589, 0), 25386395Simp PCMCIA_CARD(3COM, 3CCFEM556BI, 0), /* ROADRUNNER */ 25486394Simp PCMCIA_CARD(3COM, 3CXEM556, 0), 25586394Simp PCMCIA_CARD(3COM, 3CXEM556INT, 0), 256117700Smarkm {NULL} 25770765Speter}; 25870765Speter 25966058Simpstatic int 26066058Simpep_pccard_match(device_t dev) 26166058Simp{ 26270765Speter const struct pccard_product *pp; 26370765Speter 26470765Speter if ((pp = pccard_product_lookup(dev, ep_pccard_products, 265117700Smarkm sizeof(ep_pccard_products[0]), NULL)) != NULL) { 266113315Simp if (pp->pp_name != NULL) 267113315Simp device_set_desc(dev, pp->pp_name); 26870765Speter return 0; 26970765Speter } 27066058Simp return EIO; 27166058Simp} 27266058Simp 27352472Simpstatic device_method_t ep_pccard_methods[] = { 27452472Simp /* Device interface */ 275117700Smarkm DEVMETHOD(device_probe, pccard_compat_probe), 276117700Smarkm DEVMETHOD(device_attach, pccard_compat_attach), 277117700Smarkm DEVMETHOD(device_detach, ep_detach), 27851673Smdodd 27966058Simp /* Card interface */ 280117700Smarkm DEVMETHOD(card_compat_match, ep_pccard_match), 281117700Smarkm DEVMETHOD(card_compat_probe, ep_pccard_probe), 282117700Smarkm DEVMETHOD(card_compat_attach, ep_pccard_attach), 28366058Simp 284117700Smarkm {0, 0} 28552472Simp}; 28651673Smdodd 28752472Simpstatic driver_t ep_pccard_driver = { 28852472Simp "ep", 28952472Simp ep_pccard_methods, 29052549Smdodd sizeof(struct ep_softc), 29152472Simp}; 29251673Smdodd 29352472Simpextern devclass_t ep_devclass; 29452472Simp 29552472SimpDRIVER_MODULE(ep, pccard, ep_pccard_driver, ep_devclass, 0, 0); 296