2 * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Herb Peyerl.
16 * 4. The name of Herb Peyerl may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * Pccard support for 3C589 by:
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/socket.h>
44 #include <sys/module.h>
47 #include <machine/bus.h>
48 #include <machine/resource.h>
50 #include <net/ethernet.h>
52 #include <net/if_arp.h>
53 #include <net/if_media.h>
55 #include <dev/ep/if_epreg.h>
56 #include <dev/ep/if_epvar.h>
58 #include <dev/pccard/pccardvar.h>
61 #include "pccarddevs.h"
63 static const char *ep_pccard_identify(u_short id);
66 * Initialize the device - called from Slot manager.
69 ep_pccard_probe(device_t dev)
71 struct ep_softc *sc = device_get_softc(dev);
72 struct ep_board *epb = &sc->epb;
77 error = ep_alloc(dev);
82 * It appears that the eeprom comes in two sizes. There's
83 * a 512 byte eeprom and a 2k eeprom. Bit 13 of the eeprom
84 * command register is supposed to contain the size of the
88 * XXX - Certain (newer?) 3Com cards need epb->cmd_off ==
89 * 2. Sadly, you need to have a correct cmd_off in order to
90 * identify the card. So we have to hit it with both and
91 * cross our virtual fingers. There's got to be a better way
92 * to do this. jyoung@accessus.net 09/11/1999
97 /* XXX check return */
98 error = get_e(sc, EEPROM_PROD_ID, &result);
99 epb->prod_id = result;
101 if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) {
103 device_printf(dev, "Pass 1 of 2 detection "
104 "failed (nonfatal) id 0x%x\n", epb->prod_id);
106 /* XXX check return */
107 error = get_e(sc, EEPROM_PROD_ID, &result);
108 epb->prod_id = result;
109 if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) {
110 device_printf(dev, "Unit failed to come ready or "
111 "product ID unknown! (id 0x%x)\n", epb->prod_id);
116 device_set_desc(dev, desc);
119 * Newer cards supported by this device need to have their
122 error = ep_get_macaddr(sc, (u_char *)&sc->arpcom.ac_enaddr);
129 ep_pccard_identify(u_short id)
131 /* Determine device type and associated MII capabilities */
133 case 0x6055: /* 3C556 */
134 return ("3Com 3C556");
135 case 0x4057: /* 3C574 */
136 return ("3Com 3C574");
137 case 0x4b57: /* 3C574B */
138 return ("3Com 3C574B, Megahertz 3CCFE574BT or "
139 "Fast Etherlink 3C574-TX");
140 case 0x2b57: /* 3CXSH572BT */
141 return ("3Com OfficeConnect 572BT");
142 case 0x9058: /* 3C589 */
143 return ("3Com Etherlink III 3C589");
144 case 0x2056: /* 3C562/3C563 */
145 return ("3Com 3C562D/3C563D");
146 case 0x0010: /* 3C1 */
147 return ("3Com Megahertz C1");
149 return ("3Com 3CCEM556");
151 printf("Unknown ID: 0x%x\n", id);
157 ep_pccard_card_attach(struct ep_board * epb)
159 /* Determine device type and associated MII capabilities */
160 switch (epb->prod_id) {
161 case 0x6055: /* 3C556 */
162 case 0x2b57: /* 3C572BT */
163 case 0x4057: /* 3C574 */
164 case 0x4b57: /* 3C574B */
167 case 0x2056: /* 3C562D/3C563D */
168 case 0x9058: /* 3C589 */
169 case 0x0010: /* 3C1 */
170 case 0x0035: /* 3C[XC]EM556 */
179 ep_pccard_attach(device_t dev)
181 struct ep_softc *sc = device_get_softc(dev);
185 if ((error = ep_alloc(dev))) {
186 device_printf(dev, "ep_alloc() failed! (%d)\n", error);
191 /* XXX check return */
192 error = get_e(sc, EEPROM_PROD_ID, &result);
193 sc->epb.prod_id = result;
195 if (!ep_pccard_card_attach(&sc->epb)) {
197 error = get_e(sc, EEPROM_PROD_ID, &result);
198 sc->epb.prod_id = result;
199 error = get_e(sc, EEPROM_RESOURCE_CFG, &result);
200 sc->epb.res_cfg = result;
201 if (!ep_pccard_card_attach(&sc->epb)) {
203 "Probe found ID, attach failed so ignore card!\n");
208 error = get_e(sc, EEPROM_ADDR_CFG, &result);
210 /* ROM size = 0, ROM base = 0 */
211 /* For now, ignore AUTO SELECT feature of 3C589B and later. */
212 CSR_WRITE_2(sc, EP_W0_ADDRESS_CFG, result & 0xc000);
215 * Fake IRQ must be 3 for 3C589 and 3C589B. 3C589D and newer
216 * ignore this value. 3C589C is unknown, as are the other
217 * cards supported by this driver, but it appears to never hurt
221 CSR_WRITE_2(sc, EP_W0_PRODUCT_ID, sc->epb.prod_id);
223 if (sc->epb.mii_trans) {
225 * turn on the MII transciever
228 CSR_WRITE_2(sc, EP_W3_OPTIONS, 0x8040);
230 CSR_WRITE_2(sc, EP_W3_OPTIONS, 0xc040);
231 CSR_WRITE_2(sc, EP_COMMAND, RX_RESET);
232 CSR_WRITE_2(sc, EP_COMMAND, TX_RESET);
235 CSR_WRITE_2(sc, EP_W3_OPTIONS, 0x8040);
239 if ((error = ep_attach(sc))) {
240 device_printf(dev, "ep_attach() failed! (%d)\n", error);
243 if ((error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE, ep_intr,
244 sc, &sc->ep_intrhand))) {
245 device_printf(dev, "bus_setup_intr() failed! (%d)\n", error);
254 static const struct pccard_product ep_pccard_products[] = {
255 PCMCIA_CARD(3COM, 3C1, 0),
256 PCMCIA_CARD(3COM, 3C562, 0),
257 PCMCIA_CARD(3COM, 3C574, 0), /* ROADRUNNER */
258 PCMCIA_CARD(3COM, 3C589, 0),
259 PCMCIA_CARD(3COM, 3CCFEM556BI, 0), /* ROADRUNNER */
260 PCMCIA_CARD(3COM, 3CXEM556, 0),
261 PCMCIA_CARD(3COM, 3CXEM556INT, 0),
266 ep_pccard_match(device_t dev)
268 const struct pccard_product *pp;
270 if ((pp = pccard_product_lookup(dev, ep_pccard_products,
271 sizeof(ep_pccard_products[0]), NULL)) != NULL) {
272 if (pp->pp_name != NULL)
273 device_set_desc(dev, pp->pp_name);
279 static device_method_t ep_pccard_methods[] = {
280 /* Device interface */
281 DEVMETHOD(device_probe, pccard_compat_probe),
282 DEVMETHOD(device_attach, pccard_compat_attach),
283 DEVMETHOD(device_detach, ep_detach),
286 DEVMETHOD(card_compat_match, ep_pccard_match),
287 DEVMETHOD(card_compat_probe, ep_pccard_probe),
288 DEVMETHOD(card_compat_attach, ep_pccard_attach),
293 static driver_t ep_pccard_driver = {
296 sizeof(struct ep_softc),
299 extern devclass_t ep_devclass;
301 DRIVER_MODULE(ep, pccard, ep_pccard_driver, ep_devclass, 0, 0);