iomd.c revision 1.1.4.5 1 /* $NetBSD: iomd.c,v 1.1.4.5 2002/10/18 02:35:29 nathanw Exp $ */
2
3 /*
4 * Copyright (c) 1996-1997 Mark Brinicombe.
5 * Copyright (c) 1997 Causality Limited
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Mark Brinicombe.
19 * 4. The name of the company nor the name of the author may be used to
20 * endorse or promote products derived from this software without specific
21 * prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * RiscBSD kernel project
36 *
37 * iomd.c
38 *
39 * Probing and configuration for the IOMD
40 *
41 * Created : 10/10/95
42 * Updated : 18/03/01 for rpckbd as part of the wscons project
43 */
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/kernel.h>
48 #include <sys/conf.h>
49 #include <sys/malloc.h>
50 #include <sys/device.h>
51 #include <machine/bus.h>
52 #include <machine/cpu.h>
53 #include <machine/intr.h>
54 #include <arm/iomd/iomdreg.h>
55 #include <arm/iomd/iomdvar.h>
56
57 #include "iomd.h"
58
59 /*
60 * IOMD device.
61 *
62 * This probes and attaches the top level IOMD device.
63 * It then configures any children of the IOMD device.
64 */
65
66 /*
67 * IOMD softc structure.
68 *
69 * Contains the device node, bus space tag, handle and address
70 * and the IOMD id.
71 */
72
73 struct iomd_softc {
74 struct device sc_dev; /* device node */
75 bus_space_tag_t sc_iot; /* bus tag */
76 bus_space_handle_t sc_ioh; /* bus handle */
77 int sc_id; /* IOMD id */
78 };
79
80 static int iomdmatch __P((struct device *parent, struct cfdata *cf,
81 void *aux));
82 static void iomdattach __P((struct device *parent, struct device *self,
83 void *aux));
84 static int iomdprint __P((void *aux, const char *iomdbus));
85
86 CFATTACH_DECL(iomd, sizeof(struct iomd_softc),
87 iomdmatch, iomdattach, NULL, NULL);
88
89 extern struct bus_space iomd_bs_tag;
90
91 int iomd_found;
92 u_int32_t iomd_base = IOMD_BASE;
93
94 /* following flag is used in iomd_irq.s ... has to be cleaned up one day ! */
95 u_int32_t arm7500_ioc_found = 0;
96
97
98 /* Declare prototypes */
99
100 /*
101 * int iomdprint(void *aux, const char *name)
102 *
103 * print configuration info for children
104 */
105
106 static int
107 iomdprint(aux, name)
108 void *aux;
109 const char *name;
110 {
111 /* union iomd_attach_args *ia = aux;*/
112
113 return(QUIET);
114 }
115
116 /*
117 * int iomdmatch(struct device *parent, struct cfdata *cf, void *aux)
118 *
119 * Just return ok for this if it is device 0
120 */
121
122 static int
123 iomdmatch(parent, cf, aux)
124 struct device *parent;
125 struct cfdata *cf;
126 void *aux;
127 {
128 if (iomd_found)
129 return 0;
130 return 1;
131 }
132
133
134 /*
135 * void iomdattach(struct device *parent, struct device *dev, void *aux)
136 *
137 * Map the IOMD and identify it.
138 * Then configure the child devices based on the IOMD ID.
139 */
140
141 static void
142 iomdattach(parent, self, aux)
143 struct device *parent;
144 struct device *self;
145 void *aux;
146 {
147 struct iomd_softc *sc = (struct iomd_softc *)self;
148 /* struct mainbus_attach_args *mb = aux;*/
149 int refresh;
150 #if 0
151 int i, tmp;
152 #endif
153 union iomd_attach_args ia;
154 bus_space_tag_t iot;
155 bus_space_handle_t ioh;
156
157 /* There can be only 1 IOMD. */
158 iomd_found = 1;
159
160 iot = sc->sc_iot = &iomd_bs_tag;
161
162 /* Map the IOMD */
163 if (bus_space_map(iot, (int) iomd_base, IOMD_SIZE, 0, &ioh))
164 panic("%s: Cannot map registers", self->dv_xname);
165
166 sc->sc_ioh = ioh;
167
168 /* Get the ID */
169 sc->sc_id = bus_space_read_1(iot, ioh, IOMD_ID0)
170 | (bus_space_read_1(iot, ioh, IOMD_ID1) << 8);
171 printf(": ");
172
173 /* Identify it and get the DRAM refresh rate */
174 switch (sc->sc_id) {
175 case ARM7500_IOC_ID:
176 printf("ARM7500 IOMD ");
177 refresh = bus_space_read_1(iot, ioh, IOMD_REFCR) & 0x0f;
178 arm7500_ioc_found = 1;
179 break;
180 case ARM7500FE_IOC_ID:
181 printf("ARM7500FE IOMD ");
182 refresh = bus_space_read_1(iot, ioh, IOMD_REFCR) & 0x0f;
183 arm7500_ioc_found = 1;
184 break;
185 case RPC600_IOMD_ID:
186 printf("IOMD20 ");
187 refresh = bus_space_read_1(iot, ioh, IOMD_VREFCR) & 0x09;
188 arm7500_ioc_found = 0;
189 break;
190 default:
191 printf("Unknown IOMD ID=%04x ", sc->sc_id);
192 refresh = -1;
193 arm7500_ioc_found = 0; /* just in case */
194 break;
195 }
196 printf("version %d\n", bus_space_read_1(iot, ioh, IOMD_VERSION));
197
198 /* Report the DRAM refresh rate */
199 printf("%s: ", self->dv_xname);
200 printf("DRAM refresh=");
201 switch (refresh) {
202 case 0x0:
203 printf("off");
204 break;
205 case 0x1:
206 printf("16us");
207 break;
208 case 0x2:
209 printf("32us");
210 break;
211 case 0x4:
212 printf("64us");
213 break;
214 case 0x8:
215 printf("128us");
216 break;
217 default:
218 printf("unknown [%02x]", refresh);
219 break;
220 }
221
222 printf("\n");
223 #if 0
224 /*
225 * No point in reporting this as it may get changed when devices are
226 * attached
227 */
228 tmp = bus_space_read_1(iot, ioh, IOMD_IOTCR);
229 printf("%s: I/O timings: combo %c, NPCCS1/2 %c", self->dv_xname,
230 'A' + ((tmp >>2) & 3), 'A' + (tmp & 3));
231 tmp = bus_space_read_1(iot, ioh, IOMD_ECTCR);
232 printf(", EASI ");
233 for (i = 0; i < 8; i++, tmp >>= 1)
234 printf("%c", 'A' + ((tmp & 1) << 2));
235 tmp = bus_space_read_1(iot, ioh, IOMD_DMATCR);
236 printf(", DMA ");
237 for (i = 0; i < 4; i++, tmp >>= 2)
238 printf("%c", 'A' + (tmp & 3));
239 printf("\n");
240 #endif
241
242 /* Set up the external DMA channels */
243 /* XXX - this should be machine dependant not IOMD dependant */
244 switch (sc->sc_id) {
245 case ARM7500_IOC_ID:
246 case ARM7500FE_IOC_ID:
247 break;
248 case RPC600_IOMD_ID:
249 /* DMA channels 2 & 3 are external */
250 bus_space_write_1(iot, ioh, IOMD_DMAEXT, 0x0c);
251 break;
252 }
253
254 /* Configure the child devices */
255
256 /* Attach clock device */
257
258 ia.ia_clk.ca_name = "clk";
259 ia.ia_clk.ca_iot = iot;
260 ia.ia_clk.ca_ioh = ioh;
261 config_found(self, &ia, iomdprint);
262
263 /* Attach kbd device when configured */
264 if (bus_space_subregion(iot, ioh, IOMD_KBDDAT, 8, &ia.ia_kbd.ka_ioh))
265 panic("%s: Cannot map kbd registers", self->dv_xname);
266 ia.ia_kbd.ka_name = "kbd";
267 ia.ia_kbd.ka_iot = iot;
268 ia.ia_kbd.ka_rxirq = IRQ_KBDRX;
269 ia.ia_kbd.ka_txirq = IRQ_KBDTX;
270 config_found(self, &ia, iomdprint);
271
272 /* Attach rpckbc device when configured */
273 ia.ia_kbd.ka_name = "rpckbd";
274 ia.ia_kbd.ka_rxirq = IRQ_KBDRX;
275 ia.ia_kbd.ka_txirq = IRQ_KBDTX;
276 config_found(self, &ia, iomdprint);
277
278 /* Attach iic device */
279
280 if (bus_space_subregion(iot, ioh, IOMD_IOCR, 4, &ia.ia_iic.ia_ioh))
281 panic("%s: Cannot map iic registers", self->dv_xname);
282 ia.ia_iic.ia_name = "iic";
283 ia.ia_iic.ia_iot = iot;
284 ia.ia_iic.ia_irq = -1;
285 config_found(self, &ia, iomdprint);
286
287 switch (sc->sc_id) {
288 case ARM7500_IOC_ID:
289 case ARM7500FE_IOC_ID:
290 /* Attach opms device */
291
292 if (bus_space_subregion(iot, ioh, IOMD_MSDATA, 8, &ia.ia_opms.pa_ioh))
293 panic("%s: Cannot map opms registers", self->dv_xname);
294 ia.ia_opms.pa_name = "opms";
295 ia.ia_opms.pa_iot = iot;
296 ia.ia_opms.pa_irq = IRQ_MSDRX;
297 config_found(self, &ia, iomdprint);
298 break;
299 case RPC600_IOMD_ID:
300 /* Attach (ws)qms device */
301
302 if (bus_space_subregion(iot, ioh, IOMD_MOUSEX, 8, &ia.ia_qms.qa_ioh))
303 panic("%s: Cannot map qms registers", self->dv_xname);
304
305 if (bus_space_map(iot, IO_MOUSE_BUTTONS, 4, 0, &ia.ia_qms.qa_ioh_but))
306 panic("%s: Cannot map registers", self->dv_xname);
307 ia.ia_qms.qa_name = "qms";
308 ia.ia_qms.qa_iot = iot;
309 ia.ia_qms.qa_irq = IRQ_VSYNC;
310 config_found(self, &ia, iomdprint);
311 break;
312 }
313 }
314
315 /* End of iomd.c */
316