]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/sparc64/sparc64/schppm.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / sparc64 / sparc64 / schppm.c
1 /*-
2  * Copyright (c) 2008 Marius Strobl <marius@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  *
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
24  * SUCH DAMAGE.
25  */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/bus.h>
33 #include <sys/kernel.h>
34 #include <sys/module.h>
35 #include <sys/resource.h>
36 #include <sys/rman.h>
37
38 #include <dev/ofw/ofw_bus.h>
39
40 #include <machine/bus.h>
41 #include <machine/resource.h>
42
43 #define SCHPPM_NREG     1
44
45 #define SCHPPM_ESTAR    0
46
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)
53
54 static struct resource_spec schppm_res_spec[] = {
55         { SYS_RES_MEMORY, SCHPPM_ESTAR, RF_ACTIVE },
56         { -1, 0 }
57 };
58
59 struct schppm_softc {
60         struct resource         *sc_res[SCHPPM_NREG];
61 };
62
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))
67
68 static device_probe_t schppm_probe;
69 static device_attach_t schppm_attach;
70
71 static device_method_t schppm_methods[] = {
72         /* Device interface */
73         DEVMETHOD(device_probe,         schppm_probe),
74         DEVMETHOD(device_attach,        schppm_attach),
75
76         DEVMETHOD_END
77 };
78
79 static devclass_t schppm_devclass;
80
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);
84
85 static int
86 schppm_probe(device_t dev)
87 {
88         const char* compat;
89
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);
95         }
96         return (ENXIO);
97 }
98
99 static int
100 schppm_attach(device_t dev)
101 {
102         struct schppm_softc *sc;
103
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);
108                 return (ENXIO);
109         }
110
111         if (bootverbose) {
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:
116                         printf("full");
117                         break;
118                 case SCHPPM_ESTAR_CTRL_2:
119                         printf("half");
120                         break;
121                 case SCHPPM_ESTAR_CTRL_32:
122                         printf("1/32");
123                         break;
124                 default:
125                         printf("unknown");
126                         break;
127                 }
128                 printf(" speed\n");
129         }
130
131         return (0);
132 }