2 * Copyright (c) 2008 Marius Strobl <marius@FreeBSD.org>
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/kernel.h>
34 #include <sys/module.h>
35 #include <sys/resource.h>
38 #include <dev/ofw/ofw_bus.h>
40 #include <machine/bus.h>
41 #include <machine/resource.h>
45 #define SCHPPM_ESTAR 0
47 #define SCHPPM_ESTAR_CTRL 0x00
48 #define SCHPPM_ESTAR_CTRL_1 0x00000001
49 #define SCHPPM_ESTAR_CTRL_2 0x00000002
50 #define SCHPPM_ESTAR_CTRL_32 0x00000020
51 #define SCHPPM_ESTAR_CTRL_MASK \
52 (SCHPPM_ESTAR_CTRL_1 | SCHPPM_ESTAR_CTRL_2 | SCHPPM_ESTAR_CTRL_32)
54 static struct resource_spec schppm_res_spec[] = {
55 { SYS_RES_MEMORY, SCHPPM_ESTAR, RF_ACTIVE },
60 struct resource *sc_res[SCHPPM_NREG];
63 #define SCHPPM_READ(sc, reg, off) \
64 bus_read_8((sc)->sc_res[(reg)], (off))
65 #define SCHPPM_WRITE(sc, reg, off, val) \
66 bus_write_8((sc)->sc_res[(reg)], (off), (val))
68 static device_probe_t schppm_probe;
69 static device_attach_t schppm_attach;
71 static device_method_t schppm_methods[] = {
72 /* Device interface */
73 DEVMETHOD(device_probe, schppm_probe),
74 DEVMETHOD(device_attach, schppm_attach),
79 static devclass_t schppm_devclass;
81 DEFINE_CLASS_0(schppm, schppm_driver, schppm_methods,
82 sizeof(struct schppm_softc));
83 DRIVER_MODULE(schppm, nexus, schppm_driver, schppm_devclass, 0, 0);
86 schppm_probe(device_t dev)
90 compat = ofw_bus_get_compat(dev);
91 if (compat != NULL && strcmp(ofw_bus_get_name(dev), "ppm") == 0 &&
92 strcmp(compat, "gp2-ppm") == 0) {
93 device_set_desc(dev, "Schizo power management");
94 return (BUS_PROBE_DEFAULT);
100 schppm_attach(device_t dev)
102 struct schppm_softc *sc;
104 sc = device_get_softc(dev);
105 if (bus_alloc_resources(dev, schppm_res_spec, sc->sc_res)) {
106 device_printf(dev, "failed to allocate resources\n");
107 bus_release_resources(dev, schppm_res_spec, sc->sc_res);
112 device_printf(dev, "running at ");
113 switch (SCHPPM_READ(sc, SCHPPM_ESTAR, SCHPPM_ESTAR_CTRL) &
114 SCHPPM_ESTAR_CTRL_MASK) {
115 case SCHPPM_ESTAR_CTRL_1:
118 case SCHPPM_ESTAR_CTRL_2:
121 case SCHPPM_ESTAR_CTRL_32: