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_FILE_STATE "state"
54 #define ACPI_THERMAL_FILE_TEMPERATURE "temperature"
55 #define ACPI_THERMAL_FILE_TRIP_POINTS "trip_points"
56 #define ACPI_THERMAL_FILE_COOLING_MODE "cooling_mode"
57 #define ACPI_THERMAL_FILE_POLLING_FREQ "polling_frequency"
58 #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80
59 #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81
60 #define ACPI_THERMAL_NOTIFY_DEVICES 0x82
61 #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0
62 #define ACPI_THERMAL_NOTIFY_HOT 0xF1
63 #define ACPI_THERMAL_MODE_ACTIVE 0x00
65 #define ACPI_THERMAL_MAX_ACTIVE 10
66 #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
68 #define _COMPONENT ACPI_THERMAL_COMPONENT
69 ACPI_MODULE_NAME("thermal");
71 MODULE_AUTHOR("Paul Diefenbaugh");
72 MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
73 MODULE_LICENSE("GPL");
76 module_param(act, int, 0644);
77 MODULE_PARM_DESC(act, "Disable or override all lowest active trip points.");
80 module_param(crt, int, 0644);
81 MODULE_PARM_DESC(crt, "Disable or lower all critical trip points.");
84 module_param(tzp, int, 0444);
85 MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.");
88 module_param(nocrt, int, 0);
89 MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points.");
92 module_param(off, int, 0);
93 MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.");
96 module_param(psv, int, 0644);
97 MODULE_PARM_DESC(psv, "Disable or override all passive trip points.");
99 static int acpi_thermal_add(struct acpi_device *device);
100 static int acpi_thermal_remove(struct acpi_device *device);
101 static void acpi_thermal_notify(struct acpi_device *device, u32 event);
103 static const struct acpi_device_id thermal_device_ids[] = {
104 {ACPI_THERMAL_HID, 0},
107 MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
109 #ifdef CONFIG_PM_SLEEP
110 static int acpi_thermal_resume(struct device *dev);
112 static SIMPLE_DEV_PM_OPS(acpi_thermal_pm, NULL, acpi_thermal_resume);
114 static struct acpi_driver acpi_thermal_driver = {
116 .class = ACPI_THERMAL_CLASS,
117 .ids = thermal_device_ids,
119 .add = acpi_thermal_add,
120 .remove = acpi_thermal_remove,
121 .notify = acpi_thermal_notify,
123 .drv.pm = &acpi_thermal_pm,
126 struct acpi_thermal_state {
135 struct acpi_thermal_state_flags {
141 struct acpi_thermal_critical {
142 struct acpi_thermal_state_flags flags;
143 unsigned long temperature;
146 struct acpi_thermal_hot {
147 struct acpi_thermal_state_flags flags;
148 unsigned long temperature;
151 struct acpi_thermal_passive {
152 struct acpi_thermal_state_flags flags;
153 unsigned long temperature;
157 struct acpi_handle_list devices;
160 struct acpi_thermal_active {
161 struct acpi_thermal_state_flags flags;
162 unsigned long temperature;
163 struct acpi_handle_list devices;
166 struct acpi_thermal_trips {
167 struct acpi_thermal_critical critical;
168 struct acpi_thermal_hot hot;
169 struct acpi_thermal_passive passive;
170 struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
173 struct acpi_thermal_flags {
174 u8 cooling_mode:1; /* _SCP */
175 u8 devices:1; /* _TZD */
179 struct acpi_thermal {
180 struct acpi_device * device;
182 unsigned long temperature;
183 unsigned long last_temperature;
184 unsigned long polling_frequency;
186 struct acpi_thermal_flags flags;
187 struct acpi_thermal_state state;
188 struct acpi_thermal_trips trips;
189 struct acpi_handle_list devices;
190 struct thermal_zone_device *thermal_zone;
195 /* --------------------------------------------------------------------------
196 Thermal Zone Management
197 -------------------------------------------------------------------------- */
199 static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
201 acpi_status status = AE_OK;
202 unsigned long long tmp;
207 tz->last_temperature = tz->temperature;
209 status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp);
210 if (ACPI_FAILURE(status))
213 tz->temperature = tmp;
214 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
220 static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
222 acpi_status status = AE_OK;
223 unsigned long long tmp;
228 status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp);
229 if (ACPI_FAILURE(status))
232 tz->polling_frequency = tmp;
233 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
234 tz->polling_frequency));
239 static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
241 acpi_status status = AE_OK;
242 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
243 struct acpi_object_list arg_list = { 1, &arg0 };
244 acpi_handle handle = NULL;
250 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
251 if (ACPI_FAILURE(status)) {
252 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
256 arg0.integer.value = mode;
258 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
259 if (ACPI_FAILURE(status))
265 #define ACPI_TRIPS_CRITICAL 0x01
266 #define ACPI_TRIPS_HOT 0x02
267 #define ACPI_TRIPS_PASSIVE 0x04
268 #define ACPI_TRIPS_ACTIVE 0x08
269 #define ACPI_TRIPS_DEVICES 0x10
271 #define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE)
272 #define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES
274 #define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \
275 ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \
279 * This exception is thrown out in two cases:
280 * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
281 * when re-evaluating the AML code.
282 * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change.
283 * We need to re-bind the cooling devices of a thermal zone when this occurs.
285 #define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \
287 if (flags != ACPI_TRIPS_INIT) \
288 ACPI_EXCEPTION((AE_INFO, AE_ERROR, \
289 "ACPI thermal trip point %s changed\n" \
290 "Please send acpidump to linux-acpi@vger.kernel.org", str)); \
293 static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
295 acpi_status status = AE_OK;
296 unsigned long long tmp;
297 struct acpi_handle_list devices;
301 /* Critical Shutdown */
302 if (flag & ACPI_TRIPS_CRITICAL) {
303 status = acpi_evaluate_integer(tz->device->handle,
305 tz->trips.critical.temperature = tmp;
307 * Treat freezing temperatures as invalid as well; some
308 * BIOSes return really low values and cause reboots at startup.
309 * Below zero (Celsius) values clearly aren't right for sure..
310 * ... so lets discard those as invalid.
312 if (ACPI_FAILURE(status)) {
313 tz->trips.critical.flags.valid = 0;
314 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
315 "No critical threshold\n"));
316 } else if (tmp <= 2732) {
317 printk(KERN_WARNING FW_BUG "Invalid critical threshold "
319 tz->trips.critical.flags.valid = 0;
321 tz->trips.critical.flags.valid = 1;
322 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
323 "Found critical threshold [%lu]\n",
324 tz->trips.critical.temperature));
326 if (tz->trips.critical.flags.valid == 1) {
328 tz->trips.critical.flags.valid = 0;
329 } else if (crt > 0) {
330 unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
332 * Allow override critical threshold
334 if (crt_k > tz->trips.critical.temperature)
335 printk(KERN_WARNING PREFIX
336 "Critical threshold %d C\n", crt);
337 tz->trips.critical.temperature = crt_k;
342 /* Critical Sleep (optional) */
343 if (flag & ACPI_TRIPS_HOT) {
344 status = acpi_evaluate_integer(tz->device->handle,
346 if (ACPI_FAILURE(status)) {
347 tz->trips.hot.flags.valid = 0;
348 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
349 "No hot threshold\n"));
351 tz->trips.hot.temperature = tmp;
352 tz->trips.hot.flags.valid = 1;
353 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
354 "Found hot threshold [%lu]\n",
355 tz->trips.critical.temperature));
359 /* Passive (optional) */
360 if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) ||
361 (flag == ACPI_TRIPS_INIT)) {
362 valid = tz->trips.passive.flags.valid;
365 } else if (psv > 0) {
366 tmp = CELSIUS_TO_KELVIN(psv);
369 status = acpi_evaluate_integer(tz->device->handle,
373 if (ACPI_FAILURE(status))
374 tz->trips.passive.flags.valid = 0;
376 tz->trips.passive.temperature = tmp;
377 tz->trips.passive.flags.valid = 1;
378 if (flag == ACPI_TRIPS_INIT) {
379 status = acpi_evaluate_integer(
380 tz->device->handle, "_TC1",
382 if (ACPI_FAILURE(status))
383 tz->trips.passive.flags.valid = 0;
385 tz->trips.passive.tc1 = tmp;
386 status = acpi_evaluate_integer(
387 tz->device->handle, "_TC2",
389 if (ACPI_FAILURE(status))
390 tz->trips.passive.flags.valid = 0;
392 tz->trips.passive.tc2 = tmp;
393 status = acpi_evaluate_integer(
394 tz->device->handle, "_TSP",
396 if (ACPI_FAILURE(status))
397 tz->trips.passive.flags.valid = 0;
399 tz->trips.passive.tsp = tmp;
403 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) {
404 memset(&devices, 0, sizeof(struct acpi_handle_list));
405 status = acpi_evaluate_reference(tz->device->handle, "_PSL",
407 if (ACPI_FAILURE(status)) {
408 printk(KERN_WARNING PREFIX
409 "Invalid passive threshold\n");
410 tz->trips.passive.flags.valid = 0;
413 tz->trips.passive.flags.valid = 1;
415 if (memcmp(&tz->trips.passive.devices, &devices,
416 sizeof(struct acpi_handle_list))) {
417 memcpy(&tz->trips.passive.devices, &devices,
418 sizeof(struct acpi_handle_list));
419 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
422 if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) {
423 if (valid != tz->trips.passive.flags.valid)
424 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
427 /* Active (optional) */
428 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
429 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
430 valid = tz->trips.active[i].flags.valid;
433 break; /* disable all active trip points */
435 if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) &&
436 tz->trips.active[i].flags.valid)) {
437 status = acpi_evaluate_integer(tz->device->handle,
439 if (ACPI_FAILURE(status)) {
440 tz->trips.active[i].flags.valid = 0;
446 tz->trips.active[0].temperature =
447 CELSIUS_TO_KELVIN(act);
450 * Don't allow override higher than
451 * the next higher trip point
453 tz->trips.active[i - 1].temperature =
454 (tz->trips.active[i - 2].temperature <
455 CELSIUS_TO_KELVIN(act) ?
456 tz->trips.active[i - 2].temperature :
457 CELSIUS_TO_KELVIN(act));
460 tz->trips.active[i].temperature = tmp;
461 tz->trips.active[i].flags.valid = 1;
466 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) {
467 memset(&devices, 0, sizeof(struct acpi_handle_list));
468 status = acpi_evaluate_reference(tz->device->handle,
469 name, NULL, &devices);
470 if (ACPI_FAILURE(status)) {
471 printk(KERN_WARNING PREFIX
472 "Invalid active%d threshold\n", i);
473 tz->trips.active[i].flags.valid = 0;
476 tz->trips.active[i].flags.valid = 1;
478 if (memcmp(&tz->trips.active[i].devices, &devices,
479 sizeof(struct acpi_handle_list))) {
480 memcpy(&tz->trips.active[i].devices, &devices,
481 sizeof(struct acpi_handle_list));
482 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
485 if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES))
486 if (valid != tz->trips.active[i].flags.valid)
487 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
489 if (!tz->trips.active[i].flags.valid)
493 if (flag & ACPI_TRIPS_DEVICES) {
494 memset(&devices, 0, sizeof(struct acpi_handle_list));
495 status = acpi_evaluate_reference(tz->device->handle, "_TZD",
497 if (memcmp(&tz->devices, &devices,
498 sizeof(struct acpi_handle_list))) {
499 memcpy(&tz->devices, &devices,
500 sizeof(struct acpi_handle_list));
501 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
508 static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
510 int i, valid, ret = acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
515 valid = tz->trips.critical.flags.valid |
516 tz->trips.hot.flags.valid |
517 tz->trips.passive.flags.valid;
519 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
520 valid |= tz->trips.active[i].flags.valid;
523 printk(KERN_WARNING FW_BUG "No valid trip found\n");
529 static void acpi_thermal_check(void *data)
531 struct acpi_thermal *tz = data;
533 if (!tz->tz_enabled) {
534 pr_warn("thermal zone is disabled \n");
537 thermal_zone_device_update(tz->thermal_zone);
540 /* sys I/F for generic thermal sysfs support */
541 #define KELVIN_TO_MILLICELSIUS(t, off) (((t) - (off)) * 100)
543 static int thermal_get_temp(struct thermal_zone_device *thermal,
546 struct acpi_thermal *tz = thermal->devdata;
552 result = acpi_thermal_get_temperature(tz);
556 *temp = KELVIN_TO_MILLICELSIUS(tz->temperature, tz->kelvin_offset);
560 static int thermal_get_mode(struct thermal_zone_device *thermal,
561 enum thermal_device_mode *mode)
563 struct acpi_thermal *tz = thermal->devdata;
568 *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
569 THERMAL_DEVICE_DISABLED;
574 static int thermal_set_mode(struct thermal_zone_device *thermal,
575 enum thermal_device_mode mode)
577 struct acpi_thermal *tz = thermal->devdata;
584 * enable/disable thermal management from ACPI thermal driver
586 if (mode == THERMAL_DEVICE_ENABLED)
588 else if (mode == THERMAL_DEVICE_DISABLED)
593 if (enable != tz->tz_enabled) {
594 tz->tz_enabled = enable;
595 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
596 "%s kernel ACPI thermal control\n",
597 tz->tz_enabled ? "Enable" : "Disable"));
598 acpi_thermal_check(tz);
603 static int thermal_get_trip_type(struct thermal_zone_device *thermal,
604 int trip, enum thermal_trip_type *type)
606 struct acpi_thermal *tz = thermal->devdata;
612 if (tz->trips.critical.flags.valid) {
614 *type = THERMAL_TRIP_CRITICAL;
620 if (tz->trips.hot.flags.valid) {
622 *type = THERMAL_TRIP_HOT;
628 if (tz->trips.passive.flags.valid) {
630 *type = THERMAL_TRIP_PASSIVE;
636 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
637 tz->trips.active[i].flags.valid; i++) {
639 *type = THERMAL_TRIP_ACTIVE;
648 static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
649 int trip, unsigned long *temp)
651 struct acpi_thermal *tz = thermal->devdata;
657 if (tz->trips.critical.flags.valid) {
659 *temp = KELVIN_TO_MILLICELSIUS(
660 tz->trips.critical.temperature,
667 if (tz->trips.hot.flags.valid) {
669 *temp = KELVIN_TO_MILLICELSIUS(
670 tz->trips.hot.temperature,
677 if (tz->trips.passive.flags.valid) {
679 *temp = KELVIN_TO_MILLICELSIUS(
680 tz->trips.passive.temperature,
687 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
688 tz->trips.active[i].flags.valid; i++) {
690 *temp = KELVIN_TO_MILLICELSIUS(
691 tz->trips.active[i].temperature,
701 static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
702 unsigned long *temperature) {
703 struct acpi_thermal *tz = thermal->devdata;
705 if (tz->trips.critical.flags.valid) {
706 *temperature = KELVIN_TO_MILLICELSIUS(
707 tz->trips.critical.temperature,
714 static int thermal_get_trend(struct thermal_zone_device *thermal,
715 int trip, enum thermal_trend *trend)
717 struct acpi_thermal *tz = thermal->devdata;
718 enum thermal_trip_type type;
721 if (thermal_get_trip_type(thermal, trip, &type))
724 if (type == THERMAL_TRIP_ACTIVE) {
725 unsigned long trip_temp;
726 unsigned long temp = KELVIN_TO_MILLICELSIUS(tz->temperature,
728 if (thermal_get_trip_temp(thermal, trip, &trip_temp))
731 if (temp > trip_temp) {
732 *trend = THERMAL_TREND_RAISING;
735 /* Fall back on default trend */
741 * tz->temperature has already been updated by generic thermal layer,
742 * before this callback being invoked
744 i = (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature))
745 + (tz->trips.passive.tc2
746 * (tz->temperature - tz->trips.passive.temperature));
749 *trend = THERMAL_TREND_RAISING;
751 *trend = THERMAL_TREND_DROPPING;
753 *trend = THERMAL_TREND_STABLE;
758 static int thermal_notify(struct thermal_zone_device *thermal, int trip,
759 enum thermal_trip_type trip_type)
762 struct acpi_thermal *tz = thermal->devdata;
764 if (trip_type == THERMAL_TRIP_CRITICAL)
765 type = ACPI_THERMAL_NOTIFY_CRITICAL;
766 else if (trip_type == THERMAL_TRIP_HOT)
767 type = ACPI_THERMAL_NOTIFY_HOT;
771 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
772 dev_name(&tz->device->dev), type, 1);
774 if (trip_type == THERMAL_TRIP_CRITICAL && nocrt)
780 static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
781 struct thermal_cooling_device *cdev,
784 struct acpi_device *device = cdev->devdata;
785 struct acpi_thermal *tz = thermal->devdata;
786 struct acpi_device *dev;
794 if (tz->trips.critical.flags.valid)
797 if (tz->trips.hot.flags.valid)
800 if (tz->trips.passive.flags.valid) {
802 for (i = 0; i < tz->trips.passive.devices.count;
804 handle = tz->trips.passive.devices.handles[i];
805 status = acpi_bus_get_device(handle, &dev);
806 if (ACPI_FAILURE(status) || dev != device)
810 thermal_zone_bind_cooling_device
811 (thermal, trip, cdev,
812 THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
815 thermal_zone_unbind_cooling_device
816 (thermal, trip, cdev);
822 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
823 if (!tz->trips.active[i].flags.valid)
827 j < tz->trips.active[i].devices.count;
829 handle = tz->trips.active[i].devices.handles[j];
830 status = acpi_bus_get_device(handle, &dev);
831 if (ACPI_FAILURE(status) || dev != device)
834 result = thermal_zone_bind_cooling_device
835 (thermal, trip, cdev,
836 THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
838 result = thermal_zone_unbind_cooling_device
839 (thermal, trip, cdev);
845 for (i = 0; i < tz->devices.count; i++) {
846 handle = tz->devices.handles[i];
847 status = acpi_bus_get_device(handle, &dev);
848 if (ACPI_SUCCESS(status) && (dev == device)) {
850 result = thermal_zone_bind_cooling_device
855 result = thermal_zone_unbind_cooling_device
867 acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
868 struct thermal_cooling_device *cdev)
870 return acpi_thermal_cooling_device_cb(thermal, cdev, true);
874 acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
875 struct thermal_cooling_device *cdev)
877 return acpi_thermal_cooling_device_cb(thermal, cdev, false);
880 static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
881 .bind = acpi_thermal_bind_cooling_device,
882 .unbind = acpi_thermal_unbind_cooling_device,
883 .get_temp = thermal_get_temp,
884 .get_mode = thermal_get_mode,
885 .set_mode = thermal_set_mode,
886 .get_trip_type = thermal_get_trip_type,
887 .get_trip_temp = thermal_get_trip_temp,
888 .get_crit_temp = thermal_get_crit_temp,
889 .get_trend = thermal_get_trend,
890 .notify = thermal_notify,
893 static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
900 if (tz->trips.critical.flags.valid)
903 if (tz->trips.hot.flags.valid)
906 if (tz->trips.passive.flags.valid)
909 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
910 tz->trips.active[i].flags.valid; i++, trips++);
912 if (tz->trips.passive.flags.valid)
914 thermal_zone_device_register("acpitz", trips, 0, tz,
915 &acpi_thermal_zone_ops, NULL,
916 tz->trips.passive.tsp*100,
917 tz->polling_frequency*100);
920 thermal_zone_device_register("acpitz", trips, 0, tz,
921 &acpi_thermal_zone_ops, NULL,
922 0, tz->polling_frequency*100);
923 if (IS_ERR(tz->thermal_zone))
926 result = sysfs_create_link(&tz->device->dev.kobj,
927 &tz->thermal_zone->device.kobj, "thermal_zone");
931 result = sysfs_create_link(&tz->thermal_zone->device.kobj,
932 &tz->device->dev.kobj, "device");
936 status = acpi_attach_data(tz->device->handle,
937 acpi_bus_private_data_handler,
939 if (ACPI_FAILURE(status)) {
940 printk(KERN_ERR PREFIX
941 "Error attaching device data\n");
947 dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
948 tz->thermal_zone->id);
952 static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
954 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
955 sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
956 thermal_zone_device_unregister(tz->thermal_zone);
957 tz->thermal_zone = NULL;
958 acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler);
962 /* --------------------------------------------------------------------------
964 -------------------------------------------------------------------------- */
966 static void acpi_thermal_notify(struct acpi_device *device, u32 event)
968 struct acpi_thermal *tz = acpi_driver_data(device);
975 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
976 acpi_thermal_check(tz);
978 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
979 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS);
980 acpi_thermal_check(tz);
981 acpi_bus_generate_netlink_event(device->pnp.device_class,
982 dev_name(&device->dev), event, 0);
984 case ACPI_THERMAL_NOTIFY_DEVICES:
985 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES);
986 acpi_thermal_check(tz);
987 acpi_bus_generate_netlink_event(device->pnp.device_class,
988 dev_name(&device->dev), event, 0);
991 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
992 "Unsupported event [0x%x]\n", event));
998 * On some platforms, the AML code has dependency about
999 * the evaluating order of _TMP and _CRT/_HOT/_PSV/_ACx.
1000 * 1. On HP Pavilion G4-1016tx, _TMP must be invoked after
1001 * /_CRT/_HOT/_PSV/_ACx, or else system will be power off.
1002 * 2. On HP Compaq 6715b/6715s, the return value of _PSV is 0
1003 * if _TMP has never been evaluated.
1005 * As this dependency is totally transparent to OS, evaluate
1006 * all of them once, in the order of _CRT/_HOT/_PSV/_ACx,
1007 * _TMP, before they are actually used.
1009 static void acpi_thermal_aml_dependency_fix(struct acpi_thermal *tz)
1011 acpi_handle handle = tz->device->handle;
1012 unsigned long long value;
1015 acpi_evaluate_integer(handle, "_CRT", NULL, &value);
1016 acpi_evaluate_integer(handle, "_HOT", NULL, &value);
1017 acpi_evaluate_integer(handle, "_PSV", NULL, &value);
1018 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1019 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
1022 status = acpi_evaluate_integer(handle, name, NULL, &value);
1023 if (status == AE_NOT_FOUND)
1026 acpi_evaluate_integer(handle, "_TMP", NULL, &value);
1029 static int acpi_thermal_get_info(struct acpi_thermal *tz)
1037 acpi_thermal_aml_dependency_fix(tz);
1039 /* Get trip points [_CRT, _PSV, etc.] (required) */
1040 result = acpi_thermal_get_trip_points(tz);
1044 /* Get temperature [_TMP] (required) */
1045 result = acpi_thermal_get_temperature(tz);
1049 /* Set the cooling mode [_SCP] to active cooling (default) */
1050 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
1052 tz->flags.cooling_mode = 1;
1054 /* Get default polling frequency [_TZP] (optional) */
1056 tz->polling_frequency = tzp;
1058 acpi_thermal_get_polling_frequency(tz);
1064 * The exact offset between Kelvin and degree Celsius is 273.15. However ACPI
1065 * handles temperature values with a single decimal place. As a consequence,
1066 * some implementations use an offset of 273.1 and others use an offset of
1067 * 273.2. Try to find out which one is being used, to present the most
1068 * accurate and visually appealing number.
1070 * The heuristic below should work for all ACPI thermal zones which have a
1071 * critical trip point with a value being a multiple of 0.5 degree Celsius.
1073 static void acpi_thermal_guess_offset(struct acpi_thermal *tz)
1075 if (tz->trips.critical.flags.valid &&
1076 (tz->trips.critical.temperature % 5) == 1)
1077 tz->kelvin_offset = 2731;
1079 tz->kelvin_offset = 2732;
1082 static int acpi_thermal_add(struct acpi_device *device)
1085 struct acpi_thermal *tz = NULL;
1091 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1095 tz->device = device;
1096 strcpy(tz->name, device->pnp.bus_id);
1097 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1098 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
1099 device->driver_data = tz;
1101 result = acpi_thermal_get_info(tz);
1105 acpi_thermal_guess_offset(tz);
1107 result = acpi_thermal_register_thermal_zone(tz);
1111 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
1112 acpi_device_name(device), acpi_device_bid(device),
1113 KELVIN_TO_CELSIUS(tz->temperature));
1122 static int acpi_thermal_remove(struct acpi_device *device)
1124 struct acpi_thermal *tz = NULL;
1126 if (!device || !acpi_driver_data(device))
1129 tz = acpi_driver_data(device);
1131 acpi_thermal_unregister_thermal_zone(tz);
1136 #ifdef CONFIG_PM_SLEEP
1137 static int acpi_thermal_resume(struct device *dev)
1139 struct acpi_thermal *tz;
1140 int i, j, power_state, result;
1145 tz = acpi_driver_data(to_acpi_device(dev));
1149 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1150 if (!(&tz->trips.active[i]))
1152 if (!tz->trips.active[i].flags.valid)
1154 tz->trips.active[i].flags.enabled = 1;
1155 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1156 result = acpi_bus_update_power(
1157 tz->trips.active[i].devices.handles[j],
1159 if (result || (power_state != ACPI_STATE_D0)) {
1160 tz->trips.active[i].flags.enabled = 0;
1164 tz->state.active |= tz->trips.active[i].flags.enabled;
1167 acpi_thermal_check(tz);
1173 static int thermal_act(const struct dmi_system_id *d) {
1176 printk(KERN_NOTICE "ACPI: %s detected: "
1177 "disabling all active thermal trip points\n", d->ident);
1182 static int thermal_nocrt(const struct dmi_system_id *d) {
1184 printk(KERN_NOTICE "ACPI: %s detected: "
1185 "disabling all critical thermal trip point actions.\n", d->ident);
1189 static int thermal_tzp(const struct dmi_system_id *d) {
1192 printk(KERN_NOTICE "ACPI: %s detected: "
1193 "enabling thermal zone polling\n", d->ident);
1194 tzp = 300; /* 300 dS = 30 Seconds */
1198 static int thermal_psv(const struct dmi_system_id *d) {
1201 printk(KERN_NOTICE "ACPI: %s detected: "
1202 "disabling all passive thermal trip points\n", d->ident);
1208 static struct dmi_system_id thermal_dmi_table[] __initdata = {
1210 * Award BIOS on this AOpen makes thermal control almost worthless.
1211 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1214 .callback = thermal_act,
1215 .ident = "AOpen i915GMm-HFS",
1217 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1218 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1222 .callback = thermal_psv,
1223 .ident = "AOpen i915GMm-HFS",
1225 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1226 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1230 .callback = thermal_tzp,
1231 .ident = "AOpen i915GMm-HFS",
1233 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1234 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1238 .callback = thermal_nocrt,
1239 .ident = "Gigabyte GA-7ZX",
1241 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
1242 DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
1248 static int __init acpi_thermal_init(void)
1252 dmi_check_system(thermal_dmi_table);
1255 printk(KERN_NOTICE "ACPI: thermal control disabled\n");
1259 result = acpi_bus_register_driver(&acpi_thermal_driver);
1266 static void __exit acpi_thermal_exit(void)
1269 acpi_bus_unregister_driver(&acpi_thermal_driver);
1274 module_init(acpi_thermal_init);
1275 module_exit(acpi_thermal_exit);