1 /* $NetBSD: am79c930.c,v 1.15 2007/10/19 11:59:47 ad 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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Am79c930 chip driver.
35 * This is used by the awi driver to use the shared
36 * memory attached to the 79c930 to communicate with the firmware running
37 * in the 930's on-board 80188 core.
39 * The 79c930 can be mapped into just I/O space, or also have a
40 * memory mapping; the mapping must be set up by the bus front-end
41 * before am79c930_init is called.
47 * read_8, read_16, read_32, read_64, read_bytes
48 * write_8, write_16, write_32, write_64, write_bytes
49 * (two versions, depending on whether memory-space or i/o space is in use).
56 #include <sys/cdefs.h>
58 __KERNEL_RCSID(0, "$NetBSD: am79c930.c,v 1.15 2007/10/19 11:59:47 ad Exp $");
61 __FBSDID("$FreeBSD$");
64 #include <sys/param.h>
65 #include <sys/systm.h>
66 #include <sys/endian.h>
68 #include <sys/device.h>
73 #include <machine/bus_pio.h>
74 #include <machine/bus_memio.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 #ifndef __BUS_SPACE_HAS_STREAM_METHODS
93 #define bus_space_read_stream_2 bus_space_read_2
94 #define bus_space_read_stream_4 bus_space_read_4
95 #define bus_space_write_stream_2 bus_space_write_2
96 #define bus_space_write_stream_4 bus_space_write_4
97 #endif /* __BUS_SPACE_HAS_STREAM_METHODS */
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 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_stream_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_stream_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_stream_2(sc
->sc_memt
,
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);
340 mem_read_4(struct am79c930_softc
*sc
, u_int32_t off
)
342 /* could be unaligned */
343 if ((off
& 0x3) == 0)
344 return le32toh(bus_space_read_stream_4(sc
->sc_memt
, sc
->sc_memh
,
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);
355 mem_read_bytes(struct am79c930_softc
*sc
, u_int32_t off
, u_int8_t
*ptr
,
358 bus_space_read_region_1 (sc
->sc_memt
, sc
->sc_memh
, off
, ptr
, len
);
367 am79c930_gcr_setbits(struct am79c930_softc
*sc
, u_int8_t bits
)
369 u_int8_t gcr
= bus_space_read_1 (sc
->sc_iot
, sc
->sc_ioh
, AM79C930_GCR
);
373 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, AM79C930_GCR
, gcr
);
381 am79c930_gcr_clearbits(struct am79c930_softc
*sc
, u_int8_t bits
)
383 u_int8_t gcr
= bus_space_read_1 (sc
->sc_iot
, sc
->sc_ioh
, AM79C930_GCR
);
387 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, AM79C930_GCR
, gcr
);
391 am79c930_gcr_read(struct am79c930_softc
*sc
)
393 return bus_space_read_1 (sc
->sc_iot
, sc
->sc_ioh
, AM79C930_GCR
);
398 am79c930_regdump(struct am79c930_softc
*sc
)
404 for (i
=0; i
<8; i
++) {
405 buf
[i
] = bus_space_read_1 (sc
->sc_iot
, sc
->sc_ioh
, i
);
408 printf("am79c930: regdump:");
409 for (i
=0; i
<8; i
++) {
410 printf(" %02x", buf
[i
]);
417 am79c930_chip_init(struct am79c930_softc
*sc
, int how
)
419 /* zero the bank select register, and leave it that way.. */
420 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, AM79C930_BSS
, 0);
422 sc
->sc_ops
= &memspace_ops
;
424 sc
->sc_ops
= &iospace_ops
;