Home | History | Annotate | Line # | Download | only in isa
if_cs_isa.c revision 1.1
      1 /*	$NetBSD: if_cs_isa.c,v 1.1 1998/07/27 01:20:43 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright 1997
      5  * Digital Equipment Corporation. All rights reserved.
      6  *
      7  * This software is furnished under license and may be used and
      8  * copied only in accordance with the following terms and conditions.
      9  * Subject to these conditions, you may download, copy, install,
     10  * use, modify and distribute this software in source and/or binary
     11  * form. No title or ownership is transferred hereby.
     12  *
     13  * 1) Any source code used, modified or distributed must reproduce
     14  *    and retain this copyright notice and list of conditions as
     15  *    they appear in the source file.
     16  *
     17  * 2) No right is granted to use any trade name, trademark, or logo of
     18  *    Digital Equipment Corporation. Neither the "Digital Equipment
     19  *    Corporation" name nor any trademark or logo of Digital Equipment
     20  *    Corporation may be used to endorse or promote products derived
     21  *    from this software without the prior written permission of
     22  *    Digital Equipment Corporation.
     23  *
     24  * 3) This software is provided "AS-IS" and any express or implied
     25  *    warranties, including but not limited to, any implied warranties
     26  *    of merchantability, fitness for a particular purpose, or
     27  *    non-infringement are disclaimed. In no event shall DIGITAL be
     28  *    liable for any damages whatsoever, and in particular, DIGITAL
     29  *    shall not be liable for special, indirect, consequential, or
     30  *    incidental damages or damages for lost profits, loss of
     31  *    revenue or loss of use, whether such damages arise in contract,
     32  *    negligence, tort, under statute, in equity, at law or otherwise,
     33  *    even if advised of the possibility of such damage.
     34  */
     35 
     36 #include <sys/param.h>
     37 #include <sys/systm.h>
     38 #include <sys/socket.h>
     39 #include <sys/device.h>
     40 
     41 #include <net/if.h>
     42 #include <net/if_ether.h>
     43 #include <net/if_media.h>
     44 
     45 #include <machine/bus.h>
     46 #include <machine/intr.h>
     47 
     48 #include <dev/isa/isareg.h>
     49 #include <dev/isa/isavar.h>
     50 #include <dev/isa/isadmavar.h>
     51 
     52 #include <dev/isa/cs89x0reg.h>
     53 #include <dev/isa/cs89x0var.h>
     54 
     55 int	cs_isa_probe __P((struct device *, struct cfdata *, void *));
     56 void	cs_isa_attach __P((struct device *, struct device *, void *));
     57 
     58 struct cfattach cs_ca = {
     59 	sizeof(struct cs_softc), cs_isa_probe, cs_isa_attach
     60 };
     61 
     62 int
     63 cs_isa_probe(parent, cf, aux)
     64 	struct device *parent;
     65 	struct cfdata *cf;
     66 	void *aux;
     67 {
     68 	struct isa_attach_args *ia = aux;
     69 	bus_space_tag_t iot = ia->ia_iot;
     70 	bus_space_tag_t memt = ia->ia_memt;
     71 	bus_space_handle_t ioh, memh;
     72 	int rv = 0, have_io = 0, have_mem = 0;
     73 	u_int16_t isa_cfg, isa_membase;
     74 	bus_addr_t maddr = ia->ia_maddr;
     75 	int irq = ia->ia_irq;
     76 
     77 	/*
     78 	 * Disallow wildcarded I/O base.
     79 	 */
     80 	if (ia->ia_iobase == ISACF_PORT_DEFAULT)
     81 		return (0);
     82 
     83 	/*
     84 	 * Map the I/O space.
     85 	 */
     86 	if (bus_space_map(ia->ia_iot, ia->ia_iobase, CS8900_IOSIZE, 0, &ioh))
     87 		goto out;
     88 	have_io = 1;
     89 
     90 	/* Verify that it's a Crystal product. */
     91 	if (CS_READ_PACKET_PAGE_IO(iot, ioh, PKTPG_EISA_NUM) !=
     92 	    EISA_NUM_CRYSTAL)
     93 		goto out;
     94 
     95 	/*
     96 	 * Verify that it's a supported chip.
     97 	 */
     98 	switch (CS_READ_PACKET_PAGE_IO(iot, ioh, PKTPG_PRODUCT_ID) &
     99 	    PROD_ID_MASK) {
    100 	case PROD_ID_CS8900:
    101 #ifdef notyet
    102 	case PROD_ID_CS8920:
    103 	case PROD_ID_CS8920M:
    104 #endif
    105 		rv = 1;
    106 	}
    107 
    108 	/*
    109 	 * If the IRQ or memory address were not specified, read the
    110 	 * ISA_CFG EEPROM location.
    111 	 */
    112 	if (maddr == ISACF_IOMEM_DEFAULT || irq == ISACF_IRQ_DEFAULT) {
    113 		if (cs_verify_eeprom(iot, ioh) == CS_ERROR) {
    114 			printf("cs_isa_probe: EEPROM bad or missing\n");
    115 			goto out;
    116 		}
    117 		if (cs_read_eeprom(iot, ioh, EEPROM_ISA_CFG, &isa_cfg)
    118 		    == CS_ERROR) {
    119 			printf("cs_isa_probe: unable to read ISA_CFG\n");
    120 			goto out;
    121 		}
    122 	}
    123 
    124 	/*
    125 	 * If the IRQ wasn't specified, get it from the EEPROM.
    126 	 */
    127 	if (irq == ISACF_IRQ_DEFAULT) {
    128 		irq = isa_cfg & ISA_CFG_IRQ_MASK;
    129 		if (irq == 3)
    130 			irq = 5;
    131 		else
    132 			irq += 10;
    133 	}
    134 
    135 	/*
    136 	 * If the memory address wasn't specified, get it from the EEPROM.
    137 	 */
    138 	if (maddr == ISACF_IOMEM_DEFAULT) {
    139 		if ((isa_cfg & ISA_CFG_MEM_MODE) == 0) {
    140 			/* EEPROM says don't use memory mode. */
    141 			goto out;
    142 		}
    143 		if (cs_read_eeprom(iot, ioh, EEPROM_MEM_BASE, &isa_membase)
    144 		    == CS_ERROR) {
    145 			printf("cs_isa_probe: unable to read MEM_BASE\n");
    146 			goto out;
    147 		}
    148 
    149 		isa_membase &= MEM_BASE_MASK;
    150 		maddr = (int)isa_membase << 8;
    151 	}
    152 
    153 	/*
    154 	 * We now have a valid mem address; attempt to map it.
    155 	 */
    156 	if (bus_space_map(ia->ia_memt, maddr, CS8900_MEMSIZE, 0, &memh)) {
    157 		/* Can't map it; fall back on i/o-only mode. */
    158 		printf("cs_isa_probe: unable to map memory space\n");
    159 		maddr = ISACF_IOMEM_DEFAULT;
    160 	} else
    161 		have_mem = 1;
    162 
    163  out:
    164 	if (have_io)
    165 		bus_space_unmap(iot, ioh, CS8900_IOSIZE);
    166 	if (have_mem)
    167 		bus_space_unmap(memt, memh, CS8900_MEMSIZE);
    168 
    169 	if (rv) {
    170 		ia->ia_iosize = CS8900_IOSIZE;
    171 		ia->ia_maddr = maddr;
    172 		ia->ia_irq = irq;
    173 		if (ia->ia_maddr != ISACF_IOMEM_DEFAULT)
    174 			ia->ia_msize = CS8900_MEMSIZE;
    175 	}
    176 	return (rv);
    177 }
    178 
    179 void
    180 cs_isa_attach(parent, self, aux)
    181 	struct device *parent, *self;
    182 	void *aux;
    183 {
    184 	struct cs_softc *sc = (struct cs_softc *) self;
    185 	struct isa_attach_args *ia = aux;
    186 
    187 	sc->sc_ic = ia->ia_ic;
    188 	sc->sc_iot = ia->ia_iot;
    189 	sc->sc_memt = ia->ia_memt;
    190 
    191 	sc->sc_drq = ia->ia_drq;
    192 	sc->sc_irq = ia->ia_irq;
    193 
    194 	printf("\n");
    195 
    196 	/*
    197 	 * Map the device.
    198 	 */
    199 	if (bus_space_map(sc->sc_iot, ia->ia_iobase, ia->ia_iosize,
    200 	    0, &sc->sc_ioh)) {
    201 		printf("%s: unable to map i/o space\n", sc->sc_dev.dv_xname);
    202 		return;
    203 	}
    204 
    205 	/*
    206 	 * Validate IRQ.
    207 	 */
    208 	if (CS8900_IRQ_ISVALID(sc->sc_irq) == 0) {
    209 		printf("%s: invalid IRQ %d\n", sc->sc_dev.dv_xname, sc->sc_irq);
    210 		return;
    211 	}
    212 
    213 	/*
    214 	 * Map the memory space if it was specified.  If we can do this,
    215 	 * we set ourselves up to use memory mode forever.  Otherwise,
    216 	 * we fall back on I/O mode.
    217 	 */
    218 	if (ia->ia_maddr != ISACF_IOMEM_DEFAULT &&
    219 	    ia->ia_msize == CS8900_MEMSIZE &&
    220 	    CS8900_MEMBASE_ISVALID(ia->ia_maddr)) {
    221 		if (bus_space_map(sc->sc_memt, ia->ia_maddr, ia->ia_msize,
    222 		    0, &sc->sc_memh)) {
    223 			printf("%s: unable to map memory space\n",
    224 			    sc->sc_dev.dv_xname);
    225 		} else {
    226 			sc->sc_cfgflags |= CFGFLG_MEM_MODE;
    227 			sc->sc_pktpgaddr = ia->ia_maddr;
    228 		}
    229 	}
    230 
    231 	sc->sc_ih = isa_intr_establish(ia->ia_ic, sc->sc_irq, IST_EDGE,
    232 	    IPL_NET, cs_intr, sc);
    233 	if (sc->sc_ih == NULL) {
    234 		printf("%s: unable to establish interrupt\n",
    235 		    sc->sc_dev.dv_xname);
    236 		return;
    237 	}
    238 
    239 	cs_attach(sc, NULL, NULL, 0, 0);
    240 }
    241