2 * acpi_thermal.c - ACPI Thermal Zone Driver ($Revision: 41 $)
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 * This driver fully implements the ACPI thermal policy as described in the
26 * ACPI 2.0 Specification.
28 * TBD: 1. Implement passive cooling hysteresis.
29 * 2. Enhance passive cooling (CPU) states/limit interface to support
30 * concepts of 'multiple limiters', upper/lower limits, etc.
34 #include <linux/kernel.h>
35 #include <linux/module.h>
36 #include <linux/dmi.h>
37 #include <linux/init.h>
38 #include <linux/types.h>
39 #include <linux/proc_fs.h>
40 #include <linux/timer.h>
41 #include <linux/jiffies.h>
42 #include <linux/kmod.h>
43 #include <linux/seq_file.h>
44 #include <linux/reboot.h>
45 #include <asm/uaccess.h>
47 #include <acpi/acpi_bus.h>
48 #include <acpi/acpi_drivers.h>
50 #define ACPI_THERMAL_COMPONENT 0x04000000
51 #define ACPI_THERMAL_CLASS "thermal_zone"
52 #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
53 #define ACPI_THERMAL_FILE_STATE "state"
54 #define ACPI_THERMAL_FILE_TEMPERATURE "temperature"
55 #define ACPI_THERMAL_FILE_TRIP_POINTS "trip_points"
56 #define ACPI_THERMAL_FILE_COOLING_MODE "cooling_mode"
57 #define ACPI_THERMAL_FILE_POLLING_FREQ "polling_frequency"
58 #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80
59 #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81
60 #define ACPI_THERMAL_NOTIFY_DEVICES 0x82
61 #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0
62 #define ACPI_THERMAL_NOTIFY_HOT 0xF1
63 #define ACPI_THERMAL_MODE_ACTIVE 0x00
65 #define ACPI_THERMAL_MAX_ACTIVE 10
66 #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
68 #define KELVIN_TO_CELSIUS(t) (long)(((long)t-2732>=0) ? ((long)t-2732+5)/10 : ((long)t-2732-5)/10)
69 #define CELSIUS_TO_KELVIN(t) ((t+273)*10)
71 #define _COMPONENT ACPI_THERMAL_COMPONENT
72 ACPI_MODULE_NAME("thermal");
74 MODULE_AUTHOR("Paul Diefenbaugh");
75 MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
76 MODULE_LICENSE("GPL");
79 module_param(act, int, 0644);
80 MODULE_PARM_DESC(act, "Disable or override all lowest active trip points.");
83 module_param(crt, int, 0644);
84 MODULE_PARM_DESC(crt, "Disable or lower all critical trip points.");
87 module_param(tzp, int, 0444);
88 MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.");
91 module_param(nocrt, int, 0);
92 MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points.");
95 module_param(off, int, 0);
96 MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.");
99 module_param(psv, int, 0644);
100 MODULE_PARM_DESC(psv, "Disable or override all passive trip points.");
102 static int acpi_thermal_add(struct acpi_device *device);
103 static int acpi_thermal_remove(struct acpi_device *device, int type);
104 static int acpi_thermal_resume(struct acpi_device *device);
105 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
106 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
107 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
108 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
109 static ssize_t acpi_thermal_write_cooling_mode(struct file *,
110 const char __user *, size_t,
112 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
113 static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
116 static const struct acpi_device_id thermal_device_ids[] = {
117 {ACPI_THERMAL_HID, 0},
120 MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
122 static struct acpi_driver acpi_thermal_driver = {
124 .class = ACPI_THERMAL_CLASS,
125 .ids = thermal_device_ids,
127 .add = acpi_thermal_add,
128 .remove = acpi_thermal_remove,
129 .resume = acpi_thermal_resume,
133 struct acpi_thermal_state {
142 struct acpi_thermal_state_flags {
148 struct acpi_thermal_critical {
149 struct acpi_thermal_state_flags flags;
150 unsigned long temperature;
153 struct acpi_thermal_hot {
154 struct acpi_thermal_state_flags flags;
155 unsigned long temperature;
158 struct acpi_thermal_passive {
159 struct acpi_thermal_state_flags flags;
160 unsigned long temperature;
164 struct acpi_handle_list devices;
167 struct acpi_thermal_active {
168 struct acpi_thermal_state_flags flags;
169 unsigned long temperature;
170 struct acpi_handle_list devices;
173 struct acpi_thermal_trips {
174 struct acpi_thermal_critical critical;
175 struct acpi_thermal_hot hot;
176 struct acpi_thermal_passive passive;
177 struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
180 struct acpi_thermal_flags {
181 u8 cooling_mode:1; /* _SCP */
182 u8 devices:1; /* _TZD */
186 struct acpi_thermal {
187 struct acpi_device * device;
189 unsigned long temperature;
190 unsigned long last_temperature;
191 unsigned long polling_frequency;
193 struct acpi_thermal_flags flags;
194 struct acpi_thermal_state state;
195 struct acpi_thermal_trips trips;
196 struct acpi_handle_list devices;
197 struct timer_list timer;
201 static const struct file_operations acpi_thermal_state_fops = {
202 .open = acpi_thermal_state_open_fs,
205 .release = single_release,
208 static const struct file_operations acpi_thermal_temp_fops = {
209 .open = acpi_thermal_temp_open_fs,
212 .release = single_release,
215 static const struct file_operations acpi_thermal_trip_fops = {
216 .open = acpi_thermal_trip_open_fs,
219 .release = single_release,
222 static const struct file_operations acpi_thermal_cooling_fops = {
223 .open = acpi_thermal_cooling_open_fs,
225 .write = acpi_thermal_write_cooling_mode,
227 .release = single_release,
230 static const struct file_operations acpi_thermal_polling_fops = {
231 .open = acpi_thermal_polling_open_fs,
233 .write = acpi_thermal_write_polling,
235 .release = single_release,
238 /* --------------------------------------------------------------------------
239 Thermal Zone Management
240 -------------------------------------------------------------------------- */
242 static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
244 acpi_status status = AE_OK;
250 tz->last_temperature = tz->temperature;
253 acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tz->temperature);
254 if (ACPI_FAILURE(status))
257 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
263 static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
265 acpi_status status = AE_OK;
272 acpi_evaluate_integer(tz->device->handle, "_TZP", NULL,
273 &tz->polling_frequency);
274 if (ACPI_FAILURE(status))
277 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
278 tz->polling_frequency));
283 static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
289 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
291 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
292 "Polling frequency set to %lu seconds\n",
293 tz->polling_frequency/10));
298 static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
300 acpi_status status = AE_OK;
301 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
302 struct acpi_object_list arg_list = { 1, &arg0 };
303 acpi_handle handle = NULL;
309 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
310 if (ACPI_FAILURE(status)) {
311 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
315 arg0.integer.value = mode;
317 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
318 if (ACPI_FAILURE(status))
324 static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
326 acpi_status status = AE_OK;
333 /* Critical Shutdown (required) */
335 status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL,
336 &tz->trips.critical.temperature);
337 if (ACPI_FAILURE(status)) {
338 tz->trips.critical.flags.valid = 0;
339 ACPI_EXCEPTION((AE_INFO, status, "No critical threshold"));
342 tz->trips.critical.flags.valid = 1;
343 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
344 "Found critical threshold [%lu]\n",
345 tz->trips.critical.temperature));
348 if (tz->trips.critical.flags.valid == 1) {
350 tz->trips.critical.flags.valid = 0;
351 } else if (crt > 0) {
352 unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
355 * Allow override to lower critical threshold
357 if (crt_k < tz->trips.critical.temperature)
358 tz->trips.critical.temperature = crt_k;
362 /* Critical Sleep (optional) */
365 acpi_evaluate_integer(tz->device->handle, "_HOT", NULL,
366 &tz->trips.hot.temperature);
367 if (ACPI_FAILURE(status)) {
368 tz->trips.hot.flags.valid = 0;
369 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No hot threshold\n"));
371 tz->trips.hot.flags.valid = 1;
372 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found hot threshold [%lu]\n",
373 tz->trips.hot.temperature));
376 /* Passive: Processors (optional) */
380 } else if (psv > 0) {
381 tz->trips.passive.temperature = CELSIUS_TO_KELVIN(psv);
384 status = acpi_evaluate_integer(tz->device->handle,
385 "_PSV", NULL, &tz->trips.passive.temperature);
388 if (ACPI_FAILURE(status)) {
389 tz->trips.passive.flags.valid = 0;
390 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No passive threshold\n"));
392 tz->trips.passive.flags.valid = 1;
395 acpi_evaluate_integer(tz->device->handle, "_TC1", NULL,
396 &tz->trips.passive.tc1);
397 if (ACPI_FAILURE(status))
398 tz->trips.passive.flags.valid = 0;
401 acpi_evaluate_integer(tz->device->handle, "_TC2", NULL,
402 &tz->trips.passive.tc2);
403 if (ACPI_FAILURE(status))
404 tz->trips.passive.flags.valid = 0;
407 acpi_evaluate_integer(tz->device->handle, "_TSP", NULL,
408 &tz->trips.passive.tsp);
409 if (ACPI_FAILURE(status))
410 tz->trips.passive.flags.valid = 0;
413 acpi_evaluate_reference(tz->device->handle, "_PSL", NULL,
414 &tz->trips.passive.devices);
415 if (ACPI_FAILURE(status))
416 tz->trips.passive.flags.valid = 0;
418 if (!tz->trips.passive.flags.valid)
419 printk(KERN_WARNING PREFIX "Invalid passive threshold\n");
421 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
422 "Found passive threshold [%lu]\n",
423 tz->trips.passive.temperature));
426 /* Active: Fans, etc. (optional) */
428 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
430 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
433 break; /* disable all active trip points */
435 status = acpi_evaluate_integer(tz->device->handle,
436 name, NULL, &tz->trips.active[i].temperature);
438 if (ACPI_FAILURE(status)) {
439 if (i == 0) /* no active trip points */
441 if (act <= 0) /* no override requested */
443 if (i == 1) { /* 1 trip point */
444 tz->trips.active[0].temperature =
445 CELSIUS_TO_KELVIN(act);
446 } else { /* multiple trips */
448 * Don't allow override higher than
449 * the next higher trip point
451 tz->trips.active[i - 1].temperature =
452 (tz->trips.active[i - 2].temperature <
453 CELSIUS_TO_KELVIN(act) ?
454 tz->trips.active[i - 2].temperature :
455 CELSIUS_TO_KELVIN(act));
462 acpi_evaluate_reference(tz->device->handle, name, NULL,
463 &tz->trips.active[i].devices);
464 if (ACPI_SUCCESS(status)) {
465 tz->trips.active[i].flags.valid = 1;
466 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
467 "Found active threshold [%d]:[%lu]\n",
468 i, tz->trips.active[i].temperature));
470 ACPI_EXCEPTION((AE_INFO, status,
471 "Invalid active threshold [%d]", i));
477 static int acpi_thermal_get_devices(struct acpi_thermal *tz)
479 acpi_status status = AE_OK;
486 acpi_evaluate_reference(tz->device->handle, "_TZD", NULL, &tz->devices);
487 if (ACPI_FAILURE(status))
493 static int acpi_thermal_critical(struct acpi_thermal *tz)
495 if (!tz || !tz->trips.critical.flags.valid || nocrt)
498 if (tz->temperature >= tz->trips.critical.temperature) {
499 printk(KERN_WARNING PREFIX "Critical trip point\n");
500 tz->trips.critical.flags.enabled = 1;
501 } else if (tz->trips.critical.flags.enabled)
502 tz->trips.critical.flags.enabled = 0;
505 "Critical temperature reached (%ld C), shutting down.\n",
506 KELVIN_TO_CELSIUS(tz->temperature));
507 acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL,
508 tz->trips.critical.flags.enabled);
509 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
510 tz->device->dev.bus_id,
511 ACPI_THERMAL_NOTIFY_CRITICAL,
512 tz->trips.critical.flags.enabled);
514 orderly_poweroff(true);
519 static int acpi_thermal_hot(struct acpi_thermal *tz)
521 if (!tz || !tz->trips.hot.flags.valid || nocrt)
524 if (tz->temperature >= tz->trips.hot.temperature) {
525 printk(KERN_WARNING PREFIX "Hot trip point\n");
526 tz->trips.hot.flags.enabled = 1;
527 } else if (tz->trips.hot.flags.enabled)
528 tz->trips.hot.flags.enabled = 0;
530 acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
531 tz->trips.hot.flags.enabled);
532 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
533 tz->device->dev.bus_id,
534 ACPI_THERMAL_NOTIFY_HOT,
535 tz->trips.hot.flags.enabled);
537 /* TBD: Call user-mode "sleep(S4)" function */
542 static void acpi_thermal_passive(struct acpi_thermal *tz)
545 struct acpi_thermal_passive *passive = NULL;
550 if (!tz || !tz->trips.passive.flags.valid)
553 passive = &(tz->trips.passive);
558 * Calculate the thermal trend (using the passive cooling equation)
559 * and modify the performance limit for all passive cooling devices
560 * accordingly. Note that we assume symmetry.
562 if (tz->temperature >= passive->temperature) {
564 (passive->tc1 * (tz->temperature - tz->last_temperature)) +
565 (passive->tc2 * (tz->temperature - passive->temperature));
566 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
567 "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
568 trend, passive->tc1, tz->temperature,
569 tz->last_temperature, passive->tc2,
570 tz->temperature, passive->temperature));
571 passive->flags.enabled = 1;
574 for (i = 0; i < passive->devices.count; i++)
575 acpi_processor_set_thermal_limit(passive->
578 ACPI_PROCESSOR_LIMIT_INCREMENT);
580 else if (trend < 0) {
581 for (i = 0; i < passive->devices.count; i++)
583 * assume that we are on highest
584 * freq/lowest thrott and can leave
585 * passive mode, even in error case
587 if (!acpi_processor_set_thermal_limit
588 (passive->devices.handles[i],
589 ACPI_PROCESSOR_LIMIT_DECREMENT))
592 * Leave cooling mode, even if the temp might
593 * higher than trip point This is because some
594 * machines might have long thermal polling
595 * frequencies (tsp) defined. We will fall back
596 * into passive mode in next cycle (probably quicker)
599 passive->flags.enabled = 0;
600 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
601 "Disabling passive cooling, still above threshold,"
602 " but we are cooling down\n"));
611 * Implement passive cooling hysteresis to slowly increase performance
612 * and avoid thrashing around the passive trip point. Note that we
615 if (!passive->flags.enabled)
617 for (i = 0; i < passive->devices.count; i++)
618 if (!acpi_processor_set_thermal_limit
619 (passive->devices.handles[i],
620 ACPI_PROCESSOR_LIMIT_DECREMENT))
623 passive->flags.enabled = 0;
624 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
625 "Disabling passive cooling (zone is cool)\n"));
629 static void acpi_thermal_active(struct acpi_thermal *tz)
632 struct acpi_thermal_active *active = NULL;
635 unsigned long maxtemp = 0;
641 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
642 active = &(tz->trips.active[i]);
643 if (!active || !active->flags.valid)
645 if (tz->temperature >= active->temperature) {
649 * If not already enabled, turn ON all cooling devices
650 * associated with this active threshold.
652 if (active->temperature > maxtemp)
653 tz->state.active_index = i;
654 maxtemp = active->temperature;
655 if (active->flags.enabled)
657 for (j = 0; j < active->devices.count; j++) {
659 acpi_bus_set_power(active->devices.
663 printk(KERN_WARNING PREFIX
664 "Unable to turn cooling device [%p] 'on'\n",
669 active->flags.enabled = 1;
670 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
671 "Cooling device [%p] now 'on'\n",
672 active->devices.handles[j]));
676 if (!active->flags.enabled)
681 * Turn OFF all cooling devices associated with this
684 for (j = 0; j < active->devices.count; j++) {
685 result = acpi_bus_set_power(active->devices.handles[j],
688 printk(KERN_WARNING PREFIX
689 "Unable to turn cooling device [%p] 'off'\n",
690 active->devices.handles[j]);
693 active->flags.enabled = 0;
694 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
695 "Cooling device [%p] now 'off'\n",
696 active->devices.handles[j]));
701 static void acpi_thermal_check(void *context);
703 static void acpi_thermal_run(unsigned long data)
705 struct acpi_thermal *tz = (struct acpi_thermal *)data;
707 acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data);
710 static void acpi_thermal_check(void *data)
713 struct acpi_thermal *tz = data;
714 unsigned long sleep_time = 0;
715 unsigned long timeout_jiffies = 0;
717 struct acpi_thermal_state state;
721 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
725 /* Check if someone else is already running */
726 if (!mutex_trylock(&tz->lock))
731 result = acpi_thermal_get_temperature(tz);
735 memset(&tz->state, 0, sizeof(tz->state));
740 * Compare the current temperature to the trip point values to see
741 * if we've entered one of the thermal policy states. Note that
742 * this function determines when a state is entered, but the
743 * individual policy decides when it is exited (e.g. hysteresis).
745 if (tz->trips.critical.flags.valid)
747 (tz->temperature >= tz->trips.critical.temperature);
748 if (tz->trips.hot.flags.valid)
749 state.hot |= (tz->temperature >= tz->trips.hot.temperature);
750 if (tz->trips.passive.flags.valid)
752 (tz->temperature >= tz->trips.passive.temperature);
753 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
754 if (tz->trips.active[i].flags.valid)
757 tz->trips.active[i].temperature);
762 * Separated from the above check to allow individual policy to
763 * determine when to exit a given state.
766 acpi_thermal_critical(tz);
768 acpi_thermal_hot(tz);
770 acpi_thermal_passive(tz);
772 acpi_thermal_active(tz);
777 * Again, separated from the above two to allow independent policy
780 tz->state.critical = tz->trips.critical.flags.enabled;
781 tz->state.hot = tz->trips.hot.flags.enabled;
782 tz->state.passive = tz->trips.passive.flags.enabled;
783 tz->state.active = 0;
784 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
785 tz->state.active |= tz->trips.active[i].flags.enabled;
788 * Calculate Sleep Time
789 * --------------------
790 * If we're in the passive state, use _TSP's value. Otherwise
791 * use the default polling frequency (e.g. _TZP). If no polling
792 * frequency is specified then we'll wait forever (at least until
793 * a thermal event occurs). Note that _TSP and _TZD values are
794 * given in 1/10th seconds (we must covert to milliseconds).
796 if (tz->state.passive) {
797 sleep_time = tz->trips.passive.tsp * 100;
798 timeout_jiffies = jiffies + (HZ * sleep_time) / 1000;
799 } else if (tz->polling_frequency > 0) {
800 sleep_time = tz->polling_frequency * 100;
801 timeout_jiffies = round_jiffies(jiffies + (HZ * sleep_time) / 1000);
804 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n",
805 tz->name, tz->temperature, sleep_time));
812 if (timer_pending(&(tz->timer)))
813 del_timer(&(tz->timer));
815 if (timer_pending(&(tz->timer)))
816 mod_timer(&(tz->timer), timeout_jiffies);
818 tz->timer.data = (unsigned long)tz;
819 tz->timer.function = acpi_thermal_run;
820 tz->timer.expires = timeout_jiffies;
821 add_timer(&(tz->timer));
825 mutex_unlock(&tz->lock);
828 /* --------------------------------------------------------------------------
830 -------------------------------------------------------------------------- */
832 static struct proc_dir_entry *acpi_thermal_dir;
834 static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
836 struct acpi_thermal *tz = seq->private;
842 seq_puts(seq, "state: ");
844 if (!tz->state.critical && !tz->state.hot && !tz->state.passive
845 && !tz->state.active)
846 seq_puts(seq, "ok\n");
848 if (tz->state.critical)
849 seq_puts(seq, "critical ");
851 seq_puts(seq, "hot ");
852 if (tz->state.passive)
853 seq_puts(seq, "passive ");
854 if (tz->state.active)
855 seq_printf(seq, "active[%d]", tz->state.active_index);
863 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
865 return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
868 static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
871 struct acpi_thermal *tz = seq->private;
877 result = acpi_thermal_get_temperature(tz);
881 seq_printf(seq, "temperature: %ld C\n",
882 KELVIN_TO_CELSIUS(tz->temperature));
888 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
890 return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
893 static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
895 struct acpi_thermal *tz = seq->private;
896 struct acpi_device *device;
906 if (tz->trips.critical.flags.valid)
907 seq_printf(seq, "critical (S5): %ld C%s",
908 KELVIN_TO_CELSIUS(tz->trips.critical.temperature),
909 nocrt ? " <disabled>\n" : "\n");
911 if (tz->trips.hot.flags.valid)
912 seq_printf(seq, "hot (S4): %ld C%s",
913 KELVIN_TO_CELSIUS(tz->trips.hot.temperature),
914 nocrt ? " <disabled>\n" : "\n");
916 if (tz->trips.passive.flags.valid) {
918 "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
919 KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
920 tz->trips.passive.tc1, tz->trips.passive.tc2,
921 tz->trips.passive.tsp);
922 for (j = 0; j < tz->trips.passive.devices.count; j++) {
923 status = acpi_bus_get_device(tz->trips.passive.devices.
924 handles[j], &device);
925 seq_printf(seq, "%4.4s ", status ? "" :
926 acpi_device_bid(device));
931 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
932 if (!(tz->trips.active[i].flags.valid))
934 seq_printf(seq, "active[%d]: %ld C: devices=",
936 KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
937 for (j = 0; j < tz->trips.active[i].devices.count; j++){
938 status = acpi_bus_get_device(tz->trips.active[i].
941 seq_printf(seq, "%4.4s ", status ? "" :
942 acpi_device_bid(device));
951 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
953 return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
956 static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
958 struct acpi_thermal *tz = seq->private;
964 if (!tz->flags.cooling_mode)
965 seq_puts(seq, "<setting not supported>\n");
967 seq_puts(seq, "0 - Active; 1 - Passive\n");
973 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
975 return single_open(file, acpi_thermal_cooling_seq_show,
980 acpi_thermal_write_cooling_mode(struct file *file,
981 const char __user * buffer,
982 size_t count, loff_t * ppos)
984 struct seq_file *m = file->private_data;
985 struct acpi_thermal *tz = m->private;
987 char mode_string[12] = { '\0' };
990 if (!tz || (count > sizeof(mode_string) - 1))
993 if (!tz->flags.cooling_mode)
996 if (copy_from_user(mode_string, buffer, count))
999 mode_string[count] = '\0';
1001 result = acpi_thermal_set_cooling_mode(tz,
1002 simple_strtoul(mode_string, NULL,
1007 acpi_thermal_check(tz);
1012 static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
1014 struct acpi_thermal *tz = seq->private;
1020 if (!tz->polling_frequency) {
1021 seq_puts(seq, "<polling disabled>\n");
1025 seq_printf(seq, "polling frequency: %lu seconds\n",
1026 (tz->polling_frequency / 10));
1032 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
1034 return single_open(file, acpi_thermal_polling_seq_show,
1039 acpi_thermal_write_polling(struct file *file,
1040 const char __user * buffer,
1041 size_t count, loff_t * ppos)
1043 struct seq_file *m = file->private_data;
1044 struct acpi_thermal *tz = m->private;
1046 char polling_string[12] = { '\0' };
1050 if (!tz || (count > sizeof(polling_string) - 1))
1053 if (copy_from_user(polling_string, buffer, count))
1056 polling_string[count] = '\0';
1058 seconds = simple_strtoul(polling_string, NULL, 0);
1060 result = acpi_thermal_set_polling(tz, seconds);
1064 acpi_thermal_check(tz);
1069 static int acpi_thermal_add_fs(struct acpi_device *device)
1071 struct proc_dir_entry *entry = NULL;
1074 if (!acpi_device_dir(device)) {
1075 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1077 if (!acpi_device_dir(device))
1079 acpi_device_dir(device)->owner = THIS_MODULE;
1083 entry = create_proc_entry(ACPI_THERMAL_FILE_STATE,
1084 S_IRUGO, acpi_device_dir(device));
1088 entry->proc_fops = &acpi_thermal_state_fops;
1089 entry->data = acpi_driver_data(device);
1090 entry->owner = THIS_MODULE;
1093 /* 'temperature' [R] */
1094 entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1095 S_IRUGO, acpi_device_dir(device));
1099 entry->proc_fops = &acpi_thermal_temp_fops;
1100 entry->data = acpi_driver_data(device);
1101 entry->owner = THIS_MODULE;
1104 /* 'trip_points' [R] */
1105 entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1107 acpi_device_dir(device));
1111 entry->proc_fops = &acpi_thermal_trip_fops;
1112 entry->data = acpi_driver_data(device);
1113 entry->owner = THIS_MODULE;
1116 /* 'cooling_mode' [R/W] */
1117 entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1118 S_IFREG | S_IRUGO | S_IWUSR,
1119 acpi_device_dir(device));
1123 entry->proc_fops = &acpi_thermal_cooling_fops;
1124 entry->data = acpi_driver_data(device);
1125 entry->owner = THIS_MODULE;
1128 /* 'polling_frequency' [R/W] */
1129 entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1130 S_IFREG | S_IRUGO | S_IWUSR,
1131 acpi_device_dir(device));
1135 entry->proc_fops = &acpi_thermal_polling_fops;
1136 entry->data = acpi_driver_data(device);
1137 entry->owner = THIS_MODULE;
1143 static int acpi_thermal_remove_fs(struct acpi_device *device)
1146 if (acpi_device_dir(device)) {
1147 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1148 acpi_device_dir(device));
1149 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1150 acpi_device_dir(device));
1151 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1152 acpi_device_dir(device));
1153 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1154 acpi_device_dir(device));
1155 remove_proc_entry(ACPI_THERMAL_FILE_STATE,
1156 acpi_device_dir(device));
1157 remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
1158 acpi_device_dir(device) = NULL;
1164 /* --------------------------------------------------------------------------
1166 -------------------------------------------------------------------------- */
1168 static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
1170 struct acpi_thermal *tz = data;
1171 struct acpi_device *device = NULL;
1177 device = tz->device;
1180 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
1181 acpi_thermal_check(tz);
1183 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
1184 acpi_thermal_get_trip_points(tz);
1185 acpi_thermal_check(tz);
1186 acpi_bus_generate_proc_event(device, event, 0);
1187 acpi_bus_generate_netlink_event(device->pnp.device_class,
1188 device->dev.bus_id, event, 0);
1190 case ACPI_THERMAL_NOTIFY_DEVICES:
1191 if (tz->flags.devices)
1192 acpi_thermal_get_devices(tz);
1193 acpi_bus_generate_proc_event(device, event, 0);
1194 acpi_bus_generate_netlink_event(device->pnp.device_class,
1195 device->dev.bus_id, event, 0);
1198 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1199 "Unsupported event [0x%x]\n", event));
1206 static int acpi_thermal_get_info(struct acpi_thermal *tz)
1214 /* Get temperature [_TMP] (required) */
1215 result = acpi_thermal_get_temperature(tz);
1219 /* Get trip points [_CRT, _PSV, etc.] (required) */
1220 result = acpi_thermal_get_trip_points(tz);
1224 /* Set the cooling mode [_SCP] to active cooling (default) */
1225 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
1227 tz->flags.cooling_mode = 1;
1229 /* Get default polling frequency [_TZP] (optional) */
1231 tz->polling_frequency = tzp;
1233 acpi_thermal_get_polling_frequency(tz);
1235 /* Get devices in this thermal zone [_TZD] (optional) */
1236 result = acpi_thermal_get_devices(tz);
1238 tz->flags.devices = 1;
1243 static int acpi_thermal_add(struct acpi_device *device)
1246 acpi_status status = AE_OK;
1247 struct acpi_thermal *tz = NULL;
1253 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1257 tz->device = device;
1258 strcpy(tz->name, device->pnp.bus_id);
1259 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1260 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
1261 acpi_driver_data(device) = tz;
1262 mutex_init(&tz->lock);
1263 result = acpi_thermal_get_info(tz);
1267 result = acpi_thermal_add_fs(device);
1271 init_timer(&tz->timer);
1273 acpi_thermal_check(tz);
1275 status = acpi_install_notify_handler(device->handle,
1277 acpi_thermal_notify, tz);
1278 if (ACPI_FAILURE(status)) {
1283 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
1284 acpi_device_name(device), acpi_device_bid(device),
1285 KELVIN_TO_CELSIUS(tz->temperature));
1289 acpi_thermal_remove_fs(device);
1296 static int acpi_thermal_remove(struct acpi_device *device, int type)
1298 acpi_status status = AE_OK;
1299 struct acpi_thermal *tz = NULL;
1302 if (!device || !acpi_driver_data(device))
1305 tz = acpi_driver_data(device);
1307 /* avoid timer adding new defer task */
1309 /* wait for running timer (on other CPUs) finish */
1310 del_timer_sync(&(tz->timer));
1311 /* synchronize deferred task */
1312 acpi_os_wait_events_complete(NULL);
1313 /* deferred task may reinsert timer */
1314 del_timer_sync(&(tz->timer));
1316 status = acpi_remove_notify_handler(device->handle,
1318 acpi_thermal_notify);
1320 /* Terminate policy */
1321 if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
1322 tz->trips.passive.flags.enabled = 0;
1323 acpi_thermal_passive(tz);
1325 if (tz->trips.active[0].flags.valid
1326 && tz->trips.active[0].flags.enabled) {
1327 tz->trips.active[0].flags.enabled = 0;
1328 acpi_thermal_active(tz);
1331 acpi_thermal_remove_fs(device);
1332 mutex_destroy(&tz->lock);
1337 static int acpi_thermal_resume(struct acpi_device *device)
1339 struct acpi_thermal *tz = NULL;
1340 int i, j, power_state, result;
1343 if (!device || !acpi_driver_data(device))
1346 tz = acpi_driver_data(device);
1348 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1349 if (!(&tz->trips.active[i]))
1351 if (!tz->trips.active[i].flags.valid)
1353 tz->trips.active[i].flags.enabled = 1;
1354 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1355 result = acpi_bus_get_power(tz->trips.active[i].devices.
1356 handles[j], &power_state);
1357 if (result || (power_state != ACPI_STATE_D0)) {
1358 tz->trips.active[i].flags.enabled = 0;
1362 tz->state.active |= tz->trips.active[i].flags.enabled;
1365 acpi_thermal_check(tz);
1371 static int thermal_act(const struct dmi_system_id *d) {
1374 printk(KERN_NOTICE "ACPI: %s detected: "
1375 "disabling all active thermal trip points\n", d->ident);
1380 static int thermal_nocrt(const struct dmi_system_id *d) {
1382 printk(KERN_NOTICE "ACPI: %s detected: "
1383 "disabling all critical thermal trip point actions.\n", d->ident);
1387 static int thermal_tzp(const struct dmi_system_id *d) {
1390 printk(KERN_NOTICE "ACPI: %s detected: "
1391 "enabling thermal zone polling\n", d->ident);
1392 tzp = 300; /* 300 dS = 30 Seconds */
1396 static int thermal_psv(const struct dmi_system_id *d) {
1399 printk(KERN_NOTICE "ACPI: %s detected: "
1400 "disabling all passive thermal trip points\n", d->ident);
1406 static struct dmi_system_id thermal_dmi_table[] __initdata = {
1408 * Award BIOS on this AOpen makes thermal control almost worthless.
1409 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1412 .callback = thermal_act,
1413 .ident = "AOpen i915GMm-HFS",
1415 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1416 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1420 .callback = thermal_psv,
1421 .ident = "AOpen i915GMm-HFS",
1423 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1424 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1428 .callback = thermal_tzp,
1429 .ident = "AOpen i915GMm-HFS",
1431 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1432 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1436 .callback = thermal_nocrt,
1437 .ident = "Gigabyte GA-7ZX",
1439 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
1440 DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
1445 #endif /* CONFIG_DMI */
1447 static int __init acpi_thermal_init(void)
1451 dmi_check_system(thermal_dmi_table);
1454 printk(KERN_NOTICE "ACPI: thermal control disabled\n");
1457 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
1458 if (!acpi_thermal_dir)
1460 acpi_thermal_dir->owner = THIS_MODULE;
1462 result = acpi_bus_register_driver(&acpi_thermal_driver);
1464 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1471 static void __exit acpi_thermal_exit(void)
1474 acpi_bus_unregister_driver(&acpi_thermal_driver);
1476 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1481 module_init(acpi_thermal_init);
1482 module_exit(acpi_thermal_exit);