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