2 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@bluezbox.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
34 #include <sys/kernel.h>
36 #include <sys/module.h>
38 #include <machine/bus.h>
39 #include <machine/intr.h>
41 #include <dev/ofw/openfirm.h>
42 #include <dev/ofw/ofw_bus.h>
43 #include <dev/ofw/ofw_bus_subr.h>
46 #define dprintf(fmt, args...) printf(fmt, ##args)
48 #define dprintf(fmt, args...)
51 #define VICIRQSTATUS 0x000
52 #define VICFIQSTATUS 0x004
53 #define VICRAWINTR 0x008
54 #define VICINTSELECT 0x00C
55 #define VICINTENABLE 0x010
56 #define VICINTENCLEAR 0x014
57 #define VICSOFTINT 0x018
58 #define VICSOFTINTCLEAR 0x01C
59 #define VICPROTECTION 0x020
60 #define VICPERIPHID 0xFE0
61 #define VICPRIMECELLID 0xFF0
65 struct pl190_intc_softc {
67 struct resource * intc_res;
70 static struct pl190_intc_softc *pl190_intc_sc = NULL;
72 #define intc_vic_read_4(reg) \
73 bus_read_4(pl190_intc_sc->intc_res, (reg))
74 #define intc_vic_write_4(reg, val) \
75 bus_write_4(pl190_intc_sc->intc_res, (reg), (val))
78 pl190_intc_probe(device_t dev)
81 if (!ofw_bus_status_okay(dev))
84 if (!ofw_bus_is_compatible(dev, "arm,versatile-vic"))
86 device_set_desc(dev, "ARM PL190 VIC");
87 return (BUS_PROBE_DEFAULT);
91 pl190_intc_attach(device_t dev)
93 struct pl190_intc_softc *sc = device_get_softc(dev);
102 /* Request memory resources */
104 sc->intc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
106 if (sc->intc_res == NULL) {
107 device_printf(dev, "Error: could not allocate memory resources\n");
113 * All interrupts should use IRQ line
115 intc_vic_write_4(VICINTSELECT, 0x00000000);
116 /* Disable all interrupts */
117 intc_vic_write_4(VICINTENCLEAR, 0xffffffff);
118 /* Enable INT31, SIC IRQ */
119 intc_vic_write_4(VICINTENABLE, (1U << 31));
122 for (i = 3; i >= 0; i--) {
124 (intc_vic_read_4(VICPERIPHID + i*4) & 0xff);
127 device_printf(dev, "Peripheral ID: %08x\n", id);
130 for (i = 3; i >= 0; i--) {
132 (intc_vic_read_4(VICPRIMECELLID + i*4) & 0xff);
135 device_printf(dev, "PrimeCell ID: %08x\n", id);
140 static device_method_t pl190_intc_methods[] = {
141 DEVMETHOD(device_probe, pl190_intc_probe),
142 DEVMETHOD(device_attach, pl190_intc_attach),
146 static driver_t pl190_intc_driver = {
149 sizeof(struct pl190_intc_softc),
152 static devclass_t pl190_intc_devclass;
154 EARLY_DRIVER_MODULE(intc, simplebus, pl190_intc_driver, pl190_intc_devclass,
155 0, 0, BUS_PASS_INTERRUPT + BUS_PASS_ORDER_MIDDLE);
158 arm_get_next_irq(int last_irq)
161 int32_t irq = last_irq + 1;
167 pending = intc_vic_read_4(VICIRQSTATUS);
168 while (irq < VIC_NIRQS) {
169 if (pending & (1 << irq))
178 arm_mask_irq(uintptr_t nb)
181 dprintf("%s: %d\n", __func__, nb);
182 intc_vic_write_4(VICINTENCLEAR, (1 << nb));
186 arm_unmask_irq(uintptr_t nb)
189 dprintf("%s: %d\n", __func__, nb);
190 intc_vic_write_4(VICINTENABLE, (1 << nb));