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.2 2003/06/17 04:28:22 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>
68 #include <sys/device.h>
71 #include <machine/cpu.h>
73 #include <machine/bus_pio.h>
74 #include <machine/bus_memio.h>
76 #include <machine/bus.h>
78 #include <machine/intr.h>
82 #include <dev/ic/am79c930reg.h>
83 #include <dev/ic/am79c930var.h>
86 #include <dev/awi/am79c930reg.h>
87 #include <dev/awi/am79c930var.h>
90 #define AM930_DELAY(x) /*nothing*/
92 void am79c930_regdump __P((struct am79c930_softc *sc));
94 static void io_write_1 __P((struct am79c930_softc *, u_int32_t, u_int8_t));
95 static void io_write_2 __P((struct am79c930_softc *, u_int32_t, u_int16_t));
96 static void io_write_4 __P((struct am79c930_softc *, u_int32_t, u_int32_t));
97 static void io_write_bytes __P((struct am79c930_softc *, u_int32_t, u_int8_t *, size_t));
99 static u_int8_t io_read_1 __P((struct am79c930_softc *, u_int32_t));
100 static u_int16_t io_read_2 __P((struct am79c930_softc *, u_int32_t));
101 static u_int32_t io_read_4 __P((struct am79c930_softc *, u_int32_t));
102 static void io_read_bytes __P((struct am79c930_softc *, u_int32_t, u_int8_t *, size_t));
104 static void mem_write_1 __P((struct am79c930_softc *, u_int32_t, u_int8_t));
105 static void mem_write_2 __P((struct am79c930_softc *, u_int32_t, u_int16_t));
106 static void mem_write_4 __P((struct am79c930_softc *, u_int32_t, u_int32_t));
107 static void mem_write_bytes __P((struct am79c930_softc *, u_int32_t, u_int8_t *, size_t));
109 static u_int8_t mem_read_1 __P((struct am79c930_softc *, u_int32_t));
110 static u_int16_t mem_read_2 __P((struct am79c930_softc *, u_int32_t));
111 static u_int32_t mem_read_4 __P((struct am79c930_softc *, u_int32_t));
112 static void mem_read_bytes __P((struct am79c930_softc *, u_int32_t, u_int8_t *, size_t));
114 static struct am79c930_ops iospace_ops = {
125 struct am79c930_ops memspace_ops = {
136 static void io_write_1 (sc, off, val)
137 struct am79c930_softc *sc;
142 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
145 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
147 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA, val);
151 static void io_write_2 (sc, off, val)
152 struct am79c930_softc *sc;
157 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
160 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
162 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA, val & 0xff);
164 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA, (val>>8)&0xff);
168 static void io_write_4 (sc, off, val)
169 struct am79c930_softc *sc;
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 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,val & 0xff);
181 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>8)&0xff);
183 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>16)&0xff);
185 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>24)&0xff);
189 static void io_write_bytes (sc, off, ptr, len)
190 struct am79c930_softc *sc;
198 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
201 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
203 for (i=0; i<len; i++)
204 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,ptr[i]);
207 static u_int8_t io_read_1 (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);
223 static u_int16_t io_read_2 (sc, off)
224 struct am79c930_softc *sc;
229 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
232 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
234 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
236 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 8;
241 static u_int32_t io_read_4 (sc, off)
242 struct am79c930_softc *sc;
247 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
250 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
252 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
254 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 8;
256 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 16;
258 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 24;
263 static void io_read_bytes (sc, off, ptr, len)
264 struct am79c930_softc *sc;
271 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
274 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
276 for (i=0; i<len; i++)
277 ptr[i] = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
281 static void mem_write_1 (sc, off, val)
282 struct am79c930_softc *sc;
286 bus_space_write_1(sc->sc_memt, sc->sc_memh, off, val);
289 static void mem_write_2 (sc, off, val)
290 struct am79c930_softc *sc;
294 bus_space_tag_t t = sc->sc_memt;
295 bus_space_handle_t h = sc->sc_memh;
297 /* could be unaligned */
298 if ((off & 0x1) == 0)
299 bus_space_write_2(t, h, off, val);
301 bus_space_write_1(t, h, off, val & 0xff);
302 bus_space_write_1(t, h, off+1, (val >> 8) & 0xff);
306 static void mem_write_4 (sc, off, val)
307 struct am79c930_softc *sc;
311 bus_space_tag_t t = sc->sc_memt;
312 bus_space_handle_t h = sc->sc_memh;
314 /* could be unaligned */
315 if ((off & 0x3) == 0)
316 bus_space_write_4(t, h, off, val);
318 bus_space_write_1(t, h, off, val & 0xff);
319 bus_space_write_1(t, h, off+1, (val >> 8) & 0xff);
320 bus_space_write_1(t, h, off+2, (val >> 16) & 0xff);
321 bus_space_write_1(t, h, off+3, (val >> 24) & 0xff);
325 static void mem_write_bytes (sc, off, ptr, len)
326 struct am79c930_softc *sc;
331 bus_space_write_region_1 (sc->sc_memt, sc->sc_memh, off, ptr, len);
335 static u_int8_t mem_read_1 (sc, off)
336 struct am79c930_softc *sc;
339 return bus_space_read_1(sc->sc_memt, sc->sc_memh, off);
342 static u_int16_t mem_read_2 (sc, off)
343 struct am79c930_softc *sc;
346 /* could be unaligned */
347 if ((off & 0x1) == 0)
348 return bus_space_read_2(sc->sc_memt, sc->sc_memh, off);
351 bus_space_read_1(sc->sc_memt, sc->sc_memh, off ) |
352 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+1) << 8);
355 static u_int32_t mem_read_4 (sc, off)
356 struct am79c930_softc *sc;
359 /* could be unaligned */
360 if ((off & 0x3) == 0)
361 return bus_space_read_4(sc->sc_memt, sc->sc_memh, off);
364 bus_space_read_1(sc->sc_memt, sc->sc_memh, off ) |
365 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+1) << 8) |
366 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+2) <<16) |
367 (bus_space_read_1(sc->sc_memt, sc->sc_memh, off+3) <<24);
372 static void mem_read_bytes (sc, off, ptr, len)
373 struct am79c930_softc *sc;
378 bus_space_read_region_1 (sc->sc_memt, sc->sc_memh, off, ptr, len);
388 void am79c930_gcr_setbits (sc, bits)
389 struct am79c930_softc *sc;
392 u_int8_t gcr = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
396 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_GCR, gcr);
403 void am79c930_gcr_clearbits (sc, bits)
404 struct am79c930_softc *sc;
407 u_int8_t gcr = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
411 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_GCR, gcr);
414 u_int8_t am79c930_gcr_read (sc)
415 struct am79c930_softc *sc;
417 return bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
421 void am79c930_regdump (sc)
422 struct am79c930_softc *sc;
428 for (i=0; i<8; i++) {
429 buf[i] = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, i);
432 printf("am79c930: regdump:");
433 for (i=0; i<8; i++) {
434 printf(" %02x", buf[i]);
440 void am79c930_chip_init (sc, how)
441 struct am79c930_softc *sc;
443 /* zero the bank select register, and leave it that way.. */
444 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_BSS, 0);
446 sc->sc_ops = &memspace_ops;
448 sc->sc_ops = &iospace_ops;