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 <linux/thermal.h>
45 #include <linux/acpi.h>
46 #include <asm/uaccess.h>
48 #define PREFIX "ACPI: "
50 #define ACPI_THERMAL_CLASS "thermal_zone"
51 #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
52 #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80
53 #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81
54 #define ACPI_THERMAL_NOTIFY_DEVICES 0x82
55 #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0
56 #define ACPI_THERMAL_NOTIFY_HOT 0xF1
57 #define ACPI_THERMAL_MODE_ACTIVE 0x00
59 #define ACPI_THERMAL_MAX_ACTIVE 10
60 #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
62 #define _COMPONENT ACPI_THERMAL_COMPONENT
63 ACPI_MODULE_NAME("thermal");
65 MODULE_AUTHOR("Paul Diefenbaugh");
66 MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
67 MODULE_LICENSE("GPL");
70 module_param(act, int, 0644);
71 MODULE_PARM_DESC(act, "Disable or override all lowest active trip points.");
74 module_param(crt, int, 0644);
75 MODULE_PARM_DESC(crt, "Disable or lower all critical trip points.");
78 module_param(tzp, int, 0444);
79 MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.");
82 module_param(nocrt, int, 0);
83 MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points.");
86 module_param(off, int, 0);
87 MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.");
90 module_param(psv, int, 0644);
91 MODULE_PARM_DESC(psv, "Disable or override all passive trip points.");
93 static int acpi_thermal_add(struct acpi_device *device);
94 static int acpi_thermal_remove(struct acpi_device *device);
95 static void acpi_thermal_notify(struct acpi_device *device, u32 event);
97 static const struct acpi_device_id thermal_device_ids[] = {
98 {ACPI_THERMAL_HID, 0},
101 MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
103 #ifdef CONFIG_PM_SLEEP
104 static int acpi_thermal_resume(struct device *dev);
106 #define acpi_thermal_resume NULL
108 static SIMPLE_DEV_PM_OPS(acpi_thermal_pm, NULL, acpi_thermal_resume);
110 static struct acpi_driver acpi_thermal_driver = {
112 .class = ACPI_THERMAL_CLASS,
113 .ids = thermal_device_ids,
115 .add = acpi_thermal_add,
116 .remove = acpi_thermal_remove,
117 .notify = acpi_thermal_notify,
119 .drv.pm = &acpi_thermal_pm,
122 struct acpi_thermal_state {
131 struct acpi_thermal_state_flags {
137 struct acpi_thermal_critical {
138 struct acpi_thermal_state_flags flags;
139 unsigned long temperature;
142 struct acpi_thermal_hot {
143 struct acpi_thermal_state_flags flags;
144 unsigned long temperature;
147 struct acpi_thermal_passive {
148 struct acpi_thermal_state_flags flags;
149 unsigned long temperature;
153 struct acpi_handle_list devices;
156 struct acpi_thermal_active {
157 struct acpi_thermal_state_flags flags;
158 unsigned long temperature;
159 struct acpi_handle_list devices;
162 struct acpi_thermal_trips {
163 struct acpi_thermal_critical critical;
164 struct acpi_thermal_hot hot;
165 struct acpi_thermal_passive passive;
166 struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
169 struct acpi_thermal_flags {
170 u8 cooling_mode:1; /* _SCP */
171 u8 devices:1; /* _TZD */
175 struct acpi_thermal {
176 struct acpi_device * device;
178 unsigned long temperature;
179 unsigned long last_temperature;
180 unsigned long polling_frequency;
182 struct acpi_thermal_flags flags;
183 struct acpi_thermal_state state;
184 struct acpi_thermal_trips trips;
185 struct acpi_handle_list devices;
186 struct thermal_zone_device *thermal_zone;
191 /* --------------------------------------------------------------------------
192 Thermal Zone Management
193 -------------------------------------------------------------------------- */
195 static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
197 acpi_status status = AE_OK;
198 unsigned long long tmp;
203 tz->last_temperature = tz->temperature;
205 status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp);
206 if (ACPI_FAILURE(status))
209 tz->temperature = tmp;
210 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
216 static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
218 acpi_status status = AE_OK;
219 unsigned long long tmp;
224 status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp);
225 if (ACPI_FAILURE(status))
228 tz->polling_frequency = tmp;
229 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
230 tz->polling_frequency));
235 static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
240 if (!acpi_has_method(tz->device->handle, "_SCP")) {
241 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
243 } else if (ACPI_FAILURE(acpi_execute_simple_method(tz->device->handle,
251 #define ACPI_TRIPS_CRITICAL 0x01
252 #define ACPI_TRIPS_HOT 0x02
253 #define ACPI_TRIPS_PASSIVE 0x04
254 #define ACPI_TRIPS_ACTIVE 0x08
255 #define ACPI_TRIPS_DEVICES 0x10
257 #define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE)
258 #define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES
260 #define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \
261 ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \
265 * This exception is thrown out in two cases:
266 * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
267 * when re-evaluating the AML code.
268 * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change.
269 * We need to re-bind the cooling devices of a thermal zone when this occurs.
271 #define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \
273 if (flags != ACPI_TRIPS_INIT) \
274 ACPI_EXCEPTION((AE_INFO, AE_ERROR, \
275 "ACPI thermal trip point %s changed\n" \
276 "Please send acpidump to linux-acpi@vger.kernel.org", str)); \
279 static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
281 acpi_status status = AE_OK;
282 unsigned long long tmp;
283 struct acpi_handle_list devices;
287 /* Critical Shutdown */
288 if (flag & ACPI_TRIPS_CRITICAL) {
289 status = acpi_evaluate_integer(tz->device->handle,
291 tz->trips.critical.temperature = tmp;
293 * Treat freezing temperatures as invalid as well; some
294 * BIOSes return really low values and cause reboots at startup.
295 * Below zero (Celsius) values clearly aren't right for sure..
296 * ... so lets discard those as invalid.
298 if (ACPI_FAILURE(status)) {
299 tz->trips.critical.flags.valid = 0;
300 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
301 "No critical threshold\n"));
302 } else if (tmp <= 2732) {
303 pr_warn(FW_BUG "Invalid critical threshold (%llu)\n",
305 tz->trips.critical.flags.valid = 0;
307 tz->trips.critical.flags.valid = 1;
308 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
309 "Found critical threshold [%lu]\n",
310 tz->trips.critical.temperature));
312 if (tz->trips.critical.flags.valid == 1) {
314 tz->trips.critical.flags.valid = 0;
315 } else if (crt > 0) {
316 unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
318 * Allow override critical threshold
320 if (crt_k > tz->trips.critical.temperature)
321 pr_warn(PREFIX "Critical threshold %d C\n",
323 tz->trips.critical.temperature = crt_k;
328 /* Critical Sleep (optional) */
329 if (flag & ACPI_TRIPS_HOT) {
330 status = acpi_evaluate_integer(tz->device->handle,
332 if (ACPI_FAILURE(status)) {
333 tz->trips.hot.flags.valid = 0;
334 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
335 "No hot threshold\n"));
337 tz->trips.hot.temperature = tmp;
338 tz->trips.hot.flags.valid = 1;
339 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
340 "Found hot threshold [%lu]\n",
341 tz->trips.critical.temperature));
345 /* Passive (optional) */
346 if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) ||
347 (flag == ACPI_TRIPS_INIT)) {
348 valid = tz->trips.passive.flags.valid;
351 } else if (psv > 0) {
352 tmp = CELSIUS_TO_KELVIN(psv);
355 status = acpi_evaluate_integer(tz->device->handle,
359 if (ACPI_FAILURE(status))
360 tz->trips.passive.flags.valid = 0;
362 tz->trips.passive.temperature = tmp;
363 tz->trips.passive.flags.valid = 1;
364 if (flag == ACPI_TRIPS_INIT) {
365 status = acpi_evaluate_integer(
366 tz->device->handle, "_TC1",
368 if (ACPI_FAILURE(status))
369 tz->trips.passive.flags.valid = 0;
371 tz->trips.passive.tc1 = tmp;
372 status = acpi_evaluate_integer(
373 tz->device->handle, "_TC2",
375 if (ACPI_FAILURE(status))
376 tz->trips.passive.flags.valid = 0;
378 tz->trips.passive.tc2 = tmp;
379 status = acpi_evaluate_integer(
380 tz->device->handle, "_TSP",
382 if (ACPI_FAILURE(status))
383 tz->trips.passive.flags.valid = 0;
385 tz->trips.passive.tsp = tmp;
389 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) {
390 memset(&devices, 0, sizeof(struct acpi_handle_list));
391 status = acpi_evaluate_reference(tz->device->handle, "_PSL",
393 if (ACPI_FAILURE(status)) {
394 pr_warn(PREFIX "Invalid passive threshold\n");
395 tz->trips.passive.flags.valid = 0;
398 tz->trips.passive.flags.valid = 1;
400 if (memcmp(&tz->trips.passive.devices, &devices,
401 sizeof(struct acpi_handle_list))) {
402 memcpy(&tz->trips.passive.devices, &devices,
403 sizeof(struct acpi_handle_list));
404 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
407 if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) {
408 if (valid != tz->trips.passive.flags.valid)
409 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
412 /* Active (optional) */
413 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
414 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
415 valid = tz->trips.active[i].flags.valid;
418 break; /* disable all active trip points */
420 if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) &&
421 tz->trips.active[i].flags.valid)) {
422 status = acpi_evaluate_integer(tz->device->handle,
424 if (ACPI_FAILURE(status)) {
425 tz->trips.active[i].flags.valid = 0;
431 tz->trips.active[0].temperature =
432 CELSIUS_TO_KELVIN(act);
435 * Don't allow override higher than
436 * the next higher trip point
438 tz->trips.active[i - 1].temperature =
439 (tz->trips.active[i - 2].temperature <
440 CELSIUS_TO_KELVIN(act) ?
441 tz->trips.active[i - 2].temperature :
442 CELSIUS_TO_KELVIN(act));
445 tz->trips.active[i].temperature = tmp;
446 tz->trips.active[i].flags.valid = 1;
451 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) {
452 memset(&devices, 0, sizeof(struct acpi_handle_list));
453 status = acpi_evaluate_reference(tz->device->handle,
454 name, NULL, &devices);
455 if (ACPI_FAILURE(status)) {
456 pr_warn(PREFIX "Invalid active%d threshold\n",
458 tz->trips.active[i].flags.valid = 0;
461 tz->trips.active[i].flags.valid = 1;
463 if (memcmp(&tz->trips.active[i].devices, &devices,
464 sizeof(struct acpi_handle_list))) {
465 memcpy(&tz->trips.active[i].devices, &devices,
466 sizeof(struct acpi_handle_list));
467 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
470 if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES))
471 if (valid != tz->trips.active[i].flags.valid)
472 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
474 if (!tz->trips.active[i].flags.valid)
478 if ((flag & ACPI_TRIPS_DEVICES)
479 && acpi_has_method(tz->device->handle, "_TZD")) {
480 memset(&devices, 0, sizeof(devices));
481 status = acpi_evaluate_reference(tz->device->handle, "_TZD",
483 if (ACPI_SUCCESS(status)
484 && memcmp(&tz->devices, &devices, sizeof(devices))) {
485 tz->devices = devices;
486 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
493 static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
495 int i, valid, ret = acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
500 valid = tz->trips.critical.flags.valid |
501 tz->trips.hot.flags.valid |
502 tz->trips.passive.flags.valid;
504 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
505 valid |= tz->trips.active[i].flags.valid;
508 pr_warn(FW_BUG "No valid trip found\n");
514 static void acpi_thermal_check(void *data)
516 struct acpi_thermal *tz = data;
521 thermal_zone_device_update(tz->thermal_zone);
524 /* sys I/F for generic thermal sysfs support */
525 #define KELVIN_TO_MILLICELSIUS(t, off) (((t) - (off)) * 100)
527 static int thermal_get_temp(struct thermal_zone_device *thermal,
530 struct acpi_thermal *tz = thermal->devdata;
536 result = acpi_thermal_get_temperature(tz);
540 *temp = KELVIN_TO_MILLICELSIUS(tz->temperature, tz->kelvin_offset);
544 static int thermal_get_mode(struct thermal_zone_device *thermal,
545 enum thermal_device_mode *mode)
547 struct acpi_thermal *tz = thermal->devdata;
552 *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
553 THERMAL_DEVICE_DISABLED;
558 static int thermal_set_mode(struct thermal_zone_device *thermal,
559 enum thermal_device_mode mode)
561 struct acpi_thermal *tz = thermal->devdata;
568 * enable/disable thermal management from ACPI thermal driver
570 if (mode == THERMAL_DEVICE_ENABLED)
572 else if (mode == THERMAL_DEVICE_DISABLED) {
574 pr_warn("thermal zone will be disabled\n");
578 if (enable != tz->tz_enabled) {
579 tz->tz_enabled = enable;
580 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
581 "%s kernel ACPI thermal control\n",
582 tz->tz_enabled ? "Enable" : "Disable"));
583 acpi_thermal_check(tz);
588 static int thermal_get_trip_type(struct thermal_zone_device *thermal,
589 int trip, enum thermal_trip_type *type)
591 struct acpi_thermal *tz = thermal->devdata;
597 if (tz->trips.critical.flags.valid) {
599 *type = THERMAL_TRIP_CRITICAL;
605 if (tz->trips.hot.flags.valid) {
607 *type = THERMAL_TRIP_HOT;
613 if (tz->trips.passive.flags.valid) {
615 *type = THERMAL_TRIP_PASSIVE;
621 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
622 tz->trips.active[i].flags.valid; i++) {
624 *type = THERMAL_TRIP_ACTIVE;
633 static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
634 int trip, unsigned long *temp)
636 struct acpi_thermal *tz = thermal->devdata;
642 if (tz->trips.critical.flags.valid) {
644 *temp = KELVIN_TO_MILLICELSIUS(
645 tz->trips.critical.temperature,
652 if (tz->trips.hot.flags.valid) {
654 *temp = KELVIN_TO_MILLICELSIUS(
655 tz->trips.hot.temperature,
662 if (tz->trips.passive.flags.valid) {
664 *temp = KELVIN_TO_MILLICELSIUS(
665 tz->trips.passive.temperature,
672 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
673 tz->trips.active[i].flags.valid; i++) {
675 *temp = KELVIN_TO_MILLICELSIUS(
676 tz->trips.active[i].temperature,
686 static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
687 unsigned long *temperature) {
688 struct acpi_thermal *tz = thermal->devdata;
690 if (tz->trips.critical.flags.valid) {
691 *temperature = KELVIN_TO_MILLICELSIUS(
692 tz->trips.critical.temperature,
699 static int thermal_get_trend(struct thermal_zone_device *thermal,
700 int trip, enum thermal_trend *trend)
702 struct acpi_thermal *tz = thermal->devdata;
703 enum thermal_trip_type type;
706 if (thermal_get_trip_type(thermal, trip, &type))
709 if (type == THERMAL_TRIP_ACTIVE) {
710 unsigned long trip_temp;
711 unsigned long temp = KELVIN_TO_MILLICELSIUS(tz->temperature,
713 if (thermal_get_trip_temp(thermal, trip, &trip_temp))
716 if (temp > trip_temp) {
717 *trend = THERMAL_TREND_RAISING;
720 /* Fall back on default trend */
726 * tz->temperature has already been updated by generic thermal layer,
727 * before this callback being invoked
729 i = (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature))
730 + (tz->trips.passive.tc2
731 * (tz->temperature - tz->trips.passive.temperature));
734 *trend = THERMAL_TREND_RAISING;
736 *trend = THERMAL_TREND_DROPPING;
738 *trend = THERMAL_TREND_STABLE;
743 static int thermal_notify(struct thermal_zone_device *thermal, int trip,
744 enum thermal_trip_type trip_type)
747 struct acpi_thermal *tz = thermal->devdata;
749 if (trip_type == THERMAL_TRIP_CRITICAL)
750 type = ACPI_THERMAL_NOTIFY_CRITICAL;
751 else if (trip_type == THERMAL_TRIP_HOT)
752 type = ACPI_THERMAL_NOTIFY_HOT;
756 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
757 dev_name(&tz->device->dev), type, 1);
759 if (trip_type == THERMAL_TRIP_CRITICAL && nocrt)
765 static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
766 struct thermal_cooling_device *cdev,
769 struct acpi_device *device = cdev->devdata;
770 struct acpi_thermal *tz = thermal->devdata;
771 struct acpi_device *dev;
779 if (tz->trips.critical.flags.valid)
782 if (tz->trips.hot.flags.valid)
785 if (tz->trips.passive.flags.valid) {
787 for (i = 0; i < tz->trips.passive.devices.count;
789 handle = tz->trips.passive.devices.handles[i];
790 status = acpi_bus_get_device(handle, &dev);
791 if (ACPI_FAILURE(status) || dev != device)
795 thermal_zone_bind_cooling_device
796 (thermal, trip, cdev,
797 THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
800 thermal_zone_unbind_cooling_device
801 (thermal, trip, cdev);
807 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
808 if (!tz->trips.active[i].flags.valid)
812 j < tz->trips.active[i].devices.count;
814 handle = tz->trips.active[i].devices.handles[j];
815 status = acpi_bus_get_device(handle, &dev);
816 if (ACPI_FAILURE(status) || dev != device)
819 result = thermal_zone_bind_cooling_device
820 (thermal, trip, cdev,
821 THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
823 result = thermal_zone_unbind_cooling_device
824 (thermal, trip, cdev);
830 for (i = 0; i < tz->devices.count; i++) {
831 handle = tz->devices.handles[i];
832 status = acpi_bus_get_device(handle, &dev);
833 if (ACPI_SUCCESS(status) && (dev == device)) {
835 result = thermal_zone_bind_cooling_device
836 (thermal, THERMAL_TRIPS_NONE,
837 cdev, THERMAL_NO_LIMIT,
840 result = thermal_zone_unbind_cooling_device
841 (thermal, THERMAL_TRIPS_NONE,
853 acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
854 struct thermal_cooling_device *cdev)
856 return acpi_thermal_cooling_device_cb(thermal, cdev, true);
860 acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
861 struct thermal_cooling_device *cdev)
863 return acpi_thermal_cooling_device_cb(thermal, cdev, false);
866 static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
867 .bind = acpi_thermal_bind_cooling_device,
868 .unbind = acpi_thermal_unbind_cooling_device,
869 .get_temp = thermal_get_temp,
870 .get_mode = thermal_get_mode,
871 .set_mode = thermal_set_mode,
872 .get_trip_type = thermal_get_trip_type,
873 .get_trip_temp = thermal_get_trip_temp,
874 .get_crit_temp = thermal_get_crit_temp,
875 .get_trend = thermal_get_trend,
876 .notify = thermal_notify,
879 static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
886 if (tz->trips.critical.flags.valid)
889 if (tz->trips.hot.flags.valid)
892 if (tz->trips.passive.flags.valid)
895 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
896 tz->trips.active[i].flags.valid; i++, trips++);
898 if (tz->trips.passive.flags.valid)
900 thermal_zone_device_register("acpitz", trips, 0, tz,
901 &acpi_thermal_zone_ops, NULL,
902 tz->trips.passive.tsp*100,
903 tz->polling_frequency*100);
906 thermal_zone_device_register("acpitz", trips, 0, tz,
907 &acpi_thermal_zone_ops, NULL,
908 0, tz->polling_frequency*100);
909 if (IS_ERR(tz->thermal_zone))
912 result = sysfs_create_link(&tz->device->dev.kobj,
913 &tz->thermal_zone->device.kobj, "thermal_zone");
917 result = sysfs_create_link(&tz->thermal_zone->device.kobj,
918 &tz->device->dev.kobj, "device");
922 status = acpi_attach_data(tz->device->handle,
923 acpi_bus_private_data_handler,
925 if (ACPI_FAILURE(status)) {
926 pr_err(PREFIX "Error attaching device data\n");
932 dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
933 tz->thermal_zone->id);
937 static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
939 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
940 sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
941 thermal_zone_device_unregister(tz->thermal_zone);
942 tz->thermal_zone = NULL;
943 acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler);
947 /* --------------------------------------------------------------------------
949 -------------------------------------------------------------------------- */
951 static void acpi_thermal_notify(struct acpi_device *device, u32 event)
953 struct acpi_thermal *tz = acpi_driver_data(device);
960 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
961 acpi_thermal_check(tz);
963 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
964 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS);
965 acpi_thermal_check(tz);
966 acpi_bus_generate_netlink_event(device->pnp.device_class,
967 dev_name(&device->dev), event, 0);
969 case ACPI_THERMAL_NOTIFY_DEVICES:
970 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES);
971 acpi_thermal_check(tz);
972 acpi_bus_generate_netlink_event(device->pnp.device_class,
973 dev_name(&device->dev), event, 0);
976 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
977 "Unsupported event [0x%x]\n", event));
983 * On some platforms, the AML code has dependency about
984 * the evaluating order of _TMP and _CRT/_HOT/_PSV/_ACx.
985 * 1. On HP Pavilion G4-1016tx, _TMP must be invoked after
986 * /_CRT/_HOT/_PSV/_ACx, or else system will be power off.
987 * 2. On HP Compaq 6715b/6715s, the return value of _PSV is 0
988 * if _TMP has never been evaluated.
990 * As this dependency is totally transparent to OS, evaluate
991 * all of them once, in the order of _CRT/_HOT/_PSV/_ACx,
992 * _TMP, before they are actually used.
994 static void acpi_thermal_aml_dependency_fix(struct acpi_thermal *tz)
996 acpi_handle handle = tz->device->handle;
997 unsigned long long value;
1000 acpi_evaluate_integer(handle, "_CRT", NULL, &value);
1001 acpi_evaluate_integer(handle, "_HOT", NULL, &value);
1002 acpi_evaluate_integer(handle, "_PSV", NULL, &value);
1003 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1004 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
1007 status = acpi_evaluate_integer(handle, name, NULL, &value);
1008 if (status == AE_NOT_FOUND)
1011 acpi_evaluate_integer(handle, "_TMP", NULL, &value);
1014 static int acpi_thermal_get_info(struct acpi_thermal *tz)
1022 acpi_thermal_aml_dependency_fix(tz);
1024 /* Get trip points [_CRT, _PSV, etc.] (required) */
1025 result = acpi_thermal_get_trip_points(tz);
1029 /* Get temperature [_TMP] (required) */
1030 result = acpi_thermal_get_temperature(tz);
1034 /* Set the cooling mode [_SCP] to active cooling (default) */
1035 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
1037 tz->flags.cooling_mode = 1;
1039 /* Get default polling frequency [_TZP] (optional) */
1041 tz->polling_frequency = tzp;
1043 acpi_thermal_get_polling_frequency(tz);
1049 * The exact offset between Kelvin and degree Celsius is 273.15. However ACPI
1050 * handles temperature values with a single decimal place. As a consequence,
1051 * some implementations use an offset of 273.1 and others use an offset of
1052 * 273.2. Try to find out which one is being used, to present the most
1053 * accurate and visually appealing number.
1055 * The heuristic below should work for all ACPI thermal zones which have a
1056 * critical trip point with a value being a multiple of 0.5 degree Celsius.
1058 static void acpi_thermal_guess_offset(struct acpi_thermal *tz)
1060 if (tz->trips.critical.flags.valid &&
1061 (tz->trips.critical.temperature % 5) == 1)
1062 tz->kelvin_offset = 2731;
1064 tz->kelvin_offset = 2732;
1067 static int acpi_thermal_add(struct acpi_device *device)
1070 struct acpi_thermal *tz = NULL;
1076 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1080 tz->device = device;
1081 strcpy(tz->name, device->pnp.bus_id);
1082 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1083 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
1084 device->driver_data = tz;
1086 result = acpi_thermal_get_info(tz);
1090 acpi_thermal_guess_offset(tz);
1092 result = acpi_thermal_register_thermal_zone(tz);
1096 pr_info(PREFIX "%s [%s] (%ld C)\n", acpi_device_name(device),
1097 acpi_device_bid(device), KELVIN_TO_CELSIUS(tz->temperature));
1106 static int acpi_thermal_remove(struct acpi_device *device)
1108 struct acpi_thermal *tz = NULL;
1110 if (!device || !acpi_driver_data(device))
1113 tz = acpi_driver_data(device);
1115 acpi_thermal_unregister_thermal_zone(tz);
1120 #ifdef CONFIG_PM_SLEEP
1121 static int acpi_thermal_resume(struct device *dev)
1123 struct acpi_thermal *tz;
1124 int i, j, power_state, result;
1129 tz = acpi_driver_data(to_acpi_device(dev));
1133 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1134 if (!(&tz->trips.active[i]))
1136 if (!tz->trips.active[i].flags.valid)
1138 tz->trips.active[i].flags.enabled = 1;
1139 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1140 result = acpi_bus_update_power(
1141 tz->trips.active[i].devices.handles[j],
1143 if (result || (power_state != ACPI_STATE_D0)) {
1144 tz->trips.active[i].flags.enabled = 0;
1148 tz->state.active |= tz->trips.active[i].flags.enabled;
1151 acpi_thermal_check(tz);
1157 static int thermal_act(const struct dmi_system_id *d) {
1160 pr_notice(PREFIX "%s detected: "
1161 "disabling all active thermal trip points\n", d->ident);
1166 static int thermal_nocrt(const struct dmi_system_id *d) {
1168 pr_notice(PREFIX "%s detected: "
1169 "disabling all critical thermal trip point actions.\n", d->ident);
1173 static int thermal_tzp(const struct dmi_system_id *d) {
1176 pr_notice(PREFIX "%s detected: "
1177 "enabling thermal zone polling\n", d->ident);
1178 tzp = 300; /* 300 dS = 30 Seconds */
1182 static int thermal_psv(const struct dmi_system_id *d) {
1185 pr_notice(PREFIX "%s detected: "
1186 "disabling all passive thermal trip points\n", d->ident);
1192 static struct dmi_system_id thermal_dmi_table[] __initdata = {
1194 * Award BIOS on this AOpen makes thermal control almost worthless.
1195 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1198 .callback = thermal_act,
1199 .ident = "AOpen i915GMm-HFS",
1201 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1202 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1206 .callback = thermal_psv,
1207 .ident = "AOpen i915GMm-HFS",
1209 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1210 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1214 .callback = thermal_tzp,
1215 .ident = "AOpen i915GMm-HFS",
1217 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1218 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1222 .callback = thermal_nocrt,
1223 .ident = "Gigabyte GA-7ZX",
1225 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
1226 DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
1232 static int __init acpi_thermal_init(void)
1236 dmi_check_system(thermal_dmi_table);
1239 pr_notice(PREFIX "thermal control disabled\n");
1243 result = acpi_bus_register_driver(&acpi_thermal_driver);
1250 static void __exit acpi_thermal_exit(void)
1253 acpi_bus_unregister_driver(&acpi_thermal_driver);
1258 module_init(acpi_thermal_init);
1259 module_exit(acpi_thermal_exit);