2 * acpi_thermal.c - ACPI Thermal Zone Driver ($Revision: 41 $)
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 * This driver fully implements the ACPI thermal policy as described in the
26 * ACPI 2.0 Specification.
28 * TBD: 1. Implement passive cooling hysteresis.
29 * 2. Enhance passive cooling (CPU) states/limit interface to support
30 * concepts of 'multiple limiters', upper/lower limits, etc.
34 #include <linux/kernel.h>
35 #include <linux/module.h>
36 #include <linux/dmi.h>
37 #include <linux/init.h>
38 #include <linux/slab.h>
39 #include <linux/types.h>
40 #include <linux/jiffies.h>
41 #include <linux/kmod.h>
42 #include <linux/reboot.h>
43 #include <linux/device.h>
44 #include <asm/uaccess.h>
45 #include <linux/thermal.h>
46 #include <acpi/acpi_bus.h>
47 #include <acpi/acpi_drivers.h>
49 #define PREFIX "ACPI: "
51 #define ACPI_THERMAL_CLASS "thermal_zone"
52 #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
53 #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80
54 #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81
55 #define ACPI_THERMAL_NOTIFY_DEVICES 0x82
56 #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0
57 #define ACPI_THERMAL_NOTIFY_HOT 0xF1
58 #define ACPI_THERMAL_MODE_ACTIVE 0x00
60 #define ACPI_THERMAL_MAX_ACTIVE 10
61 #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
63 #define _COMPONENT ACPI_THERMAL_COMPONENT
64 ACPI_MODULE_NAME("thermal");
66 MODULE_AUTHOR("Paul Diefenbaugh");
67 MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
68 MODULE_LICENSE("GPL");
71 module_param(act, int, 0644);
72 MODULE_PARM_DESC(act, "Disable or override all lowest active trip points.");
75 module_param(crt, int, 0644);
76 MODULE_PARM_DESC(crt, "Disable or lower all critical trip points.");
79 module_param(tzp, int, 0444);
80 MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.");
83 module_param(nocrt, int, 0);
84 MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points.");
87 module_param(off, int, 0);
88 MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.");
91 module_param(psv, int, 0644);
92 MODULE_PARM_DESC(psv, "Disable or override all passive trip points.");
94 static int acpi_thermal_add(struct acpi_device *device);
95 static int acpi_thermal_remove(struct acpi_device *device);
96 static void acpi_thermal_notify(struct acpi_device *device, u32 event);
98 static const struct acpi_device_id thermal_device_ids[] = {
99 {ACPI_THERMAL_HID, 0},
102 MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
104 #ifdef CONFIG_PM_SLEEP
105 static int acpi_thermal_resume(struct device *dev);
107 static SIMPLE_DEV_PM_OPS(acpi_thermal_pm, NULL, acpi_thermal_resume);
109 static struct acpi_driver acpi_thermal_driver = {
111 .class = ACPI_THERMAL_CLASS,
112 .ids = thermal_device_ids,
114 .add = acpi_thermal_add,
115 .remove = acpi_thermal_remove,
116 .notify = acpi_thermal_notify,
118 .drv.pm = &acpi_thermal_pm,
121 struct acpi_thermal_state {
130 struct acpi_thermal_state_flags {
136 struct acpi_thermal_critical {
137 struct acpi_thermal_state_flags flags;
138 unsigned long temperature;
141 struct acpi_thermal_hot {
142 struct acpi_thermal_state_flags flags;
143 unsigned long temperature;
146 struct acpi_thermal_passive {
147 struct acpi_thermal_state_flags flags;
148 unsigned long temperature;
152 struct acpi_handle_list devices;
155 struct acpi_thermal_active {
156 struct acpi_thermal_state_flags flags;
157 unsigned long temperature;
158 struct acpi_handle_list devices;
161 struct acpi_thermal_trips {
162 struct acpi_thermal_critical critical;
163 struct acpi_thermal_hot hot;
164 struct acpi_thermal_passive passive;
165 struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
168 struct acpi_thermal_flags {
169 u8 cooling_mode:1; /* _SCP */
170 u8 devices:1; /* _TZD */
174 struct acpi_thermal {
175 struct acpi_device * device;
177 unsigned long temperature;
178 unsigned long last_temperature;
179 unsigned long polling_frequency;
181 struct acpi_thermal_flags flags;
182 struct acpi_thermal_state state;
183 struct acpi_thermal_trips trips;
184 struct acpi_handle_list devices;
185 struct thermal_zone_device *thermal_zone;
190 /* --------------------------------------------------------------------------
191 Thermal Zone Management
192 -------------------------------------------------------------------------- */
194 static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
196 acpi_status status = AE_OK;
197 unsigned long long tmp;
202 tz->last_temperature = tz->temperature;
204 status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp);
205 if (ACPI_FAILURE(status))
208 tz->temperature = tmp;
209 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
215 static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
217 acpi_status status = AE_OK;
218 unsigned long long tmp;
223 status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp);
224 if (ACPI_FAILURE(status))
227 tz->polling_frequency = tmp;
228 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
229 tz->polling_frequency));
234 static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
236 acpi_status status = AE_OK;
237 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
238 struct acpi_object_list arg_list = { 1, &arg0 };
239 acpi_handle handle = NULL;
245 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
246 if (ACPI_FAILURE(status)) {
247 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
251 arg0.integer.value = mode;
253 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
254 if (ACPI_FAILURE(status))
260 #define ACPI_TRIPS_CRITICAL 0x01
261 #define ACPI_TRIPS_HOT 0x02
262 #define ACPI_TRIPS_PASSIVE 0x04
263 #define ACPI_TRIPS_ACTIVE 0x08
264 #define ACPI_TRIPS_DEVICES 0x10
266 #define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE)
267 #define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES
269 #define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \
270 ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \
274 * This exception is thrown out in two cases:
275 * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
276 * when re-evaluating the AML code.
277 * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change.
278 * We need to re-bind the cooling devices of a thermal zone when this occurs.
280 #define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \
282 if (flags != ACPI_TRIPS_INIT) \
283 ACPI_EXCEPTION((AE_INFO, AE_ERROR, \
284 "ACPI thermal trip point %s changed\n" \
285 "Please send acpidump to linux-acpi@vger.kernel.org", str)); \
288 static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
290 acpi_status status = AE_OK;
291 unsigned long long tmp;
292 struct acpi_handle_list devices;
296 /* Critical Shutdown */
297 if (flag & ACPI_TRIPS_CRITICAL) {
298 status = acpi_evaluate_integer(tz->device->handle,
300 tz->trips.critical.temperature = tmp;
302 * Treat freezing temperatures as invalid as well; some
303 * BIOSes return really low values and cause reboots at startup.
304 * Below zero (Celsius) values clearly aren't right for sure..
305 * ... so lets discard those as invalid.
307 if (ACPI_FAILURE(status)) {
308 tz->trips.critical.flags.valid = 0;
309 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
310 "No critical threshold\n"));
311 } else if (tmp <= 2732) {
312 printk(KERN_WARNING FW_BUG "Invalid critical threshold "
314 tz->trips.critical.flags.valid = 0;
316 tz->trips.critical.flags.valid = 1;
317 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
318 "Found critical threshold [%lu]\n",
319 tz->trips.critical.temperature));
321 if (tz->trips.critical.flags.valid == 1) {
323 tz->trips.critical.flags.valid = 0;
324 } else if (crt > 0) {
325 unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
327 * Allow override critical threshold
329 if (crt_k > tz->trips.critical.temperature)
330 printk(KERN_WARNING PREFIX
331 "Critical threshold %d C\n", crt);
332 tz->trips.critical.temperature = crt_k;
337 /* Critical Sleep (optional) */
338 if (flag & ACPI_TRIPS_HOT) {
339 status = acpi_evaluate_integer(tz->device->handle,
341 if (ACPI_FAILURE(status)) {
342 tz->trips.hot.flags.valid = 0;
343 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
344 "No hot threshold\n"));
346 tz->trips.hot.temperature = tmp;
347 tz->trips.hot.flags.valid = 1;
348 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
349 "Found hot threshold [%lu]\n",
350 tz->trips.critical.temperature));
354 /* Passive (optional) */
355 if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) ||
356 (flag == ACPI_TRIPS_INIT)) {
357 valid = tz->trips.passive.flags.valid;
360 } else if (psv > 0) {
361 tmp = CELSIUS_TO_KELVIN(psv);
364 status = acpi_evaluate_integer(tz->device->handle,
368 if (ACPI_FAILURE(status))
369 tz->trips.passive.flags.valid = 0;
371 tz->trips.passive.temperature = tmp;
372 tz->trips.passive.flags.valid = 1;
373 if (flag == ACPI_TRIPS_INIT) {
374 status = acpi_evaluate_integer(
375 tz->device->handle, "_TC1",
377 if (ACPI_FAILURE(status))
378 tz->trips.passive.flags.valid = 0;
380 tz->trips.passive.tc1 = tmp;
381 status = acpi_evaluate_integer(
382 tz->device->handle, "_TC2",
384 if (ACPI_FAILURE(status))
385 tz->trips.passive.flags.valid = 0;
387 tz->trips.passive.tc2 = tmp;
388 status = acpi_evaluate_integer(
389 tz->device->handle, "_TSP",
391 if (ACPI_FAILURE(status))
392 tz->trips.passive.flags.valid = 0;
394 tz->trips.passive.tsp = tmp;
398 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) {
399 memset(&devices, 0, sizeof(struct acpi_handle_list));
400 status = acpi_evaluate_reference(tz->device->handle, "_PSL",
402 if (ACPI_FAILURE(status)) {
403 printk(KERN_WARNING PREFIX
404 "Invalid passive threshold\n");
405 tz->trips.passive.flags.valid = 0;
408 tz->trips.passive.flags.valid = 1;
410 if (memcmp(&tz->trips.passive.devices, &devices,
411 sizeof(struct acpi_handle_list))) {
412 memcpy(&tz->trips.passive.devices, &devices,
413 sizeof(struct acpi_handle_list));
414 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
417 if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) {
418 if (valid != tz->trips.passive.flags.valid)
419 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
422 /* Active (optional) */
423 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
424 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
425 valid = tz->trips.active[i].flags.valid;
428 break; /* disable all active trip points */
430 if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) &&
431 tz->trips.active[i].flags.valid)) {
432 status = acpi_evaluate_integer(tz->device->handle,
434 if (ACPI_FAILURE(status)) {
435 tz->trips.active[i].flags.valid = 0;
441 tz->trips.active[0].temperature =
442 CELSIUS_TO_KELVIN(act);
445 * Don't allow override higher than
446 * the next higher trip point
448 tz->trips.active[i - 1].temperature =
449 (tz->trips.active[i - 2].temperature <
450 CELSIUS_TO_KELVIN(act) ?
451 tz->trips.active[i - 2].temperature :
452 CELSIUS_TO_KELVIN(act));
455 tz->trips.active[i].temperature = tmp;
456 tz->trips.active[i].flags.valid = 1;
461 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) {
462 memset(&devices, 0, sizeof(struct acpi_handle_list));
463 status = acpi_evaluate_reference(tz->device->handle,
464 name, NULL, &devices);
465 if (ACPI_FAILURE(status)) {
466 printk(KERN_WARNING PREFIX
467 "Invalid active%d threshold\n", i);
468 tz->trips.active[i].flags.valid = 0;
471 tz->trips.active[i].flags.valid = 1;
473 if (memcmp(&tz->trips.active[i].devices, &devices,
474 sizeof(struct acpi_handle_list))) {
475 memcpy(&tz->trips.active[i].devices, &devices,
476 sizeof(struct acpi_handle_list));
477 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
480 if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES))
481 if (valid != tz->trips.active[i].flags.valid)
482 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
484 if (!tz->trips.active[i].flags.valid)
488 if (flag & ACPI_TRIPS_DEVICES) {
489 memset(&devices, 0, sizeof(struct acpi_handle_list));
490 status = acpi_evaluate_reference(tz->device->handle, "_TZD",
492 if (memcmp(&tz->devices, &devices,
493 sizeof(struct acpi_handle_list))) {
494 memcpy(&tz->devices, &devices,
495 sizeof(struct acpi_handle_list));
496 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
503 static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
505 int i, valid, ret = acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
510 valid = tz->trips.critical.flags.valid |
511 tz->trips.hot.flags.valid |
512 tz->trips.passive.flags.valid;
514 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
515 valid |= tz->trips.active[i].flags.valid;
518 printk(KERN_WARNING FW_BUG "No valid trip found\n");
524 static void acpi_thermal_check(void *data)
526 struct acpi_thermal *tz = data;
528 if (!tz->tz_enabled) {
529 pr_warn("thermal zone is disabled \n");
532 thermal_zone_device_update(tz->thermal_zone);
535 /* sys I/F for generic thermal sysfs support */
536 #define KELVIN_TO_MILLICELSIUS(t, off) (((t) - (off)) * 100)
538 static int thermal_get_temp(struct thermal_zone_device *thermal,
541 struct acpi_thermal *tz = thermal->devdata;
547 result = acpi_thermal_get_temperature(tz);
551 *temp = KELVIN_TO_MILLICELSIUS(tz->temperature, tz->kelvin_offset);
555 static int thermal_get_mode(struct thermal_zone_device *thermal,
556 enum thermal_device_mode *mode)
558 struct acpi_thermal *tz = thermal->devdata;
563 *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
564 THERMAL_DEVICE_DISABLED;
569 static int thermal_set_mode(struct thermal_zone_device *thermal,
570 enum thermal_device_mode mode)
572 struct acpi_thermal *tz = thermal->devdata;
579 * enable/disable thermal management from ACPI thermal driver
581 if (mode == THERMAL_DEVICE_ENABLED)
583 else if (mode == THERMAL_DEVICE_DISABLED)
588 if (enable != tz->tz_enabled) {
589 tz->tz_enabled = enable;
590 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
591 "%s kernel ACPI thermal control\n",
592 tz->tz_enabled ? "Enable" : "Disable"));
593 acpi_thermal_check(tz);
598 static int thermal_get_trip_type(struct thermal_zone_device *thermal,
599 int trip, enum thermal_trip_type *type)
601 struct acpi_thermal *tz = thermal->devdata;
607 if (tz->trips.critical.flags.valid) {
609 *type = THERMAL_TRIP_CRITICAL;
615 if (tz->trips.hot.flags.valid) {
617 *type = THERMAL_TRIP_HOT;
623 if (tz->trips.passive.flags.valid) {
625 *type = THERMAL_TRIP_PASSIVE;
631 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
632 tz->trips.active[i].flags.valid; i++) {
634 *type = THERMAL_TRIP_ACTIVE;
643 static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
644 int trip, unsigned long *temp)
646 struct acpi_thermal *tz = thermal->devdata;
652 if (tz->trips.critical.flags.valid) {
654 *temp = KELVIN_TO_MILLICELSIUS(
655 tz->trips.critical.temperature,
662 if (tz->trips.hot.flags.valid) {
664 *temp = KELVIN_TO_MILLICELSIUS(
665 tz->trips.hot.temperature,
672 if (tz->trips.passive.flags.valid) {
674 *temp = KELVIN_TO_MILLICELSIUS(
675 tz->trips.passive.temperature,
682 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
683 tz->trips.active[i].flags.valid; i++) {
685 *temp = KELVIN_TO_MILLICELSIUS(
686 tz->trips.active[i].temperature,
696 static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
697 unsigned long *temperature) {
698 struct acpi_thermal *tz = thermal->devdata;
700 if (tz->trips.critical.flags.valid) {
701 *temperature = KELVIN_TO_MILLICELSIUS(
702 tz->trips.critical.temperature,
709 static int thermal_get_trend(struct thermal_zone_device *thermal,
710 int trip, enum thermal_trend *trend)
712 struct acpi_thermal *tz = thermal->devdata;
713 enum thermal_trip_type type;
716 if (thermal_get_trip_type(thermal, trip, &type))
719 if (type == THERMAL_TRIP_ACTIVE) {
720 unsigned long trip_temp;
721 unsigned long temp = KELVIN_TO_MILLICELSIUS(tz->temperature,
723 if (thermal_get_trip_temp(thermal, trip, &trip_temp))
726 if (temp > trip_temp) {
727 *trend = THERMAL_TREND_RAISING;
730 /* Fall back on default trend */
736 * tz->temperature has already been updated by generic thermal layer,
737 * before this callback being invoked
739 i = (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature))
740 + (tz->trips.passive.tc2
741 * (tz->temperature - tz->trips.passive.temperature));
744 *trend = THERMAL_TREND_RAISING;
746 *trend = THERMAL_TREND_DROPPING;
748 *trend = THERMAL_TREND_STABLE;
753 static int thermal_notify(struct thermal_zone_device *thermal, int trip,
754 enum thermal_trip_type trip_type)
757 struct acpi_thermal *tz = thermal->devdata;
759 if (trip_type == THERMAL_TRIP_CRITICAL)
760 type = ACPI_THERMAL_NOTIFY_CRITICAL;
761 else if (trip_type == THERMAL_TRIP_HOT)
762 type = ACPI_THERMAL_NOTIFY_HOT;
766 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
767 dev_name(&tz->device->dev), type, 1);
769 if (trip_type == THERMAL_TRIP_CRITICAL && nocrt)
775 static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
776 struct thermal_cooling_device *cdev,
779 struct acpi_device *device = cdev->devdata;
780 struct acpi_thermal *tz = thermal->devdata;
781 struct acpi_device *dev;
789 if (tz->trips.critical.flags.valid)
792 if (tz->trips.hot.flags.valid)
795 if (tz->trips.passive.flags.valid) {
797 for (i = 0; i < tz->trips.passive.devices.count;
799 handle = tz->trips.passive.devices.handles[i];
800 status = acpi_bus_get_device(handle, &dev);
801 if (ACPI_FAILURE(status) || dev != device)
805 thermal_zone_bind_cooling_device
806 (thermal, trip, cdev,
807 THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
810 thermal_zone_unbind_cooling_device
811 (thermal, trip, cdev);
817 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
818 if (!tz->trips.active[i].flags.valid)
822 j < tz->trips.active[i].devices.count;
824 handle = tz->trips.active[i].devices.handles[j];
825 status = acpi_bus_get_device(handle, &dev);
826 if (ACPI_FAILURE(status) || dev != device)
829 result = thermal_zone_bind_cooling_device
830 (thermal, trip, cdev,
831 THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
833 result = thermal_zone_unbind_cooling_device
834 (thermal, trip, cdev);
840 for (i = 0; i < tz->devices.count; i++) {
841 handle = tz->devices.handles[i];
842 status = acpi_bus_get_device(handle, &dev);
843 if (ACPI_SUCCESS(status) && (dev == device)) {
845 result = thermal_zone_bind_cooling_device
850 result = thermal_zone_unbind_cooling_device
862 acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
863 struct thermal_cooling_device *cdev)
865 return acpi_thermal_cooling_device_cb(thermal, cdev, true);
869 acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
870 struct thermal_cooling_device *cdev)
872 return acpi_thermal_cooling_device_cb(thermal, cdev, false);
875 static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
876 .bind = acpi_thermal_bind_cooling_device,
877 .unbind = acpi_thermal_unbind_cooling_device,
878 .get_temp = thermal_get_temp,
879 .get_mode = thermal_get_mode,
880 .set_mode = thermal_set_mode,
881 .get_trip_type = thermal_get_trip_type,
882 .get_trip_temp = thermal_get_trip_temp,
883 .get_crit_temp = thermal_get_crit_temp,
884 .get_trend = thermal_get_trend,
885 .notify = thermal_notify,
888 static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
895 if (tz->trips.critical.flags.valid)
898 if (tz->trips.hot.flags.valid)
901 if (tz->trips.passive.flags.valid)
904 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
905 tz->trips.active[i].flags.valid; i++, trips++);
907 if (tz->trips.passive.flags.valid)
909 thermal_zone_device_register("acpitz", trips, 0, tz,
910 &acpi_thermal_zone_ops, NULL,
911 tz->trips.passive.tsp*100,
912 tz->polling_frequency*100);
915 thermal_zone_device_register("acpitz", trips, 0, tz,
916 &acpi_thermal_zone_ops, NULL,
917 0, tz->polling_frequency*100);
918 if (IS_ERR(tz->thermal_zone))
921 result = sysfs_create_link(&tz->device->dev.kobj,
922 &tz->thermal_zone->device.kobj, "thermal_zone");
926 result = sysfs_create_link(&tz->thermal_zone->device.kobj,
927 &tz->device->dev.kobj, "device");
931 status = acpi_attach_data(tz->device->handle,
932 acpi_bus_private_data_handler,
934 if (ACPI_FAILURE(status)) {
935 printk(KERN_ERR PREFIX
936 "Error attaching device data\n");
942 dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
943 tz->thermal_zone->id);
947 static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
949 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
950 sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
951 thermal_zone_device_unregister(tz->thermal_zone);
952 tz->thermal_zone = NULL;
953 acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler);
957 /* --------------------------------------------------------------------------
959 -------------------------------------------------------------------------- */
961 static void acpi_thermal_notify(struct acpi_device *device, u32 event)
963 struct acpi_thermal *tz = acpi_driver_data(device);
970 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
971 acpi_thermal_check(tz);
973 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
974 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS);
975 acpi_thermal_check(tz);
976 acpi_bus_generate_netlink_event(device->pnp.device_class,
977 dev_name(&device->dev), event, 0);
979 case ACPI_THERMAL_NOTIFY_DEVICES:
980 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES);
981 acpi_thermal_check(tz);
982 acpi_bus_generate_netlink_event(device->pnp.device_class,
983 dev_name(&device->dev), event, 0);
986 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
987 "Unsupported event [0x%x]\n", event));
993 * On some platforms, the AML code has dependency about
994 * the evaluating order of _TMP and _CRT/_HOT/_PSV/_ACx.
995 * 1. On HP Pavilion G4-1016tx, _TMP must be invoked after
996 * /_CRT/_HOT/_PSV/_ACx, or else system will be power off.
997 * 2. On HP Compaq 6715b/6715s, the return value of _PSV is 0
998 * if _TMP has never been evaluated.
1000 * As this dependency is totally transparent to OS, evaluate
1001 * all of them once, in the order of _CRT/_HOT/_PSV/_ACx,
1002 * _TMP, before they are actually used.
1004 static void acpi_thermal_aml_dependency_fix(struct acpi_thermal *tz)
1006 acpi_handle handle = tz->device->handle;
1007 unsigned long long value;
1010 acpi_evaluate_integer(handle, "_CRT", NULL, &value);
1011 acpi_evaluate_integer(handle, "_HOT", NULL, &value);
1012 acpi_evaluate_integer(handle, "_PSV", NULL, &value);
1013 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1014 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
1017 status = acpi_evaluate_integer(handle, name, NULL, &value);
1018 if (status == AE_NOT_FOUND)
1021 acpi_evaluate_integer(handle, "_TMP", NULL, &value);
1024 static int acpi_thermal_get_info(struct acpi_thermal *tz)
1032 acpi_thermal_aml_dependency_fix(tz);
1034 /* Get trip points [_CRT, _PSV, etc.] (required) */
1035 result = acpi_thermal_get_trip_points(tz);
1039 /* Get temperature [_TMP] (required) */
1040 result = acpi_thermal_get_temperature(tz);
1044 /* Set the cooling mode [_SCP] to active cooling (default) */
1045 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
1047 tz->flags.cooling_mode = 1;
1049 /* Get default polling frequency [_TZP] (optional) */
1051 tz->polling_frequency = tzp;
1053 acpi_thermal_get_polling_frequency(tz);
1059 * The exact offset between Kelvin and degree Celsius is 273.15. However ACPI
1060 * handles temperature values with a single decimal place. As a consequence,
1061 * some implementations use an offset of 273.1 and others use an offset of
1062 * 273.2. Try to find out which one is being used, to present the most
1063 * accurate and visually appealing number.
1065 * The heuristic below should work for all ACPI thermal zones which have a
1066 * critical trip point with a value being a multiple of 0.5 degree Celsius.
1068 static void acpi_thermal_guess_offset(struct acpi_thermal *tz)
1070 if (tz->trips.critical.flags.valid &&
1071 (tz->trips.critical.temperature % 5) == 1)
1072 tz->kelvin_offset = 2731;
1074 tz->kelvin_offset = 2732;
1077 static int acpi_thermal_add(struct acpi_device *device)
1080 struct acpi_thermal *tz = NULL;
1086 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1090 tz->device = device;
1091 strcpy(tz->name, device->pnp.bus_id);
1092 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1093 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
1094 device->driver_data = tz;
1096 result = acpi_thermal_get_info(tz);
1100 acpi_thermal_guess_offset(tz);
1102 result = acpi_thermal_register_thermal_zone(tz);
1106 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
1107 acpi_device_name(device), acpi_device_bid(device),
1108 KELVIN_TO_CELSIUS(tz->temperature));
1117 static int acpi_thermal_remove(struct acpi_device *device)
1119 struct acpi_thermal *tz = NULL;
1121 if (!device || !acpi_driver_data(device))
1124 tz = acpi_driver_data(device);
1126 acpi_thermal_unregister_thermal_zone(tz);
1131 #ifdef CONFIG_PM_SLEEP
1132 static int acpi_thermal_resume(struct device *dev)
1134 struct acpi_thermal *tz;
1135 int i, j, power_state, result;
1140 tz = acpi_driver_data(to_acpi_device(dev));
1144 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1145 if (!(&tz->trips.active[i]))
1147 if (!tz->trips.active[i].flags.valid)
1149 tz->trips.active[i].flags.enabled = 1;
1150 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1151 result = acpi_bus_update_power(
1152 tz->trips.active[i].devices.handles[j],
1154 if (result || (power_state != ACPI_STATE_D0)) {
1155 tz->trips.active[i].flags.enabled = 0;
1159 tz->state.active |= tz->trips.active[i].flags.enabled;
1162 acpi_thermal_check(tz);
1168 static int thermal_act(const struct dmi_system_id *d) {
1171 printk(KERN_NOTICE "ACPI: %s detected: "
1172 "disabling all active thermal trip points\n", d->ident);
1177 static int thermal_nocrt(const struct dmi_system_id *d) {
1179 printk(KERN_NOTICE "ACPI: %s detected: "
1180 "disabling all critical thermal trip point actions.\n", d->ident);
1184 static int thermal_tzp(const struct dmi_system_id *d) {
1187 printk(KERN_NOTICE "ACPI: %s detected: "
1188 "enabling thermal zone polling\n", d->ident);
1189 tzp = 300; /* 300 dS = 30 Seconds */
1193 static int thermal_psv(const struct dmi_system_id *d) {
1196 printk(KERN_NOTICE "ACPI: %s detected: "
1197 "disabling all passive thermal trip points\n", d->ident);
1203 static struct dmi_system_id thermal_dmi_table[] __initdata = {
1205 * Award BIOS on this AOpen makes thermal control almost worthless.
1206 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1209 .callback = thermal_act,
1210 .ident = "AOpen i915GMm-HFS",
1212 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1213 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1217 .callback = thermal_psv,
1218 .ident = "AOpen i915GMm-HFS",
1220 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1221 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1225 .callback = thermal_tzp,
1226 .ident = "AOpen i915GMm-HFS",
1228 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1229 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1233 .callback = thermal_nocrt,
1234 .ident = "Gigabyte GA-7ZX",
1236 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
1237 DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
1243 static int __init acpi_thermal_init(void)
1247 dmi_check_system(thermal_dmi_table);
1250 printk(KERN_NOTICE "ACPI: thermal control disabled\n");
1254 result = acpi_bus_register_driver(&acpi_thermal_driver);
1261 static void __exit acpi_thermal_exit(void)
1264 acpi_bus_unregister_driver(&acpi_thermal_driver);
1269 module_init(acpi_thermal_init);
1270 module_exit(acpi_thermal_exit);