1 /* $NetBSD: iomd.c,v 1.24 2022/09/27 06:36:42 skrll 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/cdefs.h>
46 __KERNEL_RCSID(0, "$NetBSD: iomd.c,v 1.24 2022/09/27 06:36:42 skrll Exp $");
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/kernel.h>
51 #include <sys/conf.h>
52 #include <sys/device.h>
53 #include <sys/bus.h>
54 #include <machine/cpu.h>
55 #include <machine/intr.h>
56 #include <arm/iomd/iomdreg.h>
57 #include <arm/iomd/iomdvar.h>
58
59 #include "iomd.h"
60
61 /*
62 * IOMD device.
63 *
64 * This probes and attaches the top level IOMD device.
65 * It then configures any children of the IOMD device.
66 */
67
68 /*
69 * IOMD softc structure.
70 *
71 * Contains the device node, bus space tag, handle and address
72 * and the IOMD id.
73 */
74
75 struct iomd_softc {
76 device_t sc_dev; /* device node */
77 bus_space_tag_t sc_iot; /* bus tag */
78 bus_space_handle_t sc_ioh; /* bus handle */
79 int sc_id; /* IOMD id */
80 };
81
82 static int iomdmatch(device_t parent, cfdata_t cf, void *aux);
83 static void iomdattach(device_t parent, device_t self, void *aux);
84 static int iomdprint(void *aux, const char *iomdbus);
85
86 CFATTACH_DECL_NEW(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 uint32_t iomd_base = IOMD_BASE;
93
94 /* following flag is used in iomd_irq.s ... has to be cleaned up one day ! */
95 uint32_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
iomdprint(void * aux,const char * name)107 iomdprint(void *aux, const char *name)
108 {
109 /* union iomd_attach_args *ia = aux;*/
110
111 return QUIET;
112 }
113
114 /*
115 * int iomdmatch(device_t parent, cfdata_t cf, void *aux)
116 *
117 * Just return ok for this if it is device 0
118 */
119
120 static int
iomdmatch(device_t parent,cfdata_t cf,void * aux)121 iomdmatch(device_t parent, cfdata_t cf, void *aux)
122 {
123
124 if (iomd_found)
125 return 0;
126 return 1;
127 }
128
129
130 /*
131 * void iomdattach(device_t parent, device_t dev, void *aux)
132 *
133 * Map the IOMD and identify it.
134 * Then configure the child devices based on the IOMD ID.
135 */
136
137 static void
iomdattach(device_t parent,device_t self,void * aux)138 iomdattach(device_t parent, device_t self, void *aux)
139 {
140 struct iomd_softc *sc = device_private(self);
141 /* struct mainbus_attach_args *mb = aux;*/
142 int refresh;
143 #if 0
144 int i, tmp;
145 #endif
146 union iomd_attach_args ia;
147 bus_space_tag_t iot;
148 bus_space_handle_t ioh;
149
150 /* There can be only 1 IOMD. */
151 iomd_found = 1;
152
153 sc->sc_dev = self;
154 iot = sc->sc_iot = &iomd_bs_tag;
155
156 /* Map the IOMD */
157 if (bus_space_map(iot, (int) iomd_base, IOMD_SIZE, 0, &ioh))
158 panic("%s: Cannot map registers", device_xname(self));
159
160 sc->sc_ioh = ioh;
161
162 /* Get the ID */
163 sc->sc_id = bus_space_read_1(iot, ioh, IOMD_ID0)
164 | (bus_space_read_1(iot, ioh, IOMD_ID1) << 8);
165 aprint_normal(": ");
166
167 /* Identify it and get the DRAM refresh rate */
168 switch (sc->sc_id) {
169 case ARM7500_IOC_ID:
170 aprint_normal("ARM7500 IOMD ");
171 refresh = bus_space_read_1(iot, ioh, IOMD_REFCR) & 0x0f;
172 arm7500_ioc_found = 1;
173 break;
174 case ARM7500FE_IOC_ID:
175 aprint_normal("ARM7500FE IOMD ");
176 refresh = bus_space_read_1(iot, ioh, IOMD_REFCR) & 0x0f;
177 arm7500_ioc_found = 1;
178 break;
179 case RPC600_IOMD_ID:
180 aprint_normal("IOMD20 ");
181 refresh = bus_space_read_1(iot, ioh, IOMD_VREFCR) & 0x09;
182 arm7500_ioc_found = 0;
183 break;
184 default:
185 aprint_normal("Unknown IOMD ID=%04x ", sc->sc_id);
186 refresh = -1;
187 arm7500_ioc_found = 0; /* just in case */
188 break;
189 }
190 aprint_normal("version %d\n", bus_space_read_1(iot, ioh, IOMD_VERSION));
191
192 /* Report the DRAM refresh rate */
193 aprint_normal("%s: ", device_xname(self));
194 aprint_normal("DRAM refresh=");
195 switch (refresh) {
196 case 0x0:
197 aprint_normal("off");
198 break;
199 case 0x1:
200 aprint_normal("16us");
201 break;
202 case 0x2:
203 aprint_normal("32us");
204 break;
205 case 0x4:
206 aprint_normal("64us");
207 break;
208 case 0x8:
209 aprint_normal("128us");
210 break;
211 default:
212 aprint_normal("unknown [%02x]", refresh);
213 break;
214 }
215
216 aprint_normal("\n");
217 #if 0
218 /*
219 * No point in reporting this as it may get changed when devices are
220 * attached
221 */
222 tmp = bus_space_read_1(iot, ioh, IOMD_IOTCR);
223 aprint_normal("%s: I/O timings: combo %c, NPCCS1/2 %c", device_xname(self),
224 'A' + ((tmp >>2) & 3), 'A' + (tmp & 3));
225 tmp = bus_space_read_1(iot, ioh, IOMD_ECTCR);
226 aprint_normal(", EASI ");
227 for (i = 0; i < 8; i++, tmp >>= 1)
228 aprint_normal("%c", 'A' + ((tmp & 1) << 2));
229 tmp = bus_space_read_1(iot, ioh, IOMD_DMATCR);
230 aprint_normal(", DMA ");
231 for (i = 0; i < 4; i++, tmp >>= 2)
232 aprint_normal("%c", 'A' + (tmp & 3));
233 aprint_normal("\n");
234 #endif
235
236 /* Set up the external DMA channels */
237 /* XXX - this should be machine dependent not IOMD dependent */
238 switch (sc->sc_id) {
239 case ARM7500_IOC_ID:
240 case ARM7500FE_IOC_ID:
241 break;
242 case RPC600_IOMD_ID:
243 /* DMA channels 2 & 3 are external */
244 bus_space_write_1(iot, ioh, IOMD_DMAEXT, 0x0c);
245 break;
246 }
247
248 /* Configure the child devices */
249
250 /* Attach clock device */
251
252 ia.ia_clk.ca_name = "clk";
253 ia.ia_clk.ca_iot = iot;
254 ia.ia_clk.ca_ioh = ioh;
255 config_found(self, &ia, iomdprint, CFARGS_NONE);
256
257 /* Attach kbd device when configured */
258 if (bus_space_subregion(iot, ioh, IOMD_KBDDAT, 8, &ia.ia_kbd.ka_ioh))
259 panic("%s: Cannot map kbd registers", device_xname(self));
260 ia.ia_kbd.ka_name = "kbd";
261 ia.ia_kbd.ka_iot = iot;
262 ia.ia_kbd.ka_rxirq = IRQ_KBDRX;
263 ia.ia_kbd.ka_txirq = IRQ_KBDTX;
264 config_found(self, &ia, iomdprint, CFARGS_NONE);
265
266 /* Attach iic device */
267
268 if (bus_space_subregion(iot, ioh, IOMD_IOCR, 4, &ia.ia_iic.ia_ioh))
269 panic("%s: Cannot map iic registers", device_xname(self));
270 ia.ia_iic.ia_name = "iic";
271 ia.ia_iic.ia_iot = iot;
272 ia.ia_iic.ia_irq = -1;
273 config_found(self, &ia, iomdprint, CFARGS_NONE);
274
275 switch (sc->sc_id) {
276 case ARM7500_IOC_ID:
277 case ARM7500FE_IOC_ID:
278 /* Attach opms device */
279
280 if (bus_space_subregion(iot, ioh, IOMD_MSDATA, 8,
281 &ia.ia_opms.pa_ioh))
282 panic("%s: Cannot map opms registers", device_xname(self));
283 ia.ia_opms.pa_name = "opms";
284 ia.ia_opms.pa_iot = iot;
285 ia.ia_opms.pa_irq = IRQ_MSDRX;
286 config_found(self, &ia, iomdprint, CFARGS_NONE);
287 break;
288 case RPC600_IOMD_ID:
289 /* Attach (ws)qms device */
290
291 if (bus_space_subregion(iot, ioh, IOMD_MOUSEX, 8,
292 &ia.ia_qms.qa_ioh))
293 panic("%s: Cannot map qms registers", device_xname(self));
294
295 if (bus_space_map(iot, IO_MOUSE_BUTTONS, 4, 0, &ia.ia_qms.qa_ioh_but))
296 panic("%s: Cannot map registers", device_xname(self));
297 ia.ia_qms.qa_name = "qms";
298 ia.ia_qms.qa_iot = iot;
299 ia.ia_qms.qa_irq = IRQ_VSYNC;
300 config_found(self, &ia, iomdprint, CFARGS_NONE);
301 break;
302 }
303 }
304
305 /* End of iomd.c */
306