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