2 * acpi_thermal.c - ACPI Thermal Zone Driver ($Revision: 41 $)
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 * This driver fully implements the ACPI thermal policy as described in the
26 * ACPI 2.0 Specification.
28 * TBD: 1. Implement passive cooling hysteresis.
29 * 2. Enhance passive cooling (CPU) states/limit interface to support
30 * concepts of 'multiple limiters', upper/lower limits, etc.
34 #include <linux/kernel.h>
35 #include <linux/module.h>
36 #include <linux/init.h>
37 #include <linux/types.h>
38 #include <linux/proc_fs.h>
39 #include <linux/timer.h>
40 #include <linux/jiffies.h>
41 #include <linux/kmod.h>
42 #include <linux/seq_file.h>
43 #include <linux/reboot.h>
44 #include <asm/uaccess.h>
46 #include <acpi/acpi_bus.h>
47 #include <acpi/acpi_drivers.h>
49 #define ACPI_THERMAL_COMPONENT 0x04000000
50 #define ACPI_THERMAL_CLASS "thermal_zone"
51 #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
52 #define ACPI_THERMAL_FILE_STATE "state"
53 #define ACPI_THERMAL_FILE_TEMPERATURE "temperature"
54 #define ACPI_THERMAL_FILE_TRIP_POINTS "trip_points"
55 #define ACPI_THERMAL_FILE_COOLING_MODE "cooling_mode"
56 #define ACPI_THERMAL_FILE_POLLING_FREQ "polling_frequency"
57 #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80
58 #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81
59 #define ACPI_THERMAL_NOTIFY_DEVICES 0x82
60 #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0
61 #define ACPI_THERMAL_NOTIFY_HOT 0xF1
62 #define ACPI_THERMAL_MODE_ACTIVE 0x00
64 #define ACPI_THERMAL_MAX_ACTIVE 10
65 #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
67 #define KELVIN_TO_CELSIUS(t) (long)(((long)t-2732>=0) ? ((long)t-2732+5)/10 : ((long)t-2732-5)/10)
68 #define CELSIUS_TO_KELVIN(t) ((t+273)*10)
70 #define _COMPONENT ACPI_THERMAL_COMPONENT
71 ACPI_MODULE_NAME("thermal");
73 MODULE_AUTHOR("Paul Diefenbaugh");
74 MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
75 MODULE_LICENSE("GPL");
78 module_param(tzp
, int, 0444);
79 MODULE_PARM_DESC(tzp
, "Thermal zone polling frequency, in 1/10 seconds.\n");
82 module_param(off
, int, 0);
83 MODULE_PARM_DESC(off
, "Set to disable ACPI thermal support.\n");
85 static int acpi_thermal_add(struct acpi_device
*device
);
86 static int acpi_thermal_remove(struct acpi_device
*device
, int type
);
87 static int acpi_thermal_resume(struct acpi_device
*device
);
88 static int acpi_thermal_state_open_fs(struct inode
*inode
, struct file
*file
);
89 static int acpi_thermal_temp_open_fs(struct inode
*inode
, struct file
*file
);
90 static int acpi_thermal_trip_open_fs(struct inode
*inode
, struct file
*file
);
91 static int acpi_thermal_cooling_open_fs(struct inode
*inode
, struct file
*file
);
92 static ssize_t
acpi_thermal_write_cooling_mode(struct file
*,
93 const char __user
*, size_t,
95 static int acpi_thermal_polling_open_fs(struct inode
*inode
, struct file
*file
);
96 static ssize_t
acpi_thermal_write_polling(struct file
*, const char __user
*,
99 static const struct acpi_device_id thermal_device_ids
[] = {
100 {ACPI_THERMAL_HID
, 0},
103 MODULE_DEVICE_TABLE(acpi
, thermal_device_ids
);
105 static struct acpi_driver acpi_thermal_driver
= {
107 .class = ACPI_THERMAL_CLASS
,
108 .ids
= thermal_device_ids
,
110 .add
= acpi_thermal_add
,
111 .remove
= acpi_thermal_remove
,
112 .resume
= acpi_thermal_resume
,
116 struct acpi_thermal_state
{
125 struct acpi_thermal_state_flags
{
131 struct acpi_thermal_critical
{
132 struct acpi_thermal_state_flags flags
;
133 unsigned long temperature
;
136 struct acpi_thermal_hot
{
137 struct acpi_thermal_state_flags flags
;
138 unsigned long temperature
;
141 struct acpi_thermal_passive
{
142 struct acpi_thermal_state_flags flags
;
143 unsigned long temperature
;
147 struct acpi_handle_list devices
;
150 struct acpi_thermal_active
{
151 struct acpi_thermal_state_flags flags
;
152 unsigned long temperature
;
153 struct acpi_handle_list devices
;
156 struct acpi_thermal_trips
{
157 struct acpi_thermal_critical critical
;
158 struct acpi_thermal_hot hot
;
159 struct acpi_thermal_passive passive
;
160 struct acpi_thermal_active active
[ACPI_THERMAL_MAX_ACTIVE
];
163 struct acpi_thermal_flags
{
164 u8 cooling_mode
:1; /* _SCP */
165 u8 devices
:1; /* _TZD */
169 struct acpi_thermal
{
170 struct acpi_device
* device
;
172 unsigned long temperature
;
173 unsigned long last_temperature
;
174 unsigned long polling_frequency
;
176 struct acpi_thermal_flags flags
;
177 struct acpi_thermal_state state
;
178 struct acpi_thermal_trips trips
;
179 struct acpi_handle_list devices
;
180 struct timer_list timer
;
183 static const struct file_operations acpi_thermal_state_fops
= {
184 .open
= acpi_thermal_state_open_fs
,
187 .release
= single_release
,
190 static const struct file_operations acpi_thermal_temp_fops
= {
191 .open
= acpi_thermal_temp_open_fs
,
194 .release
= single_release
,
197 static const struct file_operations acpi_thermal_trip_fops
= {
198 .open
= acpi_thermal_trip_open_fs
,
201 .release
= single_release
,
204 static const struct file_operations acpi_thermal_cooling_fops
= {
205 .open
= acpi_thermal_cooling_open_fs
,
207 .write
= acpi_thermal_write_cooling_mode
,
209 .release
= single_release
,
212 static const struct file_operations acpi_thermal_polling_fops
= {
213 .open
= acpi_thermal_polling_open_fs
,
215 .write
= acpi_thermal_write_polling
,
217 .release
= single_release
,
220 /* --------------------------------------------------------------------------
221 Thermal Zone Management
222 -------------------------------------------------------------------------- */
224 static int acpi_thermal_get_temperature(struct acpi_thermal
*tz
)
226 acpi_status status
= AE_OK
;
232 tz
->last_temperature
= tz
->temperature
;
235 acpi_evaluate_integer(tz
->device
->handle
, "_TMP", NULL
, &tz
->temperature
);
236 if (ACPI_FAILURE(status
))
239 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Temperature is %lu dK\n",
245 static int acpi_thermal_get_polling_frequency(struct acpi_thermal
*tz
)
247 acpi_status status
= AE_OK
;
254 acpi_evaluate_integer(tz
->device
->handle
, "_TZP", NULL
,
255 &tz
->polling_frequency
);
256 if (ACPI_FAILURE(status
))
259 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Polling frequency is %lu dS\n",
260 tz
->polling_frequency
));
265 static int acpi_thermal_set_polling(struct acpi_thermal
*tz
, int seconds
)
271 tz
->polling_frequency
= seconds
* 10; /* Convert value to deci-seconds */
273 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
274 "Polling frequency set to %lu seconds\n",
275 tz
->polling_frequency
/10));
280 static int acpi_thermal_set_cooling_mode(struct acpi_thermal
*tz
, int mode
)
282 acpi_status status
= AE_OK
;
283 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
284 struct acpi_object_list arg_list
= { 1, &arg0
};
285 acpi_handle handle
= NULL
;
291 status
= acpi_get_handle(tz
->device
->handle
, "_SCP", &handle
);
292 if (ACPI_FAILURE(status
)) {
293 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "_SCP not present\n"));
297 arg0
.integer
.value
= mode
;
299 status
= acpi_evaluate_object(handle
, NULL
, &arg_list
, NULL
);
300 if (ACPI_FAILURE(status
))
306 static int acpi_thermal_get_trip_points(struct acpi_thermal
*tz
)
308 acpi_status status
= AE_OK
;
315 /* Critical Shutdown (required) */
317 status
= acpi_evaluate_integer(tz
->device
->handle
, "_CRT", NULL
,
318 &tz
->trips
.critical
.temperature
);
319 if (ACPI_FAILURE(status
)) {
320 tz
->trips
.critical
.flags
.valid
= 0;
321 ACPI_EXCEPTION((AE_INFO
, status
, "No critical threshold"));
324 tz
->trips
.critical
.flags
.valid
= 1;
325 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
326 "Found critical threshold [%lu]\n",
327 tz
->trips
.critical
.temperature
));
330 /* Critical Sleep (optional) */
333 acpi_evaluate_integer(tz
->device
->handle
, "_HOT", NULL
,
334 &tz
->trips
.hot
.temperature
);
335 if (ACPI_FAILURE(status
)) {
336 tz
->trips
.hot
.flags
.valid
= 0;
337 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "No hot threshold\n"));
339 tz
->trips
.hot
.flags
.valid
= 1;
340 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found hot threshold [%lu]\n",
341 tz
->trips
.hot
.temperature
));
344 /* Passive: Processors (optional) */
347 acpi_evaluate_integer(tz
->device
->handle
, "_PSV", NULL
,
348 &tz
->trips
.passive
.temperature
);
349 if (ACPI_FAILURE(status
)) {
350 tz
->trips
.passive
.flags
.valid
= 0;
351 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "No passive threshold\n"));
353 tz
->trips
.passive
.flags
.valid
= 1;
356 acpi_evaluate_integer(tz
->device
->handle
, "_TC1", NULL
,
357 &tz
->trips
.passive
.tc1
);
358 if (ACPI_FAILURE(status
))
359 tz
->trips
.passive
.flags
.valid
= 0;
362 acpi_evaluate_integer(tz
->device
->handle
, "_TC2", NULL
,
363 &tz
->trips
.passive
.tc2
);
364 if (ACPI_FAILURE(status
))
365 tz
->trips
.passive
.flags
.valid
= 0;
368 acpi_evaluate_integer(tz
->device
->handle
, "_TSP", NULL
,
369 &tz
->trips
.passive
.tsp
);
370 if (ACPI_FAILURE(status
))
371 tz
->trips
.passive
.flags
.valid
= 0;
374 acpi_evaluate_reference(tz
->device
->handle
, "_PSL", NULL
,
375 &tz
->trips
.passive
.devices
);
376 if (ACPI_FAILURE(status
))
377 tz
->trips
.passive
.flags
.valid
= 0;
379 if (!tz
->trips
.passive
.flags
.valid
)
380 printk(KERN_WARNING PREFIX
"Invalid passive threshold\n");
382 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
383 "Found passive threshold [%lu]\n",
384 tz
->trips
.passive
.temperature
));
387 /* Active: Fans, etc. (optional) */
389 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
391 char name
[5] = { '_', 'A', 'C', ('0' + i
), '\0' };
394 acpi_evaluate_integer(tz
->device
->handle
, name
, NULL
,
395 &tz
->trips
.active
[i
].temperature
);
396 if (ACPI_FAILURE(status
))
401 acpi_evaluate_reference(tz
->device
->handle
, name
, NULL
,
402 &tz
->trips
.active
[i
].devices
);
403 if (ACPI_SUCCESS(status
)) {
404 tz
->trips
.active
[i
].flags
.valid
= 1;
405 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
406 "Found active threshold [%d]:[%lu]\n",
407 i
, tz
->trips
.active
[i
].temperature
));
409 ACPI_EXCEPTION((AE_INFO
, status
,
410 "Invalid active threshold [%d]", i
));
416 static int acpi_thermal_get_devices(struct acpi_thermal
*tz
)
418 acpi_status status
= AE_OK
;
425 acpi_evaluate_reference(tz
->device
->handle
, "_TZD", NULL
, &tz
->devices
);
426 if (ACPI_FAILURE(status
))
432 static int acpi_thermal_critical(struct acpi_thermal
*tz
)
434 if (!tz
|| !tz
->trips
.critical
.flags
.valid
)
437 if (tz
->temperature
>= tz
->trips
.critical
.temperature
) {
438 printk(KERN_WARNING PREFIX
"Critical trip point\n");
439 tz
->trips
.critical
.flags
.enabled
= 1;
440 } else if (tz
->trips
.critical
.flags
.enabled
)
441 tz
->trips
.critical
.flags
.enabled
= 0;
444 "Critical temperature reached (%ld C), shutting down.\n",
445 KELVIN_TO_CELSIUS(tz
->temperature
));
446 acpi_bus_generate_event(tz
->device
, ACPI_THERMAL_NOTIFY_CRITICAL
,
447 tz
->trips
.critical
.flags
.enabled
);
449 orderly_poweroff(true);
454 static int acpi_thermal_hot(struct acpi_thermal
*tz
)
456 if (!tz
|| !tz
->trips
.hot
.flags
.valid
)
459 if (tz
->temperature
>= tz
->trips
.hot
.temperature
) {
460 printk(KERN_WARNING PREFIX
"Hot trip point\n");
461 tz
->trips
.hot
.flags
.enabled
= 1;
462 } else if (tz
->trips
.hot
.flags
.enabled
)
463 tz
->trips
.hot
.flags
.enabled
= 0;
465 acpi_bus_generate_event(tz
->device
, ACPI_THERMAL_NOTIFY_HOT
,
466 tz
->trips
.hot
.flags
.enabled
);
468 /* TBD: Call user-mode "sleep(S4)" function */
473 static void acpi_thermal_passive(struct acpi_thermal
*tz
)
476 struct acpi_thermal_passive
*passive
= NULL
;
481 if (!tz
|| !tz
->trips
.passive
.flags
.valid
)
484 passive
= &(tz
->trips
.passive
);
489 * Calculate the thermal trend (using the passive cooling equation)
490 * and modify the performance limit for all passive cooling devices
491 * accordingly. Note that we assume symmetry.
493 if (tz
->temperature
>= passive
->temperature
) {
495 (passive
->tc1
* (tz
->temperature
- tz
->last_temperature
)) +
496 (passive
->tc2
* (tz
->temperature
- passive
->temperature
));
497 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
498 "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
499 trend
, passive
->tc1
, tz
->temperature
,
500 tz
->last_temperature
, passive
->tc2
,
501 tz
->temperature
, passive
->temperature
));
502 passive
->flags
.enabled
= 1;
505 for (i
= 0; i
< passive
->devices
.count
; i
++)
506 acpi_processor_set_thermal_limit(passive
->
509 ACPI_PROCESSOR_LIMIT_INCREMENT
);
511 else if (trend
< 0) {
512 for (i
= 0; i
< passive
->devices
.count
; i
++)
514 * assume that we are on highest
515 * freq/lowest thrott and can leave
516 * passive mode, even in error case
518 if (!acpi_processor_set_thermal_limit
519 (passive
->devices
.handles
[i
],
520 ACPI_PROCESSOR_LIMIT_DECREMENT
))
523 * Leave cooling mode, even if the temp might
524 * higher than trip point This is because some
525 * machines might have long thermal polling
526 * frequencies (tsp) defined. We will fall back
527 * into passive mode in next cycle (probably quicker)
530 passive
->flags
.enabled
= 0;
531 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
532 "Disabling passive cooling, still above threshold,"
533 " but we are cooling down\n"));
542 * Implement passive cooling hysteresis to slowly increase performance
543 * and avoid thrashing around the passive trip point. Note that we
546 if (!passive
->flags
.enabled
)
548 for (i
= 0; i
< passive
->devices
.count
; i
++)
549 if (!acpi_processor_set_thermal_limit
550 (passive
->devices
.handles
[i
],
551 ACPI_PROCESSOR_LIMIT_DECREMENT
))
554 passive
->flags
.enabled
= 0;
555 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
556 "Disabling passive cooling (zone is cool)\n"));
560 static void acpi_thermal_active(struct acpi_thermal
*tz
)
563 struct acpi_thermal_active
*active
= NULL
;
566 unsigned long maxtemp
= 0;
572 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
573 active
= &(tz
->trips
.active
[i
]);
574 if (!active
|| !active
->flags
.valid
)
576 if (tz
->temperature
>= active
->temperature
) {
580 * If not already enabled, turn ON all cooling devices
581 * associated with this active threshold.
583 if (active
->temperature
> maxtemp
)
584 tz
->state
.active_index
= i
;
585 maxtemp
= active
->temperature
;
586 if (active
->flags
.enabled
)
588 for (j
= 0; j
< active
->devices
.count
; j
++) {
590 acpi_bus_set_power(active
->devices
.
594 printk(KERN_WARNING PREFIX
595 "Unable to turn cooling device [%p] 'on'\n",
600 active
->flags
.enabled
= 1;
601 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
602 "Cooling device [%p] now 'on'\n",
603 active
->devices
.handles
[j
]));
607 if (!active
->flags
.enabled
)
612 * Turn OFF all cooling devices associated with this
615 for (j
= 0; j
< active
->devices
.count
; j
++) {
616 result
= acpi_bus_set_power(active
->devices
.handles
[j
],
619 printk(KERN_WARNING PREFIX
620 "Unable to turn cooling device [%p] 'off'\n",
621 active
->devices
.handles
[j
]);
624 active
->flags
.enabled
= 0;
625 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
626 "Cooling device [%p] now 'off'\n",
627 active
->devices
.handles
[j
]));
632 static void acpi_thermal_check(void *context
);
634 static void acpi_thermal_run(unsigned long data
)
636 struct acpi_thermal
*tz
= (struct acpi_thermal
*)data
;
638 acpi_os_execute(OSL_GPE_HANDLER
, acpi_thermal_check
, (void *)data
);
641 static void acpi_thermal_check(void *data
)
644 struct acpi_thermal
*tz
= data
;
645 unsigned long sleep_time
= 0;
647 struct acpi_thermal_state state
;
651 printk(KERN_ERR PREFIX
"Invalid (NULL) context\n");
657 result
= acpi_thermal_get_temperature(tz
);
661 memset(&tz
->state
, 0, sizeof(tz
->state
));
666 * Compare the current temperature to the trip point values to see
667 * if we've entered one of the thermal policy states. Note that
668 * this function determines when a state is entered, but the
669 * individual policy decides when it is exited (e.g. hysteresis).
671 if (tz
->trips
.critical
.flags
.valid
)
673 (tz
->temperature
>= tz
->trips
.critical
.temperature
);
674 if (tz
->trips
.hot
.flags
.valid
)
675 state
.hot
|= (tz
->temperature
>= tz
->trips
.hot
.temperature
);
676 if (tz
->trips
.passive
.flags
.valid
)
678 (tz
->temperature
>= tz
->trips
.passive
.temperature
);
679 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++)
680 if (tz
->trips
.active
[i
].flags
.valid
)
683 tz
->trips
.active
[i
].temperature
);
688 * Separated from the above check to allow individual policy to
689 * determine when to exit a given state.
692 acpi_thermal_critical(tz
);
694 acpi_thermal_hot(tz
);
696 acpi_thermal_passive(tz
);
698 acpi_thermal_active(tz
);
703 * Again, separated from the above two to allow independent policy
706 tz
->state
.critical
= tz
->trips
.critical
.flags
.enabled
;
707 tz
->state
.hot
= tz
->trips
.hot
.flags
.enabled
;
708 tz
->state
.passive
= tz
->trips
.passive
.flags
.enabled
;
709 tz
->state
.active
= 0;
710 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++)
711 tz
->state
.active
|= tz
->trips
.active
[i
].flags
.enabled
;
714 * Calculate Sleep Time
715 * --------------------
716 * If we're in the passive state, use _TSP's value. Otherwise
717 * use the default polling frequency (e.g. _TZP). If no polling
718 * frequency is specified then we'll wait forever (at least until
719 * a thermal event occurs). Note that _TSP and _TZD values are
720 * given in 1/10th seconds (we must covert to milliseconds).
722 if (tz
->state
.passive
)
723 sleep_time
= tz
->trips
.passive
.tsp
* 100;
724 else if (tz
->polling_frequency
> 0)
725 sleep_time
= tz
->polling_frequency
* 100;
727 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "%s: temperature[%lu] sleep[%lu]\n",
728 tz
->name
, tz
->temperature
, sleep_time
));
735 if (timer_pending(&(tz
->timer
)))
736 del_timer(&(tz
->timer
));
738 if (timer_pending(&(tz
->timer
)))
739 mod_timer(&(tz
->timer
),
740 jiffies
+ (HZ
* sleep_time
) / 1000);
742 tz
->timer
.data
= (unsigned long)tz
;
743 tz
->timer
.function
= acpi_thermal_run
;
744 tz
->timer
.expires
= jiffies
+ (HZ
* sleep_time
) / 1000;
745 add_timer(&(tz
->timer
));
752 /* --------------------------------------------------------------------------
754 -------------------------------------------------------------------------- */
756 static struct proc_dir_entry
*acpi_thermal_dir
;
758 static int acpi_thermal_state_seq_show(struct seq_file
*seq
, void *offset
)
760 struct acpi_thermal
*tz
= seq
->private;
766 seq_puts(seq
, "state: ");
768 if (!tz
->state
.critical
&& !tz
->state
.hot
&& !tz
->state
.passive
769 && !tz
->state
.active
)
770 seq_puts(seq
, "ok\n");
772 if (tz
->state
.critical
)
773 seq_puts(seq
, "critical ");
775 seq_puts(seq
, "hot ");
776 if (tz
->state
.passive
)
777 seq_puts(seq
, "passive ");
778 if (tz
->state
.active
)
779 seq_printf(seq
, "active[%d]", tz
->state
.active_index
);
787 static int acpi_thermal_state_open_fs(struct inode
*inode
, struct file
*file
)
789 return single_open(file
, acpi_thermal_state_seq_show
, PDE(inode
)->data
);
792 static int acpi_thermal_temp_seq_show(struct seq_file
*seq
, void *offset
)
795 struct acpi_thermal
*tz
= seq
->private;
801 result
= acpi_thermal_get_temperature(tz
);
805 seq_printf(seq
, "temperature: %ld C\n",
806 KELVIN_TO_CELSIUS(tz
->temperature
));
812 static int acpi_thermal_temp_open_fs(struct inode
*inode
, struct file
*file
)
814 return single_open(file
, acpi_thermal_temp_seq_show
, PDE(inode
)->data
);
817 static int acpi_thermal_trip_seq_show(struct seq_file
*seq
, void *offset
)
819 struct acpi_thermal
*tz
= seq
->private;
820 struct acpi_device
*device
;
830 if (tz
->trips
.critical
.flags
.valid
)
831 seq_printf(seq
, "critical (S5): %ld C\n",
832 KELVIN_TO_CELSIUS(tz
->trips
.critical
.temperature
));
834 if (tz
->trips
.hot
.flags
.valid
)
835 seq_printf(seq
, "hot (S4): %ld C\n",
836 KELVIN_TO_CELSIUS(tz
->trips
.hot
.temperature
));
838 if (tz
->trips
.passive
.flags
.valid
) {
840 "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
841 KELVIN_TO_CELSIUS(tz
->trips
.passive
.temperature
),
842 tz
->trips
.passive
.tc1
, tz
->trips
.passive
.tc2
,
843 tz
->trips
.passive
.tsp
);
844 for (j
= 0; j
< tz
->trips
.passive
.devices
.count
; j
++) {
845 status
= acpi_bus_get_device(tz
->trips
.passive
.devices
.
846 handles
[j
], &device
);
847 seq_printf(seq
, "%4.4s ", status
? "" :
848 acpi_device_bid(device
));
853 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
854 if (!(tz
->trips
.active
[i
].flags
.valid
))
856 seq_printf(seq
, "active[%d]: %ld C: devices=",
858 KELVIN_TO_CELSIUS(tz
->trips
.active
[i
].temperature
));
859 for (j
= 0; j
< tz
->trips
.active
[i
].devices
.count
; j
++){
860 status
= acpi_bus_get_device(tz
->trips
.active
[i
].
863 seq_printf(seq
, "%4.4s ", status
? "" :
864 acpi_device_bid(device
));
873 static int acpi_thermal_trip_open_fs(struct inode
*inode
, struct file
*file
)
875 return single_open(file
, acpi_thermal_trip_seq_show
, PDE(inode
)->data
);
878 static int acpi_thermal_cooling_seq_show(struct seq_file
*seq
, void *offset
)
880 struct acpi_thermal
*tz
= seq
->private;
886 if (!tz
->flags
.cooling_mode
)
887 seq_puts(seq
, "<setting not supported>\n");
889 seq_puts(seq
, "0 - Active; 1 - Passive\n");
895 static int acpi_thermal_cooling_open_fs(struct inode
*inode
, struct file
*file
)
897 return single_open(file
, acpi_thermal_cooling_seq_show
,
902 acpi_thermal_write_cooling_mode(struct file
*file
,
903 const char __user
* buffer
,
904 size_t count
, loff_t
* ppos
)
906 struct seq_file
*m
= file
->private_data
;
907 struct acpi_thermal
*tz
= m
->private;
909 char mode_string
[12] = { '\0' };
912 if (!tz
|| (count
> sizeof(mode_string
) - 1))
915 if (!tz
->flags
.cooling_mode
)
918 if (copy_from_user(mode_string
, buffer
, count
))
921 mode_string
[count
] = '\0';
923 result
= acpi_thermal_set_cooling_mode(tz
,
924 simple_strtoul(mode_string
, NULL
,
929 acpi_thermal_check(tz
);
934 static int acpi_thermal_polling_seq_show(struct seq_file
*seq
, void *offset
)
936 struct acpi_thermal
*tz
= seq
->private;
942 if (!tz
->polling_frequency
) {
943 seq_puts(seq
, "<polling disabled>\n");
947 seq_printf(seq
, "polling frequency: %lu seconds\n",
948 (tz
->polling_frequency
/ 10));
954 static int acpi_thermal_polling_open_fs(struct inode
*inode
, struct file
*file
)
956 return single_open(file
, acpi_thermal_polling_seq_show
,
961 acpi_thermal_write_polling(struct file
*file
,
962 const char __user
* buffer
,
963 size_t count
, loff_t
* ppos
)
965 struct seq_file
*m
= file
->private_data
;
966 struct acpi_thermal
*tz
= m
->private;
968 char polling_string
[12] = { '\0' };
972 if (!tz
|| (count
> sizeof(polling_string
) - 1))
975 if (copy_from_user(polling_string
, buffer
, count
))
978 polling_string
[count
] = '\0';
980 seconds
= simple_strtoul(polling_string
, NULL
, 0);
982 result
= acpi_thermal_set_polling(tz
, seconds
);
986 acpi_thermal_check(tz
);
991 static int acpi_thermal_add_fs(struct acpi_device
*device
)
993 struct proc_dir_entry
*entry
= NULL
;
996 if (!acpi_device_dir(device
)) {
997 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
999 if (!acpi_device_dir(device
))
1001 acpi_device_dir(device
)->owner
= THIS_MODULE
;
1005 entry
= create_proc_entry(ACPI_THERMAL_FILE_STATE
,
1006 S_IRUGO
, acpi_device_dir(device
));
1010 entry
->proc_fops
= &acpi_thermal_state_fops
;
1011 entry
->data
= acpi_driver_data(device
);
1012 entry
->owner
= THIS_MODULE
;
1015 /* 'temperature' [R] */
1016 entry
= create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE
,
1017 S_IRUGO
, acpi_device_dir(device
));
1021 entry
->proc_fops
= &acpi_thermal_temp_fops
;
1022 entry
->data
= acpi_driver_data(device
);
1023 entry
->owner
= THIS_MODULE
;
1026 /* 'trip_points' [R/W] */
1027 entry
= create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS
,
1028 S_IFREG
| S_IRUGO
| S_IWUSR
,
1029 acpi_device_dir(device
));
1033 entry
->proc_fops
= &acpi_thermal_trip_fops
;
1034 entry
->data
= acpi_driver_data(device
);
1035 entry
->owner
= THIS_MODULE
;
1038 /* 'cooling_mode' [R/W] */
1039 entry
= create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE
,
1040 S_IFREG
| S_IRUGO
| S_IWUSR
,
1041 acpi_device_dir(device
));
1045 entry
->proc_fops
= &acpi_thermal_cooling_fops
;
1046 entry
->data
= acpi_driver_data(device
);
1047 entry
->owner
= THIS_MODULE
;
1050 /* 'polling_frequency' [R/W] */
1051 entry
= create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ
,
1052 S_IFREG
| S_IRUGO
| S_IWUSR
,
1053 acpi_device_dir(device
));
1057 entry
->proc_fops
= &acpi_thermal_polling_fops
;
1058 entry
->data
= acpi_driver_data(device
);
1059 entry
->owner
= THIS_MODULE
;
1065 static int acpi_thermal_remove_fs(struct acpi_device
*device
)
1068 if (acpi_device_dir(device
)) {
1069 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ
,
1070 acpi_device_dir(device
));
1071 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE
,
1072 acpi_device_dir(device
));
1073 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS
,
1074 acpi_device_dir(device
));
1075 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE
,
1076 acpi_device_dir(device
));
1077 remove_proc_entry(ACPI_THERMAL_FILE_STATE
,
1078 acpi_device_dir(device
));
1079 remove_proc_entry(acpi_device_bid(device
), acpi_thermal_dir
);
1080 acpi_device_dir(device
) = NULL
;
1086 /* --------------------------------------------------------------------------
1088 -------------------------------------------------------------------------- */
1090 static void acpi_thermal_notify(acpi_handle handle
, u32 event
, void *data
)
1092 struct acpi_thermal
*tz
= data
;
1093 struct acpi_device
*device
= NULL
;
1099 device
= tz
->device
;
1102 case ACPI_THERMAL_NOTIFY_TEMPERATURE
:
1103 acpi_thermal_check(tz
);
1105 case ACPI_THERMAL_NOTIFY_THRESHOLDS
:
1106 acpi_thermal_get_trip_points(tz
);
1107 acpi_thermal_check(tz
);
1108 acpi_bus_generate_event(device
, event
, 0);
1110 case ACPI_THERMAL_NOTIFY_DEVICES
:
1111 if (tz
->flags
.devices
)
1112 acpi_thermal_get_devices(tz
);
1113 acpi_bus_generate_event(device
, event
, 0);
1116 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1117 "Unsupported event [0x%x]\n", event
));
1124 static int acpi_thermal_get_info(struct acpi_thermal
*tz
)
1132 /* Get temperature [_TMP] (required) */
1133 result
= acpi_thermal_get_temperature(tz
);
1137 /* Get trip points [_CRT, _PSV, etc.] (required) */
1138 result
= acpi_thermal_get_trip_points(tz
);
1142 /* Set the cooling mode [_SCP] to active cooling (default) */
1143 result
= acpi_thermal_set_cooling_mode(tz
, ACPI_THERMAL_MODE_ACTIVE
);
1145 tz
->flags
.cooling_mode
= 1;
1147 /* Get default polling frequency [_TZP] (optional) */
1149 tz
->polling_frequency
= tzp
;
1151 acpi_thermal_get_polling_frequency(tz
);
1153 /* Get devices in this thermal zone [_TZD] (optional) */
1154 result
= acpi_thermal_get_devices(tz
);
1156 tz
->flags
.devices
= 1;
1161 static int acpi_thermal_add(struct acpi_device
*device
)
1164 acpi_status status
= AE_OK
;
1165 struct acpi_thermal
*tz
= NULL
;
1171 tz
= kzalloc(sizeof(struct acpi_thermal
), GFP_KERNEL
);
1175 tz
->device
= device
;
1176 strcpy(tz
->name
, device
->pnp
.bus_id
);
1177 strcpy(acpi_device_name(device
), ACPI_THERMAL_DEVICE_NAME
);
1178 strcpy(acpi_device_class(device
), ACPI_THERMAL_CLASS
);
1179 acpi_driver_data(device
) = tz
;
1181 result
= acpi_thermal_get_info(tz
);
1185 result
= acpi_thermal_add_fs(device
);
1189 init_timer(&tz
->timer
);
1191 acpi_thermal_check(tz
);
1193 status
= acpi_install_notify_handler(device
->handle
,
1195 acpi_thermal_notify
, tz
);
1196 if (ACPI_FAILURE(status
)) {
1201 printk(KERN_INFO PREFIX
"%s [%s] (%ld C)\n",
1202 acpi_device_name(device
), acpi_device_bid(device
),
1203 KELVIN_TO_CELSIUS(tz
->temperature
));
1207 acpi_thermal_remove_fs(device
);
1214 static int acpi_thermal_remove(struct acpi_device
*device
, int type
)
1216 acpi_status status
= AE_OK
;
1217 struct acpi_thermal
*tz
= NULL
;
1220 if (!device
|| !acpi_driver_data(device
))
1223 tz
= acpi_driver_data(device
);
1225 /* avoid timer adding new defer task */
1227 /* wait for running timer (on other CPUs) finish */
1228 del_timer_sync(&(tz
->timer
));
1229 /* synchronize deferred task */
1230 acpi_os_wait_events_complete(NULL
);
1231 /* deferred task may reinsert timer */
1232 del_timer_sync(&(tz
->timer
));
1234 status
= acpi_remove_notify_handler(device
->handle
,
1236 acpi_thermal_notify
);
1238 /* Terminate policy */
1239 if (tz
->trips
.passive
.flags
.valid
&& tz
->trips
.passive
.flags
.enabled
) {
1240 tz
->trips
.passive
.flags
.enabled
= 0;
1241 acpi_thermal_passive(tz
);
1243 if (tz
->trips
.active
[0].flags
.valid
1244 && tz
->trips
.active
[0].flags
.enabled
) {
1245 tz
->trips
.active
[0].flags
.enabled
= 0;
1246 acpi_thermal_active(tz
);
1249 acpi_thermal_remove_fs(device
);
1255 static int acpi_thermal_resume(struct acpi_device
*device
)
1257 struct acpi_thermal
*tz
= NULL
;
1258 int i
, j
, power_state
, result
;
1261 if (!device
|| !acpi_driver_data(device
))
1264 tz
= acpi_driver_data(device
);
1266 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
1267 if (!(&tz
->trips
.active
[i
]))
1269 if (!tz
->trips
.active
[i
].flags
.valid
)
1271 tz
->trips
.active
[i
].flags
.enabled
= 1;
1272 for (j
= 0; j
< tz
->trips
.active
[i
].devices
.count
; j
++) {
1273 result
= acpi_bus_get_power(tz
->trips
.active
[i
].devices
.
1274 handles
[j
], &power_state
);
1275 if (result
|| (power_state
!= ACPI_STATE_D0
)) {
1276 tz
->trips
.active
[i
].flags
.enabled
= 0;
1280 tz
->state
.active
|= tz
->trips
.active
[i
].flags
.enabled
;
1283 acpi_thermal_check(tz
);
1288 static int __init
acpi_thermal_init(void)
1293 printk(KERN_NOTICE
"ACPI: thermal control disabled\n");
1296 acpi_thermal_dir
= proc_mkdir(ACPI_THERMAL_CLASS
, acpi_root_dir
);
1297 if (!acpi_thermal_dir
)
1299 acpi_thermal_dir
->owner
= THIS_MODULE
;
1301 result
= acpi_bus_register_driver(&acpi_thermal_driver
);
1303 remove_proc_entry(ACPI_THERMAL_CLASS
, acpi_root_dir
);
1310 static void __exit
acpi_thermal_exit(void)
1313 acpi_bus_unregister_driver(&acpi_thermal_driver
);
1315 remove_proc_entry(ACPI_THERMAL_CLASS
, acpi_root_dir
);
1320 module_init(acpi_thermal_init
);
1321 module_exit(acpi_thermal_exit
);