Home | History | Annotate | Line # | Download | only in isa
if_sm_isa.c revision 1.19.2.1
      1 /*	$NetBSD: if_sm_isa.c,v 1.19.2.1 2008/05/18 12:34:03 yamt 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  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #include <sys/cdefs.h>
     34 __KERNEL_RCSID(0, "$NetBSD: if_sm_isa.c,v 1.19.2.1 2008/05/18 12:34:03 yamt Exp $");
     35 
     36 #include <sys/param.h>
     37 #include <sys/systm.h>
     38 #include <sys/mbuf.h>
     39 #include <sys/socket.h>
     40 #include <sys/ioctl.h>
     41 #include <sys/errno.h>
     42 #include <sys/syslog.h>
     43 #include <sys/select.h>
     44 #include <sys/device.h>
     45 
     46 #include <net/if.h>
     47 #include <net/if_dl.h>
     48 #include <net/if_ether.h>
     49 #include <net/if_media.h>
     50 
     51 #include <sys/intr.h>
     52 #include <sys/bus.h>
     53 
     54 #include <dev/mii/mii.h>
     55 #include <dev/mii/miivar.h>
     56 
     57 #include <dev/ic/smc91cxxreg.h>
     58 #include <dev/ic/smc91cxxvar.h>
     59 
     60 #include <dev/isa/isavar.h>
     61 
     62 int	sm_isa_match(struct device *, struct cfdata *, void *);
     63 void	sm_isa_attach(struct device *, struct device *, void *);
     64 
     65 struct sm_isa_softc {
     66 	struct	smc91cxx_softc sc_smc;		/* real "smc" softc */
     67 
     68 	/* ISA-specific goo. */
     69 	void	*sc_ih;				/* interrupt cookie */
     70 };
     71 
     72 CFATTACH_DECL(sm_isa, sizeof(struct sm_isa_softc),
     73     sm_isa_match, sm_isa_attach, NULL, NULL);
     74 
     75 int
     76 sm_isa_match(struct device *parent, struct cfdata *match,
     77     void *aux)
     78 {
     79 	struct isa_attach_args *ia = aux;
     80 	bus_space_tag_t iot = ia->ia_iot;
     81 	bus_space_handle_t ioh;
     82 	u_int16_t tmp;
     83 	int rv = 0;
     84 	extern const char *smc91cxx_idstrs[];
     85 
     86 	if (ia->ia_nio < 1)
     87 		return (0);
     88 	if (ia->ia_nirq < 1)
     89 		return (0);
     90 
     91 	if (ISA_DIRECT_CONFIG(ia))
     92 		return (0);
     93 
     94 	/* Disallow wildcarded values. */
     95 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
     96 		return (0);
     97 	if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
     98 		return (0);
     99 
    100 	/* Map i/o space. */
    101 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, SMC_IOSIZE, 0, &ioh))
    102 		return (0);
    103 
    104 	/* Check that high byte of BANK_SELECT is what we expect. */
    105 	tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
    106 	if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
    107 		goto out;
    108 
    109 	/*
    110 	 * Switch to bank 0 and perform the test again.
    111 	 * XXX INVASIVE!
    112 	 */
    113 	bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 0);
    114 	tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
    115 	if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
    116 		goto out;
    117 
    118 	/*
    119 	 * Switch to bank 1 and check the base address register.
    120 	 * XXX INVASIVE!
    121 	 */
    122 	bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 1);
    123 	tmp = bus_space_read_2(iot, ioh, BASE_ADDR_REG_W);
    124 	if (ia->ia_io[0].ir_addr != ((tmp >> 3) & 0x3e0))
    125 		goto out;
    126 
    127 	/*
    128 	 * Check for a recognized chip id.
    129 	 * XXX INVASIVE!
    130 	 */
    131 	bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 3);
    132 	tmp = bus_space_read_2(iot, ioh, REVISION_REG_W);
    133 	if (smc91cxx_idstrs[RR_ID(tmp)] == NULL)
    134 		goto out;
    135 
    136 	/*
    137 	 * Assume we have an SMC91Cxx.
    138 	 */
    139 	ia->ia_nio = 1;
    140 	ia->ia_io[0].ir_size = SMC_IOSIZE;
    141 
    142 	ia->ia_nirq = 1;
    143 
    144 	ia->ia_niomem = 0;
    145 	ia->ia_ndrq = 0;
    146 
    147 	rv = 1;
    148 
    149  out:
    150 	bus_space_unmap(iot, ioh, SMC_IOSIZE);
    151 	return (rv);
    152 }
    153 
    154 void
    155 sm_isa_attach(struct device *parent, struct device *self, void *aux)
    156 {
    157 	struct sm_isa_softc *isc = (struct sm_isa_softc *)self;
    158 	struct smc91cxx_softc *sc = &isc->sc_smc;
    159 	struct isa_attach_args *ia = aux;
    160 	bus_space_tag_t iot = ia->ia_iot;
    161 	bus_space_handle_t ioh;
    162 
    163 	printf("\n");
    164 
    165 	/* Map i/o space. */
    166 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, SMC_IOSIZE, 0, &ioh))
    167 		panic("sm_isa_attach: can't map i/o space");
    168 
    169 	sc->sc_bst = iot;
    170 	sc->sc_bsh = ioh;
    171 
    172 	/* should always be enabled */
    173 	sc->sc_flags |= SMC_FLAGS_ENABLED;
    174 
    175 	/* XXX Should get Ethernet address from EEPROM!! */
    176 
    177 	/* Perform generic intialization. */
    178 	smc91cxx_attach(sc, NULL);
    179 
    180 	/* Establish the interrupt handler. */
    181 	isc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
    182 	    IST_EDGE, IPL_NET, smc91cxx_intr, sc);
    183 	if (isc->sc_ih == NULL)
    184 		aprint_error_dev(&sc->sc_dev, "couldn't establish interrupt handler\n");
    185 }
    186