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
);
490 acpi_bus_generate_netlink_event(tz
->device
->pnp
.device_class
,
491 tz
->device
->dev
.bus_id
,
492 ACPI_THERMAL_NOTIFY_CRITICAL
,
493 tz
->trips
.critical
.flags
.enabled
);
495 orderly_poweroff(true);
500 static int acpi_thermal_hot(struct acpi_thermal
*tz
)
502 if (!tz
|| !tz
->trips
.hot
.flags
.valid
|| nocrt
)
505 if (tz
->temperature
>= tz
->trips
.hot
.temperature
) {
506 printk(KERN_WARNING PREFIX
"Hot trip point\n");
507 tz
->trips
.hot
.flags
.enabled
= 1;
508 } else if (tz
->trips
.hot
.flags
.enabled
)
509 tz
->trips
.hot
.flags
.enabled
= 0;
511 acpi_bus_generate_event(tz
->device
, ACPI_THERMAL_NOTIFY_HOT
,
512 tz
->trips
.hot
.flags
.enabled
);
513 acpi_bus_generate_netlink_event(tz
->device
->pnp
.device_class
,
514 tz
->device
->dev
.bus_id
,
515 ACPI_THERMAL_NOTIFY_HOT
,
516 tz
->trips
.hot
.flags
.enabled
);
518 /* TBD: Call user-mode "sleep(S4)" function */
523 static void acpi_thermal_passive(struct acpi_thermal
*tz
)
526 struct acpi_thermal_passive
*passive
= NULL
;
531 if (!tz
|| !tz
->trips
.passive
.flags
.valid
)
534 passive
= &(tz
->trips
.passive
);
539 * Calculate the thermal trend (using the passive cooling equation)
540 * and modify the performance limit for all passive cooling devices
541 * accordingly. Note that we assume symmetry.
543 if (tz
->temperature
>= passive
->temperature
) {
545 (passive
->tc1
* (tz
->temperature
- tz
->last_temperature
)) +
546 (passive
->tc2
* (tz
->temperature
- passive
->temperature
));
547 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
548 "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
549 trend
, passive
->tc1
, tz
->temperature
,
550 tz
->last_temperature
, passive
->tc2
,
551 tz
->temperature
, passive
->temperature
));
552 passive
->flags
.enabled
= 1;
555 for (i
= 0; i
< passive
->devices
.count
; i
++)
556 acpi_processor_set_thermal_limit(passive
->
559 ACPI_PROCESSOR_LIMIT_INCREMENT
);
561 else if (trend
< 0) {
562 for (i
= 0; i
< passive
->devices
.count
; i
++)
564 * assume that we are on highest
565 * freq/lowest thrott and can leave
566 * passive mode, even in error case
568 if (!acpi_processor_set_thermal_limit
569 (passive
->devices
.handles
[i
],
570 ACPI_PROCESSOR_LIMIT_DECREMENT
))
573 * Leave cooling mode, even if the temp might
574 * higher than trip point This is because some
575 * machines might have long thermal polling
576 * frequencies (tsp) defined. We will fall back
577 * into passive mode in next cycle (probably quicker)
580 passive
->flags
.enabled
= 0;
581 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
582 "Disabling passive cooling, still above threshold,"
583 " but we are cooling down\n"));
592 * Implement passive cooling hysteresis to slowly increase performance
593 * and avoid thrashing around the passive trip point. Note that we
596 if (!passive
->flags
.enabled
)
598 for (i
= 0; i
< passive
->devices
.count
; i
++)
599 if (!acpi_processor_set_thermal_limit
600 (passive
->devices
.handles
[i
],
601 ACPI_PROCESSOR_LIMIT_DECREMENT
))
604 passive
->flags
.enabled
= 0;
605 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
606 "Disabling passive cooling (zone is cool)\n"));
610 static void acpi_thermal_active(struct acpi_thermal
*tz
)
613 struct acpi_thermal_active
*active
= NULL
;
616 unsigned long maxtemp
= 0;
622 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
623 active
= &(tz
->trips
.active
[i
]);
624 if (!active
|| !active
->flags
.valid
)
626 if (tz
->temperature
>= active
->temperature
) {
630 * If not already enabled, turn ON all cooling devices
631 * associated with this active threshold.
633 if (active
->temperature
> maxtemp
)
634 tz
->state
.active_index
= i
;
635 maxtemp
= active
->temperature
;
636 if (active
->flags
.enabled
)
638 for (j
= 0; j
< active
->devices
.count
; j
++) {
640 acpi_bus_set_power(active
->devices
.
644 printk(KERN_WARNING PREFIX
645 "Unable to turn cooling device [%p] 'on'\n",
650 active
->flags
.enabled
= 1;
651 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
652 "Cooling device [%p] now 'on'\n",
653 active
->devices
.handles
[j
]));
657 if (!active
->flags
.enabled
)
662 * Turn OFF all cooling devices associated with this
665 for (j
= 0; j
< active
->devices
.count
; j
++) {
666 result
= acpi_bus_set_power(active
->devices
.handles
[j
],
669 printk(KERN_WARNING PREFIX
670 "Unable to turn cooling device [%p] 'off'\n",
671 active
->devices
.handles
[j
]);
674 active
->flags
.enabled
= 0;
675 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
676 "Cooling device [%p] now 'off'\n",
677 active
->devices
.handles
[j
]));
682 static void acpi_thermal_check(void *context
);
684 static void acpi_thermal_run(unsigned long data
)
686 struct acpi_thermal
*tz
= (struct acpi_thermal
*)data
;
688 acpi_os_execute(OSL_GPE_HANDLER
, acpi_thermal_check
, (void *)data
);
691 static void acpi_thermal_check(void *data
)
694 struct acpi_thermal
*tz
= data
;
695 unsigned long sleep_time
= 0;
697 struct acpi_thermal_state state
;
701 printk(KERN_ERR PREFIX
"Invalid (NULL) context\n");
707 result
= acpi_thermal_get_temperature(tz
);
711 memset(&tz
->state
, 0, sizeof(tz
->state
));
716 * Compare the current temperature to the trip point values to see
717 * if we've entered one of the thermal policy states. Note that
718 * this function determines when a state is entered, but the
719 * individual policy decides when it is exited (e.g. hysteresis).
721 if (tz
->trips
.critical
.flags
.valid
)
723 (tz
->temperature
>= tz
->trips
.critical
.temperature
);
724 if (tz
->trips
.hot
.flags
.valid
)
725 state
.hot
|= (tz
->temperature
>= tz
->trips
.hot
.temperature
);
726 if (tz
->trips
.passive
.flags
.valid
)
728 (tz
->temperature
>= tz
->trips
.passive
.temperature
);
729 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++)
730 if (tz
->trips
.active
[i
].flags
.valid
)
733 tz
->trips
.active
[i
].temperature
);
738 * Separated from the above check to allow individual policy to
739 * determine when to exit a given state.
742 acpi_thermal_critical(tz
);
744 acpi_thermal_hot(tz
);
746 acpi_thermal_passive(tz
);
748 acpi_thermal_active(tz
);
753 * Again, separated from the above two to allow independent policy
756 tz
->state
.critical
= tz
->trips
.critical
.flags
.enabled
;
757 tz
->state
.hot
= tz
->trips
.hot
.flags
.enabled
;
758 tz
->state
.passive
= tz
->trips
.passive
.flags
.enabled
;
759 tz
->state
.active
= 0;
760 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++)
761 tz
->state
.active
|= tz
->trips
.active
[i
].flags
.enabled
;
764 * Calculate Sleep Time
765 * --------------------
766 * If we're in the passive state, use _TSP's value. Otherwise
767 * use the default polling frequency (e.g. _TZP). If no polling
768 * frequency is specified then we'll wait forever (at least until
769 * a thermal event occurs). Note that _TSP and _TZD values are
770 * given in 1/10th seconds (we must covert to milliseconds).
772 if (tz
->state
.passive
)
773 sleep_time
= tz
->trips
.passive
.tsp
* 100;
774 else if (tz
->polling_frequency
> 0)
775 sleep_time
= tz
->polling_frequency
* 100;
777 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "%s: temperature[%lu] sleep[%lu]\n",
778 tz
->name
, tz
->temperature
, sleep_time
));
785 if (timer_pending(&(tz
->timer
)))
786 del_timer(&(tz
->timer
));
788 if (timer_pending(&(tz
->timer
)))
789 mod_timer(&(tz
->timer
),
790 jiffies
+ (HZ
* sleep_time
) / 1000);
792 tz
->timer
.data
= (unsigned long)tz
;
793 tz
->timer
.function
= acpi_thermal_run
;
794 tz
->timer
.expires
= jiffies
+ (HZ
* sleep_time
) / 1000;
795 add_timer(&(tz
->timer
));
802 /* --------------------------------------------------------------------------
804 -------------------------------------------------------------------------- */
806 static struct proc_dir_entry
*acpi_thermal_dir
;
808 static int acpi_thermal_state_seq_show(struct seq_file
*seq
, void *offset
)
810 struct acpi_thermal
*tz
= seq
->private;
816 seq_puts(seq
, "state: ");
818 if (!tz
->state
.critical
&& !tz
->state
.hot
&& !tz
->state
.passive
819 && !tz
->state
.active
)
820 seq_puts(seq
, "ok\n");
822 if (tz
->state
.critical
)
823 seq_puts(seq
, "critical ");
825 seq_puts(seq
, "hot ");
826 if (tz
->state
.passive
)
827 seq_puts(seq
, "passive ");
828 if (tz
->state
.active
)
829 seq_printf(seq
, "active[%d]", tz
->state
.active_index
);
837 static int acpi_thermal_state_open_fs(struct inode
*inode
, struct file
*file
)
839 return single_open(file
, acpi_thermal_state_seq_show
, PDE(inode
)->data
);
842 static int acpi_thermal_temp_seq_show(struct seq_file
*seq
, void *offset
)
845 struct acpi_thermal
*tz
= seq
->private;
851 result
= acpi_thermal_get_temperature(tz
);
855 seq_printf(seq
, "temperature: %ld C\n",
856 KELVIN_TO_CELSIUS(tz
->temperature
));
862 static int acpi_thermal_temp_open_fs(struct inode
*inode
, struct file
*file
)
864 return single_open(file
, acpi_thermal_temp_seq_show
, PDE(inode
)->data
);
867 static int acpi_thermal_trip_seq_show(struct seq_file
*seq
, void *offset
)
869 struct acpi_thermal
*tz
= seq
->private;
870 struct acpi_device
*device
;
880 if (tz
->trips
.critical
.flags
.valid
)
881 seq_printf(seq
, "critical (S5): %ld C%s",
882 KELVIN_TO_CELSIUS(tz
->trips
.critical
.temperature
),
883 nocrt
? " <disabled>\n" : "\n");
885 if (tz
->trips
.hot
.flags
.valid
)
886 seq_printf(seq
, "hot (S4): %ld C%s",
887 KELVIN_TO_CELSIUS(tz
->trips
.hot
.temperature
),
888 nocrt
? " <disabled>\n" : "\n");
890 if (tz
->trips
.passive
.flags
.valid
) {
892 "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
893 KELVIN_TO_CELSIUS(tz
->trips
.passive
.temperature
),
894 tz
->trips
.passive
.tc1
, tz
->trips
.passive
.tc2
,
895 tz
->trips
.passive
.tsp
);
896 for (j
= 0; j
< tz
->trips
.passive
.devices
.count
; j
++) {
897 status
= acpi_bus_get_device(tz
->trips
.passive
.devices
.
898 handles
[j
], &device
);
899 seq_printf(seq
, "%4.4s ", status
? "" :
900 acpi_device_bid(device
));
905 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
906 if (!(tz
->trips
.active
[i
].flags
.valid
))
908 seq_printf(seq
, "active[%d]: %ld C: devices=",
910 KELVIN_TO_CELSIUS(tz
->trips
.active
[i
].temperature
));
911 for (j
= 0; j
< tz
->trips
.active
[i
].devices
.count
; j
++){
912 status
= acpi_bus_get_device(tz
->trips
.active
[i
].
915 seq_printf(seq
, "%4.4s ", status
? "" :
916 acpi_device_bid(device
));
925 static int acpi_thermal_trip_open_fs(struct inode
*inode
, struct file
*file
)
927 return single_open(file
, acpi_thermal_trip_seq_show
, PDE(inode
)->data
);
930 static int acpi_thermal_cooling_seq_show(struct seq_file
*seq
, void *offset
)
932 struct acpi_thermal
*tz
= seq
->private;
938 if (!tz
->flags
.cooling_mode
)
939 seq_puts(seq
, "<setting not supported>\n");
941 seq_puts(seq
, "0 - Active; 1 - Passive\n");
947 static int acpi_thermal_cooling_open_fs(struct inode
*inode
, struct file
*file
)
949 return single_open(file
, acpi_thermal_cooling_seq_show
,
954 acpi_thermal_write_cooling_mode(struct file
*file
,
955 const char __user
* buffer
,
956 size_t count
, loff_t
* ppos
)
958 struct seq_file
*m
= file
->private_data
;
959 struct acpi_thermal
*tz
= m
->private;
961 char mode_string
[12] = { '\0' };
964 if (!tz
|| (count
> sizeof(mode_string
) - 1))
967 if (!tz
->flags
.cooling_mode
)
970 if (copy_from_user(mode_string
, buffer
, count
))
973 mode_string
[count
] = '\0';
975 result
= acpi_thermal_set_cooling_mode(tz
,
976 simple_strtoul(mode_string
, NULL
,
981 acpi_thermal_check(tz
);
986 static int acpi_thermal_polling_seq_show(struct seq_file
*seq
, void *offset
)
988 struct acpi_thermal
*tz
= seq
->private;
994 if (!tz
->polling_frequency
) {
995 seq_puts(seq
, "<polling disabled>\n");
999 seq_printf(seq
, "polling frequency: %lu seconds\n",
1000 (tz
->polling_frequency
/ 10));
1006 static int acpi_thermal_polling_open_fs(struct inode
*inode
, struct file
*file
)
1008 return single_open(file
, acpi_thermal_polling_seq_show
,
1013 acpi_thermal_write_polling(struct file
*file
,
1014 const char __user
* buffer
,
1015 size_t count
, loff_t
* ppos
)
1017 struct seq_file
*m
= file
->private_data
;
1018 struct acpi_thermal
*tz
= m
->private;
1020 char polling_string
[12] = { '\0' };
1024 if (!tz
|| (count
> sizeof(polling_string
) - 1))
1027 if (copy_from_user(polling_string
, buffer
, count
))
1030 polling_string
[count
] = '\0';
1032 seconds
= simple_strtoul(polling_string
, NULL
, 0);
1034 result
= acpi_thermal_set_polling(tz
, seconds
);
1038 acpi_thermal_check(tz
);
1043 static int acpi_thermal_add_fs(struct acpi_device
*device
)
1045 struct proc_dir_entry
*entry
= NULL
;
1048 if (!acpi_device_dir(device
)) {
1049 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
1051 if (!acpi_device_dir(device
))
1053 acpi_device_dir(device
)->owner
= THIS_MODULE
;
1057 entry
= create_proc_entry(ACPI_THERMAL_FILE_STATE
,
1058 S_IRUGO
, acpi_device_dir(device
));
1062 entry
->proc_fops
= &acpi_thermal_state_fops
;
1063 entry
->data
= acpi_driver_data(device
);
1064 entry
->owner
= THIS_MODULE
;
1067 /* 'temperature' [R] */
1068 entry
= create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE
,
1069 S_IRUGO
, acpi_device_dir(device
));
1073 entry
->proc_fops
= &acpi_thermal_temp_fops
;
1074 entry
->data
= acpi_driver_data(device
);
1075 entry
->owner
= THIS_MODULE
;
1078 /* 'trip_points' [R/W] */
1079 entry
= create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS
,
1080 S_IFREG
| S_IRUGO
| S_IWUSR
,
1081 acpi_device_dir(device
));
1085 entry
->proc_fops
= &acpi_thermal_trip_fops
;
1086 entry
->data
= acpi_driver_data(device
);
1087 entry
->owner
= THIS_MODULE
;
1090 /* 'cooling_mode' [R/W] */
1091 entry
= create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE
,
1092 S_IFREG
| S_IRUGO
| S_IWUSR
,
1093 acpi_device_dir(device
));
1097 entry
->proc_fops
= &acpi_thermal_cooling_fops
;
1098 entry
->data
= acpi_driver_data(device
);
1099 entry
->owner
= THIS_MODULE
;
1102 /* 'polling_frequency' [R/W] */
1103 entry
= create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ
,
1104 S_IFREG
| S_IRUGO
| S_IWUSR
,
1105 acpi_device_dir(device
));
1109 entry
->proc_fops
= &acpi_thermal_polling_fops
;
1110 entry
->data
= acpi_driver_data(device
);
1111 entry
->owner
= THIS_MODULE
;
1117 static int acpi_thermal_remove_fs(struct acpi_device
*device
)
1120 if (acpi_device_dir(device
)) {
1121 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ
,
1122 acpi_device_dir(device
));
1123 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE
,
1124 acpi_device_dir(device
));
1125 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS
,
1126 acpi_device_dir(device
));
1127 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE
,
1128 acpi_device_dir(device
));
1129 remove_proc_entry(ACPI_THERMAL_FILE_STATE
,
1130 acpi_device_dir(device
));
1131 remove_proc_entry(acpi_device_bid(device
), acpi_thermal_dir
);
1132 acpi_device_dir(device
) = NULL
;
1138 /* --------------------------------------------------------------------------
1140 -------------------------------------------------------------------------- */
1142 static void acpi_thermal_notify(acpi_handle handle
, u32 event
, void *data
)
1144 struct acpi_thermal
*tz
= data
;
1145 struct acpi_device
*device
= NULL
;
1151 device
= tz
->device
;
1154 case ACPI_THERMAL_NOTIFY_TEMPERATURE
:
1155 acpi_thermal_check(tz
);
1157 case ACPI_THERMAL_NOTIFY_THRESHOLDS
:
1158 acpi_thermal_get_trip_points(tz
);
1159 acpi_thermal_check(tz
);
1160 acpi_bus_generate_event(device
, event
, 0);
1161 acpi_bus_generate_netlink_event(device
->pnp
.device_class
,
1162 device
->dev
.bus_id
, event
, 0);
1164 case ACPI_THERMAL_NOTIFY_DEVICES
:
1165 if (tz
->flags
.devices
)
1166 acpi_thermal_get_devices(tz
);
1167 acpi_bus_generate_event(device
, event
, 0);
1168 acpi_bus_generate_netlink_event(device
->pnp
.device_class
,
1169 device
->dev
.bus_id
, event
, 0);
1172 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1173 "Unsupported event [0x%x]\n", event
));
1180 static int acpi_thermal_get_info(struct acpi_thermal
*tz
)
1188 /* Get temperature [_TMP] (required) */
1189 result
= acpi_thermal_get_temperature(tz
);
1193 /* Get trip points [_CRT, _PSV, etc.] (required) */
1194 result
= acpi_thermal_get_trip_points(tz
);
1198 /* Set the cooling mode [_SCP] to active cooling (default) */
1199 result
= acpi_thermal_set_cooling_mode(tz
, ACPI_THERMAL_MODE_ACTIVE
);
1201 tz
->flags
.cooling_mode
= 1;
1203 /* Get default polling frequency [_TZP] (optional) */
1205 tz
->polling_frequency
= tzp
;
1207 acpi_thermal_get_polling_frequency(tz
);
1209 /* Get devices in this thermal zone [_TZD] (optional) */
1210 result
= acpi_thermal_get_devices(tz
);
1212 tz
->flags
.devices
= 1;
1217 static int acpi_thermal_add(struct acpi_device
*device
)
1220 acpi_status status
= AE_OK
;
1221 struct acpi_thermal
*tz
= NULL
;
1227 tz
= kzalloc(sizeof(struct acpi_thermal
), GFP_KERNEL
);
1231 tz
->device
= device
;
1232 strcpy(tz
->name
, device
->pnp
.bus_id
);
1233 strcpy(acpi_device_name(device
), ACPI_THERMAL_DEVICE_NAME
);
1234 strcpy(acpi_device_class(device
), ACPI_THERMAL_CLASS
);
1235 acpi_driver_data(device
) = tz
;
1237 result
= acpi_thermal_get_info(tz
);
1241 result
= acpi_thermal_add_fs(device
);
1245 init_timer(&tz
->timer
);
1247 acpi_thermal_check(tz
);
1249 status
= acpi_install_notify_handler(device
->handle
,
1251 acpi_thermal_notify
, tz
);
1252 if (ACPI_FAILURE(status
)) {
1257 printk(KERN_INFO PREFIX
"%s [%s] (%ld C)\n",
1258 acpi_device_name(device
), acpi_device_bid(device
),
1259 KELVIN_TO_CELSIUS(tz
->temperature
));
1263 acpi_thermal_remove_fs(device
);
1270 static int acpi_thermal_remove(struct acpi_device
*device
, int type
)
1272 acpi_status status
= AE_OK
;
1273 struct acpi_thermal
*tz
= NULL
;
1276 if (!device
|| !acpi_driver_data(device
))
1279 tz
= acpi_driver_data(device
);
1281 /* avoid timer adding new defer task */
1283 /* wait for running timer (on other CPUs) finish */
1284 del_timer_sync(&(tz
->timer
));
1285 /* synchronize deferred task */
1286 acpi_os_wait_events_complete(NULL
);
1287 /* deferred task may reinsert timer */
1288 del_timer_sync(&(tz
->timer
));
1290 status
= acpi_remove_notify_handler(device
->handle
,
1292 acpi_thermal_notify
);
1294 /* Terminate policy */
1295 if (tz
->trips
.passive
.flags
.valid
&& tz
->trips
.passive
.flags
.enabled
) {
1296 tz
->trips
.passive
.flags
.enabled
= 0;
1297 acpi_thermal_passive(tz
);
1299 if (tz
->trips
.active
[0].flags
.valid
1300 && tz
->trips
.active
[0].flags
.enabled
) {
1301 tz
->trips
.active
[0].flags
.enabled
= 0;
1302 acpi_thermal_active(tz
);
1305 acpi_thermal_remove_fs(device
);
1311 static int acpi_thermal_resume(struct acpi_device
*device
)
1313 struct acpi_thermal
*tz
= NULL
;
1314 int i
, j
, power_state
, result
;
1317 if (!device
|| !acpi_driver_data(device
))
1320 tz
= acpi_driver_data(device
);
1322 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
1323 if (!(&tz
->trips
.active
[i
]))
1325 if (!tz
->trips
.active
[i
].flags
.valid
)
1327 tz
->trips
.active
[i
].flags
.enabled
= 1;
1328 for (j
= 0; j
< tz
->trips
.active
[i
].devices
.count
; j
++) {
1329 result
= acpi_bus_get_power(tz
->trips
.active
[i
].devices
.
1330 handles
[j
], &power_state
);
1331 if (result
|| (power_state
!= ACPI_STATE_D0
)) {
1332 tz
->trips
.active
[i
].flags
.enabled
= 0;
1336 tz
->state
.active
|= tz
->trips
.active
[i
].flags
.enabled
;
1339 acpi_thermal_check(tz
);
1345 static int thermal_act(struct dmi_system_id
*d
) {
1348 printk(KERN_NOTICE
"ACPI: %s detected: "
1349 "disabling all active thermal trip points\n", d
->ident
);
1354 static int thermal_tzp(struct dmi_system_id
*d
) {
1357 printk(KERN_NOTICE
"ACPI: %s detected: "
1358 "enabling thermal zone polling\n", d
->ident
);
1359 tzp
= 300; /* 300 dS = 30 Seconds */
1363 static int thermal_psv(struct dmi_system_id
*d
) {
1366 printk(KERN_NOTICE
"ACPI: %s detected: "
1367 "disabling all passive thermal trip points\n", d
->ident
);
1373 static struct dmi_system_id thermal_dmi_table
[] __initdata
= {
1375 * Award BIOS on this AOpen makes thermal control almost worthless.
1376 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1379 .callback
= thermal_act
,
1380 .ident
= "AOpen i915GMm-HFS",
1382 DMI_MATCH(DMI_BOARD_VENDOR
, "AOpen"),
1383 DMI_MATCH(DMI_BOARD_NAME
, "i915GMm-HFS"),
1387 .callback
= thermal_psv
,
1388 .ident
= "AOpen i915GMm-HFS",
1390 DMI_MATCH(DMI_BOARD_VENDOR
, "AOpen"),
1391 DMI_MATCH(DMI_BOARD_NAME
, "i915GMm-HFS"),
1395 .callback
= thermal_tzp
,
1396 .ident
= "AOpen i915GMm-HFS",
1398 DMI_MATCH(DMI_BOARD_VENDOR
, "AOpen"),
1399 DMI_MATCH(DMI_BOARD_NAME
, "i915GMm-HFS"),
1404 #endif /* CONFIG_DMI */
1406 static int __init
acpi_thermal_init(void)
1410 dmi_check_system(thermal_dmi_table
);
1413 printk(KERN_NOTICE
"ACPI: thermal control disabled\n");
1416 acpi_thermal_dir
= proc_mkdir(ACPI_THERMAL_CLASS
, acpi_root_dir
);
1417 if (!acpi_thermal_dir
)
1419 acpi_thermal_dir
->owner
= THIS_MODULE
;
1421 result
= acpi_bus_register_driver(&acpi_thermal_driver
);
1423 remove_proc_entry(ACPI_THERMAL_CLASS
, acpi_root_dir
);
1430 static void __exit
acpi_thermal_exit(void)
1433 acpi_bus_unregister_driver(&acpi_thermal_driver
);
1435 remove_proc_entry(ACPI_THERMAL_CLASS
, acpi_root_dir
);
1440 module_init(acpi_thermal_init
);
1441 module_exit(acpi_thermal_exit
);