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