1 /* $NetBSD: imx31_ahb.c,v 1.2 2008/04/27 18:58:44 matt Exp $ */
4 * Copyright (c) 2002, 2005 Genetec Corporation. All rights reserved.
5 * Written by Hiroyuki Bessho for Genetec Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the NetBSD Project by
18 * Genetec Corporation.
19 * 4. The name of Genetec Corporation may not be used to endorse or
20 * promote products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
36 * Autoconfiguration support for the Intel PXA2[15]0 application
37 * processor. This code is derived from arm/sa11x0/sa11x0.c
41 * Copyright (c) 2001, The NetBSD Foundation, Inc. All rights reserved.
43 * This code is derived from software contributed to The NetBSD Foundation
44 * by IWAMOTO Toshihiro and Ichiro FUKUHARA.
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
55 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
56 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
57 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
59 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
60 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
61 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
62 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
63 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
64 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
65 * POSSIBILITY OF SUCH DAMAGE.
69 * Shin Takemura and PocketBSD Project. All rights reserved.
71 * Redistribution and use in source and binary forms, with or without
72 * modification, are permitted provided that the following conditions
74 * 1. Redistributions of source code must retain the above copyright
75 * notice, this list of conditions and the following disclaimer.
76 * 2. Redistributions in binary form must reproduce the above copyright
77 * notice, this list of conditions and the following disclaimer in the
78 * documentation and/or other materials provided with the distribution.
79 * 3. All advertising materials mentioning features or use of this software
80 * must display the following acknowledgement:
81 * This product includes software developed by the PocketBSD project
82 * and its contributors.
83 * 4. Neither the name of the project nor the names of its contributors
84 * may be used to endorse or promote products derived from this software
85 * without specific prior written permission.
87 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
88 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
89 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
90 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
91 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
92 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
93 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
94 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
95 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
96 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
101 #include <sys/cdefs.h>
102 __KERNEL_RCSID(0, "$Id: imx31_ahb.c,v 1.3 2008/05/02 22:00:29 martin Exp $");
104 #include "locators.h"
108 #include <sys/param.h>
109 #include <sys/systm.h>
110 #include <sys/device.h>
111 #include <sys/kernel.h>
112 #include <sys/reboot.h>
114 #include <machine/cpu.h>
115 #include <machine/bus.h>
117 #include <arm/cpufunc.h>
118 #include <arm/mainbus/mainbus.h>
120 #include <machine/intr.h>
122 #include <arm/imx/imx31reg.h>
123 #include <arm/imx/imx31var.h>
126 struct device sc_dev
;
127 bus_dma_tag_t sc_dmat
;
128 bus_space_tag_t sc_memt
;
129 bus_space_handle_t sc_memh
;
133 static int ahb_match(device_t
, cfdata_t
, void *);
134 static void ahb_attach(device_t
, device_t
, void *);
135 static int ahb_search(device_t
, cfdata_t
, const int *, void *);
136 static void ahb_attach_critical(struct ahb_softc
*);
137 static int ahbbus_print(void *, const char *);
139 /* attach structures */
140 CFATTACH_DECL(ahb
, sizeof(struct ahb_softc
),
141 ahb_match
, ahb_attach
, NULL
, NULL
);
143 static struct ahb_softc
*ahb_sc
;
146 ahb_match(device_t parent
, cfdata_t match
, void *aux
)
152 ahb_attach(device_t parent
, device_t self
, void *aux
)
154 struct ahb_softc
*sc
= (struct ahb_softc
*)self
;
155 extern struct bus_space imx31_bs_tag
;
156 struct ahb_attach_args ahba
;
159 sc
->sc_memt
= &imx31_bs_tag
;
160 #if NBUS_DMA_GENERIC > 0
161 sc
->sc_dmat
= &imx31_bus_dma_tag
;
166 aprint_normal(": AHB-Lite 2.v6 bus interface\n");
169 * Attach critical devices
171 ahb_attach_critical(sc
);
174 * Attach all other devices
176 ahba
.ahba_name
= "ahb";
177 ahba
.ahba_memt
= sc
->sc_memt
;
178 ahba
.ahba_dmat
= sc
->sc_dmat
;
179 config_search_ia(ahb_search
, self
, "ahb", &ahba
);
183 ahb_search(device_t parent
, cfdata_t cf
, const int *ldesc
, void *aux
)
185 struct ahb_attach_args
* const ahba
= aux
;
187 ahba
->ahba_addr
= cf
->cf_loc
[AHBCF_ADDR
];
188 ahba
->ahba_size
= cf
->cf_loc
[AHBCF_SIZE
];
189 ahba
->ahba_intr
= cf
->cf_loc
[AHBCF_INTR
];
190 ahba
->ahba_irqbase
= cf
->cf_loc
[AHBCF_IRQBASE
];
192 if (config_match(parent
, cf
, ahba
))
193 config_attach(parent
, cf
, ahba
, ahbbus_print
);
199 ahb_find(device_t parent
, cfdata_t cf
, const int *ldesc
, void *aux
)
201 struct ahb_attach_args
* const ahba
= aux
;
202 struct ahb_attach_args ahba0
;
204 if (strcmp(ahba
->ahba_name
, "ahb"))
206 if (ahba
->ahba_addr
!= AHBCF_ADDR_DEFAULT
207 && ahba
->ahba_addr
!= cf
->cf_loc
[AHBCF_ADDR
])
209 if (ahba
->ahba_size
!= AHBCF_SIZE_DEFAULT
210 && ahba
->ahba_size
!= cf
->cf_loc
[AHBCF_SIZE
])
212 if (ahba
->ahba_intr
!= AHBCF_INTR_DEFAULT
213 && ahba
->ahba_intr
!= cf
->cf_loc
[AHBCF_INTR
])
215 if (ahba
->ahba_irqbase
!= AHBCF_IRQBASE_DEFAULT
216 && ahba
->ahba_irqbase
!= cf
->cf_loc
[AHBCF_IRQBASE
])
220 ahba0
.ahba_addr
= cf
->cf_loc
[AHBCF_ADDR
];
221 ahba0
.ahba_size
= cf
->cf_loc
[AHBCF_SIZE
];
222 ahba0
.ahba_intr
= cf
->cf_loc
[AHBCF_INTR
];
223 ahba0
.ahba_irqbase
= cf
->cf_loc
[AHBCF_IRQBASE
];
225 return config_match(parent
, cf
, &ahba0
);
229 #error no avic present in config file
232 static const struct {
236 } critical_devs
[] = {
237 { .name
= "avic", .addr
= INTC_BASE
, .required
= true },
238 { .name
= "gpio1", .addr
= GPIO1_BASE
, .required
= false },
239 { .name
= "gpio2", .addr
= GPIO2_BASE
, .required
= false },
240 { .name
= "gpio3", .addr
= GPIO3_BASE
, .required
= false },
242 { .name
= "dmac", .addr
= DMAC_BASE
, .required
= true },
247 ahb_attach_critical(struct ahb_softc
*sc
)
249 struct ahb_attach_args ahba
;
253 for (i
= 0; i
< __arraycount(critical_devs
); i
++) {
254 ahba
.ahba_name
= "ahb";
255 ahba
.ahba_memt
= sc
->sc_memt
;
256 ahba
.ahba_dmat
= sc
->sc_dmat
;
258 ahba
.ahba_addr
= critical_devs
[i
].addr
;
259 ahba
.ahba_size
= AHBCF_SIZE_DEFAULT
;
260 ahba
.ahba_intr
= AHBCF_INTR_DEFAULT
;
261 ahba
.ahba_irqbase
= AHBCF_IRQBASE_DEFAULT
;
263 cf
= config_search_ia(ahb_find
, &sc
->sc_dev
, "ahb", &ahba
);
264 if (cf
== NULL
&& critical_devs
[i
].required
)
265 panic("ahb_attach_critical: failed to find %s!",
266 critical_devs
[i
].name
);
268 ahba
.ahba_addr
= cf
->cf_loc
[AHBCF_ADDR
];
269 ahba
.ahba_size
= cf
->cf_loc
[AHBCF_SIZE
];
270 ahba
.ahba_intr
= cf
->cf_loc
[AHBCF_INTR
];
271 ahba
.ahba_irqbase
= cf
->cf_loc
[AHBCF_IRQBASE
];
272 config_attach(&sc
->sc_dev
, cf
, &ahba
, ahbbus_print
);
277 ahbbus_print(void *aux
, const char *name
)
279 struct ahb_attach_args
*ahba
= (struct ahb_attach_args
*)aux
;
281 if (ahba
->ahba_addr
!= AHBCF_ADDR_DEFAULT
) {
282 aprint_normal(" addr 0x%lx", ahba
->ahba_addr
);
283 if (ahba
->ahba_size
> AHBCF_SIZE_DEFAULT
)
284 aprint_normal("-0x%lx",
285 ahba
->ahba_addr
+ ahba
->ahba_size
-1);
287 if (ahba
->ahba_intr
!= AHBCF_INTR_DEFAULT
)
288 aprint_normal(" intr %d", ahba
->ahba_intr
);
289 if (ahba
->ahba_irqbase
!= AHBCF_IRQBASE_DEFAULT
)
290 aprint_normal(" irqbase %d", ahba
->ahba_irqbase
);
295 static inline uint32_t
296 read_clock_counter_xsc1(void)
299 __asm
volatile("mrc p14, 0, %0, c1, c0, 0" : "=r" (x
) );
304 static inline uint32_t
305 read_clock_counter_xsc2(void)
308 __asm
volatile("mrc p14, 0, %0, c1, c1, 0" : "=r" (x
) );