gemini_obio.c revision 1.2 1 1.2 cliff /* $NetBSD: gemini_obio.c,v 1.2 2008/11/09 09:04:33 cliff Exp $ */
2 1.1 matt
3 1.1 matt /* adapted from:
4 1.2 cliff * $Id: gemini_obio.c,v 1.2 2008/11/09 09:04:33 cliff Exp $
5 1.1 matt */
6 1.1 matt
7 1.1 matt /*
8 1.1 matt * Autoconfiguration support for the Texas Instruments OMAP "On Board" I/O.
9 1.1 matt *
10 1.1 matt * Based on arm/omap/omap_emifs.c which in turn was derived
11 1.1 matt * Based on arm/xscale/pxa2x0.c which in turn was derived
12 1.1 matt * from arm/sa11x0/sa11x0.c
13 1.1 matt *
14 1.1 matt * Copyright (c) 2002, 2005 Genetec Corporation. All rights reserved.
15 1.1 matt * Written by Hiroyuki Bessho for Genetec Corporation.
16 1.1 matt *
17 1.1 matt * Redistribution and use in source and binary forms, with or without
18 1.1 matt * modification, are permitted provided that the following conditions
19 1.1 matt * are met:
20 1.1 matt * 1. Redistributions of source code must retain the above copyright
21 1.1 matt * notice, this list of conditions and the following disclaimer.
22 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
23 1.1 matt * notice, this list of conditions and the following disclaimer in the
24 1.1 matt * documentation and/or other materials provided with the distribution.
25 1.1 matt * 3. All advertising materials mentioning features or use of this software
26 1.1 matt * must display the following acknowledgement:
27 1.1 matt * This product includes software developed for the NetBSD Project by
28 1.1 matt * Genetec Corporation.
29 1.1 matt * 4. The name of Genetec Corporation may not be used to endorse or
30 1.1 matt * promote products derived from this software without specific prior
31 1.1 matt * written permission.
32 1.1 matt *
33 1.1 matt * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
34 1.1 matt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
35 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
36 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
37 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
40 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
41 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
44 1.1 matt *
45 1.1 matt * Copyright (c) 1997,1998, 2001, The NetBSD Foundation, Inc.
46 1.1 matt * All rights reserved.
47 1.1 matt *
48 1.1 matt * This code is derived from software contributed to The NetBSD Foundation
49 1.1 matt * by IWAMOTO Toshihiro, Ichiro FUKUHARA and Paul Kranenburg.
50 1.1 matt *
51 1.1 matt * Redistribution and use in source and binary forms, with or without
52 1.1 matt * modification, are permitted provided that the following conditions
53 1.1 matt * are met:
54 1.1 matt * 1. Redistributions of source code must retain the above copyright
55 1.1 matt * notice, this list of conditions and the following disclaimer.
56 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
57 1.1 matt * notice, this list of conditions and the following disclaimer in the
58 1.1 matt * documentation and/or other materials provided with the distribution.
59 1.1 matt *
60 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
61 1.1 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
62 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
63 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
64 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
65 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
66 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
67 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
68 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
69 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
70 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
71 1.1 matt *
72 1.1 matt * Copyright (c) 1999
73 1.1 matt * Shin Takemura and PocketBSD Project. All rights reserved.
74 1.1 matt *
75 1.1 matt * Redistribution and use in source and binary forms, with or without
76 1.1 matt * modification, are permitted provided that the following conditions
77 1.1 matt * are met:
78 1.1 matt * 1. Redistributions of source code must retain the above copyright
79 1.1 matt * notice, this list of conditions and the following disclaimer.
80 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
81 1.1 matt * notice, this list of conditions and the following disclaimer in the
82 1.1 matt * documentation and/or other materials provided with the distribution.
83 1.1 matt * 3. All advertising materials mentioning features or use of this software
84 1.1 matt * must display the following acknowledgement:
85 1.1 matt * This product includes software developed by the PocketBSD project
86 1.1 matt * and its contributors.
87 1.1 matt * 4. Neither the name of the project nor the names of its contributors
88 1.1 matt * may be used to endorse or promote products derived from this software
89 1.1 matt * without specific prior written permission.
90 1.1 matt *
91 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
92 1.1 matt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
93 1.1 matt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
94 1.1 matt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
95 1.1 matt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
96 1.1 matt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
97 1.1 matt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
98 1.1 matt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
99 1.1 matt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
100 1.1 matt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
101 1.1 matt * SUCH DAMAGE.
102 1.1 matt */
103 1.1 matt
104 1.1 matt #include "opt_gemini.h"
105 1.1 matt #include <sys/cdefs.h>
106 1.2 cliff __KERNEL_RCSID(0, "$NetBSD: gemini_obio.c,v 1.2 2008/11/09 09:04:33 cliff Exp $");
107 1.1 matt
108 1.1 matt #include "locators.h"
109 1.1 matt #include "obio.h"
110 1.1 matt #include "geminiicu.h"
111 1.2 cliff #include "pci.h"
112 1.1 matt
113 1.1 matt #include <sys/param.h>
114 1.1 matt #include <sys/systm.h>
115 1.1 matt #include <sys/device.h>
116 1.1 matt #include <sys/kernel.h>
117 1.1 matt #include <sys/reboot.h>
118 1.1 matt
119 1.1 matt #include <machine/cpu.h>
120 1.1 matt #include <machine/bus.h>
121 1.1 matt
122 1.1 matt #include <arm/cpufunc.h>
123 1.1 matt #include <arm/mainbus/mainbus.h>
124 1.1 matt #include <arm/gemini/gemini_var.h>
125 1.1 matt #include <arm/gemini/gemini_reg.h>
126 1.1 matt
127 1.1 matt #include <arm/gemini/gemini_obiovar.h>
128 1.1 matt
129 1.1 matt typedef struct {
130 1.1 matt boolean_t cs_valid;
131 1.1 matt ulong cs_addr;
132 1.1 matt ulong cs_size;
133 1.1 matt } obio_csconfig_t;
134 1.1 matt
135 1.1 matt /* prototypes */
136 1.1 matt static int obio_match(device_t, cfdata_t, void *);
137 1.1 matt static void obio_attach(device_t, device_t, void *);
138 1.1 matt static int obio_search(device_t, cfdata_t, const int *, void *);
139 1.1 matt static int obio_find(device_t, cfdata_t, const int *, void *);
140 1.1 matt static int obio_print(void *, const char *);
141 1.1 matt static void obio_attach_critical(struct obio_softc *);
142 1.1 matt
143 1.1 matt /* attach structures */
144 1.1 matt CFATTACH_DECL(obio, sizeof(struct obio_softc),
145 1.1 matt obio_match, obio_attach, NULL, NULL);
146 1.1 matt
147 1.1 matt
148 1.1 matt static int
149 1.1 matt obio_match(device_t parent, cfdata_t match, void *aux)
150 1.1 matt {
151 1.1 matt return 1;
152 1.1 matt }
153 1.1 matt
154 1.1 matt static void
155 1.1 matt obio_attach(device_t parent, device_t self, void *aux)
156 1.1 matt {
157 1.1 matt struct obio_softc *sc = device_private(self);
158 1.1 matt struct mainbus_attach_args *mb = (struct mainbus_attach_args *)aux;
159 1.2 cliff #if NPCI > 0
160 1.1 matt struct pcibus_attach_args pba;
161 1.2 cliff #endif
162 1.1 matt
163 1.1 matt sc->sc_iot = &gemini_bs_tag;
164 1.1 matt
165 1.1 matt aprint_normal(": On-Board IO\n");
166 1.1 matt
167 1.1 matt sc->sc_ioh = 0;
168 1.1 matt sc->sc_dmat = &gemini_bus_dma_tag;
169 1.1 matt sc->sc_base = mb->mb_iobase;
170 1.1 matt sc->sc_size = mb->mb_iosize;
171 1.1 matt
172 1.1 matt /*
173 1.1 matt * Attach critical devices first.
174 1.1 matt */
175 1.1 matt obio_attach_critical(sc);
176 1.1 matt
177 1.2 cliff #if NPCI > 0
178 1.1 matt /*
179 1.1 matt * map PCI controller registers
180 1.1 matt */
181 1.1 matt if (bus_space_map(sc->sc_iot, GEMINI_PCICFG_BASE,
182 1.1 matt GEMINI_PCI_CFG_DATA+4, 0, &sc->sc_pcicfg_ioh)) {
183 1.1 matt aprint_error("cannot map PCI controller at %#x\n",
184 1.1 matt GEMINI_PCICFG_BASE);
185 1.1 matt return;
186 1.1 matt }
187 1.1 matt /*
188 1.1 matt * initialize the PCI chipset tag
189 1.1 matt */
190 1.1 matt gemini_pci_init(&sc->sc_pci_chipset, sc);
191 1.2 cliff #endif /* NPCI */
192 1.1 matt
193 1.1 matt /*
194 1.1 matt * attach the rest of our devices
195 1.1 matt */
196 1.1 matt config_search_ia(obio_search, self, "obio", NULL);
197 1.1 matt
198 1.2 cliff #if NPCI > 0
199 1.1 matt /*
200 1.1 matt * attach the PCI bus
201 1.1 matt */
202 1.1 matt pba.pba_memt = sc->sc_iot;
203 1.1 matt pba.pba_iot = sc->sc_iot;;
204 1.1 matt pba.pba_dmat = sc->sc_dmat;
205 1.1 matt pba.pba_dmat64 = NULL;
206 1.1 matt pba.pba_pc = &sc->sc_pci_chipset;
207 1.1 matt pba.pba_bus = 0;
208 1.1 matt pba.pba_bridgetag = NULL;
209 1.1 matt pba.pba_intrswiz = 0;
210 1.1 matt pba.pba_intrtag = 0;
211 1.1 matt pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
212 1.1 matt PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
213 1.1 matt
214 1.1 matt (void) config_found_ia(&sc->sc_dev, "pcibus", &pba, pcibusprint);
215 1.2 cliff #endif /* NPCI */
216 1.1 matt
217 1.1 matt }
218 1.1 matt
219 1.1 matt static int
220 1.1 matt obio_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
221 1.1 matt {
222 1.1 matt struct obio_softc * const sc = device_private(parent);
223 1.1 matt struct obio_attach_args oa;
224 1.1 matt
225 1.1 matt /* Set up the attach args. */
226 1.1 matt if (cf->cf_loc[OBIOCF_NOBYTEACC] == 1) {
227 1.1 matt #if 0
228 1.1 matt if (cf->cf_loc[OBIOCF_MULT] == 1)
229 1.1 matt oa.obio_iot = &nobyteacc_bs_tag;
230 1.1 matt else
231 1.1 matt #endif
232 1.1 matt panic("nobyteacc specified for device with "
233 1.1 matt "non-byte multiplier\n");
234 1.1 matt } else {
235 1.1 matt switch (cf->cf_loc[OBIOCF_MULT]) {
236 1.1 matt case 1:
237 1.1 matt oa.obio_iot = &gemini_bs_tag;
238 1.1 matt break;
239 1.1 matt #if 0
240 1.1 matt case 2:
241 1.1 matt oa.obio_iot = &gemini_a2x_bs_tag;
242 1.1 matt break;
243 1.1 matt #endif
244 1.1 matt case 4:
245 1.1 matt oa.obio_iot = &gemini_a4x_bs_tag;
246 1.1 matt break;
247 1.1 matt default:
248 1.1 matt panic("Unsupported obio bus multiplier.");
249 1.1 matt break;
250 1.1 matt }
251 1.1 matt }
252 1.1 matt
253 1.1 matt oa.obio_dmat = sc->sc_dmat;
254 1.1 matt oa.obio_addr = cf->cf_loc[OBIOCF_ADDR];
255 1.1 matt oa.obio_size = cf->cf_loc[OBIOCF_SIZE];
256 1.1 matt oa.obio_intr = cf->cf_loc[OBIOCF_INTR];
257 1.1 matt oa.obio_intrbase = cf->cf_loc[OBIOCF_INTRBASE];
258 1.1 matt
259 1.1 matt if (config_match(parent, cf, &oa)) {
260 1.1 matt config_attach(parent, cf, &oa, obio_print);
261 1.1 matt return 0; /* love it */
262 1.1 matt }
263 1.1 matt
264 1.1 matt return UNCONF; /* NG */
265 1.1 matt }
266 1.1 matt
267 1.1 matt static int
268 1.1 matt obio_find(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
269 1.1 matt {
270 1.1 matt struct obio_attach_args * const oa = aux;
271 1.1 matt
272 1.1 matt if (oa->obio_addr != OBIOCF_ADDR_DEFAULT
273 1.1 matt && oa->obio_addr != cf->cf_loc[OBIOCF_ADDR])
274 1.1 matt return 0;
275 1.1 matt if (oa->obio_size != OBIOCF_SIZE_DEFAULT
276 1.1 matt && oa->obio_size != cf->cf_loc[OBIOCF_SIZE])
277 1.1 matt return 0;
278 1.1 matt if (oa->obio_intr != OBIOCF_INTR_DEFAULT
279 1.1 matt && oa->obio_intr != cf->cf_loc[OBIOCF_INTR])
280 1.1 matt return 0;
281 1.1 matt if (oa->obio_intrbase != OBIOCF_INTRBASE_DEFAULT
282 1.1 matt && oa->obio_intrbase != cf->cf_loc[OBIOCF_INTRBASE])
283 1.1 matt return 0;
284 1.1 matt
285 1.1 matt /* Set up the attach args. */
286 1.1 matt if (cf->cf_loc[OBIOCF_NOBYTEACC] == 1) {
287 1.1 matt #if 0
288 1.1 matt if (cf->cf_loc[OBIOCF_MULT] == 1)
289 1.1 matt oa->obio_iot = &nobyteacc_bs_tag;
290 1.1 matt else
291 1.1 matt #endif
292 1.1 matt panic("nobyteacc specified for device with "
293 1.1 matt "non-byte multiplier\n");
294 1.1 matt } else {
295 1.1 matt switch (cf->cf_loc[OBIOCF_MULT]) {
296 1.1 matt case 1:
297 1.1 matt oa->obio_iot = &gemini_bs_tag;
298 1.1 matt break;
299 1.1 matt #if 0
300 1.1 matt case 2:
301 1.1 matt oa->obio_iot = &gemini_a2x_bs_tag;
302 1.1 matt break;
303 1.1 matt #endif
304 1.1 matt case 4:
305 1.1 matt oa->obio_iot = &gemini_a4x_bs_tag;
306 1.1 matt break;
307 1.1 matt default:
308 1.1 matt panic("Unsupported obio bus multiplier.");
309 1.1 matt break;
310 1.1 matt }
311 1.1 matt }
312 1.1 matt oa->obio_addr = cf->cf_loc[OBIOCF_ADDR];
313 1.1 matt oa->obio_size = cf->cf_loc[OBIOCF_SIZE];
314 1.1 matt oa->obio_intr = cf->cf_loc[OBIOCF_INTR];
315 1.1 matt oa->obio_intrbase = cf->cf_loc[OBIOCF_INTRBASE];
316 1.1 matt
317 1.1 matt return config_match(parent, cf, oa);
318 1.1 matt }
319 1.1 matt
320 1.1 matt #if NGEMINIICU == 0
321 1.1 matt #error no geminiicu present in config file
322 1.1 matt #endif
323 1.1 matt
324 1.1 matt static const struct {
325 1.1 matt const char *name;
326 1.1 matt bus_addr_t addr;
327 1.1 matt bool required;
328 1.1 matt } critical_devs[] = {
329 1.2 cliff #ifdef GEMINI_MASTER
330 1.1 matt { .name = "geminiicu0", .addr = 0x48000000, .required = true },
331 1.1 matt { .name = "geminiwdt0", .addr = 0x41000000, .required = true },
332 1.1 matt { .name = "geminitmr0", .addr = 0x43000000, .required = true },
333 1.2 cliff { .name = "geminitmr2", .addr = 0x43000000, .required = true },
334 1.2 cliff #else
335 1.2 cliff { .name = "geminiicu1", .addr = 0x49000000, .required = true },
336 1.1 matt { .name = "geminitmr1", .addr = 0x43000000, .required = true },
337 1.1 matt { .name = "geminitmr2", .addr = 0x43000000, .required = true },
338 1.2 cliff #endif
339 1.1 matt { .name = "com0", .addr = 0x42000000, .required = true },
340 1.1 matt };
341 1.1 matt
342 1.1 matt static void
343 1.1 matt obio_attach_critical(struct obio_softc *sc)
344 1.1 matt {
345 1.1 matt struct obio_attach_args oa;
346 1.1 matt cfdata_t cf;
347 1.1 matt size_t i;
348 1.1 matt
349 1.1 matt for (i = 0; i < __arraycount(critical_devs); i++) {
350 1.1 matt oa.obio_iot = sc->sc_iot;
351 1.1 matt oa.obio_dmat = sc->sc_dmat;
352 1.1 matt
353 1.1 matt oa.obio_addr = critical_devs[i].addr;
354 1.1 matt oa.obio_size = OBIOCF_SIZE_DEFAULT;
355 1.1 matt oa.obio_intr = OBIOCF_INTR_DEFAULT;
356 1.1 matt oa.obio_intrbase = OBIOCF_INTRBASE_DEFAULT;
357 1.1 matt
358 1.1 matt #if 0
359 1.1 matt if (oa.obio_addr != OBIOCF_ADDR_DEFAULT
360 1.1 matt && (oa.obio_addr < sc->sc_base
361 1.1 matt || oa.obio_addr >= sc->sc_base + sc->sc_size))
362 1.1 matt continue;
363 1.1 matt #endif
364 1.1 matt
365 1.1 matt cf = config_search_ia(obio_find, &sc->sc_dev, "obio", &oa);
366 1.1 matt if (cf == NULL && critical_devs[i].required)
367 1.1 matt panic("obio_attach_critical: failed to find %s!",
368 1.1 matt critical_devs[i].name);
369 1.1 matt
370 1.1 matt oa.obio_addr = cf->cf_loc[OBIOCF_ADDR];
371 1.1 matt oa.obio_size = cf->cf_loc[OBIOCF_SIZE];
372 1.1 matt oa.obio_intr = cf->cf_loc[OBIOCF_INTR];
373 1.1 matt oa.obio_intrbase = cf->cf_loc[OBIOCF_INTRBASE];
374 1.1 matt config_attach(&sc->sc_dev, cf, &oa, obio_print);
375 1.1 matt }
376 1.1 matt }
377 1.1 matt
378 1.1 matt static int
379 1.1 matt obio_print(void *aux, const char *name)
380 1.1 matt {
381 1.1 matt struct obio_attach_args *oa = (struct obio_attach_args*)aux;
382 1.1 matt
383 1.1 matt if (oa->obio_addr != OBIOCF_ADDR_DEFAULT) {
384 1.1 matt aprint_normal(" addr 0x%08lx", oa->obio_addr);
385 1.1 matt if (oa->obio_size != OBIOCF_SIZE_DEFAULT)
386 1.1 matt aprint_normal("-0x%08lx",
387 1.1 matt oa->obio_addr + oa->obio_size-1);
388 1.1 matt }
389 1.1 matt if (oa->obio_intr != OBIOCF_INTR_DEFAULT)
390 1.1 matt aprint_normal(" intr %d", oa->obio_intr);
391 1.1 matt if (oa->obio_intrbase != OBIOCF_INTRBASE_DEFAULT)
392 1.1 matt aprint_normal(" intrbase %d", oa->obio_intrbase);
393 1.1 matt
394 1.1 matt return UNCONF;
395 1.1 matt }
396