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 $ */
5 * Copyright (c) 1999 The NetBSD Foundation, Inc.
8 * This code is derived from software contributed to The NetBSD Foundation
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
41 * Am79c930 chip driver.
43 * This is used by the awi driver to use the shared
44 * memory attached to the 79c930 to communicate with the firmware running
45 * in the 930's on-board 80188 core.
47 * The 79c930 can be mapped into just I/O space, or also have a
48 * memory mapping; the mapping must be set up by the bus front-end
49 * before am79c930_init is called.
55 * read_8, read_16, read_32, read_64, read_bytes
56 * write_8, write_16, write_32, write_64, write_bytes
57 * (two versions, depending on whether memory-space or i/o space is in use).
64 #include <sys/param.h>
65 #include <sys/systm.h>
67 #include <sys/device.h>
70 #include <machine/cpu.h>
72 #include <machine/bus_pio.h>
73 #include <machine/bus_memio.h>
75 #include <machine/bus.h>
77 #include <machine/intr.h>
81 #include <dev/ic/am79c930reg.h>
82 #include <dev/ic/am79c930var.h>
85 #include <dev/awi/am79c930reg.h>
86 #include <dev/awi/am79c930var.h>
89 #define AM930_DELAY(x) /*nothing*/
91 void am79c930_regdump __P((struct am79c930_softc *sc));
93 static void io_write_1 __P((struct am79c930_softc *, u_int32_t, u_int8_t));
94 static void io_write_2 __P((struct am79c930_softc *, u_int32_t, u_int16_t));
95 static void io_write_4 __P((struct am79c930_softc *, u_int32_t, u_int32_t));
96 static void io_write_bytes __P((struct am79c930_softc *, u_int32_t, u_int8_t *, size_t));
98 static u_int8_t io_read_1 __P((struct am79c930_softc *, u_int32_t));
99 static u_int16_t io_read_2 __P((struct am79c930_softc *, u_int32_t));
100 static u_int32_t io_read_4 __P((struct am79c930_softc *, u_int32_t));
101 static void io_read_bytes __P((struct am79c930_softc *, u_int32_t, u_int8_t *, size_t));
103 static void mem_write_1 __P((struct am79c930_softc *, u_int32_t, u_int8_t));
104 static void mem_write_2 __P((struct am79c930_softc *, u_int32_t, u_int16_t));
105 static void mem_write_4 __P((struct am79c930_softc *, u_int32_t, u_int32_t));
106 static void mem_write_bytes __P((struct am79c930_softc *, u_int32_t, u_int8_t *, size_t));
108 static u_int8_t mem_read_1 __P((struct am79c930_softc *, u_int32_t));
109 static u_int16_t mem_read_2 __P((struct am79c930_softc *, u_int32_t));
110 static u_int32_t mem_read_4 __P((struct am79c930_softc *, u_int32_t));
111 static void mem_read_bytes __P((struct am79c930_softc *, u_int32_t, u_int8_t *, size_t));
113 static struct am79c930_ops iospace_ops = {
124 struct am79c930_ops memspace_ops = {
135 static void io_write_1 (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);
150 static void io_write_2 (sc, off, val)
151 struct am79c930_softc *sc;
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);
167 static void io_write_4 (sc, off, val)
168 struct am79c930_softc *sc;
173 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
176 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
178 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,val & 0xff);
180 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>8)&0xff);
182 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>16)&0xff);
184 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>24)&0xff);
188 static void io_write_bytes (sc, off, ptr, len)
189 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 for (i=0; i<len; i++)
203 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,ptr[i]);
206 static u_int8_t io_read_1 (sc, off)
207 struct am79c930_softc *sc;
212 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
215 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
217 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
222 static u_int16_t io_read_2 (sc, off)
223 struct am79c930_softc *sc;
228 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
231 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
233 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
235 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 8;
240 static u_int32_t io_read_4 (sc, off)
241 struct am79c930_softc *sc;
246 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
249 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
251 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
253 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 8;
255 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 16;
257 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 24;
262 static void io_read_bytes (sc, off, ptr, len)
263 struct am79c930_softc *sc;
270 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
273 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
275 for (i=0; i<len; i++)
276 ptr[i] = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
280 static void mem_write_1 (sc, off, val)
281 struct am79c930_softc *sc;
285 bus_space_write_1(sc->sc_memt, sc->sc_memh, off, val);
288 static void mem_write_2 (sc, off, val)
289 struct am79c930_softc *sc;
293 bus_space_tag_t t = sc->sc_memt;
294 bus_space_handle_t h = sc->sc_memh;
296 /* could be unaligned */
297 if ((off & 0x1) == 0)
298 bus_space_write_2(t, h, off, val);
300 bus_space_write_1(t, h, off, val & 0xff);
301 bus_space_write_1(t, h, off+1, (val >> 8) & 0xff);
305 static void mem_write_4 (sc, off, val)
306 struct am79c930_softc *sc;
310 bus_space_tag_t t = sc->sc_memt;
311 bus_space_handle_t h = sc->sc_memh;
313 /* could be unaligned */
314 if ((off & 0x3) == 0)
315 bus_space_write_4(t, h, off, val);
317 bus_space_write_1(t, h, off, val & 0xff);
318 bus_space_write_1(t, h, off+1, (val >> 8) & 0xff);
319 bus_space_write_1(t, h, off+2, (val >> 16) & 0xff);
320 bus_space_write_1(t, h, off+3, (val >> 24) & 0xff);
324 static void mem_write_bytes (sc, off, ptr, len)
325 struct am79c930_softc *sc;
330 bus_space_write_region_1 (sc->sc_memt, sc->sc_memh, off, ptr, len);
334 static u_int8_t mem_read_1 (sc, off)
335 struct am79c930_softc *sc;
338 return bus_space_read_1(sc->sc_memt, sc->sc_memh, off);
341 static u_int16_t mem_read_2 (sc, off)
342 struct am79c930_softc *sc;
345 /* could be unaligned */
346 if ((off & 0x1) == 0)
347 return bus_space_read_2(sc->sc_memt, sc->sc_memh, off);
350 bus_space_read_1(sc->sc_memt, sc->sc_memh, off ) |
351 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+1) << 8);
354 static u_int32_t mem_read_4 (sc, off)
355 struct am79c930_softc *sc;
358 /* could be unaligned */
359 if ((off & 0x3) == 0)
360 return bus_space_read_4(sc->sc_memt, sc->sc_memh, off);
363 bus_space_read_1(sc->sc_memt, sc->sc_memh, off ) |
364 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+1) << 8) |
365 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+2) <<16) |
366 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+3) <<24);
371 static void mem_read_bytes (sc, off, ptr, len)
372 struct am79c930_softc *sc;
377 bus_space_read_region_1 (sc->sc_memt, sc->sc_memh, off, ptr, len);
387 void am79c930_gcr_setbits (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);
402 void am79c930_gcr_clearbits (sc, bits)
403 struct am79c930_softc *sc;
406 u_int8_t gcr = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
410 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_GCR, gcr);
413 u_int8_t am79c930_gcr_read (sc)
414 struct am79c930_softc *sc;
416 return bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
420 void am79c930_regdump (sc)
421 struct am79c930_softc *sc;
427 for (i=0; i<8; i++) {
428 buf[i] = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, i);
431 printf("am79c930: regdump:");
432 for (i=0; i<8; i++) {
433 printf(" %02x", buf[i]);
439 void am79c930_chip_init (sc, how)
440 struct am79c930_softc *sc;
442 /* zero the bank select register, and leave it that way.. */
443 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_BSS, 0);
445 sc->sc_ops = &memspace_ops;
447 sc->sc_ops = &iospace_ops;