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 <asm/uaccess.h>
45 #include <acpi/acpi_bus.h>
46 #include <acpi/acpi_drivers.h>
48 #define ACPI_THERMAL_COMPONENT 0x04000000
49 #define ACPI_THERMAL_CLASS "thermal_zone"
50 #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
51 #define ACPI_THERMAL_FILE_STATE "state"
52 #define ACPI_THERMAL_FILE_TEMPERATURE "temperature"
53 #define ACPI_THERMAL_FILE_TRIP_POINTS "trip_points"
54 #define ACPI_THERMAL_FILE_COOLING_MODE "cooling_mode"
55 #define ACPI_THERMAL_FILE_POLLING_FREQ "polling_frequency"
56 #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80
57 #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81
58 #define ACPI_THERMAL_NOTIFY_DEVICES 0x82
59 #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0
60 #define ACPI_THERMAL_NOTIFY_HOT 0xF1
61 #define ACPI_THERMAL_MODE_ACTIVE 0x00
62 #define ACPI_THERMAL_MODE_PASSIVE 0x01
63 #define ACPI_THERMAL_MODE_CRITICAL 0xff
64 #define ACPI_THERMAL_PATH_POWEROFF "/sbin/poweroff"
66 #define ACPI_THERMAL_MAX_ACTIVE 10
67 #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
69 #define KELVIN_TO_CELSIUS(t) (long)(((long)t-2732>=0) ? ((long)t-2732+5)/10 : ((long)t-2732-5)/10)
70 #define CELSIUS_TO_KELVIN(t) ((t+273)*10)
72 #define _COMPONENT ACPI_THERMAL_COMPONENT
73 ACPI_MODULE_NAME("thermal");
75 MODULE_AUTHOR("Paul Diefenbaugh");
76 MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
77 MODULE_LICENSE("GPL");
80 module_param(tzp, int, 0);
81 MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.\n");
83 static int acpi_thermal_add(struct acpi_device *device);
84 static int acpi_thermal_remove(struct acpi_device *device, int type);
85 static int acpi_thermal_resume(struct acpi_device *device);
86 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
87 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
88 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
89 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
90 static ssize_t acpi_thermal_write_cooling_mode(struct file *,
91 const char __user *, size_t,
93 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
94 static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
97 static struct acpi_driver acpi_thermal_driver = {
99 .class = ACPI_THERMAL_CLASS,
100 .ids = ACPI_THERMAL_HID,
102 .add = acpi_thermal_add,
103 .remove = acpi_thermal_remove,
104 .resume = acpi_thermal_resume,
108 struct acpi_thermal_state {
117 struct acpi_thermal_state_flags {
123 struct acpi_thermal_critical {
124 struct acpi_thermal_state_flags flags;
125 unsigned long temperature;
128 struct acpi_thermal_hot {
129 struct acpi_thermal_state_flags flags;
130 unsigned long temperature;
133 struct acpi_thermal_passive {
134 struct acpi_thermal_state_flags flags;
135 unsigned long temperature;
139 struct acpi_handle_list devices;
142 struct acpi_thermal_active {
143 struct acpi_thermal_state_flags flags;
144 unsigned long temperature;
145 struct acpi_handle_list devices;
148 struct acpi_thermal_trips {
149 struct acpi_thermal_critical critical;
150 struct acpi_thermal_hot hot;
151 struct acpi_thermal_passive passive;
152 struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
155 struct acpi_thermal_flags {
156 u8 cooling_mode:1; /* _SCP */
157 u8 devices:1; /* _TZD */
161 struct acpi_thermal {
162 struct acpi_device * device;
164 unsigned long temperature;
165 unsigned long last_temperature;
166 unsigned long polling_frequency;
169 struct acpi_thermal_flags flags;
170 struct acpi_thermal_state state;
171 struct acpi_thermal_trips trips;
172 struct acpi_handle_list devices;
173 struct timer_list timer;
176 static const struct file_operations acpi_thermal_state_fops = {
177 .open = acpi_thermal_state_open_fs,
180 .release = single_release,
183 static const struct file_operations acpi_thermal_temp_fops = {
184 .open = acpi_thermal_temp_open_fs,
187 .release = single_release,
190 static const struct file_operations acpi_thermal_trip_fops = {
191 .open = acpi_thermal_trip_open_fs,
194 .release = single_release,
197 static const struct file_operations acpi_thermal_cooling_fops = {
198 .open = acpi_thermal_cooling_open_fs,
200 .write = acpi_thermal_write_cooling_mode,
202 .release = single_release,
205 static const struct file_operations acpi_thermal_polling_fops = {
206 .open = acpi_thermal_polling_open_fs,
208 .write = acpi_thermal_write_polling,
210 .release = single_release,
213 /* --------------------------------------------------------------------------
214 Thermal Zone Management
215 -------------------------------------------------------------------------- */
217 static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
219 acpi_status status = AE_OK;
225 tz->last_temperature = tz->temperature;
228 acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tz->temperature);
229 if (ACPI_FAILURE(status))
232 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
238 static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
240 acpi_status status = AE_OK;
247 acpi_evaluate_integer(tz->device->handle, "_TZP", NULL,
248 &tz->polling_frequency);
249 if (ACPI_FAILURE(status))
252 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
253 tz->polling_frequency));
258 static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
264 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
266 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
267 "Polling frequency set to %lu seconds\n",
268 tz->polling_frequency/10));
273 static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
275 acpi_status status = AE_OK;
276 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
277 struct acpi_object_list arg_list = { 1, &arg0 };
278 acpi_handle handle = NULL;
284 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
285 if (ACPI_FAILURE(status)) {
286 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
290 arg0.integer.value = mode;
292 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
293 if (ACPI_FAILURE(status))
296 tz->cooling_mode = mode;
298 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Cooling mode [%s]\n",
299 mode ? "passive" : "active"));
304 static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
306 acpi_status status = AE_OK;
313 /* Critical Shutdown (required) */
315 status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL,
316 &tz->trips.critical.temperature);
317 if (ACPI_FAILURE(status)) {
318 tz->trips.critical.flags.valid = 0;
319 ACPI_EXCEPTION((AE_INFO, status, "No critical threshold"));
322 tz->trips.critical.flags.valid = 1;
323 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
324 "Found critical threshold [%lu]\n",
325 tz->trips.critical.temperature));
328 /* Critical Sleep (optional) */
331 acpi_evaluate_integer(tz->device->handle, "_HOT", NULL,
332 &tz->trips.hot.temperature);
333 if (ACPI_FAILURE(status)) {
334 tz->trips.hot.flags.valid = 0;
335 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No hot threshold\n"));
337 tz->trips.hot.flags.valid = 1;
338 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found hot threshold [%lu]\n",
339 tz->trips.hot.temperature));
342 /* Passive: Processors (optional) */
345 acpi_evaluate_integer(tz->device->handle, "_PSV", NULL,
346 &tz->trips.passive.temperature);
347 if (ACPI_FAILURE(status)) {
348 tz->trips.passive.flags.valid = 0;
349 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No passive threshold\n"));
351 tz->trips.passive.flags.valid = 1;
354 acpi_evaluate_integer(tz->device->handle, "_TC1", NULL,
355 &tz->trips.passive.tc1);
356 if (ACPI_FAILURE(status))
357 tz->trips.passive.flags.valid = 0;
360 acpi_evaluate_integer(tz->device->handle, "_TC2", NULL,
361 &tz->trips.passive.tc2);
362 if (ACPI_FAILURE(status))
363 tz->trips.passive.flags.valid = 0;
366 acpi_evaluate_integer(tz->device->handle, "_TSP", NULL,
367 &tz->trips.passive.tsp);
368 if (ACPI_FAILURE(status))
369 tz->trips.passive.flags.valid = 0;
372 acpi_evaluate_reference(tz->device->handle, "_PSL", NULL,
373 &tz->trips.passive.devices);
374 if (ACPI_FAILURE(status))
375 tz->trips.passive.flags.valid = 0;
377 if (!tz->trips.passive.flags.valid)
378 printk(KERN_WARNING PREFIX "Invalid passive threshold\n");
380 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
381 "Found passive threshold [%lu]\n",
382 tz->trips.passive.temperature));
385 /* Active: Fans, etc. (optional) */
387 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
389 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
392 acpi_evaluate_integer(tz->device->handle, name, NULL,
393 &tz->trips.active[i].temperature);
394 if (ACPI_FAILURE(status))
399 acpi_evaluate_reference(tz->device->handle, name, NULL,
400 &tz->trips.active[i].devices);
401 if (ACPI_SUCCESS(status)) {
402 tz->trips.active[i].flags.valid = 1;
403 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
404 "Found active threshold [%d]:[%lu]\n",
405 i, tz->trips.active[i].temperature));
407 ACPI_EXCEPTION((AE_INFO, status,
408 "Invalid active threshold [%d]", i));
414 static int acpi_thermal_get_devices(struct acpi_thermal *tz)
416 acpi_status status = AE_OK;
423 acpi_evaluate_reference(tz->device->handle, "_TZD", NULL, &tz->devices);
424 if (ACPI_FAILURE(status))
430 static int acpi_thermal_call_usermode(char *path)
432 char *argv[2] = { NULL, NULL };
433 char *envp[3] = { NULL, NULL, NULL };
441 /* minimal command environment */
443 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
445 call_usermodehelper(argv[0], argv, envp, 0);
450 static int acpi_thermal_critical(struct acpi_thermal *tz)
452 if (!tz || !tz->trips.critical.flags.valid)
455 if (tz->temperature >= tz->trips.critical.temperature) {
456 printk(KERN_WARNING PREFIX "Critical trip point\n");
457 tz->trips.critical.flags.enabled = 1;
458 } else if (tz->trips.critical.flags.enabled)
459 tz->trips.critical.flags.enabled = 0;
462 "Critical temperature reached (%ld C), shutting down.\n",
463 KELVIN_TO_CELSIUS(tz->temperature));
464 acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL,
465 tz->trips.critical.flags.enabled);
467 acpi_thermal_call_usermode(ACPI_THERMAL_PATH_POWEROFF);
472 static int acpi_thermal_hot(struct acpi_thermal *tz)
474 if (!tz || !tz->trips.hot.flags.valid)
477 if (tz->temperature >= tz->trips.hot.temperature) {
478 printk(KERN_WARNING PREFIX "Hot trip point\n");
479 tz->trips.hot.flags.enabled = 1;
480 } else if (tz->trips.hot.flags.enabled)
481 tz->trips.hot.flags.enabled = 0;
483 acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
484 tz->trips.hot.flags.enabled);
486 /* TBD: Call user-mode "sleep(S4)" function */
491 static void acpi_thermal_passive(struct acpi_thermal *tz)
494 struct acpi_thermal_passive *passive = NULL;
499 if (!tz || !tz->trips.passive.flags.valid)
502 passive = &(tz->trips.passive);
507 * Calculate the thermal trend (using the passive cooling equation)
508 * and modify the performance limit for all passive cooling devices
509 * accordingly. Note that we assume symmetry.
511 if (tz->temperature >= passive->temperature) {
513 (passive->tc1 * (tz->temperature - tz->last_temperature)) +
514 (passive->tc2 * (tz->temperature - passive->temperature));
515 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
516 "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
517 trend, passive->tc1, tz->temperature,
518 tz->last_temperature, passive->tc2,
519 tz->temperature, passive->temperature));
520 passive->flags.enabled = 1;
523 for (i = 0; i < passive->devices.count; i++)
524 acpi_processor_set_thermal_limit(passive->
527 ACPI_PROCESSOR_LIMIT_INCREMENT);
529 else if (trend < 0) {
530 for (i = 0; i < passive->devices.count; i++)
532 * assume that we are on highest
533 * freq/lowest thrott and can leave
534 * passive mode, even in error case
536 if (!acpi_processor_set_thermal_limit
537 (passive->devices.handles[i],
538 ACPI_PROCESSOR_LIMIT_DECREMENT))
541 * Leave cooling mode, even if the temp might
542 * higher than trip point This is because some
543 * machines might have long thermal polling
544 * frequencies (tsp) defined. We will fall back
545 * into passive mode in next cycle (probably quicker)
548 passive->flags.enabled = 0;
549 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
550 "Disabling passive cooling, still above threshold,"
551 " but we are cooling down\n"));
560 * Implement passive cooling hysteresis to slowly increase performance
561 * and avoid thrashing around the passive trip point. Note that we
564 if (!passive->flags.enabled)
566 for (i = 0; i < passive->devices.count; i++)
567 if (!acpi_processor_set_thermal_limit
568 (passive->devices.handles[i],
569 ACPI_PROCESSOR_LIMIT_DECREMENT))
572 passive->flags.enabled = 0;
573 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
574 "Disabling passive cooling (zone is cool)\n"));
578 static void acpi_thermal_active(struct acpi_thermal *tz)
581 struct acpi_thermal_active *active = NULL;
584 unsigned long maxtemp = 0;
590 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
591 active = &(tz->trips.active[i]);
592 if (!active || !active->flags.valid)
594 if (tz->temperature >= active->temperature) {
598 * If not already enabled, turn ON all cooling devices
599 * associated with this active threshold.
601 if (active->temperature > maxtemp)
602 tz->state.active_index = i;
603 maxtemp = active->temperature;
604 if (active->flags.enabled)
606 for (j = 0; j < active->devices.count; j++) {
608 acpi_bus_set_power(active->devices.
612 printk(KERN_WARNING PREFIX
613 "Unable to turn cooling device [%p] 'on'\n",
618 active->flags.enabled = 1;
619 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
620 "Cooling device [%p] now 'on'\n",
621 active->devices.handles[j]));
625 if (!active->flags.enabled)
630 * Turn OFF all cooling devices associated with this
633 for (j = 0; j < active->devices.count; j++) {
634 result = acpi_bus_set_power(active->devices.handles[j],
637 printk(KERN_WARNING PREFIX
638 "Unable to turn cooling device [%p] 'off'\n",
639 active->devices.handles[j]);
642 active->flags.enabled = 0;
643 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
644 "Cooling device [%p] now 'off'\n",
645 active->devices.handles[j]));
650 static void acpi_thermal_check(void *context);
652 static void acpi_thermal_run(unsigned long data)
654 struct acpi_thermal *tz = (struct acpi_thermal *)data;
656 acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data);
659 static void acpi_thermal_check(void *data)
662 struct acpi_thermal *tz = data;
663 unsigned long sleep_time = 0;
665 struct acpi_thermal_state state;
669 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
675 result = acpi_thermal_get_temperature(tz);
679 memset(&tz->state, 0, sizeof(tz->state));
684 * Compare the current temperature to the trip point values to see
685 * if we've entered one of the thermal policy states. Note that
686 * this function determines when a state is entered, but the
687 * individual policy decides when it is exited (e.g. hysteresis).
689 if (tz->trips.critical.flags.valid)
691 (tz->temperature >= tz->trips.critical.temperature);
692 if (tz->trips.hot.flags.valid)
693 state.hot |= (tz->temperature >= tz->trips.hot.temperature);
694 if (tz->trips.passive.flags.valid)
696 (tz->temperature >= tz->trips.passive.temperature);
697 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
698 if (tz->trips.active[i].flags.valid)
701 tz->trips.active[i].temperature);
706 * Separated from the above check to allow individual policy to
707 * determine when to exit a given state.
710 acpi_thermal_critical(tz);
712 acpi_thermal_hot(tz);
714 acpi_thermal_passive(tz);
716 acpi_thermal_active(tz);
721 * Again, separated from the above two to allow independent policy
724 tz->state.critical = tz->trips.critical.flags.enabled;
725 tz->state.hot = tz->trips.hot.flags.enabled;
726 tz->state.passive = tz->trips.passive.flags.enabled;
727 tz->state.active = 0;
728 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
729 tz->state.active |= tz->trips.active[i].flags.enabled;
732 * Calculate Sleep Time
733 * --------------------
734 * If we're in the passive state, use _TSP's value. Otherwise
735 * use the default polling frequency (e.g. _TZP). If no polling
736 * frequency is specified then we'll wait forever (at least until
737 * a thermal event occurs). Note that _TSP and _TZD values are
738 * given in 1/10th seconds (we must covert to milliseconds).
740 if (tz->state.passive)
741 sleep_time = tz->trips.passive.tsp * 100;
742 else if (tz->polling_frequency > 0)
743 sleep_time = tz->polling_frequency * 100;
745 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n",
746 tz->name, tz->temperature, sleep_time));
753 if (timer_pending(&(tz->timer)))
754 del_timer(&(tz->timer));
756 if (timer_pending(&(tz->timer)))
757 mod_timer(&(tz->timer),
758 jiffies + (HZ * sleep_time) / 1000);
760 tz->timer.data = (unsigned long)tz;
761 tz->timer.function = acpi_thermal_run;
762 tz->timer.expires = jiffies + (HZ * sleep_time) / 1000;
763 add_timer(&(tz->timer));
770 /* --------------------------------------------------------------------------
772 -------------------------------------------------------------------------- */
774 static struct proc_dir_entry *acpi_thermal_dir;
776 static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
778 struct acpi_thermal *tz = seq->private;
784 seq_puts(seq, "state: ");
786 if (!tz->state.critical && !tz->state.hot && !tz->state.passive
787 && !tz->state.active)
788 seq_puts(seq, "ok\n");
790 if (tz->state.critical)
791 seq_puts(seq, "critical ");
793 seq_puts(seq, "hot ");
794 if (tz->state.passive)
795 seq_puts(seq, "passive ");
796 if (tz->state.active)
797 seq_printf(seq, "active[%d]", tz->state.active_index);
805 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
807 return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
810 static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
813 struct acpi_thermal *tz = seq->private;
819 result = acpi_thermal_get_temperature(tz);
823 seq_printf(seq, "temperature: %ld C\n",
824 KELVIN_TO_CELSIUS(tz->temperature));
830 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
832 return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
835 static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
837 struct acpi_thermal *tz = seq->private;
845 if (tz->trips.critical.flags.valid)
846 seq_printf(seq, "critical (S5): %ld C\n",
847 KELVIN_TO_CELSIUS(tz->trips.critical.temperature));
849 if (tz->trips.hot.flags.valid)
850 seq_printf(seq, "hot (S4): %ld C\n",
851 KELVIN_TO_CELSIUS(tz->trips.hot.temperature));
853 if (tz->trips.passive.flags.valid) {
855 "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
856 KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
857 tz->trips.passive.tc1, tz->trips.passive.tc2,
858 tz->trips.passive.tsp);
859 for (j = 0; j < tz->trips.passive.devices.count; j++) {
861 seq_printf(seq, "0x%p ",
862 tz->trips.passive.devices.handles[j]);
867 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
868 if (!(tz->trips.active[i].flags.valid))
870 seq_printf(seq, "active[%d]: %ld C: devices=",
872 KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
873 for (j = 0; j < tz->trips.active[i].devices.count; j++)
874 seq_printf(seq, "0x%p ",
875 tz->trips.active[i].devices.handles[j]);
883 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
885 return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
888 static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
890 struct acpi_thermal *tz = seq->private;
896 if (!tz->flags.cooling_mode) {
897 seq_puts(seq, "<setting not supported>\n");
900 if (tz->cooling_mode == ACPI_THERMAL_MODE_CRITICAL)
901 seq_printf(seq, "cooling mode: critical\n");
903 seq_printf(seq, "cooling mode: %s\n",
904 tz->cooling_mode ? "passive" : "active");
910 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
912 return single_open(file, acpi_thermal_cooling_seq_show,
917 acpi_thermal_write_cooling_mode(struct file *file,
918 const char __user * buffer,
919 size_t count, loff_t * ppos)
921 struct seq_file *m = file->private_data;
922 struct acpi_thermal *tz = m->private;
924 char mode_string[12] = { '\0' };
927 if (!tz || (count > sizeof(mode_string) - 1))
930 if (!tz->flags.cooling_mode)
933 if (copy_from_user(mode_string, buffer, count))
936 mode_string[count] = '\0';
938 result = acpi_thermal_set_cooling_mode(tz,
939 simple_strtoul(mode_string, NULL,
944 acpi_thermal_check(tz);
949 static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
951 struct acpi_thermal *tz = seq->private;
957 if (!tz->polling_frequency) {
958 seq_puts(seq, "<polling disabled>\n");
962 seq_printf(seq, "polling frequency: %lu seconds\n",
963 (tz->polling_frequency / 10));
969 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
971 return single_open(file, acpi_thermal_polling_seq_show,
976 acpi_thermal_write_polling(struct file *file,
977 const char __user * buffer,
978 size_t count, loff_t * ppos)
980 struct seq_file *m = file->private_data;
981 struct acpi_thermal *tz = m->private;
983 char polling_string[12] = { '\0' };
987 if (!tz || (count > sizeof(polling_string) - 1))
990 if (copy_from_user(polling_string, buffer, count))
993 polling_string[count] = '\0';
995 seconds = simple_strtoul(polling_string, NULL, 0);
997 result = acpi_thermal_set_polling(tz, seconds);
1001 acpi_thermal_check(tz);
1006 static int acpi_thermal_add_fs(struct acpi_device *device)
1008 struct proc_dir_entry *entry = NULL;
1011 if (!acpi_device_dir(device)) {
1012 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1014 if (!acpi_device_dir(device))
1016 acpi_device_dir(device)->owner = THIS_MODULE;
1020 entry = create_proc_entry(ACPI_THERMAL_FILE_STATE,
1021 S_IRUGO, acpi_device_dir(device));
1025 entry->proc_fops = &acpi_thermal_state_fops;
1026 entry->data = acpi_driver_data(device);
1027 entry->owner = THIS_MODULE;
1030 /* 'temperature' [R] */
1031 entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1032 S_IRUGO, acpi_device_dir(device));
1036 entry->proc_fops = &acpi_thermal_temp_fops;
1037 entry->data = acpi_driver_data(device);
1038 entry->owner = THIS_MODULE;
1041 /* 'trip_points' [R/W] */
1042 entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1043 S_IFREG | S_IRUGO | S_IWUSR,
1044 acpi_device_dir(device));
1048 entry->proc_fops = &acpi_thermal_trip_fops;
1049 entry->data = acpi_driver_data(device);
1050 entry->owner = THIS_MODULE;
1053 /* 'cooling_mode' [R/W] */
1054 entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1055 S_IFREG | S_IRUGO | S_IWUSR,
1056 acpi_device_dir(device));
1060 entry->proc_fops = &acpi_thermal_cooling_fops;
1061 entry->data = acpi_driver_data(device);
1062 entry->owner = THIS_MODULE;
1065 /* 'polling_frequency' [R/W] */
1066 entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1067 S_IFREG | S_IRUGO | S_IWUSR,
1068 acpi_device_dir(device));
1072 entry->proc_fops = &acpi_thermal_polling_fops;
1073 entry->data = acpi_driver_data(device);
1074 entry->owner = THIS_MODULE;
1080 static int acpi_thermal_remove_fs(struct acpi_device *device)
1083 if (acpi_device_dir(device)) {
1084 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1085 acpi_device_dir(device));
1086 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1087 acpi_device_dir(device));
1088 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1089 acpi_device_dir(device));
1090 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1091 acpi_device_dir(device));
1092 remove_proc_entry(ACPI_THERMAL_FILE_STATE,
1093 acpi_device_dir(device));
1094 remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
1095 acpi_device_dir(device) = NULL;
1101 /* --------------------------------------------------------------------------
1103 -------------------------------------------------------------------------- */
1105 static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
1107 struct acpi_thermal *tz = data;
1108 struct acpi_device *device = NULL;
1114 device = tz->device;
1117 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
1118 acpi_thermal_check(tz);
1120 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
1121 acpi_thermal_get_trip_points(tz);
1122 acpi_thermal_check(tz);
1123 acpi_bus_generate_event(device, event, 0);
1125 case ACPI_THERMAL_NOTIFY_DEVICES:
1126 if (tz->flags.devices)
1127 acpi_thermal_get_devices(tz);
1128 acpi_bus_generate_event(device, event, 0);
1131 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1132 "Unsupported event [0x%x]\n", event));
1139 static int acpi_thermal_get_info(struct acpi_thermal *tz)
1147 /* Get temperature [_TMP] (required) */
1148 result = acpi_thermal_get_temperature(tz);
1152 /* Get trip points [_CRT, _PSV, etc.] (required) */
1153 result = acpi_thermal_get_trip_points(tz);
1157 /* Set the cooling mode [_SCP] to active cooling (default) */
1158 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
1160 tz->flags.cooling_mode = 1;
1162 /* Oh,we have not _SCP method.
1163 Generally show cooling_mode by _ACx, _PSV,spec 12.2 */
1164 tz->flags.cooling_mode = 0;
1165 if (tz->trips.active[0].flags.valid
1166 && tz->trips.passive.flags.valid) {
1167 if (tz->trips.passive.temperature >
1168 tz->trips.active[0].temperature)
1169 tz->cooling_mode = ACPI_THERMAL_MODE_ACTIVE;
1171 tz->cooling_mode = ACPI_THERMAL_MODE_PASSIVE;
1172 } else if (!tz->trips.active[0].flags.valid
1173 && tz->trips.passive.flags.valid) {
1174 tz->cooling_mode = ACPI_THERMAL_MODE_PASSIVE;
1175 } else if (tz->trips.active[0].flags.valid
1176 && !tz->trips.passive.flags.valid) {
1177 tz->cooling_mode = ACPI_THERMAL_MODE_ACTIVE;
1179 /* _ACx and _PSV are optional, but _CRT is required */
1180 tz->cooling_mode = ACPI_THERMAL_MODE_CRITICAL;
1184 /* Get default polling frequency [_TZP] (optional) */
1186 tz->polling_frequency = tzp;
1188 acpi_thermal_get_polling_frequency(tz);
1190 /* Get devices in this thermal zone [_TZD] (optional) */
1191 result = acpi_thermal_get_devices(tz);
1193 tz->flags.devices = 1;
1198 static int acpi_thermal_add(struct acpi_device *device)
1201 acpi_status status = AE_OK;
1202 struct acpi_thermal *tz = NULL;
1208 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1212 tz->device = device;
1213 strcpy(tz->name, device->pnp.bus_id);
1214 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1215 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
1216 acpi_driver_data(device) = tz;
1218 result = acpi_thermal_get_info(tz);
1222 result = acpi_thermal_add_fs(device);
1226 init_timer(&tz->timer);
1228 acpi_thermal_check(tz);
1230 status = acpi_install_notify_handler(device->handle,
1232 acpi_thermal_notify, tz);
1233 if (ACPI_FAILURE(status)) {
1238 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
1239 acpi_device_name(device), acpi_device_bid(device),
1240 KELVIN_TO_CELSIUS(tz->temperature));
1244 acpi_thermal_remove_fs(device);
1251 static int acpi_thermal_remove(struct acpi_device *device, int type)
1253 acpi_status status = AE_OK;
1254 struct acpi_thermal *tz = NULL;
1257 if (!device || !acpi_driver_data(device))
1260 tz = acpi_driver_data(device);
1262 /* avoid timer adding new defer task */
1264 /* wait for running timer (on other CPUs) finish */
1265 del_timer_sync(&(tz->timer));
1266 /* synchronize deferred task */
1267 acpi_os_wait_events_complete(NULL);
1268 /* deferred task may reinsert timer */
1269 del_timer_sync(&(tz->timer));
1271 status = acpi_remove_notify_handler(device->handle,
1273 acpi_thermal_notify);
1275 /* Terminate policy */
1276 if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
1277 tz->trips.passive.flags.enabled = 0;
1278 acpi_thermal_passive(tz);
1280 if (tz->trips.active[0].flags.valid
1281 && tz->trips.active[0].flags.enabled) {
1282 tz->trips.active[0].flags.enabled = 0;
1283 acpi_thermal_active(tz);
1286 acpi_thermal_remove_fs(device);
1292 static int acpi_thermal_resume(struct acpi_device *device)
1294 struct acpi_thermal *tz = NULL;
1295 int i, j, power_state, result;
1298 if (!device || !acpi_driver_data(device))
1301 tz = acpi_driver_data(device);
1303 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1304 if (!(&tz->trips.active[i]))
1306 if (!tz->trips.active[i].flags.valid)
1308 tz->trips.active[i].flags.enabled = 1;
1309 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1310 result = acpi_bus_get_power(tz->trips.active[i].devices.
1311 handles[j], &power_state);
1312 if (result || (power_state != ACPI_STATE_D0)) {
1313 tz->trips.active[i].flags.enabled = 0;
1317 tz->state.active |= tz->trips.active[i].flags.enabled;
1320 acpi_thermal_check(tz);
1325 static int __init acpi_thermal_init(void)
1330 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
1331 if (!acpi_thermal_dir)
1333 acpi_thermal_dir->owner = THIS_MODULE;
1335 result = acpi_bus_register_driver(&acpi_thermal_driver);
1337 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1344 static void __exit acpi_thermal_exit(void)
1347 acpi_bus_unregister_driver(&acpi_thermal_driver);
1349 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1354 module_init(acpi_thermal_init);
1355 module_exit(acpi_thermal_exit);