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/timer.h>
41 #include <linux/jiffies.h>
42 #include <linux/kmod.h>
43 #include <linux/seq_file.h>
44 #include <linux/reboot.h>
45 #include <asm/uaccess.h>
47 #include <acpi/acpi_bus.h>
48 #include <acpi/acpi_drivers.h>
50 #define ACPI_THERMAL_COMPONENT 0x04000000
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 KELVIN_TO_CELSIUS(t) (long)(((long)t-2732>=0) ? ((long)t-2732+5)/10 : ((long)t-2732-5)/10)
69 #define CELSIUS_TO_KELVIN(t) ((t+273)*10)
71 #define _COMPONENT ACPI_THERMAL_COMPONENT
72 ACPI_MODULE_NAME("thermal");
74 MODULE_AUTHOR("Paul Diefenbaugh");
75 MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
76 MODULE_LICENSE("GPL");
79 module_param(act, int, 0644);
80 MODULE_PARM_DESC(act, "Disable or override all lowest active trip points.");
83 module_param(crt, int, 0644);
84 MODULE_PARM_DESC(crt, "Disable or lower all critical trip points.");
87 module_param(tzp, int, 0444);
88 MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.");
91 module_param(nocrt, int, 0);
92 MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points.");
95 module_param(off, int, 0);
96 MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.");
99 module_param(psv, int, 0644);
100 MODULE_PARM_DESC(psv, "Disable or override all passive trip points.");
102 static int acpi_thermal_add(struct acpi_device *device);
103 static int acpi_thermal_remove(struct acpi_device *device, int type);
104 static int acpi_thermal_resume(struct acpi_device *device);
105 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
106 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
107 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
108 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
109 static ssize_t acpi_thermal_write_cooling_mode(struct file *,
110 const char __user *, size_t,
112 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
113 static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
116 static const struct acpi_device_id thermal_device_ids[] = {
117 {ACPI_THERMAL_HID, 0},
120 MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
122 static struct acpi_driver acpi_thermal_driver = {
124 .class = ACPI_THERMAL_CLASS,
125 .ids = thermal_device_ids,
127 .add = acpi_thermal_add,
128 .remove = acpi_thermal_remove,
129 .resume = acpi_thermal_resume,
133 struct acpi_thermal_state {
142 struct acpi_thermal_state_flags {
148 struct acpi_thermal_critical {
149 struct acpi_thermal_state_flags flags;
150 unsigned long temperature;
153 struct acpi_thermal_hot {
154 struct acpi_thermal_state_flags flags;
155 unsigned long temperature;
158 struct acpi_thermal_passive {
159 struct acpi_thermal_state_flags flags;
160 unsigned long temperature;
164 struct acpi_handle_list devices;
167 struct acpi_thermal_active {
168 struct acpi_thermal_state_flags flags;
169 unsigned long temperature;
170 struct acpi_handle_list devices;
173 struct acpi_thermal_trips {
174 struct acpi_thermal_critical critical;
175 struct acpi_thermal_hot hot;
176 struct acpi_thermal_passive passive;
177 struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
180 struct acpi_thermal_flags {
181 u8 cooling_mode:1; /* _SCP */
182 u8 devices:1; /* _TZD */
186 struct acpi_thermal {
187 struct acpi_device * device;
189 unsigned long temperature;
190 unsigned long last_temperature;
191 unsigned long polling_frequency;
193 struct acpi_thermal_flags flags;
194 struct acpi_thermal_state state;
195 struct acpi_thermal_trips trips;
196 struct acpi_handle_list devices;
197 struct timer_list timer;
200 static const struct file_operations acpi_thermal_state_fops = {
201 .open = acpi_thermal_state_open_fs,
204 .release = single_release,
207 static const struct file_operations acpi_thermal_temp_fops = {
208 .open = acpi_thermal_temp_open_fs,
211 .release = single_release,
214 static const struct file_operations acpi_thermal_trip_fops = {
215 .open = acpi_thermal_trip_open_fs,
218 .release = single_release,
221 static const struct file_operations acpi_thermal_cooling_fops = {
222 .open = acpi_thermal_cooling_open_fs,
224 .write = acpi_thermal_write_cooling_mode,
226 .release = single_release,
229 static const struct file_operations acpi_thermal_polling_fops = {
230 .open = acpi_thermal_polling_open_fs,
232 .write = acpi_thermal_write_polling,
234 .release = single_release,
237 /* --------------------------------------------------------------------------
238 Thermal Zone Management
239 -------------------------------------------------------------------------- */
241 static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
243 acpi_status status = AE_OK;
249 tz->last_temperature = tz->temperature;
252 acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tz->temperature);
253 if (ACPI_FAILURE(status))
256 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
262 static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
264 acpi_status status = AE_OK;
271 acpi_evaluate_integer(tz->device->handle, "_TZP", NULL,
272 &tz->polling_frequency);
273 if (ACPI_FAILURE(status))
276 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
277 tz->polling_frequency));
282 static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
288 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
290 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
291 "Polling frequency set to %lu seconds\n",
292 tz->polling_frequency/10));
297 static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
299 acpi_status status = AE_OK;
300 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
301 struct acpi_object_list arg_list = { 1, &arg0 };
302 acpi_handle handle = NULL;
308 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
309 if (ACPI_FAILURE(status)) {
310 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
314 arg0.integer.value = mode;
316 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
317 if (ACPI_FAILURE(status))
323 static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
325 acpi_status status = AE_OK;
332 /* Critical Shutdown (required) */
334 status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL,
335 &tz->trips.critical.temperature);
336 if (ACPI_FAILURE(status)) {
337 tz->trips.critical.flags.valid = 0;
338 ACPI_EXCEPTION((AE_INFO, status, "No critical threshold"));
341 tz->trips.critical.flags.valid = 1;
342 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
343 "Found critical threshold [%lu]\n",
344 tz->trips.critical.temperature));
347 if (tz->trips.critical.flags.valid == 1) {
349 tz->trips.critical.flags.valid = 0;
350 } else if (crt > 0) {
351 unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
354 * Allow override to lower critical threshold
356 if (crt_k < tz->trips.critical.temperature)
357 tz->trips.critical.temperature = crt_k;
361 /* Critical Sleep (optional) */
364 acpi_evaluate_integer(tz->device->handle, "_HOT", NULL,
365 &tz->trips.hot.temperature);
366 if (ACPI_FAILURE(status)) {
367 tz->trips.hot.flags.valid = 0;
368 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No hot threshold\n"));
370 tz->trips.hot.flags.valid = 1;
371 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found hot threshold [%lu]\n",
372 tz->trips.hot.temperature));
375 /* Passive: Processors (optional) */
379 } else if (psv > 0) {
380 tz->trips.passive.temperature = CELSIUS_TO_KELVIN(psv);
383 status = acpi_evaluate_integer(tz->device->handle,
384 "_PSV", NULL, &tz->trips.passive.temperature);
387 if (ACPI_FAILURE(status)) {
388 tz->trips.passive.flags.valid = 0;
389 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No passive threshold\n"));
391 tz->trips.passive.flags.valid = 1;
394 acpi_evaluate_integer(tz->device->handle, "_TC1", NULL,
395 &tz->trips.passive.tc1);
396 if (ACPI_FAILURE(status))
397 tz->trips.passive.flags.valid = 0;
400 acpi_evaluate_integer(tz->device->handle, "_TC2", NULL,
401 &tz->trips.passive.tc2);
402 if (ACPI_FAILURE(status))
403 tz->trips.passive.flags.valid = 0;
406 acpi_evaluate_integer(tz->device->handle, "_TSP", NULL,
407 &tz->trips.passive.tsp);
408 if (ACPI_FAILURE(status))
409 tz->trips.passive.flags.valid = 0;
412 acpi_evaluate_reference(tz->device->handle, "_PSL", NULL,
413 &tz->trips.passive.devices);
414 if (ACPI_FAILURE(status))
415 tz->trips.passive.flags.valid = 0;
417 if (!tz->trips.passive.flags.valid)
418 printk(KERN_WARNING PREFIX "Invalid passive threshold\n");
420 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
421 "Found passive threshold [%lu]\n",
422 tz->trips.passive.temperature));
425 /* Active: Fans, etc. (optional) */
427 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
429 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
432 break; /* disable all active trip points */
434 status = acpi_evaluate_integer(tz->device->handle,
435 name, NULL, &tz->trips.active[i].temperature);
437 if (ACPI_FAILURE(status)) {
438 if (i == 0) /* no active trip points */
440 if (act <= 0) /* no override requested */
442 if (i == 1) { /* 1 trip point */
443 tz->trips.active[0].temperature =
444 CELSIUS_TO_KELVIN(act);
445 } else { /* multiple trips */
447 * Don't allow override higher than
448 * the next higher trip point
450 tz->trips.active[i - 1].temperature =
451 (tz->trips.active[i - 2].temperature <
452 CELSIUS_TO_KELVIN(act) ?
453 tz->trips.active[i - 2].temperature :
454 CELSIUS_TO_KELVIN(act));
461 acpi_evaluate_reference(tz->device->handle, name, NULL,
462 &tz->trips.active[i].devices);
463 if (ACPI_SUCCESS(status)) {
464 tz->trips.active[i].flags.valid = 1;
465 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
466 "Found active threshold [%d]:[%lu]\n",
467 i, tz->trips.active[i].temperature));
469 ACPI_EXCEPTION((AE_INFO, status,
470 "Invalid active threshold [%d]", i));
476 static int acpi_thermal_get_devices(struct acpi_thermal *tz)
478 acpi_status status = AE_OK;
485 acpi_evaluate_reference(tz->device->handle, "_TZD", NULL, &tz->devices);
486 if (ACPI_FAILURE(status))
492 static int acpi_thermal_critical(struct acpi_thermal *tz)
494 if (!tz || !tz->trips.critical.flags.valid || nocrt)
497 if (tz->temperature >= tz->trips.critical.temperature) {
498 printk(KERN_WARNING PREFIX "Critical trip point\n");
499 tz->trips.critical.flags.enabled = 1;
500 } else if (tz->trips.critical.flags.enabled)
501 tz->trips.critical.flags.enabled = 0;
504 "Critical temperature reached (%ld C), shutting down.\n",
505 KELVIN_TO_CELSIUS(tz->temperature));
506 acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL,
507 tz->trips.critical.flags.enabled);
508 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
509 tz->device->dev.bus_id,
510 ACPI_THERMAL_NOTIFY_CRITICAL,
511 tz->trips.critical.flags.enabled);
513 orderly_poweroff(true);
518 static int acpi_thermal_hot(struct acpi_thermal *tz)
520 if (!tz || !tz->trips.hot.flags.valid || nocrt)
523 if (tz->temperature >= tz->trips.hot.temperature) {
524 printk(KERN_WARNING PREFIX "Hot trip point\n");
525 tz->trips.hot.flags.enabled = 1;
526 } else if (tz->trips.hot.flags.enabled)
527 tz->trips.hot.flags.enabled = 0;
529 acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
530 tz->trips.hot.flags.enabled);
531 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
532 tz->device->dev.bus_id,
533 ACPI_THERMAL_NOTIFY_HOT,
534 tz->trips.hot.flags.enabled);
536 /* TBD: Call user-mode "sleep(S4)" function */
541 static void acpi_thermal_passive(struct acpi_thermal *tz)
544 struct acpi_thermal_passive *passive = NULL;
549 if (!tz || !tz->trips.passive.flags.valid)
552 passive = &(tz->trips.passive);
557 * Calculate the thermal trend (using the passive cooling equation)
558 * and modify the performance limit for all passive cooling devices
559 * accordingly. Note that we assume symmetry.
561 if (tz->temperature >= passive->temperature) {
563 (passive->tc1 * (tz->temperature - tz->last_temperature)) +
564 (passive->tc2 * (tz->temperature - passive->temperature));
565 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
566 "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
567 trend, passive->tc1, tz->temperature,
568 tz->last_temperature, passive->tc2,
569 tz->temperature, passive->temperature));
570 passive->flags.enabled = 1;
573 for (i = 0; i < passive->devices.count; i++)
574 acpi_processor_set_thermal_limit(passive->
577 ACPI_PROCESSOR_LIMIT_INCREMENT);
579 else if (trend < 0) {
580 for (i = 0; i < passive->devices.count; i++)
582 * assume that we are on highest
583 * freq/lowest thrott and can leave
584 * passive mode, even in error case
586 if (!acpi_processor_set_thermal_limit
587 (passive->devices.handles[i],
588 ACPI_PROCESSOR_LIMIT_DECREMENT))
591 * Leave cooling mode, even if the temp might
592 * higher than trip point This is because some
593 * machines might have long thermal polling
594 * frequencies (tsp) defined. We will fall back
595 * into passive mode in next cycle (probably quicker)
598 passive->flags.enabled = 0;
599 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
600 "Disabling passive cooling, still above threshold,"
601 " but we are cooling down\n"));
610 * Implement passive cooling hysteresis to slowly increase performance
611 * and avoid thrashing around the passive trip point. Note that we
614 if (!passive->flags.enabled)
616 for (i = 0; i < passive->devices.count; i++)
617 if (!acpi_processor_set_thermal_limit
618 (passive->devices.handles[i],
619 ACPI_PROCESSOR_LIMIT_DECREMENT))
622 passive->flags.enabled = 0;
623 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
624 "Disabling passive cooling (zone is cool)\n"));
628 static void acpi_thermal_active(struct acpi_thermal *tz)
631 struct acpi_thermal_active *active = NULL;
634 unsigned long maxtemp = 0;
640 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
641 active = &(tz->trips.active[i]);
642 if (!active || !active->flags.valid)
644 if (tz->temperature >= active->temperature) {
648 * If not already enabled, turn ON all cooling devices
649 * associated with this active threshold.
651 if (active->temperature > maxtemp)
652 tz->state.active_index = i;
653 maxtemp = active->temperature;
654 if (active->flags.enabled)
656 for (j = 0; j < active->devices.count; j++) {
658 acpi_bus_set_power(active->devices.
662 printk(KERN_WARNING PREFIX
663 "Unable to turn cooling device [%p] 'on'\n",
668 active->flags.enabled = 1;
669 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
670 "Cooling device [%p] now 'on'\n",
671 active->devices.handles[j]));
675 if (!active->flags.enabled)
680 * Turn OFF all cooling devices associated with this
683 for (j = 0; j < active->devices.count; j++) {
684 result = acpi_bus_set_power(active->devices.handles[j],
687 printk(KERN_WARNING PREFIX
688 "Unable to turn cooling device [%p] 'off'\n",
689 active->devices.handles[j]);
692 active->flags.enabled = 0;
693 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
694 "Cooling device [%p] now 'off'\n",
695 active->devices.handles[j]));
700 static void acpi_thermal_check(void *context);
702 static void acpi_thermal_run(unsigned long data)
704 struct acpi_thermal *tz = (struct acpi_thermal *)data;
706 acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data);
709 static void acpi_thermal_check(void *data)
712 struct acpi_thermal *tz = data;
713 unsigned long sleep_time = 0;
715 struct acpi_thermal_state state;
719 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
725 result = acpi_thermal_get_temperature(tz);
729 memset(&tz->state, 0, sizeof(tz->state));
734 * Compare the current temperature to the trip point values to see
735 * if we've entered one of the thermal policy states. Note that
736 * this function determines when a state is entered, but the
737 * individual policy decides when it is exited (e.g. hysteresis).
739 if (tz->trips.critical.flags.valid)
741 (tz->temperature >= tz->trips.critical.temperature);
742 if (tz->trips.hot.flags.valid)
743 state.hot |= (tz->temperature >= tz->trips.hot.temperature);
744 if (tz->trips.passive.flags.valid)
746 (tz->temperature >= tz->trips.passive.temperature);
747 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
748 if (tz->trips.active[i].flags.valid)
751 tz->trips.active[i].temperature);
756 * Separated from the above check to allow individual policy to
757 * determine when to exit a given state.
760 acpi_thermal_critical(tz);
762 acpi_thermal_hot(tz);
764 acpi_thermal_passive(tz);
766 acpi_thermal_active(tz);
771 * Again, separated from the above two to allow independent policy
774 tz->state.critical = tz->trips.critical.flags.enabled;
775 tz->state.hot = tz->trips.hot.flags.enabled;
776 tz->state.passive = tz->trips.passive.flags.enabled;
777 tz->state.active = 0;
778 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
779 tz->state.active |= tz->trips.active[i].flags.enabled;
782 * Calculate Sleep Time
783 * --------------------
784 * If we're in the passive state, use _TSP's value. Otherwise
785 * use the default polling frequency (e.g. _TZP). If no polling
786 * frequency is specified then we'll wait forever (at least until
787 * a thermal event occurs). Note that _TSP and _TZD values are
788 * given in 1/10th seconds (we must covert to milliseconds).
790 if (tz->state.passive)
791 sleep_time = tz->trips.passive.tsp * 100;
792 else if (tz->polling_frequency > 0)
793 sleep_time = tz->polling_frequency * 100;
795 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n",
796 tz->name, tz->temperature, sleep_time));
803 if (timer_pending(&(tz->timer)))
804 del_timer(&(tz->timer));
806 if (timer_pending(&(tz->timer)))
807 mod_timer(&(tz->timer),
808 jiffies + (HZ * sleep_time) / 1000);
810 tz->timer.data = (unsigned long)tz;
811 tz->timer.function = acpi_thermal_run;
812 tz->timer.expires = jiffies + (HZ * sleep_time) / 1000;
813 add_timer(&(tz->timer));
820 /* --------------------------------------------------------------------------
822 -------------------------------------------------------------------------- */
824 static struct proc_dir_entry *acpi_thermal_dir;
826 static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
828 struct acpi_thermal *tz = seq->private;
834 seq_puts(seq, "state: ");
836 if (!tz->state.critical && !tz->state.hot && !tz->state.passive
837 && !tz->state.active)
838 seq_puts(seq, "ok\n");
840 if (tz->state.critical)
841 seq_puts(seq, "critical ");
843 seq_puts(seq, "hot ");
844 if (tz->state.passive)
845 seq_puts(seq, "passive ");
846 if (tz->state.active)
847 seq_printf(seq, "active[%d]", tz->state.active_index);
855 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
857 return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
860 static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
863 struct acpi_thermal *tz = seq->private;
869 result = acpi_thermal_get_temperature(tz);
873 seq_printf(seq, "temperature: %ld C\n",
874 KELVIN_TO_CELSIUS(tz->temperature));
880 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
882 return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
885 static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
887 struct acpi_thermal *tz = seq->private;
888 struct acpi_device *device;
898 if (tz->trips.critical.flags.valid)
899 seq_printf(seq, "critical (S5): %ld C%s",
900 KELVIN_TO_CELSIUS(tz->trips.critical.temperature),
901 nocrt ? " <disabled>\n" : "\n");
903 if (tz->trips.hot.flags.valid)
904 seq_printf(seq, "hot (S4): %ld C%s",
905 KELVIN_TO_CELSIUS(tz->trips.hot.temperature),
906 nocrt ? " <disabled>\n" : "\n");
908 if (tz->trips.passive.flags.valid) {
910 "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
911 KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
912 tz->trips.passive.tc1, tz->trips.passive.tc2,
913 tz->trips.passive.tsp);
914 for (j = 0; j < tz->trips.passive.devices.count; j++) {
915 status = acpi_bus_get_device(tz->trips.passive.devices.
916 handles[j], &device);
917 seq_printf(seq, "%4.4s ", status ? "" :
918 acpi_device_bid(device));
923 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
924 if (!(tz->trips.active[i].flags.valid))
926 seq_printf(seq, "active[%d]: %ld C: devices=",
928 KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
929 for (j = 0; j < tz->trips.active[i].devices.count; j++){
930 status = acpi_bus_get_device(tz->trips.active[i].
933 seq_printf(seq, "%4.4s ", status ? "" :
934 acpi_device_bid(device));
943 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
945 return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
948 static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
950 struct acpi_thermal *tz = seq->private;
956 if (!tz->flags.cooling_mode)
957 seq_puts(seq, "<setting not supported>\n");
959 seq_puts(seq, "0 - Active; 1 - Passive\n");
965 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
967 return single_open(file, acpi_thermal_cooling_seq_show,
972 acpi_thermal_write_cooling_mode(struct file *file,
973 const char __user * buffer,
974 size_t count, loff_t * ppos)
976 struct seq_file *m = file->private_data;
977 struct acpi_thermal *tz = m->private;
979 char mode_string[12] = { '\0' };
982 if (!tz || (count > sizeof(mode_string) - 1))
985 if (!tz->flags.cooling_mode)
988 if (copy_from_user(mode_string, buffer, count))
991 mode_string[count] = '\0';
993 result = acpi_thermal_set_cooling_mode(tz,
994 simple_strtoul(mode_string, NULL,
999 acpi_thermal_check(tz);
1004 static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
1006 struct acpi_thermal *tz = seq->private;
1012 if (!tz->polling_frequency) {
1013 seq_puts(seq, "<polling disabled>\n");
1017 seq_printf(seq, "polling frequency: %lu seconds\n",
1018 (tz->polling_frequency / 10));
1024 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
1026 return single_open(file, acpi_thermal_polling_seq_show,
1031 acpi_thermal_write_polling(struct file *file,
1032 const char __user * buffer,
1033 size_t count, loff_t * ppos)
1035 struct seq_file *m = file->private_data;
1036 struct acpi_thermal *tz = m->private;
1038 char polling_string[12] = { '\0' };
1042 if (!tz || (count > sizeof(polling_string) - 1))
1045 if (copy_from_user(polling_string, buffer, count))
1048 polling_string[count] = '\0';
1050 seconds = simple_strtoul(polling_string, NULL, 0);
1052 result = acpi_thermal_set_polling(tz, seconds);
1056 acpi_thermal_check(tz);
1061 static int acpi_thermal_add_fs(struct acpi_device *device)
1063 struct proc_dir_entry *entry = NULL;
1066 if (!acpi_device_dir(device)) {
1067 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1069 if (!acpi_device_dir(device))
1071 acpi_device_dir(device)->owner = THIS_MODULE;
1075 entry = create_proc_entry(ACPI_THERMAL_FILE_STATE,
1076 S_IRUGO, acpi_device_dir(device));
1080 entry->proc_fops = &acpi_thermal_state_fops;
1081 entry->data = acpi_driver_data(device);
1082 entry->owner = THIS_MODULE;
1085 /* 'temperature' [R] */
1086 entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1087 S_IRUGO, acpi_device_dir(device));
1091 entry->proc_fops = &acpi_thermal_temp_fops;
1092 entry->data = acpi_driver_data(device);
1093 entry->owner = THIS_MODULE;
1096 /* 'trip_points' [R] */
1097 entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1099 acpi_device_dir(device));
1103 entry->proc_fops = &acpi_thermal_trip_fops;
1104 entry->data = acpi_driver_data(device);
1105 entry->owner = THIS_MODULE;
1108 /* 'cooling_mode' [R/W] */
1109 entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1110 S_IFREG | S_IRUGO | S_IWUSR,
1111 acpi_device_dir(device));
1115 entry->proc_fops = &acpi_thermal_cooling_fops;
1116 entry->data = acpi_driver_data(device);
1117 entry->owner = THIS_MODULE;
1120 /* 'polling_frequency' [R/W] */
1121 entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1122 S_IFREG | S_IRUGO | S_IWUSR,
1123 acpi_device_dir(device));
1127 entry->proc_fops = &acpi_thermal_polling_fops;
1128 entry->data = acpi_driver_data(device);
1129 entry->owner = THIS_MODULE;
1135 static int acpi_thermal_remove_fs(struct acpi_device *device)
1138 if (acpi_device_dir(device)) {
1139 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1140 acpi_device_dir(device));
1141 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1142 acpi_device_dir(device));
1143 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1144 acpi_device_dir(device));
1145 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1146 acpi_device_dir(device));
1147 remove_proc_entry(ACPI_THERMAL_FILE_STATE,
1148 acpi_device_dir(device));
1149 remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
1150 acpi_device_dir(device) = NULL;
1156 /* --------------------------------------------------------------------------
1158 -------------------------------------------------------------------------- */
1160 static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
1162 struct acpi_thermal *tz = data;
1163 struct acpi_device *device = NULL;
1169 device = tz->device;
1172 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
1173 acpi_thermal_check(tz);
1175 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
1176 acpi_thermal_get_trip_points(tz);
1177 acpi_thermal_check(tz);
1178 acpi_bus_generate_proc_event(device, event, 0);
1179 acpi_bus_generate_netlink_event(device->pnp.device_class,
1180 device->dev.bus_id, event, 0);
1182 case ACPI_THERMAL_NOTIFY_DEVICES:
1183 if (tz->flags.devices)
1184 acpi_thermal_get_devices(tz);
1185 acpi_bus_generate_proc_event(device, event, 0);
1186 acpi_bus_generate_netlink_event(device->pnp.device_class,
1187 device->dev.bus_id, event, 0);
1190 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1191 "Unsupported event [0x%x]\n", event));
1198 static int acpi_thermal_get_info(struct acpi_thermal *tz)
1206 /* Get temperature [_TMP] (required) */
1207 result = acpi_thermal_get_temperature(tz);
1211 /* Get trip points [_CRT, _PSV, etc.] (required) */
1212 result = acpi_thermal_get_trip_points(tz);
1216 /* Set the cooling mode [_SCP] to active cooling (default) */
1217 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
1219 tz->flags.cooling_mode = 1;
1221 /* Get default polling frequency [_TZP] (optional) */
1223 tz->polling_frequency = tzp;
1225 acpi_thermal_get_polling_frequency(tz);
1227 /* Get devices in this thermal zone [_TZD] (optional) */
1228 result = acpi_thermal_get_devices(tz);
1230 tz->flags.devices = 1;
1235 static int acpi_thermal_add(struct acpi_device *device)
1238 acpi_status status = AE_OK;
1239 struct acpi_thermal *tz = NULL;
1245 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1249 tz->device = device;
1250 strcpy(tz->name, device->pnp.bus_id);
1251 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1252 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
1253 acpi_driver_data(device) = tz;
1255 result = acpi_thermal_get_info(tz);
1259 result = acpi_thermal_add_fs(device);
1263 init_timer(&tz->timer);
1265 acpi_thermal_check(tz);
1267 status = acpi_install_notify_handler(device->handle,
1269 acpi_thermal_notify, tz);
1270 if (ACPI_FAILURE(status)) {
1275 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
1276 acpi_device_name(device), acpi_device_bid(device),
1277 KELVIN_TO_CELSIUS(tz->temperature));
1281 acpi_thermal_remove_fs(device);
1288 static int acpi_thermal_remove(struct acpi_device *device, int type)
1290 acpi_status status = AE_OK;
1291 struct acpi_thermal *tz = NULL;
1294 if (!device || !acpi_driver_data(device))
1297 tz = acpi_driver_data(device);
1299 /* avoid timer adding new defer task */
1301 /* wait for running timer (on other CPUs) finish */
1302 del_timer_sync(&(tz->timer));
1303 /* synchronize deferred task */
1304 acpi_os_wait_events_complete(NULL);
1305 /* deferred task may reinsert timer */
1306 del_timer_sync(&(tz->timer));
1308 status = acpi_remove_notify_handler(device->handle,
1310 acpi_thermal_notify);
1312 /* Terminate policy */
1313 if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
1314 tz->trips.passive.flags.enabled = 0;
1315 acpi_thermal_passive(tz);
1317 if (tz->trips.active[0].flags.valid
1318 && tz->trips.active[0].flags.enabled) {
1319 tz->trips.active[0].flags.enabled = 0;
1320 acpi_thermal_active(tz);
1323 acpi_thermal_remove_fs(device);
1329 static int acpi_thermal_resume(struct acpi_device *device)
1331 struct acpi_thermal *tz = NULL;
1332 int i, j, power_state, result;
1335 if (!device || !acpi_driver_data(device))
1338 tz = acpi_driver_data(device);
1340 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1341 if (!(&tz->trips.active[i]))
1343 if (!tz->trips.active[i].flags.valid)
1345 tz->trips.active[i].flags.enabled = 1;
1346 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1347 result = acpi_bus_get_power(tz->trips.active[i].devices.
1348 handles[j], &power_state);
1349 if (result || (power_state != ACPI_STATE_D0)) {
1350 tz->trips.active[i].flags.enabled = 0;
1354 tz->state.active |= tz->trips.active[i].flags.enabled;
1357 acpi_thermal_check(tz);
1363 static int thermal_act(const struct dmi_system_id *d) {
1366 printk(KERN_NOTICE "ACPI: %s detected: "
1367 "disabling all active thermal trip points\n", d->ident);
1372 static int thermal_nocrt(const struct dmi_system_id *d) {
1374 printk(KERN_NOTICE "ACPI: %s detected: "
1375 "disabling all critical thermal trip point actions.\n", d->ident);
1379 static int thermal_tzp(const struct dmi_system_id *d) {
1382 printk(KERN_NOTICE "ACPI: %s detected: "
1383 "enabling thermal zone polling\n", d->ident);
1384 tzp = 300; /* 300 dS = 30 Seconds */
1388 static int thermal_psv(const struct dmi_system_id *d) {
1391 printk(KERN_NOTICE "ACPI: %s detected: "
1392 "disabling all passive thermal trip points\n", d->ident);
1398 static struct dmi_system_id thermal_dmi_table[] __initdata = {
1400 * Award BIOS on this AOpen makes thermal control almost worthless.
1401 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1404 .callback = thermal_act,
1405 .ident = "AOpen i915GMm-HFS",
1407 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1408 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1412 .callback = thermal_psv,
1413 .ident = "AOpen i915GMm-HFS",
1415 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1416 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1420 .callback = thermal_tzp,
1421 .ident = "AOpen i915GMm-HFS",
1423 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1424 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1428 .callback = thermal_nocrt,
1429 .ident = "Gigabyte GA-7ZX",
1431 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
1432 DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
1437 #endif /* CONFIG_DMI */
1439 static int __init acpi_thermal_init(void)
1443 dmi_check_system(thermal_dmi_table);
1446 printk(KERN_NOTICE "ACPI: thermal control disabled\n");
1449 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
1450 if (!acpi_thermal_dir)
1452 acpi_thermal_dir->owner = THIS_MODULE;
1454 result = acpi_bus_register_driver(&acpi_thermal_driver);
1456 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1463 static void __exit acpi_thermal_exit(void)
1466 acpi_bus_unregister_driver(&acpi_thermal_driver);
1468 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1473 module_init(acpi_thermal_init);
1474 module_exit(acpi_thermal_exit);