imx31_ahb.c revision 1.1.2.3 1 1.1.2.3 matt /* $NetBSD: imx31_ahb.c,v 1.1.2.3 2007/09/12 06:17:11 matt Exp $ */
2 1.1.2.1 matt
3 1.1.2.1 matt /*
4 1.1.2.1 matt * Copyright (c) 2002, 2005 Genetec Corporation. All rights reserved.
5 1.1.2.1 matt * Written by Hiroyuki Bessho for Genetec Corporation.
6 1.1.2.1 matt *
7 1.1.2.1 matt * Redistribution and use in source and binary forms, with or without
8 1.1.2.1 matt * modification, are permitted provided that the following conditions
9 1.1.2.1 matt * are met:
10 1.1.2.1 matt * 1. Redistributions of source code must retain the above copyright
11 1.1.2.1 matt * notice, this list of conditions and the following disclaimer.
12 1.1.2.1 matt * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.2.1 matt * notice, this list of conditions and the following disclaimer in the
14 1.1.2.1 matt * documentation and/or other materials provided with the distribution.
15 1.1.2.1 matt * 3. All advertising materials mentioning features or use of this software
16 1.1.2.1 matt * must display the following acknowledgement:
17 1.1.2.1 matt * This product includes software developed for the NetBSD Project by
18 1.1.2.1 matt * Genetec Corporation.
19 1.1.2.1 matt * 4. The name of Genetec Corporation may not be used to endorse or
20 1.1.2.1 matt * promote products derived from this software without specific prior
21 1.1.2.1 matt * written permission.
22 1.1.2.1 matt *
23 1.1.2.1 matt * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
24 1.1.2.1 matt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.1.2.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.1.2.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
27 1.1.2.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.1.2.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.1.2.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.1.2.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.1.2.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.1.2.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.1.2.1 matt * POSSIBILITY OF SUCH DAMAGE.
34 1.1.2.1 matt *
35 1.1.2.1 matt *
36 1.1.2.1 matt * Autoconfiguration support for the Intel PXA2[15]0 application
37 1.1.2.1 matt * processor. This code is derived from arm/sa11x0/sa11x0.c
38 1.1.2.1 matt */
39 1.1.2.1 matt
40 1.1.2.1 matt /*-
41 1.1.2.1 matt * Copyright (c) 2001, The NetBSD Foundation, Inc. All rights reserved.
42 1.1.2.1 matt *
43 1.1.2.1 matt * This code is derived from software contributed to The NetBSD Foundation
44 1.1.2.1 matt * by IWAMOTO Toshihiro and Ichiro FUKUHARA.
45 1.1.2.1 matt *
46 1.1.2.1 matt * Redistribution and use in source and binary forms, with or without
47 1.1.2.1 matt * modification, are permitted provided that the following conditions
48 1.1.2.1 matt * are met:
49 1.1.2.1 matt * 1. Redistributions of source code must retain the above copyright
50 1.1.2.1 matt * notice, this list of conditions and the following disclaimer.
51 1.1.2.1 matt * 2. Redistributions in binary form must reproduce the above copyright
52 1.1.2.1 matt * notice, this list of conditions and the following disclaimer in the
53 1.1.2.1 matt * documentation and/or other materials provided with the distribution.
54 1.1.2.1 matt * 3. All advertising materials mentioning features or use of this software
55 1.1.2.1 matt * must display the following acknowledgement:
56 1.1.2.1 matt * This product includes software developed by the NetBSD
57 1.1.2.1 matt * Foundation, Inc. and its contributors.
58 1.1.2.1 matt * 4. Neither the name of The NetBSD Foundation nor the names of its
59 1.1.2.1 matt * contributors may be used to endorse or promote products derived
60 1.1.2.1 matt * from this software without specific prior written permission.
61 1.1.2.1 matt */
62 1.1.2.1 matt /*-
63 1.1.2.1 matt * Copyright (c) 1999
64 1.1.2.1 matt * Shin Takemura and PocketBSD Project. All rights reserved.
65 1.1.2.1 matt *
66 1.1.2.1 matt * Redistribution and use in source and binary forms, with or without
67 1.1.2.1 matt * modification, are permitted provided that the following conditions
68 1.1.2.1 matt * are met:
69 1.1.2.1 matt * 1. Redistributions of source code must retain the above copyright
70 1.1.2.1 matt * notice, this list of conditions and the following disclaimer.
71 1.1.2.1 matt * 2. Redistributions in binary form must reproduce the above copyright
72 1.1.2.1 matt * notice, this list of conditions and the following disclaimer in the
73 1.1.2.1 matt * documentation and/or other materials provided with the distribution.
74 1.1.2.1 matt * 3. All advertising materials mentioning features or use of this software
75 1.1.2.1 matt * must display the following acknowledgement:
76 1.1.2.1 matt * This product includes software developed by the PocketBSD project
77 1.1.2.1 matt * and its contributors.
78 1.1.2.1 matt * 4. Neither the name of the project nor the names of its contributors
79 1.1.2.1 matt * may be used to endorse or promote products derived from this software
80 1.1.2.1 matt * without specific prior written permission.
81 1.1.2.1 matt *
82 1.1.2.1 matt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
83 1.1.2.1 matt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
84 1.1.2.1 matt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
85 1.1.2.1 matt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
86 1.1.2.1 matt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
87 1.1.2.1 matt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
88 1.1.2.1 matt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
89 1.1.2.1 matt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
90 1.1.2.1 matt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
91 1.1.2.1 matt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
92 1.1.2.1 matt * SUCH DAMAGE.
93 1.1.2.1 matt *
94 1.1.2.1 matt */
95 1.1.2.1 matt
96 1.1.2.1 matt #include <sys/cdefs.h>
97 1.1.2.3 matt __KERNEL_RCSID(0, "$Id: imx31_ahb.c,v 1.1.2.3 2007/09/12 06:17:11 matt Exp $");
98 1.1.2.1 matt
99 1.1.2.1 matt #include "locators.h"
100 1.1.2.1 matt #include "avic.h"
101 1.1.2.1 matt #include "imxgpio.h"
102 1.1.2.1 matt
103 1.1.2.1 matt #include <sys/param.h>
104 1.1.2.1 matt #include <sys/systm.h>
105 1.1.2.1 matt #include <sys/device.h>
106 1.1.2.1 matt #include <sys/kernel.h>
107 1.1.2.1 matt #include <sys/reboot.h>
108 1.1.2.1 matt
109 1.1.2.1 matt #include <machine/cpu.h>
110 1.1.2.1 matt #include <machine/bus.h>
111 1.1.2.1 matt
112 1.1.2.1 matt #include <arm/cpufunc.h>
113 1.1.2.1 matt #include <arm/mainbus/mainbus.h>
114 1.1.2.1 matt
115 1.1.2.1 matt #include <machine/intr.h>
116 1.1.2.1 matt
117 1.1.2.1 matt #include <arm/imx/imx31reg.h>
118 1.1.2.1 matt #include <arm/imx/imx31var.h>
119 1.1.2.1 matt
120 1.1.2.1 matt struct ahb_softc {
121 1.1.2.1 matt struct device sc_dev;
122 1.1.2.1 matt bus_dma_tag_t sc_dmat;
123 1.1.2.1 matt bus_space_tag_t sc_memt;
124 1.1.2.1 matt bus_space_handle_t sc_memh;
125 1.1.2.1 matt };
126 1.1.2.1 matt
127 1.1.2.1 matt /* prototypes */
128 1.1.2.1 matt static int ahb_match(device_t, cfdata_t, void *);
129 1.1.2.1 matt static void ahb_attach(device_t, device_t, void *);
130 1.1.2.1 matt static int ahb_search(device_t, cfdata_t, const int *, void *);
131 1.1.2.1 matt static void ahb_attach_critical(struct ahb_softc *);
132 1.1.2.1 matt static int ahbbus_print(void *, const char *);
133 1.1.2.1 matt
134 1.1.2.1 matt /* attach structures */
135 1.1.2.1 matt CFATTACH_DECL(ahb, sizeof(struct ahb_softc),
136 1.1.2.1 matt ahb_match, ahb_attach, NULL, NULL);
137 1.1.2.1 matt
138 1.1.2.1 matt static struct ahb_softc *ahb_sc;
139 1.1.2.1 matt
140 1.1.2.1 matt static int
141 1.1.2.1 matt ahb_match(device_t parent, cfdata_t match, void *aux)
142 1.1.2.1 matt {
143 1.1.2.1 matt return 1;
144 1.1.2.1 matt }
145 1.1.2.1 matt
146 1.1.2.1 matt static void
147 1.1.2.1 matt ahb_attach(device_t parent, device_t self, void *aux)
148 1.1.2.1 matt {
149 1.1.2.1 matt struct ahb_softc *sc = (struct ahb_softc *)self;
150 1.1.2.1 matt extern struct bus_space imx31_bs_tag;
151 1.1.2.1 matt struct ahb_attach_args ahba;
152 1.1.2.1 matt
153 1.1.2.1 matt ahb_sc = sc;
154 1.1.2.1 matt sc->sc_memt = &imx31_bs_tag;
155 1.1.2.1 matt #if NBUS_DMA_GENERIC > 0
156 1.1.2.1 matt sc->sc_dmat = &imx31_bus_dma_tag;
157 1.1.2.1 matt #else
158 1.1.2.1 matt sc->sc_dmat = 0;
159 1.1.2.1 matt #endif
160 1.1.2.1 matt
161 1.1.2.1 matt aprint_normal(": AHB-Lite 2.v6 bus interface\n");
162 1.1.2.1 matt
163 1.1.2.1 matt /*
164 1.1.2.1 matt * Attach critical devices
165 1.1.2.1 matt */
166 1.1.2.1 matt ahb_attach_critical(sc);
167 1.1.2.1 matt
168 1.1.2.1 matt /*
169 1.1.2.1 matt * Attach all other devices
170 1.1.2.1 matt */
171 1.1.2.2 matt ahba.ahba_name = "ahb";
172 1.1.2.1 matt ahba.ahba_memt = sc->sc_memt;
173 1.1.2.1 matt ahba.ahba_dmat = sc->sc_dmat;
174 1.1.2.1 matt config_search_ia(ahb_search, self, "ahb", &ahba);
175 1.1.2.1 matt }
176 1.1.2.1 matt
177 1.1.2.1 matt static int
178 1.1.2.1 matt ahb_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
179 1.1.2.1 matt {
180 1.1.2.1 matt struct ahb_attach_args * const ahba = aux;
181 1.1.2.1 matt
182 1.1.2.1 matt ahba->ahba_addr = cf->cf_loc[AHBCF_ADDR];
183 1.1.2.1 matt ahba->ahba_size = cf->cf_loc[AHBCF_SIZE];
184 1.1.2.1 matt ahba->ahba_intr = cf->cf_loc[AHBCF_INTR];
185 1.1.2.1 matt ahba->ahba_irqbase = cf->cf_loc[AHBCF_IRQBASE];
186 1.1.2.1 matt
187 1.1.2.1 matt if (config_match(parent, cf, ahba))
188 1.1.2.1 matt config_attach(parent, cf, ahba, ahbbus_print);
189 1.1.2.1 matt
190 1.1.2.1 matt return 0;
191 1.1.2.1 matt }
192 1.1.2.1 matt
193 1.1.2.3 matt static int
194 1.1.2.3 matt ahb_find(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
195 1.1.2.1 matt {
196 1.1.2.3 matt struct ahb_attach_args * const ahba = aux;
197 1.1.2.3 matt struct ahb_attach_args ahba0;
198 1.1.2.1 matt
199 1.1.2.3 matt if (strcmp(ahba->ahba_name, "ahb"))
200 1.1.2.3 matt return 0;
201 1.1.2.3 matt if (ahba->ahba_addr != AHBCF_ADDR_DEFAULT
202 1.1.2.3 matt && ahba->ahba_addr != cf->cf_loc[AHBCF_ADDR])
203 1.1.2.3 matt return 0;
204 1.1.2.3 matt if (ahba->ahba_size != AHBCF_SIZE_DEFAULT
205 1.1.2.3 matt && ahba->ahba_size != cf->cf_loc[AHBCF_SIZE])
206 1.1.2.3 matt return 0;
207 1.1.2.3 matt if (ahba->ahba_intr != AHBCF_INTR_DEFAULT
208 1.1.2.3 matt && ahba->ahba_intr != cf->cf_loc[AHBCF_INTR])
209 1.1.2.3 matt return 0;
210 1.1.2.3 matt if (ahba->ahba_irqbase != AHBCF_IRQBASE_DEFAULT
211 1.1.2.3 matt && ahba->ahba_irqbase != cf->cf_loc[AHBCF_IRQBASE])
212 1.1.2.3 matt return 0;
213 1.1.2.3 matt
214 1.1.2.3 matt ahba0 = *ahba;
215 1.1.2.3 matt ahba0.ahba_addr = cf->cf_loc[AHBCF_ADDR];
216 1.1.2.3 matt ahba0.ahba_size = cf->cf_loc[AHBCF_SIZE];
217 1.1.2.3 matt ahba0.ahba_intr = cf->cf_loc[AHBCF_INTR];
218 1.1.2.3 matt ahba0.ahba_irqbase = cf->cf_loc[AHBCF_IRQBASE];
219 1.1.2.3 matt
220 1.1.2.3 matt return config_match(parent, cf, &ahba0);
221 1.1.2.3 matt }
222 1.1.2.2 matt
223 1.1.2.1 matt #if NAVIC == 0
224 1.1.2.1 matt #error no avic present in config file
225 1.1.2.1 matt #endif
226 1.1.2.1 matt
227 1.1.2.3 matt static const struct {
228 1.1.2.3 matt const char *name;
229 1.1.2.3 matt bus_addr_t addr;
230 1.1.2.3 matt bool required;
231 1.1.2.3 matt } critical_devs[] = {
232 1.1.2.3 matt { .name = "avic", .addr = INTC_BASE, .required = true },
233 1.1.2.3 matt { .name = "gpio1", .addr = GPIO1_BASE, .required = false },
234 1.1.2.3 matt { .name = "gpio2", .addr = GPIO2_BASE, .required = false },
235 1.1.2.3 matt { .name = "gpio3", .addr = GPIO3_BASE, .required = false },
236 1.1.2.3 matt #if 0
237 1.1.2.3 matt { .name = "dmac", .addr = DMAC_BASE, .required = true },
238 1.1.2.1 matt #endif
239 1.1.2.3 matt };
240 1.1.2.1 matt
241 1.1.2.3 matt static void
242 1.1.2.3 matt ahb_attach_critical(struct ahb_softc *sc)
243 1.1.2.3 matt {
244 1.1.2.3 matt struct ahb_attach_args ahba;
245 1.1.2.3 matt cfdata_t cf;
246 1.1.2.3 matt size_t i;
247 1.1.2.3 matt
248 1.1.2.3 matt for (i = 0; i < __arraycount(critical_devs); i++) {
249 1.1.2.3 matt ahba.ahba_name = "ahb";
250 1.1.2.3 matt ahba.ahba_memt = sc->sc_memt;
251 1.1.2.3 matt ahba.ahba_dmat = sc->sc_dmat;
252 1.1.2.3 matt
253 1.1.2.3 matt ahba.ahba_addr = critical_devs[i].addr;
254 1.1.2.3 matt ahba.ahba_size = AHBCF_SIZE_DEFAULT;
255 1.1.2.3 matt ahba.ahba_intr = AHBCF_INTR_DEFAULT;
256 1.1.2.3 matt ahba.ahba_irqbase = AHBCF_IRQBASE_DEFAULT;
257 1.1.2.3 matt
258 1.1.2.3 matt cf = config_search_ia(ahb_find, &sc->sc_dev, "ahb", &ahba);
259 1.1.2.3 matt if (cf == NULL && critical_devs[i].required)
260 1.1.2.3 matt panic("ahb_attach_critical: failed to find %s!",
261 1.1.2.3 matt critical_devs[i].name);
262 1.1.2.3 matt
263 1.1.2.3 matt ahba.ahba_addr = cf->cf_loc[AHBCF_ADDR];
264 1.1.2.3 matt ahba.ahba_size = cf->cf_loc[AHBCF_SIZE];
265 1.1.2.3 matt ahba.ahba_intr = cf->cf_loc[AHBCF_INTR];
266 1.1.2.3 matt ahba.ahba_irqbase = cf->cf_loc[AHBCF_IRQBASE];
267 1.1.2.3 matt config_attach(&sc->sc_dev, cf, &ahba, ahbbus_print);
268 1.1.2.3 matt }
269 1.1.2.1 matt }
270 1.1.2.1 matt
271 1.1.2.1 matt static int
272 1.1.2.1 matt ahbbus_print(void *aux, const char *name)
273 1.1.2.1 matt {
274 1.1.2.1 matt struct ahb_attach_args *ahba = (struct ahb_attach_args*)aux;
275 1.1.2.1 matt
276 1.1.2.1 matt if (ahba->ahba_addr != AHBCF_ADDR_DEFAULT) {
277 1.1.2.1 matt aprint_normal(" addr 0x%lx", ahba->ahba_addr);
278 1.1.2.1 matt if (ahba->ahba_size > AHBCF_SIZE_DEFAULT)
279 1.1.2.1 matt aprint_normal("-0x%lx",
280 1.1.2.1 matt ahba->ahba_addr + ahba->ahba_size-1);
281 1.1.2.1 matt }
282 1.1.2.1 matt if (ahba->ahba_intr != AHBCF_INTR_DEFAULT)
283 1.1.2.1 matt aprint_normal(" intr %d", ahba->ahba_intr);
284 1.1.2.3 matt if (ahba->ahba_irqbase != AHBCF_IRQBASE_DEFAULT)
285 1.1.2.1 matt aprint_normal(" irqbase %d", ahba->ahba_irqbase);
286 1.1.2.1 matt
287 1.1.2.1 matt return (UNCONF);
288 1.1.2.1 matt }
289 1.1.2.1 matt
290 1.1.2.1 matt static inline uint32_t
291 1.1.2.1 matt read_clock_counter_xsc1(void)
292 1.1.2.1 matt {
293 1.1.2.1 matt uint32_t x;
294 1.1.2.1 matt __asm volatile("mrc p14, 0, %0, c1, c0, 0" : "=r" (x) );
295 1.1.2.1 matt
296 1.1.2.1 matt return x;
297 1.1.2.1 matt }
298 1.1.2.1 matt
299 1.1.2.1 matt static inline uint32_t
300 1.1.2.1 matt read_clock_counter_xsc2(void)
301 1.1.2.1 matt {
302 1.1.2.1 matt uint32_t x;
303 1.1.2.1 matt __asm volatile("mrc p14, 0, %0, c1, c1, 0" : "=r" (x) );
304 1.1.2.1 matt
305 1.1.2.1 matt return x;
306 1.1.2.1 matt }
307 1.1.2.1 matt
308