Home | History | Annotate | Line # | Download | only in isa
      1 /*	$NetBSD: if_sm_isa.c,v 1.24 2018/02/08 09:05:19 dholland 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.24 2018/02/08 09:05:19 dholland 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(device_t, cfdata_t, void *);
     63 void	sm_isa_attach(device_t, device_t, 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_NEW(sm_isa, sizeof(struct sm_isa_softc),
     73     sm_isa_match, sm_isa_attach, NULL, NULL);
     74 
     75 int
     76 sm_isa_match(device_t parent, cfdata_t match, void *aux)
     77 {
     78 	struct isa_attach_args *ia = aux;
     79 	bus_space_tag_t iot = ia->ia_iot;
     80 	bus_space_handle_t ioh;
     81 	u_int16_t tmp;
     82 	int rv = 0;
     83 	extern const char *smc91cxx_idstrs[];
     84 
     85 	if (ia->ia_nio < 1)
     86 		return (0);
     87 	if (ia->ia_nirq < 1)
     88 		return (0);
     89 
     90 	if (ISA_DIRECT_CONFIG(ia))
     91 		return (0);
     92 
     93 	/* Disallow wildcarded values. */
     94 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
     95 		return (0);
     96 	if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
     97 		return (0);
     98 
     99 	/* Map i/o space. */
    100 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, SMC_IOSIZE, 0, &ioh))
    101 		return (0);
    102 
    103 	/* Check that high byte of BANK_SELECT is what we expect. */
    104 	tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
    105 	if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
    106 		goto out;
    107 
    108 	/*
    109 	 * Switch to bank 0 and perform the test again.
    110 	 * XXX INVASIVE!
    111 	 */
    112 	bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 0);
    113 	tmp = bus_space_read_2(iot, ioh, BANK_SELECT_REG_W);
    114 	if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE)
    115 		goto out;
    116 
    117 	/*
    118 	 * Switch to bank 1 and check the base address register.
    119 	 * XXX INVASIVE!
    120 	 */
    121 	bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 1);
    122 	tmp = bus_space_read_2(iot, ioh, BASE_ADDR_REG_W);
    123 	if (ia->ia_io[0].ir_addr != ((tmp >> 3) & 0x3e0))
    124 		goto out;
    125 
    126 	/*
    127 	 * Check for a recognized chip id.
    128 	 * XXX INVASIVE!
    129 	 */
    130 	bus_space_write_2(iot, ioh, BANK_SELECT_REG_W, 3);
    131 	tmp = bus_space_read_2(iot, ioh, REVISION_REG_W);
    132 	if (smc91cxx_idstrs[RR_ID(tmp)] == NULL)
    133 		goto out;
    134 
    135 	/*
    136 	 * Assume we have an SMC91Cxx.
    137 	 */
    138 	ia->ia_nio = 1;
    139 	ia->ia_io[0].ir_size = SMC_IOSIZE;
    140 
    141 	ia->ia_nirq = 1;
    142 
    143 	ia->ia_niomem = 0;
    144 	ia->ia_ndrq = 0;
    145 
    146 	rv = 1;
    147 
    148  out:
    149 	bus_space_unmap(iot, ioh, SMC_IOSIZE);
    150 	return (rv);
    151 }
    152 
    153 void
    154 sm_isa_attach(device_t parent, device_t self, void *aux)
    155 {
    156 	struct sm_isa_softc *isc = device_private(self);
    157 	struct smc91cxx_softc *sc = &isc->sc_smc;
    158 	struct isa_attach_args *ia = aux;
    159 	bus_space_tag_t iot = ia->ia_iot;
    160 	bus_space_handle_t ioh;
    161 
    162 	printf("\n");
    163 
    164 	/* Map i/o space. */
    165 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, SMC_IOSIZE, 0, &ioh))
    166 		panic("sm_isa_attach: can't map i/o space");
    167 
    168 	sc->sc_dev = self;
    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 initialization. */
    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(self, "couldn't establish interrupt handler\n");
    185 }
    186