2 * Copyright (c) 2006 Benno Rice. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #include <sys/cdefs.h>
26 __FBSDID("$FreeBSD$");
28 #include <sys/param.h>
29 #include <sys/systm.h>
31 #include <sys/kernel.h>
32 #include <sys/module.h>
33 #include <sys/malloc.h>
35 #include <sys/timetc.h>
36 #include <machine/armreg.h>
37 #include <machine/bus.h>
38 #include <machine/intr.h>
40 #include <arm/xscale/pxa/pxavar.h>
41 #include <arm/xscale/pxa/pxareg.h>
43 struct pxa_icu_softc {
44 struct resource * pi_res[1];
45 bus_space_tag_t pi_bst;
46 bus_space_handle_t pi_bsh;
49 static struct resource_spec pxa_icu_spec[] = {
50 { SYS_RES_MEMORY, 0, RF_ACTIVE },
54 static struct pxa_icu_softc *pxa_icu_softc = NULL;
56 static int pxa_icu_probe(device_t);
57 static int pxa_icu_attach(device_t);
59 uint32_t pxa_icu_get_icip(void);
60 void pxa_icu_clear_icip(int);
61 uint32_t pxa_icu_get_icfp(void);
62 void pxa_icu_clear_icfp(int);
63 uint32_t pxa_icu_get_icmr(void);
64 void pxa_icu_set_icmr(uint32_t);
65 uint32_t pxa_icu_get_iclr(void);
66 void pxa_icu_set_iclr(uint32_t);
67 uint32_t pxa_icu_get_icpr(void);
68 void pxa_icu_idle_enable(void);
69 void pxa_icu_idle_disable(void);
71 extern uint32_t pxa_gpio_intr_flags[];
74 pxa_icu_probe(device_t dev)
77 device_set_desc(dev, "Interrupt Controller");
82 pxa_icu_attach(device_t dev)
85 struct pxa_icu_softc *sc;
87 sc = (struct pxa_icu_softc *)device_get_softc(dev);
89 if (pxa_icu_softc != NULL)
93 error = bus_alloc_resources(dev, pxa_icu_spec, sc->pi_res);
95 device_printf(dev, "could not allocate resources\n");
99 sc->pi_bst = rman_get_bustag(sc->pi_res[0]);
100 sc->pi_bsh = rman_get_bushandle(sc->pi_res[0]);
102 /* Disable all interrupts. */
105 /* Route all interrupts to IRQ rather than FIQ. */
108 /* XXX: This should move to configure_final or something. */
109 enable_interrupts(PSR_I|PSR_F);
114 static device_method_t pxa_icu_methods[] = {
115 DEVMETHOD(device_probe, pxa_icu_probe),
116 DEVMETHOD(device_attach, pxa_icu_attach),
121 static driver_t pxa_icu_driver = {
124 sizeof(struct pxa_icu_softc),
127 static devclass_t pxa_icu_devclass;
129 DRIVER_MODULE(pxaicu, pxa, pxa_icu_driver, pxa_icu_devclass, 0, 0);
132 arm_get_next_irq(int last __unused)
136 if ((irq = pxa_icu_get_icip()) != 0) {
137 return (ffs(irq) - 1);
140 return (pxa_gpio_get_next_irq());
144 arm_mask_irq(uintptr_t nb)
148 if (nb >= IRQ_GPIO0) {
149 pxa_gpio_mask_irq(nb);
153 mr = pxa_icu_get_icmr();
155 pxa_icu_set_icmr(mr);
159 arm_unmask_irq(uintptr_t nb)
163 if (nb >= IRQ_GPIO0) {
164 pxa_gpio_unmask_irq(nb);
168 mr = pxa_icu_get_icmr();
170 pxa_icu_set_icmr(mr);
177 return (bus_space_read_4(pxa_icu_softc->pi_bst,
178 pxa_icu_softc->pi_bsh, ICU_IP));
182 pxa_icu_clear_icip(int irq)
185 bus_space_write_4(pxa_icu_softc->pi_bst,
186 pxa_icu_softc->pi_bsh, ICU_IP, (1 << irq));
193 return (bus_space_read_4(pxa_icu_softc->pi_bst,
194 pxa_icu_softc->pi_bsh, ICU_FP));
198 pxa_icu_clear_icfp(int irq)
201 bus_space_write_4(pxa_icu_softc->pi_bst,
202 pxa_icu_softc->pi_bsh, ICU_FP, (1 << irq));
209 return (bus_space_read_4(pxa_icu_softc->pi_bst,
210 pxa_icu_softc->pi_bsh, ICU_MR));
214 pxa_icu_set_icmr(uint32_t val)
217 bus_space_write_4(pxa_icu_softc->pi_bst,
218 pxa_icu_softc->pi_bsh, ICU_MR, val);
225 return (bus_space_read_4(pxa_icu_softc->pi_bst,
226 pxa_icu_softc->pi_bsh, ICU_LR));
230 pxa_icu_set_iclr(uint32_t val)
233 bus_space_write_4(pxa_icu_softc->pi_bst,
234 pxa_icu_softc->pi_bsh, ICU_LR, val);
241 return (bus_space_read_4(pxa_icu_softc->pi_bst,
242 pxa_icu_softc->pi_bsh, ICU_PR));
246 pxa_icu_idle_enable()
249 bus_space_write_4(pxa_icu_softc->pi_bst,
250 pxa_icu_softc->pi_bsh, ICU_CR, 0x0);
254 pxa_icu_idle_disable()
257 bus_space_write_4(pxa_icu_softc->pi_bst,
258 pxa_icu_softc->pi_bsh, ICU_CR, 0x1);