2 * acpi_thermal.c - ACPI Thermal Zone Driver ($Revision: 41 $)
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 * This driver fully implements the ACPI thermal policy as described in the
26 * ACPI 2.0 Specification.
28 * TBD: 1. Implement passive cooling hysteresis.
29 * 2. Enhance passive cooling (CPU) states/limit interface to support
30 * concepts of 'multiple limiters', upper/lower limits, etc.
34 #include <linux/kernel.h>
35 #include <linux/module.h>
36 #include <linux/init.h>
37 #include <linux/types.h>
38 #include <linux/proc_fs.h>
39 #include <linux/timer.h>
40 #include <linux/jiffies.h>
41 #include <linux/kmod.h>
42 #include <linux/seq_file.h>
43 #include <linux/reboot.h>
44 #include <asm/uaccess.h>
46 #include <acpi/acpi_bus.h>
47 #include <acpi/acpi_drivers.h>
49 #define ACPI_THERMAL_COMPONENT 0x04000000
50 #define ACPI_THERMAL_CLASS "thermal_zone"
51 #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
52 #define ACPI_THERMAL_FILE_STATE "state"
53 #define ACPI_THERMAL_FILE_TEMPERATURE "temperature"
54 #define ACPI_THERMAL_FILE_TRIP_POINTS "trip_points"
55 #define ACPI_THERMAL_FILE_COOLING_MODE "cooling_mode"
56 #define ACPI_THERMAL_FILE_POLLING_FREQ "polling_frequency"
57 #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80
58 #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81
59 #define ACPI_THERMAL_NOTIFY_DEVICES 0x82
60 #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0
61 #define ACPI_THERMAL_NOTIFY_HOT 0xF1
62 #define ACPI_THERMAL_MODE_ACTIVE 0x00
64 #define ACPI_THERMAL_MAX_ACTIVE 10
65 #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
67 #define KELVIN_TO_CELSIUS(t) (long)(((long)t-2732>=0) ? ((long)t-2732+5)/10 : ((long)t-2732-5)/10)
68 #define CELSIUS_TO_KELVIN(t) ((t+273)*10)
70 #define _COMPONENT ACPI_THERMAL_COMPONENT
71 ACPI_MODULE_NAME("thermal");
73 MODULE_AUTHOR("Paul Diefenbaugh");
74 MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
75 MODULE_LICENSE("GPL");
78 module_param(tzp
, int, 0);
79 MODULE_PARM_DESC(tzp
, "Thermal zone polling frequency, in 1/10 seconds.\n");
81 static int acpi_thermal_add(struct acpi_device
*device
);
82 static int acpi_thermal_remove(struct acpi_device
*device
, int type
);
83 static int acpi_thermal_resume(struct acpi_device
*device
);
84 static int acpi_thermal_state_open_fs(struct inode
*inode
, struct file
*file
);
85 static int acpi_thermal_temp_open_fs(struct inode
*inode
, struct file
*file
);
86 static int acpi_thermal_trip_open_fs(struct inode
*inode
, struct file
*file
);
87 static int acpi_thermal_cooling_open_fs(struct inode
*inode
, struct file
*file
);
88 static ssize_t
acpi_thermal_write_cooling_mode(struct file
*,
89 const char __user
*, size_t,
91 static int acpi_thermal_polling_open_fs(struct inode
*inode
, struct file
*file
);
92 static ssize_t
acpi_thermal_write_polling(struct file
*, const char __user
*,
95 static const struct acpi_device_id thermal_device_ids
[] = {
96 {ACPI_THERMAL_HID
, 0},
99 MODULE_DEVICE_TABLE(acpi
, thermal_device_ids
);
101 static struct acpi_driver acpi_thermal_driver
= {
103 .class = ACPI_THERMAL_CLASS
,
104 .ids
= thermal_device_ids
,
106 .add
= acpi_thermal_add
,
107 .remove
= acpi_thermal_remove
,
108 .resume
= acpi_thermal_resume
,
112 struct acpi_thermal_state
{
121 struct acpi_thermal_state_flags
{
127 struct acpi_thermal_critical
{
128 struct acpi_thermal_state_flags flags
;
129 unsigned long temperature
;
132 struct acpi_thermal_hot
{
133 struct acpi_thermal_state_flags flags
;
134 unsigned long temperature
;
137 struct acpi_thermal_passive
{
138 struct acpi_thermal_state_flags flags
;
139 unsigned long temperature
;
143 struct acpi_handle_list devices
;
146 struct acpi_thermal_active
{
147 struct acpi_thermal_state_flags flags
;
148 unsigned long temperature
;
149 struct acpi_handle_list devices
;
152 struct acpi_thermal_trips
{
153 struct acpi_thermal_critical critical
;
154 struct acpi_thermal_hot hot
;
155 struct acpi_thermal_passive passive
;
156 struct acpi_thermal_active active
[ACPI_THERMAL_MAX_ACTIVE
];
159 struct acpi_thermal_flags
{
160 u8 cooling_mode
:1; /* _SCP */
161 u8 devices
:1; /* _TZD */
165 struct acpi_thermal
{
166 struct acpi_device
* device
;
168 unsigned long temperature
;
169 unsigned long last_temperature
;
170 unsigned long polling_frequency
;
172 struct acpi_thermal_flags flags
;
173 struct acpi_thermal_state state
;
174 struct acpi_thermal_trips trips
;
175 struct acpi_handle_list devices
;
176 struct timer_list timer
;
179 static const struct file_operations acpi_thermal_state_fops
= {
180 .open
= acpi_thermal_state_open_fs
,
183 .release
= single_release
,
186 static const struct file_operations acpi_thermal_temp_fops
= {
187 .open
= acpi_thermal_temp_open_fs
,
190 .release
= single_release
,
193 static const struct file_operations acpi_thermal_trip_fops
= {
194 .open
= acpi_thermal_trip_open_fs
,
197 .release
= single_release
,
200 static const struct file_operations acpi_thermal_cooling_fops
= {
201 .open
= acpi_thermal_cooling_open_fs
,
203 .write
= acpi_thermal_write_cooling_mode
,
205 .release
= single_release
,
208 static const struct file_operations acpi_thermal_polling_fops
= {
209 .open
= acpi_thermal_polling_open_fs
,
211 .write
= acpi_thermal_write_polling
,
213 .release
= single_release
,
216 /* --------------------------------------------------------------------------
217 Thermal Zone Management
218 -------------------------------------------------------------------------- */
220 static int acpi_thermal_get_temperature(struct acpi_thermal
*tz
)
222 acpi_status status
= AE_OK
;
228 tz
->last_temperature
= tz
->temperature
;
231 acpi_evaluate_integer(tz
->device
->handle
, "_TMP", NULL
, &tz
->temperature
);
232 if (ACPI_FAILURE(status
))
235 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Temperature is %lu dK\n",
241 static int acpi_thermal_get_polling_frequency(struct acpi_thermal
*tz
)
243 acpi_status status
= AE_OK
;
250 acpi_evaluate_integer(tz
->device
->handle
, "_TZP", NULL
,
251 &tz
->polling_frequency
);
252 if (ACPI_FAILURE(status
))
255 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Polling frequency is %lu dS\n",
256 tz
->polling_frequency
));
261 static int acpi_thermal_set_polling(struct acpi_thermal
*tz
, int seconds
)
267 tz
->polling_frequency
= seconds
* 10; /* Convert value to deci-seconds */
269 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
270 "Polling frequency set to %lu seconds\n",
271 tz
->polling_frequency
/10));
276 static int acpi_thermal_set_cooling_mode(struct acpi_thermal
*tz
, int mode
)
278 acpi_status status
= AE_OK
;
279 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
280 struct acpi_object_list arg_list
= { 1, &arg0
};
281 acpi_handle handle
= NULL
;
287 status
= acpi_get_handle(tz
->device
->handle
, "_SCP", &handle
);
288 if (ACPI_FAILURE(status
)) {
289 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "_SCP not present\n"));
293 arg0
.integer
.value
= mode
;
295 status
= acpi_evaluate_object(handle
, NULL
, &arg_list
, NULL
);
296 if (ACPI_FAILURE(status
))
302 static int acpi_thermal_get_trip_points(struct acpi_thermal
*tz
)
304 acpi_status status
= AE_OK
;
311 /* Critical Shutdown (required) */
313 status
= acpi_evaluate_integer(tz
->device
->handle
, "_CRT", NULL
,
314 &tz
->trips
.critical
.temperature
);
315 if (ACPI_FAILURE(status
)) {
316 tz
->trips
.critical
.flags
.valid
= 0;
317 ACPI_EXCEPTION((AE_INFO
, status
, "No critical threshold"));
320 tz
->trips
.critical
.flags
.valid
= 1;
321 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
322 "Found critical threshold [%lu]\n",
323 tz
->trips
.critical
.temperature
));
326 /* Critical Sleep (optional) */
329 acpi_evaluate_integer(tz
->device
->handle
, "_HOT", NULL
,
330 &tz
->trips
.hot
.temperature
);
331 if (ACPI_FAILURE(status
)) {
332 tz
->trips
.hot
.flags
.valid
= 0;
333 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "No hot threshold\n"));
335 tz
->trips
.hot
.flags
.valid
= 1;
336 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found hot threshold [%lu]\n",
337 tz
->trips
.hot
.temperature
));
340 /* Passive: Processors (optional) */
343 acpi_evaluate_integer(tz
->device
->handle
, "_PSV", NULL
,
344 &tz
->trips
.passive
.temperature
);
345 if (ACPI_FAILURE(status
)) {
346 tz
->trips
.passive
.flags
.valid
= 0;
347 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "No passive threshold\n"));
349 tz
->trips
.passive
.flags
.valid
= 1;
352 acpi_evaluate_integer(tz
->device
->handle
, "_TC1", NULL
,
353 &tz
->trips
.passive
.tc1
);
354 if (ACPI_FAILURE(status
))
355 tz
->trips
.passive
.flags
.valid
= 0;
358 acpi_evaluate_integer(tz
->device
->handle
, "_TC2", NULL
,
359 &tz
->trips
.passive
.tc2
);
360 if (ACPI_FAILURE(status
))
361 tz
->trips
.passive
.flags
.valid
= 0;
364 acpi_evaluate_integer(tz
->device
->handle
, "_TSP", NULL
,
365 &tz
->trips
.passive
.tsp
);
366 if (ACPI_FAILURE(status
))
367 tz
->trips
.passive
.flags
.valid
= 0;
370 acpi_evaluate_reference(tz
->device
->handle
, "_PSL", NULL
,
371 &tz
->trips
.passive
.devices
);
372 if (ACPI_FAILURE(status
))
373 tz
->trips
.passive
.flags
.valid
= 0;
375 if (!tz
->trips
.passive
.flags
.valid
)
376 printk(KERN_WARNING PREFIX
"Invalid passive threshold\n");
378 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
379 "Found passive threshold [%lu]\n",
380 tz
->trips
.passive
.temperature
));
383 /* Active: Fans, etc. (optional) */
385 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
387 char name
[5] = { '_', 'A', 'C', ('0' + i
), '\0' };
390 acpi_evaluate_integer(tz
->device
->handle
, name
, NULL
,
391 &tz
->trips
.active
[i
].temperature
);
392 if (ACPI_FAILURE(status
))
397 acpi_evaluate_reference(tz
->device
->handle
, name
, NULL
,
398 &tz
->trips
.active
[i
].devices
);
399 if (ACPI_SUCCESS(status
)) {
400 tz
->trips
.active
[i
].flags
.valid
= 1;
401 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
402 "Found active threshold [%d]:[%lu]\n",
403 i
, tz
->trips
.active
[i
].temperature
));
405 ACPI_EXCEPTION((AE_INFO
, status
,
406 "Invalid active threshold [%d]", i
));
412 static int acpi_thermal_get_devices(struct acpi_thermal
*tz
)
414 acpi_status status
= AE_OK
;
421 acpi_evaluate_reference(tz
->device
->handle
, "_TZD", NULL
, &tz
->devices
);
422 if (ACPI_FAILURE(status
))
428 static int acpi_thermal_critical(struct acpi_thermal
*tz
)
430 if (!tz
|| !tz
->trips
.critical
.flags
.valid
)
433 if (tz
->temperature
>= tz
->trips
.critical
.temperature
) {
434 printk(KERN_WARNING PREFIX
"Critical trip point\n");
435 tz
->trips
.critical
.flags
.enabled
= 1;
436 } else if (tz
->trips
.critical
.flags
.enabled
)
437 tz
->trips
.critical
.flags
.enabled
= 0;
440 "Critical temperature reached (%ld C), shutting down.\n",
441 KELVIN_TO_CELSIUS(tz
->temperature
));
442 acpi_bus_generate_event(tz
->device
, ACPI_THERMAL_NOTIFY_CRITICAL
,
443 tz
->trips
.critical
.flags
.enabled
);
445 orderly_poweroff(true);
450 static int acpi_thermal_hot(struct acpi_thermal
*tz
)
452 if (!tz
|| !tz
->trips
.hot
.flags
.valid
)
455 if (tz
->temperature
>= tz
->trips
.hot
.temperature
) {
456 printk(KERN_WARNING PREFIX
"Hot trip point\n");
457 tz
->trips
.hot
.flags
.enabled
= 1;
458 } else if (tz
->trips
.hot
.flags
.enabled
)
459 tz
->trips
.hot
.flags
.enabled
= 0;
461 acpi_bus_generate_event(tz
->device
, ACPI_THERMAL_NOTIFY_HOT
,
462 tz
->trips
.hot
.flags
.enabled
);
464 /* TBD: Call user-mode "sleep(S4)" function */
469 static void acpi_thermal_passive(struct acpi_thermal
*tz
)
472 struct acpi_thermal_passive
*passive
= NULL
;
477 if (!tz
|| !tz
->trips
.passive
.flags
.valid
)
480 passive
= &(tz
->trips
.passive
);
485 * Calculate the thermal trend (using the passive cooling equation)
486 * and modify the performance limit for all passive cooling devices
487 * accordingly. Note that we assume symmetry.
489 if (tz
->temperature
>= passive
->temperature
) {
491 (passive
->tc1
* (tz
->temperature
- tz
->last_temperature
)) +
492 (passive
->tc2
* (tz
->temperature
- passive
->temperature
));
493 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
494 "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
495 trend
, passive
->tc1
, tz
->temperature
,
496 tz
->last_temperature
, passive
->tc2
,
497 tz
->temperature
, passive
->temperature
));
498 passive
->flags
.enabled
= 1;
501 for (i
= 0; i
< passive
->devices
.count
; i
++)
502 acpi_processor_set_thermal_limit(passive
->
505 ACPI_PROCESSOR_LIMIT_INCREMENT
);
507 else if (trend
< 0) {
508 for (i
= 0; i
< passive
->devices
.count
; i
++)
510 * assume that we are on highest
511 * freq/lowest thrott and can leave
512 * passive mode, even in error case
514 if (!acpi_processor_set_thermal_limit
515 (passive
->devices
.handles
[i
],
516 ACPI_PROCESSOR_LIMIT_DECREMENT
))
519 * Leave cooling mode, even if the temp might
520 * higher than trip point This is because some
521 * machines might have long thermal polling
522 * frequencies (tsp) defined. We will fall back
523 * into passive mode in next cycle (probably quicker)
526 passive
->flags
.enabled
= 0;
527 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
528 "Disabling passive cooling, still above threshold,"
529 " but we are cooling down\n"));
538 * Implement passive cooling hysteresis to slowly increase performance
539 * and avoid thrashing around the passive trip point. Note that we
542 if (!passive
->flags
.enabled
)
544 for (i
= 0; i
< passive
->devices
.count
; i
++)
545 if (!acpi_processor_set_thermal_limit
546 (passive
->devices
.handles
[i
],
547 ACPI_PROCESSOR_LIMIT_DECREMENT
))
550 passive
->flags
.enabled
= 0;
551 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
552 "Disabling passive cooling (zone is cool)\n"));
556 static void acpi_thermal_active(struct acpi_thermal
*tz
)
559 struct acpi_thermal_active
*active
= NULL
;
562 unsigned long maxtemp
= 0;
568 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
569 active
= &(tz
->trips
.active
[i
]);
570 if (!active
|| !active
->flags
.valid
)
572 if (tz
->temperature
>= active
->temperature
) {
576 * If not already enabled, turn ON all cooling devices
577 * associated with this active threshold.
579 if (active
->temperature
> maxtemp
)
580 tz
->state
.active_index
= i
;
581 maxtemp
= active
->temperature
;
582 if (active
->flags
.enabled
)
584 for (j
= 0; j
< active
->devices
.count
; j
++) {
586 acpi_bus_set_power(active
->devices
.
590 printk(KERN_WARNING PREFIX
591 "Unable to turn cooling device [%p] 'on'\n",
596 active
->flags
.enabled
= 1;
597 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
598 "Cooling device [%p] now 'on'\n",
599 active
->devices
.handles
[j
]));
603 if (!active
->flags
.enabled
)
608 * Turn OFF all cooling devices associated with this
611 for (j
= 0; j
< active
->devices
.count
; j
++) {
612 result
= acpi_bus_set_power(active
->devices
.handles
[j
],
615 printk(KERN_WARNING PREFIX
616 "Unable to turn cooling device [%p] 'off'\n",
617 active
->devices
.handles
[j
]);
620 active
->flags
.enabled
= 0;
621 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
622 "Cooling device [%p] now 'off'\n",
623 active
->devices
.handles
[j
]));
628 static void acpi_thermal_check(void *context
);
630 static void acpi_thermal_run(unsigned long data
)
632 struct acpi_thermal
*tz
= (struct acpi_thermal
*)data
;
634 acpi_os_execute(OSL_GPE_HANDLER
, acpi_thermal_check
, (void *)data
);
637 static void acpi_thermal_check(void *data
)
640 struct acpi_thermal
*tz
= data
;
641 unsigned long sleep_time
= 0;
643 struct acpi_thermal_state state
;
647 printk(KERN_ERR PREFIX
"Invalid (NULL) context\n");
653 result
= acpi_thermal_get_temperature(tz
);
657 memset(&tz
->state
, 0, sizeof(tz
->state
));
662 * Compare the current temperature to the trip point values to see
663 * if we've entered one of the thermal policy states. Note that
664 * this function determines when a state is entered, but the
665 * individual policy decides when it is exited (e.g. hysteresis).
667 if (tz
->trips
.critical
.flags
.valid
)
669 (tz
->temperature
>= tz
->trips
.critical
.temperature
);
670 if (tz
->trips
.hot
.flags
.valid
)
671 state
.hot
|= (tz
->temperature
>= tz
->trips
.hot
.temperature
);
672 if (tz
->trips
.passive
.flags
.valid
)
674 (tz
->temperature
>= tz
->trips
.passive
.temperature
);
675 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++)
676 if (tz
->trips
.active
[i
].flags
.valid
)
679 tz
->trips
.active
[i
].temperature
);
684 * Separated from the above check to allow individual policy to
685 * determine when to exit a given state.
688 acpi_thermal_critical(tz
);
690 acpi_thermal_hot(tz
);
692 acpi_thermal_passive(tz
);
694 acpi_thermal_active(tz
);
699 * Again, separated from the above two to allow independent policy
702 tz
->state
.critical
= tz
->trips
.critical
.flags
.enabled
;
703 tz
->state
.hot
= tz
->trips
.hot
.flags
.enabled
;
704 tz
->state
.passive
= tz
->trips
.passive
.flags
.enabled
;
705 tz
->state
.active
= 0;
706 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++)
707 tz
->state
.active
|= tz
->trips
.active
[i
].flags
.enabled
;
710 * Calculate Sleep Time
711 * --------------------
712 * If we're in the passive state, use _TSP's value. Otherwise
713 * use the default polling frequency (e.g. _TZP). If no polling
714 * frequency is specified then we'll wait forever (at least until
715 * a thermal event occurs). Note that _TSP and _TZD values are
716 * given in 1/10th seconds (we must covert to milliseconds).
718 if (tz
->state
.passive
)
719 sleep_time
= tz
->trips
.passive
.tsp
* 100;
720 else if (tz
->polling_frequency
> 0)
721 sleep_time
= tz
->polling_frequency
* 100;
723 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "%s: temperature[%lu] sleep[%lu]\n",
724 tz
->name
, tz
->temperature
, sleep_time
));
731 if (timer_pending(&(tz
->timer
)))
732 del_timer(&(tz
->timer
));
734 if (timer_pending(&(tz
->timer
)))
735 mod_timer(&(tz
->timer
),
736 jiffies
+ (HZ
* sleep_time
) / 1000);
738 tz
->timer
.data
= (unsigned long)tz
;
739 tz
->timer
.function
= acpi_thermal_run
;
740 tz
->timer
.expires
= jiffies
+ (HZ
* sleep_time
) / 1000;
741 add_timer(&(tz
->timer
));
748 /* --------------------------------------------------------------------------
750 -------------------------------------------------------------------------- */
752 static struct proc_dir_entry
*acpi_thermal_dir
;
754 static int acpi_thermal_state_seq_show(struct seq_file
*seq
, void *offset
)
756 struct acpi_thermal
*tz
= seq
->private;
762 seq_puts(seq
, "state: ");
764 if (!tz
->state
.critical
&& !tz
->state
.hot
&& !tz
->state
.passive
765 && !tz
->state
.active
)
766 seq_puts(seq
, "ok\n");
768 if (tz
->state
.critical
)
769 seq_puts(seq
, "critical ");
771 seq_puts(seq
, "hot ");
772 if (tz
->state
.passive
)
773 seq_puts(seq
, "passive ");
774 if (tz
->state
.active
)
775 seq_printf(seq
, "active[%d]", tz
->state
.active_index
);
783 static int acpi_thermal_state_open_fs(struct inode
*inode
, struct file
*file
)
785 return single_open(file
, acpi_thermal_state_seq_show
, PDE(inode
)->data
);
788 static int acpi_thermal_temp_seq_show(struct seq_file
*seq
, void *offset
)
791 struct acpi_thermal
*tz
= seq
->private;
797 result
= acpi_thermal_get_temperature(tz
);
801 seq_printf(seq
, "temperature: %ld C\n",
802 KELVIN_TO_CELSIUS(tz
->temperature
));
808 static int acpi_thermal_temp_open_fs(struct inode
*inode
, struct file
*file
)
810 return single_open(file
, acpi_thermal_temp_seq_show
, PDE(inode
)->data
);
813 static int acpi_thermal_trip_seq_show(struct seq_file
*seq
, void *offset
)
815 struct acpi_thermal
*tz
= seq
->private;
816 struct acpi_device
*device
;
826 if (tz
->trips
.critical
.flags
.valid
)
827 seq_printf(seq
, "critical (S5): %ld C\n",
828 KELVIN_TO_CELSIUS(tz
->trips
.critical
.temperature
));
830 if (tz
->trips
.hot
.flags
.valid
)
831 seq_printf(seq
, "hot (S4): %ld C\n",
832 KELVIN_TO_CELSIUS(tz
->trips
.hot
.temperature
));
834 if (tz
->trips
.passive
.flags
.valid
) {
836 "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
837 KELVIN_TO_CELSIUS(tz
->trips
.passive
.temperature
),
838 tz
->trips
.passive
.tc1
, tz
->trips
.passive
.tc2
,
839 tz
->trips
.passive
.tsp
);
840 for (j
= 0; j
< tz
->trips
.passive
.devices
.count
; j
++) {
841 status
= acpi_bus_get_device(tz
->trips
.passive
.devices
.
842 handles
[j
], &device
);
843 seq_printf(seq
, "%4.4s ", status
? "" :
844 acpi_device_bid(device
));
849 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
850 if (!(tz
->trips
.active
[i
].flags
.valid
))
852 seq_printf(seq
, "active[%d]: %ld C: devices=",
854 KELVIN_TO_CELSIUS(tz
->trips
.active
[i
].temperature
));
855 for (j
= 0; j
< tz
->trips
.active
[i
].devices
.count
; j
++){
856 status
= acpi_bus_get_device(tz
->trips
.active
[i
].
859 seq_printf(seq
, "%4.4s ", status
? "" :
860 acpi_device_bid(device
));
869 static int acpi_thermal_trip_open_fs(struct inode
*inode
, struct file
*file
)
871 return single_open(file
, acpi_thermal_trip_seq_show
, PDE(inode
)->data
);
874 static int acpi_thermal_cooling_seq_show(struct seq_file
*seq
, void *offset
)
876 struct acpi_thermal
*tz
= seq
->private;
882 if (!tz
->flags
.cooling_mode
)
883 seq_puts(seq
, "<setting not supported>\n");
885 seq_puts(seq
, "0 - Active; 1 - Passive\n");
891 static int acpi_thermal_cooling_open_fs(struct inode
*inode
, struct file
*file
)
893 return single_open(file
, acpi_thermal_cooling_seq_show
,
898 acpi_thermal_write_cooling_mode(struct file
*file
,
899 const char __user
* buffer
,
900 size_t count
, loff_t
* ppos
)
902 struct seq_file
*m
= file
->private_data
;
903 struct acpi_thermal
*tz
= m
->private;
905 char mode_string
[12] = { '\0' };
908 if (!tz
|| (count
> sizeof(mode_string
) - 1))
911 if (!tz
->flags
.cooling_mode
)
914 if (copy_from_user(mode_string
, buffer
, count
))
917 mode_string
[count
] = '\0';
919 result
= acpi_thermal_set_cooling_mode(tz
,
920 simple_strtoul(mode_string
, NULL
,
925 acpi_thermal_check(tz
);
930 static int acpi_thermal_polling_seq_show(struct seq_file
*seq
, void *offset
)
932 struct acpi_thermal
*tz
= seq
->private;
938 if (!tz
->polling_frequency
) {
939 seq_puts(seq
, "<polling disabled>\n");
943 seq_printf(seq
, "polling frequency: %lu seconds\n",
944 (tz
->polling_frequency
/ 10));
950 static int acpi_thermal_polling_open_fs(struct inode
*inode
, struct file
*file
)
952 return single_open(file
, acpi_thermal_polling_seq_show
,
957 acpi_thermal_write_polling(struct file
*file
,
958 const char __user
* buffer
,
959 size_t count
, loff_t
* ppos
)
961 struct seq_file
*m
= file
->private_data
;
962 struct acpi_thermal
*tz
= m
->private;
964 char polling_string
[12] = { '\0' };
968 if (!tz
|| (count
> sizeof(polling_string
) - 1))
971 if (copy_from_user(polling_string
, buffer
, count
))
974 polling_string
[count
] = '\0';
976 seconds
= simple_strtoul(polling_string
, NULL
, 0);
978 result
= acpi_thermal_set_polling(tz
, seconds
);
982 acpi_thermal_check(tz
);
987 static int acpi_thermal_add_fs(struct acpi_device
*device
)
989 struct proc_dir_entry
*entry
= NULL
;
992 if (!acpi_device_dir(device
)) {
993 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
995 if (!acpi_device_dir(device
))
997 acpi_device_dir(device
)->owner
= THIS_MODULE
;
1001 entry
= create_proc_entry(ACPI_THERMAL_FILE_STATE
,
1002 S_IRUGO
, acpi_device_dir(device
));
1006 entry
->proc_fops
= &acpi_thermal_state_fops
;
1007 entry
->data
= acpi_driver_data(device
);
1008 entry
->owner
= THIS_MODULE
;
1011 /* 'temperature' [R] */
1012 entry
= create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE
,
1013 S_IRUGO
, acpi_device_dir(device
));
1017 entry
->proc_fops
= &acpi_thermal_temp_fops
;
1018 entry
->data
= acpi_driver_data(device
);
1019 entry
->owner
= THIS_MODULE
;
1022 /* 'trip_points' [R/W] */
1023 entry
= create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS
,
1024 S_IFREG
| S_IRUGO
| S_IWUSR
,
1025 acpi_device_dir(device
));
1029 entry
->proc_fops
= &acpi_thermal_trip_fops
;
1030 entry
->data
= acpi_driver_data(device
);
1031 entry
->owner
= THIS_MODULE
;
1034 /* 'cooling_mode' [R/W] */
1035 entry
= create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE
,
1036 S_IFREG
| S_IRUGO
| S_IWUSR
,
1037 acpi_device_dir(device
));
1041 entry
->proc_fops
= &acpi_thermal_cooling_fops
;
1042 entry
->data
= acpi_driver_data(device
);
1043 entry
->owner
= THIS_MODULE
;
1046 /* 'polling_frequency' [R/W] */
1047 entry
= create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ
,
1048 S_IFREG
| S_IRUGO
| S_IWUSR
,
1049 acpi_device_dir(device
));
1053 entry
->proc_fops
= &acpi_thermal_polling_fops
;
1054 entry
->data
= acpi_driver_data(device
);
1055 entry
->owner
= THIS_MODULE
;
1061 static int acpi_thermal_remove_fs(struct acpi_device
*device
)
1064 if (acpi_device_dir(device
)) {
1065 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ
,
1066 acpi_device_dir(device
));
1067 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE
,
1068 acpi_device_dir(device
));
1069 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS
,
1070 acpi_device_dir(device
));
1071 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE
,
1072 acpi_device_dir(device
));
1073 remove_proc_entry(ACPI_THERMAL_FILE_STATE
,
1074 acpi_device_dir(device
));
1075 remove_proc_entry(acpi_device_bid(device
), acpi_thermal_dir
);
1076 acpi_device_dir(device
) = NULL
;
1082 /* --------------------------------------------------------------------------
1084 -------------------------------------------------------------------------- */
1086 static void acpi_thermal_notify(acpi_handle handle
, u32 event
, void *data
)
1088 struct acpi_thermal
*tz
= data
;
1089 struct acpi_device
*device
= NULL
;
1095 device
= tz
->device
;
1098 case ACPI_THERMAL_NOTIFY_TEMPERATURE
:
1099 acpi_thermal_check(tz
);
1101 case ACPI_THERMAL_NOTIFY_THRESHOLDS
:
1102 acpi_thermal_get_trip_points(tz
);
1103 acpi_thermal_check(tz
);
1104 acpi_bus_generate_event(device
, event
, 0);
1106 case ACPI_THERMAL_NOTIFY_DEVICES
:
1107 if (tz
->flags
.devices
)
1108 acpi_thermal_get_devices(tz
);
1109 acpi_bus_generate_event(device
, event
, 0);
1112 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1113 "Unsupported event [0x%x]\n", event
));
1120 static int acpi_thermal_get_info(struct acpi_thermal
*tz
)
1128 /* Get temperature [_TMP] (required) */
1129 result
= acpi_thermal_get_temperature(tz
);
1133 /* Get trip points [_CRT, _PSV, etc.] (required) */
1134 result
= acpi_thermal_get_trip_points(tz
);
1138 /* Set the cooling mode [_SCP] to active cooling (default) */
1139 result
= acpi_thermal_set_cooling_mode(tz
, ACPI_THERMAL_MODE_ACTIVE
);
1141 tz
->flags
.cooling_mode
= 1;
1143 /* Get default polling frequency [_TZP] (optional) */
1145 tz
->polling_frequency
= tzp
;
1147 acpi_thermal_get_polling_frequency(tz
);
1149 /* Get devices in this thermal zone [_TZD] (optional) */
1150 result
= acpi_thermal_get_devices(tz
);
1152 tz
->flags
.devices
= 1;
1157 static int acpi_thermal_add(struct acpi_device
*device
)
1160 acpi_status status
= AE_OK
;
1161 struct acpi_thermal
*tz
= NULL
;
1167 tz
= kzalloc(sizeof(struct acpi_thermal
), GFP_KERNEL
);
1171 tz
->device
= device
;
1172 strcpy(tz
->name
, device
->pnp
.bus_id
);
1173 strcpy(acpi_device_name(device
), ACPI_THERMAL_DEVICE_NAME
);
1174 strcpy(acpi_device_class(device
), ACPI_THERMAL_CLASS
);
1175 acpi_driver_data(device
) = tz
;
1177 result
= acpi_thermal_get_info(tz
);
1181 result
= acpi_thermal_add_fs(device
);
1185 init_timer(&tz
->timer
);
1187 acpi_thermal_check(tz
);
1189 status
= acpi_install_notify_handler(device
->handle
,
1191 acpi_thermal_notify
, tz
);
1192 if (ACPI_FAILURE(status
)) {
1197 printk(KERN_INFO PREFIX
"%s [%s] (%ld C)\n",
1198 acpi_device_name(device
), acpi_device_bid(device
),
1199 KELVIN_TO_CELSIUS(tz
->temperature
));
1203 acpi_thermal_remove_fs(device
);
1210 static int acpi_thermal_remove(struct acpi_device
*device
, int type
)
1212 acpi_status status
= AE_OK
;
1213 struct acpi_thermal
*tz
= NULL
;
1216 if (!device
|| !acpi_driver_data(device
))
1219 tz
= acpi_driver_data(device
);
1221 /* avoid timer adding new defer task */
1223 /* wait for running timer (on other CPUs) finish */
1224 del_timer_sync(&(tz
->timer
));
1225 /* synchronize deferred task */
1226 acpi_os_wait_events_complete(NULL
);
1227 /* deferred task may reinsert timer */
1228 del_timer_sync(&(tz
->timer
));
1230 status
= acpi_remove_notify_handler(device
->handle
,
1232 acpi_thermal_notify
);
1234 /* Terminate policy */
1235 if (tz
->trips
.passive
.flags
.valid
&& tz
->trips
.passive
.flags
.enabled
) {
1236 tz
->trips
.passive
.flags
.enabled
= 0;
1237 acpi_thermal_passive(tz
);
1239 if (tz
->trips
.active
[0].flags
.valid
1240 && tz
->trips
.active
[0].flags
.enabled
) {
1241 tz
->trips
.active
[0].flags
.enabled
= 0;
1242 acpi_thermal_active(tz
);
1245 acpi_thermal_remove_fs(device
);
1251 static int acpi_thermal_resume(struct acpi_device
*device
)
1253 struct acpi_thermal
*tz
= NULL
;
1254 int i
, j
, power_state
, result
;
1257 if (!device
|| !acpi_driver_data(device
))
1260 tz
= acpi_driver_data(device
);
1262 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
1263 if (!(&tz
->trips
.active
[i
]))
1265 if (!tz
->trips
.active
[i
].flags
.valid
)
1267 tz
->trips
.active
[i
].flags
.enabled
= 1;
1268 for (j
= 0; j
< tz
->trips
.active
[i
].devices
.count
; j
++) {
1269 result
= acpi_bus_get_power(tz
->trips
.active
[i
].devices
.
1270 handles
[j
], &power_state
);
1271 if (result
|| (power_state
!= ACPI_STATE_D0
)) {
1272 tz
->trips
.active
[i
].flags
.enabled
= 0;
1276 tz
->state
.active
|= tz
->trips
.active
[i
].flags
.enabled
;
1279 acpi_thermal_check(tz
);
1284 static int __init
acpi_thermal_init(void)
1289 acpi_thermal_dir
= proc_mkdir(ACPI_THERMAL_CLASS
, acpi_root_dir
);
1290 if (!acpi_thermal_dir
)
1292 acpi_thermal_dir
->owner
= THIS_MODULE
;
1294 result
= acpi_bus_register_driver(&acpi_thermal_driver
);
1296 remove_proc_entry(ACPI_THERMAL_CLASS
, acpi_root_dir
);
1303 static void __exit
acpi_thermal_exit(void)
1306 acpi_bus_unregister_driver(&acpi_thermal_driver
);
1308 remove_proc_entry(ACPI_THERMAL_CLASS
, acpi_root_dir
);
1313 module_init(acpi_thermal_init
);
1314 module_exit(acpi_thermal_exit
);