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 <asm/uaccess.h>
45 #include <acpi/acpi_bus.h>
46 #include <acpi/acpi_drivers.h>
48 #define ACPI_THERMAL_COMPONENT 0x04000000
49 #define ACPI_THERMAL_CLASS "thermal_zone"
50 #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
51 #define ACPI_THERMAL_FILE_STATE "state"
52 #define ACPI_THERMAL_FILE_TEMPERATURE "temperature"
53 #define ACPI_THERMAL_FILE_TRIP_POINTS "trip_points"
54 #define ACPI_THERMAL_FILE_COOLING_MODE "cooling_mode"
55 #define ACPI_THERMAL_FILE_POLLING_FREQ "polling_frequency"
56 #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80
57 #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81
58 #define ACPI_THERMAL_NOTIFY_DEVICES 0x82
59 #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0
60 #define ACPI_THERMAL_NOTIFY_HOT 0xF1
61 #define ACPI_THERMAL_MODE_ACTIVE 0x00
62 #define ACPI_THERMAL_PATH_POWEROFF "/sbin/poweroff"
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 struct acpi_driver acpi_thermal_driver
= {
97 .class = ACPI_THERMAL_CLASS
,
98 .ids
= ACPI_THERMAL_HID
,
100 .add
= acpi_thermal_add
,
101 .remove
= acpi_thermal_remove
,
102 .resume
= acpi_thermal_resume
,
106 struct acpi_thermal_state
{
115 struct acpi_thermal_state_flags
{
121 struct acpi_thermal_critical
{
122 struct acpi_thermal_state_flags flags
;
123 unsigned long temperature
;
126 struct acpi_thermal_hot
{
127 struct acpi_thermal_state_flags flags
;
128 unsigned long temperature
;
131 struct acpi_thermal_passive
{
132 struct acpi_thermal_state_flags flags
;
133 unsigned long temperature
;
137 struct acpi_handle_list devices
;
140 struct acpi_thermal_active
{
141 struct acpi_thermal_state_flags flags
;
142 unsigned long temperature
;
143 struct acpi_handle_list devices
;
146 struct acpi_thermal_trips
{
147 struct acpi_thermal_critical critical
;
148 struct acpi_thermal_hot hot
;
149 struct acpi_thermal_passive passive
;
150 struct acpi_thermal_active active
[ACPI_THERMAL_MAX_ACTIVE
];
153 struct acpi_thermal_flags
{
154 u8 cooling_mode
:1; /* _SCP */
155 u8 devices
:1; /* _TZD */
159 struct acpi_thermal
{
160 struct acpi_device
* device
;
162 unsigned long temperature
;
163 unsigned long last_temperature
;
164 unsigned long polling_frequency
;
166 struct acpi_thermal_flags flags
;
167 struct acpi_thermal_state state
;
168 struct acpi_thermal_trips trips
;
169 struct acpi_handle_list devices
;
170 struct timer_list timer
;
173 static const struct file_operations acpi_thermal_state_fops
= {
174 .open
= acpi_thermal_state_open_fs
,
177 .release
= single_release
,
180 static const struct file_operations acpi_thermal_temp_fops
= {
181 .open
= acpi_thermal_temp_open_fs
,
184 .release
= single_release
,
187 static const struct file_operations acpi_thermal_trip_fops
= {
188 .open
= acpi_thermal_trip_open_fs
,
191 .release
= single_release
,
194 static const struct file_operations acpi_thermal_cooling_fops
= {
195 .open
= acpi_thermal_cooling_open_fs
,
197 .write
= acpi_thermal_write_cooling_mode
,
199 .release
= single_release
,
202 static const struct file_operations acpi_thermal_polling_fops
= {
203 .open
= acpi_thermal_polling_open_fs
,
205 .write
= acpi_thermal_write_polling
,
207 .release
= single_release
,
210 /* --------------------------------------------------------------------------
211 Thermal Zone Management
212 -------------------------------------------------------------------------- */
214 static int acpi_thermal_get_temperature(struct acpi_thermal
*tz
)
216 acpi_status status
= AE_OK
;
222 tz
->last_temperature
= tz
->temperature
;
225 acpi_evaluate_integer(tz
->device
->handle
, "_TMP", NULL
, &tz
->temperature
);
226 if (ACPI_FAILURE(status
))
229 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Temperature is %lu dK\n",
235 static int acpi_thermal_get_polling_frequency(struct acpi_thermal
*tz
)
237 acpi_status status
= AE_OK
;
244 acpi_evaluate_integer(tz
->device
->handle
, "_TZP", NULL
,
245 &tz
->polling_frequency
);
246 if (ACPI_FAILURE(status
))
249 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Polling frequency is %lu dS\n",
250 tz
->polling_frequency
));
255 static int acpi_thermal_set_polling(struct acpi_thermal
*tz
, int seconds
)
261 tz
->polling_frequency
= seconds
* 10; /* Convert value to deci-seconds */
263 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
264 "Polling frequency set to %lu seconds\n",
265 tz
->polling_frequency
/10));
270 static int acpi_thermal_set_cooling_mode(struct acpi_thermal
*tz
, int mode
)
272 acpi_status status
= AE_OK
;
273 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
274 struct acpi_object_list arg_list
= { 1, &arg0
};
275 acpi_handle handle
= NULL
;
281 status
= acpi_get_handle(tz
->device
->handle
, "_SCP", &handle
);
282 if (ACPI_FAILURE(status
)) {
283 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "_SCP not present\n"));
287 arg0
.integer
.value
= mode
;
289 status
= acpi_evaluate_object(handle
, NULL
, &arg_list
, NULL
);
290 if (ACPI_FAILURE(status
))
296 static int acpi_thermal_get_trip_points(struct acpi_thermal
*tz
)
298 acpi_status status
= AE_OK
;
305 /* Critical Shutdown (required) */
307 status
= acpi_evaluate_integer(tz
->device
->handle
, "_CRT", NULL
,
308 &tz
->trips
.critical
.temperature
);
309 if (ACPI_FAILURE(status
)) {
310 tz
->trips
.critical
.flags
.valid
= 0;
311 ACPI_EXCEPTION((AE_INFO
, status
, "No critical threshold"));
314 tz
->trips
.critical
.flags
.valid
= 1;
315 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
316 "Found critical threshold [%lu]\n",
317 tz
->trips
.critical
.temperature
));
320 /* Critical Sleep (optional) */
323 acpi_evaluate_integer(tz
->device
->handle
, "_HOT", NULL
,
324 &tz
->trips
.hot
.temperature
);
325 if (ACPI_FAILURE(status
)) {
326 tz
->trips
.hot
.flags
.valid
= 0;
327 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "No hot threshold\n"));
329 tz
->trips
.hot
.flags
.valid
= 1;
330 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found hot threshold [%lu]\n",
331 tz
->trips
.hot
.temperature
));
334 /* Passive: Processors (optional) */
337 acpi_evaluate_integer(tz
->device
->handle
, "_PSV", NULL
,
338 &tz
->trips
.passive
.temperature
);
339 if (ACPI_FAILURE(status
)) {
340 tz
->trips
.passive
.flags
.valid
= 0;
341 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "No passive threshold\n"));
343 tz
->trips
.passive
.flags
.valid
= 1;
346 acpi_evaluate_integer(tz
->device
->handle
, "_TC1", NULL
,
347 &tz
->trips
.passive
.tc1
);
348 if (ACPI_FAILURE(status
))
349 tz
->trips
.passive
.flags
.valid
= 0;
352 acpi_evaluate_integer(tz
->device
->handle
, "_TC2", NULL
,
353 &tz
->trips
.passive
.tc2
);
354 if (ACPI_FAILURE(status
))
355 tz
->trips
.passive
.flags
.valid
= 0;
358 acpi_evaluate_integer(tz
->device
->handle
, "_TSP", NULL
,
359 &tz
->trips
.passive
.tsp
);
360 if (ACPI_FAILURE(status
))
361 tz
->trips
.passive
.flags
.valid
= 0;
364 acpi_evaluate_reference(tz
->device
->handle
, "_PSL", NULL
,
365 &tz
->trips
.passive
.devices
);
366 if (ACPI_FAILURE(status
))
367 tz
->trips
.passive
.flags
.valid
= 0;
369 if (!tz
->trips
.passive
.flags
.valid
)
370 printk(KERN_WARNING PREFIX
"Invalid passive threshold\n");
372 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
373 "Found passive threshold [%lu]\n",
374 tz
->trips
.passive
.temperature
));
377 /* Active: Fans, etc. (optional) */
379 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
381 char name
[5] = { '_', 'A', 'C', ('0' + i
), '\0' };
384 acpi_evaluate_integer(tz
->device
->handle
, name
, NULL
,
385 &tz
->trips
.active
[i
].temperature
);
386 if (ACPI_FAILURE(status
))
391 acpi_evaluate_reference(tz
->device
->handle
, name
, NULL
,
392 &tz
->trips
.active
[i
].devices
);
393 if (ACPI_SUCCESS(status
)) {
394 tz
->trips
.active
[i
].flags
.valid
= 1;
395 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
396 "Found active threshold [%d]:[%lu]\n",
397 i
, tz
->trips
.active
[i
].temperature
));
399 ACPI_EXCEPTION((AE_INFO
, status
,
400 "Invalid active threshold [%d]", i
));
406 static int acpi_thermal_get_devices(struct acpi_thermal
*tz
)
408 acpi_status status
= AE_OK
;
415 acpi_evaluate_reference(tz
->device
->handle
, "_TZD", NULL
, &tz
->devices
);
416 if (ACPI_FAILURE(status
))
422 static int acpi_thermal_call_usermode(char *path
)
424 char *argv
[2] = { NULL
, NULL
};
425 char *envp
[3] = { NULL
, NULL
, NULL
};
433 /* minimal command environment */
435 envp
[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
437 call_usermodehelper(argv
[0], argv
, envp
, 0);
442 static int acpi_thermal_critical(struct acpi_thermal
*tz
)
444 if (!tz
|| !tz
->trips
.critical
.flags
.valid
)
447 if (tz
->temperature
>= tz
->trips
.critical
.temperature
) {
448 printk(KERN_WARNING PREFIX
"Critical trip point\n");
449 tz
->trips
.critical
.flags
.enabled
= 1;
450 } else if (tz
->trips
.critical
.flags
.enabled
)
451 tz
->trips
.critical
.flags
.enabled
= 0;
454 "Critical temperature reached (%ld C), shutting down.\n",
455 KELVIN_TO_CELSIUS(tz
->temperature
));
456 acpi_bus_generate_event(tz
->device
, ACPI_THERMAL_NOTIFY_CRITICAL
,
457 tz
->trips
.critical
.flags
.enabled
);
459 acpi_thermal_call_usermode(ACPI_THERMAL_PATH_POWEROFF
);
464 static int acpi_thermal_hot(struct acpi_thermal
*tz
)
466 if (!tz
|| !tz
->trips
.hot
.flags
.valid
)
469 if (tz
->temperature
>= tz
->trips
.hot
.temperature
) {
470 printk(KERN_WARNING PREFIX
"Hot trip point\n");
471 tz
->trips
.hot
.flags
.enabled
= 1;
472 } else if (tz
->trips
.hot
.flags
.enabled
)
473 tz
->trips
.hot
.flags
.enabled
= 0;
475 acpi_bus_generate_event(tz
->device
, ACPI_THERMAL_NOTIFY_HOT
,
476 tz
->trips
.hot
.flags
.enabled
);
478 /* TBD: Call user-mode "sleep(S4)" function */
483 static void acpi_thermal_passive(struct acpi_thermal
*tz
)
486 struct acpi_thermal_passive
*passive
= NULL
;
491 if (!tz
|| !tz
->trips
.passive
.flags
.valid
)
494 passive
= &(tz
->trips
.passive
);
499 * Calculate the thermal trend (using the passive cooling equation)
500 * and modify the performance limit for all passive cooling devices
501 * accordingly. Note that we assume symmetry.
503 if (tz
->temperature
>= passive
->temperature
) {
505 (passive
->tc1
* (tz
->temperature
- tz
->last_temperature
)) +
506 (passive
->tc2
* (tz
->temperature
- passive
->temperature
));
507 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
508 "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
509 trend
, passive
->tc1
, tz
->temperature
,
510 tz
->last_temperature
, passive
->tc2
,
511 tz
->temperature
, passive
->temperature
));
512 passive
->flags
.enabled
= 1;
515 for (i
= 0; i
< passive
->devices
.count
; i
++)
516 acpi_processor_set_thermal_limit(passive
->
519 ACPI_PROCESSOR_LIMIT_INCREMENT
);
521 else if (trend
< 0) {
522 for (i
= 0; i
< passive
->devices
.count
; i
++)
524 * assume that we are on highest
525 * freq/lowest thrott and can leave
526 * passive mode, even in error case
528 if (!acpi_processor_set_thermal_limit
529 (passive
->devices
.handles
[i
],
530 ACPI_PROCESSOR_LIMIT_DECREMENT
))
533 * Leave cooling mode, even if the temp might
534 * higher than trip point This is because some
535 * machines might have long thermal polling
536 * frequencies (tsp) defined. We will fall back
537 * into passive mode in next cycle (probably quicker)
540 passive
->flags
.enabled
= 0;
541 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
542 "Disabling passive cooling, still above threshold,"
543 " but we are cooling down\n"));
552 * Implement passive cooling hysteresis to slowly increase performance
553 * and avoid thrashing around the passive trip point. Note that we
556 if (!passive
->flags
.enabled
)
558 for (i
= 0; i
< passive
->devices
.count
; i
++)
559 if (!acpi_processor_set_thermal_limit
560 (passive
->devices
.handles
[i
],
561 ACPI_PROCESSOR_LIMIT_DECREMENT
))
564 passive
->flags
.enabled
= 0;
565 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
566 "Disabling passive cooling (zone is cool)\n"));
570 static void acpi_thermal_active(struct acpi_thermal
*tz
)
573 struct acpi_thermal_active
*active
= NULL
;
576 unsigned long maxtemp
= 0;
582 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
583 active
= &(tz
->trips
.active
[i
]);
584 if (!active
|| !active
->flags
.valid
)
586 if (tz
->temperature
>= active
->temperature
) {
590 * If not already enabled, turn ON all cooling devices
591 * associated with this active threshold.
593 if (active
->temperature
> maxtemp
)
594 tz
->state
.active_index
= i
;
595 maxtemp
= active
->temperature
;
596 if (active
->flags
.enabled
)
598 for (j
= 0; j
< active
->devices
.count
; j
++) {
600 acpi_bus_set_power(active
->devices
.
604 printk(KERN_WARNING PREFIX
605 "Unable to turn cooling device [%p] 'on'\n",
610 active
->flags
.enabled
= 1;
611 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
612 "Cooling device [%p] now 'on'\n",
613 active
->devices
.handles
[j
]));
617 if (!active
->flags
.enabled
)
622 * Turn OFF all cooling devices associated with this
625 for (j
= 0; j
< active
->devices
.count
; j
++) {
626 result
= acpi_bus_set_power(active
->devices
.handles
[j
],
629 printk(KERN_WARNING PREFIX
630 "Unable to turn cooling device [%p] 'off'\n",
631 active
->devices
.handles
[j
]);
634 active
->flags
.enabled
= 0;
635 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
636 "Cooling device [%p] now 'off'\n",
637 active
->devices
.handles
[j
]));
642 static void acpi_thermal_check(void *context
);
644 static void acpi_thermal_run(unsigned long data
)
646 struct acpi_thermal
*tz
= (struct acpi_thermal
*)data
;
648 acpi_os_execute(OSL_GPE_HANDLER
, acpi_thermal_check
, (void *)data
);
651 static void acpi_thermal_check(void *data
)
654 struct acpi_thermal
*tz
= data
;
655 unsigned long sleep_time
= 0;
657 struct acpi_thermal_state state
;
661 printk(KERN_ERR PREFIX
"Invalid (NULL) context\n");
667 result
= acpi_thermal_get_temperature(tz
);
671 memset(&tz
->state
, 0, sizeof(tz
->state
));
676 * Compare the current temperature to the trip point values to see
677 * if we've entered one of the thermal policy states. Note that
678 * this function determines when a state is entered, but the
679 * individual policy decides when it is exited (e.g. hysteresis).
681 if (tz
->trips
.critical
.flags
.valid
)
683 (tz
->temperature
>= tz
->trips
.critical
.temperature
);
684 if (tz
->trips
.hot
.flags
.valid
)
685 state
.hot
|= (tz
->temperature
>= tz
->trips
.hot
.temperature
);
686 if (tz
->trips
.passive
.flags
.valid
)
688 (tz
->temperature
>= tz
->trips
.passive
.temperature
);
689 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++)
690 if (tz
->trips
.active
[i
].flags
.valid
)
693 tz
->trips
.active
[i
].temperature
);
698 * Separated from the above check to allow individual policy to
699 * determine when to exit a given state.
702 acpi_thermal_critical(tz
);
704 acpi_thermal_hot(tz
);
706 acpi_thermal_passive(tz
);
708 acpi_thermal_active(tz
);
713 * Again, separated from the above two to allow independent policy
716 tz
->state
.critical
= tz
->trips
.critical
.flags
.enabled
;
717 tz
->state
.hot
= tz
->trips
.hot
.flags
.enabled
;
718 tz
->state
.passive
= tz
->trips
.passive
.flags
.enabled
;
719 tz
->state
.active
= 0;
720 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++)
721 tz
->state
.active
|= tz
->trips
.active
[i
].flags
.enabled
;
724 * Calculate Sleep Time
725 * --------------------
726 * If we're in the passive state, use _TSP's value. Otherwise
727 * use the default polling frequency (e.g. _TZP). If no polling
728 * frequency is specified then we'll wait forever (at least until
729 * a thermal event occurs). Note that _TSP and _TZD values are
730 * given in 1/10th seconds (we must covert to milliseconds).
732 if (tz
->state
.passive
)
733 sleep_time
= tz
->trips
.passive
.tsp
* 100;
734 else if (tz
->polling_frequency
> 0)
735 sleep_time
= tz
->polling_frequency
* 100;
737 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "%s: temperature[%lu] sleep[%lu]\n",
738 tz
->name
, tz
->temperature
, sleep_time
));
745 if (timer_pending(&(tz
->timer
)))
746 del_timer(&(tz
->timer
));
748 if (timer_pending(&(tz
->timer
)))
749 mod_timer(&(tz
->timer
),
750 jiffies
+ (HZ
* sleep_time
) / 1000);
752 tz
->timer
.data
= (unsigned long)tz
;
753 tz
->timer
.function
= acpi_thermal_run
;
754 tz
->timer
.expires
= jiffies
+ (HZ
* sleep_time
) / 1000;
755 add_timer(&(tz
->timer
));
762 /* --------------------------------------------------------------------------
764 -------------------------------------------------------------------------- */
766 static struct proc_dir_entry
*acpi_thermal_dir
;
768 static int acpi_thermal_state_seq_show(struct seq_file
*seq
, void *offset
)
770 struct acpi_thermal
*tz
= seq
->private;
776 seq_puts(seq
, "state: ");
778 if (!tz
->state
.critical
&& !tz
->state
.hot
&& !tz
->state
.passive
779 && !tz
->state
.active
)
780 seq_puts(seq
, "ok\n");
782 if (tz
->state
.critical
)
783 seq_puts(seq
, "critical ");
785 seq_puts(seq
, "hot ");
786 if (tz
->state
.passive
)
787 seq_puts(seq
, "passive ");
788 if (tz
->state
.active
)
789 seq_printf(seq
, "active[%d]", tz
->state
.active_index
);
797 static int acpi_thermal_state_open_fs(struct inode
*inode
, struct file
*file
)
799 return single_open(file
, acpi_thermal_state_seq_show
, PDE(inode
)->data
);
802 static int acpi_thermal_temp_seq_show(struct seq_file
*seq
, void *offset
)
805 struct acpi_thermal
*tz
= seq
->private;
811 result
= acpi_thermal_get_temperature(tz
);
815 seq_printf(seq
, "temperature: %ld C\n",
816 KELVIN_TO_CELSIUS(tz
->temperature
));
822 static int acpi_thermal_temp_open_fs(struct inode
*inode
, struct file
*file
)
824 return single_open(file
, acpi_thermal_temp_seq_show
, PDE(inode
)->data
);
827 static int acpi_thermal_trip_seq_show(struct seq_file
*seq
, void *offset
)
829 struct acpi_thermal
*tz
= seq
->private;
830 struct acpi_device
*device
;
838 if (tz
->trips
.critical
.flags
.valid
)
839 seq_printf(seq
, "critical (S5): %ld C\n",
840 KELVIN_TO_CELSIUS(tz
->trips
.critical
.temperature
));
842 if (tz
->trips
.hot
.flags
.valid
)
843 seq_printf(seq
, "hot (S4): %ld C\n",
844 KELVIN_TO_CELSIUS(tz
->trips
.hot
.temperature
));
846 if (tz
->trips
.passive
.flags
.valid
) {
848 "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
849 KELVIN_TO_CELSIUS(tz
->trips
.passive
.temperature
),
850 tz
->trips
.passive
.tc1
, tz
->trips
.passive
.tc2
,
851 tz
->trips
.passive
.tsp
);
852 for (j
= 0; j
< tz
->trips
.passive
.devices
.count
; j
++) {
853 acpi_bus_get_device(tz
->trips
.passive
.devices
.handles
[j
], &device
);
854 seq_printf(seq
, "%4.4s ", acpi_device_bid(device
));
859 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
860 if (!(tz
->trips
.active
[i
].flags
.valid
))
862 seq_printf(seq
, "active[%d]: %ld C: devices=",
864 KELVIN_TO_CELSIUS(tz
->trips
.active
[i
].temperature
));
865 for (j
= 0; j
< tz
->trips
.active
[i
].devices
.count
; j
++){
866 acpi_bus_get_device(tz
->trips
.active
[i
].devices
.handles
[j
], &device
);
867 seq_printf(seq
, "%4.4s ", acpi_device_bid(device
));
876 static int acpi_thermal_trip_open_fs(struct inode
*inode
, struct file
*file
)
878 return single_open(file
, acpi_thermal_trip_seq_show
, PDE(inode
)->data
);
881 static int acpi_thermal_cooling_seq_show(struct seq_file
*seq
, void *offset
)
883 struct acpi_thermal
*tz
= seq
->private;
889 if (!tz
->flags
.cooling_mode
)
890 seq_puts(seq
, "<setting not supported>\n");
892 seq_puts(seq
, "0 - Active; 1 - Passive\n");
898 static int acpi_thermal_cooling_open_fs(struct inode
*inode
, struct file
*file
)
900 return single_open(file
, acpi_thermal_cooling_seq_show
,
905 acpi_thermal_write_cooling_mode(struct file
*file
,
906 const char __user
* buffer
,
907 size_t count
, loff_t
* ppos
)
909 struct seq_file
*m
= file
->private_data
;
910 struct acpi_thermal
*tz
= m
->private;
912 char mode_string
[12] = { '\0' };
915 if (!tz
|| (count
> sizeof(mode_string
) - 1))
918 if (!tz
->flags
.cooling_mode
)
921 if (copy_from_user(mode_string
, buffer
, count
))
924 mode_string
[count
] = '\0';
926 result
= acpi_thermal_set_cooling_mode(tz
,
927 simple_strtoul(mode_string
, NULL
,
932 acpi_thermal_check(tz
);
937 static int acpi_thermal_polling_seq_show(struct seq_file
*seq
, void *offset
)
939 struct acpi_thermal
*tz
= seq
->private;
945 if (!tz
->polling_frequency
) {
946 seq_puts(seq
, "<polling disabled>\n");
950 seq_printf(seq
, "polling frequency: %lu seconds\n",
951 (tz
->polling_frequency
/ 10));
957 static int acpi_thermal_polling_open_fs(struct inode
*inode
, struct file
*file
)
959 return single_open(file
, acpi_thermal_polling_seq_show
,
964 acpi_thermal_write_polling(struct file
*file
,
965 const char __user
* buffer
,
966 size_t count
, loff_t
* ppos
)
968 struct seq_file
*m
= file
->private_data
;
969 struct acpi_thermal
*tz
= m
->private;
971 char polling_string
[12] = { '\0' };
975 if (!tz
|| (count
> sizeof(polling_string
) - 1))
978 if (copy_from_user(polling_string
, buffer
, count
))
981 polling_string
[count
] = '\0';
983 seconds
= simple_strtoul(polling_string
, NULL
, 0);
985 result
= acpi_thermal_set_polling(tz
, seconds
);
989 acpi_thermal_check(tz
);
994 static int acpi_thermal_add_fs(struct acpi_device
*device
)
996 struct proc_dir_entry
*entry
= NULL
;
999 if (!acpi_device_dir(device
)) {
1000 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
1002 if (!acpi_device_dir(device
))
1004 acpi_device_dir(device
)->owner
= THIS_MODULE
;
1008 entry
= create_proc_entry(ACPI_THERMAL_FILE_STATE
,
1009 S_IRUGO
, acpi_device_dir(device
));
1013 entry
->proc_fops
= &acpi_thermal_state_fops
;
1014 entry
->data
= acpi_driver_data(device
);
1015 entry
->owner
= THIS_MODULE
;
1018 /* 'temperature' [R] */
1019 entry
= create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE
,
1020 S_IRUGO
, acpi_device_dir(device
));
1024 entry
->proc_fops
= &acpi_thermal_temp_fops
;
1025 entry
->data
= acpi_driver_data(device
);
1026 entry
->owner
= THIS_MODULE
;
1029 /* 'trip_points' [R/W] */
1030 entry
= create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS
,
1031 S_IFREG
| S_IRUGO
| S_IWUSR
,
1032 acpi_device_dir(device
));
1036 entry
->proc_fops
= &acpi_thermal_trip_fops
;
1037 entry
->data
= acpi_driver_data(device
);
1038 entry
->owner
= THIS_MODULE
;
1041 /* 'cooling_mode' [R/W] */
1042 entry
= create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE
,
1043 S_IFREG
| S_IRUGO
| S_IWUSR
,
1044 acpi_device_dir(device
));
1048 entry
->proc_fops
= &acpi_thermal_cooling_fops
;
1049 entry
->data
= acpi_driver_data(device
);
1050 entry
->owner
= THIS_MODULE
;
1053 /* 'polling_frequency' [R/W] */
1054 entry
= create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ
,
1055 S_IFREG
| S_IRUGO
| S_IWUSR
,
1056 acpi_device_dir(device
));
1060 entry
->proc_fops
= &acpi_thermal_polling_fops
;
1061 entry
->data
= acpi_driver_data(device
);
1062 entry
->owner
= THIS_MODULE
;
1068 static int acpi_thermal_remove_fs(struct acpi_device
*device
)
1071 if (acpi_device_dir(device
)) {
1072 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ
,
1073 acpi_device_dir(device
));
1074 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE
,
1075 acpi_device_dir(device
));
1076 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS
,
1077 acpi_device_dir(device
));
1078 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE
,
1079 acpi_device_dir(device
));
1080 remove_proc_entry(ACPI_THERMAL_FILE_STATE
,
1081 acpi_device_dir(device
));
1082 remove_proc_entry(acpi_device_bid(device
), acpi_thermal_dir
);
1083 acpi_device_dir(device
) = NULL
;
1089 /* --------------------------------------------------------------------------
1091 -------------------------------------------------------------------------- */
1093 static void acpi_thermal_notify(acpi_handle handle
, u32 event
, void *data
)
1095 struct acpi_thermal
*tz
= data
;
1096 struct acpi_device
*device
= NULL
;
1102 device
= tz
->device
;
1105 case ACPI_THERMAL_NOTIFY_TEMPERATURE
:
1106 acpi_thermal_check(tz
);
1108 case ACPI_THERMAL_NOTIFY_THRESHOLDS
:
1109 acpi_thermal_get_trip_points(tz
);
1110 acpi_thermal_check(tz
);
1111 acpi_bus_generate_event(device
, event
, 0);
1113 case ACPI_THERMAL_NOTIFY_DEVICES
:
1114 if (tz
->flags
.devices
)
1115 acpi_thermal_get_devices(tz
);
1116 acpi_bus_generate_event(device
, event
, 0);
1119 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1120 "Unsupported event [0x%x]\n", event
));
1127 static int acpi_thermal_get_info(struct acpi_thermal
*tz
)
1135 /* Get temperature [_TMP] (required) */
1136 result
= acpi_thermal_get_temperature(tz
);
1140 /* Get trip points [_CRT, _PSV, etc.] (required) */
1141 result
= acpi_thermal_get_trip_points(tz
);
1145 /* Set the cooling mode [_SCP] to active cooling (default) */
1146 result
= acpi_thermal_set_cooling_mode(tz
, ACPI_THERMAL_MODE_ACTIVE
);
1148 tz
->flags
.cooling_mode
= 1;
1150 /* Get default polling frequency [_TZP] (optional) */
1152 tz
->polling_frequency
= tzp
;
1154 acpi_thermal_get_polling_frequency(tz
);
1156 /* Get devices in this thermal zone [_TZD] (optional) */
1157 result
= acpi_thermal_get_devices(tz
);
1159 tz
->flags
.devices
= 1;
1164 static int acpi_thermal_add(struct acpi_device
*device
)
1167 acpi_status status
= AE_OK
;
1168 struct acpi_thermal
*tz
= NULL
;
1174 tz
= kzalloc(sizeof(struct acpi_thermal
), GFP_KERNEL
);
1178 tz
->device
= device
;
1179 strcpy(tz
->name
, device
->pnp
.bus_id
);
1180 strcpy(acpi_device_name(device
), ACPI_THERMAL_DEVICE_NAME
);
1181 strcpy(acpi_device_class(device
), ACPI_THERMAL_CLASS
);
1182 acpi_driver_data(device
) = tz
;
1184 result
= acpi_thermal_get_info(tz
);
1188 result
= acpi_thermal_add_fs(device
);
1192 init_timer(&tz
->timer
);
1194 acpi_thermal_check(tz
);
1196 status
= acpi_install_notify_handler(device
->handle
,
1198 acpi_thermal_notify
, tz
);
1199 if (ACPI_FAILURE(status
)) {
1204 printk(KERN_INFO PREFIX
"%s [%s] (%ld C)\n",
1205 acpi_device_name(device
), acpi_device_bid(device
),
1206 KELVIN_TO_CELSIUS(tz
->temperature
));
1210 acpi_thermal_remove_fs(device
);
1217 static int acpi_thermal_remove(struct acpi_device
*device
, int type
)
1219 acpi_status status
= AE_OK
;
1220 struct acpi_thermal
*tz
= NULL
;
1223 if (!device
|| !acpi_driver_data(device
))
1226 tz
= acpi_driver_data(device
);
1228 /* avoid timer adding new defer task */
1230 /* wait for running timer (on other CPUs) finish */
1231 del_timer_sync(&(tz
->timer
));
1232 /* synchronize deferred task */
1233 acpi_os_wait_events_complete(NULL
);
1234 /* deferred task may reinsert timer */
1235 del_timer_sync(&(tz
->timer
));
1237 status
= acpi_remove_notify_handler(device
->handle
,
1239 acpi_thermal_notify
);
1241 /* Terminate policy */
1242 if (tz
->trips
.passive
.flags
.valid
&& tz
->trips
.passive
.flags
.enabled
) {
1243 tz
->trips
.passive
.flags
.enabled
= 0;
1244 acpi_thermal_passive(tz
);
1246 if (tz
->trips
.active
[0].flags
.valid
1247 && tz
->trips
.active
[0].flags
.enabled
) {
1248 tz
->trips
.active
[0].flags
.enabled
= 0;
1249 acpi_thermal_active(tz
);
1252 acpi_thermal_remove_fs(device
);
1258 static int acpi_thermal_resume(struct acpi_device
*device
)
1260 struct acpi_thermal
*tz
= NULL
;
1261 int i
, j
, power_state
, result
;
1264 if (!device
|| !acpi_driver_data(device
))
1267 tz
= acpi_driver_data(device
);
1269 for (i
= 0; i
< ACPI_THERMAL_MAX_ACTIVE
; i
++) {
1270 if (!(&tz
->trips
.active
[i
]))
1272 if (!tz
->trips
.active
[i
].flags
.valid
)
1274 tz
->trips
.active
[i
].flags
.enabled
= 1;
1275 for (j
= 0; j
< tz
->trips
.active
[i
].devices
.count
; j
++) {
1276 result
= acpi_bus_get_power(tz
->trips
.active
[i
].devices
.
1277 handles
[j
], &power_state
);
1278 if (result
|| (power_state
!= ACPI_STATE_D0
)) {
1279 tz
->trips
.active
[i
].flags
.enabled
= 0;
1283 tz
->state
.active
|= tz
->trips
.active
[i
].flags
.enabled
;
1286 acpi_thermal_check(tz
);
1291 static int __init
acpi_thermal_init(void)
1296 acpi_thermal_dir
= proc_mkdir(ACPI_THERMAL_CLASS
, acpi_root_dir
);
1297 if (!acpi_thermal_dir
)
1299 acpi_thermal_dir
->owner
= THIS_MODULE
;
1301 result
= acpi_bus_register_driver(&acpi_thermal_driver
);
1303 remove_proc_entry(ACPI_THERMAL_CLASS
, acpi_root_dir
);
1310 static void __exit
acpi_thermal_exit(void)
1313 acpi_bus_unregister_driver(&acpi_thermal_driver
);
1315 remove_proc_entry(ACPI_THERMAL_CLASS
, acpi_root_dir
);
1320 module_init(acpi_thermal_init
);
1321 module_exit(acpi_thermal_exit
);