1 /* $NetBSD: am79c930.c,v 1.5 2000/03/23 13:57:58 onoe Exp $ */
2 /* $FreeBSD: src/sys/dev/awi/am79c930.c,v 1.2.2.1 2000/12/07 04:09:39 imp Exp $ */
3 /* $DragonFly: src/sys/dev/netif/awi/Attic/am79c930.c,v 1.8 2006/10/25 20:55:56 dillon Exp $ */
6 * Copyright (c) 1999 The NetBSD Foundation, Inc.
9 * This code is derived from software contributed to The NetBSD Foundation
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the NetBSD
23 * Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
42 * Am79c930 chip driver.
44 * This is used by the awi driver to use the shared
45 * memory attached to the 79c930 to communicate with the firmware running
46 * in the 930's on-board 80188 core.
48 * The 79c930 can be mapped into just I/O space, or also have a
49 * memory mapping; the mapping must be set up by the bus front-end
50 * before am79c930_init is called.
56 * read_8, read_16, read_32, read_64, read_bytes
57 * write_8, write_16, write_32, write_64, write_bytes
58 * (two versions, depending on whether memory-space or i/o space is in use).
65 #include <sys/param.h>
66 #include <sys/systm.h>
69 #include <machine/cpu.h>
71 #include <dev/netif/awi/am79c930reg.h>
72 #include <dev/netif/awi/am79c930var.h>
74 #define AM930_DELAY(x) /*nothing*/
76 void am79c930_regdump (struct am79c930_softc *sc);
78 static void io_write_1 (struct am79c930_softc *, u_int32_t, u_int8_t);
79 static void io_write_2 (struct am79c930_softc *, u_int32_t, u_int16_t);
80 static void io_write_4 (struct am79c930_softc *, u_int32_t, u_int32_t);
81 static void io_write_bytes (struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
83 static u_int8_t io_read_1 (struct am79c930_softc *, u_int32_t);
84 static u_int16_t io_read_2 (struct am79c930_softc *, u_int32_t);
85 static u_int32_t io_read_4 (struct am79c930_softc *, u_int32_t);
86 static void io_read_bytes (struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
88 static void mem_write_1 (struct am79c930_softc *, u_int32_t, u_int8_t);
89 static void mem_write_2 (struct am79c930_softc *, u_int32_t, u_int16_t);
90 static void mem_write_4 (struct am79c930_softc *, u_int32_t, u_int32_t);
91 static void mem_write_bytes (struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
93 static u_int8_t mem_read_1 (struct am79c930_softc *, u_int32_t);
94 static u_int16_t mem_read_2 (struct am79c930_softc *, u_int32_t);
95 static u_int32_t mem_read_4 (struct am79c930_softc *, u_int32_t);
96 static void mem_read_bytes (struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
98 static struct am79c930_ops iospace_ops = {
109 struct am79c930_ops memspace_ops = {
121 io_write_1(struct am79c930_softc *sc, u_int32_t off, u_int8_t val)
124 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
127 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
129 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA, val);
134 io_write_2(struct am79c930_softc *sc, u_int32_t off, u_int16_t val)
137 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
140 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
142 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA, val & 0xff);
144 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA, (val>>8)&0xff);
149 io_write_4(struct am79c930_softc *sc, u_int32_t off, u_int32_t val)
152 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
155 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
157 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,val & 0xff);
159 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>8)&0xff);
161 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>16)&0xff);
163 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>24)&0xff);
168 io_write_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
174 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
177 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
179 for (i=0; i<len; i++)
180 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,ptr[i]);
184 io_read_1(struct am79c930_softc *sc, u_int32_t off)
188 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
191 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
193 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
199 io_read_2(struct am79c930_softc *sc, u_int32_t off)
203 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
206 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
208 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
210 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 8;
216 io_read_4(struct am79c930_softc *sc, u_int32_t off)
220 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
223 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
225 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
227 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 8;
229 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 16;
231 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 24;
237 io_read_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
242 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
245 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
247 for (i=0; i<len; i++)
248 ptr[i] = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
253 mem_write_1(struct am79c930_softc *sc, u_int32_t off, u_int8_t val)
255 bus_space_write_1(sc->sc_memt, sc->sc_memh, off, val);
259 mem_write_2(struct am79c930_softc *sc, u_int32_t off, u_int16_t val)
261 bus_space_tag_t t = sc->sc_memt;
262 bus_space_handle_t h = sc->sc_memh;
264 /* could be unaligned */
265 if ((off & 0x1) == 0)
266 bus_space_write_2(t, h, off, val);
268 bus_space_write_1(t, h, off, val & 0xff);
269 bus_space_write_1(t, h, off+1, (val >> 8) & 0xff);
274 mem_write_4(struct am79c930_softc *sc, u_int32_t off, u_int32_t val)
276 bus_space_tag_t t = sc->sc_memt;
277 bus_space_handle_t h = sc->sc_memh;
279 /* could be unaligned */
280 if ((off & 0x3) == 0)
281 bus_space_write_4(t, h, off, val);
283 bus_space_write_1(t, h, off, val & 0xff);
284 bus_space_write_1(t, h, off+1, (val >> 8) & 0xff);
285 bus_space_write_1(t, h, off+2, (val >> 16) & 0xff);
286 bus_space_write_1(t, h, off+3, (val >> 24) & 0xff);
291 mem_write_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
294 bus_space_write_region_1 (sc->sc_memt, sc->sc_memh, off, ptr, len);
299 mem_read_1(struct am79c930_softc *sc, u_int32_t off)
301 return bus_space_read_1(sc->sc_memt, sc->sc_memh, off);
305 mem_read_2(struct am79c930_softc *sc, u_int32_t off)
307 /* could be unaligned */
308 if ((off & 0x1) == 0)
309 return bus_space_read_2(sc->sc_memt, sc->sc_memh, off);
312 bus_space_read_1(sc->sc_memt, sc->sc_memh, off ) |
313 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+1) << 8);
317 mem_read_4(struct am79c930_softc *sc, u_int32_t off)
319 /* could be unaligned */
320 if ((off & 0x3) == 0)
321 return bus_space_read_4(sc->sc_memt, sc->sc_memh, off);
324 bus_space_read_1(sc->sc_memt, sc->sc_memh, off ) |
325 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+1) << 8) |
326 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+2) <<16) |
327 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+3) <<24);
331 mem_read_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
334 bus_space_read_region_1 (sc->sc_memt, sc->sc_memh, off, ptr, len);
345 am79c930_gcr_setbits(struct am79c930_softc *sc, u_int8_t bits)
347 u_int8_t gcr = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
351 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_GCR, gcr);
359 am79c930_gcr_clearbits(struct am79c930_softc *sc, u_int8_t bits)
361 u_int8_t gcr = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
365 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_GCR, gcr);
369 am79c930_gcr_read(struct am79c930_softc *sc)
371 return bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
376 am79c930_regdump(struct am79c930_softc *sc)
382 for (i=0; i<8; i++) {
383 buf[i] = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, i);
386 printf("am79c930: regdump:");
387 for (i=0; i<8; i++) {
388 printf(" %02x", buf[i]);
395 am79c930_chip_init(struct am79c930_softc *sc, int how)
397 /* zero the bank select register, and leave it that way.. */
398 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_BSS, 0);
400 sc->sc_ops = &memspace_ops;
402 sc->sc_ops = &iospace_ops;