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(off, int, 0);
83 MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.\n");
86 module_param(psv, int, 0644);
87 MODULE_PARM_DESC(psv, "Disable or override all passive trip points.\n");
89 static int acpi_thermal_add(struct acpi_device *device);
90 static int acpi_thermal_remove(struct acpi_device *device, int type);
91 static int acpi_thermal_resume(struct acpi_device *device);
92 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
93 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
94 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
95 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
96 static ssize_t acpi_thermal_write_cooling_mode(struct file *,
97 const char __user *, size_t,
99 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
100 static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
103 static const struct acpi_device_id thermal_device_ids[] = {
104 {ACPI_THERMAL_HID, 0},
107 MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
109 static struct acpi_driver acpi_thermal_driver = {
111 .class = ACPI_THERMAL_CLASS,
112 .ids = thermal_device_ids,
114 .add = acpi_thermal_add,
115 .remove = acpi_thermal_remove,
116 .resume = acpi_thermal_resume,
120 struct acpi_thermal_state {
129 struct acpi_thermal_state_flags {
135 struct acpi_thermal_critical {
136 struct acpi_thermal_state_flags flags;
137 unsigned long temperature;
140 struct acpi_thermal_hot {
141 struct acpi_thermal_state_flags flags;
142 unsigned long temperature;
145 struct acpi_thermal_passive {
146 struct acpi_thermal_state_flags flags;
147 unsigned long temperature;
151 struct acpi_handle_list devices;
154 struct acpi_thermal_active {
155 struct acpi_thermal_state_flags flags;
156 unsigned long temperature;
157 struct acpi_handle_list devices;
160 struct acpi_thermal_trips {
161 struct acpi_thermal_critical critical;
162 struct acpi_thermal_hot hot;
163 struct acpi_thermal_passive passive;
164 struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
167 struct acpi_thermal_flags {
168 u8 cooling_mode:1; /* _SCP */
169 u8 devices:1; /* _TZD */
173 struct acpi_thermal {
174 struct acpi_device * device;
176 unsigned long temperature;
177 unsigned long last_temperature;
178 unsigned long polling_frequency;
180 struct acpi_thermal_flags flags;
181 struct acpi_thermal_state state;
182 struct acpi_thermal_trips trips;
183 struct acpi_handle_list devices;
184 struct timer_list timer;
187 static const struct file_operations acpi_thermal_state_fops = {
188 .open = acpi_thermal_state_open_fs,
191 .release = single_release,
194 static const struct file_operations acpi_thermal_temp_fops = {
195 .open = acpi_thermal_temp_open_fs,
198 .release = single_release,
201 static const struct file_operations acpi_thermal_trip_fops = {
202 .open = acpi_thermal_trip_open_fs,
205 .release = single_release,
208 static const struct file_operations acpi_thermal_cooling_fops = {
209 .open = acpi_thermal_cooling_open_fs,
211 .write = acpi_thermal_write_cooling_mode,
213 .release = single_release,
216 static const struct file_operations acpi_thermal_polling_fops = {
217 .open = acpi_thermal_polling_open_fs,
219 .write = acpi_thermal_write_polling,
221 .release = single_release,
224 /* --------------------------------------------------------------------------
225 Thermal Zone Management
226 -------------------------------------------------------------------------- */
228 static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
230 acpi_status status = AE_OK;
236 tz->last_temperature = tz->temperature;
239 acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tz->temperature);
240 if (ACPI_FAILURE(status))
243 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
249 static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
251 acpi_status status = AE_OK;
258 acpi_evaluate_integer(tz->device->handle, "_TZP", NULL,
259 &tz->polling_frequency);
260 if (ACPI_FAILURE(status))
263 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
264 tz->polling_frequency));
269 static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
275 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
277 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
278 "Polling frequency set to %lu seconds\n",
279 tz->polling_frequency/10));
284 static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
286 acpi_status status = AE_OK;
287 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
288 struct acpi_object_list arg_list = { 1, &arg0 };
289 acpi_handle handle = NULL;
295 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
296 if (ACPI_FAILURE(status)) {
297 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
301 arg0.integer.value = mode;
303 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
304 if (ACPI_FAILURE(status))
310 static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
312 acpi_status status = AE_OK;
319 /* Critical Shutdown (required) */
321 status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL,
322 &tz->trips.critical.temperature);
323 if (ACPI_FAILURE(status)) {
324 tz->trips.critical.flags.valid = 0;
325 ACPI_EXCEPTION((AE_INFO, status, "No critical threshold"));
328 tz->trips.critical.flags.valid = 1;
329 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
330 "Found critical threshold [%lu]\n",
331 tz->trips.critical.temperature));
334 /* Critical Sleep (optional) */
337 acpi_evaluate_integer(tz->device->handle, "_HOT", NULL,
338 &tz->trips.hot.temperature);
339 if (ACPI_FAILURE(status)) {
340 tz->trips.hot.flags.valid = 0;
341 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No hot threshold\n"));
343 tz->trips.hot.flags.valid = 1;
344 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found hot threshold [%lu]\n",
345 tz->trips.hot.temperature));
348 /* Passive: Processors (optional) */
352 } else if (psv > 0) {
353 tz->trips.passive.temperature = CELSIUS_TO_KELVIN(psv);
356 status = acpi_evaluate_integer(tz->device->handle,
357 "_PSV", NULL, &tz->trips.passive.temperature);
360 if (ACPI_FAILURE(status)) {
361 tz->trips.passive.flags.valid = 0;
362 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No passive threshold\n"));
364 tz->trips.passive.flags.valid = 1;
367 acpi_evaluate_integer(tz->device->handle, "_TC1", NULL,
368 &tz->trips.passive.tc1);
369 if (ACPI_FAILURE(status))
370 tz->trips.passive.flags.valid = 0;
373 acpi_evaluate_integer(tz->device->handle, "_TC2", NULL,
374 &tz->trips.passive.tc2);
375 if (ACPI_FAILURE(status))
376 tz->trips.passive.flags.valid = 0;
379 acpi_evaluate_integer(tz->device->handle, "_TSP", NULL,
380 &tz->trips.passive.tsp);
381 if (ACPI_FAILURE(status))
382 tz->trips.passive.flags.valid = 0;
385 acpi_evaluate_reference(tz->device->handle, "_PSL", NULL,
386 &tz->trips.passive.devices);
387 if (ACPI_FAILURE(status))
388 tz->trips.passive.flags.valid = 0;
390 if (!tz->trips.passive.flags.valid)
391 printk(KERN_WARNING PREFIX "Invalid passive threshold\n");
393 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
394 "Found passive threshold [%lu]\n",
395 tz->trips.passive.temperature));
398 /* Active: Fans, etc. (optional) */
400 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
402 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
405 acpi_evaluate_integer(tz->device->handle, name, NULL,
406 &tz->trips.active[i].temperature);
407 if (ACPI_FAILURE(status))
412 acpi_evaluate_reference(tz->device->handle, name, NULL,
413 &tz->trips.active[i].devices);
414 if (ACPI_SUCCESS(status)) {
415 tz->trips.active[i].flags.valid = 1;
416 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
417 "Found active threshold [%d]:[%lu]\n",
418 i, tz->trips.active[i].temperature));
420 ACPI_EXCEPTION((AE_INFO, status,
421 "Invalid active threshold [%d]", i));
427 static int acpi_thermal_get_devices(struct acpi_thermal *tz)
429 acpi_status status = AE_OK;
436 acpi_evaluate_reference(tz->device->handle, "_TZD", NULL, &tz->devices);
437 if (ACPI_FAILURE(status))
443 static int acpi_thermal_critical(struct acpi_thermal *tz)
445 if (!tz || !tz->trips.critical.flags.valid)
448 if (tz->temperature >= tz->trips.critical.temperature) {
449 printk(KERN_WARNING PREFIX "Critical trip point\n");
450 tz->trips.critical.flags.enabled = 1;
451 } else if (tz->trips.critical.flags.enabled)
452 tz->trips.critical.flags.enabled = 0;
455 "Critical temperature reached (%ld C), shutting down.\n",
456 KELVIN_TO_CELSIUS(tz->temperature));
457 acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL,
458 tz->trips.critical.flags.enabled);
460 orderly_poweroff(true);
465 static int acpi_thermal_hot(struct acpi_thermal *tz)
467 if (!tz || !tz->trips.hot.flags.valid)
470 if (tz->temperature >= tz->trips.hot.temperature) {
471 printk(KERN_WARNING PREFIX "Hot trip point\n");
472 tz->trips.hot.flags.enabled = 1;
473 } else if (tz->trips.hot.flags.enabled)
474 tz->trips.hot.flags.enabled = 0;
476 acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
477 tz->trips.hot.flags.enabled);
479 /* TBD: Call user-mode "sleep(S4)" function */
484 static void acpi_thermal_passive(struct acpi_thermal *tz)
487 struct acpi_thermal_passive *passive = NULL;
492 if (!tz || !tz->trips.passive.flags.valid)
495 passive = &(tz->trips.passive);
500 * Calculate the thermal trend (using the passive cooling equation)
501 * and modify the performance limit for all passive cooling devices
502 * accordingly. Note that we assume symmetry.
504 if (tz->temperature >= passive->temperature) {
506 (passive->tc1 * (tz->temperature - tz->last_temperature)) +
507 (passive->tc2 * (tz->temperature - passive->temperature));
508 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
509 "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
510 trend, passive->tc1, tz->temperature,
511 tz->last_temperature, passive->tc2,
512 tz->temperature, passive->temperature));
513 passive->flags.enabled = 1;
516 for (i = 0; i < passive->devices.count; i++)
517 acpi_processor_set_thermal_limit(passive->
520 ACPI_PROCESSOR_LIMIT_INCREMENT);
522 else if (trend < 0) {
523 for (i = 0; i < passive->devices.count; i++)
525 * assume that we are on highest
526 * freq/lowest thrott and can leave
527 * passive mode, even in error case
529 if (!acpi_processor_set_thermal_limit
530 (passive->devices.handles[i],
531 ACPI_PROCESSOR_LIMIT_DECREMENT))
534 * Leave cooling mode, even if the temp might
535 * higher than trip point This is because some
536 * machines might have long thermal polling
537 * frequencies (tsp) defined. We will fall back
538 * into passive mode in next cycle (probably quicker)
541 passive->flags.enabled = 0;
542 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
543 "Disabling passive cooling, still above threshold,"
544 " but we are cooling down\n"));
553 * Implement passive cooling hysteresis to slowly increase performance
554 * and avoid thrashing around the passive trip point. Note that we
557 if (!passive->flags.enabled)
559 for (i = 0; i < passive->devices.count; i++)
560 if (!acpi_processor_set_thermal_limit
561 (passive->devices.handles[i],
562 ACPI_PROCESSOR_LIMIT_DECREMENT))
565 passive->flags.enabled = 0;
566 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
567 "Disabling passive cooling (zone is cool)\n"));
571 static void acpi_thermal_active(struct acpi_thermal *tz)
574 struct acpi_thermal_active *active = NULL;
577 unsigned long maxtemp = 0;
583 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
584 active = &(tz->trips.active[i]);
585 if (!active || !active->flags.valid)
587 if (tz->temperature >= active->temperature) {
591 * If not already enabled, turn ON all cooling devices
592 * associated with this active threshold.
594 if (active->temperature > maxtemp)
595 tz->state.active_index = i;
596 maxtemp = active->temperature;
597 if (active->flags.enabled)
599 for (j = 0; j < active->devices.count; j++) {
601 acpi_bus_set_power(active->devices.
605 printk(KERN_WARNING PREFIX
606 "Unable to turn cooling device [%p] 'on'\n",
611 active->flags.enabled = 1;
612 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
613 "Cooling device [%p] now 'on'\n",
614 active->devices.handles[j]));
618 if (!active->flags.enabled)
623 * Turn OFF all cooling devices associated with this
626 for (j = 0; j < active->devices.count; j++) {
627 result = acpi_bus_set_power(active->devices.handles[j],
630 printk(KERN_WARNING PREFIX
631 "Unable to turn cooling device [%p] 'off'\n",
632 active->devices.handles[j]);
635 active->flags.enabled = 0;
636 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
637 "Cooling device [%p] now 'off'\n",
638 active->devices.handles[j]));
643 static void acpi_thermal_check(void *context);
645 static void acpi_thermal_run(unsigned long data)
647 struct acpi_thermal *tz = (struct acpi_thermal *)data;
649 acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data);
652 static void acpi_thermal_check(void *data)
655 struct acpi_thermal *tz = data;
656 unsigned long sleep_time = 0;
658 struct acpi_thermal_state state;
662 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
668 result = acpi_thermal_get_temperature(tz);
672 memset(&tz->state, 0, sizeof(tz->state));
677 * Compare the current temperature to the trip point values to see
678 * if we've entered one of the thermal policy states. Note that
679 * this function determines when a state is entered, but the
680 * individual policy decides when it is exited (e.g. hysteresis).
682 if (tz->trips.critical.flags.valid)
684 (tz->temperature >= tz->trips.critical.temperature);
685 if (tz->trips.hot.flags.valid)
686 state.hot |= (tz->temperature >= tz->trips.hot.temperature);
687 if (tz->trips.passive.flags.valid)
689 (tz->temperature >= tz->trips.passive.temperature);
690 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
691 if (tz->trips.active[i].flags.valid)
694 tz->trips.active[i].temperature);
699 * Separated from the above check to allow individual policy to
700 * determine when to exit a given state.
703 acpi_thermal_critical(tz);
705 acpi_thermal_hot(tz);
707 acpi_thermal_passive(tz);
709 acpi_thermal_active(tz);
714 * Again, separated from the above two to allow independent policy
717 tz->state.critical = tz->trips.critical.flags.enabled;
718 tz->state.hot = tz->trips.hot.flags.enabled;
719 tz->state.passive = tz->trips.passive.flags.enabled;
720 tz->state.active = 0;
721 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
722 tz->state.active |= tz->trips.active[i].flags.enabled;
725 * Calculate Sleep Time
726 * --------------------
727 * If we're in the passive state, use _TSP's value. Otherwise
728 * use the default polling frequency (e.g. _TZP). If no polling
729 * frequency is specified then we'll wait forever (at least until
730 * a thermal event occurs). Note that _TSP and _TZD values are
731 * given in 1/10th seconds (we must covert to milliseconds).
733 if (tz->state.passive)
734 sleep_time = tz->trips.passive.tsp * 100;
735 else if (tz->polling_frequency > 0)
736 sleep_time = tz->polling_frequency * 100;
738 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n",
739 tz->name, tz->temperature, sleep_time));
746 if (timer_pending(&(tz->timer)))
747 del_timer(&(tz->timer));
749 if (timer_pending(&(tz->timer)))
750 mod_timer(&(tz->timer),
751 jiffies + (HZ * sleep_time) / 1000);
753 tz->timer.data = (unsigned long)tz;
754 tz->timer.function = acpi_thermal_run;
755 tz->timer.expires = jiffies + (HZ * sleep_time) / 1000;
756 add_timer(&(tz->timer));
763 /* --------------------------------------------------------------------------
765 -------------------------------------------------------------------------- */
767 static struct proc_dir_entry *acpi_thermal_dir;
769 static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
771 struct acpi_thermal *tz = seq->private;
777 seq_puts(seq, "state: ");
779 if (!tz->state.critical && !tz->state.hot && !tz->state.passive
780 && !tz->state.active)
781 seq_puts(seq, "ok\n");
783 if (tz->state.critical)
784 seq_puts(seq, "critical ");
786 seq_puts(seq, "hot ");
787 if (tz->state.passive)
788 seq_puts(seq, "passive ");
789 if (tz->state.active)
790 seq_printf(seq, "active[%d]", tz->state.active_index);
798 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
800 return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
803 static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
806 struct acpi_thermal *tz = seq->private;
812 result = acpi_thermal_get_temperature(tz);
816 seq_printf(seq, "temperature: %ld C\n",
817 KELVIN_TO_CELSIUS(tz->temperature));
823 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
825 return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
828 static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
830 struct acpi_thermal *tz = seq->private;
831 struct acpi_device *device;
841 if (tz->trips.critical.flags.valid)
842 seq_printf(seq, "critical (S5): %ld C\n",
843 KELVIN_TO_CELSIUS(tz->trips.critical.temperature));
845 if (tz->trips.hot.flags.valid)
846 seq_printf(seq, "hot (S4): %ld C\n",
847 KELVIN_TO_CELSIUS(tz->trips.hot.temperature));
849 if (tz->trips.passive.flags.valid) {
851 "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
852 KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
853 tz->trips.passive.tc1, tz->trips.passive.tc2,
854 tz->trips.passive.tsp);
855 for (j = 0; j < tz->trips.passive.devices.count; j++) {
856 status = acpi_bus_get_device(tz->trips.passive.devices.
857 handles[j], &device);
858 seq_printf(seq, "%4.4s ", status ? "" :
859 acpi_device_bid(device));
864 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
865 if (!(tz->trips.active[i].flags.valid))
867 seq_printf(seq, "active[%d]: %ld C: devices=",
869 KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
870 for (j = 0; j < tz->trips.active[i].devices.count; j++){
871 status = acpi_bus_get_device(tz->trips.active[i].
874 seq_printf(seq, "%4.4s ", status ? "" :
875 acpi_device_bid(device));
884 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
886 return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
889 static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
891 struct acpi_thermal *tz = seq->private;
897 if (!tz->flags.cooling_mode)
898 seq_puts(seq, "<setting not supported>\n");
900 seq_puts(seq, "0 - Active; 1 - Passive\n");
906 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
908 return single_open(file, acpi_thermal_cooling_seq_show,
913 acpi_thermal_write_cooling_mode(struct file *file,
914 const char __user * buffer,
915 size_t count, loff_t * ppos)
917 struct seq_file *m = file->private_data;
918 struct acpi_thermal *tz = m->private;
920 char mode_string[12] = { '\0' };
923 if (!tz || (count > sizeof(mode_string) - 1))
926 if (!tz->flags.cooling_mode)
929 if (copy_from_user(mode_string, buffer, count))
932 mode_string[count] = '\0';
934 result = acpi_thermal_set_cooling_mode(tz,
935 simple_strtoul(mode_string, NULL,
940 acpi_thermal_check(tz);
945 static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
947 struct acpi_thermal *tz = seq->private;
953 if (!tz->polling_frequency) {
954 seq_puts(seq, "<polling disabled>\n");
958 seq_printf(seq, "polling frequency: %lu seconds\n",
959 (tz->polling_frequency / 10));
965 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
967 return single_open(file, acpi_thermal_polling_seq_show,
972 acpi_thermal_write_polling(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 polling_string[12] = { '\0' };
983 if (!tz || (count > sizeof(polling_string) - 1))
986 if (copy_from_user(polling_string, buffer, count))
989 polling_string[count] = '\0';
991 seconds = simple_strtoul(polling_string, NULL, 0);
993 result = acpi_thermal_set_polling(tz, seconds);
997 acpi_thermal_check(tz);
1002 static int acpi_thermal_add_fs(struct acpi_device *device)
1004 struct proc_dir_entry *entry = NULL;
1007 if (!acpi_device_dir(device)) {
1008 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1010 if (!acpi_device_dir(device))
1012 acpi_device_dir(device)->owner = THIS_MODULE;
1016 entry = create_proc_entry(ACPI_THERMAL_FILE_STATE,
1017 S_IRUGO, acpi_device_dir(device));
1021 entry->proc_fops = &acpi_thermal_state_fops;
1022 entry->data = acpi_driver_data(device);
1023 entry->owner = THIS_MODULE;
1026 /* 'temperature' [R] */
1027 entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1028 S_IRUGO, acpi_device_dir(device));
1032 entry->proc_fops = &acpi_thermal_temp_fops;
1033 entry->data = acpi_driver_data(device);
1034 entry->owner = THIS_MODULE;
1037 /* 'trip_points' [R/W] */
1038 entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1039 S_IFREG | S_IRUGO | S_IWUSR,
1040 acpi_device_dir(device));
1044 entry->proc_fops = &acpi_thermal_trip_fops;
1045 entry->data = acpi_driver_data(device);
1046 entry->owner = THIS_MODULE;
1049 /* 'cooling_mode' [R/W] */
1050 entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1051 S_IFREG | S_IRUGO | S_IWUSR,
1052 acpi_device_dir(device));
1056 entry->proc_fops = &acpi_thermal_cooling_fops;
1057 entry->data = acpi_driver_data(device);
1058 entry->owner = THIS_MODULE;
1061 /* 'polling_frequency' [R/W] */
1062 entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1063 S_IFREG | S_IRUGO | S_IWUSR,
1064 acpi_device_dir(device));
1068 entry->proc_fops = &acpi_thermal_polling_fops;
1069 entry->data = acpi_driver_data(device);
1070 entry->owner = THIS_MODULE;
1076 static int acpi_thermal_remove_fs(struct acpi_device *device)
1079 if (acpi_device_dir(device)) {
1080 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1081 acpi_device_dir(device));
1082 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1083 acpi_device_dir(device));
1084 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1085 acpi_device_dir(device));
1086 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1087 acpi_device_dir(device));
1088 remove_proc_entry(ACPI_THERMAL_FILE_STATE,
1089 acpi_device_dir(device));
1090 remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
1091 acpi_device_dir(device) = NULL;
1097 /* --------------------------------------------------------------------------
1099 -------------------------------------------------------------------------- */
1101 static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
1103 struct acpi_thermal *tz = data;
1104 struct acpi_device *device = NULL;
1110 device = tz->device;
1113 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
1114 acpi_thermal_check(tz);
1116 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
1117 acpi_thermal_get_trip_points(tz);
1118 acpi_thermal_check(tz);
1119 acpi_bus_generate_event(device, event, 0);
1121 case ACPI_THERMAL_NOTIFY_DEVICES:
1122 if (tz->flags.devices)
1123 acpi_thermal_get_devices(tz);
1124 acpi_bus_generate_event(device, event, 0);
1127 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1128 "Unsupported event [0x%x]\n", event));
1135 static int acpi_thermal_get_info(struct acpi_thermal *tz)
1143 /* Get temperature [_TMP] (required) */
1144 result = acpi_thermal_get_temperature(tz);
1148 /* Get trip points [_CRT, _PSV, etc.] (required) */
1149 result = acpi_thermal_get_trip_points(tz);
1153 /* Set the cooling mode [_SCP] to active cooling (default) */
1154 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
1156 tz->flags.cooling_mode = 1;
1158 /* Get default polling frequency [_TZP] (optional) */
1160 tz->polling_frequency = tzp;
1162 acpi_thermal_get_polling_frequency(tz);
1164 /* Get devices in this thermal zone [_TZD] (optional) */
1165 result = acpi_thermal_get_devices(tz);
1167 tz->flags.devices = 1;
1172 static int acpi_thermal_add(struct acpi_device *device)
1175 acpi_status status = AE_OK;
1176 struct acpi_thermal *tz = NULL;
1182 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1186 tz->device = device;
1187 strcpy(tz->name, device->pnp.bus_id);
1188 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1189 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
1190 acpi_driver_data(device) = tz;
1192 result = acpi_thermal_get_info(tz);
1196 result = acpi_thermal_add_fs(device);
1200 init_timer(&tz->timer);
1202 acpi_thermal_check(tz);
1204 status = acpi_install_notify_handler(device->handle,
1206 acpi_thermal_notify, tz);
1207 if (ACPI_FAILURE(status)) {
1212 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
1213 acpi_device_name(device), acpi_device_bid(device),
1214 KELVIN_TO_CELSIUS(tz->temperature));
1218 acpi_thermal_remove_fs(device);
1225 static int acpi_thermal_remove(struct acpi_device *device, int type)
1227 acpi_status status = AE_OK;
1228 struct acpi_thermal *tz = NULL;
1231 if (!device || !acpi_driver_data(device))
1234 tz = acpi_driver_data(device);
1236 /* avoid timer adding new defer task */
1238 /* wait for running timer (on other CPUs) finish */
1239 del_timer_sync(&(tz->timer));
1240 /* synchronize deferred task */
1241 acpi_os_wait_events_complete(NULL);
1242 /* deferred task may reinsert timer */
1243 del_timer_sync(&(tz->timer));
1245 status = acpi_remove_notify_handler(device->handle,
1247 acpi_thermal_notify);
1249 /* Terminate policy */
1250 if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
1251 tz->trips.passive.flags.enabled = 0;
1252 acpi_thermal_passive(tz);
1254 if (tz->trips.active[0].flags.valid
1255 && tz->trips.active[0].flags.enabled) {
1256 tz->trips.active[0].flags.enabled = 0;
1257 acpi_thermal_active(tz);
1260 acpi_thermal_remove_fs(device);
1266 static int acpi_thermal_resume(struct acpi_device *device)
1268 struct acpi_thermal *tz = NULL;
1269 int i, j, power_state, result;
1272 if (!device || !acpi_driver_data(device))
1275 tz = acpi_driver_data(device);
1277 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1278 if (!(&tz->trips.active[i]))
1280 if (!tz->trips.active[i].flags.valid)
1282 tz->trips.active[i].flags.enabled = 1;
1283 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1284 result = acpi_bus_get_power(tz->trips.active[i].devices.
1285 handles[j], &power_state);
1286 if (result || (power_state != ACPI_STATE_D0)) {
1287 tz->trips.active[i].flags.enabled = 0;
1291 tz->state.active |= tz->trips.active[i].flags.enabled;
1294 acpi_thermal_check(tz);
1299 static int __init acpi_thermal_init(void)
1304 printk(KERN_NOTICE "ACPI: thermal control disabled\n");
1307 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
1308 if (!acpi_thermal_dir)
1310 acpi_thermal_dir->owner = THIS_MODULE;
1312 result = acpi_bus_register_driver(&acpi_thermal_driver);
1314 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1321 static void __exit acpi_thermal_exit(void)
1324 acpi_bus_unregister_driver(&acpi_thermal_driver);
1326 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1331 module_init(acpi_thermal_init);
1332 module_exit(acpi_thermal_exit);