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