ioblix_zbus.c revision 1.6 1 /* $NetBSD: ioblix_zbus.c,v 1.6 2002/01/28 09:56:59 aymeric Exp $ */
2
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Ignatios Souvatzis.
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 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: ioblix_zbus.c,v 1.6 2002/01/28 09:56:59 aymeric Exp $");
41
42 /* IOBlix Zorro driver */
43 /* XXX to be done: we need to probe the com clock speed! */
44
45 #include <sys/types.h>
46
47 #include <sys/conf.h>
48 #include <sys/device.h>
49 #include <sys/systm.h>
50 #include <sys/param.h>
51
52 #include <machine/bus.h>
53 #include <machine/conf.h>
54
55 #include <amiga/include/cpu.h>
56
57 #include <amiga/amiga/device.h>
58 #include <amiga/amiga/drcustom.h>
59
60 #include <amiga/dev/supio.h>
61 #include <amiga/dev/zbusvar.h>
62
63
64 struct iobz_softc {
65 struct device sc_dev;
66 struct bus_space_tag sc_bst;
67 };
68
69 int iobzmatch(struct device *, struct cfdata *, void *);
70 void iobzattach(struct device *, struct device *, void *);
71 int iobzprint(void *auxp, const char *);
72 void iobz_shutdown(void *);
73
74 struct cfattach iobl_zbus_ca = {
75 sizeof(struct iobz_softc), iobzmatch, iobzattach
76 };
77
78 int
79 iobzmatch(struct device *parent, struct cfdata *cfp, void *auxp)
80 {
81
82 struct zbus_args *zap;
83
84 zap = auxp;
85
86 if (zap->manid != 4711)
87 return (0);
88
89 if (zap->prodid != 1)
90 return (0);
91
92 return (1);
93 }
94
95 struct iobz_devs {
96 char *name;
97 unsigned off;
98 int arg;
99 } iobzdevices[] = {
100 { "com", 0x100, 24000000 }, /* XXX see below */
101 { "com", 0x108, 24000000 },
102 { "com", 0x110, 24000000 },
103 { "com", 0x118, 24000000 },
104 { "lpt", 0x200, 0 },
105 { "lpt", 0x300, 0 },
106 { 0, 0, 0}
107 };
108
109 #ifndef IOBZCLOCK
110 #define IOBZCLOCK 22118400;
111 #endif
112 int iobzclock = IOBZCLOCK; /* patchable! */
113
114 void
115 iobzattach(struct device *parent, struct device *self, void *auxp)
116 {
117 struct iobz_softc *iobzsc;
118 struct iobz_devs *iobzd;
119 struct zbus_args *zap;
120 struct supio_attach_args supa;
121 extern const struct amiga_bus_space_methods amiga_bus_stride_16;
122 volatile u_int8_t *p;
123
124
125 iobzsc = (struct iobz_softc *)self;
126 zap = auxp;
127
128 if (parent)
129 printf("\n");
130
131 iobzsc->sc_bst.base = (u_long)zap->va;
132 iobzsc->sc_bst.absm = &amiga_bus_stride_16;
133
134 supa.supio_iot = &iobzsc->sc_bst;
135 supa.supio_ipl = 6;
136
137 iobzd = iobzdevices;
138
139 while (iobzd->name) {
140 supa.supio_name = iobzd->name;
141 supa.supio_iobase = iobzd->off;
142 supa.supio_arg = iobzclock /* XXX iobzd->arg */;
143 config_found(self, &supa, iobzprint); /* XXX */
144 ++iobzd;
145 }
146
147 p = (volatile u_int8_t *)zap->va + 2;
148 (void)shutdownhook_establish(iobz_shutdown, (void *)p);
149 *p = ((*p) & 0x1F) | 0x80;
150 }
151
152 int
153 iobzprint(void *auxp, const char *pnp)
154 {
155 struct supio_attach_args *supa;
156 supa = auxp;
157
158 if (pnp == NULL)
159 return(QUIET);
160
161 printf("%s at %s port 0x%02x",
162 supa->supio_name, pnp, supa->supio_iobase);
163
164 return(UNCONF);
165 }
166
167 /*
168 * Disable board interupts at shutdown time.
169 */
170
171 void
172 iobz_shutdown(void *p) {
173 volatile int8_t *q;
174
175 q = p;
176
177 *q &= 0x1F;
178 }
179