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.\n");
83 module_param(tzp, int, 0444);
84 MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.\n");
87 module_param(nocrt, int, 0);
88 MODULE_PARM_DESC(nocrt, "Set to disable action on ACPI thermal zone critical and hot trips.\n");
91 module_param(off, int, 0);
92 MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.\n");
95 module_param(psv, int, 0644);
96 MODULE_PARM_DESC(psv, "Disable or override all passive trip points.\n");
98 static int acpi_thermal_add(struct acpi_device *device);
99 static int acpi_thermal_remove(struct acpi_device *device, int type);
100 static int acpi_thermal_resume(struct acpi_device *device);
101 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
102 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
103 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
104 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
105 static ssize_t acpi_thermal_write_cooling_mode(struct file *,
106 const char __user *, size_t,
108 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
109 static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
112 static const struct acpi_device_id thermal_device_ids[] = {
113 {ACPI_THERMAL_HID, 0},
116 MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
118 static struct acpi_driver acpi_thermal_driver = {
120 .class = ACPI_THERMAL_CLASS,
121 .ids = thermal_device_ids,
123 .add = acpi_thermal_add,
124 .remove = acpi_thermal_remove,
125 .resume = acpi_thermal_resume,
129 struct acpi_thermal_state {
138 struct acpi_thermal_state_flags {
144 struct acpi_thermal_critical {
145 struct acpi_thermal_state_flags flags;
146 unsigned long temperature;
149 struct acpi_thermal_hot {
150 struct acpi_thermal_state_flags flags;
151 unsigned long temperature;
154 struct acpi_thermal_passive {
155 struct acpi_thermal_state_flags flags;
156 unsigned long temperature;
160 struct acpi_handle_list devices;
163 struct acpi_thermal_active {
164 struct acpi_thermal_state_flags flags;
165 unsigned long temperature;
166 struct acpi_handle_list devices;
169 struct acpi_thermal_trips {
170 struct acpi_thermal_critical critical;
171 struct acpi_thermal_hot hot;
172 struct acpi_thermal_passive passive;
173 struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
176 struct acpi_thermal_flags {
177 u8 cooling_mode:1; /* _SCP */
178 u8 devices:1; /* _TZD */
182 struct acpi_thermal {
183 struct acpi_device * device;
185 unsigned long temperature;
186 unsigned long last_temperature;
187 unsigned long polling_frequency;
189 struct acpi_thermal_flags flags;
190 struct acpi_thermal_state state;
191 struct acpi_thermal_trips trips;
192 struct acpi_handle_list devices;
193 struct timer_list timer;
196 static const struct file_operations acpi_thermal_state_fops = {
197 .open = acpi_thermal_state_open_fs,
200 .release = single_release,
203 static const struct file_operations acpi_thermal_temp_fops = {
204 .open = acpi_thermal_temp_open_fs,
207 .release = single_release,
210 static const struct file_operations acpi_thermal_trip_fops = {
211 .open = acpi_thermal_trip_open_fs,
214 .release = single_release,
217 static const struct file_operations acpi_thermal_cooling_fops = {
218 .open = acpi_thermal_cooling_open_fs,
220 .write = acpi_thermal_write_cooling_mode,
222 .release = single_release,
225 static const struct file_operations acpi_thermal_polling_fops = {
226 .open = acpi_thermal_polling_open_fs,
228 .write = acpi_thermal_write_polling,
230 .release = single_release,
233 /* --------------------------------------------------------------------------
234 Thermal Zone Management
235 -------------------------------------------------------------------------- */
237 static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
239 acpi_status status = AE_OK;
245 tz->last_temperature = tz->temperature;
248 acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tz->temperature);
249 if (ACPI_FAILURE(status))
252 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
258 static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
260 acpi_status status = AE_OK;
267 acpi_evaluate_integer(tz->device->handle, "_TZP", NULL,
268 &tz->polling_frequency);
269 if (ACPI_FAILURE(status))
272 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
273 tz->polling_frequency));
278 static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
284 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
286 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
287 "Polling frequency set to %lu seconds\n",
288 tz->polling_frequency/10));
293 static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
295 acpi_status status = AE_OK;
296 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
297 struct acpi_object_list arg_list = { 1, &arg0 };
298 acpi_handle handle = NULL;
304 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
305 if (ACPI_FAILURE(status)) {
306 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
310 arg0.integer.value = mode;
312 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
313 if (ACPI_FAILURE(status))
319 static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
321 acpi_status status = AE_OK;
328 /* Critical Shutdown (required) */
330 status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL,
331 &tz->trips.critical.temperature);
332 if (ACPI_FAILURE(status)) {
333 tz->trips.critical.flags.valid = 0;
334 ACPI_EXCEPTION((AE_INFO, status, "No critical threshold"));
337 tz->trips.critical.flags.valid = 1;
338 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
339 "Found critical threshold [%lu]\n",
340 tz->trips.critical.temperature));
343 /* Critical Sleep (optional) */
346 acpi_evaluate_integer(tz->device->handle, "_HOT", NULL,
347 &tz->trips.hot.temperature);
348 if (ACPI_FAILURE(status)) {
349 tz->trips.hot.flags.valid = 0;
350 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No hot threshold\n"));
352 tz->trips.hot.flags.valid = 1;
353 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found hot threshold [%lu]\n",
354 tz->trips.hot.temperature));
357 /* Passive: Processors (optional) */
361 } else if (psv > 0) {
362 tz->trips.passive.temperature = CELSIUS_TO_KELVIN(psv);
365 status = acpi_evaluate_integer(tz->device->handle,
366 "_PSV", NULL, &tz->trips.passive.temperature);
369 if (ACPI_FAILURE(status)) {
370 tz->trips.passive.flags.valid = 0;
371 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No passive threshold\n"));
373 tz->trips.passive.flags.valid = 1;
376 acpi_evaluate_integer(tz->device->handle, "_TC1", NULL,
377 &tz->trips.passive.tc1);
378 if (ACPI_FAILURE(status))
379 tz->trips.passive.flags.valid = 0;
382 acpi_evaluate_integer(tz->device->handle, "_TC2", NULL,
383 &tz->trips.passive.tc2);
384 if (ACPI_FAILURE(status))
385 tz->trips.passive.flags.valid = 0;
388 acpi_evaluate_integer(tz->device->handle, "_TSP", NULL,
389 &tz->trips.passive.tsp);
390 if (ACPI_FAILURE(status))
391 tz->trips.passive.flags.valid = 0;
394 acpi_evaluate_reference(tz->device->handle, "_PSL", NULL,
395 &tz->trips.passive.devices);
396 if (ACPI_FAILURE(status))
397 tz->trips.passive.flags.valid = 0;
399 if (!tz->trips.passive.flags.valid)
400 printk(KERN_WARNING PREFIX "Invalid passive threshold\n");
402 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
403 "Found passive threshold [%lu]\n",
404 tz->trips.passive.temperature));
407 /* Active: Fans, etc. (optional) */
409 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
411 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
414 break; /* disable all active trip points */
416 status = acpi_evaluate_integer(tz->device->handle,
417 name, NULL, &tz->trips.active[i].temperature);
419 if (ACPI_FAILURE(status)) {
420 if (i == 0) /* no active trip points */
422 if (act <= 0) /* no override requested */
424 if (i == 1) { /* 1 trip point */
425 tz->trips.active[0].temperature =
426 CELSIUS_TO_KELVIN(act);
427 } else { /* multiple trips */
429 * Don't allow override higher than
430 * the next higher trip point
432 tz->trips.active[i - 1].temperature =
433 (tz->trips.active[i - 2].temperature <
434 CELSIUS_TO_KELVIN(act) ?
435 tz->trips.active[i - 2].temperature :
436 CELSIUS_TO_KELVIN(act));
443 acpi_evaluate_reference(tz->device->handle, name, NULL,
444 &tz->trips.active[i].devices);
445 if (ACPI_SUCCESS(status)) {
446 tz->trips.active[i].flags.valid = 1;
447 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
448 "Found active threshold [%d]:[%lu]\n",
449 i, tz->trips.active[i].temperature));
451 ACPI_EXCEPTION((AE_INFO, status,
452 "Invalid active threshold [%d]", i));
458 static int acpi_thermal_get_devices(struct acpi_thermal *tz)
460 acpi_status status = AE_OK;
467 acpi_evaluate_reference(tz->device->handle, "_TZD", NULL, &tz->devices);
468 if (ACPI_FAILURE(status))
474 static int acpi_thermal_critical(struct acpi_thermal *tz)
476 if (!tz || !tz->trips.critical.flags.valid || nocrt)
479 if (tz->temperature >= tz->trips.critical.temperature) {
480 printk(KERN_WARNING PREFIX "Critical trip point\n");
481 tz->trips.critical.flags.enabled = 1;
482 } else if (tz->trips.critical.flags.enabled)
483 tz->trips.critical.flags.enabled = 0;
486 "Critical temperature reached (%ld C), shutting down.\n",
487 KELVIN_TO_CELSIUS(tz->temperature));
488 acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL,
489 tz->trips.critical.flags.enabled);
491 orderly_poweroff(true);
496 static int acpi_thermal_hot(struct acpi_thermal *tz)
498 if (!tz || !tz->trips.hot.flags.valid || nocrt)
501 if (tz->temperature >= tz->trips.hot.temperature) {
502 printk(KERN_WARNING PREFIX "Hot trip point\n");
503 tz->trips.hot.flags.enabled = 1;
504 } else if (tz->trips.hot.flags.enabled)
505 tz->trips.hot.flags.enabled = 0;
507 acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
508 tz->trips.hot.flags.enabled);
510 /* TBD: Call user-mode "sleep(S4)" function */
515 static void acpi_thermal_passive(struct acpi_thermal *tz)
518 struct acpi_thermal_passive *passive = NULL;
523 if (!tz || !tz->trips.passive.flags.valid)
526 passive = &(tz->trips.passive);
531 * Calculate the thermal trend (using the passive cooling equation)
532 * and modify the performance limit for all passive cooling devices
533 * accordingly. Note that we assume symmetry.
535 if (tz->temperature >= passive->temperature) {
537 (passive->tc1 * (tz->temperature - tz->last_temperature)) +
538 (passive->tc2 * (tz->temperature - passive->temperature));
539 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
540 "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
541 trend, passive->tc1, tz->temperature,
542 tz->last_temperature, passive->tc2,
543 tz->temperature, passive->temperature));
544 passive->flags.enabled = 1;
547 for (i = 0; i < passive->devices.count; i++)
548 acpi_processor_set_thermal_limit(passive->
551 ACPI_PROCESSOR_LIMIT_INCREMENT);
553 else if (trend < 0) {
554 for (i = 0; i < passive->devices.count; i++)
556 * assume that we are on highest
557 * freq/lowest thrott and can leave
558 * passive mode, even in error case
560 if (!acpi_processor_set_thermal_limit
561 (passive->devices.handles[i],
562 ACPI_PROCESSOR_LIMIT_DECREMENT))
565 * Leave cooling mode, even if the temp might
566 * higher than trip point This is because some
567 * machines might have long thermal polling
568 * frequencies (tsp) defined. We will fall back
569 * into passive mode in next cycle (probably quicker)
572 passive->flags.enabled = 0;
573 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
574 "Disabling passive cooling, still above threshold,"
575 " but we are cooling down\n"));
584 * Implement passive cooling hysteresis to slowly increase performance
585 * and avoid thrashing around the passive trip point. Note that we
588 if (!passive->flags.enabled)
590 for (i = 0; i < passive->devices.count; i++)
591 if (!acpi_processor_set_thermal_limit
592 (passive->devices.handles[i],
593 ACPI_PROCESSOR_LIMIT_DECREMENT))
596 passive->flags.enabled = 0;
597 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
598 "Disabling passive cooling (zone is cool)\n"));
602 static void acpi_thermal_active(struct acpi_thermal *tz)
605 struct acpi_thermal_active *active = NULL;
608 unsigned long maxtemp = 0;
614 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
615 active = &(tz->trips.active[i]);
616 if (!active || !active->flags.valid)
618 if (tz->temperature >= active->temperature) {
622 * If not already enabled, turn ON all cooling devices
623 * associated with this active threshold.
625 if (active->temperature > maxtemp)
626 tz->state.active_index = i;
627 maxtemp = active->temperature;
628 if (active->flags.enabled)
630 for (j = 0; j < active->devices.count; j++) {
632 acpi_bus_set_power(active->devices.
636 printk(KERN_WARNING PREFIX
637 "Unable to turn cooling device [%p] 'on'\n",
642 active->flags.enabled = 1;
643 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
644 "Cooling device [%p] now 'on'\n",
645 active->devices.handles[j]));
649 if (!active->flags.enabled)
654 * Turn OFF all cooling devices associated with this
657 for (j = 0; j < active->devices.count; j++) {
658 result = acpi_bus_set_power(active->devices.handles[j],
661 printk(KERN_WARNING PREFIX
662 "Unable to turn cooling device [%p] 'off'\n",
663 active->devices.handles[j]);
666 active->flags.enabled = 0;
667 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
668 "Cooling device [%p] now 'off'\n",
669 active->devices.handles[j]));
674 static void acpi_thermal_check(void *context);
676 static void acpi_thermal_run(unsigned long data)
678 struct acpi_thermal *tz = (struct acpi_thermal *)data;
680 acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data);
683 static void acpi_thermal_check(void *data)
686 struct acpi_thermal *tz = data;
687 unsigned long sleep_time = 0;
689 struct acpi_thermal_state state;
693 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
699 result = acpi_thermal_get_temperature(tz);
703 memset(&tz->state, 0, sizeof(tz->state));
708 * Compare the current temperature to the trip point values to see
709 * if we've entered one of the thermal policy states. Note that
710 * this function determines when a state is entered, but the
711 * individual policy decides when it is exited (e.g. hysteresis).
713 if (tz->trips.critical.flags.valid)
715 (tz->temperature >= tz->trips.critical.temperature);
716 if (tz->trips.hot.flags.valid)
717 state.hot |= (tz->temperature >= tz->trips.hot.temperature);
718 if (tz->trips.passive.flags.valid)
720 (tz->temperature >= tz->trips.passive.temperature);
721 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
722 if (tz->trips.active[i].flags.valid)
725 tz->trips.active[i].temperature);
730 * Separated from the above check to allow individual policy to
731 * determine when to exit a given state.
734 acpi_thermal_critical(tz);
736 acpi_thermal_hot(tz);
738 acpi_thermal_passive(tz);
740 acpi_thermal_active(tz);
745 * Again, separated from the above two to allow independent policy
748 tz->state.critical = tz->trips.critical.flags.enabled;
749 tz->state.hot = tz->trips.hot.flags.enabled;
750 tz->state.passive = tz->trips.passive.flags.enabled;
751 tz->state.active = 0;
752 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
753 tz->state.active |= tz->trips.active[i].flags.enabled;
756 * Calculate Sleep Time
757 * --------------------
758 * If we're in the passive state, use _TSP's value. Otherwise
759 * use the default polling frequency (e.g. _TZP). If no polling
760 * frequency is specified then we'll wait forever (at least until
761 * a thermal event occurs). Note that _TSP and _TZD values are
762 * given in 1/10th seconds (we must covert to milliseconds).
764 if (tz->state.passive)
765 sleep_time = tz->trips.passive.tsp * 100;
766 else if (tz->polling_frequency > 0)
767 sleep_time = tz->polling_frequency * 100;
769 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n",
770 tz->name, tz->temperature, sleep_time));
777 if (timer_pending(&(tz->timer)))
778 del_timer(&(tz->timer));
780 if (timer_pending(&(tz->timer)))
781 mod_timer(&(tz->timer),
782 jiffies + (HZ * sleep_time) / 1000);
784 tz->timer.data = (unsigned long)tz;
785 tz->timer.function = acpi_thermal_run;
786 tz->timer.expires = jiffies + (HZ * sleep_time) / 1000;
787 add_timer(&(tz->timer));
794 /* --------------------------------------------------------------------------
796 -------------------------------------------------------------------------- */
798 static struct proc_dir_entry *acpi_thermal_dir;
800 static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
802 struct acpi_thermal *tz = seq->private;
808 seq_puts(seq, "state: ");
810 if (!tz->state.critical && !tz->state.hot && !tz->state.passive
811 && !tz->state.active)
812 seq_puts(seq, "ok\n");
814 if (tz->state.critical)
815 seq_puts(seq, "critical ");
817 seq_puts(seq, "hot ");
818 if (tz->state.passive)
819 seq_puts(seq, "passive ");
820 if (tz->state.active)
821 seq_printf(seq, "active[%d]", tz->state.active_index);
829 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
831 return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
834 static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
837 struct acpi_thermal *tz = seq->private;
843 result = acpi_thermal_get_temperature(tz);
847 seq_printf(seq, "temperature: %ld C\n",
848 KELVIN_TO_CELSIUS(tz->temperature));
854 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
856 return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
859 static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
861 struct acpi_thermal *tz = seq->private;
862 struct acpi_device *device;
872 if (tz->trips.critical.flags.valid)
873 seq_printf(seq, "critical (S5): %ld C%s",
874 KELVIN_TO_CELSIUS(tz->trips.critical.temperature),
875 nocrt ? " <disabled>\n" : "\n");
877 if (tz->trips.hot.flags.valid)
878 seq_printf(seq, "hot (S4): %ld C%s",
879 KELVIN_TO_CELSIUS(tz->trips.hot.temperature),
880 nocrt ? " <disabled>\n" : "\n");
882 if (tz->trips.passive.flags.valid) {
884 "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
885 KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
886 tz->trips.passive.tc1, tz->trips.passive.tc2,
887 tz->trips.passive.tsp);
888 for (j = 0; j < tz->trips.passive.devices.count; j++) {
889 status = acpi_bus_get_device(tz->trips.passive.devices.
890 handles[j], &device);
891 seq_printf(seq, "%4.4s ", status ? "" :
892 acpi_device_bid(device));
897 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
898 if (!(tz->trips.active[i].flags.valid))
900 seq_printf(seq, "active[%d]: %ld C: devices=",
902 KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
903 for (j = 0; j < tz->trips.active[i].devices.count; j++){
904 status = acpi_bus_get_device(tz->trips.active[i].
907 seq_printf(seq, "%4.4s ", status ? "" :
908 acpi_device_bid(device));
917 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
919 return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
922 static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
924 struct acpi_thermal *tz = seq->private;
930 if (!tz->flags.cooling_mode)
931 seq_puts(seq, "<setting not supported>\n");
933 seq_puts(seq, "0 - Active; 1 - Passive\n");
939 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
941 return single_open(file, acpi_thermal_cooling_seq_show,
946 acpi_thermal_write_cooling_mode(struct file *file,
947 const char __user * buffer,
948 size_t count, loff_t * ppos)
950 struct seq_file *m = file->private_data;
951 struct acpi_thermal *tz = m->private;
953 char mode_string[12] = { '\0' };
956 if (!tz || (count > sizeof(mode_string) - 1))
959 if (!tz->flags.cooling_mode)
962 if (copy_from_user(mode_string, buffer, count))
965 mode_string[count] = '\0';
967 result = acpi_thermal_set_cooling_mode(tz,
968 simple_strtoul(mode_string, NULL,
973 acpi_thermal_check(tz);
978 static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
980 struct acpi_thermal *tz = seq->private;
986 if (!tz->polling_frequency) {
987 seq_puts(seq, "<polling disabled>\n");
991 seq_printf(seq, "polling frequency: %lu seconds\n",
992 (tz->polling_frequency / 10));
998 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
1000 return single_open(file, acpi_thermal_polling_seq_show,
1005 acpi_thermal_write_polling(struct file *file,
1006 const char __user * buffer,
1007 size_t count, loff_t * ppos)
1009 struct seq_file *m = file->private_data;
1010 struct acpi_thermal *tz = m->private;
1012 char polling_string[12] = { '\0' };
1016 if (!tz || (count > sizeof(polling_string) - 1))
1019 if (copy_from_user(polling_string, buffer, count))
1022 polling_string[count] = '\0';
1024 seconds = simple_strtoul(polling_string, NULL, 0);
1026 result = acpi_thermal_set_polling(tz, seconds);
1030 acpi_thermal_check(tz);
1035 static int acpi_thermal_add_fs(struct acpi_device *device)
1037 struct proc_dir_entry *entry = NULL;
1040 if (!acpi_device_dir(device)) {
1041 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1043 if (!acpi_device_dir(device))
1045 acpi_device_dir(device)->owner = THIS_MODULE;
1049 entry = create_proc_entry(ACPI_THERMAL_FILE_STATE,
1050 S_IRUGO, acpi_device_dir(device));
1054 entry->proc_fops = &acpi_thermal_state_fops;
1055 entry->data = acpi_driver_data(device);
1056 entry->owner = THIS_MODULE;
1059 /* 'temperature' [R] */
1060 entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1061 S_IRUGO, acpi_device_dir(device));
1065 entry->proc_fops = &acpi_thermal_temp_fops;
1066 entry->data = acpi_driver_data(device);
1067 entry->owner = THIS_MODULE;
1070 /* 'trip_points' [R/W] */
1071 entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1072 S_IFREG | S_IRUGO | S_IWUSR,
1073 acpi_device_dir(device));
1077 entry->proc_fops = &acpi_thermal_trip_fops;
1078 entry->data = acpi_driver_data(device);
1079 entry->owner = THIS_MODULE;
1082 /* 'cooling_mode' [R/W] */
1083 entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1084 S_IFREG | S_IRUGO | S_IWUSR,
1085 acpi_device_dir(device));
1089 entry->proc_fops = &acpi_thermal_cooling_fops;
1090 entry->data = acpi_driver_data(device);
1091 entry->owner = THIS_MODULE;
1094 /* 'polling_frequency' [R/W] */
1095 entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1096 S_IFREG | S_IRUGO | S_IWUSR,
1097 acpi_device_dir(device));
1101 entry->proc_fops = &acpi_thermal_polling_fops;
1102 entry->data = acpi_driver_data(device);
1103 entry->owner = THIS_MODULE;
1109 static int acpi_thermal_remove_fs(struct acpi_device *device)
1112 if (acpi_device_dir(device)) {
1113 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1114 acpi_device_dir(device));
1115 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1116 acpi_device_dir(device));
1117 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1118 acpi_device_dir(device));
1119 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1120 acpi_device_dir(device));
1121 remove_proc_entry(ACPI_THERMAL_FILE_STATE,
1122 acpi_device_dir(device));
1123 remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
1124 acpi_device_dir(device) = NULL;
1130 /* --------------------------------------------------------------------------
1132 -------------------------------------------------------------------------- */
1134 static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
1136 struct acpi_thermal *tz = data;
1137 struct acpi_device *device = NULL;
1143 device = tz->device;
1146 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
1147 acpi_thermal_check(tz);
1149 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
1150 acpi_thermal_get_trip_points(tz);
1151 acpi_thermal_check(tz);
1152 acpi_bus_generate_event(device, event, 0);
1154 case ACPI_THERMAL_NOTIFY_DEVICES:
1155 if (tz->flags.devices)
1156 acpi_thermal_get_devices(tz);
1157 acpi_bus_generate_event(device, event, 0);
1160 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1161 "Unsupported event [0x%x]\n", event));
1168 static int acpi_thermal_get_info(struct acpi_thermal *tz)
1176 /* Get temperature [_TMP] (required) */
1177 result = acpi_thermal_get_temperature(tz);
1181 /* Get trip points [_CRT, _PSV, etc.] (required) */
1182 result = acpi_thermal_get_trip_points(tz);
1186 /* Set the cooling mode [_SCP] to active cooling (default) */
1187 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
1189 tz->flags.cooling_mode = 1;
1191 /* Get default polling frequency [_TZP] (optional) */
1193 tz->polling_frequency = tzp;
1195 acpi_thermal_get_polling_frequency(tz);
1197 /* Get devices in this thermal zone [_TZD] (optional) */
1198 result = acpi_thermal_get_devices(tz);
1200 tz->flags.devices = 1;
1205 static int acpi_thermal_add(struct acpi_device *device)
1208 acpi_status status = AE_OK;
1209 struct acpi_thermal *tz = NULL;
1215 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1219 tz->device = device;
1220 strcpy(tz->name, device->pnp.bus_id);
1221 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1222 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
1223 acpi_driver_data(device) = tz;
1225 result = acpi_thermal_get_info(tz);
1229 result = acpi_thermal_add_fs(device);
1233 init_timer(&tz->timer);
1235 acpi_thermal_check(tz);
1237 status = acpi_install_notify_handler(device->handle,
1239 acpi_thermal_notify, tz);
1240 if (ACPI_FAILURE(status)) {
1245 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
1246 acpi_device_name(device), acpi_device_bid(device),
1247 KELVIN_TO_CELSIUS(tz->temperature));
1251 acpi_thermal_remove_fs(device);
1258 static int acpi_thermal_remove(struct acpi_device *device, int type)
1260 acpi_status status = AE_OK;
1261 struct acpi_thermal *tz = NULL;
1264 if (!device || !acpi_driver_data(device))
1267 tz = acpi_driver_data(device);
1269 /* avoid timer adding new defer task */
1271 /* wait for running timer (on other CPUs) finish */
1272 del_timer_sync(&(tz->timer));
1273 /* synchronize deferred task */
1274 acpi_os_wait_events_complete(NULL);
1275 /* deferred task may reinsert timer */
1276 del_timer_sync(&(tz->timer));
1278 status = acpi_remove_notify_handler(device->handle,
1280 acpi_thermal_notify);
1282 /* Terminate policy */
1283 if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
1284 tz->trips.passive.flags.enabled = 0;
1285 acpi_thermal_passive(tz);
1287 if (tz->trips.active[0].flags.valid
1288 && tz->trips.active[0].flags.enabled) {
1289 tz->trips.active[0].flags.enabled = 0;
1290 acpi_thermal_active(tz);
1293 acpi_thermal_remove_fs(device);
1299 static int acpi_thermal_resume(struct acpi_device *device)
1301 struct acpi_thermal *tz = NULL;
1302 int i, j, power_state, result;
1305 if (!device || !acpi_driver_data(device))
1308 tz = acpi_driver_data(device);
1310 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1311 if (!(&tz->trips.active[i]))
1313 if (!tz->trips.active[i].flags.valid)
1315 tz->trips.active[i].flags.enabled = 1;
1316 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1317 result = acpi_bus_get_power(tz->trips.active[i].devices.
1318 handles[j], &power_state);
1319 if (result || (power_state != ACPI_STATE_D0)) {
1320 tz->trips.active[i].flags.enabled = 0;
1324 tz->state.active |= tz->trips.active[i].flags.enabled;
1327 acpi_thermal_check(tz);
1333 static int thermal_act(struct dmi_system_id *d) {
1336 printk(KERN_NOTICE "ACPI: %s detected: "
1337 "disabling all active thermal trip points\n", d->ident);
1342 static int thermal_tzp(struct dmi_system_id *d) {
1345 printk(KERN_NOTICE "ACPI: %s detected: "
1346 "enabling thermal zone polling\n", d->ident);
1347 tzp = 300; /* 300 dS = 30 Seconds */
1351 static int thermal_psv(struct dmi_system_id *d) {
1354 printk(KERN_NOTICE "ACPI: %s detected: "
1355 "disabling all passive thermal trip points\n", d->ident);
1361 static struct dmi_system_id thermal_dmi_table[] __initdata = {
1363 * Award BIOS on this AOpen makes thermal control almost worthless.
1364 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1367 .callback = thermal_act,
1368 .ident = "AOpen i915GMm-HFS",
1370 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1371 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1375 .callback = thermal_psv,
1376 .ident = "AOpen i915GMm-HFS",
1378 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1379 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1383 .callback = thermal_tzp,
1384 .ident = "AOpen i915GMm-HFS",
1386 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1387 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1392 #endif /* CONFIG_DMI */
1394 static int __init acpi_thermal_init(void)
1398 dmi_check_system(thermal_dmi_table);
1401 printk(KERN_NOTICE "ACPI: thermal control disabled\n");
1404 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
1405 if (!acpi_thermal_dir)
1407 acpi_thermal_dir->owner = THIS_MODULE;
1409 result = acpi_bus_register_driver(&acpi_thermal_driver);
1411 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1418 static void __exit acpi_thermal_exit(void)
1421 acpi_bus_unregister_driver(&acpi_thermal_driver);
1423 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1428 module_init(acpi_thermal_init);
1429 module_exit(acpi_thermal_exit);