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.6 2005/06/13 20:25:56 joerg 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>
68 #include <machine/cpu.h>
69 #include <machine/bus.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 = {
120 static void io_write_1 (sc, off, val)
121 struct am79c930_softc *sc;
126 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
129 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
131 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA, val);
135 static void io_write_2 (sc, off, val)
136 struct am79c930_softc *sc;
141 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
144 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
146 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA, val & 0xff);
148 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA, (val>>8)&0xff);
152 static void io_write_4 (sc, off, val)
153 struct am79c930_softc *sc;
158 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
161 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
163 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,val & 0xff);
165 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>8)&0xff);
167 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>16)&0xff);
169 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>24)&0xff);
173 static void io_write_bytes (sc, off, ptr, len)
174 struct am79c930_softc *sc;
182 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
185 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
187 for (i=0; i<len; i++)
188 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,ptr[i]);
191 static u_int8_t io_read_1 (sc, off)
192 struct am79c930_softc *sc;
197 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
200 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
202 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
207 static u_int16_t io_read_2 (sc, off)
208 struct am79c930_softc *sc;
213 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
216 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
218 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
220 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 8;
225 static u_int32_t io_read_4 (sc, off)
226 struct am79c930_softc *sc;
231 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
234 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
236 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
238 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 8;
240 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 16;
242 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 24;
247 static void io_read_bytes (sc, off, ptr, len)
248 struct am79c930_softc *sc;
255 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
258 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
260 for (i=0; i<len; i++)
261 ptr[i] = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
265 static void mem_write_1 (sc, off, val)
266 struct am79c930_softc *sc;
270 bus_space_write_1(sc->sc_memt, sc->sc_memh, off, val);
273 static void mem_write_2 (sc, off, val)
274 struct am79c930_softc *sc;
278 bus_space_tag_t t = sc->sc_memt;
279 bus_space_handle_t h = sc->sc_memh;
281 /* could be unaligned */
282 if ((off & 0x1) == 0)
283 bus_space_write_2(t, h, off, val);
285 bus_space_write_1(t, h, off, val & 0xff);
286 bus_space_write_1(t, h, off+1, (val >> 8) & 0xff);
290 static void mem_write_4 (sc, off, val)
291 struct am79c930_softc *sc;
295 bus_space_tag_t t = sc->sc_memt;
296 bus_space_handle_t h = sc->sc_memh;
298 /* could be unaligned */
299 if ((off & 0x3) == 0)
300 bus_space_write_4(t, h, off, val);
302 bus_space_write_1(t, h, off, val & 0xff);
303 bus_space_write_1(t, h, off+1, (val >> 8) & 0xff);
304 bus_space_write_1(t, h, off+2, (val >> 16) & 0xff);
305 bus_space_write_1(t, h, off+3, (val >> 24) & 0xff);
309 static void mem_write_bytes (sc, off, ptr, len)
310 struct am79c930_softc *sc;
315 bus_space_write_region_1 (sc->sc_memt, sc->sc_memh, off, ptr, len);
319 static u_int8_t mem_read_1 (sc, off)
320 struct am79c930_softc *sc;
323 return bus_space_read_1(sc->sc_memt, sc->sc_memh, off);
326 static u_int16_t mem_read_2 (sc, off)
327 struct am79c930_softc *sc;
330 /* could be unaligned */
331 if ((off & 0x1) == 0)
332 return bus_space_read_2(sc->sc_memt, sc->sc_memh, off);
335 bus_space_read_1(sc->sc_memt, sc->sc_memh, off ) |
336 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+1) << 8);
339 static u_int32_t mem_read_4 (sc, off)
340 struct am79c930_softc *sc;
343 /* could be unaligned */
344 if ((off & 0x3) == 0)
345 return bus_space_read_4(sc->sc_memt, sc->sc_memh, off);
348 bus_space_read_1(sc->sc_memt, sc->sc_memh, off ) |
349 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+1) << 8) |
350 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+2) <<16) |
351 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+3) <<24);
356 static void mem_read_bytes (sc, off, ptr, len)
357 struct am79c930_softc *sc;
362 bus_space_read_region_1 (sc->sc_memt, sc->sc_memh, off, ptr, len);
372 void am79c930_gcr_setbits (sc, bits)
373 struct am79c930_softc *sc;
376 u_int8_t gcr = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
380 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_GCR, gcr);
387 void am79c930_gcr_clearbits (sc, bits)
388 struct am79c930_softc *sc;
391 u_int8_t gcr = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
395 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_GCR, gcr);
398 u_int8_t am79c930_gcr_read (sc)
399 struct am79c930_softc *sc;
401 return bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
405 void am79c930_regdump (sc)
406 struct am79c930_softc *sc;
412 for (i=0; i<8; i++) {
413 buf[i] = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, i);
416 printf("am79c930: regdump:");
417 for (i=0; i<8; i++) {
418 printf(" %02x", buf[i]);
424 void am79c930_chip_init (sc, how)
425 struct am79c930_softc *sc;
427 /* zero the bank select register, and leave it that way.. */
428 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_BSS, 0);
430 sc->sc_ops = &memspace_ops;
432 sc->sc_ops = &iospace_ops;