2 * Copyright (c) 2016 Svatopluk Kraus
3 * Copyright (c) 2016 Michal Meloun
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 AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * 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>
34 #include <sys/kernel.h>
35 #include <sys/module.h>
37 #include <sys/systm.h>
39 #include <machine/fdt.h>
40 #include <machine/intr.h>
41 #include <machine/resource.h>
43 #include <dev/ofw/ofw_bus.h>
44 #include <dev/ofw/ofw_bus_subr.h>
48 static struct ofw_compat_data compat_data[] = {
49 {"ti,omap4-wugen-mpu", 1},
53 struct omap4_wugen_sc {
55 struct resource *sc_mem_res;
60 omap4_wugen_activate_intr(device_t dev, struct intr_irqsrc *isrc,
61 struct resource *res, struct intr_map_data *data)
63 struct omap4_wugen_sc *sc = device_get_softc(dev);
65 return (PIC_ACTIVATE_INTR(sc->sc_parent, isrc, res, data));
69 omap4_wugen_disable_intr(device_t dev, struct intr_irqsrc *isrc)
71 struct omap4_wugen_sc *sc = device_get_softc(dev);
73 PIC_DISABLE_INTR(sc->sc_parent, isrc);
77 omap4_wugen_enable_intr(device_t dev, struct intr_irqsrc *isrc)
79 struct omap4_wugen_sc *sc = device_get_softc(dev);
81 PIC_ENABLE_INTR(sc->sc_parent, isrc);
85 omap4_wugen_map_intr(device_t dev, struct intr_map_data *data,
86 struct intr_irqsrc **isrcp)
88 struct omap4_wugen_sc *sc = device_get_softc(dev);
90 return (PIC_MAP_INTR(sc->sc_parent, data, isrcp));
94 omap4_wugen_deactivate_intr(device_t dev, struct intr_irqsrc *isrc,
95 struct resource *res, struct intr_map_data *data)
97 struct omap4_wugen_sc *sc = device_get_softc(dev);
99 return (PIC_DEACTIVATE_INTR(sc->sc_parent, isrc, res, data));
103 omap4_wugen_setup_intr(device_t dev, struct intr_irqsrc *isrc,
104 struct resource *res, struct intr_map_data *data)
106 struct omap4_wugen_sc *sc = device_get_softc(dev);
108 return (PIC_SETUP_INTR(sc->sc_parent, isrc, res, data));
112 omap4_wugen_teardown_intr(device_t dev, struct intr_irqsrc *isrc,
113 struct resource *res, struct intr_map_data *data)
115 struct omap4_wugen_sc *sc = device_get_softc(dev);
117 return (PIC_TEARDOWN_INTR(sc->sc_parent, isrc, res, data));
121 omap4_wugen_pre_ithread(device_t dev, struct intr_irqsrc *isrc)
123 struct omap4_wugen_sc *sc = device_get_softc(dev);
125 PIC_PRE_ITHREAD(sc->sc_parent, isrc);
130 omap4_wugen_post_ithread(device_t dev, struct intr_irqsrc *isrc)
132 struct omap4_wugen_sc *sc = device_get_softc(dev);
134 PIC_POST_ITHREAD(sc->sc_parent, isrc);
138 omap4_wugen_post_filter(device_t dev, struct intr_irqsrc *isrc)
140 struct omap4_wugen_sc *sc = device_get_softc(dev);
142 PIC_POST_FILTER(sc->sc_parent, isrc);
147 omap4_wugen_bind_intr(device_t dev, struct intr_irqsrc *isrc)
149 struct omap4_wugen_sc *sc = device_get_softc(dev);
151 return (PIC_BIND_INTR(sc->sc_parent, isrc));
156 omap4_wugen_probe(device_t dev)
159 if (!ofw_bus_status_okay(dev))
162 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
165 return (BUS_PROBE_DEFAULT);
169 omap4_wugen_detach(device_t dev)
171 struct omap4_wugen_sc *sc;
173 sc = device_get_softc(dev);
174 if (sc->sc_mem_res != NULL) {
175 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res);
176 sc->sc_mem_res = NULL;
182 omap4_wugen_attach(device_t dev)
184 struct omap4_wugen_sc *sc;
186 phandle_t parent_xref;
189 sc = device_get_softc(dev);
191 node = ofw_bus_get_node(dev);
193 rv = OF_getencprop(node, "interrupt-parent", &parent_xref,
194 sizeof(parent_xref));
196 device_printf(dev, "can't read parent node property\n");
199 sc->sc_parent = OF_device_from_xref(parent_xref);
200 if (sc->sc_parent == NULL) {
201 device_printf(dev, "can't find parent controller\n");
206 sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
208 if (sc->sc_mem_res == NULL) {
209 device_printf(dev, "can't allocate resources\n");
213 if (intr_pic_register(dev, OF_xref_from_node(node)) == NULL) {
214 device_printf(dev, "can't register PIC\n");
220 omap4_wugen_detach(dev);
224 static device_method_t omap4_wugen_methods[] = {
225 DEVMETHOD(device_probe, omap4_wugen_probe),
226 DEVMETHOD(device_attach, omap4_wugen_attach),
227 DEVMETHOD(device_detach, omap4_wugen_detach),
229 /* Interrupt controller interface */
230 DEVMETHOD(pic_activate_intr, omap4_wugen_activate_intr),
231 DEVMETHOD(pic_disable_intr, omap4_wugen_disable_intr),
232 DEVMETHOD(pic_enable_intr, omap4_wugen_enable_intr),
233 DEVMETHOD(pic_map_intr, omap4_wugen_map_intr),
234 DEVMETHOD(pic_deactivate_intr, omap4_wugen_deactivate_intr),
235 DEVMETHOD(pic_setup_intr, omap4_wugen_setup_intr),
236 DEVMETHOD(pic_teardown_intr, omap4_wugen_teardown_intr),
237 DEVMETHOD(pic_pre_ithread, omap4_wugen_pre_ithread),
238 DEVMETHOD(pic_post_ithread, omap4_wugen_post_ithread),
239 DEVMETHOD(pic_post_filter, omap4_wugen_post_filter),
241 DEVMETHOD(pic_bind_intr, omap4_wugen_bind_intr),
245 devclass_t omap4_wugen_devclass;
246 DEFINE_CLASS_0(omap4_wugen, omap4_wugen_driver, omap4_wugen_methods,
247 sizeof(struct omap4_wugen_sc));
248 EARLY_DRIVER_MODULE(omap4_wugen, simplebus, omap4_wugen_driver,
249 omap4_wugen_devclass, NULL, NULL,
250 BUS_PASS_INTERRUPT + BUS_PASS_ORDER_MIDDLE + 1);