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>
80 #include <machine/bus_pio.h>
81 #include <machine/bus_memio.h>
83 #include <machine/bus.h>
85 #include <machine/intr.h>
89 #include <dev/ic/am79c930reg.h>
90 #include <dev/ic/am79c930var.h>
93 #include <dev/awi/am79c930reg.h>
94 #include <dev/awi/am79c930var.h>
97 #define AM930_DELAY(x) /*nothing*/
99 void am79c930_regdump(struct am79c930_softc *sc);
101 static void io_write_1(struct am79c930_softc *, u_int32_t, u_int8_t);
102 static void io_write_2(struct am79c930_softc *, u_int32_t, u_int16_t);
103 static void io_write_4(struct am79c930_softc *, u_int32_t, u_int32_t);
104 static void io_write_bytes(struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
106 static u_int8_t io_read_1(struct am79c930_softc *, u_int32_t);
107 static u_int16_t io_read_2(struct am79c930_softc *, u_int32_t);
108 static u_int32_t io_read_4(struct am79c930_softc *, u_int32_t);
109 static void io_read_bytes(struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
111 static void mem_write_1(struct am79c930_softc *, u_int32_t, u_int8_t);
112 static void mem_write_2(struct am79c930_softc *, u_int32_t, u_int16_t);
113 static void mem_write_4(struct am79c930_softc *, u_int32_t, u_int32_t);
114 static void mem_write_bytes(struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
116 static u_int8_t mem_read_1(struct am79c930_softc *, u_int32_t);
117 static u_int16_t mem_read_2(struct am79c930_softc *, u_int32_t);
118 static u_int32_t mem_read_4(struct am79c930_softc *, u_int32_t);
119 static void mem_read_bytes(struct am79c930_softc *, u_int32_t, u_int8_t *, size_t);
121 static struct am79c930_ops iospace_ops = {
132 struct am79c930_ops memspace_ops = {
144 io_write_1( struct am79c930_softc *sc, u_int32_t off, u_int8_t val)
147 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
150 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
152 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA, val);
157 io_write_2(struct am79c930_softc *sc, u_int32_t off, u_int16_t val)
160 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
163 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
165 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA, val & 0xff);
167 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA, (val>>8)&0xff);
172 io_write_4(struct am79c930_softc *sc, u_int32_t off, u_int32_t val)
175 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
178 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
180 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,val & 0xff);
182 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>8)&0xff);
184 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>16)&0xff);
186 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>24)&0xff);
191 io_write_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
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 for (i=0; i<len; i++)
203 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,ptr[i]);
207 io_read_1(struct am79c930_softc *sc, u_int32_t off)
211 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
214 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
216 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
222 io_read_2(struct am79c930_softc *sc, u_int32_t off)
226 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
229 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
231 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
233 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 8;
239 io_read_4(struct am79c930_softc *sc, u_int32_t off)
243 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
246 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
248 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
250 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 8;
252 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 16;
254 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 24;
260 io_read_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
265 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
268 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
270 for (i=0; i<len; i++)
271 ptr[i] = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
276 mem_write_1(struct am79c930_softc *sc, u_int32_t off, u_int8_t val)
278 bus_space_write_1(sc->sc_memt, sc->sc_memh, off, val);
282 void mem_write_2(struct am79c930_softc *sc, u_int32_t off, u_int16_t val)
284 bus_space_tag_t t = sc->sc_memt;
285 bus_space_handle_t h = sc->sc_memh;
287 /* could be unaligned */
288 if ((off & 0x1) == 0)
289 bus_space_write_2(t, h, off, htole16(val));
291 bus_space_write_1(t, h, off, val & 0xff);
292 bus_space_write_1(t, h, off+1, (val >> 8) & 0xff);
297 mem_write_4(struct am79c930_softc *sc, u_int32_t off, u_int32_t val)
299 bus_space_tag_t t = sc->sc_memt;
300 bus_space_handle_t h = sc->sc_memh;
302 /* could be unaligned */
303 if ((off & 0x3) == 0)
304 bus_space_write_4(t, h, off, htole32(val));
306 bus_space_write_1(t, h, off, val & 0xff);
307 bus_space_write_1(t, h, off+1, (val >> 8) & 0xff);
308 bus_space_write_1(t, h, off+2, (val >> 16) & 0xff);
309 bus_space_write_1(t, h, off+3, (val >> 24) & 0xff);
314 mem_write_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
317 bus_space_write_region_1 (sc->sc_memt, sc->sc_memh, off, ptr, len);
321 mem_read_1(struct am79c930_softc *sc, u_int32_t off)
323 return bus_space_read_1(sc->sc_memt, sc->sc_memh, off);
327 mem_read_2(struct am79c930_softc *sc, u_int32_t off)
329 /* could be unaligned */
330 if ((off & 0x1) == 0)
331 return le16toh(bus_space_read_2(sc->sc_memt, sc->sc_memh, off));
334 bus_space_read_1(sc->sc_memt, sc->sc_memh, off ) |
335 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+1) << 8);
339 mem_read_4(struct am79c930_softc *sc, u_int32_t off)
341 /* could be unaligned */
342 if ((off & 0x3) == 0)
343 return le32toh(bus_space_read_4(sc->sc_memt, sc->sc_memh, off));
346 bus_space_read_1(sc->sc_memt, sc->sc_memh, off ) |
347 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+1) << 8) |
348 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+2) <<16) |
349 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+3) <<24);
353 mem_read_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
356 bus_space_read_region_1 (sc->sc_memt, sc->sc_memh, off, ptr, len);
365 am79c930_gcr_setbits(struct am79c930_softc *sc, u_int8_t bits)
367 u_int8_t gcr = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
371 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_GCR, gcr);
379 am79c930_gcr_clearbits(struct am79c930_softc *sc, u_int8_t bits)
381 u_int8_t gcr = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
385 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_GCR, gcr);
389 am79c930_gcr_read(struct am79c930_softc *sc)
391 return bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
396 am79c930_regdump(struct am79c930_softc *sc)
402 for (i=0; i<8; i++) {
403 buf[i] = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, i);
406 printf("am79c930: regdump:");
407 for (i=0; i<8; i++) {
408 printf(" %02x", buf[i]);
415 am79c930_chip_init(struct am79c930_softc *sc, int how)
417 /* zero the bank select register, and leave it that way.. */
418 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_BSS, 0);
420 sc->sc_ops = &memspace_ops;
422 sc->sc_ops = &iospace_ops;