gemini_obio.c revision 1.1 1 1.1 matt /* $NetBSD: gemini_obio.c,v 1.1 2008/10/24 04:23:18 matt Exp $ */
2 1.1 matt
3 1.1 matt /* adapted from:
4 1.1 matt * $Id: gemini_obio.c,v 1.1 2008/10/24 04:23:18 matt 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.1 matt __KERNEL_RCSID(0, "$NetBSD: gemini_obio.c,v 1.1 2008/10/24 04:23:18 matt 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.1 matt
112 1.1 matt #include <sys/param.h>
113 1.1 matt #include <sys/systm.h>
114 1.1 matt #include <sys/device.h>
115 1.1 matt #include <sys/kernel.h>
116 1.1 matt #include <sys/reboot.h>
117 1.1 matt
118 1.1 matt #include <machine/cpu.h>
119 1.1 matt #include <machine/bus.h>
120 1.1 matt
121 1.1 matt #include <arm/cpufunc.h>
122 1.1 matt #include <arm/mainbus/mainbus.h>
123 1.1 matt #include <arm/gemini/gemini_var.h>
124 1.1 matt #include <arm/gemini/gemini_reg.h>
125 1.1 matt
126 1.1 matt #include <arm/gemini/gemini_obiovar.h>
127 1.1 matt
128 1.1 matt typedef struct {
129 1.1 matt boolean_t cs_valid;
130 1.1 matt ulong cs_addr;
131 1.1 matt ulong cs_size;
132 1.1 matt } obio_csconfig_t;
133 1.1 matt
134 1.1 matt /* prototypes */
135 1.1 matt static int obio_match(device_t, cfdata_t, void *);
136 1.1 matt static void obio_attach(device_t, device_t, void *);
137 1.1 matt static int obio_search(device_t, cfdata_t, const int *, void *);
138 1.1 matt static int obio_find(device_t, cfdata_t, const int *, void *);
139 1.1 matt static int obio_print(void *, const char *);
140 1.1 matt static void obio_attach_critical(struct obio_softc *);
141 1.1 matt
142 1.1 matt /* attach structures */
143 1.1 matt CFATTACH_DECL(obio, sizeof(struct obio_softc),
144 1.1 matt obio_match, obio_attach, NULL, NULL);
145 1.1 matt
146 1.1 matt
147 1.1 matt static int
148 1.1 matt obio_match(device_t parent, cfdata_t match, void *aux)
149 1.1 matt {
150 1.1 matt return 1;
151 1.1 matt }
152 1.1 matt
153 1.1 matt static void
154 1.1 matt obio_attach(device_t parent, device_t self, void *aux)
155 1.1 matt {
156 1.1 matt struct obio_softc *sc = device_private(self);
157 1.1 matt struct mainbus_attach_args *mb = (struct mainbus_attach_args *)aux;
158 1.1 matt struct pcibus_attach_args pba;
159 1.1 matt
160 1.1 matt sc->sc_iot = &gemini_bs_tag;
161 1.1 matt
162 1.1 matt aprint_normal(": On-Board IO\n");
163 1.1 matt
164 1.1 matt sc->sc_ioh = 0;
165 1.1 matt sc->sc_dmat = &gemini_bus_dma_tag;
166 1.1 matt sc->sc_base = mb->mb_iobase;
167 1.1 matt sc->sc_size = mb->mb_iosize;
168 1.1 matt
169 1.1 matt /*
170 1.1 matt * Attach critical devices first.
171 1.1 matt */
172 1.1 matt obio_attach_critical(sc);
173 1.1 matt
174 1.1 matt /*
175 1.1 matt * map PCI controller registers
176 1.1 matt */
177 1.1 matt if (bus_space_map(sc->sc_iot, GEMINI_PCICFG_BASE,
178 1.1 matt GEMINI_PCI_CFG_DATA+4, 0, &sc->sc_pcicfg_ioh)) {
179 1.1 matt aprint_error("cannot map PCI controller at %#x\n",
180 1.1 matt GEMINI_PCICFG_BASE);
181 1.1 matt return;
182 1.1 matt }
183 1.1 matt /*
184 1.1 matt * initialize the PCI chipset tag
185 1.1 matt */
186 1.1 matt gemini_pci_init(&sc->sc_pci_chipset, sc);
187 1.1 matt
188 1.1 matt /*
189 1.1 matt * attach the rest of our devices
190 1.1 matt */
191 1.1 matt config_search_ia(obio_search, self, "obio", NULL);
192 1.1 matt
193 1.1 matt /*
194 1.1 matt * attach the PCI bus
195 1.1 matt */
196 1.1 matt pba.pba_memt = sc->sc_iot;
197 1.1 matt pba.pba_iot = sc->sc_iot;;
198 1.1 matt pba.pba_dmat = sc->sc_dmat;
199 1.1 matt pba.pba_dmat64 = NULL;
200 1.1 matt pba.pba_pc = &sc->sc_pci_chipset;
201 1.1 matt pba.pba_bus = 0;
202 1.1 matt pba.pba_bridgetag = NULL;
203 1.1 matt pba.pba_intrswiz = 0;
204 1.1 matt pba.pba_intrtag = 0;
205 1.1 matt pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
206 1.1 matt PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
207 1.1 matt
208 1.1 matt (void) config_found_ia(&sc->sc_dev, "pcibus", &pba, pcibusprint);
209 1.1 matt
210 1.1 matt }
211 1.1 matt
212 1.1 matt static int
213 1.1 matt obio_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
214 1.1 matt {
215 1.1 matt struct obio_softc * const sc = device_private(parent);
216 1.1 matt struct obio_attach_args oa;
217 1.1 matt
218 1.1 matt /* Set up the attach args. */
219 1.1 matt if (cf->cf_loc[OBIOCF_NOBYTEACC] == 1) {
220 1.1 matt #if 0
221 1.1 matt if (cf->cf_loc[OBIOCF_MULT] == 1)
222 1.1 matt oa.obio_iot = &nobyteacc_bs_tag;
223 1.1 matt else
224 1.1 matt #endif
225 1.1 matt panic("nobyteacc specified for device with "
226 1.1 matt "non-byte multiplier\n");
227 1.1 matt } else {
228 1.1 matt switch (cf->cf_loc[OBIOCF_MULT]) {
229 1.1 matt case 1:
230 1.1 matt oa.obio_iot = &gemini_bs_tag;
231 1.1 matt break;
232 1.1 matt #if 0
233 1.1 matt case 2:
234 1.1 matt oa.obio_iot = &gemini_a2x_bs_tag;
235 1.1 matt break;
236 1.1 matt #endif
237 1.1 matt case 4:
238 1.1 matt oa.obio_iot = &gemini_a4x_bs_tag;
239 1.1 matt break;
240 1.1 matt default:
241 1.1 matt panic("Unsupported obio bus multiplier.");
242 1.1 matt break;
243 1.1 matt }
244 1.1 matt }
245 1.1 matt
246 1.1 matt oa.obio_dmat = sc->sc_dmat;
247 1.1 matt oa.obio_addr = cf->cf_loc[OBIOCF_ADDR];
248 1.1 matt oa.obio_size = cf->cf_loc[OBIOCF_SIZE];
249 1.1 matt oa.obio_intr = cf->cf_loc[OBIOCF_INTR];
250 1.1 matt oa.obio_intrbase = cf->cf_loc[OBIOCF_INTRBASE];
251 1.1 matt
252 1.1 matt if (config_match(parent, cf, &oa)) {
253 1.1 matt config_attach(parent, cf, &oa, obio_print);
254 1.1 matt return 0; /* love it */
255 1.1 matt }
256 1.1 matt
257 1.1 matt return UNCONF; /* NG */
258 1.1 matt }
259 1.1 matt
260 1.1 matt static int
261 1.1 matt obio_find(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
262 1.1 matt {
263 1.1 matt struct obio_attach_args * const oa = aux;
264 1.1 matt
265 1.1 matt if (oa->obio_addr != OBIOCF_ADDR_DEFAULT
266 1.1 matt && oa->obio_addr != cf->cf_loc[OBIOCF_ADDR])
267 1.1 matt return 0;
268 1.1 matt if (oa->obio_size != OBIOCF_SIZE_DEFAULT
269 1.1 matt && oa->obio_size != cf->cf_loc[OBIOCF_SIZE])
270 1.1 matt return 0;
271 1.1 matt if (oa->obio_intr != OBIOCF_INTR_DEFAULT
272 1.1 matt && oa->obio_intr != cf->cf_loc[OBIOCF_INTR])
273 1.1 matt return 0;
274 1.1 matt if (oa->obio_intrbase != OBIOCF_INTRBASE_DEFAULT
275 1.1 matt && oa->obio_intrbase != cf->cf_loc[OBIOCF_INTRBASE])
276 1.1 matt return 0;
277 1.1 matt
278 1.1 matt /* Set up the attach args. */
279 1.1 matt if (cf->cf_loc[OBIOCF_NOBYTEACC] == 1) {
280 1.1 matt #if 0
281 1.1 matt if (cf->cf_loc[OBIOCF_MULT] == 1)
282 1.1 matt oa->obio_iot = &nobyteacc_bs_tag;
283 1.1 matt else
284 1.1 matt #endif
285 1.1 matt panic("nobyteacc specified for device with "
286 1.1 matt "non-byte multiplier\n");
287 1.1 matt } else {
288 1.1 matt switch (cf->cf_loc[OBIOCF_MULT]) {
289 1.1 matt case 1:
290 1.1 matt oa->obio_iot = &gemini_bs_tag;
291 1.1 matt break;
292 1.1 matt #if 0
293 1.1 matt case 2:
294 1.1 matt oa->obio_iot = &gemini_a2x_bs_tag;
295 1.1 matt break;
296 1.1 matt #endif
297 1.1 matt case 4:
298 1.1 matt oa->obio_iot = &gemini_a4x_bs_tag;
299 1.1 matt break;
300 1.1 matt default:
301 1.1 matt panic("Unsupported obio bus multiplier.");
302 1.1 matt break;
303 1.1 matt }
304 1.1 matt }
305 1.1 matt oa->obio_addr = cf->cf_loc[OBIOCF_ADDR];
306 1.1 matt oa->obio_size = cf->cf_loc[OBIOCF_SIZE];
307 1.1 matt oa->obio_intr = cf->cf_loc[OBIOCF_INTR];
308 1.1 matt oa->obio_intrbase = cf->cf_loc[OBIOCF_INTRBASE];
309 1.1 matt
310 1.1 matt return config_match(parent, cf, oa);
311 1.1 matt }
312 1.1 matt
313 1.1 matt #if NGEMINIICU == 0
314 1.1 matt #error no geminiicu present in config file
315 1.1 matt #endif
316 1.1 matt
317 1.1 matt static const struct {
318 1.1 matt const char *name;
319 1.1 matt bus_addr_t addr;
320 1.1 matt bool required;
321 1.1 matt } critical_devs[] = {
322 1.1 matt { .name = "geminiicu0", .addr = 0x48000000, .required = true },
323 1.1 matt { .name = "geminiwdt0", .addr = 0x41000000, .required = true },
324 1.1 matt { .name = "geminitmr0", .addr = 0x43000000, .required = true },
325 1.1 matt { .name = "geminitmr1", .addr = 0x43000000, .required = true },
326 1.1 matt { .name = "geminitmr2", .addr = 0x43000000, .required = true },
327 1.1 matt { .name = "com0", .addr = 0x42000000, .required = true },
328 1.1 matt };
329 1.1 matt
330 1.1 matt static void
331 1.1 matt obio_attach_critical(struct obio_softc *sc)
332 1.1 matt {
333 1.1 matt struct obio_attach_args oa;
334 1.1 matt cfdata_t cf;
335 1.1 matt size_t i;
336 1.1 matt
337 1.1 matt for (i = 0; i < __arraycount(critical_devs); i++) {
338 1.1 matt oa.obio_iot = sc->sc_iot;
339 1.1 matt oa.obio_dmat = sc->sc_dmat;
340 1.1 matt
341 1.1 matt oa.obio_addr = critical_devs[i].addr;
342 1.1 matt oa.obio_size = OBIOCF_SIZE_DEFAULT;
343 1.1 matt oa.obio_intr = OBIOCF_INTR_DEFAULT;
344 1.1 matt oa.obio_intrbase = OBIOCF_INTRBASE_DEFAULT;
345 1.1 matt
346 1.1 matt #if 0
347 1.1 matt if (oa.obio_addr != OBIOCF_ADDR_DEFAULT
348 1.1 matt && (oa.obio_addr < sc->sc_base
349 1.1 matt || oa.obio_addr >= sc->sc_base + sc->sc_size))
350 1.1 matt continue;
351 1.1 matt #endif
352 1.1 matt
353 1.1 matt cf = config_search_ia(obio_find, &sc->sc_dev, "obio", &oa);
354 1.1 matt if (cf == NULL && critical_devs[i].required)
355 1.1 matt panic("obio_attach_critical: failed to find %s!",
356 1.1 matt critical_devs[i].name);
357 1.1 matt
358 1.1 matt oa.obio_addr = cf->cf_loc[OBIOCF_ADDR];
359 1.1 matt oa.obio_size = cf->cf_loc[OBIOCF_SIZE];
360 1.1 matt oa.obio_intr = cf->cf_loc[OBIOCF_INTR];
361 1.1 matt oa.obio_intrbase = cf->cf_loc[OBIOCF_INTRBASE];
362 1.1 matt config_attach(&sc->sc_dev, cf, &oa, obio_print);
363 1.1 matt }
364 1.1 matt }
365 1.1 matt
366 1.1 matt static int
367 1.1 matt obio_print(void *aux, const char *name)
368 1.1 matt {
369 1.1 matt struct obio_attach_args *oa = (struct obio_attach_args*)aux;
370 1.1 matt
371 1.1 matt if (oa->obio_addr != OBIOCF_ADDR_DEFAULT) {
372 1.1 matt aprint_normal(" addr 0x%08lx", oa->obio_addr);
373 1.1 matt if (oa->obio_size != OBIOCF_SIZE_DEFAULT)
374 1.1 matt aprint_normal("-0x%08lx",
375 1.1 matt oa->obio_addr + oa->obio_size-1);
376 1.1 matt }
377 1.1 matt if (oa->obio_intr != OBIOCF_INTR_DEFAULT)
378 1.1 matt aprint_normal(" intr %d", oa->obio_intr);
379 1.1 matt if (oa->obio_intrbase != OBIOCF_INTRBASE_DEFAULT)
380 1.1 matt aprint_normal(" intrbase %d", oa->obio_intrbase);
381 1.1 matt
382 1.1 matt return UNCONF;
383 1.1 matt }
384