Home | History | Annotate | Line # | Download | only in ic
fmv.c revision 1.3
      1 /*	$NetBSD: fmv.c,v 1.3 2002/11/30 14:15:11 tsutsui Exp $	*/
      2 
      3 /*
      4  * All Rights Reserved, Copyright (C) Fujitsu Limited 1995
      5  *
      6  * This software may be used, modified, copied, distributed, and sold, in
      7  * both source and binary form provided that the above copyright, these
      8  * terms and the following disclaimer are retained.  The name of the author
      9  * and/or the contributor may not be used to endorse or promote products
     10  * derived from this software without specific prior written permission.
     11  *
     12  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND THE CONTRIBUTOR ``AS IS'' AND
     13  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     14  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     15  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR THE CONTRIBUTOR BE LIABLE
     16  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     17  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     18  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION.
     19  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     20  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     21  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     22  * SUCH DAMAGE.
     23  */
     24 
     25 /*
     26  * Portions copyright (C) 1993, David Greenman.  This software may be used,
     27  * modified, copied, distributed, and sold, in both source and binary form
     28  * provided that the above copyright and these terms are retained.  Under no
     29  * circumstances is the author responsible for the proper functioning of this
     30  * software, nor does the author assume any responsibility for damages
     31  * incurred with its use.
     32  */
     33 
     34 #include <sys/cdefs.h>
     35 __KERNEL_RCSID(0, "$NetBSD: fmv.c,v 1.3 2002/11/30 14:15:11 tsutsui Exp $");
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.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 
     47 #include <dev/ic/mb86960reg.h>
     48 #include <dev/ic/mb86960var.h>
     49 #include <dev/ic/fmvreg.h>
     50 #include <dev/ic/fmvvar.h>
     51 
     52 /*
     53  * Determine type and ethernet address.
     54  */
     55 int
     56 fmv_detect(iot, ioh, enaddr)
     57 	bus_space_tag_t iot;
     58 	bus_space_handle_t ioh;
     59 	u_int8_t *enaddr;
     60 {
     61 	int model, id, type;
     62 
     63 	/* Get our station address from EEPROM. */
     64 	bus_space_read_region_1(iot, ioh, FE_FMV4, enaddr, ETHER_ADDR_LEN);
     65 
     66 	/* Make sure we got a valid station address. */
     67 	if ((enaddr[0] & 0x03) != 0x00 ||
     68 	    (enaddr[0] == 0x00 && enaddr[1] == 0x00 && enaddr[2] == 0x00)) {
     69 #ifdef FMV_DEBUG
     70 		printf("fmv_detect: invalid ethernet address\n");
     71 #endif
     72 		return (0);
     73 	}
     74 
     75 	/* Determine the card type. */
     76 	model = bus_space_read_1(iot, ioh, FE_FMV0) & FE_FMV0_MODEL;
     77 	id    = bus_space_read_1(iot, ioh, FE_FMV1) & FE_FMV1_CARDID_REV;
     78 
     79 	switch (model) {
     80 	case FE_FMV0_MODEL_FMV181:
     81 		type = FE_TYPE_FMV181;
     82 		if (id == FE_FMV1_CARDID_REV_A)
     83 			type = FE_TYPE_FMV181A;
     84 		break;
     85 	case FE_FMV0_MODEL_FMV182:
     86 		type = FE_TYPE_FMV182;
     87 		if (id == FE_FMV1_CARDID_REV_A)
     88 			type = FE_TYPE_FMV182A;
     89 		else if (id == FE_FMV1_CARDID_PNP)
     90 			type = FE_TYPE_FMV184;
     91 		break;
     92 	case FE_FMV0_MODEL_FMV183:
     93 		type = FE_TYPE_FMV183;
     94 		break;
     95 	default:
     96 		type = 0;
     97 #ifdef FMV_DEBUG
     98 		printf("fmv_detect: unknown card\n");
     99 #endif
    100 		break;
    101 	}
    102 
    103 	return (type);
    104 }
    105 
    106 void
    107 fmv_attach(sc)
    108 	struct mb86960_softc *sc;
    109 {
    110 	bus_space_tag_t iot;
    111 	bus_space_handle_t ioh;
    112 	const char *typestr;
    113 	int type;
    114 	u_int8_t myea[ETHER_ADDR_LEN];
    115 
    116 	iot = sc->sc_bst;
    117 	ioh = sc->sc_bsh;
    118 
    119 	/* Determine the card type. */
    120 	type = fmv_detect(iot, ioh, myea);
    121 	switch (type) {
    122 	case FE_TYPE_FMV181:
    123 		typestr = "FMV-181";
    124 		break;
    125 	case FE_TYPE_FMV181A:
    126 		typestr = "FMV-181A";
    127 		break;
    128 	case FE_TYPE_FMV182:
    129 		typestr = "FMV-182";
    130 		break;
    131 	case FE_TYPE_FMV182A:
    132 		typestr = "FMV-182A";
    133 		break;
    134 	case FE_TYPE_FMV183:
    135 		typestr = "FMV-183";
    136 		break;
    137 	case FE_TYPE_FMV184:
    138 		typestr = "FMV-184";
    139 		break;
    140 	default:
    141 	  	/* Unknown card type: maybe a new model, but... */
    142 		panic("\n%s: unknown FMV-18x card", sc->sc_dev.dv_xname);
    143 	}
    144 
    145 	printf(": %s Ethernet\n", typestr);
    146 
    147 	/* This interface is always enabled. */
    148 	sc->sc_stat |= FE_STAT_ENABLED;
    149 
    150 	/*
    151 	 * Minimum initialization of the hardware.
    152 	 * We write into registers; hope I/O ports have no
    153 	 * overlap with other boards.
    154 	 */
    155 
    156 	/* Initialize ASIC. */
    157 	bus_space_write_1(iot, ioh, FE_FMV3, 0);
    158 	bus_space_write_1(iot, ioh, FE_FMV10, 0);
    159 
    160 	/* Wait for a while.  I'm not sure this is necessary.  FIXME */
    161 	delay(200);
    162 
    163 	/*
    164 	 * Do generic MB86960 attach.
    165 	 */
    166 	mb86960_attach(sc, myea);
    167 
    168 	/* Is this really needs to be done here? XXX */
    169 	/* Turn the "master interrupt control" flag of ASIC on. */
    170 	bus_space_write_1(iot, ioh, FE_FMV3, FE_FMV3_ENABLE_FLAG);
    171 
    172 	mb86960_config(sc, NULL, 0, 0);
    173 }
    174