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/sched.h>
40 #include <linux/kmod.h>
41 #include <linux/seq_file.h>
42 #include <asm/uaccess.h>
44 #include <acpi/acpi_bus.h>
45 #include <acpi/acpi_drivers.h>
47 #define ACPI_THERMAL_COMPONENT 0x04000000
48 #define ACPI_THERMAL_CLASS "thermal_zone"
49 #define ACPI_THERMAL_DRIVER_NAME "ACPI Thermal Zone Driver"
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_MODE_PASSIVE 0x01
63 #define ACPI_THERMAL_PATH_POWEROFF "/sbin/poweroff"
65 #define ACPI_THERMAL_MAX_ACTIVE 10
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 ("acpi_thermal")
73 MODULE_AUTHOR("Paul Diefenbaugh");
74 MODULE_DESCRIPTION(ACPI_THERMAL_DRIVER_NAME);
75 MODULE_LICENSE("GPL");
78 MODULE_PARM(tzp, "i");
79 MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.\n");
82 static int acpi_thermal_add (struct acpi_device *device);
83 static int acpi_thermal_remove (struct acpi_device *device, int type);
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 ssize_t acpi_thermal_write_trip_points (struct file*,const char __user *,size_t,loff_t *);
88 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
89 static ssize_t acpi_thermal_write_cooling_mode (struct file*,const char __user *,size_t,loff_t *);
90 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
91 static ssize_t acpi_thermal_write_polling(struct file*,const char __user *,size_t,loff_t *);
93 static struct acpi_driver acpi_thermal_driver = {
94 .name = ACPI_THERMAL_DRIVER_NAME,
95 .class = ACPI_THERMAL_CLASS,
96 .ids = ACPI_THERMAL_HID,
98 .add = acpi_thermal_add,
99 .remove = acpi_thermal_remove,
103 struct acpi_thermal_state {
112 struct acpi_thermal_state_flags {
118 struct acpi_thermal_critical {
119 struct acpi_thermal_state_flags flags;
120 unsigned long temperature;
123 struct acpi_thermal_hot {
124 struct acpi_thermal_state_flags flags;
125 unsigned long temperature;
128 struct acpi_thermal_passive {
129 struct acpi_thermal_state_flags flags;
130 unsigned long temperature;
134 struct acpi_handle_list devices;
137 struct acpi_thermal_active {
138 struct acpi_thermal_state_flags flags;
139 unsigned long temperature;
140 struct acpi_handle_list devices;
143 struct acpi_thermal_trips {
144 struct acpi_thermal_critical critical;
145 struct acpi_thermal_hot hot;
146 struct acpi_thermal_passive passive;
147 struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
150 struct acpi_thermal_flags {
151 u8 cooling_mode:1; /* _SCP */
152 u8 devices:1; /* _TZD */
156 struct acpi_thermal {
159 unsigned long temperature;
160 unsigned long last_temperature;
161 unsigned long polling_frequency;
163 struct acpi_thermal_flags flags;
164 struct acpi_thermal_state state;
165 struct acpi_thermal_trips trips;
166 struct acpi_handle_list devices;
167 struct timer_list timer;
170 static struct file_operations acpi_thermal_state_fops = {
171 .open = acpi_thermal_state_open_fs,
174 .release = single_release,
177 static struct file_operations acpi_thermal_temp_fops = {
178 .open = acpi_thermal_temp_open_fs,
181 .release = single_release,
184 static struct file_operations acpi_thermal_trip_fops = {
185 .open = acpi_thermal_trip_open_fs,
187 .write = acpi_thermal_write_trip_points,
189 .release = single_release,
192 static struct file_operations acpi_thermal_cooling_fops = {
193 .open = acpi_thermal_cooling_open_fs,
195 .write = acpi_thermal_write_cooling_mode,
197 .release = single_release,
200 static struct file_operations acpi_thermal_polling_fops = {
201 .open = acpi_thermal_polling_open_fs,
203 .write = acpi_thermal_write_polling,
205 .release = single_release,
208 /* --------------------------------------------------------------------------
209 Thermal Zone Management
210 -------------------------------------------------------------------------- */
213 acpi_thermal_get_temperature (
214 struct acpi_thermal *tz)
216 acpi_status status = AE_OK;
218 ACPI_FUNCTION_TRACE("acpi_thermal_get_temperature");
221 return_VALUE(-EINVAL);
223 tz->last_temperature = tz->temperature;
225 status = acpi_evaluate_integer(tz->handle, "_TMP", NULL, &tz->temperature);
226 if (ACPI_FAILURE(status))
229 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n", tz->temperature));
236 acpi_thermal_get_polling_frequency (
237 struct acpi_thermal *tz)
239 acpi_status status = AE_OK;
241 ACPI_FUNCTION_TRACE("acpi_thermal_get_polling_frequency");
244 return_VALUE(-EINVAL);
246 status = acpi_evaluate_integer(tz->handle, "_TZP", NULL, &tz->polling_frequency);
247 if (ACPI_FAILURE(status))
248 return_VALUE(-ENODEV);
250 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n", tz->polling_frequency));
257 acpi_thermal_set_polling (
258 struct acpi_thermal *tz,
261 ACPI_FUNCTION_TRACE("acpi_thermal_set_polling");
264 return_VALUE(-EINVAL);
266 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
268 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency set to %lu seconds\n", tz->polling_frequency));
275 acpi_thermal_set_cooling_mode (
276 struct acpi_thermal *tz,
279 acpi_status status = AE_OK;
280 union acpi_object arg0 = {ACPI_TYPE_INTEGER};
281 struct acpi_object_list arg_list = {1, &arg0};
282 acpi_handle handle = NULL;
284 ACPI_FUNCTION_TRACE("acpi_thermal_set_cooling_mode");
287 return_VALUE(-EINVAL);
289 status = acpi_get_handle(tz->handle, "_SCP", &handle);
290 if (ACPI_FAILURE(status)) {
291 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
292 return_VALUE(-ENODEV);
295 arg0.integer.value = mode;
297 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
298 if (ACPI_FAILURE(status))
299 return_VALUE(-ENODEV);
301 tz->cooling_mode = mode;
303 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Cooling mode [%s]\n",
304 mode?"passive":"active"));
311 acpi_thermal_get_trip_points (
312 struct acpi_thermal *tz)
314 acpi_status status = AE_OK;
317 ACPI_FUNCTION_TRACE("acpi_thermal_get_trip_points");
320 return_VALUE(-EINVAL);
322 /* Critical Shutdown (required) */
324 status = acpi_evaluate_integer(tz->handle, "_CRT", NULL,
325 &tz->trips.critical.temperature);
326 if (ACPI_FAILURE(status)) {
327 tz->trips.critical.flags.valid = 0;
328 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "No critical threshold\n"));
332 tz->trips.critical.flags.valid = 1;
333 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found critical threshold [%lu]\n", tz->trips.critical.temperature));
336 /* Critical Sleep (optional) */
338 status = acpi_evaluate_integer(tz->handle, "_HOT", NULL, &tz->trips.hot.temperature);
339 if (ACPI_FAILURE(status)) {
340 tz->trips.hot.flags.valid = 0;
341 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No hot threshold\n"));
344 tz->trips.hot.flags.valid = 1;
345 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found hot threshold [%lu]\n", tz->trips.hot.temperature));
348 /* Passive: Processors (optional) */
350 status = acpi_evaluate_integer(tz->handle, "_PSV", NULL, &tz->trips.passive.temperature);
351 if (ACPI_FAILURE(status)) {
352 tz->trips.passive.flags.valid = 0;
353 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No passive threshold\n"));
356 tz->trips.passive.flags.valid = 1;
358 status = acpi_evaluate_integer(tz->handle, "_TC1", NULL, &tz->trips.passive.tc1);
359 if (ACPI_FAILURE(status))
360 tz->trips.passive.flags.valid = 0;
362 status = acpi_evaluate_integer(tz->handle, "_TC2", NULL, &tz->trips.passive.tc2);
363 if (ACPI_FAILURE(status))
364 tz->trips.passive.flags.valid = 0;
366 status = acpi_evaluate_integer(tz->handle, "_TSP", NULL, &tz->trips.passive.tsp);
367 if (ACPI_FAILURE(status))
368 tz->trips.passive.flags.valid = 0;
370 status = acpi_evaluate_reference(tz->handle, "_PSL", NULL, &tz->trips.passive.devices);
371 if (ACPI_FAILURE(status))
372 tz->trips.passive.flags.valid = 0;
374 if (!tz->trips.passive.flags.valid)
375 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid passive threshold\n"));
377 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found passive threshold [%lu]\n", tz->trips.passive.temperature));
380 /* Active: Fans, etc. (optional) */
382 for (i=0; i<ACPI_THERMAL_MAX_ACTIVE; i++) {
384 char name[5] = {'_','A','C',('0'+i),'\0'};
386 status = acpi_evaluate_integer(tz->handle, name, NULL, &tz->trips.active[i].temperature);
387 if (ACPI_FAILURE(status))
391 status = acpi_evaluate_reference(tz->handle, name, NULL, &tz->trips.active[i].devices);
392 if (ACPI_SUCCESS(status)) {
393 tz->trips.active[i].flags.valid = 1;
394 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found active threshold [%d]:[%lu]\n", i, tz->trips.active[i].temperature));
397 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid active threshold [%d]\n", i));
405 acpi_thermal_get_devices (
406 struct acpi_thermal *tz)
408 acpi_status status = AE_OK;
410 ACPI_FUNCTION_TRACE("acpi_thermal_get_devices");
413 return_VALUE(-EINVAL);
415 status = acpi_evaluate_reference(tz->handle, "_TZD", NULL, &tz->devices);
416 if (ACPI_FAILURE(status))
417 return_VALUE(-ENODEV);
424 acpi_thermal_call_usermode (
427 char *argv[2] = {NULL, NULL};
428 char *envp[3] = {NULL, NULL, NULL};
430 ACPI_FUNCTION_TRACE("acpi_thermal_call_usermode");
433 return_VALUE(-EINVAL);
437 /* minimal command environment */
439 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
441 call_usermodehelper(argv[0], argv, envp, 0);
448 acpi_thermal_critical (
449 struct acpi_thermal *tz)
452 struct acpi_device *device = NULL;
454 ACPI_FUNCTION_TRACE("acpi_thermal_critical");
456 if (!tz || !tz->trips.critical.flags.valid)
457 return_VALUE(-EINVAL);
459 if (tz->temperature >= tz->trips.critical.temperature) {
460 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Critical trip point\n"));
461 tz->trips.critical.flags.enabled = 1;
463 else if (tz->trips.critical.flags.enabled)
464 tz->trips.critical.flags.enabled = 0;
466 result = acpi_bus_get_device(tz->handle, &device);
468 return_VALUE(result);
470 printk(KERN_EMERG "Critical temperature reached (%ld C), shutting down.\n", KELVIN_TO_CELSIUS(tz->temperature));
471 acpi_bus_generate_event(device, ACPI_THERMAL_NOTIFY_CRITICAL, tz->trips.critical.flags.enabled);
473 acpi_thermal_call_usermode(ACPI_THERMAL_PATH_POWEROFF);
481 struct acpi_thermal *tz)
484 struct acpi_device *device = NULL;
486 ACPI_FUNCTION_TRACE("acpi_thermal_hot");
488 if (!tz || !tz->trips.hot.flags.valid)
489 return_VALUE(-EINVAL);
491 if (tz->temperature >= tz->trips.hot.temperature) {
492 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Hot trip point\n"));
493 tz->trips.hot.flags.enabled = 1;
495 else if (tz->trips.hot.flags.enabled)
496 tz->trips.hot.flags.enabled = 0;
498 result = acpi_bus_get_device(tz->handle, &device);
500 return_VALUE(result);
502 acpi_bus_generate_event(device, ACPI_THERMAL_NOTIFY_HOT, tz->trips.hot.flags.enabled);
504 /* TBD: Call user-mode "sleep(S4)" function */
511 acpi_thermal_passive (
512 struct acpi_thermal *tz)
515 struct acpi_thermal_passive *passive = NULL;
519 ACPI_FUNCTION_TRACE("acpi_thermal_passive");
521 if (!tz || !tz->trips.passive.flags.valid)
522 return_VALUE(-EINVAL);
524 passive = &(tz->trips.passive);
529 * Calculate the thermal trend (using the passive cooling equation)
530 * and modify the performance limit for all passive cooling devices
531 * accordingly. Note that we assume symmetry.
533 if (tz->temperature >= passive->temperature) {
534 trend = (passive->tc1 * (tz->temperature - tz->last_temperature)) + (passive->tc2 * (tz->temperature - passive->temperature));
535 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
536 "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
537 trend, passive->tc1, tz->temperature,
538 tz->last_temperature, passive->tc2,
539 tz->temperature, passive->temperature));
540 tz->trips.passive.flags.enabled = 1;
543 for (i=0; i<passive->devices.count; i++)
544 acpi_processor_set_thermal_limit(
545 passive->devices.handles[i],
546 ACPI_PROCESSOR_LIMIT_INCREMENT);
549 for (i=0; i<passive->devices.count; i++)
550 acpi_processor_set_thermal_limit(
551 passive->devices.handles[i],
552 ACPI_PROCESSOR_LIMIT_DECREMENT);
558 * Implement passive cooling hysteresis to slowly increase performance
559 * and avoid thrashing around the passive trip point. Note that we
562 else if (tz->trips.passive.flags.enabled) {
563 for (i=0; i<passive->devices.count; i++)
564 result = acpi_processor_set_thermal_limit(
565 passive->devices.handles[i],
566 ACPI_PROCESSOR_LIMIT_DECREMENT);
568 tz->trips.passive.flags.enabled = 0;
569 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
570 "Disabling passive cooling (zone is cool)\n"));
579 acpi_thermal_active (
580 struct acpi_thermal *tz)
583 struct acpi_thermal_active *active = NULL;
586 unsigned long maxtemp = 0;
588 ACPI_FUNCTION_TRACE("acpi_thermal_active");
591 return_VALUE(-EINVAL);
593 for (i=0; i<ACPI_THERMAL_MAX_ACTIVE; i++) {
595 active = &(tz->trips.active[i]);
596 if (!active || !active->flags.valid)
602 * If not already enabled, turn ON all cooling devices
603 * associated with this active threshold.
605 if (tz->temperature >= active->temperature) {
606 if (active->temperature > maxtemp)
607 tz->state.active_index = i, maxtemp = active->temperature;
608 if (!active->flags.enabled) {
609 for (j = 0; j < active->devices.count; j++) {
610 result = acpi_bus_set_power(active->devices.handles[j], ACPI_STATE_D0);
612 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Unable to turn cooling device [%p] 'on'\n", active->devices.handles[j]));
615 active->flags.enabled = 1;
616 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Cooling device [%p] now 'on'\n", active->devices.handles[j]));
623 * Turn OFF all cooling devices associated with this
626 else if (active->flags.enabled) {
627 for (j = 0; j < active->devices.count; j++) {
628 result = acpi_bus_set_power(active->devices.handles[j], ACPI_STATE_D3);
630 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Unable to turn cooling device [%p] 'off'\n", active->devices.handles[j]));
633 active->flags.enabled = 0;
634 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Cooling device [%p] now 'off'\n", active->devices.handles[j]));
643 static void acpi_thermal_check (void *context);
649 acpi_os_queue_for_execution(OSD_PRIORITY_GPE, acpi_thermal_check, (void *) data);
658 struct acpi_thermal *tz = (struct acpi_thermal *) data;
659 unsigned long sleep_time = 0;
661 struct acpi_thermal_state state = tz->state;
663 ACPI_FUNCTION_TRACE("acpi_thermal_check");
666 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid (NULL) context.\n"));
670 result = acpi_thermal_get_temperature(tz);
674 memset(&tz->state, 0, sizeof(tz->state));
679 * Compare the current temperature to the trip point values to see
680 * if we've entered one of the thermal policy states. Note that
681 * this function determines when a state is entered, but the
682 * individual policy decides when it is exited (e.g. hysteresis).
684 if (tz->trips.critical.flags.valid)
685 state.critical |= (tz->temperature >= tz->trips.critical.temperature);
686 if (tz->trips.hot.flags.valid)
687 state.hot |= (tz->temperature >= tz->trips.hot.temperature);
688 if (tz->trips.passive.flags.valid)
689 state.passive |= (tz->temperature >= tz->trips.passive.temperature);
690 for (i=0; i<ACPI_THERMAL_MAX_ACTIVE; i++)
691 if (tz->trips.active[i].flags.valid)
692 state.active |= (tz->temperature >= tz->trips.active[i].temperature);
697 * Separated from the above check to allow individual policy to
698 * determine when to exit a given state.
701 acpi_thermal_critical(tz);
703 acpi_thermal_hot(tz);
705 acpi_thermal_passive(tz);
707 acpi_thermal_active(tz);
712 * Again, separated from the above two to allow independent policy
715 if (tz->trips.critical.flags.enabled)
716 tz->state.critical = 1;
717 if (tz->trips.hot.flags.enabled)
719 if (tz->trips.passive.flags.enabled)
720 tz->state.passive = 1;
721 for (i=0; i<ACPI_THERMAL_MAX_ACTIVE; i++)
722 if (tz->trips.active[i].flags.enabled)
723 tz->state.active = 1;
726 * Calculate Sleep Time
727 * --------------------
728 * If we're in the passive state, use _TSP's value. Otherwise
729 * use the default polling frequency (e.g. _TZP). If no polling
730 * frequency is specified then we'll wait forever (at least until
731 * a thermal event occurs). Note that _TSP and _TZD values are
732 * given in 1/10th seconds (we must covert to milliseconds).
734 if (tz->state.passive)
735 sleep_time = tz->trips.passive.tsp * 100;
736 else if (tz->polling_frequency > 0)
737 sleep_time = tz->polling_frequency * 100;
739 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n",
740 tz->name, tz->temperature, sleep_time));
747 if (timer_pending(&(tz->timer)))
748 del_timer(&(tz->timer));
751 if (timer_pending(&(tz->timer)))
752 mod_timer(&(tz->timer), (HZ * sleep_time) / 1000);
754 tz->timer.data = (unsigned long) tz;
755 tz->timer.function = acpi_thermal_run;
756 tz->timer.expires = jiffies + (HZ * sleep_time) / 1000;
757 add_timer(&(tz->timer));
765 /* --------------------------------------------------------------------------
767 -------------------------------------------------------------------------- */
769 struct proc_dir_entry *acpi_thermal_dir;
771 static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
773 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
775 ACPI_FUNCTION_TRACE("acpi_thermal_state_seq_show");
780 seq_puts(seq, "state: ");
782 if (!tz->state.critical && !tz->state.hot && !tz->state.passive && !tz->state.active)
783 seq_puts(seq, "ok\n");
785 if (tz->state.critical)
786 seq_puts(seq, "critical ");
788 seq_puts(seq, "hot ");
789 if (tz->state.passive)
790 seq_puts(seq, "passive ");
791 if (tz->state.active)
792 seq_printf(seq, "active[%d]", tz->state.active_index);
800 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
802 return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
806 static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
809 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
811 ACPI_FUNCTION_TRACE("acpi_thermal_temp_seq_show");
816 result = acpi_thermal_get_temperature(tz);
820 seq_printf(seq, "temperature: %ld C\n",
821 KELVIN_TO_CELSIUS(tz->temperature));
827 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
829 return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
833 static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
835 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
839 ACPI_FUNCTION_TRACE("acpi_thermal_trip_seq_show");
844 if (tz->trips.critical.flags.valid)
845 seq_printf(seq, "critical (S5): %ld C\n",
846 KELVIN_TO_CELSIUS(tz->trips.critical.temperature));
848 if (tz->trips.hot.flags.valid)
849 seq_printf(seq, "hot (S4): %ld C\n",
850 KELVIN_TO_CELSIUS(tz->trips.hot.temperature));
852 if (tz->trips.passive.flags.valid) {
853 seq_printf(seq, "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
854 KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
855 tz->trips.passive.tc1,
856 tz->trips.passive.tc2,
857 tz->trips.passive.tsp);
858 for (j=0; j<tz->trips.passive.devices.count; j++) {
860 seq_printf(seq, "0x%p ", tz->trips.passive.devices.handles[j]);
865 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
866 if (!(tz->trips.active[i].flags.valid))
868 seq_printf(seq, "active[%d]: %ld C: devices=",
869 i, KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
870 for (j = 0; j < tz->trips.active[i].devices.count; j++)
871 seq_printf(seq, "0x%p ",
872 tz->trips.active[i].devices.handles[j]);
880 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
882 return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
886 acpi_thermal_write_trip_points (
888 const char __user *buffer,
892 struct seq_file *m = (struct seq_file *)file->private_data;
893 struct acpi_thermal *tz = (struct acpi_thermal *)m->private;
895 char limit_string[25] = {'\0'};
896 int critical, hot, passive, active0, active1;
898 ACPI_FUNCTION_TRACE("acpi_thermal_write_trip_points");
900 if (!tz || (count > sizeof(limit_string) - 1)) {
901 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument\n"));
902 return_VALUE(-EINVAL);
905 if (copy_from_user(limit_string, buffer, count)) {
906 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data\n"));
907 return_VALUE(-EFAULT);
910 limit_string[count] = '\0';
912 if (sscanf(limit_string, "%d:%d:%d:%d:%d", &critical, &hot, &passive, &active0, &active1) != 5) {
913 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data format\n"));
914 return_VALUE(-EINVAL);
917 tz->trips.critical.temperature = CELSIUS_TO_KELVIN(critical);
918 tz->trips.hot.temperature = CELSIUS_TO_KELVIN(hot);
919 tz->trips.passive.temperature = CELSIUS_TO_KELVIN(passive);
920 tz->trips.active[0].temperature = CELSIUS_TO_KELVIN(active0);
921 tz->trips.active[1].temperature = CELSIUS_TO_KELVIN(active1);
927 static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
929 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
931 ACPI_FUNCTION_TRACE("acpi_thermal_cooling_seq_show");
936 if (!tz->flags.cooling_mode) {
937 seq_puts(seq, "<not supported>\n");
941 seq_printf(seq, "cooling mode: %s\n",
942 tz->cooling_mode?"passive":"active");
948 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
950 return single_open(file, acpi_thermal_cooling_seq_show,
955 acpi_thermal_write_cooling_mode (
957 const char __user *buffer,
961 struct seq_file *m = (struct seq_file *)file->private_data;
962 struct acpi_thermal *tz = (struct acpi_thermal *)m->private;
964 char mode_string[12] = {'\0'};
966 ACPI_FUNCTION_TRACE("acpi_thermal_write_cooling_mode");
968 if (!tz || (count > sizeof(mode_string) - 1))
969 return_VALUE(-EINVAL);
971 if (!tz->flags.cooling_mode)
972 return_VALUE(-ENODEV);
974 if (copy_from_user(mode_string, buffer, count))
975 return_VALUE(-EFAULT);
977 mode_string[count] = '\0';
979 result = acpi_thermal_set_cooling_mode(tz,
980 simple_strtoul(mode_string, NULL, 0));
982 return_VALUE(result);
988 static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
990 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
992 ACPI_FUNCTION_TRACE("acpi_thermal_polling_seq_show");
997 if (!tz->polling_frequency) {
998 seq_puts(seq, "<polling disabled>\n");
1002 seq_printf(seq, "polling frequency: %lu seconds\n",
1003 (tz->polling_frequency / 10));
1009 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
1011 return single_open(file, acpi_thermal_polling_seq_show,
1016 acpi_thermal_write_polling (
1018 const char __user *buffer,
1022 struct seq_file *m = (struct seq_file *)file->private_data;
1023 struct acpi_thermal *tz = (struct acpi_thermal *)m->private;
1025 char polling_string[12] = {'\0'};
1028 ACPI_FUNCTION_TRACE("acpi_thermal_write_polling");
1030 if (!tz || (count > sizeof(polling_string) - 1))
1031 return_VALUE(-EINVAL);
1033 if (copy_from_user(polling_string, buffer, count))
1034 return_VALUE(-EFAULT);
1036 polling_string[count] = '\0';
1038 seconds = simple_strtoul(polling_string, NULL, 0);
1040 result = acpi_thermal_set_polling(tz, seconds);
1042 return_VALUE(result);
1044 acpi_thermal_check(tz);
1046 return_VALUE(count);
1051 acpi_thermal_add_fs (
1052 struct acpi_device *device)
1054 struct proc_dir_entry *entry = NULL;
1056 ACPI_FUNCTION_TRACE("acpi_thermal_add_fs");
1058 if (!acpi_device_dir(device)) {
1059 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1061 if (!acpi_device_dir(device))
1062 return_VALUE(-ENODEV);
1063 acpi_device_dir(device)->owner = THIS_MODULE;
1067 entry = create_proc_entry(ACPI_THERMAL_FILE_STATE,
1068 S_IRUGO, acpi_device_dir(device));
1070 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1071 "Unable to create '%s' fs entry\n",
1072 ACPI_THERMAL_FILE_STATE));
1074 entry->proc_fops = &acpi_thermal_state_fops;
1075 entry->data = acpi_driver_data(device);
1076 entry->owner = THIS_MODULE;
1079 /* 'temperature' [R] */
1080 entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1081 S_IRUGO, acpi_device_dir(device));
1083 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1084 "Unable to create '%s' fs entry\n",
1085 ACPI_THERMAL_FILE_TEMPERATURE));
1087 entry->proc_fops = &acpi_thermal_temp_fops;
1088 entry->data = acpi_driver_data(device);
1089 entry->owner = THIS_MODULE;
1092 /* 'trip_points' [R/W] */
1093 entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1094 S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
1096 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1097 "Unable to create '%s' fs entry\n",
1098 ACPI_THERMAL_FILE_TRIP_POINTS));
1100 entry->proc_fops = &acpi_thermal_trip_fops;
1101 entry->data = acpi_driver_data(device);
1102 entry->owner = THIS_MODULE;
1105 /* 'cooling_mode' [R/W] */
1106 entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1107 S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
1109 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1110 "Unable to create '%s' fs entry\n",
1111 ACPI_THERMAL_FILE_COOLING_MODE));
1113 entry->proc_fops = &acpi_thermal_cooling_fops;
1114 entry->data = acpi_driver_data(device);
1115 entry->owner = THIS_MODULE;
1118 /* 'polling_frequency' [R/W] */
1119 entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1120 S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
1122 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1123 "Unable to create '%s' fs entry\n",
1124 ACPI_THERMAL_FILE_POLLING_FREQ));
1126 entry->proc_fops = &acpi_thermal_polling_fops;
1127 entry->data = acpi_driver_data(device);
1128 entry->owner = THIS_MODULE;
1136 acpi_thermal_remove_fs (
1137 struct acpi_device *device)
1139 ACPI_FUNCTION_TRACE("acpi_thermal_remove_fs");
1141 if (acpi_device_dir(device)) {
1142 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1143 acpi_device_dir(device));
1144 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1145 acpi_device_dir(device));
1146 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1147 acpi_device_dir(device));
1148 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1149 acpi_device_dir(device));
1150 remove_proc_entry(ACPI_THERMAL_FILE_STATE,
1151 acpi_device_dir(device));
1152 remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
1153 acpi_device_dir(device) = NULL;
1160 /* --------------------------------------------------------------------------
1162 -------------------------------------------------------------------------- */
1165 acpi_thermal_notify (
1170 struct acpi_thermal *tz = (struct acpi_thermal *) data;
1171 struct acpi_device *device = NULL;
1173 ACPI_FUNCTION_TRACE("acpi_thermal_notify");
1178 if (acpi_bus_get_device(tz->handle, &device))
1182 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
1183 acpi_thermal_check(tz);
1185 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
1186 acpi_thermal_get_trip_points(tz);
1187 acpi_thermal_check(tz);
1188 acpi_bus_generate_event(device, event, 0);
1190 case ACPI_THERMAL_NOTIFY_DEVICES:
1191 if (tz->flags.devices)
1192 acpi_thermal_get_devices(tz);
1193 acpi_bus_generate_event(device, event, 0);
1196 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1197 "Unsupported event [0x%x]\n", event));
1206 acpi_thermal_get_info (
1207 struct acpi_thermal *tz)
1211 ACPI_FUNCTION_TRACE("acpi_thermal_get_info");
1214 return_VALUE(-EINVAL);
1216 /* Get temperature [_TMP] (required) */
1217 result = acpi_thermal_get_temperature(tz);
1219 return_VALUE(result);
1221 /* Set the cooling mode [_SCP] to active cooling (default) */
1222 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
1224 tz->flags.cooling_mode = 1;
1226 /* Get trip points [_CRT, _PSV, etc.] (required) */
1227 result = acpi_thermal_get_trip_points(tz);
1229 return_VALUE(result);
1231 /* Get default polling frequency [_TZP] (optional) */
1233 tz->polling_frequency = tzp;
1235 acpi_thermal_get_polling_frequency(tz);
1237 /* Get devices in this thermal zone [_TZD] (optional) */
1238 result = acpi_thermal_get_devices(tz);
1240 tz->flags.devices = 1;
1248 struct acpi_device *device)
1251 acpi_status status = AE_OK;
1252 struct acpi_thermal *tz = NULL;
1254 ACPI_FUNCTION_TRACE("acpi_thermal_add");
1257 return_VALUE(-EINVAL);
1259 tz = kmalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1261 return_VALUE(-ENOMEM);
1262 memset(tz, 0, sizeof(struct acpi_thermal));
1264 tz->handle = device->handle;
1265 strcpy(tz->name, device->pnp.bus_id);
1266 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1267 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
1268 acpi_driver_data(device) = tz;
1270 result = acpi_thermal_get_info(tz);
1274 result = acpi_thermal_add_fs(device);
1276 return_VALUE(result);
1278 init_timer(&tz->timer);
1280 acpi_thermal_check(tz);
1282 status = acpi_install_notify_handler(tz->handle,
1283 ACPI_DEVICE_NOTIFY, acpi_thermal_notify, tz);
1284 if (ACPI_FAILURE(status)) {
1285 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1286 "Error installing notify handler\n"));
1291 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
1292 acpi_device_name(device), acpi_device_bid(device),
1293 KELVIN_TO_CELSIUS(tz->temperature));
1297 acpi_thermal_remove_fs(device);
1301 return_VALUE(result);
1306 acpi_thermal_remove (
1307 struct acpi_device *device,
1310 acpi_status status = AE_OK;
1311 struct acpi_thermal *tz = NULL;
1313 ACPI_FUNCTION_TRACE("acpi_thermal_remove");
1315 if (!device || !acpi_driver_data(device))
1316 return_VALUE(-EINVAL);
1318 tz = (struct acpi_thermal *) acpi_driver_data(device);
1320 if (timer_pending(&(tz->timer)))
1321 del_timer(&(tz->timer));
1323 status = acpi_remove_notify_handler(tz->handle,
1324 ACPI_DEVICE_NOTIFY, acpi_thermal_notify);
1325 if (ACPI_FAILURE(status))
1326 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1327 "Error removing notify handler\n"));
1329 /* Terminate policy */
1330 if (tz->trips.passive.flags.valid
1331 && tz->trips.passive.flags.enabled) {
1332 tz->trips.passive.flags.enabled = 0;
1333 acpi_thermal_passive(tz);
1335 if (tz->trips.active[0].flags.valid
1336 && tz->trips.active[0].flags.enabled) {
1337 tz->trips.active[0].flags.enabled = 0;
1338 acpi_thermal_active(tz);
1341 acpi_thermal_remove_fs(device);
1348 acpi_thermal_init (void)
1352 ACPI_FUNCTION_TRACE("acpi_thermal_init");
1354 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
1355 if (!acpi_thermal_dir)
1356 return_VALUE(-ENODEV);
1357 acpi_thermal_dir->owner = THIS_MODULE;
1359 result = acpi_bus_register_driver(&acpi_thermal_driver);
1361 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1362 return_VALUE(-ENODEV);
1370 acpi_thermal_exit (void)
1372 ACPI_FUNCTION_TRACE("acpi_thermal_exit");
1374 acpi_bus_unregister_driver(&acpi_thermal_driver);
1376 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1382 module_init(acpi_thermal_init);
1383 module_exit(acpi_thermal_exit);