3 * Ben Gray <ben.r.gray@gmail.com>.
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.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Ben Gray.
17 * 4. The name of the company nor the name of the author may be used to
18 * endorse or promote products derived from this software without specific
19 * prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY BEN GRAY ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL BEN GRAY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * SCM - System Control Module
36 * Hopefully in the end this module will contain a bunch of utility functions
37 * for configuring and querying the general system control registers, but for
38 * now it only does pin(pad) multiplexing.
40 * This is different from the GPIO module in that it is used to configure the
41 * pins between modules not just GPIO input/output.
43 * This file contains the generic top level driver, however it relies on chip
44 * specific settings and therefore expects an array of ti_scm_padconf structs
45 * call ti_padconf_devmap to be located somewhere in the kernel.
48 #include <sys/cdefs.h>
49 __FBSDID("$FreeBSD$");
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/kernel.h>
54 #include <sys/module.h>
56 #include <sys/resource.h>
59 #include <sys/mutex.h>
61 #include <machine/bus.h>
62 #include <machine/cpu.h>
63 #include <machine/cpufunc.h>
64 #include <machine/resource.h>
66 #include <dev/fdt/fdt_common.h>
67 #include <dev/fdt/fdt_pinctrl.h>
68 #include <dev/ofw/openfirm.h>
69 #include <dev/ofw/ofw_bus.h>
70 #include <dev/ofw/ofw_bus_subr.h>
74 static struct resource_spec ti_scm_res_spec[] = {
75 { SYS_RES_MEMORY, 0, RF_ACTIVE }, /* Control memory window */
79 static struct ti_scm_softc *ti_scm_sc;
81 #define ti_scm_read_4(sc, reg) \
82 bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
83 #define ti_scm_write_4(sc, reg, val) \
84 bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
87 * Device part of OMAP SCM driver
90 ti_scm_probe(device_t dev)
92 if (!ofw_bus_status_okay(dev))
95 if (!ofw_bus_is_compatible(dev, "syscon"))
99 printf("%s: multiple SCM modules in device tree data, ignoring\n",
104 device_set_desc(dev, "TI Control Module");
105 return (BUS_PROBE_DEFAULT);
109 * ti_scm_attach - attaches the timer to the simplebus
112 * Reserves memory and interrupt resources, stores the softc structure
113 * globally and registers both the timecount and eventtimer objects.
116 * Zero on sucess or ENXIO if an error occuried.
119 ti_scm_attach(device_t dev)
121 struct ti_scm_softc *sc = device_get_softc(dev);
125 if (bus_alloc_resources(dev, ti_scm_res_spec, sc->sc_res)) {
126 device_printf(dev, "could not allocate resources\n");
130 /* Global timer interface */
131 sc->sc_bst = rman_get_bustag(sc->sc_res[0]);
132 sc->sc_bsh = rman_get_bushandle(sc->sc_res[0]);
140 ti_scm_reg_read_4(uint32_t reg, uint32_t *val)
145 *val = ti_scm_read_4(ti_scm_sc, reg);
150 ti_scm_reg_write_4(uint32_t reg, uint32_t val)
155 ti_scm_write_4(ti_scm_sc, reg, val);
160 static device_method_t ti_scm_methods[] = {
161 DEVMETHOD(device_probe, ti_scm_probe),
162 DEVMETHOD(device_attach, ti_scm_attach),
167 static driver_t ti_scm_driver = {
170 sizeof(struct ti_scm_softc),
173 static devclass_t ti_scm_devclass;
175 DRIVER_MODULE(ti_scm, simplebus, ti_scm_driver, ti_scm_devclass, 0, 0);