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/jiffies.h>
41 #include <linux/kmod.h>
42 #include <linux/seq_file.h>
43 #include <linux/reboot.h>
44 #include <linux/device.h>
45 #include <asm/uaccess.h>
46 #include <linux/thermal.h>
47 #include <acpi/acpi_bus.h>
48 #include <acpi/acpi_drivers.h>
50 #define PREFIX "ACPI: "
52 #define ACPI_THERMAL_CLASS "thermal_zone"
53 #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
54 #define ACPI_THERMAL_FILE_STATE "state"
55 #define ACPI_THERMAL_FILE_TEMPERATURE "temperature"
56 #define ACPI_THERMAL_FILE_TRIP_POINTS "trip_points"
57 #define ACPI_THERMAL_FILE_COOLING_MODE "cooling_mode"
58 #define ACPI_THERMAL_FILE_POLLING_FREQ "polling_frequency"
59 #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80
60 #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81
61 #define ACPI_THERMAL_NOTIFY_DEVICES 0x82
62 #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0
63 #define ACPI_THERMAL_NOTIFY_HOT 0xF1
64 #define ACPI_THERMAL_MODE_ACTIVE 0x00
66 #define ACPI_THERMAL_MAX_ACTIVE 10
67 #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
69 #define _COMPONENT ACPI_THERMAL_COMPONENT
70 ACPI_MODULE_NAME("thermal");
72 MODULE_AUTHOR("Paul Diefenbaugh");
73 MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
74 MODULE_LICENSE("GPL");
77 module_param(act
, int, 0644);
78 MODULE_PARM_DESC(act
, "Disable or override all lowest active trip points.");
81 module_param(crt
, int, 0644);
82 MODULE_PARM_DESC(crt
, "Disable or lower all critical trip points.");
85 module_param(tzp
, int, 0444);
86 MODULE_PARM_DESC(tzp
, "Thermal zone polling frequency, in 1/10 seconds.");
89 module_param(nocrt
, int, 0);
90 MODULE_PARM_DESC(nocrt
, "Set to take no action upon ACPI thermal zone critical trips points.");
93 module_param(off
, int, 0);
94 MODULE_PARM_DESC(off
, "Set to disable ACPI thermal support.");
97 module_param(psv
, int, 0644);
98 MODULE_PARM_DESC(psv
, "Disable or override all passive trip points.");
100 static int acpi_thermal_add(struct acpi_device
*device
);
101 static int acpi_thermal_remove(struct acpi_device
*device
, int type
);
102 static int acpi_thermal_resume(struct acpi_device
*device
);
103 static void acpi_thermal_notify(struct acpi_device
*device
, u32 event
);
104 static int acpi_thermal_state_open_fs(struct inode
*inode
, struct file
*file
);
105 static int acpi_thermal_temp_open_fs(struct inode
*inode
, struct file
*file
);
106 static int acpi_thermal_trip_open_fs(struct inode
*inode
, struct file
*file
);
107 static int acpi_thermal_cooling_open_fs(struct inode
*inode
, struct file
*file
);
108 static ssize_t
acpi_thermal_write_cooling_mode(struct file
*,
109 const char __user
*, size_t,
111 static int acpi_thermal_polling_open_fs(struct inode
*inode
, struct file
*file
);
112 static ssize_t
acpi_thermal_write_polling(struct file
*, const char __user
*,
115 static const struct acpi_device_id thermal_device_ids
[] = {
116 {ACPI_THERMAL_HID
, 0},
119 MODULE_DEVICE_TABLE(acpi
, thermal_device_ids
);
121 static struct acpi_driver acpi_thermal_driver
= {
123 .class = ACPI_THERMAL_CLASS
,
124 .ids
= thermal_device_ids
,
126 .add
= acpi_thermal_add
,
127 .remove
= acpi_thermal_remove
,
128 .resume
= acpi_thermal_resume
,
129 .notify
= acpi_thermal_notify
,
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 thermal_zone_device
*thermal_zone
;
203 static const struct file_operations acpi_thermal_state_fops
= {
204 .owner
= THIS_MODULE
,
205 .open
= acpi_thermal_state_open_fs
,
208 .release
= single_release
,
211 static const struct file_operations acpi_thermal_temp_fops
= {
212 .owner
= THIS_MODULE
,
213 .open
= acpi_thermal_temp_open_fs
,
216 .release
= single_release
,
219 static const struct file_operations acpi_thermal_trip_fops
= {
220 .owner
= THIS_MODULE
,
221 .open
= acpi_thermal_trip_open_fs
,
224 .release
= single_release
,
227 static const struct file_operations acpi_thermal_cooling_fops
= {
228 .owner
= THIS_MODULE
,
229 .open
= acpi_thermal_cooling_open_fs
,
231 .write
= acpi_thermal_write_cooling_mode
,
233 .release
= single_release
,
236 static const struct file_operations acpi_thermal_polling_fops
= {
237 .owner
= THIS_MODULE
,
238 .open
= acpi_thermal_polling_open_fs
,
240 .write
= acpi_thermal_write_polling
,
242 .release
= single_release
,
245 /* --------------------------------------------------------------------------
246 Thermal Zone Management
247 -------------------------------------------------------------------------- */
249 static int acpi_thermal_get_temperature(struct acpi_thermal
*tz
)
251 acpi_status status
= AE_OK
;
252 unsigned long long tmp
;
257 tz
->last_temperature
= tz
->temperature
;
259 status
= acpi_evaluate_integer(tz
->device
->handle
, "_TMP", NULL
, &tmp
);
260 if (ACPI_FAILURE(status
))
263 tz
->temperature
= tmp
;
264 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Temperature is %lu dK\n",
270 static int acpi_thermal_get_polling_frequency(struct acpi_thermal
*tz
)
272 acpi_status status
= AE_OK
;
273 unsigned long long tmp
;
278 status
= acpi_evaluate_integer(tz
->device
->handle
, "_TZP", NULL
, &tmp
);
279 if (ACPI_FAILURE(status
))
282 tz
->polling_frequency
= tmp
;
283 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Polling frequency is %lu dS\n",
284 tz
->polling_frequency
));
289 static int acpi_thermal_set_polling(struct acpi_thermal
*tz
, int seconds
)
295 tz
->polling_frequency
= seconds
* 10; /* Convert value to deci-seconds */
297 tz
->thermal_zone
->polling_delay
= seconds
* 1000;
300 thermal_zone_device_update(tz
->thermal_zone
);
302 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
303 "Polling frequency set to %lu seconds\n",
304 tz
->polling_frequency
/10));
309 static int acpi_thermal_set_cooling_mode(struct acpi_thermal
*tz
, int mode
)
311 acpi_status status
= AE_OK
;
312 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
313 struct acpi_object_list arg_list
= { 1, &arg0
};
314 acpi_handle handle
= NULL
;
320 status
= acpi_get_handle(tz
->device
->handle
, "_SCP", &handle
);
321 if (ACPI_FAILURE(status
)) {
322 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "_SCP not present\n"));
326 arg0
.integer
.value
= mode
;
328 status
= acpi_evaluate_object(handle
, NULL
, &arg_list
, NULL
);
329 if (ACPI_FAILURE(status
))
335 #define ACPI_TRIPS_CRITICAL 0x01
336 #define ACPI_TRIPS_HOT 0x02
337 #define ACPI_TRIPS_PASSIVE 0x04
338 #define ACPI_TRIPS_ACTIVE 0x08
339 #define ACPI_TRIPS_DEVICES 0x10
341 #define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE)
342 #define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES
344 #define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \
345 ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \
349 * This exception is thrown out in two cases:
350 * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
351 * when re-evaluating the AML code.
352 * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change.
353 * We need to re-bind the cooling devices of a thermal zone when this occurs.
355 #define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \
357 if (flags != ACPI_TRIPS_INIT) \
358 ACPI_EXCEPTION((AE_INFO, AE_ERROR, \
359 "ACPI thermal trip point %s changed\n" \
360 "Please send acpidump to linux-acpi@vger.kernel.org\n", str)); \
363 static int acpi_thermal_trips_update(struct acpi_thermal
*tz
, int flag
)
365 acpi_status status
= AE_OK
;
366 unsigned long long tmp
;
367 struct acpi_handle_list devices
;
371 /* Critical Shutdown (required) */
372 if (flag
& ACPI_TRIPS_CRITICAL
) {
373 status
= acpi_evaluate_integer(tz
->device
->handle
,
375 tz
->trips
.critical
.temperature
= tmp
;
377 * Treat freezing temperatures as invalid as well; some
378 * BIOSes return really low values and cause reboots at startup.
379 * Below zero (Celsius) values clearly aren't right for sure..
380 * ... so lets discard those as invalid.
382 if (ACPI_FAILURE(status
) ||
383 tz
->trips
.critical
.temperature
<= 2732) {
384 tz
->trips
.critical
.flags
.valid
= 0;
385 ACPI_EXCEPTION((AE_INFO
, status
,
386 "No or invalid critical threshold"));
389 tz
->trips
.critical
.flags
.valid
= 1;
390 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
391 "Found critical threshold [%lu]\n",
392 tz
->trips
.critical
.temperature
));
394 if (tz
->trips
.critical
.flags
.valid
== 1) {
396 tz
->trips
.critical
.flags
.valid
= 0;
397 } else if (crt
> 0) {
398 unsigned long crt_k
= CELSIUS_TO_KELVIN(crt
);
400 * Allow override critical threshold
402 if (crt_k
> tz
->trips
.critical
.temperature
)
403 printk(KERN_WARNING PREFIX
404 "Critical threshold %d C\n", crt
);
405 tz
->trips
.critical
.temperature
= crt_k
;
410 /* Critical Sleep (optional) */
411 if (flag
& ACPI_TRIPS_HOT
) {
412 status
= acpi_evaluate_integer(tz
->device
->handle
,
414 if (ACPI_FAILURE(status
)) {
415 tz
->trips
.hot
.flags
.valid
= 0;
416 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
417 "No hot threshold\n"));
419 tz
->trips
.hot
.temperature
= tmp
;
420 tz
->trips
.hot
.flags
.valid
= 1;
421 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
422 "Found hot threshold [%lu]\n",
423 tz
->trips
.critical
.temperature
));
427 /* Passive (optional) */
428 if (((flag
& ACPI_TRIPS_PASSIVE
) && tz
->trips
.passive
.flags
.valid
) ||
429 (flag
== ACPI_TRIPS_INIT
)) {
430 valid
= tz
->trips
.passive
.flags
.valid
;
433 } else if (psv
> 0) {
434 tmp
= CELSIUS_TO_KELVIN(psv
);
437 status
= acpi_evaluate_integer(tz
->device
->handle
,
441 if (ACPI_FAILURE(status
))
442 tz
->trips
.passive
.flags
.valid
= 0;
444 tz
->trips
.passive
.temperature
= tmp
;
445 tz
->trips
.passive
.flags
.valid
= 1;
446 if (flag
== ACPI_TRIPS_INIT
) {
447 status
= acpi_evaluate_integer(
448 tz
->device
->handle
, "_TC1",
450 if (ACPI_FAILURE(status
))
451 tz
->trips
.passive
.flags
.valid
= 0;
453 tz
->trips
.passive
.tc1
= tmp
;
454 status
= acpi_evaluate_integer(
455 tz
->device
->handle
, "_TC2",
457 if (ACPI_FAILURE(status
))
458 tz
->trips
.passive
.flags
.valid
= 0;
460 tz
->trips
.passive
.tc2
= tmp
;
461 status
= acpi_evaluate_integer(
462 tz
->device
->handle
, "_TSP",
464 if (ACPI_FAILURE(status
))
465 tz
->trips
.passive
.flags
.valid
= 0;
467 tz
->trips
.passive
.tsp
= tmp
;
471 if ((flag
& ACPI_TRIPS_DEVICES
) && tz
->trips
.passive
.flags
.valid
) {
472 memset(&devices
, 0, sizeof(struct acpi_handle_list
));
473 status
= acpi_evaluate_reference(tz
->device
->handle
, "_PSL",
475 if (ACPI_FAILURE(status
)) {
476 printk(KERN_WARNING PREFIX
477 "Invalid passive threshold\n");
478 tz
->trips
.passive
.flags
.valid
= 0;
481 tz
->trips
.passive
.flags
.valid
= 1;
483 if (memcmp(&tz
->trips
.passive
.devices
, &devices
,
484 sizeof(struct acpi_handle_list
))) {
485 memcpy(&tz
->trips
.passive
.devices
, &devices
,
486 sizeof(struct acpi_handle_list
));
487 ACPI_THERMAL_TRIPS_EXCEPTION(flag
, "device");
490 if ((flag
& ACPI_TRIPS_PASSIVE
) || (flag
& ACPI_TRIPS_DEVICES
)) {
491 if (valid
!= tz
->trips
.passive
.flags
.valid
)
492 ACPI_THERMAL_TRIPS_EXCEPTION(flag
, "state");
495 /* Active (optional) */
496 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
497 char name
[5] = { '_', 'A', 'C', ('0' + i
), '\0' };
498 valid
= tz
->trips
.active
[i
].flags
.valid
;
501 break; /* disable all active trip points */
503 if ((flag
== ACPI_TRIPS_INIT
) || ((flag
& ACPI_TRIPS_ACTIVE
) &&
504 tz
->trips
.active
[i
].flags
.valid
)) {
505 status
= acpi_evaluate_integer(tz
->device
->handle
,
507 if (ACPI_FAILURE(status
)) {
508 tz
->trips
.active
[i
].flags
.valid
= 0;
514 tz
->trips
.active
[0].temperature
=
515 CELSIUS_TO_KELVIN(act
);
518 * Don't allow override higher than
519 * the next higher trip point
521 tz
->trips
.active
[i
- 1].temperature
=
522 (tz
->trips
.active
[i
- 2].temperature
<
523 CELSIUS_TO_KELVIN(act
) ?
524 tz
->trips
.active
[i
- 2].temperature
:
525 CELSIUS_TO_KELVIN(act
));
528 tz
->trips
.active
[i
].temperature
= tmp
;
529 tz
->trips
.active
[i
].flags
.valid
= 1;
534 if ((flag
& ACPI_TRIPS_DEVICES
) && tz
->trips
.active
[i
].flags
.valid
) {
535 memset(&devices
, 0, sizeof(struct acpi_handle_list
));
536 status
= acpi_evaluate_reference(tz
->device
->handle
,
537 name
, NULL
, &devices
);
538 if (ACPI_FAILURE(status
)) {
539 printk(KERN_WARNING PREFIX
540 "Invalid active%d threshold\n", i
);
541 tz
->trips
.active
[i
].flags
.valid
= 0;
544 tz
->trips
.active
[i
].flags
.valid
= 1;
546 if (memcmp(&tz
->trips
.active
[i
].devices
, &devices
,
547 sizeof(struct acpi_handle_list
))) {
548 memcpy(&tz
->trips
.active
[i
].devices
, &devices
,
549 sizeof(struct acpi_handle_list
));
550 ACPI_THERMAL_TRIPS_EXCEPTION(flag
, "device");
553 if ((flag
& ACPI_TRIPS_ACTIVE
) || (flag
& ACPI_TRIPS_DEVICES
))
554 if (valid
!= tz
->trips
.active
[i
].flags
.valid
)
555 ACPI_THERMAL_TRIPS_EXCEPTION(flag
, "state");
557 if (!tz
->trips
.active
[i
].flags
.valid
)
561 if (flag
& ACPI_TRIPS_DEVICES
) {
562 memset(&devices
, 0, sizeof(struct acpi_handle_list
));
563 status
= acpi_evaluate_reference(tz
->device
->handle
, "_TZD",
565 if (memcmp(&tz
->devices
, &devices
,
566 sizeof(struct acpi_handle_list
))) {
567 memcpy(&tz
->devices
, &devices
,
568 sizeof(struct acpi_handle_list
));
569 ACPI_THERMAL_TRIPS_EXCEPTION(flag
, "device");
576 static int acpi_thermal_get_trip_points(struct acpi_thermal
*tz
)
578 int i
, valid
, ret
= acpi_thermal_trips_update(tz
, ACPI_TRIPS_INIT
);
583 valid
= tz
->trips
.critical
.flags
.valid
|
584 tz
->trips
.hot
.flags
.valid
|
585 tz
->trips
.passive
.flags
.valid
;
587 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++)
588 valid
|= tz
->trips
.active
[i
].flags
.valid
;
591 printk(KERN_WARNING FW_BUG
"No valid trip found\n");
597 static void acpi_thermal_check(void *data
)
599 struct acpi_thermal
*tz
= data
;
601 thermal_zone_device_update(tz
->thermal_zone
);
604 /* sys I/F for generic thermal sysfs support */
605 #define KELVIN_TO_MILLICELSIUS(t, off) (((t) - (off)) * 100)
607 static int thermal_get_temp(struct thermal_zone_device
*thermal
,
610 struct acpi_thermal
*tz
= thermal
->devdata
;
616 result
= acpi_thermal_get_temperature(tz
);
620 *temp
= KELVIN_TO_MILLICELSIUS(tz
->temperature
, tz
->kelvin_offset
);
624 static const char enabled
[] = "kernel";
625 static const char disabled
[] = "user";
626 static int thermal_get_mode(struct thermal_zone_device
*thermal
,
627 enum thermal_device_mode
*mode
)
629 struct acpi_thermal
*tz
= thermal
->devdata
;
634 *mode
= tz
->tz_enabled
? THERMAL_DEVICE_ENABLED
:
635 THERMAL_DEVICE_DISABLED
;
640 static int thermal_set_mode(struct thermal_zone_device
*thermal
,
641 enum thermal_device_mode mode
)
643 struct acpi_thermal
*tz
= thermal
->devdata
;
650 * enable/disable thermal management from ACPI thermal driver
652 if (mode
== THERMAL_DEVICE_ENABLED
)
654 else if (mode
== THERMAL_DEVICE_DISABLED
)
659 if (enable
!= tz
->tz_enabled
) {
660 tz
->tz_enabled
= enable
;
661 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
662 "%s ACPI thermal control\n",
663 tz
->tz_enabled
? enabled
: disabled
));
664 acpi_thermal_check(tz
);
669 static int thermal_get_trip_type(struct thermal_zone_device
*thermal
,
670 int trip
, enum thermal_trip_type
*type
)
672 struct acpi_thermal
*tz
= thermal
->devdata
;
678 if (tz
->trips
.critical
.flags
.valid
) {
680 *type
= THERMAL_TRIP_CRITICAL
;
686 if (tz
->trips
.hot
.flags
.valid
) {
688 *type
= THERMAL_TRIP_HOT
;
694 if (tz
->trips
.passive
.flags
.valid
) {
696 *type
= THERMAL_TRIP_PASSIVE
;
702 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
&&
703 tz
->trips
.active
[i
].flags
.valid
; i
++) {
705 *type
= THERMAL_TRIP_ACTIVE
;
714 static int thermal_get_trip_temp(struct thermal_zone_device
*thermal
,
715 int trip
, unsigned long *temp
)
717 struct acpi_thermal
*tz
= thermal
->devdata
;
723 if (tz
->trips
.critical
.flags
.valid
) {
725 *temp
= KELVIN_TO_MILLICELSIUS(
726 tz
->trips
.critical
.temperature
,
733 if (tz
->trips
.hot
.flags
.valid
) {
735 *temp
= KELVIN_TO_MILLICELSIUS(
736 tz
->trips
.hot
.temperature
,
743 if (tz
->trips
.passive
.flags
.valid
) {
745 *temp
= KELVIN_TO_MILLICELSIUS(
746 tz
->trips
.passive
.temperature
,
753 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
&&
754 tz
->trips
.active
[i
].flags
.valid
; i
++) {
756 *temp
= KELVIN_TO_MILLICELSIUS(
757 tz
->trips
.active
[i
].temperature
,
767 static int thermal_get_crit_temp(struct thermal_zone_device
*thermal
,
768 unsigned long *temperature
) {
769 struct acpi_thermal
*tz
= thermal
->devdata
;
771 if (tz
->trips
.critical
.flags
.valid
) {
772 *temperature
= KELVIN_TO_MILLICELSIUS(
773 tz
->trips
.critical
.temperature
,
780 static int thermal_notify(struct thermal_zone_device
*thermal
, int trip
,
781 enum thermal_trip_type trip_type
)
784 struct acpi_thermal
*tz
= thermal
->devdata
;
786 if (trip_type
== THERMAL_TRIP_CRITICAL
)
787 type
= ACPI_THERMAL_NOTIFY_CRITICAL
;
788 else if (trip_type
== THERMAL_TRIP_HOT
)
789 type
= ACPI_THERMAL_NOTIFY_HOT
;
793 acpi_bus_generate_proc_event(tz
->device
, type
, 1);
794 acpi_bus_generate_netlink_event(tz
->device
->pnp
.device_class
,
795 dev_name(&tz
->device
->dev
), type
, 1);
797 if (trip_type
== THERMAL_TRIP_CRITICAL
&& nocrt
)
803 typedef int (*cb
)(struct thermal_zone_device
*, int,
804 struct thermal_cooling_device
*);
805 static int acpi_thermal_cooling_device_cb(struct thermal_zone_device
*thermal
,
806 struct thermal_cooling_device
*cdev
,
809 struct acpi_device
*device
= cdev
->devdata
;
810 struct acpi_thermal
*tz
= thermal
->devdata
;
811 struct acpi_device
*dev
;
819 if (tz
->trips
.critical
.flags
.valid
)
822 if (tz
->trips
.hot
.flags
.valid
)
825 if (tz
->trips
.passive
.flags
.valid
) {
827 for (i
= 0; i
< tz
->trips
.passive
.devices
.count
;
829 handle
= tz
->trips
.passive
.devices
.handles
[i
];
830 status
= acpi_bus_get_device(handle
, &dev
);
831 if (ACPI_SUCCESS(status
) && (dev
== device
)) {
832 result
= action(thermal
, trip
, cdev
);
839 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
840 if (!tz
->trips
.active
[i
].flags
.valid
)
844 j
< tz
->trips
.active
[i
].devices
.count
;
846 handle
= tz
->trips
.active
[i
].devices
.handles
[j
];
847 status
= acpi_bus_get_device(handle
, &dev
);
848 if (ACPI_SUCCESS(status
) && (dev
== device
)) {
849 result
= action(thermal
, trip
, cdev
);
856 for (i
= 0; i
< tz
->devices
.count
; i
++) {
857 handle
= tz
->devices
.handles
[i
];
858 status
= acpi_bus_get_device(handle
, &dev
);
859 if (ACPI_SUCCESS(status
) && (dev
== device
)) {
860 result
= action(thermal
, -1, cdev
);
871 acpi_thermal_bind_cooling_device(struct thermal_zone_device
*thermal
,
872 struct thermal_cooling_device
*cdev
)
874 return acpi_thermal_cooling_device_cb(thermal
, cdev
,
875 thermal_zone_bind_cooling_device
);
879 acpi_thermal_unbind_cooling_device(struct thermal_zone_device
*thermal
,
880 struct thermal_cooling_device
*cdev
)
882 return acpi_thermal_cooling_device_cb(thermal
, cdev
,
883 thermal_zone_unbind_cooling_device
);
886 static struct thermal_zone_device_ops acpi_thermal_zone_ops
= {
887 .bind
= acpi_thermal_bind_cooling_device
,
888 .unbind
= acpi_thermal_unbind_cooling_device
,
889 .get_temp
= thermal_get_temp
,
890 .get_mode
= thermal_get_mode
,
891 .set_mode
= thermal_set_mode
,
892 .get_trip_type
= thermal_get_trip_type
,
893 .get_trip_temp
= thermal_get_trip_temp
,
894 .get_crit_temp
= thermal_get_crit_temp
,
895 .notify
= thermal_notify
,
898 static int acpi_thermal_register_thermal_zone(struct acpi_thermal
*tz
)
905 if (tz
->trips
.critical
.flags
.valid
)
908 if (tz
->trips
.hot
.flags
.valid
)
911 if (tz
->trips
.passive
.flags
.valid
)
914 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
&&
915 tz
->trips
.active
[i
].flags
.valid
; i
++, trips
++);
917 if (tz
->trips
.passive
.flags
.valid
)
919 thermal_zone_device_register("acpitz", trips
, tz
,
920 &acpi_thermal_zone_ops
,
921 tz
->trips
.passive
.tc1
,
922 tz
->trips
.passive
.tc2
,
923 tz
->trips
.passive
.tsp
*100,
924 tz
->polling_frequency
*100);
927 thermal_zone_device_register("acpitz", trips
, tz
,
928 &acpi_thermal_zone_ops
,
930 tz
->polling_frequency
*100);
931 if (IS_ERR(tz
->thermal_zone
))
934 result
= sysfs_create_link(&tz
->device
->dev
.kobj
,
935 &tz
->thermal_zone
->device
.kobj
, "thermal_zone");
939 result
= sysfs_create_link(&tz
->thermal_zone
->device
.kobj
,
940 &tz
->device
->dev
.kobj
, "device");
944 status
= acpi_attach_data(tz
->device
->handle
,
945 acpi_bus_private_data_handler
,
947 if (ACPI_FAILURE(status
)) {
948 printk(KERN_ERR PREFIX
949 "Error attaching device data\n");
955 dev_info(&tz
->device
->dev
, "registered as thermal_zone%d\n",
956 tz
->thermal_zone
->id
);
960 static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal
*tz
)
962 sysfs_remove_link(&tz
->device
->dev
.kobj
, "thermal_zone");
963 sysfs_remove_link(&tz
->thermal_zone
->device
.kobj
, "device");
964 thermal_zone_device_unregister(tz
->thermal_zone
);
965 tz
->thermal_zone
= NULL
;
966 acpi_detach_data(tz
->device
->handle
, acpi_bus_private_data_handler
);
970 /* --------------------------------------------------------------------------
972 -------------------------------------------------------------------------- */
974 static struct proc_dir_entry
*acpi_thermal_dir
;
976 static int acpi_thermal_state_seq_show(struct seq_file
*seq
, void *offset
)
978 struct acpi_thermal
*tz
= seq
->private;
984 seq_puts(seq
, "state: ");
986 if (!tz
->state
.critical
&& !tz
->state
.hot
&& !tz
->state
.passive
987 && !tz
->state
.active
)
988 seq_puts(seq
, "ok\n");
990 if (tz
->state
.critical
)
991 seq_puts(seq
, "critical ");
993 seq_puts(seq
, "hot ");
994 if (tz
->state
.passive
)
995 seq_puts(seq
, "passive ");
996 if (tz
->state
.active
)
997 seq_printf(seq
, "active[%d]", tz
->state
.active_index
);
1005 static int acpi_thermal_state_open_fs(struct inode
*inode
, struct file
*file
)
1007 return single_open(file
, acpi_thermal_state_seq_show
, PDE(inode
)->data
);
1010 static int acpi_thermal_temp_seq_show(struct seq_file
*seq
, void *offset
)
1013 struct acpi_thermal
*tz
= seq
->private;
1019 result
= acpi_thermal_get_temperature(tz
);
1023 seq_printf(seq
, "temperature: %ld C\n",
1024 KELVIN_TO_CELSIUS(tz
->temperature
));
1030 static int acpi_thermal_temp_open_fs(struct inode
*inode
, struct file
*file
)
1032 return single_open(file
, acpi_thermal_temp_seq_show
, PDE(inode
)->data
);
1035 static int acpi_thermal_trip_seq_show(struct seq_file
*seq
, void *offset
)
1037 struct acpi_thermal
*tz
= seq
->private;
1038 struct acpi_device
*device
;
1048 if (tz
->trips
.critical
.flags
.valid
)
1049 seq_printf(seq
, "critical (S5): %ld C%s",
1050 KELVIN_TO_CELSIUS(tz
->trips
.critical
.temperature
),
1051 nocrt
? " <disabled>\n" : "\n");
1053 if (tz
->trips
.hot
.flags
.valid
)
1054 seq_printf(seq
, "hot (S4): %ld C%s",
1055 KELVIN_TO_CELSIUS(tz
->trips
.hot
.temperature
),
1056 nocrt
? " <disabled>\n" : "\n");
1058 if (tz
->trips
.passive
.flags
.valid
) {
1060 "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
1061 KELVIN_TO_CELSIUS(tz
->trips
.passive
.temperature
),
1062 tz
->trips
.passive
.tc1
, tz
->trips
.passive
.tc2
,
1063 tz
->trips
.passive
.tsp
);
1064 for (j
= 0; j
< tz
->trips
.passive
.devices
.count
; j
++) {
1065 status
= acpi_bus_get_device(tz
->trips
.passive
.devices
.
1066 handles
[j
], &device
);
1067 seq_printf(seq
, "%4.4s ", status
? "" :
1068 acpi_device_bid(device
));
1070 seq_puts(seq
, "\n");
1072 seq_printf(seq
, "passive (forced):");
1073 if (tz
->thermal_zone
->forced_passive
)
1074 seq_printf(seq
, " %i C\n",
1075 tz
->thermal_zone
->forced_passive
/ 1000);
1077 seq_printf(seq
, "<not set>\n");
1080 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
1081 if (!(tz
->trips
.active
[i
].flags
.valid
))
1083 seq_printf(seq
, "active[%d]: %ld C: devices=",
1085 KELVIN_TO_CELSIUS(tz
->trips
.active
[i
].temperature
));
1086 for (j
= 0; j
< tz
->trips
.active
[i
].devices
.count
; j
++){
1087 status
= acpi_bus_get_device(tz
->trips
.active
[i
].
1090 seq_printf(seq
, "%4.4s ", status
? "" :
1091 acpi_device_bid(device
));
1093 seq_puts(seq
, "\n");
1100 static int acpi_thermal_trip_open_fs(struct inode
*inode
, struct file
*file
)
1102 return single_open(file
, acpi_thermal_trip_seq_show
, PDE(inode
)->data
);
1105 static int acpi_thermal_cooling_seq_show(struct seq_file
*seq
, void *offset
)
1107 struct acpi_thermal
*tz
= seq
->private;
1113 if (!tz
->flags
.cooling_mode
)
1114 seq_puts(seq
, "<setting not supported>\n");
1116 seq_puts(seq
, "0 - Active; 1 - Passive\n");
1122 static int acpi_thermal_cooling_open_fs(struct inode
*inode
, struct file
*file
)
1124 return single_open(file
, acpi_thermal_cooling_seq_show
,
1129 acpi_thermal_write_cooling_mode(struct file
*file
,
1130 const char __user
* buffer
,
1131 size_t count
, loff_t
* ppos
)
1133 struct seq_file
*m
= file
->private_data
;
1134 struct acpi_thermal
*tz
= m
->private;
1136 char mode_string
[12] = { '\0' };
1139 if (!tz
|| (count
> sizeof(mode_string
) - 1))
1142 if (!tz
->flags
.cooling_mode
)
1145 if (copy_from_user(mode_string
, buffer
, count
))
1148 mode_string
[count
] = '\0';
1150 result
= acpi_thermal_set_cooling_mode(tz
,
1151 simple_strtoul(mode_string
, NULL
,
1156 acpi_thermal_check(tz
);
1161 static int acpi_thermal_polling_seq_show(struct seq_file
*seq
, void *offset
)
1163 struct acpi_thermal
*tz
= seq
->private;
1169 if (!tz
->thermal_zone
->polling_delay
) {
1170 seq_puts(seq
, "<polling disabled>\n");
1174 seq_printf(seq
, "polling frequency: %d seconds\n",
1175 (tz
->thermal_zone
->polling_delay
/ 1000));
1181 static int acpi_thermal_polling_open_fs(struct inode
*inode
, struct file
*file
)
1183 return single_open(file
, acpi_thermal_polling_seq_show
,
1188 acpi_thermal_write_polling(struct file
*file
,
1189 const char __user
* buffer
,
1190 size_t count
, loff_t
* ppos
)
1192 struct seq_file
*m
= file
->private_data
;
1193 struct acpi_thermal
*tz
= m
->private;
1195 char polling_string
[12] = { '\0' };
1199 if (!tz
|| (count
> sizeof(polling_string
) - 1))
1202 if (copy_from_user(polling_string
, buffer
, count
))
1205 polling_string
[count
] = '\0';
1207 seconds
= simple_strtoul(polling_string
, NULL
, 0);
1209 result
= acpi_thermal_set_polling(tz
, seconds
);
1213 acpi_thermal_check(tz
);
1218 static int acpi_thermal_add_fs(struct acpi_device
*device
)
1220 struct proc_dir_entry
*entry
= NULL
;
1223 if (!acpi_device_dir(device
)) {
1224 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
1226 if (!acpi_device_dir(device
))
1231 entry
= proc_create_data(ACPI_THERMAL_FILE_STATE
,
1232 S_IRUGO
, acpi_device_dir(device
),
1233 &acpi_thermal_state_fops
,
1234 acpi_driver_data(device
));
1238 /* 'temperature' [R] */
1239 entry
= proc_create_data(ACPI_THERMAL_FILE_TEMPERATURE
,
1240 S_IRUGO
, acpi_device_dir(device
),
1241 &acpi_thermal_temp_fops
,
1242 acpi_driver_data(device
));
1246 /* 'trip_points' [R] */
1247 entry
= proc_create_data(ACPI_THERMAL_FILE_TRIP_POINTS
,
1249 acpi_device_dir(device
),
1250 &acpi_thermal_trip_fops
,
1251 acpi_driver_data(device
));
1255 /* 'cooling_mode' [R/W] */
1256 entry
= proc_create_data(ACPI_THERMAL_FILE_COOLING_MODE
,
1257 S_IFREG
| S_IRUGO
| S_IWUSR
,
1258 acpi_device_dir(device
),
1259 &acpi_thermal_cooling_fops
,
1260 acpi_driver_data(device
));
1264 /* 'polling_frequency' [R/W] */
1265 entry
= proc_create_data(ACPI_THERMAL_FILE_POLLING_FREQ
,
1266 S_IFREG
| S_IRUGO
| S_IWUSR
,
1267 acpi_device_dir(device
),
1268 &acpi_thermal_polling_fops
,
1269 acpi_driver_data(device
));
1275 static int acpi_thermal_remove_fs(struct acpi_device
*device
)
1278 if (acpi_device_dir(device
)) {
1279 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ
,
1280 acpi_device_dir(device
));
1281 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE
,
1282 acpi_device_dir(device
));
1283 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS
,
1284 acpi_device_dir(device
));
1285 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE
,
1286 acpi_device_dir(device
));
1287 remove_proc_entry(ACPI_THERMAL_FILE_STATE
,
1288 acpi_device_dir(device
));
1289 remove_proc_entry(acpi_device_bid(device
), acpi_thermal_dir
);
1290 acpi_device_dir(device
) = NULL
;
1296 /* --------------------------------------------------------------------------
1298 -------------------------------------------------------------------------- */
1300 static void acpi_thermal_notify(struct acpi_device
*device
, u32 event
)
1302 struct acpi_thermal
*tz
= acpi_driver_data(device
);
1309 case ACPI_THERMAL_NOTIFY_TEMPERATURE
:
1310 acpi_thermal_check(tz
);
1312 case ACPI_THERMAL_NOTIFY_THRESHOLDS
:
1313 acpi_thermal_trips_update(tz
, ACPI_TRIPS_REFRESH_THRESHOLDS
);
1314 acpi_thermal_check(tz
);
1315 acpi_bus_generate_proc_event(device
, event
, 0);
1316 acpi_bus_generate_netlink_event(device
->pnp
.device_class
,
1317 dev_name(&device
->dev
), event
, 0);
1319 case ACPI_THERMAL_NOTIFY_DEVICES
:
1320 acpi_thermal_trips_update(tz
, ACPI_TRIPS_REFRESH_DEVICES
);
1321 acpi_thermal_check(tz
);
1322 acpi_bus_generate_proc_event(device
, event
, 0);
1323 acpi_bus_generate_netlink_event(device
->pnp
.device_class
,
1324 dev_name(&device
->dev
), event
, 0);
1327 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1328 "Unsupported event [0x%x]\n", event
));
1333 static int acpi_thermal_get_info(struct acpi_thermal
*tz
)
1341 /* Get temperature [_TMP] (required) */
1342 result
= acpi_thermal_get_temperature(tz
);
1346 /* Get trip points [_CRT, _PSV, etc.] (required) */
1347 result
= acpi_thermal_get_trip_points(tz
);
1351 /* Set the cooling mode [_SCP] to active cooling (default) */
1352 result
= acpi_thermal_set_cooling_mode(tz
, ACPI_THERMAL_MODE_ACTIVE
);
1354 tz
->flags
.cooling_mode
= 1;
1356 /* Get default polling frequency [_TZP] (optional) */
1358 tz
->polling_frequency
= tzp
;
1360 acpi_thermal_get_polling_frequency(tz
);
1366 * The exact offset between Kelvin and degree Celsius is 273.15. However ACPI
1367 * handles temperature values with a single decimal place. As a consequence,
1368 * some implementations use an offset of 273.1 and others use an offset of
1369 * 273.2. Try to find out which one is being used, to present the most
1370 * accurate and visually appealing number.
1372 * The heuristic below should work for all ACPI thermal zones which have a
1373 * critical trip point with a value being a multiple of 0.5 degree Celsius.
1375 static void acpi_thermal_guess_offset(struct acpi_thermal
*tz
)
1377 if (tz
->trips
.critical
.flags
.valid
&&
1378 (tz
->trips
.critical
.temperature
% 5) == 1)
1379 tz
->kelvin_offset
= 2731;
1381 tz
->kelvin_offset
= 2732;
1384 static int acpi_thermal_add(struct acpi_device
*device
)
1387 struct acpi_thermal
*tz
= NULL
;
1393 tz
= kzalloc(sizeof(struct acpi_thermal
), GFP_KERNEL
);
1397 tz
->device
= device
;
1398 strcpy(tz
->name
, device
->pnp
.bus_id
);
1399 strcpy(acpi_device_name(device
), ACPI_THERMAL_DEVICE_NAME
);
1400 strcpy(acpi_device_class(device
), ACPI_THERMAL_CLASS
);
1401 device
->driver_data
= tz
;
1402 mutex_init(&tz
->lock
);
1405 result
= acpi_thermal_get_info(tz
);
1409 acpi_thermal_guess_offset(tz
);
1411 result
= acpi_thermal_register_thermal_zone(tz
);
1415 result
= acpi_thermal_add_fs(device
);
1417 goto unregister_thermal_zone
;
1419 printk(KERN_INFO PREFIX
"%s [%s] (%ld C)\n",
1420 acpi_device_name(device
), acpi_device_bid(device
),
1421 KELVIN_TO_CELSIUS(tz
->temperature
));
1424 unregister_thermal_zone
:
1425 thermal_zone_device_unregister(tz
->thermal_zone
);
1432 static int acpi_thermal_remove(struct acpi_device
*device
, int type
)
1434 struct acpi_thermal
*tz
= NULL
;
1436 if (!device
|| !acpi_driver_data(device
))
1439 tz
= acpi_driver_data(device
);
1441 acpi_thermal_remove_fs(device
);
1442 acpi_thermal_unregister_thermal_zone(tz
);
1443 mutex_destroy(&tz
->lock
);
1448 static int acpi_thermal_resume(struct acpi_device
*device
)
1450 struct acpi_thermal
*tz
= NULL
;
1451 int i
, j
, power_state
, result
;
1454 if (!device
|| !acpi_driver_data(device
))
1457 tz
= acpi_driver_data(device
);
1459 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
1460 if (!(&tz
->trips
.active
[i
]))
1462 if (!tz
->trips
.active
[i
].flags
.valid
)
1464 tz
->trips
.active
[i
].flags
.enabled
= 1;
1465 for (j
= 0; j
< tz
->trips
.active
[i
].devices
.count
; j
++) {
1466 result
= acpi_bus_get_power(tz
->trips
.active
[i
].devices
.
1467 handles
[j
], &power_state
);
1468 if (result
|| (power_state
!= ACPI_STATE_D0
)) {
1469 tz
->trips
.active
[i
].flags
.enabled
= 0;
1473 tz
->state
.active
|= tz
->trips
.active
[i
].flags
.enabled
;
1476 acpi_thermal_check(tz
);
1481 static int thermal_act(const struct dmi_system_id
*d
) {
1484 printk(KERN_NOTICE
"ACPI: %s detected: "
1485 "disabling all active thermal trip points\n", d
->ident
);
1490 static int thermal_nocrt(const struct dmi_system_id
*d
) {
1492 printk(KERN_NOTICE
"ACPI: %s detected: "
1493 "disabling all critical thermal trip point actions.\n", d
->ident
);
1497 static int thermal_tzp(const struct dmi_system_id
*d
) {
1500 printk(KERN_NOTICE
"ACPI: %s detected: "
1501 "enabling thermal zone polling\n", d
->ident
);
1502 tzp
= 300; /* 300 dS = 30 Seconds */
1506 static int thermal_psv(const struct dmi_system_id
*d
) {
1509 printk(KERN_NOTICE
"ACPI: %s detected: "
1510 "disabling all passive thermal trip points\n", d
->ident
);
1516 static struct dmi_system_id thermal_dmi_table
[] __initdata
= {
1518 * Award BIOS on this AOpen makes thermal control almost worthless.
1519 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1522 .callback
= thermal_act
,
1523 .ident
= "AOpen i915GMm-HFS",
1525 DMI_MATCH(DMI_BOARD_VENDOR
, "AOpen"),
1526 DMI_MATCH(DMI_BOARD_NAME
, "i915GMm-HFS"),
1530 .callback
= thermal_psv
,
1531 .ident
= "AOpen i915GMm-HFS",
1533 DMI_MATCH(DMI_BOARD_VENDOR
, "AOpen"),
1534 DMI_MATCH(DMI_BOARD_NAME
, "i915GMm-HFS"),
1538 .callback
= thermal_tzp
,
1539 .ident
= "AOpen i915GMm-HFS",
1541 DMI_MATCH(DMI_BOARD_VENDOR
, "AOpen"),
1542 DMI_MATCH(DMI_BOARD_NAME
, "i915GMm-HFS"),
1546 .callback
= thermal_nocrt
,
1547 .ident
= "Gigabyte GA-7ZX",
1549 DMI_MATCH(DMI_BOARD_VENDOR
, "Gigabyte Technology Co., Ltd."),
1550 DMI_MATCH(DMI_BOARD_NAME
, "7ZX"),
1556 static int __init
acpi_thermal_init(void)
1560 dmi_check_system(thermal_dmi_table
);
1563 printk(KERN_NOTICE
"ACPI: thermal control disabled\n");
1566 acpi_thermal_dir
= proc_mkdir(ACPI_THERMAL_CLASS
, acpi_root_dir
);
1567 if (!acpi_thermal_dir
)
1570 result
= acpi_bus_register_driver(&acpi_thermal_driver
);
1572 remove_proc_entry(ACPI_THERMAL_CLASS
, acpi_root_dir
);
1579 static void __exit
acpi_thermal_exit(void)
1582 acpi_bus_unregister_driver(&acpi_thermal_driver
);
1584 remove_proc_entry(ACPI_THERMAL_CLASS
, acpi_root_dir
);
1589 module_init(acpi_thermal_init
);
1590 module_exit(acpi_thermal_exit
);