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