Deleted Added
sdiff udiff text old ( 78662 ) new ( 78915 )
full compact
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.

--- 8 unchanged lines hidden (view full) ---

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: head/sys/dev/acpica/acpi_thermal.c 78662 2001-06-23 10:38:25Z iwasaki $
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/*
40 * Hooks for the ACPI CA debugging infrastructure
41 */
42#define _COMPONENT ACPI_THERMAL_ZONE
43MODULE_NAME("THERMAL")
44
45#define TZ_ZEROC 2732
46#define TZ_KELVTOC(x) (((x) - TZ_ZEROC) / 10), (((x) - TZ_ZEROC) % 10)
47
48struct acpi_tz_softc {
49 device_t tz_dev;
50 ACPI_HANDLE tz_handle;
51 int tz_tmp;
52};
53
54static int acpi_tz_probe(device_t dev);
55static int acpi_tz_attach(device_t dev);
56static void acpi_tz_check_tripping_point(void *context);
57static void acpi_tz_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context);
58
59static device_method_t acpi_tz_methods[] = {
60 /* Device interface */
61 DEVMETHOD(device_probe, acpi_tz_probe),
62 DEVMETHOD(device_attach, acpi_tz_attach),
63
64 {0, 0}
65};
66
67static driver_t acpi_tz_driver = {
68 "acpi_tz",
69 acpi_tz_methods,
70 sizeof(struct acpi_tz_softc),
71};
72
73devclass_t acpi_tz_devclass;
74DRIVER_MODULE(acpi_tz, acpi, acpi_tz_driver, acpi_tz_devclass, 0, 0);
75
76static int
77acpi_tz_probe(device_t dev)
78{
79
80 FUNCTION_TRACE(__func__);
81
82 if ((acpi_get_type(dev) == ACPI_TYPE_THERMAL) &&
83 !acpi_disabled("thermal")) {
84 device_set_desc(dev, "thermal zone");
85 return_VALUE(0);
86 }
87 return_VALUE(ENXIO);
88}
89
90static int
91acpi_tz_attach(device_t dev)
92{
93 struct acpi_tz_softc *sc;
94 struct acpi_softc *acpi_sc;
95
96 FUNCTION_TRACE(__func__);
97
98 sc = device_get_softc(dev);
99 sc->tz_dev = dev;
100 sc->tz_handle = acpi_get_handle(dev);
101
102 AcpiInstallNotifyHandler(sc->tz_handle, ACPI_DEVICE_NOTIFY,
103 acpi_tz_notify_handler, dev);
104
105 if (device_get_unit(dev) == 0) {
106 acpi_sc = acpi_device_get_parent_softc(dev);
107 SYSCTL_ADD_UINT(&acpi_sc->acpi_sysctl_ctx,
108 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
109 OID_AUTO, "temperature", CTLFLAG_RD,
110 &sc->tz_tmp, 0, "");
111 }
112
113 /*
114 * Don't bother evaluating/printing the temperature at this point;
115 * on many systems it'll be bogus until the EC is running.
116 */
117 return_VALUE(0);
118}
119
120static void
121acpi_tz_check_tripping_point(void *context)
122{
123 struct acpi_tz_softc *sc;
124 device_t dev = context;
125 ACPI_STATUS status;
126 int tp;
127
128 FUNCTION_TRACE(__func__);
129
130 sc = device_get_softc(dev);
131 if ((status = acpi_EvaluateInteger(sc->tz_handle, "_TMP", &tp)) != AE_OK) {
132 device_printf(dev, "can't evaluate _TMP method - %s\n", acpi_strerror(status));
133 return_VOID;
134 }
135
136 sc->tz_tmp = (tp - TZ_ZEROC) / 10;
137 if (bootverbose) {
138 device_printf(dev, "%dC\n", sc->tz_tmp);
139 }
140 return_VOID;
141}
142
143#define ACPI_TZ_STATUS_CHANGE 0x80
144#define ACPI_TZ_TRIPPOINT_CHANGE 0x81
145static void
146acpi_tz_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context)
147{
148 FUNCTION_TRACE(__func__);
149
150 switch(notify){
151 case ACPI_TZ_STATUS_CHANGE:
152 case ACPI_TZ_TRIPPOINT_CHANGE:
153 /*Check trip point*/
154 AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_tz_check_tripping_point, context);
155 break;
156 }
157 return_VOID;
158}
159