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 <linux/device.h>
45 #include <asm/uaccess.h>
46 #include <linux/thermal.h>
47 #include <acpi/acpi_bus.h>
48 #include <acpi/acpi_drivers.h>
50 #define ACPI_THERMAL_CLASS "thermal_zone"
51 #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
52 #define ACPI_THERMAL_FILE_STATE "state"
53 #define ACPI_THERMAL_FILE_TEMPERATURE "temperature"
54 #define ACPI_THERMAL_FILE_TRIP_POINTS "trip_points"
55 #define ACPI_THERMAL_FILE_COOLING_MODE "cooling_mode"
56 #define ACPI_THERMAL_FILE_POLLING_FREQ "polling_frequency"
57 #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80
58 #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81
59 #define ACPI_THERMAL_NOTIFY_DEVICES 0x82
60 #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0
61 #define ACPI_THERMAL_NOTIFY_HOT 0xF1
62 #define ACPI_THERMAL_MODE_ACTIVE 0x00
64 #define ACPI_THERMAL_MAX_ACTIVE 10
65 #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
67 #define _COMPONENT ACPI_THERMAL_COMPONENT
68 ACPI_MODULE_NAME("thermal");
70 MODULE_AUTHOR("Paul Diefenbaugh");
71 MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
72 MODULE_LICENSE("GPL");
75 module_param(act, int, 0644);
76 MODULE_PARM_DESC(act, "Disable or override all lowest active trip points.");
79 module_param(crt, int, 0644);
80 MODULE_PARM_DESC(crt, "Disable or lower all critical trip points.");
83 module_param(tzp, int, 0444);
84 MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.");
87 module_param(nocrt, int, 0);
88 MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points.");
91 module_param(off, int, 0);
92 MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.");
95 module_param(psv, int, 0644);
96 MODULE_PARM_DESC(psv, "Disable or override all passive trip points.");
98 static int acpi_thermal_add(struct acpi_device *device);
99 static int acpi_thermal_remove(struct acpi_device *device, int type);
100 static int acpi_thermal_resume(struct acpi_device *device);
101 static void acpi_thermal_notify(struct acpi_device *device, u32 event);
102 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
103 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
104 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
105 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
106 static ssize_t acpi_thermal_write_cooling_mode(struct file *,
107 const char __user *, size_t,
109 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
110 static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
113 static const struct acpi_device_id thermal_device_ids[] = {
114 {ACPI_THERMAL_HID, 0},
117 MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
119 static struct acpi_driver acpi_thermal_driver = {
121 .class = ACPI_THERMAL_CLASS,
122 .ids = thermal_device_ids,
124 .add = acpi_thermal_add,
125 .remove = acpi_thermal_remove,
126 .resume = acpi_thermal_resume,
127 .notify = acpi_thermal_notify,
131 struct acpi_thermal_state {
140 struct acpi_thermal_state_flags {
146 struct acpi_thermal_critical {
147 struct acpi_thermal_state_flags flags;
148 unsigned long temperature;
151 struct acpi_thermal_hot {
152 struct acpi_thermal_state_flags flags;
153 unsigned long temperature;
156 struct acpi_thermal_passive {
157 struct acpi_thermal_state_flags flags;
158 unsigned long temperature;
162 struct acpi_handle_list devices;
165 struct acpi_thermal_active {
166 struct acpi_thermal_state_flags flags;
167 unsigned long temperature;
168 struct acpi_handle_list devices;
171 struct acpi_thermal_trips {
172 struct acpi_thermal_critical critical;
173 struct acpi_thermal_hot hot;
174 struct acpi_thermal_passive passive;
175 struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
178 struct acpi_thermal_flags {
179 u8 cooling_mode:1; /* _SCP */
180 u8 devices:1; /* _TZD */
184 struct acpi_thermal {
185 struct acpi_device * device;
187 unsigned long temperature;
188 unsigned long last_temperature;
189 unsigned long polling_frequency;
191 struct acpi_thermal_flags flags;
192 struct acpi_thermal_state state;
193 struct acpi_thermal_trips trips;
194 struct acpi_handle_list devices;
195 struct thermal_zone_device *thermal_zone;
200 static const struct file_operations acpi_thermal_state_fops = {
201 .owner = THIS_MODULE,
202 .open = acpi_thermal_state_open_fs,
205 .release = single_release,
208 static const struct file_operations acpi_thermal_temp_fops = {
209 .owner = THIS_MODULE,
210 .open = acpi_thermal_temp_open_fs,
213 .release = single_release,
216 static const struct file_operations acpi_thermal_trip_fops = {
217 .owner = THIS_MODULE,
218 .open = acpi_thermal_trip_open_fs,
221 .release = single_release,
224 static const struct file_operations acpi_thermal_cooling_fops = {
225 .owner = THIS_MODULE,
226 .open = acpi_thermal_cooling_open_fs,
228 .write = acpi_thermal_write_cooling_mode,
230 .release = single_release,
233 static const struct file_operations acpi_thermal_polling_fops = {
234 .owner = THIS_MODULE,
235 .open = acpi_thermal_polling_open_fs,
237 .write = acpi_thermal_write_polling,
239 .release = single_release,
242 /* --------------------------------------------------------------------------
243 Thermal Zone Management
244 -------------------------------------------------------------------------- */
246 static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
248 acpi_status status = AE_OK;
249 unsigned long long tmp;
254 tz->last_temperature = tz->temperature;
256 status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp);
257 if (ACPI_FAILURE(status))
260 tz->temperature = tmp;
261 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
267 static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
269 acpi_status status = AE_OK;
270 unsigned long long tmp;
275 status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp);
276 if (ACPI_FAILURE(status))
279 tz->polling_frequency = tmp;
280 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
281 tz->polling_frequency));
286 static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
292 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
294 tz->thermal_zone->polling_delay = seconds * 1000;
297 thermal_zone_device_update(tz->thermal_zone);
299 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
300 "Polling frequency set to %lu seconds\n",
301 tz->polling_frequency/10));
306 static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
308 acpi_status status = AE_OK;
309 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
310 struct acpi_object_list arg_list = { 1, &arg0 };
311 acpi_handle handle = NULL;
317 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
318 if (ACPI_FAILURE(status)) {
319 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
323 arg0.integer.value = mode;
325 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
326 if (ACPI_FAILURE(status))
332 #define ACPI_TRIPS_CRITICAL 0x01
333 #define ACPI_TRIPS_HOT 0x02
334 #define ACPI_TRIPS_PASSIVE 0x04
335 #define ACPI_TRIPS_ACTIVE 0x08
336 #define ACPI_TRIPS_DEVICES 0x10
338 #define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE)
339 #define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES
341 #define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \
342 ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \
346 * This exception is thrown out in two cases:
347 * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
348 * when re-evaluating the AML code.
349 * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change.
350 * We need to re-bind the cooling devices of a thermal zone when this occurs.
352 #define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \
354 if (flags != ACPI_TRIPS_INIT) \
355 ACPI_EXCEPTION((AE_INFO, AE_ERROR, \
356 "ACPI thermal trip point %s changed\n" \
357 "Please send acpidump to linux-acpi@vger.kernel.org\n", str)); \
360 static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
362 acpi_status status = AE_OK;
363 unsigned long long tmp;
364 struct acpi_handle_list devices;
368 /* Critical Shutdown (required) */
369 if (flag & ACPI_TRIPS_CRITICAL) {
370 status = acpi_evaluate_integer(tz->device->handle,
372 tz->trips.critical.temperature = tmp;
374 * Treat freezing temperatures as invalid as well; some
375 * BIOSes return really low values and cause reboots at startup.
376 * Below zero (Celsius) values clearly aren't right for sure..
377 * ... so lets discard those as invalid.
379 if (ACPI_FAILURE(status) ||
380 tz->trips.critical.temperature <= 2732) {
381 tz->trips.critical.flags.valid = 0;
382 ACPI_EXCEPTION((AE_INFO, status,
383 "No or invalid critical threshold"));
386 tz->trips.critical.flags.valid = 1;
387 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
388 "Found critical threshold [%lu]\n",
389 tz->trips.critical.temperature));
391 if (tz->trips.critical.flags.valid == 1) {
393 tz->trips.critical.flags.valid = 0;
394 } else if (crt > 0) {
395 unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
397 * Allow override critical threshold
399 if (crt_k > tz->trips.critical.temperature)
400 printk(KERN_WARNING PREFIX
401 "Critical threshold %d C\n", crt);
402 tz->trips.critical.temperature = crt_k;
407 /* Critical Sleep (optional) */
408 if (flag & ACPI_TRIPS_HOT) {
409 status = acpi_evaluate_integer(tz->device->handle,
411 if (ACPI_FAILURE(status)) {
412 tz->trips.hot.flags.valid = 0;
413 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
414 "No hot threshold\n"));
416 tz->trips.hot.temperature = tmp;
417 tz->trips.hot.flags.valid = 1;
418 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
419 "Found hot threshold [%lu]\n",
420 tz->trips.critical.temperature));
424 /* Passive (optional) */
425 if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) ||
426 (flag == ACPI_TRIPS_INIT)) {
427 valid = tz->trips.passive.flags.valid;
430 } else if (psv > 0) {
431 tmp = CELSIUS_TO_KELVIN(psv);
434 status = acpi_evaluate_integer(tz->device->handle,
438 if (ACPI_FAILURE(status))
439 tz->trips.passive.flags.valid = 0;
441 tz->trips.passive.temperature = tmp;
442 tz->trips.passive.flags.valid = 1;
443 if (flag == ACPI_TRIPS_INIT) {
444 status = acpi_evaluate_integer(
445 tz->device->handle, "_TC1",
447 if (ACPI_FAILURE(status))
448 tz->trips.passive.flags.valid = 0;
450 tz->trips.passive.tc1 = tmp;
451 status = acpi_evaluate_integer(
452 tz->device->handle, "_TC2",
454 if (ACPI_FAILURE(status))
455 tz->trips.passive.flags.valid = 0;
457 tz->trips.passive.tc2 = tmp;
458 status = acpi_evaluate_integer(
459 tz->device->handle, "_TSP",
461 if (ACPI_FAILURE(status))
462 tz->trips.passive.flags.valid = 0;
464 tz->trips.passive.tsp = tmp;
468 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) {
469 memset(&devices, 0, sizeof(struct acpi_handle_list));
470 status = acpi_evaluate_reference(tz->device->handle, "_PSL",
472 if (ACPI_FAILURE(status)) {
473 printk(KERN_WARNING PREFIX
474 "Invalid passive threshold\n");
475 tz->trips.passive.flags.valid = 0;
478 tz->trips.passive.flags.valid = 1;
480 if (memcmp(&tz->trips.passive.devices, &devices,
481 sizeof(struct acpi_handle_list))) {
482 memcpy(&tz->trips.passive.devices, &devices,
483 sizeof(struct acpi_handle_list));
484 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
487 if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) {
488 if (valid != tz->trips.passive.flags.valid)
489 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
492 /* Active (optional) */
493 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
494 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
495 valid = tz->trips.active[i].flags.valid;
498 break; /* disable all active trip points */
500 if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) &&
501 tz->trips.active[i].flags.valid)) {
502 status = acpi_evaluate_integer(tz->device->handle,
504 if (ACPI_FAILURE(status)) {
505 tz->trips.active[i].flags.valid = 0;
511 tz->trips.active[0].temperature =
512 CELSIUS_TO_KELVIN(act);
515 * Don't allow override higher than
516 * the next higher trip point
518 tz->trips.active[i - 1].temperature =
519 (tz->trips.active[i - 2].temperature <
520 CELSIUS_TO_KELVIN(act) ?
521 tz->trips.active[i - 2].temperature :
522 CELSIUS_TO_KELVIN(act));
525 tz->trips.active[i].temperature = tmp;
526 tz->trips.active[i].flags.valid = 1;
531 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) {
532 memset(&devices, 0, sizeof(struct acpi_handle_list));
533 status = acpi_evaluate_reference(tz->device->handle,
534 name, NULL, &devices);
535 if (ACPI_FAILURE(status)) {
536 printk(KERN_WARNING PREFIX
537 "Invalid active%d threshold\n", i);
538 tz->trips.active[i].flags.valid = 0;
541 tz->trips.active[i].flags.valid = 1;
543 if (memcmp(&tz->trips.active[i].devices, &devices,
544 sizeof(struct acpi_handle_list))) {
545 memcpy(&tz->trips.active[i].devices, &devices,
546 sizeof(struct acpi_handle_list));
547 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
550 if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES))
551 if (valid != tz->trips.active[i].flags.valid)
552 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
554 if (!tz->trips.active[i].flags.valid)
558 if (flag & ACPI_TRIPS_DEVICES) {
559 memset(&devices, 0, sizeof(struct acpi_handle_list));
560 status = acpi_evaluate_reference(tz->device->handle, "_TZD",
562 if (memcmp(&tz->devices, &devices,
563 sizeof(struct acpi_handle_list))) {
564 memcpy(&tz->devices, &devices,
565 sizeof(struct acpi_handle_list));
566 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
573 static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
575 return acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
578 static void acpi_thermal_check(void *data)
580 struct acpi_thermal *tz = data;
582 thermal_zone_device_update(tz->thermal_zone);
585 /* sys I/F for generic thermal sysfs support */
586 #define KELVIN_TO_MILLICELSIUS(t) (t * 100 - 273200)
588 static int thermal_get_temp(struct thermal_zone_device *thermal,
591 struct acpi_thermal *tz = thermal->devdata;
597 result = acpi_thermal_get_temperature(tz);
601 *temp = KELVIN_TO_MILLICELSIUS(tz->temperature);
605 static const char enabled[] = "kernel";
606 static const char disabled[] = "user";
607 static int thermal_get_mode(struct thermal_zone_device *thermal,
608 enum thermal_device_mode *mode)
610 struct acpi_thermal *tz = thermal->devdata;
615 *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
616 THERMAL_DEVICE_DISABLED;
621 static int thermal_set_mode(struct thermal_zone_device *thermal,
622 enum thermal_device_mode mode)
624 struct acpi_thermal *tz = thermal->devdata;
631 * enable/disable thermal management from ACPI thermal driver
633 if (mode == THERMAL_DEVICE_ENABLED)
635 else if (mode == THERMAL_DEVICE_DISABLED)
640 if (enable != tz->tz_enabled) {
641 tz->tz_enabled = enable;
642 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
643 "%s ACPI thermal control\n",
644 tz->tz_enabled ? enabled : disabled));
645 acpi_thermal_check(tz);
650 static int thermal_get_trip_type(struct thermal_zone_device *thermal,
651 int trip, enum thermal_trip_type *type)
653 struct acpi_thermal *tz = thermal->devdata;
659 if (tz->trips.critical.flags.valid) {
661 *type = THERMAL_TRIP_CRITICAL;
667 if (tz->trips.hot.flags.valid) {
669 *type = THERMAL_TRIP_HOT;
675 if (tz->trips.passive.flags.valid) {
677 *type = THERMAL_TRIP_PASSIVE;
683 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
684 tz->trips.active[i].flags.valid; i++) {
686 *type = THERMAL_TRIP_ACTIVE;
695 static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
696 int trip, unsigned long *temp)
698 struct acpi_thermal *tz = thermal->devdata;
704 if (tz->trips.critical.flags.valid) {
706 *temp = KELVIN_TO_MILLICELSIUS(
707 tz->trips.critical.temperature);
713 if (tz->trips.hot.flags.valid) {
715 *temp = KELVIN_TO_MILLICELSIUS(
716 tz->trips.hot.temperature);
722 if (tz->trips.passive.flags.valid) {
724 *temp = KELVIN_TO_MILLICELSIUS(
725 tz->trips.passive.temperature);
731 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
732 tz->trips.active[i].flags.valid; i++) {
734 *temp = KELVIN_TO_MILLICELSIUS(
735 tz->trips.active[i].temperature);
744 static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
745 unsigned long *temperature) {
746 struct acpi_thermal *tz = thermal->devdata;
748 if (tz->trips.critical.flags.valid) {
749 *temperature = KELVIN_TO_MILLICELSIUS(
750 tz->trips.critical.temperature);
756 static int thermal_notify(struct thermal_zone_device *thermal, int trip,
757 enum thermal_trip_type trip_type)
760 struct acpi_thermal *tz = thermal->devdata;
762 if (trip_type == THERMAL_TRIP_CRITICAL)
763 type = ACPI_THERMAL_NOTIFY_CRITICAL;
764 else if (trip_type == THERMAL_TRIP_HOT)
765 type = ACPI_THERMAL_NOTIFY_HOT;
769 acpi_bus_generate_proc_event(tz->device, type, 1);
770 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
771 dev_name(&tz->device->dev), type, 1);
773 if (trip_type == THERMAL_TRIP_CRITICAL && nocrt)
779 typedef int (*cb)(struct thermal_zone_device *, int,
780 struct thermal_cooling_device *);
781 static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
782 struct thermal_cooling_device *cdev,
785 struct acpi_device *device = cdev->devdata;
786 struct acpi_thermal *tz = thermal->devdata;
787 struct acpi_device *dev;
795 if (tz->trips.critical.flags.valid)
798 if (tz->trips.hot.flags.valid)
801 if (tz->trips.passive.flags.valid) {
803 for (i = 0; i < tz->trips.passive.devices.count;
805 handle = tz->trips.passive.devices.handles[i];
806 status = acpi_bus_get_device(handle, &dev);
807 if (ACPI_SUCCESS(status) && (dev == device)) {
808 result = action(thermal, trip, cdev);
815 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
816 if (!tz->trips.active[i].flags.valid)
820 j < tz->trips.active[i].devices.count;
822 handle = tz->trips.active[i].devices.handles[j];
823 status = acpi_bus_get_device(handle, &dev);
824 if (ACPI_SUCCESS(status) && (dev == device)) {
825 result = action(thermal, trip, cdev);
832 for (i = 0; i < tz->devices.count; i++) {
833 handle = tz->devices.handles[i];
834 status = acpi_bus_get_device(handle, &dev);
835 if (ACPI_SUCCESS(status) && (dev == device)) {
836 result = action(thermal, -1, cdev);
847 acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
848 struct thermal_cooling_device *cdev)
850 return acpi_thermal_cooling_device_cb(thermal, cdev,
851 thermal_zone_bind_cooling_device);
855 acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
856 struct thermal_cooling_device *cdev)
858 return acpi_thermal_cooling_device_cb(thermal, cdev,
859 thermal_zone_unbind_cooling_device);
862 static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
863 .bind = acpi_thermal_bind_cooling_device,
864 .unbind = acpi_thermal_unbind_cooling_device,
865 .get_temp = thermal_get_temp,
866 .get_mode = thermal_get_mode,
867 .set_mode = thermal_set_mode,
868 .get_trip_type = thermal_get_trip_type,
869 .get_trip_temp = thermal_get_trip_temp,
870 .get_crit_temp = thermal_get_crit_temp,
871 .notify = thermal_notify,
874 static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
881 if (tz->trips.critical.flags.valid)
884 if (tz->trips.hot.flags.valid)
887 if (tz->trips.passive.flags.valid)
890 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
891 tz->trips.active[i].flags.valid; i++, trips++);
893 if (tz->trips.passive.flags.valid)
895 thermal_zone_device_register("acpitz", trips, tz,
896 &acpi_thermal_zone_ops,
897 tz->trips.passive.tc1,
898 tz->trips.passive.tc2,
899 tz->trips.passive.tsp*100,
900 tz->polling_frequency*100);
903 thermal_zone_device_register("acpitz", trips, tz,
904 &acpi_thermal_zone_ops,
906 tz->polling_frequency);
907 if (IS_ERR(tz->thermal_zone))
910 result = sysfs_create_link(&tz->device->dev.kobj,
911 &tz->thermal_zone->device.kobj, "thermal_zone");
915 result = sysfs_create_link(&tz->thermal_zone->device.kobj,
916 &tz->device->dev.kobj, "device");
920 status = acpi_attach_data(tz->device->handle,
921 acpi_bus_private_data_handler,
923 if (ACPI_FAILURE(status)) {
924 printk(KERN_ERR PREFIX
925 "Error attaching device data\n");
931 dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
932 tz->thermal_zone->id);
936 static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
938 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
939 sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
940 thermal_zone_device_unregister(tz->thermal_zone);
941 tz->thermal_zone = NULL;
942 acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler);
946 /* --------------------------------------------------------------------------
948 -------------------------------------------------------------------------- */
950 static struct proc_dir_entry *acpi_thermal_dir;
952 static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
954 struct acpi_thermal *tz = seq->private;
960 seq_puts(seq, "state: ");
962 if (!tz->state.critical && !tz->state.hot && !tz->state.passive
963 && !tz->state.active)
964 seq_puts(seq, "ok\n");
966 if (tz->state.critical)
967 seq_puts(seq, "critical ");
969 seq_puts(seq, "hot ");
970 if (tz->state.passive)
971 seq_puts(seq, "passive ");
972 if (tz->state.active)
973 seq_printf(seq, "active[%d]", tz->state.active_index);
981 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
983 return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
986 static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
989 struct acpi_thermal *tz = seq->private;
995 result = acpi_thermal_get_temperature(tz);
999 seq_printf(seq, "temperature: %ld C\n",
1000 KELVIN_TO_CELSIUS(tz->temperature));
1006 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
1008 return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
1011 static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
1013 struct acpi_thermal *tz = seq->private;
1014 struct acpi_device *device;
1024 if (tz->trips.critical.flags.valid)
1025 seq_printf(seq, "critical (S5): %ld C%s",
1026 KELVIN_TO_CELSIUS(tz->trips.critical.temperature),
1027 nocrt ? " <disabled>\n" : "\n");
1029 if (tz->trips.hot.flags.valid)
1030 seq_printf(seq, "hot (S4): %ld C%s",
1031 KELVIN_TO_CELSIUS(tz->trips.hot.temperature),
1032 nocrt ? " <disabled>\n" : "\n");
1034 if (tz->trips.passive.flags.valid) {
1036 "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
1037 KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
1038 tz->trips.passive.tc1, tz->trips.passive.tc2,
1039 tz->trips.passive.tsp);
1040 for (j = 0; j < tz->trips.passive.devices.count; j++) {
1041 status = acpi_bus_get_device(tz->trips.passive.devices.
1042 handles[j], &device);
1043 seq_printf(seq, "%4.4s ", status ? "" :
1044 acpi_device_bid(device));
1046 seq_puts(seq, "\n");
1049 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1050 if (!(tz->trips.active[i].flags.valid))
1052 seq_printf(seq, "active[%d]: %ld C: devices=",
1054 KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
1055 for (j = 0; j < tz->trips.active[i].devices.count; j++){
1056 status = acpi_bus_get_device(tz->trips.active[i].
1059 seq_printf(seq, "%4.4s ", status ? "" :
1060 acpi_device_bid(device));
1062 seq_puts(seq, "\n");
1069 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
1071 return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
1074 static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
1076 struct acpi_thermal *tz = seq->private;
1082 if (!tz->flags.cooling_mode)
1083 seq_puts(seq, "<setting not supported>\n");
1085 seq_puts(seq, "0 - Active; 1 - Passive\n");
1091 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
1093 return single_open(file, acpi_thermal_cooling_seq_show,
1098 acpi_thermal_write_cooling_mode(struct file *file,
1099 const char __user * buffer,
1100 size_t count, loff_t * ppos)
1102 struct seq_file *m = file->private_data;
1103 struct acpi_thermal *tz = m->private;
1105 char mode_string[12] = { '\0' };
1108 if (!tz || (count > sizeof(mode_string) - 1))
1111 if (!tz->flags.cooling_mode)
1114 if (copy_from_user(mode_string, buffer, count))
1117 mode_string[count] = '\0';
1119 result = acpi_thermal_set_cooling_mode(tz,
1120 simple_strtoul(mode_string, NULL,
1125 acpi_thermal_check(tz);
1130 static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
1132 struct acpi_thermal *tz = seq->private;
1138 if (!tz->thermal_zone->polling_delay) {
1139 seq_puts(seq, "<polling disabled>\n");
1143 seq_printf(seq, "polling frequency: %d seconds\n",
1144 (tz->thermal_zone->polling_delay / 1000));
1150 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
1152 return single_open(file, acpi_thermal_polling_seq_show,
1157 acpi_thermal_write_polling(struct file *file,
1158 const char __user * buffer,
1159 size_t count, loff_t * ppos)
1161 struct seq_file *m = file->private_data;
1162 struct acpi_thermal *tz = m->private;
1164 char polling_string[12] = { '\0' };
1168 if (!tz || (count > sizeof(polling_string) - 1))
1171 if (copy_from_user(polling_string, buffer, count))
1174 polling_string[count] = '\0';
1176 seconds = simple_strtoul(polling_string, NULL, 0);
1178 result = acpi_thermal_set_polling(tz, seconds);
1182 acpi_thermal_check(tz);
1187 static int acpi_thermal_add_fs(struct acpi_device *device)
1189 struct proc_dir_entry *entry = NULL;
1192 if (!acpi_device_dir(device)) {
1193 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1195 if (!acpi_device_dir(device))
1200 entry = proc_create_data(ACPI_THERMAL_FILE_STATE,
1201 S_IRUGO, acpi_device_dir(device),
1202 &acpi_thermal_state_fops,
1203 acpi_driver_data(device));
1207 /* 'temperature' [R] */
1208 entry = proc_create_data(ACPI_THERMAL_FILE_TEMPERATURE,
1209 S_IRUGO, acpi_device_dir(device),
1210 &acpi_thermal_temp_fops,
1211 acpi_driver_data(device));
1215 /* 'trip_points' [R] */
1216 entry = proc_create_data(ACPI_THERMAL_FILE_TRIP_POINTS,
1218 acpi_device_dir(device),
1219 &acpi_thermal_trip_fops,
1220 acpi_driver_data(device));
1224 /* 'cooling_mode' [R/W] */
1225 entry = proc_create_data(ACPI_THERMAL_FILE_COOLING_MODE,
1226 S_IFREG | S_IRUGO | S_IWUSR,
1227 acpi_device_dir(device),
1228 &acpi_thermal_cooling_fops,
1229 acpi_driver_data(device));
1233 /* 'polling_frequency' [R/W] */
1234 entry = proc_create_data(ACPI_THERMAL_FILE_POLLING_FREQ,
1235 S_IFREG | S_IRUGO | S_IWUSR,
1236 acpi_device_dir(device),
1237 &acpi_thermal_polling_fops,
1238 acpi_driver_data(device));
1244 static int acpi_thermal_remove_fs(struct acpi_device *device)
1247 if (acpi_device_dir(device)) {
1248 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1249 acpi_device_dir(device));
1250 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1251 acpi_device_dir(device));
1252 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1253 acpi_device_dir(device));
1254 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1255 acpi_device_dir(device));
1256 remove_proc_entry(ACPI_THERMAL_FILE_STATE,
1257 acpi_device_dir(device));
1258 remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
1259 acpi_device_dir(device) = NULL;
1265 /* --------------------------------------------------------------------------
1267 -------------------------------------------------------------------------- */
1269 static void acpi_thermal_notify(struct acpi_device *device, u32 event)
1271 struct acpi_thermal *tz = acpi_driver_data(device);
1278 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
1279 acpi_thermal_check(tz);
1281 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
1282 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS);
1283 acpi_thermal_check(tz);
1284 acpi_bus_generate_proc_event(device, event, 0);
1285 acpi_bus_generate_netlink_event(device->pnp.device_class,
1286 dev_name(&device->dev), event, 0);
1288 case ACPI_THERMAL_NOTIFY_DEVICES:
1289 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES);
1290 acpi_thermal_check(tz);
1291 acpi_bus_generate_proc_event(device, event, 0);
1292 acpi_bus_generate_netlink_event(device->pnp.device_class,
1293 dev_name(&device->dev), event, 0);
1296 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1297 "Unsupported event [0x%x]\n", event));
1302 static int acpi_thermal_get_info(struct acpi_thermal *tz)
1310 /* Get temperature [_TMP] (required) */
1311 result = acpi_thermal_get_temperature(tz);
1315 /* Get trip points [_CRT, _PSV, etc.] (required) */
1316 result = acpi_thermal_get_trip_points(tz);
1320 /* Set the cooling mode [_SCP] to active cooling (default) */
1321 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
1323 tz->flags.cooling_mode = 1;
1325 /* Get default polling frequency [_TZP] (optional) */
1327 tz->polling_frequency = tzp;
1329 acpi_thermal_get_polling_frequency(tz);
1334 static int acpi_thermal_add(struct acpi_device *device)
1337 struct acpi_thermal *tz = NULL;
1343 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1347 tz->device = device;
1348 strcpy(tz->name, device->pnp.bus_id);
1349 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1350 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
1351 device->driver_data = tz;
1352 mutex_init(&tz->lock);
1355 result = acpi_thermal_get_info(tz);
1359 result = acpi_thermal_register_thermal_zone(tz);
1363 result = acpi_thermal_add_fs(device);
1365 goto unregister_thermal_zone;
1367 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
1368 acpi_device_name(device), acpi_device_bid(device),
1369 KELVIN_TO_CELSIUS(tz->temperature));
1372 unregister_thermal_zone:
1373 thermal_zone_device_unregister(tz->thermal_zone);
1380 static int acpi_thermal_remove(struct acpi_device *device, int type)
1382 struct acpi_thermal *tz = NULL;
1384 if (!device || !acpi_driver_data(device))
1387 tz = acpi_driver_data(device);
1389 acpi_thermal_remove_fs(device);
1390 acpi_thermal_unregister_thermal_zone(tz);
1391 mutex_destroy(&tz->lock);
1396 static int acpi_thermal_resume(struct acpi_device *device)
1398 struct acpi_thermal *tz = NULL;
1399 int i, j, power_state, result;
1402 if (!device || !acpi_driver_data(device))
1405 tz = acpi_driver_data(device);
1407 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1408 if (!(&tz->trips.active[i]))
1410 if (!tz->trips.active[i].flags.valid)
1412 tz->trips.active[i].flags.enabled = 1;
1413 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1414 result = acpi_bus_get_power(tz->trips.active[i].devices.
1415 handles[j], &power_state);
1416 if (result || (power_state != ACPI_STATE_D0)) {
1417 tz->trips.active[i].flags.enabled = 0;
1421 tz->state.active |= tz->trips.active[i].flags.enabled;
1424 acpi_thermal_check(tz);
1429 static int thermal_act(const struct dmi_system_id *d) {
1432 printk(KERN_NOTICE "ACPI: %s detected: "
1433 "disabling all active thermal trip points\n", d->ident);
1438 static int thermal_nocrt(const struct dmi_system_id *d) {
1440 printk(KERN_NOTICE "ACPI: %s detected: "
1441 "disabling all critical thermal trip point actions.\n", d->ident);
1445 static int thermal_tzp(const struct dmi_system_id *d) {
1448 printk(KERN_NOTICE "ACPI: %s detected: "
1449 "enabling thermal zone polling\n", d->ident);
1450 tzp = 300; /* 300 dS = 30 Seconds */
1454 static int thermal_psv(const struct dmi_system_id *d) {
1457 printk(KERN_NOTICE "ACPI: %s detected: "
1458 "disabling all passive thermal trip points\n", d->ident);
1464 static struct dmi_system_id thermal_dmi_table[] __initdata = {
1466 * Award BIOS on this AOpen makes thermal control almost worthless.
1467 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1470 .callback = thermal_act,
1471 .ident = "AOpen i915GMm-HFS",
1473 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1474 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1478 .callback = thermal_psv,
1479 .ident = "AOpen i915GMm-HFS",
1481 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1482 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1486 .callback = thermal_tzp,
1487 .ident = "AOpen i915GMm-HFS",
1489 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1490 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1494 .callback = thermal_nocrt,
1495 .ident = "Gigabyte GA-7ZX",
1497 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
1498 DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
1504 static int __init acpi_thermal_init(void)
1508 dmi_check_system(thermal_dmi_table);
1511 printk(KERN_NOTICE "ACPI: thermal control disabled\n");
1514 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
1515 if (!acpi_thermal_dir)
1518 result = acpi_bus_register_driver(&acpi_thermal_driver);
1520 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1527 static void __exit acpi_thermal_exit(void)
1530 acpi_bus_unregister_driver(&acpi_thermal_driver);
1532 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1537 module_init(acpi_thermal_init);
1538 module_exit(acpi_thermal_exit);