xref: /freebsd/sys/dev/acpica/acpi_thermal.c (revision 77a0943ded95b9e6438f7db70c4a28e4d93946d4)
1 /*-
2  * Copyright (c) 2000 Michael Smith
3  * Copyright (c) 2000 BSDi
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
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  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  *	$FreeBSD$
28  */
29 
30 #include "opt_acpi.h"
31 #include <sys/param.h>
32 #include <sys/kernel.h>
33 #include <sys/bus.h>
34 
35 #include "acpi.h"
36 
37 #include <dev/acpica/acpivar.h>
38 
39 #define TZ_KELVTOC(x)	(((x) - 2732) / 10), (((x) - 2732) % 10)
40 
41 struct acpi_tz_softc {
42     device_t	tz_dev;
43     ACPI_HANDLE	tz_handle;
44 };
45 
46 static int	acpi_tz_probe(device_t dev);
47 static int	acpi_tz_attach(device_t dev);
48 
49 static device_method_t acpi_tz_methods[] = {
50     /* Device interface */
51     DEVMETHOD(device_probe,	acpi_tz_probe),
52     DEVMETHOD(device_attach,	acpi_tz_attach),
53 
54     {0, 0}
55 };
56 
57 static driver_t acpi_tz_driver = {
58     "acpi_tz",
59     acpi_tz_methods,
60     sizeof(struct acpi_tz_softc),
61 };
62 
63 devclass_t acpi_tz_devclass;
64 DRIVER_MODULE(acpi_tz, acpi, acpi_tz_driver, acpi_tz_devclass, 0, 0);
65 
66 static int
67 acpi_tz_probe(device_t dev)
68 {
69     if (acpi_get_type(dev) == ACPI_TYPE_THERMAL) {
70 	device_set_desc(dev, "thermal zone");
71 	return(0);
72     }
73     return(ENXIO);
74 }
75 
76 static int
77 acpi_tz_attach(device_t dev)
78 {
79     struct acpi_tz_softc	*sc;
80     UINT32			param[4];
81     ACPI_BUFFER			buf;
82     ACPI_STATUS			status;
83 
84     sc = device_get_softc(dev);
85     sc->tz_dev = dev;
86     sc->tz_handle = acpi_get_handle(dev);
87 
88     buf.Pointer = &param[0];
89     buf.Length = sizeof(param);
90     if ((status = AcpiEvaluateObject(sc->tz_handle, "_TMP", NULL, &buf)) != AE_OK) {
91 	device_printf(sc->tz_dev, "can't fetch temperature - %s\n", acpi_strerror(status));
92 	return(ENXIO);
93     }
94     if (param[0] != ACPI_TYPE_NUMBER) {
95 	device_printf(sc->tz_dev, "%s._TMP does not evaluate to ACPI_TYPE_NUMBER\n",
96 		      acpi_name(sc->tz_handle));
97 	return(ENXIO);
98     }
99     device_printf(sc->tz_dev, "current temperature %d.%dC\n", TZ_KELVTOC(param[1]));
100 
101     return(0);
102 }
103