FreeBSD/Linux Kernel Cross Reference
sys/dev/awi/am79c930.c
1 /* $NetBSD: am79c930.c,v 1.9 2004/01/15 09:33:48 onoe Exp $ */
2
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Bill Sommerfeld
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.
25 *
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.
37 */
38
39 /*
40 * Am79c930 chip driver.
41 *
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.
45 *
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.
49 */
50
51 /*
52 * operations:
53 *
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).
57 *
58 * interrupt E.C.
59 * start isr
60 * end isr
61 */
62
63 #include <sys/cdefs.h>
64 #ifdef __NetBSD__
65 __KERNEL_RCSID(0, "$NetBSD: am79c930.c,v 1.9 2004/01/15 09:33:48 onoe Exp $");
66 #endif
67 #ifdef __FreeBSD__
68 __FBSDID("$FreeBSD$");
69 #endif
70
71 #include <sys/param.h>
72 #include <sys/systm.h>
73 #include <sys/endian.h>
74 #ifndef __FreeBSD__
75 #include <sys/device.h>
76 #endif
77
78 #include <machine/cpu.h>
79 #include <machine/bus.h>
80 #ifdef __NetBSD__
81 #include <machine/intr.h>
82 #endif
83
84 #ifdef __NetBSD__
85 #include <dev/ic/am79c930reg.h>
86 #include <dev/ic/am79c930var.h>
87 #endif
88 #ifdef __FreeBSD__
89 #include <dev/awi/am79c930reg.h>
90 #include <dev/awi/am79c930var.h>
91 #endif
92
93 #define AM930_DELAY(x) /*nothing*/
94
95 void am79c930_regdump(struct am79c930_softc *sc);
96
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);
101
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);
106
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);
111
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);
116
117 static struct am79c930_ops iospace_ops = {
118 io_write_1,
119 io_write_2,
120 io_write_4,
121 io_write_bytes,
122 io_read_1,
123 io_read_2,
124 io_read_4,
125 io_read_bytes
126 };
127
128 struct am79c930_ops memspace_ops = {
129 mem_write_1,
130 mem_write_2,
131 mem_write_4,
132 mem_write_bytes,
133 mem_read_1,
134 mem_read_2,
135 mem_read_4,
136 mem_read_bytes
137 };
138
139 static void
140 io_write_1( struct am79c930_softc *sc, u_int32_t off, u_int8_t val)
141 {
142 AM930_DELAY(1);
143 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
144 ((off>>8)& 0x7f));
145 AM930_DELAY(1);
146 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
147 AM930_DELAY(1);
148 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA, val);
149 AM930_DELAY(1);
150 }
151
152 static void
153 io_write_2(struct am79c930_softc *sc, u_int32_t off, u_int16_t val)
154 {
155 AM930_DELAY(1);
156 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
157 ((off>>8)& 0x7f));
158 AM930_DELAY(1);
159 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
160 AM930_DELAY(1);
161 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA, val & 0xff);
162 AM930_DELAY(1);
163 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA, (val>>8)&0xff);
164 AM930_DELAY(1);
165 }
166
167 static void
168 io_write_4(struct am79c930_softc *sc, u_int32_t off, u_int32_t val)
169 {
170 AM930_DELAY(1);
171 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
172 ((off>>8)& 0x7f));
173 AM930_DELAY(1);
174 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
175 AM930_DELAY(1);
176 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,val & 0xff);
177 AM930_DELAY(1);
178 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>8)&0xff);
179 AM930_DELAY(1);
180 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>16)&0xff);
181 AM930_DELAY(1);
182 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,(val>>24)&0xff);
183 AM930_DELAY(1);
184 }
185
186 static void
187 io_write_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
188 size_t len)
189 {
190 int i;
191
192 AM930_DELAY(1);
193 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
194 ((off>>8)& 0x7f));
195 AM930_DELAY(1);
196 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_LMA_LO, (off&0xff));
197 AM930_DELAY(1);
198 for (i=0; i<len; i++)
199 bus_space_write_1(sc->sc_iot,sc->sc_ioh,AM79C930_IODPA,ptr[i]);
200 }
201
202 static u_int8_t
203 io_read_1(struct am79c930_softc *sc, u_int32_t off)
204 {
205 u_int8_t val;
206
207 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
208 ((off>>8)& 0x7f));
209 AM930_DELAY(1);
210 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
211 AM930_DELAY(1);
212 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
213 AM930_DELAY(1);
214 return val;
215 }
216
217 static u_int16_t
218 io_read_2(struct am79c930_softc *sc, u_int32_t off)
219 {
220 u_int16_t val;
221
222 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
223 ((off>>8)& 0x7f));
224 AM930_DELAY(1);
225 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
226 AM930_DELAY(1);
227 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
228 AM930_DELAY(1);
229 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 8;
230 AM930_DELAY(1);
231 return val;
232 }
233
234 static u_int32_t
235 io_read_4(struct am79c930_softc *sc, u_int32_t off)
236 {
237 u_int32_t val;
238
239 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
240 ((off>>8)& 0x7f));
241 AM930_DELAY(1);
242 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
243 AM930_DELAY(1);
244 val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA);
245 AM930_DELAY(1);
246 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 8;
247 AM930_DELAY(1);
248 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 16;
249 AM930_DELAY(1);
250 val |= bus_space_read_1(sc->sc_iot, sc->sc_ioh, AM79C930_IODPA) << 24;
251 AM930_DELAY(1);
252 return val;
253 }
254
255 static void
256 io_read_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
257 size_t len)
258 {
259 int i;
260
261 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_HI,
262 ((off>>8)& 0x7f));
263 AM930_DELAY(1);
264 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_LMA_LO, (off&0xff));
265 AM930_DELAY(1);
266 for (i=0; i<len; i++)
267 ptr[i] = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
268 AM79C930_IODPA);
269 }
270
271 static void
272 mem_write_1(struct am79c930_softc *sc, u_int32_t off, u_int8_t val)
273 {
274 bus_space_write_1(sc->sc_memt, sc->sc_memh, off, val);
275 }
276
277 static
278 void mem_write_2(struct am79c930_softc *sc, u_int32_t off, u_int16_t val)
279 {
280 bus_space_tag_t t = sc->sc_memt;
281 bus_space_handle_t h = sc->sc_memh;
282
283 /* could be unaligned */
284 if ((off & 0x1) == 0)
285 bus_space_write_2(t, h, off, htole16(val));
286 else {
287 bus_space_write_1(t, h, off, val & 0xff);
288 bus_space_write_1(t, h, off+1, (val >> 8) & 0xff);
289 }
290 }
291
292 static void
293 mem_write_4(struct am79c930_softc *sc, u_int32_t off, u_int32_t val)
294 {
295 bus_space_tag_t t = sc->sc_memt;
296 bus_space_handle_t h = sc->sc_memh;
297
298 /* could be unaligned */
299 if ((off & 0x3) == 0)
300 bus_space_write_4(t, h, off, htole32(val));
301 else {
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);
306 }
307 }
308
309 static void
310 mem_write_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
311 size_t len)
312 {
313 bus_space_write_region_1 (sc->sc_memt, sc->sc_memh, off, ptr, len);
314 }
315
316 static u_int8_t
317 mem_read_1(struct am79c930_softc *sc, u_int32_t off)
318 {
319 return bus_space_read_1(sc->sc_memt, sc->sc_memh, off);
320 }
321
322 static u_int16_t
323 mem_read_2(struct am79c930_softc *sc, u_int32_t off)
324 {
325 /* could be unaligned */
326 if ((off & 0x1) == 0)
327 return le16toh(bus_space_read_2(sc->sc_memt, sc->sc_memh, off));
328 else
329 return
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);
332 }
333
334 static u_int32_t
335 mem_read_4(struct am79c930_softc *sc, u_int32_t off)
336 {
337 /* could be unaligned */
338 if ((off & 0x3) == 0)
339 return le32toh(bus_space_read_4(sc->sc_memt, sc->sc_memh, off));
340 else
341 return
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);
346 }
347
348 static void
349 mem_read_bytes(struct am79c930_softc *sc, u_int32_t off, u_int8_t *ptr,
350 size_t len)
351 {
352 bus_space_read_region_1 (sc->sc_memt, sc->sc_memh, off, ptr, len);
353 }
354
355
356 /*
357 * Set bits in GCR.
358 */
359
360 void
361 am79c930_gcr_setbits(struct am79c930_softc *sc, u_int8_t bits)
362 {
363 u_int8_t gcr = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
364
365 gcr |= bits;
366
367 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_GCR, gcr);
368 }
369
370 /*
371 * Clear bits in GCR.
372 */
373
374 void
375 am79c930_gcr_clearbits(struct am79c930_softc *sc, u_int8_t bits)
376 {
377 u_int8_t gcr = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
378
379 gcr &= ~bits;
380
381 bus_space_write_1(sc->sc_iot, sc->sc_ioh, AM79C930_GCR, gcr);
382 }
383
384 u_int8_t
385 am79c930_gcr_read(struct am79c930_softc *sc)
386 {
387 return bus_space_read_1 (sc->sc_iot, sc->sc_ioh, AM79C930_GCR);
388 }
389
390 #if 0
391 void
392 am79c930_regdump(struct am79c930_softc *sc)
393 {
394 u_int8_t buf[8];
395 int i;
396
397 AM930_DELAY(5);
398 for (i=0; i<8; i++) {
399 buf[i] = bus_space_read_1 (sc->sc_iot, sc->sc_ioh, i);
400 AM930_DELAY(5);
401 }
402 printf("am79c930: regdump:");
403 for (i=0; i<8; i++) {
404 printf(" %02x", buf[i]);
405 }
406 printf("\n");
407 }
408 #endif
409
410 void
411 am79c930_chip_init(struct am79c930_softc *sc, int how)
412 {
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);
415 if (how)
416 sc->sc_ops = &memspace_ops;
417 else
418 sc->sc_ops = &iospace_ops;
419 }
Cache object: 4501c295faf82cf47b2d0c5910ea4151
|