1 /* $NetBSD: am79c930.c,v 1.9 2004/01/15 09:33:48 onoe Exp $ */
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
40 * Am79c930 chip driver.
42 * This is used by the awi driver to use the shared
43 * memory attached to the 79c930 to communicate with the firmware running
44 * in the 930's on-board 80188 core.
46 * The 79c930 can be mapped into just I/O space, or also have a
47 * memory mapping; the mapping must be set up by the bus front-end
48 * before am79c930_init is called.
54 * read_8, read_16, read_32, read_64, read_bytes
55 * write_8, write_16, write_32, write_64, write_bytes
56 * (two versions, depending on whether memory-space or i/o space is in use).
63 #include <sys/cdefs.h>
65 __KERNEL_RCSID(0, "$NetBSD: am79c930.c,v 1.9 2004/01/15 09:33:48 onoe Exp $");
68 __FBSDID("$FreeBSD$");
71 #include <sys/param.h>
72 #include <sys/systm.h>
73 #include <sys/endian.h>
75 #include <sys/device.h>
78 #include <machine/cpu.h>
79 #include <machine/bus.h>
81 #include <machine/intr.h>
85 #include <dev/ic/am79c930reg.h>
86 #include <dev/ic/am79c930var.h>
89 #include <dev/awi/am79c930reg.h>
90 #include <dev/awi/am79c930var.h>
93 #define AM930_DELAY(x) /*nothing*/
95 void am79c930_regdump(struct am79c930_softc *sc);
97 static void io_write_1(struct am79c930_softc *, u_int32_t, u_int8_t);
98 static void io_write_2(struct am79c930_softc *, u_int32_t, u_int16_t);
99 static void io_write_4(struct am79c930_softc *, u_int32_t, u_int32_t);
100 static void io_write_bytes(struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
102 static u_int8_t io_read_1(struct am79c930_softc *, u_int32_t);
103 static u_int16_t io_read_2(struct am79c930_softc *, u_int32_t);
104 static u_int32_t io_read_4(struct am79c930_softc *, u_int32_t);
105 static void io_read_bytes(struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
107 static void mem_write_1(struct am79c930_softc *, u_int32_t, u_int8_t);
108 static void mem_write_2(struct am79c930_softc *, u_int32_t, u_int16_t);
109 static void mem_write_4(struct am79c930_softc *, u_int32_t, u_int32_t);
110 static void mem_write_bytes(struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
112 static u_int8_t mem_read_1(struct am79c930_softc *, u_int32_t);
113 static u_int16_t mem_read_2(struct am79c930_softc *, u_int32_t);
114 static u_int32_t mem_read_4(struct am79c930_softc *, u_int32_t);
115 static void mem_read_bytes(struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
117 static struct am79c930_ops iospace_ops = {
128 struct am79c930_ops memspace_ops = {
140 io_write_1( struct am79c930_softc *sc, u_int32_t off, u_int8_t val)
143 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
146 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
148 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA, val);
153 io_write_2(struct am79c930_softc *sc, u_int32_t off, u_int16_t val)
156 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
159 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
161 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA, val & 0xff);
163 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA, (val>>8)&0xff);
168 io_write_4(struct am79c930_softc *sc, u_int32_t off, u_int32_t val)
171 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
174 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
176 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,val & 0xff);
178 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>8)&0xff);
180 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>16)&0xff);
182 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>24)&0xff);
187 io_write_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
193 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
196 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
198 for (i=0; i<len; i++)
199 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,ptr[i]);
203 io_read_1(struct am79c930_softc *sc, u_int32_t off)
207 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
210 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
212 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
218 io_read_2(struct am79c930_softc *sc, u_int32_t off)
222 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
225 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
227 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
229 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 8;
235 io_read_4(struct am79c930_softc *sc, u_int32_t off)
239 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
242 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
244 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
246 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 8;
248 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 16;
250 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 24;
256 io_read_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
261 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
264 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
266 for (i=0; i<len; i++)
267 ptr[i] = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
272 mem_write_1(struct am79c930_softc *sc, u_int32_t off, u_int8_t val)
274 bus_space_write_1(sc->sc_memt, sc->sc_memh, off, val);
278 void mem_write_2(struct am79c930_softc *sc, u_int32_t off, u_int16_t val)
280 bus_space_tag_t t = sc->sc_memt;
281 bus_space_handle_t h = sc->sc_memh;
283 /* could be unaligned */
284 if ((off & 0x1) == 0)
285 bus_space_write_2(t, h, off, htole16(val));
287 bus_space_write_1(t, h, off, val & 0xff);
288 bus_space_write_1(t, h, off+1, (val >> 8) & 0xff);
293 mem_write_4(struct am79c930_softc *sc, u_int32_t off, u_int32_t val)
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, htole32(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);
310 mem_write_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
313 bus_space_write_region_1 (sc->sc_memt, sc->sc_memh, off, ptr, len);
317 mem_read_1(struct am79c930_softc *sc, u_int32_t off)
319 return bus_space_read_1(sc->sc_memt, sc->sc_memh, off);
323 mem_read_2(struct am79c930_softc *sc, u_int32_t off)
325 /* could be unaligned */
326 if ((off & 0x1) == 0)
327 return le16toh(bus_space_read_2(sc->sc_memt, sc->sc_memh, off));
330 bus_space_read_1(sc->sc_memt, sc->sc_memh, off ) |
331 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+1) << 8);
335 mem_read_4(struct am79c930_softc *sc, u_int32_t off)
337 /* could be unaligned */
338 if ((off & 0x3) == 0)
339 return le32toh(bus_space_read_4(sc->sc_memt, sc->sc_memh, off));
342 bus_space_read_1(sc->sc_memt, sc->sc_memh, off ) |
343 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+1) << 8) |
344 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+2) <<16) |
345 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+3) <<24);
349 mem_read_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
352 bus_space_read_region_1 (sc->sc_memt, sc->sc_memh, off, ptr, len);
361 am79c930_gcr_setbits(struct am79c930_softc *sc, u_int8_t bits)
363 u_int8_t gcr = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
367 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_GCR, gcr);
375 am79c930_gcr_clearbits(struct am79c930_softc *sc, u_int8_t bits)
377 u_int8_t gcr = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
381 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_GCR, gcr);
385 am79c930_gcr_read(struct am79c930_softc *sc)
387 return bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
392 am79c930_regdump(struct am79c930_softc *sc)
398 for (i=0; i<8; i++) {
399 buf[i] = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, i);
402 printf("am79c930: regdump:");
403 for (i=0; i<8; i++) {
404 printf(" %02x", buf[i]);
411 am79c930_chip_init(struct am79c930_softc *sc, int how)
413 /* zero the bank select register, and leave it that way.. */
414 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_BSS, 0);
416 sc->sc_ops = &memspace_ops;
418 sc->sc_ops = &iospace_ops;