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, int type);
101 static int acpi_thermal_resume(struct acpi_device *device);
102 static void acpi_thermal_notify(struct acpi_device *device, u32 event);
104 static const struct acpi_device_id thermal_device_ids[] = {
105 {ACPI_THERMAL_HID, 0},
108 MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
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 .resume = acpi_thermal_resume,
118 .notify = acpi_thermal_notify,
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;
192 /* --------------------------------------------------------------------------
193 Thermal Zone Management
194 -------------------------------------------------------------------------- */
196 static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
198 acpi_status status = AE_OK;
199 unsigned long long tmp;
204 tz->last_temperature = tz->temperature;
206 status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp);
207 if (ACPI_FAILURE(status))
210 tz->temperature = tmp;
211 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
217 static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
219 acpi_status status = AE_OK;
220 unsigned long long tmp;
225 if (tz->tz_enabled == THERMAL_DEVICE_DISABLED) {
226 tz->polling_frequency = 0;
230 /* Get default polling frequency [_TZP] (optional) */
232 tz->polling_frequency = tzp;
236 status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp);
237 if (ACPI_FAILURE(status))
240 tz->polling_frequency = tmp;
241 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
242 tz->polling_frequency));
247 static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
249 acpi_status status = AE_OK;
250 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
251 struct acpi_object_list arg_list = { 1, &arg0 };
252 acpi_handle handle = NULL;
258 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
259 if (ACPI_FAILURE(status)) {
260 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
264 arg0.integer.value = mode;
266 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
267 if (ACPI_FAILURE(status))
273 #define ACPI_TRIPS_CRITICAL 0x01
274 #define ACPI_TRIPS_HOT 0x02
275 #define ACPI_TRIPS_PASSIVE 0x04
276 #define ACPI_TRIPS_ACTIVE 0x08
277 #define ACPI_TRIPS_DEVICES 0x10
279 #define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE)
280 #define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES
282 #define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \
283 ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \
287 * This exception is thrown out in two cases:
288 * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
289 * when re-evaluating the AML code.
290 * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change.
291 * We need to re-bind the cooling devices of a thermal zone when this occurs.
293 #define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \
295 if (flags != ACPI_TRIPS_INIT) \
296 ACPI_EXCEPTION((AE_INFO, AE_ERROR, \
297 "ACPI thermal trip point %s changed\n" \
298 "Please send acpidump to linux-acpi@vger.kernel.org\n", str)); \
301 static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
303 acpi_status status = AE_OK;
304 unsigned long long tmp;
305 struct acpi_handle_list devices;
309 /* Critical Shutdown */
310 if (flag & ACPI_TRIPS_CRITICAL) {
311 status = acpi_evaluate_integer(tz->device->handle,
313 tz->trips.critical.temperature = tmp;
315 * Treat freezing temperatures as invalid as well; some
316 * BIOSes return really low values and cause reboots at startup.
317 * Below zero (Celsius) values clearly aren't right for sure..
318 * ... so lets discard those as invalid.
320 if (ACPI_FAILURE(status)) {
321 tz->trips.critical.flags.valid = 0;
322 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
323 "No critical threshold\n"));
324 } else if (tmp <= 2732) {
325 printk(KERN_WARNING FW_BUG "Invalid critical threshold "
327 tz->trips.critical.flags.valid = 0;
329 tz->trips.critical.flags.valid = 1;
330 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
331 "Found critical threshold [%lu]\n",
332 tz->trips.critical.temperature));
334 if (tz->trips.critical.flags.valid == 1) {
336 tz->trips.critical.flags.valid = 0;
337 } else if (crt > 0) {
338 unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
340 * Allow override critical threshold
342 if (crt_k > tz->trips.critical.temperature)
343 printk(KERN_WARNING PREFIX
344 "Critical threshold %d C\n", crt);
345 tz->trips.critical.temperature = crt_k;
350 /* Critical Sleep (optional) */
351 if (flag & ACPI_TRIPS_HOT) {
352 status = acpi_evaluate_integer(tz->device->handle,
354 if (ACPI_FAILURE(status)) {
355 tz->trips.hot.flags.valid = 0;
356 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
357 "No hot threshold\n"));
359 tz->trips.hot.temperature = tmp;
360 tz->trips.hot.flags.valid = 1;
361 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
362 "Found hot threshold [%lu]\n",
363 tz->trips.critical.temperature));
367 /* Passive (optional) */
368 if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) ||
369 (flag == ACPI_TRIPS_INIT)) {
370 valid = tz->trips.passive.flags.valid;
373 } else if (psv > 0) {
374 tmp = CELSIUS_TO_KELVIN(psv);
377 status = acpi_evaluate_integer(tz->device->handle,
381 if (ACPI_FAILURE(status))
382 tz->trips.passive.flags.valid = 0;
384 tz->trips.passive.temperature = tmp;
385 tz->trips.passive.flags.valid = 1;
386 if (flag == ACPI_TRIPS_INIT) {
387 status = acpi_evaluate_integer(
388 tz->device->handle, "_TC1",
390 if (ACPI_FAILURE(status))
391 tz->trips.passive.flags.valid = 0;
393 tz->trips.passive.tc1 = tmp;
394 status = acpi_evaluate_integer(
395 tz->device->handle, "_TC2",
397 if (ACPI_FAILURE(status))
398 tz->trips.passive.flags.valid = 0;
400 tz->trips.passive.tc2 = tmp;
401 status = acpi_evaluate_integer(
402 tz->device->handle, "_TSP",
404 if (ACPI_FAILURE(status))
405 tz->trips.passive.flags.valid = 0;
407 tz->trips.passive.tsp = tmp;
411 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) {
412 memset(&devices, 0, sizeof(struct acpi_handle_list));
413 status = acpi_evaluate_reference(tz->device->handle, "_PSL",
415 if (ACPI_FAILURE(status)) {
416 printk(KERN_WARNING PREFIX
417 "Invalid passive threshold\n");
418 tz->trips.passive.flags.valid = 0;
421 tz->trips.passive.flags.valid = 1;
423 if (memcmp(&tz->trips.passive.devices, &devices,
424 sizeof(struct acpi_handle_list))) {
425 memcpy(&tz->trips.passive.devices, &devices,
426 sizeof(struct acpi_handle_list));
427 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
430 if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) {
431 if (valid != tz->trips.passive.flags.valid)
432 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
435 /* Active (optional) */
436 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
437 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
438 valid = tz->trips.active[i].flags.valid;
441 break; /* disable all active trip points */
443 if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) &&
444 tz->trips.active[i].flags.valid)) {
445 status = acpi_evaluate_integer(tz->device->handle,
447 if (ACPI_FAILURE(status)) {
448 tz->trips.active[i].flags.valid = 0;
454 tz->trips.active[0].temperature =
455 CELSIUS_TO_KELVIN(act);
458 * Don't allow override higher than
459 * the next higher trip point
461 tz->trips.active[i - 1].temperature =
462 (tz->trips.active[i - 2].temperature <
463 CELSIUS_TO_KELVIN(act) ?
464 tz->trips.active[i - 2].temperature :
465 CELSIUS_TO_KELVIN(act));
468 tz->trips.active[i].temperature = tmp;
469 tz->trips.active[i].flags.valid = 1;
474 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) {
475 memset(&devices, 0, sizeof(struct acpi_handle_list));
476 status = acpi_evaluate_reference(tz->device->handle,
477 name, NULL, &devices);
478 if (ACPI_FAILURE(status)) {
479 printk(KERN_WARNING PREFIX
480 "Invalid active%d threshold\n", i);
481 tz->trips.active[i].flags.valid = 0;
484 tz->trips.active[i].flags.valid = 1;
486 if (memcmp(&tz->trips.active[i].devices, &devices,
487 sizeof(struct acpi_handle_list))) {
488 memcpy(&tz->trips.active[i].devices, &devices,
489 sizeof(struct acpi_handle_list));
490 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
493 if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES))
494 if (valid != tz->trips.active[i].flags.valid)
495 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
497 if (!tz->trips.active[i].flags.valid)
501 if (flag & ACPI_TRIPS_DEVICES) {
502 memset(&devices, 0, sizeof(struct acpi_handle_list));
503 status = acpi_evaluate_reference(tz->device->handle, "_TZD",
505 if (memcmp(&tz->devices, &devices,
506 sizeof(struct acpi_handle_list))) {
507 memcpy(&tz->devices, &devices,
508 sizeof(struct acpi_handle_list));
509 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
516 static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
518 int i, valid, ret = acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
523 valid = tz->trips.critical.flags.valid |
524 tz->trips.hot.flags.valid |
525 tz->trips.passive.flags.valid;
527 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
528 valid |= tz->trips.active[i].flags.valid;
531 printk(KERN_WARNING FW_BUG "No valid trip found\n");
537 static void acpi_thermal_check(void *data)
539 struct acpi_thermal *tz = data;
541 thermal_zone_device_update(tz->thermal_zone);
544 /* sys I/F for generic thermal sysfs support */
545 #define KELVIN_TO_MILLICELSIUS(t, off) (((t) - (off)) * 100)
547 static int thermal_get_temp(struct thermal_zone_device *thermal,
550 struct acpi_thermal *tz = thermal->devdata;
556 result = acpi_thermal_get_temperature(tz);
560 *temp = KELVIN_TO_MILLICELSIUS(tz->temperature, tz->kelvin_offset);
564 static const char enabled[] = "kernel";
565 static const char disabled[] = "user";
566 static int thermal_get_mode(struct thermal_zone_device *thermal,
567 enum thermal_device_mode *mode)
569 struct acpi_thermal *tz = thermal->devdata;
574 *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
575 THERMAL_DEVICE_DISABLED;
580 static int thermal_set_mode(struct thermal_zone_device *thermal,
581 enum thermal_device_mode mode)
583 struct acpi_thermal *tz = thermal->devdata;
590 * enable/disable thermal management from ACPI thermal driver
592 if (mode == THERMAL_DEVICE_ENABLED)
594 else if (mode == THERMAL_DEVICE_DISABLED)
599 if (enable != tz->tz_enabled) {
600 tz->tz_enabled = enable;
601 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
602 "%s ACPI thermal control\n",
603 tz->tz_enabled ? enabled : disabled));
605 acpi_thermal_get_polling_frequency(tz);
607 mutex_lock(&tz->thermal_zone->lock);
608 tz->thermal_zone->polling_delay = tz->polling_frequency*100;
609 tz->thermal_zone->passive_delay = tz->polling_frequency*100;
610 mutex_unlock(&tz->thermal_zone->lock);
612 acpi_thermal_check(tz);
617 static int thermal_get_trip_type(struct thermal_zone_device *thermal,
618 int trip, enum thermal_trip_type *type)
620 struct acpi_thermal *tz = thermal->devdata;
626 if (tz->trips.critical.flags.valid) {
628 *type = THERMAL_TRIP_CRITICAL;
634 if (tz->trips.hot.flags.valid) {
636 *type = THERMAL_TRIP_HOT;
642 if (tz->trips.passive.flags.valid) {
644 *type = THERMAL_TRIP_PASSIVE;
650 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
651 tz->trips.active[i].flags.valid; i++) {
653 *type = THERMAL_TRIP_ACTIVE;
662 static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
663 int trip, unsigned long *temp)
665 struct acpi_thermal *tz = thermal->devdata;
671 if (tz->trips.critical.flags.valid) {
673 *temp = KELVIN_TO_MILLICELSIUS(
674 tz->trips.critical.temperature,
681 if (tz->trips.hot.flags.valid) {
683 *temp = KELVIN_TO_MILLICELSIUS(
684 tz->trips.hot.temperature,
691 if (tz->trips.passive.flags.valid) {
693 *temp = KELVIN_TO_MILLICELSIUS(
694 tz->trips.passive.temperature,
701 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
702 tz->trips.active[i].flags.valid; i++) {
704 *temp = KELVIN_TO_MILLICELSIUS(
705 tz->trips.active[i].temperature,
715 static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
716 unsigned long *temperature) {
717 struct acpi_thermal *tz = thermal->devdata;
719 if (tz->trips.critical.flags.valid) {
720 *temperature = KELVIN_TO_MILLICELSIUS(
721 tz->trips.critical.temperature,
728 static int thermal_notify(struct thermal_zone_device *thermal, int trip,
729 enum thermal_trip_type trip_type)
732 struct acpi_thermal *tz = thermal->devdata;
734 if (trip_type == THERMAL_TRIP_CRITICAL)
735 type = ACPI_THERMAL_NOTIFY_CRITICAL;
736 else if (trip_type == THERMAL_TRIP_HOT)
737 type = ACPI_THERMAL_NOTIFY_HOT;
741 acpi_bus_generate_proc_event(tz->device, type, 1);
742 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
743 dev_name(&tz->device->dev), type, 1);
745 if (trip_type == THERMAL_TRIP_CRITICAL && nocrt)
751 typedef int (*cb)(struct thermal_zone_device *, int,
752 struct thermal_cooling_device *);
753 static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
754 struct thermal_cooling_device *cdev,
757 struct acpi_device *device = cdev->devdata;
758 struct acpi_thermal *tz = thermal->devdata;
759 struct acpi_device *dev;
767 if (tz->trips.critical.flags.valid)
770 if (tz->trips.hot.flags.valid)
773 if (tz->trips.passive.flags.valid) {
775 for (i = 0; i < tz->trips.passive.devices.count;
777 handle = tz->trips.passive.devices.handles[i];
778 status = acpi_bus_get_device(handle, &dev);
779 if (ACPI_SUCCESS(status) && (dev == device)) {
780 result = action(thermal, trip, cdev);
787 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
788 if (!tz->trips.active[i].flags.valid)
792 j < tz->trips.active[i].devices.count;
794 handle = tz->trips.active[i].devices.handles[j];
795 status = acpi_bus_get_device(handle, &dev);
796 if (ACPI_SUCCESS(status) && (dev == device)) {
797 result = action(thermal, trip, cdev);
804 for (i = 0; i < tz->devices.count; i++) {
805 handle = tz->devices.handles[i];
806 status = acpi_bus_get_device(handle, &dev);
807 if (ACPI_SUCCESS(status) && (dev == device)) {
808 result = action(thermal, -1, cdev);
819 acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
820 struct thermal_cooling_device *cdev)
822 return acpi_thermal_cooling_device_cb(thermal, cdev,
823 thermal_zone_bind_cooling_device);
827 acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
828 struct thermal_cooling_device *cdev)
830 return acpi_thermal_cooling_device_cb(thermal, cdev,
831 thermal_zone_unbind_cooling_device);
834 static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
835 .bind = acpi_thermal_bind_cooling_device,
836 .unbind = acpi_thermal_unbind_cooling_device,
837 .get_temp = thermal_get_temp,
838 .get_mode = thermal_get_mode,
839 .set_mode = thermal_set_mode,
840 .get_trip_type = thermal_get_trip_type,
841 .get_trip_temp = thermal_get_trip_temp,
842 .get_crit_temp = thermal_get_crit_temp,
843 .notify = thermal_notify,
846 static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
853 if (tz->trips.critical.flags.valid)
856 if (tz->trips.hot.flags.valid)
859 if (tz->trips.passive.flags.valid)
862 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
863 tz->trips.active[i].flags.valid; i++, trips++);
865 if (tz->trips.passive.flags.valid)
867 thermal_zone_device_register("acpitz", trips, tz,
868 &acpi_thermal_zone_ops,
869 tz->trips.passive.tc1,
870 tz->trips.passive.tc2,
871 tz->trips.passive.tsp*100,
872 tz->polling_frequency*100);
875 thermal_zone_device_register("acpitz", trips, tz,
876 &acpi_thermal_zone_ops,
878 tz->polling_frequency*100);
879 if (IS_ERR(tz->thermal_zone))
882 result = sysfs_create_link(&tz->device->dev.kobj,
883 &tz->thermal_zone->device.kobj, "thermal_zone");
887 result = sysfs_create_link(&tz->thermal_zone->device.kobj,
888 &tz->device->dev.kobj, "device");
892 status = acpi_attach_data(tz->device->handle,
893 acpi_bus_private_data_handler,
895 if (ACPI_FAILURE(status)) {
896 printk(KERN_ERR PREFIX
897 "Error attaching device data\n");
901 dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
902 tz->thermal_zone->id);
906 static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
908 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
909 sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
910 thermal_zone_device_unregister(tz->thermal_zone);
911 tz->thermal_zone = NULL;
912 acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler);
916 /* --------------------------------------------------------------------------
918 -------------------------------------------------------------------------- */
920 static void acpi_thermal_notify(struct acpi_device *device, u32 event)
922 struct acpi_thermal *tz = acpi_driver_data(device);
929 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
930 acpi_thermal_check(tz);
932 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
933 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS);
934 acpi_thermal_check(tz);
935 acpi_bus_generate_proc_event(device, event, 0);
936 acpi_bus_generate_netlink_event(device->pnp.device_class,
937 dev_name(&device->dev), event, 0);
939 case ACPI_THERMAL_NOTIFY_DEVICES:
940 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES);
941 acpi_thermal_check(tz);
942 acpi_bus_generate_proc_event(device, event, 0);
943 acpi_bus_generate_netlink_event(device->pnp.device_class,
944 dev_name(&device->dev), event, 0);
947 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
948 "Unsupported event [0x%x]\n", event));
953 static int acpi_thermal_get_info(struct acpi_thermal *tz)
961 /* Get trip points [_CRT, _PSV, etc.] (required) */
962 result = acpi_thermal_get_trip_points(tz);
966 /* Get temperature [_TMP] (required) */
967 result = acpi_thermal_get_temperature(tz);
971 /* Set the cooling mode [_SCP] to active cooling (default) */
972 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
974 tz->flags.cooling_mode = 1;
976 acpi_thermal_get_polling_frequency(tz);
982 * The exact offset between Kelvin and degree Celsius is 273.15. However ACPI
983 * handles temperature values with a single decimal place. As a consequence,
984 * some implementations use an offset of 273.1 and others use an offset of
985 * 273.2. Try to find out which one is being used, to present the most
986 * accurate and visually appealing number.
988 * The heuristic below should work for all ACPI thermal zones which have a
989 * critical trip point with a value being a multiple of 0.5 degree Celsius.
991 static void acpi_thermal_guess_offset(struct acpi_thermal *tz)
993 if (tz->trips.critical.flags.valid &&
994 (tz->trips.critical.temperature % 5) == 1)
995 tz->kelvin_offset = 2731;
997 tz->kelvin_offset = 2732;
1000 static int acpi_thermal_add(struct acpi_device *device)
1003 struct acpi_thermal *tz = NULL;
1009 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1013 tz->device = device;
1015 strcpy(tz->name, device->pnp.bus_id);
1016 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1017 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
1018 device->driver_data = tz;
1019 mutex_init(&tz->lock);
1022 result = acpi_thermal_get_info(tz);
1026 acpi_thermal_guess_offset(tz);
1028 result = acpi_thermal_register_thermal_zone(tz);
1032 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
1033 acpi_device_name(device), acpi_device_bid(device),
1034 KELVIN_TO_CELSIUS(tz->temperature));
1043 static int acpi_thermal_remove(struct acpi_device *device, int type)
1045 struct acpi_thermal *tz = NULL;
1047 if (!device || !acpi_driver_data(device))
1050 tz = acpi_driver_data(device);
1052 acpi_thermal_unregister_thermal_zone(tz);
1053 mutex_destroy(&tz->lock);
1058 static int acpi_thermal_resume(struct acpi_device *device)
1060 struct acpi_thermal *tz = NULL;
1061 int i, j, power_state, result;
1064 if (!device || !acpi_driver_data(device))
1067 tz = acpi_driver_data(device);
1069 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1070 if (!(&tz->trips.active[i]))
1072 if (!tz->trips.active[i].flags.valid)
1074 tz->trips.active[i].flags.enabled = 1;
1075 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1076 result = acpi_bus_update_power(
1077 tz->trips.active[i].devices.handles[j],
1079 if (result || (power_state != ACPI_STATE_D0)) {
1080 tz->trips.active[i].flags.enabled = 0;
1084 tz->state.active |= tz->trips.active[i].flags.enabled;
1087 acpi_thermal_check(tz);
1092 static int thermal_act(const struct dmi_system_id *d) {
1095 printk(KERN_NOTICE "ACPI: %s detected: "
1096 "disabling all active thermal trip points\n", d->ident);
1101 static int thermal_nocrt(const struct dmi_system_id *d) {
1103 printk(KERN_NOTICE "ACPI: %s detected: "
1104 "disabling all critical thermal trip point actions.\n", d->ident);
1108 static int thermal_tzp(const struct dmi_system_id *d) {
1111 printk(KERN_NOTICE "ACPI: %s detected: "
1112 "enabling thermal zone polling\n", d->ident);
1113 tzp = 300; /* 300 dS = 30 Seconds */
1117 static int thermal_psv(const struct dmi_system_id *d) {
1120 printk(KERN_NOTICE "ACPI: %s detected: "
1121 "disabling all passive thermal trip points\n", d->ident);
1127 static struct dmi_system_id thermal_dmi_table[] __initdata = {
1129 * Award BIOS on this AOpen makes thermal control almost worthless.
1130 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1133 .callback = thermal_act,
1134 .ident = "AOpen i915GMm-HFS",
1136 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1137 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1141 .callback = thermal_psv,
1142 .ident = "AOpen i915GMm-HFS",
1144 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1145 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1149 .callback = thermal_tzp,
1150 .ident = "AOpen i915GMm-HFS",
1152 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1153 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1157 .callback = thermal_nocrt,
1158 .ident = "Gigabyte GA-7ZX",
1160 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
1161 DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
1167 static int __init acpi_thermal_init(void)
1171 dmi_check_system(thermal_dmi_table);
1174 printk(KERN_NOTICE "ACPI: thermal control disabled\n");
1178 result = acpi_bus_register_driver(&acpi_thermal_driver);
1185 static void __exit acpi_thermal_exit(void)
1188 acpi_bus_unregister_driver(&acpi_thermal_driver);
1193 module_init(acpi_thermal_init);
1194 module_exit(acpi_thermal_exit);