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