2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2008 Marius Strobl <marius@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <sys/resource.h>
40 #include <dev/ofw/ofw_bus.h>
42 #include <machine/bus.h>
43 #include <machine/resource.h>
47 #define SCHPPM_ESTAR 0
49 #define SCHPPM_ESTAR_CTRL 0x00
50 #define SCHPPM_ESTAR_CTRL_1 0x00000001
51 #define SCHPPM_ESTAR_CTRL_2 0x00000002
52 #define SCHPPM_ESTAR_CTRL_32 0x00000020
53 #define SCHPPM_ESTAR_CTRL_MASK \
54 (SCHPPM_ESTAR_CTRL_1 | SCHPPM_ESTAR_CTRL_2 | SCHPPM_ESTAR_CTRL_32)
56 static struct resource_spec schppm_res_spec[] = {
57 { SYS_RES_MEMORY, SCHPPM_ESTAR, RF_ACTIVE },
62 struct resource *sc_res[SCHPPM_NREG];
65 #define SCHPPM_READ(sc, reg, off) \
66 bus_read_8((sc)->sc_res[(reg)], (off))
67 #define SCHPPM_WRITE(sc, reg, off, val) \
68 bus_write_8((sc)->sc_res[(reg)], (off), (val))
70 static device_probe_t schppm_probe;
71 static device_attach_t schppm_attach;
73 static device_method_t schppm_methods[] = {
74 /* Device interface */
75 DEVMETHOD(device_probe, schppm_probe),
76 DEVMETHOD(device_attach, schppm_attach),
81 static devclass_t schppm_devclass;
83 DEFINE_CLASS_0(schppm, schppm_driver, schppm_methods,
84 sizeof(struct schppm_softc));
85 DRIVER_MODULE(schppm, nexus, schppm_driver, schppm_devclass, 0, 0);
88 schppm_probe(device_t dev)
92 compat = ofw_bus_get_compat(dev);
93 if (compat != NULL && strcmp(ofw_bus_get_name(dev), "ppm") == 0 &&
94 strcmp(compat, "gp2-ppm") == 0) {
95 device_set_desc(dev, "Schizo power management");
96 return (BUS_PROBE_DEFAULT);
102 schppm_attach(device_t dev)
104 struct schppm_softc *sc;
106 sc = device_get_softc(dev);
107 if (bus_alloc_resources(dev, schppm_res_spec, sc->sc_res)) {
108 device_printf(dev, "failed to allocate resources\n");
109 bus_release_resources(dev, schppm_res_spec, sc->sc_res);
114 device_printf(dev, "running at ");
115 switch (SCHPPM_READ(sc, SCHPPM_ESTAR, SCHPPM_ESTAR_CTRL) &
116 SCHPPM_ESTAR_CTRL_MASK) {
117 case SCHPPM_ESTAR_CTRL_1:
120 case SCHPPM_ESTAR_CTRL_2:
123 case SCHPPM_ESTAR_CTRL_32: