Home | History | Annotate | Line # | Download | only in isa
if_sm_isa.c revision 1.9
      1 /*	$NetBSD: if_sm_isa.c,v 1.9 2002/01/07 21:47:09 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the NetBSD
     22  *	Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 #include <sys/cdefs.h>
     41 __KERNEL_RCSID(0, "$NetBSD: if_sm_isa.c,v 1.9 2002/01/07 21:47:09 thorpej Exp $");
     42 
     43 #include <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/mbuf.h>
     46 #include <sys/socket.h>
     47 #include <sys/ioctl.h>
     48 #include <sys/errno.h>
     49 #include <sys/syslog.h>
     50 #include <sys/select.h>
     51 #include <sys/device.h>
     52 
     53 #include <net/if.h>
     54 #include <net/if_dl.h>
     55 #include <net/if_ether.h>
     56 #include <net/if_media.h>
     57 
     58 #include <machine/intr.h>
     59 #include <machine/bus.h>
     60 
     61 #include <dev/mii/mii.h>
     62 #include <dev/mii/miivar.h>
     63 
     64 #include <dev/ic/smc91cxxreg.h>
     65 #include <dev/ic/smc91cxxvar.h>
     66 
     67 #include <dev/isa/isavar.h>
     68 
     69 int	sm_isa_match __P((struct device *, struct cfdata *, void *));
     70 void	sm_isa_attach __P((struct device *, struct device *, void *));
     71 
     72 struct sm_isa_softc {
     73 	struct	smc91cxx_softc sc_smc;		/* real "smc" softc */
     74 
     75 	/* ISA-specific goo. */
     76 	void	*sc_ih;				/* interrupt cookie */
     77 };
     78 
     79 struct cfattach sm_isa_ca = {
     80 	sizeof(struct sm_isa_softc), sm_isa_match, sm_isa_attach
     81 };
     82 
     83 int
     84 sm_isa_match(parent, match, aux)
     85 	struct device *parent;
     86 	struct cfdata *match;
     87 	void *aux;
     88 {
     89 	struct isa_attach_args *ia = aux;
     90 	bus_space_tag_t iot = ia->ia_iot;
     91 	bus_space_handle_t ioh;
     92 	u_int16_t tmp;
     93 	int rv = 0;
     94 	extern const char *smc91cxx_idstrs[];
     95 
     96 	if (ia->ia_nio < 1)
     97 		return (0);
     98 	if (ia->ia_nirq < 1)
     99 		return (0);
    100 
    101 	if (ISA_DIRECT_CONFIG(ia))
    102 		return (0);
    103 
    104 	/* Disallow wildcarded values. */
    105 	if (ia->ia_io[0].ir_addr == ISACF_PORT_DEFAULT)
    106 		return (0);
    107 	if (ia->ia_irq[0].ir_irq == ISACF_IRQ_DEFAULT)
    108 		return (0);
    109 
    110 	/* Map i/o space. */
    111 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, SMC_IOSIZE, 0, &ioh))
    112 		return (0);
    113 
    114 	/* Check that high byte of BANK_SELECT is what we expect. */
    115 	tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
    116 	if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
    117 		goto out;
    118 
    119 	/*
    120 	 * Switch to bank 0 and perform the test again.
    121 	 * XXX INVASIVE!
    122 	 */
    123 	bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 0);
    124 	tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
    125 	if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
    126 		goto out;
    127 
    128 	/*
    129 	 * Switch to bank 1 and check the base address register.
    130 	 * XXX INVASIVE!
    131 	 */
    132 	bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 1);
    133 	tmp = bus_space_read_2(iot, ioh, BASE_ADDR_REG_W);
    134 	if (ia->ia_io[0].ir_addr != ((tmp >> 3) & 0x3e0))
    135 		goto out;
    136 
    137 	/*
    138 	 * Check for a recognized chip id.
    139 	 * XXX INVASIVE!
    140 	 */
    141 	bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 3);
    142 	tmp = bus_space_read_2(iot, ioh, REVISION_REG_W);
    143 	if (smc91cxx_idstrs[RR_ID(tmp)] == NULL)
    144 		goto out;
    145 
    146 	/*
    147 	 * Assume we have an SMC91Cxx.
    148 	 */
    149 	ia->ia_nio = 1;
    150 	ia->ia_io[0].ir_size = SMC_IOSIZE;
    151 
    152 	ia->ia_nirq = 1;
    153 
    154 	ia->ia_niomem = 0;
    155 	ia->ia_ndrq = 0;
    156 
    157 	rv = 1;
    158 
    159  out:
    160 	bus_space_unmap(iot, ioh, SMC_IOSIZE);
    161 	return (rv);
    162 }
    163 
    164 void
    165 sm_isa_attach(parent, self, aux)
    166 	struct device *parent, *self;
    167 	void *aux;
    168 {
    169 	struct sm_isa_softc *isc = (struct sm_isa_softc *)self;
    170 	struct smc91cxx_softc *sc = &isc->sc_smc;
    171 	struct isa_attach_args *ia = aux;
    172 	bus_space_tag_t iot = ia->ia_iot;
    173 	bus_space_handle_t ioh;
    174 
    175 	printf("\n");
    176 
    177 	/* Map i/o space. */
    178 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, SMC_IOSIZE, 0, &ioh))
    179 		panic("sm_isa_attach: can't map i/o space");
    180 
    181 	sc->sc_bst = iot;
    182 	sc->sc_bsh = ioh;
    183 
    184 	/* should always be enabled */
    185 	sc->sc_flags |= SMC_FLAGS_ENABLED;
    186 
    187 	/* XXX Should get Ethernet address from EEPROM!! */
    188 
    189 	/* Perform generic intialization. */
    190 	smc91cxx_attach(sc, NULL);
    191 
    192 	/* Establish the interrupt handler. */
    193 	isc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
    194 	    IST_EDGE, IPL_NET, smc91cxx_intr, sc);
    195 	if (isc->sc_ih == NULL)
    196 		printf("%s: couldn't establish interrupt handler\n",
    197 		    sc->sc_dev.dv_xname);
    198 }
    199