iomd.c revision 1.7 1 /* $NetBSD: iomd.c,v 1.7 2002/10/01 03:10:13 thorpej 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 dma_time;
152 int combo_time;
153 int loop;
154 #endif
155 union iomd_attach_args ia;
156 bus_space_tag_t iot;
157 bus_space_handle_t ioh;
158
159 /* There can be only 1 IOMD. */
160 iomd_found = 1;
161
162 iot = sc->sc_iot = &iomd_bs_tag;
163
164 /* Map the IOMD */
165 if (bus_space_map(iot, (int) iomd_base, IOMD_SIZE, 0, &ioh))
166 panic("%s: Cannot map registers", self->dv_xname);
167
168 sc->sc_ioh = ioh;
169
170 /* Get the ID */
171 sc->sc_id = bus_space_read_1(iot, ioh, IOMD_ID0)
172 | (bus_space_read_1(iot, ioh, IOMD_ID1) << 8);
173 printf(": ");
174
175 /* Identify it and get the DRAM refresh rate */
176 switch (sc->sc_id) {
177 case ARM7500_IOC_ID:
178 printf("ARM7500 IOMD ");
179 refresh = bus_space_read_1(iot, ioh, IOMD_REFCR) & 0x0f;
180 arm7500_ioc_found = 1;
181 break;
182 case ARM7500FE_IOC_ID:
183 printf("ARM7500FE IOMD ");
184 refresh = bus_space_read_1(iot, ioh, IOMD_REFCR) & 0x0f;
185 arm7500_ioc_found = 1;
186 break;
187 case RPC600_IOMD_ID:
188 printf("IOMD20 ");
189 refresh = bus_space_read_1(iot, ioh, IOMD_VREFCR) & 0x09;
190 arm7500_ioc_found = 0;
191 break;
192 default:
193 printf("Unknown IOMD ID=%04x ", sc->sc_id);
194 refresh = -1;
195 arm7500_ioc_found = 0; /* just in case */
196 break;
197 }
198 printf("version %d\n", bus_space_read_1(iot, ioh, IOMD_VERSION));
199
200 /* Report the DRAM refresh rate */
201 printf("%s: ", self->dv_xname);
202 printf("DRAM refresh=");
203 switch (refresh) {
204 case 0x0:
205 printf("off");
206 break;
207 case 0x1:
208 printf("16us");
209 break;
210 case 0x2:
211 printf("32us");
212 break;
213 case 0x4:
214 printf("64us");
215 break;
216 case 0x8:
217 printf("128us");
218 break;
219 default:
220 printf("unknown [%02x]", refresh);
221 break;
222 }
223
224 #if 0
225 /*
226 * No point in reporting this as it may get changed when devices are
227 * attached
228 */
229 dma_time = ReadByte(IOMD_DMATCR);
230 printf(", dma cycle types=");
231 for (loop = 0; loop < 4; ++loop,dma_time = dma_time >> 2)
232 printf("%c", 'A' + (dma_time & 3));
233
234 combo_time = ReadByte(IOMD_IOTCR);
235 printf(", combo cycle type=%c", 'A' + ((combo_time >> 2) & 3));
236 #endif
237 printf("\n");
238
239 /* Set up the external DMA channels */
240 /* XXX - this should be machine dependant not IOMD dependant */
241 switch (sc->sc_id) {
242 case ARM7500_IOC_ID:
243 case ARM7500FE_IOC_ID:
244 break;
245 case RPC600_IOMD_ID:
246 /* DMA channels 2 & 3 are external */
247 bus_space_write_1(iot, ioh, IOMD_DMAEXT, 0x0c);
248 break;
249 }
250
251 /* Configure the child devices */
252
253 /* Attach clock device */
254
255 ia.ia_clk.ca_name = "clk";
256 ia.ia_clk.ca_iot = iot;
257 ia.ia_clk.ca_ioh = ioh;
258 config_found(self, &ia, iomdprint);
259
260 /* Attach kbd device when configured */
261 if (bus_space_subregion(iot, ioh, IOMD_KBDDAT, 8, &ia.ia_kbd.ka_ioh))
262 panic("%s: Cannot map kbd registers", self->dv_xname);
263 ia.ia_kbd.ka_name = "kbd";
264 ia.ia_kbd.ka_iot = iot;
265 ia.ia_kbd.ka_rxirq = IRQ_KBDRX;
266 ia.ia_kbd.ka_txirq = IRQ_KBDTX;
267 config_found(self, &ia, iomdprint);
268
269 /* Attach rpckbc device when configured */
270 ia.ia_kbd.ka_name = "rpckbd";
271 ia.ia_kbd.ka_rxirq = IRQ_KBDRX;
272 ia.ia_kbd.ka_txirq = IRQ_KBDTX;
273 config_found(self, &ia, iomdprint);
274
275 /* Attach iic device */
276
277 if (bus_space_subregion(iot, ioh, IOMD_IOCR, 4, &ia.ia_iic.ia_ioh))
278 panic("%s: Cannot map iic registers", self->dv_xname);
279 ia.ia_iic.ia_name = "iic";
280 ia.ia_iic.ia_iot = iot;
281 ia.ia_iic.ia_irq = -1;
282 config_found(self, &ia, iomdprint);
283
284 switch (sc->sc_id) {
285 case ARM7500_IOC_ID:
286 case ARM7500FE_IOC_ID:
287 /* Attach opms device */
288
289 if (bus_space_subregion(iot, ioh, IOMD_MSDATA, 8, &ia.ia_opms.pa_ioh))
290 panic("%s: Cannot map opms registers", self->dv_xname);
291 ia.ia_opms.pa_name = "opms";
292 ia.ia_opms.pa_iot = iot;
293 ia.ia_opms.pa_irq = IRQ_MSDRX;
294 config_found(self, &ia, iomdprint);
295 break;
296 case RPC600_IOMD_ID:
297 /* Attach (ws)qms device */
298
299 if (bus_space_subregion(iot, ioh, IOMD_MOUSEX, 8, &ia.ia_qms.qa_ioh))
300 panic("%s: Cannot map qms registers", self->dv_xname);
301
302 if (bus_space_map(iot, IO_MOUSE_BUTTONS, 4, 0, &ia.ia_qms.qa_ioh_but))
303 panic("%s: Cannot map registers", self->dv_xname);
304 ia.ia_qms.qa_name = "qms";
305 ia.ia_qms.qa_iot = iot;
306 ia.ia_qms.qa_irq = IRQ_VSYNC;
307 config_found(self, &ia, iomdprint);
308 break;
309 }
310 }
311
312 /* End of iomd.c */
313