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