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/init.h>
37 #include <linux/types.h>
38 #include <linux/proc_fs.h>
39 #include <linux/timer.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>
46 #include <acpi/acpi_bus.h>
47 #include <acpi/acpi_drivers.h>
49 #define ACPI_THERMAL_COMPONENT 0x04000000
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 KELVIN_TO_CELSIUS(t) (long)(((long)t-2732>=0) ? ((long)t-2732+5)/10 : ((long)t-2732-5)/10)
68 #define CELSIUS_TO_KELVIN(t) ((t+273)*10)
70 #define _COMPONENT ACPI_THERMAL_COMPONENT
71 ACPI_MODULE_NAME("thermal");
73 MODULE_AUTHOR("Paul Diefenbaugh");
74 MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
75 MODULE_LICENSE("GPL");
78 module_param(tzp, int, 0444);
79 MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.\n");
82 module_param(nocrt, int, 0);
83 MODULE_PARM_DESC(nocrt, "Set to disable action on ACPI thermal zone critical and hot trips.\n");
86 module_param(off, int, 0);
87 MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.\n");
90 module_param(psv, int, 0644);
91 MODULE_PARM_DESC(psv, "Disable or override all passive trip points.\n");
93 static int acpi_thermal_add(struct acpi_device *device);
94 static int acpi_thermal_remove(struct acpi_device *device, int type);
95 static int acpi_thermal_resume(struct acpi_device *device);
96 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
97 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
98 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
99 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
100 static ssize_t acpi_thermal_write_cooling_mode(struct file *,
101 const char __user *, size_t,
103 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
104 static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
107 static const struct acpi_device_id thermal_device_ids[] = {
108 {ACPI_THERMAL_HID, 0},
111 MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
113 static struct acpi_driver acpi_thermal_driver = {
115 .class = ACPI_THERMAL_CLASS,
116 .ids = thermal_device_ids,
118 .add = acpi_thermal_add,
119 .remove = acpi_thermal_remove,
120 .resume = acpi_thermal_resume,
124 struct acpi_thermal_state {
133 struct acpi_thermal_state_flags {
139 struct acpi_thermal_critical {
140 struct acpi_thermal_state_flags flags;
141 unsigned long temperature;
144 struct acpi_thermal_hot {
145 struct acpi_thermal_state_flags flags;
146 unsigned long temperature;
149 struct acpi_thermal_passive {
150 struct acpi_thermal_state_flags flags;
151 unsigned long temperature;
155 struct acpi_handle_list devices;
158 struct acpi_thermal_active {
159 struct acpi_thermal_state_flags flags;
160 unsigned long temperature;
161 struct acpi_handle_list devices;
164 struct acpi_thermal_trips {
165 struct acpi_thermal_critical critical;
166 struct acpi_thermal_hot hot;
167 struct acpi_thermal_passive passive;
168 struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
171 struct acpi_thermal_flags {
172 u8 cooling_mode:1; /* _SCP */
173 u8 devices:1; /* _TZD */
177 struct acpi_thermal {
178 struct acpi_device * device;
180 unsigned long temperature;
181 unsigned long last_temperature;
182 unsigned long polling_frequency;
184 struct acpi_thermal_flags flags;
185 struct acpi_thermal_state state;
186 struct acpi_thermal_trips trips;
187 struct acpi_handle_list devices;
188 struct timer_list timer;
191 static const struct file_operations acpi_thermal_state_fops = {
192 .open = acpi_thermal_state_open_fs,
195 .release = single_release,
198 static const struct file_operations acpi_thermal_temp_fops = {
199 .open = acpi_thermal_temp_open_fs,
202 .release = single_release,
205 static const struct file_operations acpi_thermal_trip_fops = {
206 .open = acpi_thermal_trip_open_fs,
209 .release = single_release,
212 static const struct file_operations acpi_thermal_cooling_fops = {
213 .open = acpi_thermal_cooling_open_fs,
215 .write = acpi_thermal_write_cooling_mode,
217 .release = single_release,
220 static const struct file_operations acpi_thermal_polling_fops = {
221 .open = acpi_thermal_polling_open_fs,
223 .write = acpi_thermal_write_polling,
225 .release = single_release,
228 /* --------------------------------------------------------------------------
229 Thermal Zone Management
230 -------------------------------------------------------------------------- */
232 static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
234 acpi_status status = AE_OK;
240 tz->last_temperature = tz->temperature;
243 acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tz->temperature);
244 if (ACPI_FAILURE(status))
247 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
253 static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
255 acpi_status status = AE_OK;
262 acpi_evaluate_integer(tz->device->handle, "_TZP", NULL,
263 &tz->polling_frequency);
264 if (ACPI_FAILURE(status))
267 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
268 tz->polling_frequency));
273 static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
279 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
281 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
282 "Polling frequency set to %lu seconds\n",
283 tz->polling_frequency/10));
288 static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
290 acpi_status status = AE_OK;
291 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
292 struct acpi_object_list arg_list = { 1, &arg0 };
293 acpi_handle handle = NULL;
299 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
300 if (ACPI_FAILURE(status)) {
301 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
305 arg0.integer.value = mode;
307 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
308 if (ACPI_FAILURE(status))
314 static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
316 acpi_status status = AE_OK;
323 /* Critical Shutdown (required) */
325 status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL,
326 &tz->trips.critical.temperature);
327 if (ACPI_FAILURE(status)) {
328 tz->trips.critical.flags.valid = 0;
329 ACPI_EXCEPTION((AE_INFO, status, "No critical threshold"));
332 tz->trips.critical.flags.valid = 1;
333 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
334 "Found critical threshold [%lu]\n",
335 tz->trips.critical.temperature));
338 /* Critical Sleep (optional) */
341 acpi_evaluate_integer(tz->device->handle, "_HOT", NULL,
342 &tz->trips.hot.temperature);
343 if (ACPI_FAILURE(status)) {
344 tz->trips.hot.flags.valid = 0;
345 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No hot threshold\n"));
347 tz->trips.hot.flags.valid = 1;
348 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found hot threshold [%lu]\n",
349 tz->trips.hot.temperature));
352 /* Passive: Processors (optional) */
356 } else if (psv > 0) {
357 tz->trips.passive.temperature = CELSIUS_TO_KELVIN(psv);
360 status = acpi_evaluate_integer(tz->device->handle,
361 "_PSV", NULL, &tz->trips.passive.temperature);
364 if (ACPI_FAILURE(status)) {
365 tz->trips.passive.flags.valid = 0;
366 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No passive threshold\n"));
368 tz->trips.passive.flags.valid = 1;
371 acpi_evaluate_integer(tz->device->handle, "_TC1", NULL,
372 &tz->trips.passive.tc1);
373 if (ACPI_FAILURE(status))
374 tz->trips.passive.flags.valid = 0;
377 acpi_evaluate_integer(tz->device->handle, "_TC2", NULL,
378 &tz->trips.passive.tc2);
379 if (ACPI_FAILURE(status))
380 tz->trips.passive.flags.valid = 0;
383 acpi_evaluate_integer(tz->device->handle, "_TSP", NULL,
384 &tz->trips.passive.tsp);
385 if (ACPI_FAILURE(status))
386 tz->trips.passive.flags.valid = 0;
389 acpi_evaluate_reference(tz->device->handle, "_PSL", NULL,
390 &tz->trips.passive.devices);
391 if (ACPI_FAILURE(status))
392 tz->trips.passive.flags.valid = 0;
394 if (!tz->trips.passive.flags.valid)
395 printk(KERN_WARNING PREFIX "Invalid passive threshold\n");
397 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
398 "Found passive threshold [%lu]\n",
399 tz->trips.passive.temperature));
402 /* Active: Fans, etc. (optional) */
404 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
406 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
409 acpi_evaluate_integer(tz->device->handle, name, NULL,
410 &tz->trips.active[i].temperature);
411 if (ACPI_FAILURE(status))
416 acpi_evaluate_reference(tz->device->handle, name, NULL,
417 &tz->trips.active[i].devices);
418 if (ACPI_SUCCESS(status)) {
419 tz->trips.active[i].flags.valid = 1;
420 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
421 "Found active threshold [%d]:[%lu]\n",
422 i, tz->trips.active[i].temperature));
424 ACPI_EXCEPTION((AE_INFO, status,
425 "Invalid active threshold [%d]", i));
431 static int acpi_thermal_get_devices(struct acpi_thermal *tz)
433 acpi_status status = AE_OK;
440 acpi_evaluate_reference(tz->device->handle, "_TZD", NULL, &tz->devices);
441 if (ACPI_FAILURE(status))
447 static int acpi_thermal_critical(struct acpi_thermal *tz)
449 if (!tz || !tz->trips.critical.flags.valid || nocrt)
452 if (tz->temperature >= tz->trips.critical.temperature) {
453 printk(KERN_WARNING PREFIX "Critical trip point\n");
454 tz->trips.critical.flags.enabled = 1;
455 } else if (tz->trips.critical.flags.enabled)
456 tz->trips.critical.flags.enabled = 0;
459 "Critical temperature reached (%ld C), shutting down.\n",
460 KELVIN_TO_CELSIUS(tz->temperature));
461 acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL,
462 tz->trips.critical.flags.enabled);
464 orderly_poweroff(true);
469 static int acpi_thermal_hot(struct acpi_thermal *tz)
471 if (!tz || !tz->trips.hot.flags.valid || nocrt)
474 if (tz->temperature >= tz->trips.hot.temperature) {
475 printk(KERN_WARNING PREFIX "Hot trip point\n");
476 tz->trips.hot.flags.enabled = 1;
477 } else if (tz->trips.hot.flags.enabled)
478 tz->trips.hot.flags.enabled = 0;
480 acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
481 tz->trips.hot.flags.enabled);
483 /* TBD: Call user-mode "sleep(S4)" function */
488 static void acpi_thermal_passive(struct acpi_thermal *tz)
491 struct acpi_thermal_passive *passive = NULL;
496 if (!tz || !tz->trips.passive.flags.valid)
499 passive = &(tz->trips.passive);
504 * Calculate the thermal trend (using the passive cooling equation)
505 * and modify the performance limit for all passive cooling devices
506 * accordingly. Note that we assume symmetry.
508 if (tz->temperature >= passive->temperature) {
510 (passive->tc1 * (tz->temperature - tz->last_temperature)) +
511 (passive->tc2 * (tz->temperature - passive->temperature));
512 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
513 "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
514 trend, passive->tc1, tz->temperature,
515 tz->last_temperature, passive->tc2,
516 tz->temperature, passive->temperature));
517 passive->flags.enabled = 1;
520 for (i = 0; i < passive->devices.count; i++)
521 acpi_processor_set_thermal_limit(passive->
524 ACPI_PROCESSOR_LIMIT_INCREMENT);
526 else if (trend < 0) {
527 for (i = 0; i < passive->devices.count; i++)
529 * assume that we are on highest
530 * freq/lowest thrott and can leave
531 * passive mode, even in error case
533 if (!acpi_processor_set_thermal_limit
534 (passive->devices.handles[i],
535 ACPI_PROCESSOR_LIMIT_DECREMENT))
538 * Leave cooling mode, even if the temp might
539 * higher than trip point This is because some
540 * machines might have long thermal polling
541 * frequencies (tsp) defined. We will fall back
542 * into passive mode in next cycle (probably quicker)
545 passive->flags.enabled = 0;
546 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
547 "Disabling passive cooling, still above threshold,"
548 " but we are cooling down\n"));
557 * Implement passive cooling hysteresis to slowly increase performance
558 * and avoid thrashing around the passive trip point. Note that we
561 if (!passive->flags.enabled)
563 for (i = 0; i < passive->devices.count; i++)
564 if (!acpi_processor_set_thermal_limit
565 (passive->devices.handles[i],
566 ACPI_PROCESSOR_LIMIT_DECREMENT))
569 passive->flags.enabled = 0;
570 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
571 "Disabling passive cooling (zone is cool)\n"));
575 static void acpi_thermal_active(struct acpi_thermal *tz)
578 struct acpi_thermal_active *active = NULL;
581 unsigned long maxtemp = 0;
587 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
588 active = &(tz->trips.active[i]);
589 if (!active || !active->flags.valid)
591 if (tz->temperature >= active->temperature) {
595 * If not already enabled, turn ON all cooling devices
596 * associated with this active threshold.
598 if (active->temperature > maxtemp)
599 tz->state.active_index = i;
600 maxtemp = active->temperature;
601 if (active->flags.enabled)
603 for (j = 0; j < active->devices.count; j++) {
605 acpi_bus_set_power(active->devices.
609 printk(KERN_WARNING PREFIX
610 "Unable to turn cooling device [%p] 'on'\n",
615 active->flags.enabled = 1;
616 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
617 "Cooling device [%p] now 'on'\n",
618 active->devices.handles[j]));
622 if (!active->flags.enabled)
627 * Turn OFF all cooling devices associated with this
630 for (j = 0; j < active->devices.count; j++) {
631 result = acpi_bus_set_power(active->devices.handles[j],
634 printk(KERN_WARNING PREFIX
635 "Unable to turn cooling device [%p] 'off'\n",
636 active->devices.handles[j]);
639 active->flags.enabled = 0;
640 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
641 "Cooling device [%p] now 'off'\n",
642 active->devices.handles[j]));
647 static void acpi_thermal_check(void *context);
649 static void acpi_thermal_run(unsigned long data)
651 struct acpi_thermal *tz = (struct acpi_thermal *)data;
653 acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data);
656 static void acpi_thermal_check(void *data)
659 struct acpi_thermal *tz = data;
660 unsigned long sleep_time = 0;
662 struct acpi_thermal_state state;
666 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
672 result = acpi_thermal_get_temperature(tz);
676 memset(&tz->state, 0, sizeof(tz->state));
681 * Compare the current temperature to the trip point values to see
682 * if we've entered one of the thermal policy states. Note that
683 * this function determines when a state is entered, but the
684 * individual policy decides when it is exited (e.g. hysteresis).
686 if (tz->trips.critical.flags.valid)
688 (tz->temperature >= tz->trips.critical.temperature);
689 if (tz->trips.hot.flags.valid)
690 state.hot |= (tz->temperature >= tz->trips.hot.temperature);
691 if (tz->trips.passive.flags.valid)
693 (tz->temperature >= tz->trips.passive.temperature);
694 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
695 if (tz->trips.active[i].flags.valid)
698 tz->trips.active[i].temperature);
703 * Separated from the above check to allow individual policy to
704 * determine when to exit a given state.
707 acpi_thermal_critical(tz);
709 acpi_thermal_hot(tz);
711 acpi_thermal_passive(tz);
713 acpi_thermal_active(tz);
718 * Again, separated from the above two to allow independent policy
721 tz->state.critical = tz->trips.critical.flags.enabled;
722 tz->state.hot = tz->trips.hot.flags.enabled;
723 tz->state.passive = tz->trips.passive.flags.enabled;
724 tz->state.active = 0;
725 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
726 tz->state.active |= tz->trips.active[i].flags.enabled;
729 * Calculate Sleep Time
730 * --------------------
731 * If we're in the passive state, use _TSP's value. Otherwise
732 * use the default polling frequency (e.g. _TZP). If no polling
733 * frequency is specified then we'll wait forever (at least until
734 * a thermal event occurs). Note that _TSP and _TZD values are
735 * given in 1/10th seconds (we must covert to milliseconds).
737 if (tz->state.passive)
738 sleep_time = tz->trips.passive.tsp * 100;
739 else if (tz->polling_frequency > 0)
740 sleep_time = tz->polling_frequency * 100;
742 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n",
743 tz->name, tz->temperature, sleep_time));
750 if (timer_pending(&(tz->timer)))
751 del_timer(&(tz->timer));
753 if (timer_pending(&(tz->timer)))
754 mod_timer(&(tz->timer),
755 jiffies + (HZ * sleep_time) / 1000);
757 tz->timer.data = (unsigned long)tz;
758 tz->timer.function = acpi_thermal_run;
759 tz->timer.expires = jiffies + (HZ * sleep_time) / 1000;
760 add_timer(&(tz->timer));
767 /* --------------------------------------------------------------------------
769 -------------------------------------------------------------------------- */
771 static struct proc_dir_entry *acpi_thermal_dir;
773 static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
775 struct acpi_thermal *tz = seq->private;
781 seq_puts(seq, "state: ");
783 if (!tz->state.critical && !tz->state.hot && !tz->state.passive
784 && !tz->state.active)
785 seq_puts(seq, "ok\n");
787 if (tz->state.critical)
788 seq_puts(seq, "critical ");
790 seq_puts(seq, "hot ");
791 if (tz->state.passive)
792 seq_puts(seq, "passive ");
793 if (tz->state.active)
794 seq_printf(seq, "active[%d]", tz->state.active_index);
802 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
804 return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
807 static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
810 struct acpi_thermal *tz = seq->private;
816 result = acpi_thermal_get_temperature(tz);
820 seq_printf(seq, "temperature: %ld C\n",
821 KELVIN_TO_CELSIUS(tz->temperature));
827 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
829 return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
832 static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
834 struct acpi_thermal *tz = seq->private;
835 struct acpi_device *device;
845 if (tz->trips.critical.flags.valid)
846 seq_printf(seq, "critical (S5): %ld C%s",
847 KELVIN_TO_CELSIUS(tz->trips.critical.temperature),
848 nocrt ? " <disabled>\n" : "\n");
850 if (tz->trips.hot.flags.valid)
851 seq_printf(seq, "hot (S4): %ld C%s",
852 KELVIN_TO_CELSIUS(tz->trips.hot.temperature),
853 nocrt ? " <disabled>\n" : "\n");
855 if (tz->trips.passive.flags.valid) {
857 "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
858 KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
859 tz->trips.passive.tc1, tz->trips.passive.tc2,
860 tz->trips.passive.tsp);
861 for (j = 0; j < tz->trips.passive.devices.count; j++) {
862 status = acpi_bus_get_device(tz->trips.passive.devices.
863 handles[j], &device);
864 seq_printf(seq, "%4.4s ", status ? "" :
865 acpi_device_bid(device));
870 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
871 if (!(tz->trips.active[i].flags.valid))
873 seq_printf(seq, "active[%d]: %ld C: devices=",
875 KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
876 for (j = 0; j < tz->trips.active[i].devices.count; j++){
877 status = acpi_bus_get_device(tz->trips.active[i].
880 seq_printf(seq, "%4.4s ", status ? "" :
881 acpi_device_bid(device));
890 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
892 return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
895 static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
897 struct acpi_thermal *tz = seq->private;
903 if (!tz->flags.cooling_mode)
904 seq_puts(seq, "<setting not supported>\n");
906 seq_puts(seq, "0 - Active; 1 - Passive\n");
912 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
914 return single_open(file, acpi_thermal_cooling_seq_show,
919 acpi_thermal_write_cooling_mode(struct file *file,
920 const char __user * buffer,
921 size_t count, loff_t * ppos)
923 struct seq_file *m = file->private_data;
924 struct acpi_thermal *tz = m->private;
926 char mode_string[12] = { '\0' };
929 if (!tz || (count > sizeof(mode_string) - 1))
932 if (!tz->flags.cooling_mode)
935 if (copy_from_user(mode_string, buffer, count))
938 mode_string[count] = '\0';
940 result = acpi_thermal_set_cooling_mode(tz,
941 simple_strtoul(mode_string, NULL,
946 acpi_thermal_check(tz);
951 static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
953 struct acpi_thermal *tz = seq->private;
959 if (!tz->polling_frequency) {
960 seq_puts(seq, "<polling disabled>\n");
964 seq_printf(seq, "polling frequency: %lu seconds\n",
965 (tz->polling_frequency / 10));
971 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
973 return single_open(file, acpi_thermal_polling_seq_show,
978 acpi_thermal_write_polling(struct file *file,
979 const char __user * buffer,
980 size_t count, loff_t * ppos)
982 struct seq_file *m = file->private_data;
983 struct acpi_thermal *tz = m->private;
985 char polling_string[12] = { '\0' };
989 if (!tz || (count > sizeof(polling_string) - 1))
992 if (copy_from_user(polling_string, buffer, count))
995 polling_string[count] = '\0';
997 seconds = simple_strtoul(polling_string, NULL, 0);
999 result = acpi_thermal_set_polling(tz, seconds);
1003 acpi_thermal_check(tz);
1008 static int acpi_thermal_add_fs(struct acpi_device *device)
1010 struct proc_dir_entry *entry = NULL;
1013 if (!acpi_device_dir(device)) {
1014 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1016 if (!acpi_device_dir(device))
1018 acpi_device_dir(device)->owner = THIS_MODULE;
1022 entry = create_proc_entry(ACPI_THERMAL_FILE_STATE,
1023 S_IRUGO, acpi_device_dir(device));
1027 entry->proc_fops = &acpi_thermal_state_fops;
1028 entry->data = acpi_driver_data(device);
1029 entry->owner = THIS_MODULE;
1032 /* 'temperature' [R] */
1033 entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1034 S_IRUGO, acpi_device_dir(device));
1038 entry->proc_fops = &acpi_thermal_temp_fops;
1039 entry->data = acpi_driver_data(device);
1040 entry->owner = THIS_MODULE;
1043 /* 'trip_points' [R/W] */
1044 entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1045 S_IFREG | S_IRUGO | S_IWUSR,
1046 acpi_device_dir(device));
1050 entry->proc_fops = &acpi_thermal_trip_fops;
1051 entry->data = acpi_driver_data(device);
1052 entry->owner = THIS_MODULE;
1055 /* 'cooling_mode' [R/W] */
1056 entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1057 S_IFREG | S_IRUGO | S_IWUSR,
1058 acpi_device_dir(device));
1062 entry->proc_fops = &acpi_thermal_cooling_fops;
1063 entry->data = acpi_driver_data(device);
1064 entry->owner = THIS_MODULE;
1067 /* 'polling_frequency' [R/W] */
1068 entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1069 S_IFREG | S_IRUGO | S_IWUSR,
1070 acpi_device_dir(device));
1074 entry->proc_fops = &acpi_thermal_polling_fops;
1075 entry->data = acpi_driver_data(device);
1076 entry->owner = THIS_MODULE;
1082 static int acpi_thermal_remove_fs(struct acpi_device *device)
1085 if (acpi_device_dir(device)) {
1086 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1087 acpi_device_dir(device));
1088 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1089 acpi_device_dir(device));
1090 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1091 acpi_device_dir(device));
1092 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1093 acpi_device_dir(device));
1094 remove_proc_entry(ACPI_THERMAL_FILE_STATE,
1095 acpi_device_dir(device));
1096 remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
1097 acpi_device_dir(device) = NULL;
1103 /* --------------------------------------------------------------------------
1105 -------------------------------------------------------------------------- */
1107 static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
1109 struct acpi_thermal *tz = data;
1110 struct acpi_device *device = NULL;
1116 device = tz->device;
1119 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
1120 acpi_thermal_check(tz);
1122 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
1123 acpi_thermal_get_trip_points(tz);
1124 acpi_thermal_check(tz);
1125 acpi_bus_generate_event(device, event, 0);
1127 case ACPI_THERMAL_NOTIFY_DEVICES:
1128 if (tz->flags.devices)
1129 acpi_thermal_get_devices(tz);
1130 acpi_bus_generate_event(device, event, 0);
1133 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1134 "Unsupported event [0x%x]\n", event));
1141 static int acpi_thermal_get_info(struct acpi_thermal *tz)
1149 /* Get temperature [_TMP] (required) */
1150 result = acpi_thermal_get_temperature(tz);
1154 /* Get trip points [_CRT, _PSV, etc.] (required) */
1155 result = acpi_thermal_get_trip_points(tz);
1159 /* Set the cooling mode [_SCP] to active cooling (default) */
1160 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
1162 tz->flags.cooling_mode = 1;
1164 /* Get default polling frequency [_TZP] (optional) */
1166 tz->polling_frequency = tzp;
1168 acpi_thermal_get_polling_frequency(tz);
1170 /* Get devices in this thermal zone [_TZD] (optional) */
1171 result = acpi_thermal_get_devices(tz);
1173 tz->flags.devices = 1;
1178 static int acpi_thermal_add(struct acpi_device *device)
1181 acpi_status status = AE_OK;
1182 struct acpi_thermal *tz = NULL;
1188 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1192 tz->device = device;
1193 strcpy(tz->name, device->pnp.bus_id);
1194 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1195 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
1196 acpi_driver_data(device) = tz;
1198 result = acpi_thermal_get_info(tz);
1202 result = acpi_thermal_add_fs(device);
1206 init_timer(&tz->timer);
1208 acpi_thermal_check(tz);
1210 status = acpi_install_notify_handler(device->handle,
1212 acpi_thermal_notify, tz);
1213 if (ACPI_FAILURE(status)) {
1218 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
1219 acpi_device_name(device), acpi_device_bid(device),
1220 KELVIN_TO_CELSIUS(tz->temperature));
1224 acpi_thermal_remove_fs(device);
1231 static int acpi_thermal_remove(struct acpi_device *device, int type)
1233 acpi_status status = AE_OK;
1234 struct acpi_thermal *tz = NULL;
1237 if (!device || !acpi_driver_data(device))
1240 tz = acpi_driver_data(device);
1242 /* avoid timer adding new defer task */
1244 /* wait for running timer (on other CPUs) finish */
1245 del_timer_sync(&(tz->timer));
1246 /* synchronize deferred task */
1247 acpi_os_wait_events_complete(NULL);
1248 /* deferred task may reinsert timer */
1249 del_timer_sync(&(tz->timer));
1251 status = acpi_remove_notify_handler(device->handle,
1253 acpi_thermal_notify);
1255 /* Terminate policy */
1256 if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
1257 tz->trips.passive.flags.enabled = 0;
1258 acpi_thermal_passive(tz);
1260 if (tz->trips.active[0].flags.valid
1261 && tz->trips.active[0].flags.enabled) {
1262 tz->trips.active[0].flags.enabled = 0;
1263 acpi_thermal_active(tz);
1266 acpi_thermal_remove_fs(device);
1272 static int acpi_thermal_resume(struct acpi_device *device)
1274 struct acpi_thermal *tz = NULL;
1275 int i, j, power_state, result;
1278 if (!device || !acpi_driver_data(device))
1281 tz = acpi_driver_data(device);
1283 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1284 if (!(&tz->trips.active[i]))
1286 if (!tz->trips.active[i].flags.valid)
1288 tz->trips.active[i].flags.enabled = 1;
1289 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1290 result = acpi_bus_get_power(tz->trips.active[i].devices.
1291 handles[j], &power_state);
1292 if (result || (power_state != ACPI_STATE_D0)) {
1293 tz->trips.active[i].flags.enabled = 0;
1297 tz->state.active |= tz->trips.active[i].flags.enabled;
1300 acpi_thermal_check(tz);
1305 static int __init acpi_thermal_init(void)
1310 printk(KERN_NOTICE "ACPI: thermal control disabled\n");
1313 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
1314 if (!acpi_thermal_dir)
1316 acpi_thermal_dir->owner = THIS_MODULE;
1318 result = acpi_bus_register_driver(&acpi_thermal_driver);
1320 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1327 static void __exit acpi_thermal_exit(void)
1330 acpi_bus_unregister_driver(&acpi_thermal_driver);
1332 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1337 module_init(acpi_thermal_init);
1338 module_exit(acpi_thermal_exit);