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/types.h>
39 #include <linux/proc_fs.h>
40 #include <linux/jiffies.h>
41 #include <linux/kmod.h>
42 #include <linux/seq_file.h>
43 #include <linux/reboot.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 ACPI_THERMAL_CLASS "thermal_zone"
50 #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
51 #define ACPI_THERMAL_FILE_STATE "state"
52 #define ACPI_THERMAL_FILE_TEMPERATURE "temperature"
53 #define ACPI_THERMAL_FILE_TRIP_POINTS "trip_points"
54 #define ACPI_THERMAL_FILE_COOLING_MODE "cooling_mode"
55 #define ACPI_THERMAL_FILE_POLLING_FREQ "polling_frequency"
56 #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80
57 #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81
58 #define ACPI_THERMAL_NOTIFY_DEVICES 0x82
59 #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0
60 #define ACPI_THERMAL_NOTIFY_HOT 0xF1
61 #define ACPI_THERMAL_MODE_ACTIVE 0x00
63 #define ACPI_THERMAL_MAX_ACTIVE 10
64 #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
66 #define _COMPONENT ACPI_THERMAL_COMPONENT
67 ACPI_MODULE_NAME("thermal");
69 MODULE_AUTHOR("Paul Diefenbaugh");
70 MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
71 MODULE_LICENSE("GPL");
74 module_param(act, int, 0644);
75 MODULE_PARM_DESC(act, "Disable or override all lowest active trip points.");
78 module_param(crt, int, 0644);
79 MODULE_PARM_DESC(crt, "Disable or lower all critical trip points.");
82 module_param(tzp, int, 0444);
83 MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.");
86 module_param(nocrt, int, 0);
87 MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points.");
90 module_param(off, int, 0);
91 MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.");
94 module_param(psv, int, 0644);
95 MODULE_PARM_DESC(psv, "Disable or override all passive trip points.");
97 static int acpi_thermal_add(struct acpi_device *device);
98 static int acpi_thermal_remove(struct acpi_device *device, int type);
99 static int acpi_thermal_resume(struct acpi_device *device);
100 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
101 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
102 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
103 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
104 static ssize_t acpi_thermal_write_cooling_mode(struct file *,
105 const char __user *, size_t,
107 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
108 static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
111 static const struct acpi_device_id thermal_device_ids[] = {
112 {ACPI_THERMAL_HID, 0},
115 MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
117 static struct acpi_driver acpi_thermal_driver = {
119 .class = ACPI_THERMAL_CLASS,
120 .ids = thermal_device_ids,
122 .add = acpi_thermal_add,
123 .remove = acpi_thermal_remove,
124 .resume = acpi_thermal_resume,
128 struct acpi_thermal_state {
137 struct acpi_thermal_state_flags {
143 struct acpi_thermal_critical {
144 struct acpi_thermal_state_flags flags;
145 unsigned long temperature;
148 struct acpi_thermal_hot {
149 struct acpi_thermal_state_flags flags;
150 unsigned long temperature;
153 struct acpi_thermal_passive {
154 struct acpi_thermal_state_flags flags;
155 unsigned long temperature;
159 struct acpi_handle_list devices;
162 struct acpi_thermal_active {
163 struct acpi_thermal_state_flags flags;
164 unsigned long temperature;
165 struct acpi_handle_list devices;
168 struct acpi_thermal_trips {
169 struct acpi_thermal_critical critical;
170 struct acpi_thermal_hot hot;
171 struct acpi_thermal_passive passive;
172 struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
175 struct acpi_thermal_flags {
176 u8 cooling_mode:1; /* _SCP */
177 u8 devices:1; /* _TZD */
181 struct acpi_thermal {
182 struct acpi_device * device;
184 unsigned long temperature;
185 unsigned long last_temperature;
186 unsigned long polling_frequency;
188 struct acpi_thermal_flags flags;
189 struct acpi_thermal_state state;
190 struct acpi_thermal_trips trips;
191 struct acpi_handle_list devices;
192 struct thermal_zone_device *thermal_zone;
197 static const struct file_operations acpi_thermal_state_fops = {
198 .owner = THIS_MODULE,
199 .open = acpi_thermal_state_open_fs,
202 .release = single_release,
205 static const struct file_operations acpi_thermal_temp_fops = {
206 .owner = THIS_MODULE,
207 .open = acpi_thermal_temp_open_fs,
210 .release = single_release,
213 static const struct file_operations acpi_thermal_trip_fops = {
214 .owner = THIS_MODULE,
215 .open = acpi_thermal_trip_open_fs,
218 .release = single_release,
221 static const struct file_operations acpi_thermal_cooling_fops = {
222 .owner = THIS_MODULE,
223 .open = acpi_thermal_cooling_open_fs,
225 .write = acpi_thermal_write_cooling_mode,
227 .release = single_release,
230 static const struct file_operations acpi_thermal_polling_fops = {
231 .owner = THIS_MODULE,
232 .open = acpi_thermal_polling_open_fs,
234 .write = acpi_thermal_write_polling,
236 .release = single_release,
239 /* --------------------------------------------------------------------------
240 Thermal Zone Management
241 -------------------------------------------------------------------------- */
243 static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
245 acpi_status status = AE_OK;
246 unsigned long long tmp;
251 tz->last_temperature = tz->temperature;
253 status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp);
254 if (ACPI_FAILURE(status))
257 tz->temperature = tmp;
258 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
264 static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
266 acpi_status status = AE_OK;
267 unsigned long long tmp;
272 status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp);
273 if (ACPI_FAILURE(status))
276 tz->polling_frequency = tmp;
277 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
278 tz->polling_frequency));
283 static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
289 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
291 tz->thermal_zone->polling_delay = seconds * 1000;
294 thermal_zone_device_update(tz->thermal_zone);
296 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
297 "Polling frequency set to %lu seconds\n",
298 tz->polling_frequency/10));
303 static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
305 acpi_status status = AE_OK;
306 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
307 struct acpi_object_list arg_list = { 1, &arg0 };
308 acpi_handle handle = NULL;
314 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
315 if (ACPI_FAILURE(status)) {
316 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
320 arg0.integer.value = mode;
322 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
323 if (ACPI_FAILURE(status))
329 #define ACPI_TRIPS_CRITICAL 0x01
330 #define ACPI_TRIPS_HOT 0x02
331 #define ACPI_TRIPS_PASSIVE 0x04
332 #define ACPI_TRIPS_ACTIVE 0x08
333 #define ACPI_TRIPS_DEVICES 0x10
335 #define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE)
336 #define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES
338 #define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \
339 ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \
343 * This exception is thrown out in two cases:
344 * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
345 * when re-evaluating the AML code.
346 * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change.
347 * We need to re-bind the cooling devices of a thermal zone when this occurs.
349 #define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \
351 if (flags != ACPI_TRIPS_INIT) \
352 ACPI_EXCEPTION((AE_INFO, AE_ERROR, \
353 "ACPI thermal trip point %s changed\n" \
354 "Please send acpidump to linux-acpi@vger.kernel.org\n", str)); \
357 static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
359 acpi_status status = AE_OK;
360 unsigned long long tmp;
361 struct acpi_handle_list devices;
365 /* Critical Shutdown (required) */
366 if (flag & ACPI_TRIPS_CRITICAL) {
367 status = acpi_evaluate_integer(tz->device->handle,
369 tz->trips.critical.temperature = tmp;
371 * Treat freezing temperatures as invalid as well; some
372 * BIOSes return really low values and cause reboots at startup.
373 * Below zero (Celcius) values clearly aren't right for sure..
374 * ... so lets discard those as invalid.
376 if (ACPI_FAILURE(status) ||
377 tz->trips.critical.temperature <= 2732) {
378 tz->trips.critical.flags.valid = 0;
379 ACPI_EXCEPTION((AE_INFO, status,
380 "No or invalid critical threshold"));
383 tz->trips.critical.flags.valid = 1;
384 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
385 "Found critical threshold [%lu]\n",
386 tz->trips.critical.temperature));
388 if (tz->trips.critical.flags.valid == 1) {
390 tz->trips.critical.flags.valid = 0;
391 } else if (crt > 0) {
392 unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
394 * Allow override critical threshold
396 if (crt_k > tz->trips.critical.temperature)
397 printk(KERN_WARNING PREFIX
398 "Critical threshold %d C\n", crt);
399 tz->trips.critical.temperature = crt_k;
404 /* Critical Sleep (optional) */
405 if (flag & ACPI_TRIPS_HOT) {
406 status = acpi_evaluate_integer(tz->device->handle,
408 if (ACPI_FAILURE(status)) {
409 tz->trips.hot.flags.valid = 0;
410 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
411 "No hot threshold\n"));
413 tz->trips.hot.temperature = tmp;
414 tz->trips.hot.flags.valid = 1;
415 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
416 "Found hot threshold [%lu]\n",
417 tz->trips.critical.temperature));
421 /* Passive (optional) */
422 if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) ||
423 (flag == ACPI_TRIPS_INIT)) {
424 valid = tz->trips.passive.flags.valid;
427 } else if (psv > 0) {
428 tmp = CELSIUS_TO_KELVIN(psv);
431 status = acpi_evaluate_integer(tz->device->handle,
435 if (ACPI_FAILURE(status))
436 tz->trips.passive.flags.valid = 0;
438 tz->trips.passive.temperature = tmp;
439 tz->trips.passive.flags.valid = 1;
440 if (flag == ACPI_TRIPS_INIT) {
441 status = acpi_evaluate_integer(
442 tz->device->handle, "_TC1",
444 if (ACPI_FAILURE(status))
445 tz->trips.passive.flags.valid = 0;
447 tz->trips.passive.tc1 = tmp;
448 status = acpi_evaluate_integer(
449 tz->device->handle, "_TC2",
451 if (ACPI_FAILURE(status))
452 tz->trips.passive.flags.valid = 0;
454 tz->trips.passive.tc2 = tmp;
455 status = acpi_evaluate_integer(
456 tz->device->handle, "_TSP",
458 if (ACPI_FAILURE(status))
459 tz->trips.passive.flags.valid = 0;
461 tz->trips.passive.tsp = tmp;
465 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) {
466 memset(&devices, 0, sizeof(struct acpi_handle_list));
467 status = acpi_evaluate_reference(tz->device->handle, "_PSL",
469 if (ACPI_FAILURE(status)) {
470 printk(KERN_WARNING PREFIX
471 "Invalid passive threshold\n");
472 tz->trips.passive.flags.valid = 0;
475 tz->trips.passive.flags.valid = 1;
477 if (memcmp(&tz->trips.passive.devices, &devices,
478 sizeof(struct acpi_handle_list))) {
479 memcpy(&tz->trips.passive.devices, &devices,
480 sizeof(struct acpi_handle_list));
481 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
484 if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) {
485 if (valid != tz->trips.passive.flags.valid)
486 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
489 /* Active (optional) */
490 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
491 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
492 valid = tz->trips.active[i].flags.valid;
495 break; /* disable all active trip points */
497 if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) &&
498 tz->trips.active[i].flags.valid)) {
499 status = acpi_evaluate_integer(tz->device->handle,
501 if (ACPI_FAILURE(status)) {
502 tz->trips.active[i].flags.valid = 0;
508 tz->trips.active[0].temperature =
509 CELSIUS_TO_KELVIN(act);
512 * Don't allow override higher than
513 * the next higher trip point
515 tz->trips.active[i - 1].temperature =
516 (tz->trips.active[i - 2].temperature <
517 CELSIUS_TO_KELVIN(act) ?
518 tz->trips.active[i - 2].temperature :
519 CELSIUS_TO_KELVIN(act));
522 tz->trips.active[i].temperature = tmp;
523 tz->trips.active[i].flags.valid = 1;
528 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) {
529 memset(&devices, 0, sizeof(struct acpi_handle_list));
530 status = acpi_evaluate_reference(tz->device->handle,
531 name, NULL, &devices);
532 if (ACPI_FAILURE(status)) {
533 printk(KERN_WARNING PREFIX
534 "Invalid active%d threshold\n", i);
535 tz->trips.active[i].flags.valid = 0;
538 tz->trips.active[i].flags.valid = 1;
540 if (memcmp(&tz->trips.active[i].devices, &devices,
541 sizeof(struct acpi_handle_list))) {
542 memcpy(&tz->trips.active[i].devices, &devices,
543 sizeof(struct acpi_handle_list));
544 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
547 if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES))
548 if (valid != tz->trips.active[i].flags.valid)
549 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
551 if (!tz->trips.active[i].flags.valid)
555 if (flag & ACPI_TRIPS_DEVICES) {
556 memset(&devices, 0, sizeof(struct acpi_handle_list));
557 status = acpi_evaluate_reference(tz->device->handle, "_TZD",
559 if (memcmp(&tz->devices, &devices,
560 sizeof(struct acpi_handle_list))) {
561 memcpy(&tz->devices, &devices,
562 sizeof(struct acpi_handle_list));
563 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
570 static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
572 return acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
575 static void acpi_thermal_check(void *data)
577 struct acpi_thermal *tz = data;
579 thermal_zone_device_update(tz->thermal_zone);
582 /* sys I/F for generic thermal sysfs support */
583 #define KELVIN_TO_MILLICELSIUS(t) (t * 100 - 273200)
585 static int thermal_get_temp(struct thermal_zone_device *thermal,
588 struct acpi_thermal *tz = thermal->devdata;
594 result = acpi_thermal_get_temperature(tz);
598 *temp = KELVIN_TO_MILLICELSIUS(tz->temperature);
602 static const char enabled[] = "kernel";
603 static const char disabled[] = "user";
604 static int thermal_get_mode(struct thermal_zone_device *thermal,
605 enum thermal_device_mode *mode)
607 struct acpi_thermal *tz = thermal->devdata;
612 *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
613 THERMAL_DEVICE_DISABLED;
618 static int thermal_set_mode(struct thermal_zone_device *thermal,
619 enum thermal_device_mode mode)
621 struct acpi_thermal *tz = thermal->devdata;
628 * enable/disable thermal management from ACPI thermal driver
630 if (mode == THERMAL_DEVICE_ENABLED)
632 else if (mode == THERMAL_DEVICE_DISABLED)
637 if (enable != tz->tz_enabled) {
638 tz->tz_enabled = enable;
639 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
640 "%s ACPI thermal control\n",
641 tz->tz_enabled ? enabled : disabled));
642 acpi_thermal_check(tz);
647 static int thermal_get_trip_type(struct thermal_zone_device *thermal,
648 int trip, enum thermal_trip_type *type)
650 struct acpi_thermal *tz = thermal->devdata;
656 if (tz->trips.critical.flags.valid) {
658 *type = THERMAL_TRIP_CRITICAL;
664 if (tz->trips.hot.flags.valid) {
666 *type = THERMAL_TRIP_HOT;
672 if (tz->trips.passive.flags.valid) {
674 *type = THERMAL_TRIP_PASSIVE;
680 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
681 tz->trips.active[i].flags.valid; i++) {
683 *type = THERMAL_TRIP_ACTIVE;
692 static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
693 int trip, unsigned long *temp)
695 struct acpi_thermal *tz = thermal->devdata;
701 if (tz->trips.critical.flags.valid) {
703 *temp = KELVIN_TO_MILLICELSIUS(
704 tz->trips.critical.temperature);
710 if (tz->trips.hot.flags.valid) {
712 *temp = KELVIN_TO_MILLICELSIUS(
713 tz->trips.hot.temperature);
719 if (tz->trips.passive.flags.valid) {
721 *temp = KELVIN_TO_MILLICELSIUS(
722 tz->trips.passive.temperature);
728 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
729 tz->trips.active[i].flags.valid; i++) {
731 *temp = KELVIN_TO_MILLICELSIUS(
732 tz->trips.active[i].temperature);
741 static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
742 unsigned long *temperature) {
743 struct acpi_thermal *tz = thermal->devdata;
745 if (tz->trips.critical.flags.valid) {
746 *temperature = KELVIN_TO_MILLICELSIUS(
747 tz->trips.critical.temperature);
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_proc_event(tz->device, type, 1);
767 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
768 tz->device->dev.bus_id, type, 1);
770 if (trip_type == THERMAL_TRIP_CRITICAL && nocrt)
776 typedef int (*cb)(struct thermal_zone_device *, int,
777 struct thermal_cooling_device *);
778 static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
779 struct thermal_cooling_device *cdev,
782 struct acpi_device *device = cdev->devdata;
783 struct acpi_thermal *tz = thermal->devdata;
784 struct acpi_device *dev;
792 if (tz->trips.critical.flags.valid)
795 if (tz->trips.hot.flags.valid)
798 if (tz->trips.passive.flags.valid) {
800 for (i = 0; i < tz->trips.passive.devices.count;
802 handle = tz->trips.passive.devices.handles[i];
803 status = acpi_bus_get_device(handle, &dev);
804 if (ACPI_SUCCESS(status) && (dev == device)) {
805 result = action(thermal, trip, cdev);
812 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
813 if (!tz->trips.active[i].flags.valid)
817 j < tz->trips.active[i].devices.count;
819 handle = tz->trips.active[i].devices.handles[j];
820 status = acpi_bus_get_device(handle, &dev);
821 if (ACPI_SUCCESS(status) && (dev == device)) {
822 result = action(thermal, trip, cdev);
829 for (i = 0; i < tz->devices.count; i++) {
830 handle = tz->devices.handles[i];
831 status = acpi_bus_get_device(handle, &dev);
832 if (ACPI_SUCCESS(status) && (dev == device)) {
833 result = action(thermal, -1, cdev);
844 acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
845 struct thermal_cooling_device *cdev)
847 return acpi_thermal_cooling_device_cb(thermal, cdev,
848 thermal_zone_bind_cooling_device);
852 acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
853 struct thermal_cooling_device *cdev)
855 return acpi_thermal_cooling_device_cb(thermal, cdev,
856 thermal_zone_unbind_cooling_device);
859 static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
860 .bind = acpi_thermal_bind_cooling_device,
861 .unbind = acpi_thermal_unbind_cooling_device,
862 .get_temp = thermal_get_temp,
863 .get_mode = thermal_get_mode,
864 .set_mode = thermal_set_mode,
865 .get_trip_type = thermal_get_trip_type,
866 .get_trip_temp = thermal_get_trip_temp,
867 .get_crit_temp = thermal_get_crit_temp,
868 .notify = thermal_notify,
871 static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
878 if (tz->trips.critical.flags.valid)
881 if (tz->trips.hot.flags.valid)
884 if (tz->trips.passive.flags.valid)
887 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
888 tz->trips.active[i].flags.valid; i++, trips++);
890 if (tz->trips.passive.flags.valid)
892 thermal_zone_device_register("acpitz", trips, tz,
893 &acpi_thermal_zone_ops,
894 tz->trips.passive.tc1,
895 tz->trips.passive.tc2,
896 tz->trips.passive.tsp*100,
897 tz->polling_frequency*100);
900 thermal_zone_device_register("acpitz", trips, tz,
901 &acpi_thermal_zone_ops,
903 tz->polling_frequency);
904 if (IS_ERR(tz->thermal_zone))
907 result = sysfs_create_link(&tz->device->dev.kobj,
908 &tz->thermal_zone->device.kobj, "thermal_zone");
912 result = sysfs_create_link(&tz->thermal_zone->device.kobj,
913 &tz->device->dev.kobj, "device");
917 status = acpi_attach_data(tz->device->handle,
918 acpi_bus_private_data_handler,
920 if (ACPI_FAILURE(status)) {
921 printk(KERN_ERR PREFIX
922 "Error attaching device data\n");
928 dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
929 tz->thermal_zone->id);
933 static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
935 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
936 sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
937 thermal_zone_device_unregister(tz->thermal_zone);
938 tz->thermal_zone = NULL;
939 acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler);
943 /* --------------------------------------------------------------------------
945 -------------------------------------------------------------------------- */
947 static struct proc_dir_entry *acpi_thermal_dir;
949 static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
951 struct acpi_thermal *tz = seq->private;
957 seq_puts(seq, "state: ");
959 if (!tz->state.critical && !tz->state.hot && !tz->state.passive
960 && !tz->state.active)
961 seq_puts(seq, "ok\n");
963 if (tz->state.critical)
964 seq_puts(seq, "critical ");
966 seq_puts(seq, "hot ");
967 if (tz->state.passive)
968 seq_puts(seq, "passive ");
969 if (tz->state.active)
970 seq_printf(seq, "active[%d]", tz->state.active_index);
978 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
980 return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
983 static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
986 struct acpi_thermal *tz = seq->private;
992 result = acpi_thermal_get_temperature(tz);
996 seq_printf(seq, "temperature: %ld C\n",
997 KELVIN_TO_CELSIUS(tz->temperature));
1003 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
1005 return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
1008 static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
1010 struct acpi_thermal *tz = seq->private;
1011 struct acpi_device *device;
1021 if (tz->trips.critical.flags.valid)
1022 seq_printf(seq, "critical (S5): %ld C%s",
1023 KELVIN_TO_CELSIUS(tz->trips.critical.temperature),
1024 nocrt ? " <disabled>\n" : "\n");
1026 if (tz->trips.hot.flags.valid)
1027 seq_printf(seq, "hot (S4): %ld C%s",
1028 KELVIN_TO_CELSIUS(tz->trips.hot.temperature),
1029 nocrt ? " <disabled>\n" : "\n");
1031 if (tz->trips.passive.flags.valid) {
1033 "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
1034 KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
1035 tz->trips.passive.tc1, tz->trips.passive.tc2,
1036 tz->trips.passive.tsp);
1037 for (j = 0; j < tz->trips.passive.devices.count; j++) {
1038 status = acpi_bus_get_device(tz->trips.passive.devices.
1039 handles[j], &device);
1040 seq_printf(seq, "%4.4s ", status ? "" :
1041 acpi_device_bid(device));
1043 seq_puts(seq, "\n");
1046 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1047 if (!(tz->trips.active[i].flags.valid))
1049 seq_printf(seq, "active[%d]: %ld C: devices=",
1051 KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
1052 for (j = 0; j < tz->trips.active[i].devices.count; j++){
1053 status = acpi_bus_get_device(tz->trips.active[i].
1056 seq_printf(seq, "%4.4s ", status ? "" :
1057 acpi_device_bid(device));
1059 seq_puts(seq, "\n");
1066 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
1068 return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
1071 static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
1073 struct acpi_thermal *tz = seq->private;
1079 if (!tz->flags.cooling_mode)
1080 seq_puts(seq, "<setting not supported>\n");
1082 seq_puts(seq, "0 - Active; 1 - Passive\n");
1088 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
1090 return single_open(file, acpi_thermal_cooling_seq_show,
1095 acpi_thermal_write_cooling_mode(struct file *file,
1096 const char __user * buffer,
1097 size_t count, loff_t * ppos)
1099 struct seq_file *m = file->private_data;
1100 struct acpi_thermal *tz = m->private;
1102 char mode_string[12] = { '\0' };
1105 if (!tz || (count > sizeof(mode_string) - 1))
1108 if (!tz->flags.cooling_mode)
1111 if (copy_from_user(mode_string, buffer, count))
1114 mode_string[count] = '\0';
1116 result = acpi_thermal_set_cooling_mode(tz,
1117 simple_strtoul(mode_string, NULL,
1122 acpi_thermal_check(tz);
1127 static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
1129 struct acpi_thermal *tz = seq->private;
1135 if (!tz->thermal_zone->polling_delay) {
1136 seq_puts(seq, "<polling disabled>\n");
1140 seq_printf(seq, "polling frequency: %d seconds\n",
1141 (tz->thermal_zone->polling_delay / 1000));
1147 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
1149 return single_open(file, acpi_thermal_polling_seq_show,
1154 acpi_thermal_write_polling(struct file *file,
1155 const char __user * buffer,
1156 size_t count, loff_t * ppos)
1158 struct seq_file *m = file->private_data;
1159 struct acpi_thermal *tz = m->private;
1161 char polling_string[12] = { '\0' };
1165 if (!tz || (count > sizeof(polling_string) - 1))
1168 if (copy_from_user(polling_string, buffer, count))
1171 polling_string[count] = '\0';
1173 seconds = simple_strtoul(polling_string, NULL, 0);
1175 result = acpi_thermal_set_polling(tz, seconds);
1179 acpi_thermal_check(tz);
1184 static int acpi_thermal_add_fs(struct acpi_device *device)
1186 struct proc_dir_entry *entry = NULL;
1189 if (!acpi_device_dir(device)) {
1190 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1192 if (!acpi_device_dir(device))
1194 acpi_device_dir(device)->owner = THIS_MODULE;
1198 entry = proc_create_data(ACPI_THERMAL_FILE_STATE,
1199 S_IRUGO, acpi_device_dir(device),
1200 &acpi_thermal_state_fops,
1201 acpi_driver_data(device));
1205 /* 'temperature' [R] */
1206 entry = proc_create_data(ACPI_THERMAL_FILE_TEMPERATURE,
1207 S_IRUGO, acpi_device_dir(device),
1208 &acpi_thermal_temp_fops,
1209 acpi_driver_data(device));
1213 /* 'trip_points' [R] */
1214 entry = proc_create_data(ACPI_THERMAL_FILE_TRIP_POINTS,
1216 acpi_device_dir(device),
1217 &acpi_thermal_trip_fops,
1218 acpi_driver_data(device));
1222 /* 'cooling_mode' [R/W] */
1223 entry = proc_create_data(ACPI_THERMAL_FILE_COOLING_MODE,
1224 S_IFREG | S_IRUGO | S_IWUSR,
1225 acpi_device_dir(device),
1226 &acpi_thermal_cooling_fops,
1227 acpi_driver_data(device));
1231 /* 'polling_frequency' [R/W] */
1232 entry = proc_create_data(ACPI_THERMAL_FILE_POLLING_FREQ,
1233 S_IFREG | S_IRUGO | S_IWUSR,
1234 acpi_device_dir(device),
1235 &acpi_thermal_polling_fops,
1236 acpi_driver_data(device));
1242 static int acpi_thermal_remove_fs(struct acpi_device *device)
1245 if (acpi_device_dir(device)) {
1246 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1247 acpi_device_dir(device));
1248 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1249 acpi_device_dir(device));
1250 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1251 acpi_device_dir(device));
1252 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1253 acpi_device_dir(device));
1254 remove_proc_entry(ACPI_THERMAL_FILE_STATE,
1255 acpi_device_dir(device));
1256 remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
1257 acpi_device_dir(device) = NULL;
1263 /* --------------------------------------------------------------------------
1265 -------------------------------------------------------------------------- */
1267 static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
1269 struct acpi_thermal *tz = data;
1270 struct acpi_device *device = NULL;
1276 device = tz->device;
1279 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
1280 acpi_thermal_check(tz);
1282 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
1283 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS);
1284 acpi_thermal_check(tz);
1285 acpi_bus_generate_proc_event(device, event, 0);
1286 acpi_bus_generate_netlink_event(device->pnp.device_class,
1287 dev_name(&device->dev), event, 0);
1289 case ACPI_THERMAL_NOTIFY_DEVICES:
1290 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES);
1291 acpi_thermal_check(tz);
1292 acpi_bus_generate_proc_event(device, event, 0);
1293 acpi_bus_generate_netlink_event(device->pnp.device_class,
1294 dev_name(&device->dev), event, 0);
1297 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1298 "Unsupported event [0x%x]\n", event));
1305 static int acpi_thermal_get_info(struct acpi_thermal *tz)
1313 /* Get temperature [_TMP] (required) */
1314 result = acpi_thermal_get_temperature(tz);
1318 /* Get trip points [_CRT, _PSV, etc.] (required) */
1319 result = acpi_thermal_get_trip_points(tz);
1323 /* Set the cooling mode [_SCP] to active cooling (default) */
1324 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
1326 tz->flags.cooling_mode = 1;
1328 /* Get default polling frequency [_TZP] (optional) */
1330 tz->polling_frequency = tzp;
1332 acpi_thermal_get_polling_frequency(tz);
1337 static int acpi_thermal_add(struct acpi_device *device)
1340 acpi_status status = AE_OK;
1341 struct acpi_thermal *tz = NULL;
1347 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1351 tz->device = device;
1352 strcpy(tz->name, device->pnp.bus_id);
1353 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1354 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
1355 device->driver_data = tz;
1356 mutex_init(&tz->lock);
1359 result = acpi_thermal_get_info(tz);
1363 result = acpi_thermal_register_thermal_zone(tz);
1367 result = acpi_thermal_add_fs(device);
1369 goto unregister_thermal_zone;
1371 status = acpi_install_notify_handler(device->handle,
1373 acpi_thermal_notify, tz);
1374 if (ACPI_FAILURE(status)) {
1379 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
1380 acpi_device_name(device), acpi_device_bid(device),
1381 KELVIN_TO_CELSIUS(tz->temperature));
1385 acpi_thermal_remove_fs(device);
1386 unregister_thermal_zone:
1387 thermal_zone_device_unregister(tz->thermal_zone);
1394 static int acpi_thermal_remove(struct acpi_device *device, int type)
1396 acpi_status status = AE_OK;
1397 struct acpi_thermal *tz = NULL;
1399 if (!device || !acpi_driver_data(device))
1402 tz = acpi_driver_data(device);
1404 status = acpi_remove_notify_handler(device->handle,
1406 acpi_thermal_notify);
1408 acpi_thermal_remove_fs(device);
1409 acpi_thermal_unregister_thermal_zone(tz);
1410 mutex_destroy(&tz->lock);
1415 static int acpi_thermal_resume(struct acpi_device *device)
1417 struct acpi_thermal *tz = NULL;
1418 int i, j, power_state, result;
1421 if (!device || !acpi_driver_data(device))
1424 tz = acpi_driver_data(device);
1426 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1427 if (!(&tz->trips.active[i]))
1429 if (!tz->trips.active[i].flags.valid)
1431 tz->trips.active[i].flags.enabled = 1;
1432 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1433 result = acpi_bus_get_power(tz->trips.active[i].devices.
1434 handles[j], &power_state);
1435 if (result || (power_state != ACPI_STATE_D0)) {
1436 tz->trips.active[i].flags.enabled = 0;
1440 tz->state.active |= tz->trips.active[i].flags.enabled;
1443 acpi_thermal_check(tz);
1448 static int thermal_act(const struct dmi_system_id *d) {
1451 printk(KERN_NOTICE "ACPI: %s detected: "
1452 "disabling all active thermal trip points\n", d->ident);
1457 static int thermal_nocrt(const struct dmi_system_id *d) {
1459 printk(KERN_NOTICE "ACPI: %s detected: "
1460 "disabling all critical thermal trip point actions.\n", d->ident);
1464 static int thermal_tzp(const struct dmi_system_id *d) {
1467 printk(KERN_NOTICE "ACPI: %s detected: "
1468 "enabling thermal zone polling\n", d->ident);
1469 tzp = 300; /* 300 dS = 30 Seconds */
1473 static int thermal_psv(const struct dmi_system_id *d) {
1476 printk(KERN_NOTICE "ACPI: %s detected: "
1477 "disabling all passive thermal trip points\n", d->ident);
1483 static struct dmi_system_id thermal_dmi_table[] __initdata = {
1485 * Award BIOS on this AOpen makes thermal control almost worthless.
1486 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1489 .callback = thermal_act,
1490 .ident = "AOpen i915GMm-HFS",
1492 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1493 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1497 .callback = thermal_psv,
1498 .ident = "AOpen i915GMm-HFS",
1500 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1501 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1505 .callback = thermal_tzp,
1506 .ident = "AOpen i915GMm-HFS",
1508 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1509 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1513 .callback = thermal_nocrt,
1514 .ident = "Gigabyte GA-7ZX",
1516 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
1517 DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
1523 static int __init acpi_thermal_init(void)
1527 dmi_check_system(thermal_dmi_table);
1530 printk(KERN_NOTICE "ACPI: thermal control disabled\n");
1533 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
1534 if (!acpi_thermal_dir)
1536 acpi_thermal_dir->owner = THIS_MODULE;
1538 result = acpi_bus_register_driver(&acpi_thermal_driver);
1540 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1547 static void __exit acpi_thermal_exit(void)
1550 acpi_bus_unregister_driver(&acpi_thermal_driver);
1552 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1557 module_init(acpi_thermal_init);
1558 module_exit(acpi_thermal_exit);