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