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>
46 #include <linux/thermal.h>
47 #include <acpi/acpi_bus.h>
48 #include <acpi/acpi_drivers.h>
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 _COMPONENT ACPI_THERMAL_COMPONENT
68 ACPI_MODULE_NAME("thermal");
70 MODULE_AUTHOR("Paul Diefenbaugh");
71 MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
72 MODULE_LICENSE("GPL");
75 module_param(act
, int, 0644);
76 MODULE_PARM_DESC(act
, "Disable or override all lowest active trip points.");
79 module_param(crt
, int, 0644);
80 MODULE_PARM_DESC(crt
, "Disable or lower all critical trip points.");
83 module_param(tzp
, int, 0444);
84 MODULE_PARM_DESC(tzp
, "Thermal zone polling frequency, in 1/10 seconds.");
87 module_param(nocrt
, int, 0);
88 MODULE_PARM_DESC(nocrt
, "Set to take no action upon ACPI thermal zone critical trips points.");
91 module_param(off
, int, 0);
92 MODULE_PARM_DESC(off
, "Set to disable ACPI thermal support.");
95 module_param(psv
, int, 0644);
96 MODULE_PARM_DESC(psv
, "Disable or override all passive trip points.");
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
;
194 struct thermal_zone_device
*thermal_zone
;
199 static const struct file_operations acpi_thermal_state_fops
= {
200 .owner
= THIS_MODULE
,
201 .open
= acpi_thermal_state_open_fs
,
204 .release
= single_release
,
207 static const struct file_operations acpi_thermal_temp_fops
= {
208 .owner
= THIS_MODULE
,
209 .open
= acpi_thermal_temp_open_fs
,
212 .release
= single_release
,
215 static const struct file_operations acpi_thermal_trip_fops
= {
216 .owner
= THIS_MODULE
,
217 .open
= acpi_thermal_trip_open_fs
,
220 .release
= single_release
,
223 static const struct file_operations acpi_thermal_cooling_fops
= {
224 .owner
= THIS_MODULE
,
225 .open
= acpi_thermal_cooling_open_fs
,
227 .write
= acpi_thermal_write_cooling_mode
,
229 .release
= single_release
,
232 static const struct file_operations acpi_thermal_polling_fops
= {
233 .owner
= THIS_MODULE
,
234 .open
= acpi_thermal_polling_open_fs
,
236 .write
= acpi_thermal_write_polling
,
238 .release
= single_release
,
241 /* --------------------------------------------------------------------------
242 Thermal Zone Management
243 -------------------------------------------------------------------------- */
245 static int acpi_thermal_get_temperature(struct acpi_thermal
*tz
)
247 acpi_status status
= AE_OK
;
248 unsigned long long tmp
;
253 tz
->last_temperature
= tz
->temperature
;
255 status
= acpi_evaluate_integer(tz
->device
->handle
, "_TMP", NULL
, &tmp
);
256 if (ACPI_FAILURE(status
))
259 tz
->temperature
= tmp
;
260 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Temperature is %lu dK\n",
266 static int acpi_thermal_get_polling_frequency(struct acpi_thermal
*tz
)
268 acpi_status status
= AE_OK
;
269 unsigned long long tmp
;
274 status
= acpi_evaluate_integer(tz
->device
->handle
, "_TZP", NULL
, &tmp
);
275 if (ACPI_FAILURE(status
))
278 tz
->polling_frequency
= tmp
;
279 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Polling frequency is %lu dS\n",
280 tz
->polling_frequency
));
285 static int acpi_thermal_set_polling(struct acpi_thermal
*tz
, int seconds
)
291 tz
->polling_frequency
= seconds
* 10; /* Convert value to deci-seconds */
293 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
294 "Polling frequency set to %lu seconds\n",
295 tz
->polling_frequency
/10));
300 static int acpi_thermal_set_cooling_mode(struct acpi_thermal
*tz
, int mode
)
302 acpi_status status
= AE_OK
;
303 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
304 struct acpi_object_list arg_list
= { 1, &arg0
};
305 acpi_handle handle
= NULL
;
311 status
= acpi_get_handle(tz
->device
->handle
, "_SCP", &handle
);
312 if (ACPI_FAILURE(status
)) {
313 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "_SCP not present\n"));
317 arg0
.integer
.value
= mode
;
319 status
= acpi_evaluate_object(handle
, NULL
, &arg_list
, NULL
);
320 if (ACPI_FAILURE(status
))
326 #define ACPI_TRIPS_CRITICAL 0x01
327 #define ACPI_TRIPS_HOT 0x02
328 #define ACPI_TRIPS_PASSIVE 0x04
329 #define ACPI_TRIPS_ACTIVE 0x08
330 #define ACPI_TRIPS_DEVICES 0x10
332 #define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE)
333 #define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES
335 #define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \
336 ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \
340 * This exception is thrown out in two cases:
341 * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
342 * when re-evaluating the AML code.
343 * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change.
344 * We need to re-bind the cooling devices of a thermal zone when this occurs.
346 #define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \
348 if (flags != ACPI_TRIPS_INIT) \
349 ACPI_EXCEPTION((AE_INFO, AE_ERROR, \
350 "ACPI thermal trip point %s changed\n" \
351 "Please send acpidump to linux-acpi@vger.kernel.org\n", str)); \
354 static int acpi_thermal_trips_update(struct acpi_thermal
*tz
, int flag
)
356 acpi_status status
= AE_OK
;
357 unsigned long long tmp
;
358 struct acpi_handle_list devices
;
362 /* Critical Shutdown (required) */
363 if (flag
& ACPI_TRIPS_CRITICAL
) {
364 status
= acpi_evaluate_integer(tz
->device
->handle
,
366 tz
->trips
.critical
.temperature
= tmp
;
368 * Treat freezing temperatures as invalid as well; some
369 * BIOSes return really low values and cause reboots at startup.
370 * Below zero (Celcius) values clearly aren't right for sure..
371 * ... so lets discard those as invalid.
373 if (ACPI_FAILURE(status
) ||
374 tz
->trips
.critical
.temperature
<= 2732) {
375 tz
->trips
.critical
.flags
.valid
= 0;
376 ACPI_EXCEPTION((AE_INFO
, status
,
377 "No or invalid critical threshold"));
380 tz
->trips
.critical
.flags
.valid
= 1;
381 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
382 "Found critical threshold [%lu]\n",
383 tz
->trips
.critical
.temperature
));
385 if (tz
->trips
.critical
.flags
.valid
== 1) {
387 tz
->trips
.critical
.flags
.valid
= 0;
388 } else if (crt
> 0) {
389 unsigned long crt_k
= CELSIUS_TO_KELVIN(crt
);
391 * Allow override critical threshold
393 if (crt_k
> tz
->trips
.critical
.temperature
)
394 printk(KERN_WARNING PREFIX
395 "Critical threshold %d C\n", crt
);
396 tz
->trips
.critical
.temperature
= crt_k
;
401 /* Critical Sleep (optional) */
402 if (flag
& ACPI_TRIPS_HOT
) {
403 status
= acpi_evaluate_integer(tz
->device
->handle
,
405 if (ACPI_FAILURE(status
)) {
406 tz
->trips
.hot
.flags
.valid
= 0;
407 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
408 "No hot threshold\n"));
410 tz
->trips
.hot
.temperature
= tmp
;
411 tz
->trips
.hot
.flags
.valid
= 1;
412 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
413 "Found hot threshold [%lu]\n",
414 tz
->trips
.critical
.temperature
));
418 /* Passive (optional) */
419 if (flag
& ACPI_TRIPS_PASSIVE
) {
420 valid
= tz
->trips
.passive
.flags
.valid
;
423 } else if (psv
> 0) {
424 tmp
= CELSIUS_TO_KELVIN(psv
);
427 status
= acpi_evaluate_integer(tz
->device
->handle
,
431 if (ACPI_FAILURE(status
))
432 tz
->trips
.passive
.flags
.valid
= 0;
434 tz
->trips
.passive
.temperature
= tmp
;
435 tz
->trips
.passive
.flags
.valid
= 1;
436 if (flag
== ACPI_TRIPS_INIT
) {
437 status
= acpi_evaluate_integer(
438 tz
->device
->handle
, "_TC1",
440 if (ACPI_FAILURE(status
))
441 tz
->trips
.passive
.flags
.valid
= 0;
443 tz
->trips
.passive
.tc1
= tmp
;
444 status
= acpi_evaluate_integer(
445 tz
->device
->handle
, "_TC2",
447 if (ACPI_FAILURE(status
))
448 tz
->trips
.passive
.flags
.valid
= 0;
450 tz
->trips
.passive
.tc2
= tmp
;
451 status
= acpi_evaluate_integer(
452 tz
->device
->handle
, "_TSP",
454 if (ACPI_FAILURE(status
))
455 tz
->trips
.passive
.flags
.valid
= 0;
457 tz
->trips
.passive
.tsp
= tmp
;
461 if ((flag
& ACPI_TRIPS_DEVICES
) && tz
->trips
.passive
.flags
.valid
) {
462 memset(&devices
, 0, sizeof(struct acpi_handle_list
));
463 status
= acpi_evaluate_reference(tz
->device
->handle
, "_PSL",
465 if (ACPI_FAILURE(status
))
466 tz
->trips
.passive
.flags
.valid
= 0;
468 tz
->trips
.passive
.flags
.valid
= 1;
470 if (memcmp(&tz
->trips
.passive
.devices
, &devices
,
471 sizeof(struct acpi_handle_list
))) {
472 memcpy(&tz
->trips
.passive
.devices
, &devices
,
473 sizeof(struct acpi_handle_list
));
474 ACPI_THERMAL_TRIPS_EXCEPTION(flag
, "device");
477 if ((flag
& ACPI_TRIPS_PASSIVE
) || (flag
& ACPI_TRIPS_DEVICES
)) {
478 if (valid
!= tz
->trips
.passive
.flags
.valid
)
479 ACPI_THERMAL_TRIPS_EXCEPTION(flag
, "state");
482 /* Active (optional) */
483 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
484 char name
[5] = { '_', 'A', 'C', ('0' + i
), '\0' };
485 valid
= tz
->trips
.active
[i
].flags
.valid
;
488 break; /* disable all active trip points */
490 if (flag
& ACPI_TRIPS_ACTIVE
) {
491 status
= acpi_evaluate_integer(tz
->device
->handle
,
493 if (ACPI_FAILURE(status
)) {
494 tz
->trips
.active
[i
].flags
.valid
= 0;
500 tz
->trips
.active
[0].temperature
=
501 CELSIUS_TO_KELVIN(act
);
504 * Don't allow override higher than
505 * the next higher trip point
507 tz
->trips
.active
[i
- 1].temperature
=
508 (tz
->trips
.active
[i
- 2].temperature
<
509 CELSIUS_TO_KELVIN(act
) ?
510 tz
->trips
.active
[i
- 2].temperature
:
511 CELSIUS_TO_KELVIN(act
));
514 tz
->trips
.active
[i
].temperature
= tmp
;
515 tz
->trips
.active
[i
].flags
.valid
= 1;
520 if ((flag
& ACPI_TRIPS_DEVICES
) && tz
->trips
.active
[i
].flags
.valid
) {
521 memset(&devices
, 0, sizeof(struct acpi_handle_list
));
522 status
= acpi_evaluate_reference(tz
->device
->handle
,
523 name
, NULL
, &devices
);
524 if (ACPI_FAILURE(status
))
525 tz
->trips
.active
[i
].flags
.valid
= 0;
527 tz
->trips
.active
[i
].flags
.valid
= 1;
529 if (memcmp(&tz
->trips
.active
[i
].devices
, &devices
,
530 sizeof(struct acpi_handle_list
))) {
531 memcpy(&tz
->trips
.active
[i
].devices
, &devices
,
532 sizeof(struct acpi_handle_list
));
533 ACPI_THERMAL_TRIPS_EXCEPTION(flag
, "device");
536 if ((flag
& ACPI_TRIPS_ACTIVE
) || (flag
& ACPI_TRIPS_DEVICES
))
537 if (valid
!= tz
->trips
.active
[i
].flags
.valid
)
538 ACPI_THERMAL_TRIPS_EXCEPTION(flag
, "state");
540 if (!tz
->trips
.active
[i
].flags
.valid
)
544 if (flag
& ACPI_TRIPS_DEVICES
) {
545 memset(&devices
, 0, sizeof(struct acpi_handle_list
));
546 status
= acpi_evaluate_reference(tz
->device
->handle
, "_TZD",
548 if (memcmp(&tz
->devices
, &devices
,
549 sizeof(struct acpi_handle_list
))) {
550 memcpy(&tz
->devices
, &devices
,
551 sizeof(struct acpi_handle_list
));
552 ACPI_THERMAL_TRIPS_EXCEPTION(flag
, "device");
559 static int acpi_thermal_get_trip_points(struct acpi_thermal
*tz
)
561 return acpi_thermal_trips_update(tz
, ACPI_TRIPS_INIT
);
564 static int acpi_thermal_critical(struct acpi_thermal
*tz
)
566 if (!tz
|| !tz
->trips
.critical
.flags
.valid
)
569 if (tz
->temperature
>= tz
->trips
.critical
.temperature
) {
570 printk(KERN_WARNING PREFIX
"Critical trip point\n");
571 tz
->trips
.critical
.flags
.enabled
= 1;
572 } else if (tz
->trips
.critical
.flags
.enabled
)
573 tz
->trips
.critical
.flags
.enabled
= 0;
575 acpi_bus_generate_proc_event(tz
->device
, ACPI_THERMAL_NOTIFY_CRITICAL
,
576 tz
->trips
.critical
.flags
.enabled
);
577 acpi_bus_generate_netlink_event(tz
->device
->pnp
.device_class
,
578 dev_name(&tz
->device
->dev
),
579 ACPI_THERMAL_NOTIFY_CRITICAL
,
580 tz
->trips
.critical
.flags
.enabled
);
582 /* take no action if nocrt is set */
585 "Critical temperature reached (%ld C), shutting down.\n",
586 KELVIN_TO_CELSIUS(tz
->temperature
));
587 orderly_poweroff(true);
593 static int acpi_thermal_hot(struct acpi_thermal
*tz
)
595 if (!tz
|| !tz
->trips
.hot
.flags
.valid
)
598 if (tz
->temperature
>= tz
->trips
.hot
.temperature
) {
599 printk(KERN_WARNING PREFIX
"Hot trip point\n");
600 tz
->trips
.hot
.flags
.enabled
= 1;
601 } else if (tz
->trips
.hot
.flags
.enabled
)
602 tz
->trips
.hot
.flags
.enabled
= 0;
604 acpi_bus_generate_proc_event(tz
->device
, ACPI_THERMAL_NOTIFY_HOT
,
605 tz
->trips
.hot
.flags
.enabled
);
606 acpi_bus_generate_netlink_event(tz
->device
->pnp
.device_class
,
607 dev_name(&tz
->device
->dev
),
608 ACPI_THERMAL_NOTIFY_HOT
,
609 tz
->trips
.hot
.flags
.enabled
);
611 /* TBD: Call user-mode "sleep(S4)" function if nocrt is cleared */
616 static void acpi_thermal_passive(struct acpi_thermal
*tz
)
619 struct acpi_thermal_passive
*passive
= NULL
;
624 if (!tz
|| !tz
->trips
.passive
.flags
.valid
)
627 passive
= &(tz
->trips
.passive
);
632 * Calculate the thermal trend (using the passive cooling equation)
633 * and modify the performance limit for all passive cooling devices
634 * accordingly. Note that we assume symmetry.
636 if (tz
->temperature
>= passive
->temperature
) {
638 (passive
->tc1
* (tz
->temperature
- tz
->last_temperature
)) +
639 (passive
->tc2
* (tz
->temperature
- passive
->temperature
));
640 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
641 "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
642 trend
, passive
->tc1
, tz
->temperature
,
643 tz
->last_temperature
, passive
->tc2
,
644 tz
->temperature
, passive
->temperature
));
645 passive
->flags
.enabled
= 1;
648 for (i
= 0; i
< passive
->devices
.count
; i
++)
649 acpi_processor_set_thermal_limit(passive
->
652 ACPI_PROCESSOR_LIMIT_INCREMENT
);
654 else if (trend
< 0) {
655 for (i
= 0; i
< passive
->devices
.count
; i
++)
657 * assume that we are on highest
658 * freq/lowest thrott and can leave
659 * passive mode, even in error case
661 if (!acpi_processor_set_thermal_limit
662 (passive
->devices
.handles
[i
],
663 ACPI_PROCESSOR_LIMIT_DECREMENT
))
666 * Leave cooling mode, even if the temp might
667 * higher than trip point This is because some
668 * machines might have long thermal polling
669 * frequencies (tsp) defined. We will fall back
670 * into passive mode in next cycle (probably quicker)
673 passive
->flags
.enabled
= 0;
674 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
675 "Disabling passive cooling, still above threshold,"
676 " but we are cooling down\n"));
685 * Implement passive cooling hysteresis to slowly increase performance
686 * and avoid thrashing around the passive trip point. Note that we
689 if (!passive
->flags
.enabled
)
691 for (i
= 0; i
< passive
->devices
.count
; i
++)
692 if (!acpi_processor_set_thermal_limit
693 (passive
->devices
.handles
[i
],
694 ACPI_PROCESSOR_LIMIT_DECREMENT
))
697 passive
->flags
.enabled
= 0;
698 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
699 "Disabling passive cooling (zone is cool)\n"));
703 static void acpi_thermal_active(struct acpi_thermal
*tz
)
706 struct acpi_thermal_active
*active
= NULL
;
709 unsigned long maxtemp
= 0;
715 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
716 active
= &(tz
->trips
.active
[i
]);
717 if (!active
|| !active
->flags
.valid
)
719 if (tz
->temperature
>= active
->temperature
) {
723 * If not already enabled, turn ON all cooling devices
724 * associated with this active threshold.
726 if (active
->temperature
> maxtemp
)
727 tz
->state
.active_index
= i
;
728 maxtemp
= active
->temperature
;
729 if (active
->flags
.enabled
)
731 for (j
= 0; j
< active
->devices
.count
; j
++) {
733 acpi_bus_set_power(active
->devices
.
737 printk(KERN_WARNING PREFIX
738 "Unable to turn cooling device [%p] 'on'\n",
743 active
->flags
.enabled
= 1;
744 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
745 "Cooling device [%p] now 'on'\n",
746 active
->devices
.handles
[j
]));
750 if (!active
->flags
.enabled
)
755 * Turn OFF all cooling devices associated with this
758 for (j
= 0; j
< active
->devices
.count
; j
++) {
759 result
= acpi_bus_set_power(active
->devices
.handles
[j
],
762 printk(KERN_WARNING PREFIX
763 "Unable to turn cooling device [%p] 'off'\n",
764 active
->devices
.handles
[j
]);
767 active
->flags
.enabled
= 0;
768 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
769 "Cooling device [%p] now 'off'\n",
770 active
->devices
.handles
[j
]));
775 static void acpi_thermal_check(void *context
);
777 static void acpi_thermal_run(unsigned long data
)
779 struct acpi_thermal
*tz
= (struct acpi_thermal
*)data
;
781 acpi_os_execute(OSL_GPE_HANDLER
, acpi_thermal_check
, (void *)data
);
784 static void acpi_thermal_active_off(void *data
)
787 struct acpi_thermal
*tz
= data
;
790 struct acpi_thermal_active
*active
= NULL
;
793 printk(KERN_ERR PREFIX
"Invalid (NULL) context\n");
797 result
= acpi_thermal_get_temperature(tz
);
801 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
802 active
= &(tz
->trips
.active
[i
]);
803 if (!active
|| !active
->flags
.valid
)
805 if (tz
->temperature
>= active
->temperature
) {
807 * If the thermal temperature is greater than the
808 * active threshod, unnecessary to turn off the
809 * the active cooling device.
816 * Turn OFF all cooling devices associated with this
819 for (j
= 0; j
< active
->devices
.count
; j
++)
820 result
= acpi_bus_set_power(active
->devices
.handles
[j
],
825 static void acpi_thermal_check(void *data
)
828 struct acpi_thermal
*tz
= data
;
829 unsigned long sleep_time
= 0;
830 unsigned long timeout_jiffies
= 0;
832 struct acpi_thermal_state state
;
836 printk(KERN_ERR PREFIX
"Invalid (NULL) context\n");
840 /* Check if someone else is already running */
841 if (!mutex_trylock(&tz
->lock
))
846 result
= acpi_thermal_get_temperature(tz
);
853 memset(&tz
->state
, 0, sizeof(tz
->state
));
858 * Compare the current temperature to the trip point values to see
859 * if we've entered one of the thermal policy states. Note that
860 * this function determines when a state is entered, but the
861 * individual policy decides when it is exited (e.g. hysteresis).
863 if (tz
->trips
.critical
.flags
.valid
)
865 (tz
->temperature
>= tz
->trips
.critical
.temperature
);
866 if (tz
->trips
.hot
.flags
.valid
)
867 state
.hot
|= (tz
->temperature
>= tz
->trips
.hot
.temperature
);
868 if (tz
->trips
.passive
.flags
.valid
)
870 (tz
->temperature
>= tz
->trips
.passive
.temperature
);
871 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++)
872 if (tz
->trips
.active
[i
].flags
.valid
)
875 tz
->trips
.active
[i
].temperature
);
880 * Separated from the above check to allow individual policy to
881 * determine when to exit a given state.
884 acpi_thermal_critical(tz
);
886 acpi_thermal_hot(tz
);
888 acpi_thermal_passive(tz
);
890 acpi_thermal_active(tz
);
895 * Again, separated from the above two to allow independent policy
898 tz
->state
.critical
= tz
->trips
.critical
.flags
.enabled
;
899 tz
->state
.hot
= tz
->trips
.hot
.flags
.enabled
;
900 tz
->state
.passive
= tz
->trips
.passive
.flags
.enabled
;
901 tz
->state
.active
= 0;
902 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++)
903 tz
->state
.active
|= tz
->trips
.active
[i
].flags
.enabled
;
906 * Calculate Sleep Time
907 * --------------------
908 * If we're in the passive state, use _TSP's value. Otherwise
909 * use the default polling frequency (e.g. _TZP). If no polling
910 * frequency is specified then we'll wait forever (at least until
911 * a thermal event occurs). Note that _TSP and _TZD values are
912 * given in 1/10th seconds (we must covert to milliseconds).
914 if (tz
->state
.passive
) {
915 sleep_time
= tz
->trips
.passive
.tsp
* 100;
916 timeout_jiffies
= jiffies
+ (HZ
* sleep_time
) / 1000;
917 } else if (tz
->polling_frequency
> 0) {
918 sleep_time
= tz
->polling_frequency
* 100;
919 timeout_jiffies
= round_jiffies(jiffies
+ (HZ
* sleep_time
) / 1000);
922 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "%s: temperature[%lu] sleep[%lu]\n",
923 tz
->name
, tz
->temperature
, sleep_time
));
930 if (timer_pending(&(tz
->timer
)))
931 del_timer(&(tz
->timer
));
933 if (timer_pending(&(tz
->timer
)))
934 mod_timer(&(tz
->timer
), timeout_jiffies
);
936 tz
->timer
.data
= (unsigned long)tz
;
937 tz
->timer
.function
= acpi_thermal_run
;
938 tz
->timer
.expires
= timeout_jiffies
;
939 add_timer(&(tz
->timer
));
943 mutex_unlock(&tz
->lock
);
946 /* sys I/F for generic thermal sysfs support */
947 #define KELVIN_TO_MILLICELSIUS(t) (t * 100 - 273200)
949 static int thermal_get_temp(struct thermal_zone_device
*thermal
, char *buf
)
951 struct acpi_thermal
*tz
= thermal
->devdata
;
957 result
= acpi_thermal_get_temperature(tz
);
961 return sprintf(buf
, "%ld\n", KELVIN_TO_MILLICELSIUS(tz
->temperature
));
964 static const char enabled
[] = "kernel";
965 static const char disabled
[] = "user";
966 static int thermal_get_mode(struct thermal_zone_device
*thermal
,
969 struct acpi_thermal
*tz
= thermal
->devdata
;
974 return sprintf(buf
, "%s\n", tz
->tz_enabled
?
978 static int thermal_set_mode(struct thermal_zone_device
*thermal
,
981 struct acpi_thermal
*tz
= thermal
->devdata
;
988 * enable/disable thermal management from ACPI thermal driver
990 if (!strncmp(buf
, enabled
, sizeof enabled
- 1))
992 else if (!strncmp(buf
, disabled
, sizeof disabled
- 1))
997 if (enable
!= tz
->tz_enabled
) {
998 tz
->tz_enabled
= enable
;
999 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1000 "%s ACPI thermal control\n",
1001 tz
->tz_enabled
? enabled
: disabled
));
1002 acpi_thermal_check(tz
);
1007 static int thermal_get_trip_type(struct thermal_zone_device
*thermal
,
1008 int trip
, char *buf
)
1010 struct acpi_thermal
*tz
= thermal
->devdata
;
1013 if (!tz
|| trip
< 0)
1016 if (tz
->trips
.critical
.flags
.valid
) {
1018 return sprintf(buf
, "critical\n");
1022 if (tz
->trips
.hot
.flags
.valid
) {
1024 return sprintf(buf
, "hot\n");
1028 if (tz
->trips
.passive
.flags
.valid
) {
1030 return sprintf(buf
, "passive\n");
1034 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
&&
1035 tz
->trips
.active
[i
].flags
.valid
; i
++) {
1037 return sprintf(buf
, "active%d\n", i
);
1044 static int thermal_get_trip_temp(struct thermal_zone_device
*thermal
,
1045 int trip
, char *buf
)
1047 struct acpi_thermal
*tz
= thermal
->devdata
;
1050 if (!tz
|| trip
< 0)
1053 if (tz
->trips
.critical
.flags
.valid
) {
1055 return sprintf(buf
, "%ld\n", KELVIN_TO_MILLICELSIUS(
1056 tz
->trips
.critical
.temperature
));
1060 if (tz
->trips
.hot
.flags
.valid
) {
1062 return sprintf(buf
, "%ld\n", KELVIN_TO_MILLICELSIUS(
1063 tz
->trips
.hot
.temperature
));
1067 if (tz
->trips
.passive
.flags
.valid
) {
1069 return sprintf(buf
, "%ld\n", KELVIN_TO_MILLICELSIUS(
1070 tz
->trips
.passive
.temperature
));
1074 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
&&
1075 tz
->trips
.active
[i
].flags
.valid
; i
++) {
1077 return sprintf(buf
, "%ld\n", KELVIN_TO_MILLICELSIUS(
1078 tz
->trips
.active
[i
].temperature
));
1085 static int thermal_get_crit_temp(struct thermal_zone_device
*thermal
,
1086 unsigned long *temperature
) {
1087 struct acpi_thermal
*tz
= thermal
->devdata
;
1089 if (tz
->trips
.critical
.flags
.valid
) {
1090 *temperature
= KELVIN_TO_MILLICELSIUS(
1091 tz
->trips
.critical
.temperature
);
1097 typedef int (*cb
)(struct thermal_zone_device
*, int,
1098 struct thermal_cooling_device
*);
1099 static int acpi_thermal_cooling_device_cb(struct thermal_zone_device
*thermal
,
1100 struct thermal_cooling_device
*cdev
,
1103 struct acpi_device
*device
= cdev
->devdata
;
1104 struct acpi_thermal
*tz
= thermal
->devdata
;
1105 struct acpi_device
*dev
;
1113 if (tz
->trips
.critical
.flags
.valid
)
1116 if (tz
->trips
.hot
.flags
.valid
)
1119 if (tz
->trips
.passive
.flags
.valid
) {
1121 for (i
= 0; i
< tz
->trips
.passive
.devices
.count
;
1123 handle
= tz
->trips
.passive
.devices
.handles
[i
];
1124 status
= acpi_bus_get_device(handle
, &dev
);
1125 if (ACPI_SUCCESS(status
) && (dev
== device
)) {
1126 result
= action(thermal
, trip
, cdev
);
1133 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
1134 if (!tz
->trips
.active
[i
].flags
.valid
)
1138 j
< tz
->trips
.active
[i
].devices
.count
;
1140 handle
= tz
->trips
.active
[i
].devices
.handles
[j
];
1141 status
= acpi_bus_get_device(handle
, &dev
);
1142 if (ACPI_SUCCESS(status
) && (dev
== device
)) {
1143 result
= action(thermal
, trip
, cdev
);
1150 for (i
= 0; i
< tz
->devices
.count
; i
++) {
1151 handle
= tz
->devices
.handles
[i
];
1152 status
= acpi_bus_get_device(handle
, &dev
);
1153 if (ACPI_SUCCESS(status
) && (dev
== device
)) {
1154 result
= action(thermal
, -1, cdev
);
1165 acpi_thermal_bind_cooling_device(struct thermal_zone_device
*thermal
,
1166 struct thermal_cooling_device
*cdev
)
1168 return acpi_thermal_cooling_device_cb(thermal
, cdev
,
1169 thermal_zone_bind_cooling_device
);
1173 acpi_thermal_unbind_cooling_device(struct thermal_zone_device
*thermal
,
1174 struct thermal_cooling_device
*cdev
)
1176 return acpi_thermal_cooling_device_cb(thermal
, cdev
,
1177 thermal_zone_unbind_cooling_device
);
1180 static struct thermal_zone_device_ops acpi_thermal_zone_ops
= {
1181 .bind
= acpi_thermal_bind_cooling_device
,
1182 .unbind
= acpi_thermal_unbind_cooling_device
,
1183 .get_temp
= thermal_get_temp
,
1184 .get_mode
= thermal_get_mode
,
1185 .set_mode
= thermal_set_mode
,
1186 .get_trip_type
= thermal_get_trip_type
,
1187 .get_trip_temp
= thermal_get_trip_temp
,
1188 .get_crit_temp
= thermal_get_crit_temp
,
1191 static int acpi_thermal_register_thermal_zone(struct acpi_thermal
*tz
)
1198 if (tz
->trips
.critical
.flags
.valid
)
1201 if (tz
->trips
.hot
.flags
.valid
)
1204 if (tz
->trips
.passive
.flags
.valid
)
1207 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
&&
1208 tz
->trips
.active
[i
].flags
.valid
; i
++, trips
++);
1209 tz
->thermal_zone
= thermal_zone_device_register("acpitz",
1210 trips
, tz
, &acpi_thermal_zone_ops
);
1211 if (IS_ERR(tz
->thermal_zone
))
1214 result
= sysfs_create_link(&tz
->device
->dev
.kobj
,
1215 &tz
->thermal_zone
->device
.kobj
, "thermal_zone");
1219 result
= sysfs_create_link(&tz
->thermal_zone
->device
.kobj
,
1220 &tz
->device
->dev
.kobj
, "device");
1224 status
= acpi_attach_data(tz
->device
->handle
,
1225 acpi_bus_private_data_handler
,
1227 if (ACPI_FAILURE(status
)) {
1228 printk(KERN_ERR PREFIX
1229 "Error attaching device data\n");
1235 dev_info(&tz
->device
->dev
, "registered as thermal_zone%d\n",
1236 tz
->thermal_zone
->id
);
1240 static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal
*tz
)
1242 sysfs_remove_link(&tz
->device
->dev
.kobj
, "thermal_zone");
1243 sysfs_remove_link(&tz
->thermal_zone
->device
.kobj
, "device");
1244 thermal_zone_device_unregister(tz
->thermal_zone
);
1245 tz
->thermal_zone
= NULL
;
1246 acpi_detach_data(tz
->device
->handle
, acpi_bus_private_data_handler
);
1250 /* --------------------------------------------------------------------------
1251 FS Interface (/proc)
1252 -------------------------------------------------------------------------- */
1254 static struct proc_dir_entry
*acpi_thermal_dir
;
1256 static int acpi_thermal_state_seq_show(struct seq_file
*seq
, void *offset
)
1258 struct acpi_thermal
*tz
= seq
->private;
1264 seq_puts(seq
, "state: ");
1266 if (!tz
->state
.critical
&& !tz
->state
.hot
&& !tz
->state
.passive
1267 && !tz
->state
.active
)
1268 seq_puts(seq
, "ok\n");
1270 if (tz
->state
.critical
)
1271 seq_puts(seq
, "critical ");
1273 seq_puts(seq
, "hot ");
1274 if (tz
->state
.passive
)
1275 seq_puts(seq
, "passive ");
1276 if (tz
->state
.active
)
1277 seq_printf(seq
, "active[%d]", tz
->state
.active_index
);
1278 seq_puts(seq
, "\n");
1285 static int acpi_thermal_state_open_fs(struct inode
*inode
, struct file
*file
)
1287 return single_open(file
, acpi_thermal_state_seq_show
, PDE(inode
)->data
);
1290 static int acpi_thermal_temp_seq_show(struct seq_file
*seq
, void *offset
)
1293 struct acpi_thermal
*tz
= seq
->private;
1299 result
= acpi_thermal_get_temperature(tz
);
1303 seq_printf(seq
, "temperature: %ld C\n",
1304 KELVIN_TO_CELSIUS(tz
->temperature
));
1310 static int acpi_thermal_temp_open_fs(struct inode
*inode
, struct file
*file
)
1312 return single_open(file
, acpi_thermal_temp_seq_show
, PDE(inode
)->data
);
1315 static int acpi_thermal_trip_seq_show(struct seq_file
*seq
, void *offset
)
1317 struct acpi_thermal
*tz
= seq
->private;
1318 struct acpi_device
*device
;
1328 if (tz
->trips
.critical
.flags
.valid
)
1329 seq_printf(seq
, "critical (S5): %ld C%s",
1330 KELVIN_TO_CELSIUS(tz
->trips
.critical
.temperature
),
1331 nocrt
? " <disabled>\n" : "\n");
1333 if (tz
->trips
.hot
.flags
.valid
)
1334 seq_printf(seq
, "hot (S4): %ld C%s",
1335 KELVIN_TO_CELSIUS(tz
->trips
.hot
.temperature
),
1336 nocrt
? " <disabled>\n" : "\n");
1338 if (tz
->trips
.passive
.flags
.valid
) {
1340 "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
1341 KELVIN_TO_CELSIUS(tz
->trips
.passive
.temperature
),
1342 tz
->trips
.passive
.tc1
, tz
->trips
.passive
.tc2
,
1343 tz
->trips
.passive
.tsp
);
1344 for (j
= 0; j
< tz
->trips
.passive
.devices
.count
; j
++) {
1345 status
= acpi_bus_get_device(tz
->trips
.passive
.devices
.
1346 handles
[j
], &device
);
1347 seq_printf(seq
, "%4.4s ", status
? "" :
1348 acpi_device_bid(device
));
1350 seq_puts(seq
, "\n");
1353 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
1354 if (!(tz
->trips
.active
[i
].flags
.valid
))
1356 seq_printf(seq
, "active[%d]: %ld C: devices=",
1358 KELVIN_TO_CELSIUS(tz
->trips
.active
[i
].temperature
));
1359 for (j
= 0; j
< tz
->trips
.active
[i
].devices
.count
; j
++){
1360 status
= acpi_bus_get_device(tz
->trips
.active
[i
].
1363 seq_printf(seq
, "%4.4s ", status
? "" :
1364 acpi_device_bid(device
));
1366 seq_puts(seq
, "\n");
1373 static int acpi_thermal_trip_open_fs(struct inode
*inode
, struct file
*file
)
1375 return single_open(file
, acpi_thermal_trip_seq_show
, PDE(inode
)->data
);
1378 static int acpi_thermal_cooling_seq_show(struct seq_file
*seq
, void *offset
)
1380 struct acpi_thermal
*tz
= seq
->private;
1386 if (!tz
->flags
.cooling_mode
)
1387 seq_puts(seq
, "<setting not supported>\n");
1389 seq_puts(seq
, "0 - Active; 1 - Passive\n");
1395 static int acpi_thermal_cooling_open_fs(struct inode
*inode
, struct file
*file
)
1397 return single_open(file
, acpi_thermal_cooling_seq_show
,
1402 acpi_thermal_write_cooling_mode(struct file
*file
,
1403 const char __user
* buffer
,
1404 size_t count
, loff_t
* ppos
)
1406 struct seq_file
*m
= file
->private_data
;
1407 struct acpi_thermal
*tz
= m
->private;
1409 char mode_string
[12] = { '\0' };
1412 if (!tz
|| (count
> sizeof(mode_string
) - 1))
1415 if (!tz
->flags
.cooling_mode
)
1418 if (copy_from_user(mode_string
, buffer
, count
))
1421 mode_string
[count
] = '\0';
1423 result
= acpi_thermal_set_cooling_mode(tz
,
1424 simple_strtoul(mode_string
, NULL
,
1429 acpi_thermal_check(tz
);
1434 static int acpi_thermal_polling_seq_show(struct seq_file
*seq
, void *offset
)
1436 struct acpi_thermal
*tz
= seq
->private;
1442 if (!tz
->polling_frequency
) {
1443 seq_puts(seq
, "<polling disabled>\n");
1447 seq_printf(seq
, "polling frequency: %lu seconds\n",
1448 (tz
->polling_frequency
/ 10));
1454 static int acpi_thermal_polling_open_fs(struct inode
*inode
, struct file
*file
)
1456 return single_open(file
, acpi_thermal_polling_seq_show
,
1461 acpi_thermal_write_polling(struct file
*file
,
1462 const char __user
* buffer
,
1463 size_t count
, loff_t
* ppos
)
1465 struct seq_file
*m
= file
->private_data
;
1466 struct acpi_thermal
*tz
= m
->private;
1468 char polling_string
[12] = { '\0' };
1472 if (!tz
|| (count
> sizeof(polling_string
) - 1))
1475 if (copy_from_user(polling_string
, buffer
, count
))
1478 polling_string
[count
] = '\0';
1480 seconds
= simple_strtoul(polling_string
, NULL
, 0);
1482 result
= acpi_thermal_set_polling(tz
, seconds
);
1486 acpi_thermal_check(tz
);
1491 static int acpi_thermal_add_fs(struct acpi_device
*device
)
1493 struct proc_dir_entry
*entry
= NULL
;
1496 if (!acpi_device_dir(device
)) {
1497 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
1499 if (!acpi_device_dir(device
))
1501 acpi_device_dir(device
)->owner
= THIS_MODULE
;
1505 entry
= proc_create_data(ACPI_THERMAL_FILE_STATE
,
1506 S_IRUGO
, acpi_device_dir(device
),
1507 &acpi_thermal_state_fops
,
1508 acpi_driver_data(device
));
1512 /* 'temperature' [R] */
1513 entry
= proc_create_data(ACPI_THERMAL_FILE_TEMPERATURE
,
1514 S_IRUGO
, acpi_device_dir(device
),
1515 &acpi_thermal_temp_fops
,
1516 acpi_driver_data(device
));
1520 /* 'trip_points' [R] */
1521 entry
= proc_create_data(ACPI_THERMAL_FILE_TRIP_POINTS
,
1523 acpi_device_dir(device
),
1524 &acpi_thermal_trip_fops
,
1525 acpi_driver_data(device
));
1529 /* 'cooling_mode' [R/W] */
1530 entry
= proc_create_data(ACPI_THERMAL_FILE_COOLING_MODE
,
1531 S_IFREG
| S_IRUGO
| S_IWUSR
,
1532 acpi_device_dir(device
),
1533 &acpi_thermal_cooling_fops
,
1534 acpi_driver_data(device
));
1538 /* 'polling_frequency' [R/W] */
1539 entry
= proc_create_data(ACPI_THERMAL_FILE_POLLING_FREQ
,
1540 S_IFREG
| S_IRUGO
| S_IWUSR
,
1541 acpi_device_dir(device
),
1542 &acpi_thermal_polling_fops
,
1543 acpi_driver_data(device
));
1549 static int acpi_thermal_remove_fs(struct acpi_device
*device
)
1552 if (acpi_device_dir(device
)) {
1553 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ
,
1554 acpi_device_dir(device
));
1555 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE
,
1556 acpi_device_dir(device
));
1557 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS
,
1558 acpi_device_dir(device
));
1559 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE
,
1560 acpi_device_dir(device
));
1561 remove_proc_entry(ACPI_THERMAL_FILE_STATE
,
1562 acpi_device_dir(device
));
1563 remove_proc_entry(acpi_device_bid(device
), acpi_thermal_dir
);
1564 acpi_device_dir(device
) = NULL
;
1570 /* --------------------------------------------------------------------------
1572 -------------------------------------------------------------------------- */
1574 static void acpi_thermal_notify(acpi_handle handle
, u32 event
, void *data
)
1576 struct acpi_thermal
*tz
= data
;
1577 struct acpi_device
*device
= NULL
;
1583 device
= tz
->device
;
1586 case ACPI_THERMAL_NOTIFY_TEMPERATURE
:
1587 acpi_thermal_check(tz
);
1589 case ACPI_THERMAL_NOTIFY_THRESHOLDS
:
1590 acpi_thermal_trips_update(tz
, ACPI_TRIPS_REFRESH_THRESHOLDS
);
1591 acpi_thermal_check(tz
);
1592 acpi_bus_generate_proc_event(device
, event
, 0);
1593 acpi_bus_generate_netlink_event(device
->pnp
.device_class
,
1594 dev_name(&device
->dev
), event
, 0);
1596 case ACPI_THERMAL_NOTIFY_DEVICES
:
1597 acpi_thermal_trips_update(tz
, ACPI_TRIPS_REFRESH_DEVICES
);
1598 acpi_thermal_check(tz
);
1599 acpi_bus_generate_proc_event(device
, event
, 0);
1600 acpi_bus_generate_netlink_event(device
->pnp
.device_class
,
1601 dev_name(&device
->dev
), event
, 0);
1604 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1605 "Unsupported event [0x%x]\n", event
));
1612 static int acpi_thermal_get_info(struct acpi_thermal
*tz
)
1620 /* Get temperature [_TMP] (required) */
1621 result
= acpi_thermal_get_temperature(tz
);
1625 /* Get trip points [_CRT, _PSV, etc.] (required) */
1626 result
= acpi_thermal_get_trip_points(tz
);
1630 /* Set the cooling mode [_SCP] to active cooling (default) */
1631 result
= acpi_thermal_set_cooling_mode(tz
, ACPI_THERMAL_MODE_ACTIVE
);
1633 tz
->flags
.cooling_mode
= 1;
1635 /* Get default polling frequency [_TZP] (optional) */
1637 tz
->polling_frequency
= tzp
;
1639 acpi_thermal_get_polling_frequency(tz
);
1644 static int acpi_thermal_add(struct acpi_device
*device
)
1647 acpi_status status
= AE_OK
;
1648 struct acpi_thermal
*tz
= NULL
;
1654 tz
= kzalloc(sizeof(struct acpi_thermal
), GFP_KERNEL
);
1658 tz
->device
= device
;
1659 strcpy(tz
->name
, device
->pnp
.bus_id
);
1660 strcpy(acpi_device_name(device
), ACPI_THERMAL_DEVICE_NAME
);
1661 strcpy(acpi_device_class(device
), ACPI_THERMAL_CLASS
);
1662 device
->driver_data
= tz
;
1663 mutex_init(&tz
->lock
);
1666 result
= acpi_thermal_get_info(tz
);
1670 result
= acpi_thermal_register_thermal_zone(tz
);
1674 result
= acpi_thermal_add_fs(device
);
1676 goto unregister_thermal_zone
;
1678 init_timer(&tz
->timer
);
1680 acpi_thermal_active_off(tz
);
1682 acpi_thermal_check(tz
);
1684 status
= acpi_install_notify_handler(device
->handle
,
1686 acpi_thermal_notify
, tz
);
1687 if (ACPI_FAILURE(status
)) {
1692 printk(KERN_INFO PREFIX
"%s [%s] (%ld C)\n",
1693 acpi_device_name(device
), acpi_device_bid(device
),
1694 KELVIN_TO_CELSIUS(tz
->temperature
));
1698 acpi_thermal_remove_fs(device
);
1699 unregister_thermal_zone
:
1700 thermal_zone_device_unregister(tz
->thermal_zone
);
1707 static int acpi_thermal_remove(struct acpi_device
*device
, int type
)
1709 acpi_status status
= AE_OK
;
1710 struct acpi_thermal
*tz
= NULL
;
1713 if (!device
|| !acpi_driver_data(device
))
1716 tz
= acpi_driver_data(device
);
1718 /* avoid timer adding new defer task */
1720 /* wait for running timer (on other CPUs) finish */
1721 del_timer_sync(&(tz
->timer
));
1722 /* synchronize deferred task */
1723 acpi_os_wait_events_complete(NULL
);
1724 /* deferred task may reinsert timer */
1725 del_timer_sync(&(tz
->timer
));
1727 status
= acpi_remove_notify_handler(device
->handle
,
1729 acpi_thermal_notify
);
1731 /* Terminate policy */
1732 if (tz
->trips
.passive
.flags
.valid
&& tz
->trips
.passive
.flags
.enabled
) {
1733 tz
->trips
.passive
.flags
.enabled
= 0;
1734 acpi_thermal_passive(tz
);
1736 if (tz
->trips
.active
[0].flags
.valid
1737 && tz
->trips
.active
[0].flags
.enabled
) {
1738 tz
->trips
.active
[0].flags
.enabled
= 0;
1739 acpi_thermal_active(tz
);
1742 acpi_thermal_remove_fs(device
);
1743 acpi_thermal_unregister_thermal_zone(tz
);
1744 mutex_destroy(&tz
->lock
);
1749 static int acpi_thermal_resume(struct acpi_device
*device
)
1751 struct acpi_thermal
*tz
= NULL
;
1752 int i
, j
, power_state
, result
;
1755 if (!device
|| !acpi_driver_data(device
))
1758 tz
= acpi_driver_data(device
);
1760 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
1761 if (!(&tz
->trips
.active
[i
]))
1763 if (!tz
->trips
.active
[i
].flags
.valid
)
1765 tz
->trips
.active
[i
].flags
.enabled
= 1;
1766 for (j
= 0; j
< tz
->trips
.active
[i
].devices
.count
; j
++) {
1767 result
= acpi_bus_get_power(tz
->trips
.active
[i
].devices
.
1768 handles
[j
], &power_state
);
1769 if (result
|| (power_state
!= ACPI_STATE_D0
)) {
1770 tz
->trips
.active
[i
].flags
.enabled
= 0;
1774 tz
->state
.active
|= tz
->trips
.active
[i
].flags
.enabled
;
1777 acpi_thermal_check(tz
);
1782 static int thermal_act(const struct dmi_system_id
*d
) {
1785 printk(KERN_NOTICE
"ACPI: %s detected: "
1786 "disabling all active thermal trip points\n", d
->ident
);
1791 static int thermal_nocrt(const struct dmi_system_id
*d
) {
1793 printk(KERN_NOTICE
"ACPI: %s detected: "
1794 "disabling all critical thermal trip point actions.\n", d
->ident
);
1798 static int thermal_tzp(const struct dmi_system_id
*d
) {
1801 printk(KERN_NOTICE
"ACPI: %s detected: "
1802 "enabling thermal zone polling\n", d
->ident
);
1803 tzp
= 300; /* 300 dS = 30 Seconds */
1807 static int thermal_psv(const struct dmi_system_id
*d
) {
1810 printk(KERN_NOTICE
"ACPI: %s detected: "
1811 "disabling all passive thermal trip points\n", d
->ident
);
1817 static struct dmi_system_id thermal_dmi_table
[] __initdata
= {
1819 * Award BIOS on this AOpen makes thermal control almost worthless.
1820 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1823 .callback
= thermal_act
,
1824 .ident
= "AOpen i915GMm-HFS",
1826 DMI_MATCH(DMI_BOARD_VENDOR
, "AOpen"),
1827 DMI_MATCH(DMI_BOARD_NAME
, "i915GMm-HFS"),
1831 .callback
= thermal_psv
,
1832 .ident
= "AOpen i915GMm-HFS",
1834 DMI_MATCH(DMI_BOARD_VENDOR
, "AOpen"),
1835 DMI_MATCH(DMI_BOARD_NAME
, "i915GMm-HFS"),
1839 .callback
= thermal_tzp
,
1840 .ident
= "AOpen i915GMm-HFS",
1842 DMI_MATCH(DMI_BOARD_VENDOR
, "AOpen"),
1843 DMI_MATCH(DMI_BOARD_NAME
, "i915GMm-HFS"),
1847 .callback
= thermal_nocrt
,
1848 .ident
= "Gigabyte GA-7ZX",
1850 DMI_MATCH(DMI_BOARD_VENDOR
, "Gigabyte Technology Co., Ltd."),
1851 DMI_MATCH(DMI_BOARD_NAME
, "7ZX"),
1857 static int __init
acpi_thermal_init(void)
1861 dmi_check_system(thermal_dmi_table
);
1864 printk(KERN_NOTICE
"ACPI: thermal control disabled\n");
1867 acpi_thermal_dir
= proc_mkdir(ACPI_THERMAL_CLASS
, acpi_root_dir
);
1868 if (!acpi_thermal_dir
)
1870 acpi_thermal_dir
->owner
= THIS_MODULE
;
1872 result
= acpi_bus_register_driver(&acpi_thermal_driver
);
1874 remove_proc_entry(ACPI_THERMAL_CLASS
, acpi_root_dir
);
1881 static void __exit
acpi_thermal_exit(void)
1884 acpi_bus_unregister_driver(&acpi_thermal_driver
);
1886 remove_proc_entry(ACPI_THERMAL_CLASS
, acpi_root_dir
);
1891 module_init(acpi_thermal_init
);
1892 module_exit(acpi_thermal_exit
);