2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2006 Benno Rice. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/module.h>
35 #include <sys/malloc.h>
37 #include <sys/timetc.h>
38 #include <machine/armreg.h>
39 #include <machine/bus.h>
40 #include <machine/intr.h>
42 #include <arm/xscale/pxa/pxavar.h>
43 #include <arm/xscale/pxa/pxareg.h>
45 struct pxa_icu_softc {
46 struct resource * pi_res[1];
47 bus_space_tag_t pi_bst;
48 bus_space_handle_t pi_bsh;
51 static struct resource_spec pxa_icu_spec[] = {
52 { SYS_RES_MEMORY, 0, RF_ACTIVE },
56 static struct pxa_icu_softc *pxa_icu_softc = NULL;
58 static int pxa_icu_probe(device_t);
59 static int pxa_icu_attach(device_t);
61 uint32_t pxa_icu_get_icip(void);
62 void pxa_icu_clear_icip(int);
63 uint32_t pxa_icu_get_icfp(void);
64 void pxa_icu_clear_icfp(int);
65 uint32_t pxa_icu_get_icmr(void);
66 void pxa_icu_set_icmr(uint32_t);
67 uint32_t pxa_icu_get_iclr(void);
68 void pxa_icu_set_iclr(uint32_t);
69 uint32_t pxa_icu_get_icpr(void);
70 void pxa_icu_idle_enable(void);
71 void pxa_icu_idle_disable(void);
73 extern uint32_t pxa_gpio_intr_flags[];
76 pxa_icu_probe(device_t dev)
79 device_set_desc(dev, "Interrupt Controller");
84 pxa_icu_attach(device_t dev)
87 struct pxa_icu_softc *sc;
89 sc = (struct pxa_icu_softc *)device_get_softc(dev);
91 if (pxa_icu_softc != NULL)
95 error = bus_alloc_resources(dev, pxa_icu_spec, sc->pi_res);
97 device_printf(dev, "could not allocate resources\n");
101 sc->pi_bst = rman_get_bustag(sc->pi_res[0]);
102 sc->pi_bsh = rman_get_bushandle(sc->pi_res[0]);
104 /* Disable all interrupts. */
107 /* Route all interrupts to IRQ rather than FIQ. */
110 /* XXX: This should move to configure_final or something. */
111 enable_interrupts(PSR_I|PSR_F);
116 static device_method_t pxa_icu_methods[] = {
117 DEVMETHOD(device_probe, pxa_icu_probe),
118 DEVMETHOD(device_attach, pxa_icu_attach),
123 static driver_t pxa_icu_driver = {
126 sizeof(struct pxa_icu_softc),
129 static devclass_t pxa_icu_devclass;
131 DRIVER_MODULE(pxaicu, pxa, pxa_icu_driver, pxa_icu_devclass, 0, 0);
134 arm_get_next_irq(int last __unused)
138 if ((irq = pxa_icu_get_icip()) != 0) {
139 return (ffs(irq) - 1);
142 return (pxa_gpio_get_next_irq());
146 arm_mask_irq(uintptr_t nb)
150 if (nb >= IRQ_GPIO0) {
151 pxa_gpio_mask_irq(nb);
155 mr = pxa_icu_get_icmr();
157 pxa_icu_set_icmr(mr);
161 arm_unmask_irq(uintptr_t nb)
165 if (nb >= IRQ_GPIO0) {
166 pxa_gpio_unmask_irq(nb);
170 mr = pxa_icu_get_icmr();
172 pxa_icu_set_icmr(mr);
176 pxa_icu_get_icip(void)
179 return (bus_space_read_4(pxa_icu_softc->pi_bst,
180 pxa_icu_softc->pi_bsh, ICU_IP));
184 pxa_icu_clear_icip(int irq)
187 bus_space_write_4(pxa_icu_softc->pi_bst,
188 pxa_icu_softc->pi_bsh, ICU_IP, (1 << irq));
192 pxa_icu_get_icfp(void)
195 return (bus_space_read_4(pxa_icu_softc->pi_bst,
196 pxa_icu_softc->pi_bsh, ICU_FP));
200 pxa_icu_clear_icfp(int irq)
203 bus_space_write_4(pxa_icu_softc->pi_bst,
204 pxa_icu_softc->pi_bsh, ICU_FP, (1 << irq));
208 pxa_icu_get_icmr(void)
211 return (bus_space_read_4(pxa_icu_softc->pi_bst,
212 pxa_icu_softc->pi_bsh, ICU_MR));
216 pxa_icu_set_icmr(uint32_t val)
219 bus_space_write_4(pxa_icu_softc->pi_bst,
220 pxa_icu_softc->pi_bsh, ICU_MR, val);
224 pxa_icu_get_iclr(void)
227 return (bus_space_read_4(pxa_icu_softc->pi_bst,
228 pxa_icu_softc->pi_bsh, ICU_LR));
232 pxa_icu_set_iclr(uint32_t val)
235 bus_space_write_4(pxa_icu_softc->pi_bst,
236 pxa_icu_softc->pi_bsh, ICU_LR, val);
240 pxa_icu_get_icpr(void)
243 return (bus_space_read_4(pxa_icu_softc->pi_bst,
244 pxa_icu_softc->pi_bsh, ICU_PR));
248 pxa_icu_idle_enable(void)
251 bus_space_write_4(pxa_icu_softc->pi_bst,
252 pxa_icu_softc->pi_bsh, ICU_CR, 0x0);
256 pxa_icu_idle_disable(void)
259 bus_space_write_4(pxa_icu_softc->pi_bst,
260 pxa_icu_softc->pi_bsh, ICU_CR, 0x1);