2 * Copyright (c) 2010 Aleksandr Rybalko.
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
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
33 #include <sys/interrupt.h>
34 #include <sys/kernel.h>
35 #include <sys/module.h>
37 #include <sys/malloc.h>
39 #include <machine/bus.h>
41 #include <mips/rt305x/rt305xreg.h>
42 #include <mips/rt305x/rt305x_icvar.h>
45 static int rt305x_ic_probe(device_t);
46 static int rt305x_ic_attach(device_t);
47 static int rt305x_ic_detach(device_t);
50 static struct rt305x_ic_softc *rt305x_ic_softc = NULL;
53 rt305x_ic_probe(device_t dev)
55 device_set_desc(dev, "RT305X Interrupt Controller driver");
60 rt305x_ic_attach(device_t dev)
62 struct rt305x_ic_softc *sc = device_get_softc(dev);
65 KASSERT((device_get_unit(dev) == 0),
66 ("rt305x_ic: Only one Interrupt Controller module supported"));
68 if (rt305x_ic_softc != NULL)
73 /* Map control/status registers. */
75 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
76 &sc->mem_rid, RF_ACTIVE);
78 if (sc->mem_res == NULL) {
79 device_printf(dev, "couldn't map memory\n");
81 rt305x_ic_detach(dev);
84 return (bus_generic_attach(dev));
88 rt305x_ic_detach(device_t dev)
90 struct rt305x_ic_softc *sc = device_get_softc(dev);
92 bus_generic_detach(dev);
95 bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid,
102 rt305x_ic_get(uint32_t reg)
104 struct rt305x_ic_softc *sc = rt305x_ic_softc;
109 return (bus_read_4(sc->mem_res, reg));
113 rt305x_ic_set(uint32_t reg, uint32_t val)
115 struct rt305x_ic_softc *sc = rt305x_ic_softc;
120 bus_write_4(sc->mem_res, reg, val);
126 static device_method_t rt305x_ic_methods[] = {
127 DEVMETHOD(device_probe, rt305x_ic_probe),
128 DEVMETHOD(device_attach, rt305x_ic_attach),
129 DEVMETHOD(device_detach, rt305x_ic_detach),
134 static driver_t rt305x_ic_driver = {
137 sizeof(struct rt305x_ic_softc),
139 static devclass_t rt305x_ic_devclass;
141 DRIVER_MODULE(rt305x_ic, obio, rt305x_ic_driver, rt305x_ic_devclass, 0, 0);