[PATCH] fix semaphore handling in __unregister_chrdev_region
[linux/fpc-iii.git] / drivers / acpi / thermal.c
blob79c3a686bc44217d2b9cd078bff1a89444659e2d
1 /*
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_MODE_CRITICAL 0xff
64 #define ACPI_THERMAL_PATH_POWEROFF "/sbin/poweroff"
66 #define ACPI_THERMAL_MAX_ACTIVE 10
67 #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
69 #define KELVIN_TO_CELSIUS(t) (long)(((long)t-2732>=0) ? ((long)t-2732+5)/10 : ((long)t-2732-5)/10)
70 #define CELSIUS_TO_KELVIN(t) ((t+273)*10)
72 #define _COMPONENT ACPI_THERMAL_COMPONENT
73 ACPI_MODULE_NAME ("acpi_thermal")
75 MODULE_AUTHOR("Paul Diefenbaugh");
76 MODULE_DESCRIPTION(ACPI_THERMAL_DRIVER_NAME);
77 MODULE_LICENSE("GPL");
79 static int tzp;
80 module_param(tzp, int, 0);
81 MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.\n");
84 static int acpi_thermal_add (struct acpi_device *device);
85 static int acpi_thermal_remove (struct acpi_device *device, int type);
86 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
87 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
88 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
89 static ssize_t acpi_thermal_write_trip_points (struct file*,const char __user *,size_t,loff_t *);
90 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
91 static ssize_t acpi_thermal_write_cooling_mode (struct file*,const char __user *,size_t,loff_t *);
92 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
93 static ssize_t acpi_thermal_write_polling(struct file*,const char __user *,size_t,loff_t *);
95 static struct acpi_driver acpi_thermal_driver = {
96 .name = ACPI_THERMAL_DRIVER_NAME,
97 .class = ACPI_THERMAL_CLASS,
98 .ids = ACPI_THERMAL_HID,
99 .ops = {
100 .add = acpi_thermal_add,
101 .remove = acpi_thermal_remove,
105 struct acpi_thermal_state {
106 u8 critical:1;
107 u8 hot:1;
108 u8 passive:1;
109 u8 active:1;
110 u8 reserved:4;
111 int active_index;
114 struct acpi_thermal_state_flags {
115 u8 valid:1;
116 u8 enabled:1;
117 u8 reserved:6;
120 struct acpi_thermal_critical {
121 struct acpi_thermal_state_flags flags;
122 unsigned long temperature;
125 struct acpi_thermal_hot {
126 struct acpi_thermal_state_flags flags;
127 unsigned long temperature;
130 struct acpi_thermal_passive {
131 struct acpi_thermal_state_flags flags;
132 unsigned long temperature;
133 unsigned long tc1;
134 unsigned long tc2;
135 unsigned long tsp;
136 struct acpi_handle_list devices;
139 struct acpi_thermal_active {
140 struct acpi_thermal_state_flags flags;
141 unsigned long temperature;
142 struct acpi_handle_list devices;
145 struct acpi_thermal_trips {
146 struct acpi_thermal_critical critical;
147 struct acpi_thermal_hot hot;
148 struct acpi_thermal_passive passive;
149 struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
152 struct acpi_thermal_flags {
153 u8 cooling_mode:1; /* _SCP */
154 u8 devices:1; /* _TZD */
155 u8 reserved:6;
158 struct acpi_thermal {
159 acpi_handle handle;
160 acpi_bus_id name;
161 unsigned long temperature;
162 unsigned long last_temperature;
163 unsigned long polling_frequency;
164 u8 cooling_mode;
165 volatile u8 zombie;
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 struct file_operations acpi_thermal_state_fops = {
174 .open = acpi_thermal_state_open_fs,
175 .read = seq_read,
176 .llseek = seq_lseek,
177 .release = single_release,
180 static struct file_operations acpi_thermal_temp_fops = {
181 .open = acpi_thermal_temp_open_fs,
182 .read = seq_read,
183 .llseek = seq_lseek,
184 .release = single_release,
187 static struct file_operations acpi_thermal_trip_fops = {
188 .open = acpi_thermal_trip_open_fs,
189 .read = seq_read,
190 .write = acpi_thermal_write_trip_points,
191 .llseek = seq_lseek,
192 .release = single_release,
195 static struct file_operations acpi_thermal_cooling_fops = {
196 .open = acpi_thermal_cooling_open_fs,
197 .read = seq_read,
198 .write = acpi_thermal_write_cooling_mode,
199 .llseek = seq_lseek,
200 .release = single_release,
203 static struct file_operations acpi_thermal_polling_fops = {
204 .open = acpi_thermal_polling_open_fs,
205 .read = seq_read,
206 .write = acpi_thermal_write_polling,
207 .llseek = seq_lseek,
208 .release = single_release,
211 /* --------------------------------------------------------------------------
212 Thermal Zone Management
213 -------------------------------------------------------------------------- */
215 static int
216 acpi_thermal_get_temperature (
217 struct acpi_thermal *tz)
219 acpi_status status = AE_OK;
221 ACPI_FUNCTION_TRACE("acpi_thermal_get_temperature");
223 if (!tz)
224 return_VALUE(-EINVAL);
226 tz->last_temperature = tz->temperature;
228 status = acpi_evaluate_integer(tz->handle, "_TMP", NULL, &tz->temperature);
229 if (ACPI_FAILURE(status))
230 return_VALUE(-ENODEV);
232 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n", tz->temperature));
234 return_VALUE(0);
238 static int
239 acpi_thermal_get_polling_frequency (
240 struct acpi_thermal *tz)
242 acpi_status status = AE_OK;
244 ACPI_FUNCTION_TRACE("acpi_thermal_get_polling_frequency");
246 if (!tz)
247 return_VALUE(-EINVAL);
249 status = acpi_evaluate_integer(tz->handle, "_TZP", NULL, &tz->polling_frequency);
250 if (ACPI_FAILURE(status))
251 return_VALUE(-ENODEV);
253 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n", tz->polling_frequency));
255 return_VALUE(0);
259 static int
260 acpi_thermal_set_polling (
261 struct acpi_thermal *tz,
262 int seconds)
264 ACPI_FUNCTION_TRACE("acpi_thermal_set_polling");
266 if (!tz)
267 return_VALUE(-EINVAL);
269 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
271 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency set to %lu seconds\n", tz->polling_frequency));
273 return_VALUE(0);
277 static int
278 acpi_thermal_set_cooling_mode (
279 struct acpi_thermal *tz,
280 int mode)
282 acpi_status status = AE_OK;
283 union acpi_object arg0 = {ACPI_TYPE_INTEGER};
284 struct acpi_object_list arg_list = {1, &arg0};
285 acpi_handle handle = NULL;
287 ACPI_FUNCTION_TRACE("acpi_thermal_set_cooling_mode");
289 if (!tz)
290 return_VALUE(-EINVAL);
292 status = acpi_get_handle(tz->handle, "_SCP", &handle);
293 if (ACPI_FAILURE(status)) {
294 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
295 return_VALUE(-ENODEV);
298 arg0.integer.value = mode;
300 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
301 if (ACPI_FAILURE(status))
302 return_VALUE(-ENODEV);
304 tz->cooling_mode = mode;
306 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Cooling mode [%s]\n",
307 mode?"passive":"active"));
309 return_VALUE(0);
313 static int
314 acpi_thermal_get_trip_points (
315 struct acpi_thermal *tz)
317 acpi_status status = AE_OK;
318 int i = 0;
320 ACPI_FUNCTION_TRACE("acpi_thermal_get_trip_points");
322 if (!tz)
323 return_VALUE(-EINVAL);
325 /* Critical Shutdown (required) */
327 status = acpi_evaluate_integer(tz->handle, "_CRT", NULL,
328 &tz->trips.critical.temperature);
329 if (ACPI_FAILURE(status)) {
330 tz->trips.critical.flags.valid = 0;
331 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "No critical threshold\n"));
332 return_VALUE(-ENODEV);
334 else {
335 tz->trips.critical.flags.valid = 1;
336 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found critical threshold [%lu]\n", tz->trips.critical.temperature));
339 /* Critical Sleep (optional) */
341 status = acpi_evaluate_integer(tz->handle, "_HOT", NULL, &tz->trips.hot.temperature);
342 if (ACPI_FAILURE(status)) {
343 tz->trips.hot.flags.valid = 0;
344 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No hot threshold\n"));
346 else {
347 tz->trips.hot.flags.valid = 1;
348 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found hot threshold [%lu]\n", tz->trips.hot.temperature));
351 /* Passive: Processors (optional) */
353 status = acpi_evaluate_integer(tz->handle, "_PSV", NULL, &tz->trips.passive.temperature);
354 if (ACPI_FAILURE(status)) {
355 tz->trips.passive.flags.valid = 0;
356 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No passive threshold\n"));
358 else {
359 tz->trips.passive.flags.valid = 1;
361 status = acpi_evaluate_integer(tz->handle, "_TC1", NULL, &tz->trips.passive.tc1);
362 if (ACPI_FAILURE(status))
363 tz->trips.passive.flags.valid = 0;
365 status = acpi_evaluate_integer(tz->handle, "_TC2", NULL, &tz->trips.passive.tc2);
366 if (ACPI_FAILURE(status))
367 tz->trips.passive.flags.valid = 0;
369 status = acpi_evaluate_integer(tz->handle, "_TSP", NULL, &tz->trips.passive.tsp);
370 if (ACPI_FAILURE(status))
371 tz->trips.passive.flags.valid = 0;
373 status = acpi_evaluate_reference(tz->handle, "_PSL", NULL, &tz->trips.passive.devices);
374 if (ACPI_FAILURE(status))
375 tz->trips.passive.flags.valid = 0;
377 if (!tz->trips.passive.flags.valid)
378 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid passive threshold\n"));
379 else
380 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found passive threshold [%lu]\n", 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'};
389 status = acpi_evaluate_integer(tz->handle, name, NULL, &tz->trips.active[i].temperature);
390 if (ACPI_FAILURE(status))
391 break;
393 name[2] = 'L';
394 status = acpi_evaluate_reference(tz->handle, name, NULL, &tz->trips.active[i].devices);
395 if (ACPI_SUCCESS(status)) {
396 tz->trips.active[i].flags.valid = 1;
397 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found active threshold [%d]:[%lu]\n", i, tz->trips.active[i].temperature));
399 else
400 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid active threshold [%d]\n", i));
403 return_VALUE(0);
407 static int
408 acpi_thermal_get_devices (
409 struct acpi_thermal *tz)
411 acpi_status status = AE_OK;
413 ACPI_FUNCTION_TRACE("acpi_thermal_get_devices");
415 if (!tz)
416 return_VALUE(-EINVAL);
418 status = acpi_evaluate_reference(tz->handle, "_TZD", NULL, &tz->devices);
419 if (ACPI_FAILURE(status))
420 return_VALUE(-ENODEV);
422 return_VALUE(0);
426 static int
427 acpi_thermal_call_usermode (
428 char *path)
430 char *argv[2] = {NULL, NULL};
431 char *envp[3] = {NULL, NULL, NULL};
433 ACPI_FUNCTION_TRACE("acpi_thermal_call_usermode");
435 if (!path)
436 return_VALUE(-EINVAL);
438 argv[0] = path;
440 /* minimal command environment */
441 envp[0] = "HOME=/";
442 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
444 call_usermodehelper(argv[0], argv, envp, 0);
446 return_VALUE(0);
450 static int
451 acpi_thermal_critical (
452 struct acpi_thermal *tz)
454 int result = 0;
455 struct acpi_device *device = NULL;
457 ACPI_FUNCTION_TRACE("acpi_thermal_critical");
459 if (!tz || !tz->trips.critical.flags.valid)
460 return_VALUE(-EINVAL);
462 if (tz->temperature >= tz->trips.critical.temperature) {
463 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Critical trip point\n"));
464 tz->trips.critical.flags.enabled = 1;
466 else if (tz->trips.critical.flags.enabled)
467 tz->trips.critical.flags.enabled = 0;
469 result = acpi_bus_get_device(tz->handle, &device);
470 if (result)
471 return_VALUE(result);
473 printk(KERN_EMERG "Critical temperature reached (%ld C), shutting down.\n", KELVIN_TO_CELSIUS(tz->temperature));
474 acpi_bus_generate_event(device, ACPI_THERMAL_NOTIFY_CRITICAL, tz->trips.critical.flags.enabled);
476 acpi_thermal_call_usermode(ACPI_THERMAL_PATH_POWEROFF);
478 return_VALUE(0);
482 static int
483 acpi_thermal_hot (
484 struct acpi_thermal *tz)
486 int result = 0;
487 struct acpi_device *device = NULL;
489 ACPI_FUNCTION_TRACE("acpi_thermal_hot");
491 if (!tz || !tz->trips.hot.flags.valid)
492 return_VALUE(-EINVAL);
494 if (tz->temperature >= tz->trips.hot.temperature) {
495 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Hot trip point\n"));
496 tz->trips.hot.flags.enabled = 1;
498 else if (tz->trips.hot.flags.enabled)
499 tz->trips.hot.flags.enabled = 0;
501 result = acpi_bus_get_device(tz->handle, &device);
502 if (result)
503 return_VALUE(result);
505 acpi_bus_generate_event(device, ACPI_THERMAL_NOTIFY_HOT, tz->trips.hot.flags.enabled);
507 /* TBD: Call user-mode "sleep(S4)" function */
509 return_VALUE(0);
513 static int
514 acpi_thermal_passive (
515 struct acpi_thermal *tz)
517 int result = 0;
518 struct acpi_thermal_passive *passive = NULL;
519 int trend = 0;
520 int i = 0;
522 ACPI_FUNCTION_TRACE("acpi_thermal_passive");
524 if (!tz || !tz->trips.passive.flags.valid)
525 return_VALUE(-EINVAL);
527 passive = &(tz->trips.passive);
530 * Above Trip?
531 * -----------
532 * Calculate the thermal trend (using the passive cooling equation)
533 * and modify the performance limit for all passive cooling devices
534 * accordingly. Note that we assume symmetry.
536 if (tz->temperature >= passive->temperature) {
537 trend = (passive->tc1 * (tz->temperature - tz->last_temperature)) + (passive->tc2 * (tz->temperature - passive->temperature));
538 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
539 "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
540 trend, passive->tc1, tz->temperature,
541 tz->last_temperature, passive->tc2,
542 tz->temperature, passive->temperature));
543 tz->trips.passive.flags.enabled = 1;
544 /* Heating up? */
545 if (trend > 0)
546 for (i=0; i<passive->devices.count; i++)
547 acpi_processor_set_thermal_limit(
548 passive->devices.handles[i],
549 ACPI_PROCESSOR_LIMIT_INCREMENT);
550 /* Cooling off? */
551 else if (trend < 0)
552 for (i=0; i<passive->devices.count; i++)
553 acpi_processor_set_thermal_limit(
554 passive->devices.handles[i],
555 ACPI_PROCESSOR_LIMIT_DECREMENT);
559 * Below Trip?
560 * -----------
561 * Implement passive cooling hysteresis to slowly increase performance
562 * and avoid thrashing around the passive trip point. Note that we
563 * assume symmetry.
565 else if (tz->trips.passive.flags.enabled) {
566 for (i=0; i<passive->devices.count; i++)
567 result = acpi_processor_set_thermal_limit(
568 passive->devices.handles[i],
569 ACPI_PROCESSOR_LIMIT_DECREMENT);
570 if (result == 1) {
571 tz->trips.passive.flags.enabled = 0;
572 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
573 "Disabling passive cooling (zone is cool)\n"));
577 return_VALUE(0);
581 static int
582 acpi_thermal_active (
583 struct acpi_thermal *tz)
585 int result = 0;
586 struct acpi_thermal_active *active = NULL;
587 int i = 0;
588 int j = 0;
589 unsigned long maxtemp = 0;
591 ACPI_FUNCTION_TRACE("acpi_thermal_active");
593 if (!tz)
594 return_VALUE(-EINVAL);
596 for (i=0; i<ACPI_THERMAL_MAX_ACTIVE; i++) {
598 active = &(tz->trips.active[i]);
599 if (!active || !active->flags.valid)
600 break;
603 * Above Threshold?
604 * ----------------
605 * If not already enabled, turn ON all cooling devices
606 * associated with this active threshold.
608 if (tz->temperature >= active->temperature) {
609 if (active->temperature > maxtemp)
610 tz->state.active_index = i, maxtemp = active->temperature;
611 if (!active->flags.enabled) {
612 for (j = 0; j < active->devices.count; j++) {
613 result = acpi_bus_set_power(active->devices.handles[j], ACPI_STATE_D0);
614 if (result) {
615 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Unable to turn cooling device [%p] 'on'\n", active->devices.handles[j]));
616 continue;
618 active->flags.enabled = 1;
619 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Cooling device [%p] now 'on'\n", active->devices.handles[j]));
624 * Below Threshold?
625 * ----------------
626 * Turn OFF all cooling devices associated with this
627 * threshold.
629 else if (active->flags.enabled) {
630 for (j = 0; j < active->devices.count; j++) {
631 result = acpi_bus_set_power(active->devices.handles[j], ACPI_STATE_D3);
632 if (result) {
633 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Unable to turn cooling device [%p] 'off'\n", active->devices.handles[j]));
634 continue;
636 active->flags.enabled = 0;
637 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Cooling device [%p] now 'off'\n", active->devices.handles[j]));
642 return_VALUE(0);
646 static void acpi_thermal_check (void *context);
648 static void
649 acpi_thermal_run (
650 unsigned long data)
652 struct acpi_thermal *tz = (struct acpi_thermal *)data;
653 if (!tz->zombie)
654 acpi_os_queue_for_execution(OSD_PRIORITY_GPE,
655 acpi_thermal_check, (void *) data);
659 static void
660 acpi_thermal_check (
661 void *data)
663 int result = 0;
664 struct acpi_thermal *tz = (struct acpi_thermal *) data;
665 unsigned long sleep_time = 0;
666 int i = 0;
667 struct acpi_thermal_state state;
669 ACPI_FUNCTION_TRACE("acpi_thermal_check");
671 if (!tz) {
672 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid (NULL) context.\n"));
673 return_VOID;
676 state = tz->state;
678 result = acpi_thermal_get_temperature(tz);
679 if (result)
680 return_VOID;
682 memset(&tz->state, 0, sizeof(tz->state));
685 * Check Trip Points
686 * -----------------
687 * Compare the current temperature to the trip point values to see
688 * if we've entered one of the thermal policy states. Note that
689 * this function determines when a state is entered, but the
690 * individual policy decides when it is exited (e.g. hysteresis).
692 if (tz->trips.critical.flags.valid)
693 state.critical |= (tz->temperature >= tz->trips.critical.temperature);
694 if (tz->trips.hot.flags.valid)
695 state.hot |= (tz->temperature >= tz->trips.hot.temperature);
696 if (tz->trips.passive.flags.valid)
697 state.passive |= (tz->temperature >= tz->trips.passive.temperature);
698 for (i=0; i<ACPI_THERMAL_MAX_ACTIVE; i++)
699 if (tz->trips.active[i].flags.valid)
700 state.active |= (tz->temperature >= tz->trips.active[i].temperature);
703 * Invoke Policy
704 * -------------
705 * Separated from the above check to allow individual policy to
706 * determine when to exit a given state.
708 if (state.critical)
709 acpi_thermal_critical(tz);
710 if (state.hot)
711 acpi_thermal_hot(tz);
712 if (state.passive)
713 acpi_thermal_passive(tz);
714 if (state.active)
715 acpi_thermal_active(tz);
718 * Calculate State
719 * ---------------
720 * Again, separated from the above two to allow independent policy
721 * decisions.
723 if (tz->trips.critical.flags.enabled)
724 tz->state.critical = 1;
725 if (tz->trips.hot.flags.enabled)
726 tz->state.hot = 1;
727 if (tz->trips.passive.flags.enabled)
728 tz->state.passive = 1;
729 for (i=0; i<ACPI_THERMAL_MAX_ACTIVE; i++)
730 if (tz->trips.active[i].flags.enabled)
731 tz->state.active = 1;
734 * Calculate Sleep Time
735 * --------------------
736 * If we're in the passive state, use _TSP's value. Otherwise
737 * use the default polling frequency (e.g. _TZP). If no polling
738 * frequency is specified then we'll wait forever (at least until
739 * a thermal event occurs). Note that _TSP and _TZD values are
740 * given in 1/10th seconds (we must covert to milliseconds).
742 if (tz->state.passive)
743 sleep_time = tz->trips.passive.tsp * 100;
744 else if (tz->polling_frequency > 0)
745 sleep_time = tz->polling_frequency * 100;
747 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n",
748 tz->name, tz->temperature, sleep_time));
751 * Schedule Next Poll
752 * ------------------
754 if (!sleep_time) {
755 if (timer_pending(&(tz->timer)))
756 del_timer(&(tz->timer));
758 else {
759 if (timer_pending(&(tz->timer)))
760 mod_timer(&(tz->timer), (HZ * sleep_time) / 1000);
761 else {
762 tz->timer.data = (unsigned long) tz;
763 tz->timer.function = acpi_thermal_run;
764 tz->timer.expires = jiffies + (HZ * sleep_time) / 1000;
765 add_timer(&(tz->timer));
769 return_VOID;
773 /* --------------------------------------------------------------------------
774 FS Interface (/proc)
775 -------------------------------------------------------------------------- */
777 static struct proc_dir_entry *acpi_thermal_dir;
779 static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
781 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
783 ACPI_FUNCTION_TRACE("acpi_thermal_state_seq_show");
785 if (!tz)
786 goto end;
788 seq_puts(seq, "state: ");
790 if (!tz->state.critical && !tz->state.hot && !tz->state.passive && !tz->state.active)
791 seq_puts(seq, "ok\n");
792 else {
793 if (tz->state.critical)
794 seq_puts(seq, "critical ");
795 if (tz->state.hot)
796 seq_puts(seq, "hot ");
797 if (tz->state.passive)
798 seq_puts(seq, "passive ");
799 if (tz->state.active)
800 seq_printf(seq, "active[%d]", tz->state.active_index);
801 seq_puts(seq, "\n");
804 end:
805 return_VALUE(0);
808 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
810 return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
814 static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
816 int result = 0;
817 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
819 ACPI_FUNCTION_TRACE("acpi_thermal_temp_seq_show");
821 if (!tz)
822 goto end;
824 result = acpi_thermal_get_temperature(tz);
825 if (result)
826 goto end;
828 seq_printf(seq, "temperature: %ld C\n",
829 KELVIN_TO_CELSIUS(tz->temperature));
831 end:
832 return_VALUE(0);
835 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
837 return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
841 static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
843 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
844 int i = 0;
845 int j = 0;
847 ACPI_FUNCTION_TRACE("acpi_thermal_trip_seq_show");
849 if (!tz)
850 goto end;
852 if (tz->trips.critical.flags.valid)
853 seq_printf(seq, "critical (S5): %ld C\n",
854 KELVIN_TO_CELSIUS(tz->trips.critical.temperature));
856 if (tz->trips.hot.flags.valid)
857 seq_printf(seq, "hot (S4): %ld C\n",
858 KELVIN_TO_CELSIUS(tz->trips.hot.temperature));
860 if (tz->trips.passive.flags.valid) {
861 seq_printf(seq, "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
862 KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
863 tz->trips.passive.tc1,
864 tz->trips.passive.tc2,
865 tz->trips.passive.tsp);
866 for (j=0; j<tz->trips.passive.devices.count; j++) {
868 seq_printf(seq, "0x%p ", tz->trips.passive.devices.handles[j]);
870 seq_puts(seq, "\n");
873 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
874 if (!(tz->trips.active[i].flags.valid))
875 break;
876 seq_printf(seq, "active[%d]: %ld C: devices=",
877 i, KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
878 for (j = 0; j < tz->trips.active[i].devices.count; j++)
879 seq_printf(seq, "0x%p ",
880 tz->trips.active[i].devices.handles[j]);
881 seq_puts(seq, "\n");
884 end:
885 return_VALUE(0);
888 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
890 return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
893 static ssize_t
894 acpi_thermal_write_trip_points (
895 struct file *file,
896 const char __user *buffer,
897 size_t count,
898 loff_t *ppos)
900 struct seq_file *m = (struct seq_file *)file->private_data;
901 struct acpi_thermal *tz = (struct acpi_thermal *)m->private;
903 char *limit_string;
904 int num, critical, hot, passive;
905 int *active;
906 int i = 0;
908 ACPI_FUNCTION_TRACE("acpi_thermal_write_trip_points");
910 limit_string = kmalloc(ACPI_THERMAL_MAX_LIMIT_STR_LEN, GFP_KERNEL);
911 if(!limit_string)
912 return_VALUE(-ENOMEM);
914 memset(limit_string, 0, ACPI_THERMAL_MAX_LIMIT_STR_LEN);
916 active = kmalloc(ACPI_THERMAL_MAX_ACTIVE *sizeof(int), GFP_KERNEL);
917 if(!active)
918 return_VALUE(-ENOMEM);
920 if (!tz || (count > ACPI_THERMAL_MAX_LIMIT_STR_LEN - 1)) {
921 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument\n"));
922 count = -EINVAL;
923 goto end;
926 if (copy_from_user(limit_string, buffer, count)) {
927 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data\n"));
928 count = -EFAULT;
929 goto end;
932 limit_string[count] = '\0';
934 num = sscanf(limit_string, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d",
935 &critical, &hot, &passive,
936 &active[0], &active[1], &active[2], &active[3], &active[4],
937 &active[5], &active[6], &active[7], &active[8], &active[9]);
938 if(!(num >=5 && num < (ACPI_THERMAL_MAX_ACTIVE + 3))) {
939 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data format\n"));
940 count = -EINVAL;
941 goto end;
944 tz->trips.critical.temperature = CELSIUS_TO_KELVIN(critical);
945 tz->trips.hot.temperature = CELSIUS_TO_KELVIN(hot);
946 tz->trips.passive.temperature = CELSIUS_TO_KELVIN(passive);
947 for (i = 0; i < num - 3; i++) {
948 if (!(tz->trips.active[i].flags.valid))
949 break;
950 tz->trips.active[i].temperature = CELSIUS_TO_KELVIN(active[i]);
953 end:
954 kfree(active);
955 kfree(limit_string);
956 return_VALUE(count);
960 static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
962 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
964 ACPI_FUNCTION_TRACE("acpi_thermal_cooling_seq_show");
966 if (!tz)
967 goto end;
969 if (!tz->flags.cooling_mode) {
970 seq_puts(seq, "<setting not supported>\n");
973 if ( tz->cooling_mode == ACPI_THERMAL_MODE_CRITICAL )
974 seq_printf(seq, "cooling mode: critical\n");
975 else
976 seq_printf(seq, "cooling mode: %s\n",
977 tz->cooling_mode?"passive":"active");
979 end:
980 return_VALUE(0);
983 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
985 return single_open(file, acpi_thermal_cooling_seq_show,
986 PDE(inode)->data);
989 static ssize_t
990 acpi_thermal_write_cooling_mode (
991 struct file *file,
992 const char __user *buffer,
993 size_t count,
994 loff_t *ppos)
996 struct seq_file *m = (struct seq_file *)file->private_data;
997 struct acpi_thermal *tz = (struct acpi_thermal *)m->private;
998 int result = 0;
999 char mode_string[12] = {'\0'};
1001 ACPI_FUNCTION_TRACE("acpi_thermal_write_cooling_mode");
1003 if (!tz || (count > sizeof(mode_string) - 1))
1004 return_VALUE(-EINVAL);
1006 if (!tz->flags.cooling_mode)
1007 return_VALUE(-ENODEV);
1009 if (copy_from_user(mode_string, buffer, count))
1010 return_VALUE(-EFAULT);
1012 mode_string[count] = '\0';
1014 result = acpi_thermal_set_cooling_mode(tz,
1015 simple_strtoul(mode_string, NULL, 0));
1016 if (result)
1017 return_VALUE(result);
1019 acpi_thermal_check(tz);
1021 return_VALUE(count);
1025 static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
1027 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
1029 ACPI_FUNCTION_TRACE("acpi_thermal_polling_seq_show");
1031 if (!tz)
1032 goto end;
1034 if (!tz->polling_frequency) {
1035 seq_puts(seq, "<polling disabled>\n");
1036 goto end;
1039 seq_printf(seq, "polling frequency: %lu seconds\n",
1040 (tz->polling_frequency / 10));
1042 end:
1043 return_VALUE(0);
1046 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
1048 return single_open(file, acpi_thermal_polling_seq_show,
1049 PDE(inode)->data);
1052 static ssize_t
1053 acpi_thermal_write_polling (
1054 struct file *file,
1055 const char __user *buffer,
1056 size_t count,
1057 loff_t *ppos)
1059 struct seq_file *m = (struct seq_file *)file->private_data;
1060 struct acpi_thermal *tz = (struct acpi_thermal *)m->private;
1061 int result = 0;
1062 char polling_string[12] = {'\0'};
1063 int seconds = 0;
1065 ACPI_FUNCTION_TRACE("acpi_thermal_write_polling");
1067 if (!tz || (count > sizeof(polling_string) - 1))
1068 return_VALUE(-EINVAL);
1070 if (copy_from_user(polling_string, buffer, count))
1071 return_VALUE(-EFAULT);
1073 polling_string[count] = '\0';
1075 seconds = simple_strtoul(polling_string, NULL, 0);
1077 result = acpi_thermal_set_polling(tz, seconds);
1078 if (result)
1079 return_VALUE(result);
1081 acpi_thermal_check(tz);
1083 return_VALUE(count);
1087 static int
1088 acpi_thermal_add_fs (
1089 struct acpi_device *device)
1091 struct proc_dir_entry *entry = NULL;
1093 ACPI_FUNCTION_TRACE("acpi_thermal_add_fs");
1095 if (!acpi_device_dir(device)) {
1096 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1097 acpi_thermal_dir);
1098 if (!acpi_device_dir(device))
1099 return_VALUE(-ENODEV);
1100 acpi_device_dir(device)->owner = THIS_MODULE;
1103 /* 'state' [R] */
1104 entry = create_proc_entry(ACPI_THERMAL_FILE_STATE,
1105 S_IRUGO, acpi_device_dir(device));
1106 if (!entry)
1107 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1108 "Unable to create '%s' fs entry\n",
1109 ACPI_THERMAL_FILE_STATE));
1110 else {
1111 entry->proc_fops = &acpi_thermal_state_fops;
1112 entry->data = acpi_driver_data(device);
1113 entry->owner = THIS_MODULE;
1116 /* 'temperature' [R] */
1117 entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1118 S_IRUGO, acpi_device_dir(device));
1119 if (!entry)
1120 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1121 "Unable to create '%s' fs entry\n",
1122 ACPI_THERMAL_FILE_TEMPERATURE));
1123 else {
1124 entry->proc_fops = &acpi_thermal_temp_fops;
1125 entry->data = acpi_driver_data(device);
1126 entry->owner = THIS_MODULE;
1129 /* 'trip_points' [R/W] */
1130 entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1131 S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
1132 if (!entry)
1133 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1134 "Unable to create '%s' fs entry\n",
1135 ACPI_THERMAL_FILE_TRIP_POINTS));
1136 else {
1137 entry->proc_fops = &acpi_thermal_trip_fops;
1138 entry->data = acpi_driver_data(device);
1139 entry->owner = THIS_MODULE;
1142 /* 'cooling_mode' [R/W] */
1143 entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1144 S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
1145 if (!entry)
1146 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1147 "Unable to create '%s' fs entry\n",
1148 ACPI_THERMAL_FILE_COOLING_MODE));
1149 else {
1150 entry->proc_fops = &acpi_thermal_cooling_fops;
1151 entry->data = acpi_driver_data(device);
1152 entry->owner = THIS_MODULE;
1155 /* 'polling_frequency' [R/W] */
1156 entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1157 S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
1158 if (!entry)
1159 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1160 "Unable to create '%s' fs entry\n",
1161 ACPI_THERMAL_FILE_POLLING_FREQ));
1162 else {
1163 entry->proc_fops = &acpi_thermal_polling_fops;
1164 entry->data = acpi_driver_data(device);
1165 entry->owner = THIS_MODULE;
1168 return_VALUE(0);
1172 static int
1173 acpi_thermal_remove_fs (
1174 struct acpi_device *device)
1176 ACPI_FUNCTION_TRACE("acpi_thermal_remove_fs");
1178 if (acpi_device_dir(device)) {
1179 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1180 acpi_device_dir(device));
1181 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1182 acpi_device_dir(device));
1183 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1184 acpi_device_dir(device));
1185 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1186 acpi_device_dir(device));
1187 remove_proc_entry(ACPI_THERMAL_FILE_STATE,
1188 acpi_device_dir(device));
1189 remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
1190 acpi_device_dir(device) = NULL;
1193 return_VALUE(0);
1197 /* --------------------------------------------------------------------------
1198 Driver Interface
1199 -------------------------------------------------------------------------- */
1201 static void
1202 acpi_thermal_notify (
1203 acpi_handle handle,
1204 u32 event,
1205 void *data)
1207 struct acpi_thermal *tz = (struct acpi_thermal *) data;
1208 struct acpi_device *device = NULL;
1210 ACPI_FUNCTION_TRACE("acpi_thermal_notify");
1212 if (!tz)
1213 return_VOID;
1215 if (acpi_bus_get_device(tz->handle, &device))
1216 return_VOID;
1218 switch (event) {
1219 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
1220 acpi_thermal_check(tz);
1221 break;
1222 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
1223 acpi_thermal_get_trip_points(tz);
1224 acpi_thermal_check(tz);
1225 acpi_bus_generate_event(device, event, 0);
1226 break;
1227 case ACPI_THERMAL_NOTIFY_DEVICES:
1228 if (tz->flags.devices)
1229 acpi_thermal_get_devices(tz);
1230 acpi_bus_generate_event(device, event, 0);
1231 break;
1232 default:
1233 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1234 "Unsupported event [0x%x]\n", event));
1235 break;
1238 return_VOID;
1242 static int
1243 acpi_thermal_get_info (
1244 struct acpi_thermal *tz)
1246 int result = 0;
1248 ACPI_FUNCTION_TRACE("acpi_thermal_get_info");
1250 if (!tz)
1251 return_VALUE(-EINVAL);
1253 /* Get temperature [_TMP] (required) */
1254 result = acpi_thermal_get_temperature(tz);
1255 if (result)
1256 return_VALUE(result);
1258 /* Get trip points [_CRT, _PSV, etc.] (required) */
1259 result = acpi_thermal_get_trip_points(tz);
1260 if (result)
1261 return_VALUE(result);
1263 /* Set the cooling mode [_SCP] to active cooling (default) */
1264 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
1265 if (!result)
1266 tz->flags.cooling_mode = 1;
1267 else {
1268 /* Oh,we have not _SCP method.
1269 Generally show cooling_mode by _ACx, _PSV,spec 12.2*/
1270 tz->flags.cooling_mode = 0;
1271 if ( tz->trips.active[0].flags.valid && tz->trips.passive.flags.valid ) {
1272 if ( tz->trips.passive.temperature > tz->trips.active[0].temperature )
1273 tz->cooling_mode = ACPI_THERMAL_MODE_ACTIVE;
1274 else
1275 tz->cooling_mode = ACPI_THERMAL_MODE_PASSIVE;
1276 } else if ( !tz->trips.active[0].flags.valid && tz->trips.passive.flags.valid ) {
1277 tz->cooling_mode = ACPI_THERMAL_MODE_PASSIVE;
1278 } else if ( tz->trips.active[0].flags.valid && !tz->trips.passive.flags.valid ) {
1279 tz->cooling_mode = ACPI_THERMAL_MODE_ACTIVE;
1280 } else {
1281 /* _ACx and _PSV are optional, but _CRT is required */
1282 tz->cooling_mode = ACPI_THERMAL_MODE_CRITICAL;
1286 /* Get default polling frequency [_TZP] (optional) */
1287 if (tzp)
1288 tz->polling_frequency = tzp;
1289 else
1290 acpi_thermal_get_polling_frequency(tz);
1292 /* Get devices in this thermal zone [_TZD] (optional) */
1293 result = acpi_thermal_get_devices(tz);
1294 if (!result)
1295 tz->flags.devices = 1;
1297 return_VALUE(0);
1301 static int
1302 acpi_thermal_add (
1303 struct acpi_device *device)
1305 int result = 0;
1306 acpi_status status = AE_OK;
1307 struct acpi_thermal *tz = NULL;
1309 ACPI_FUNCTION_TRACE("acpi_thermal_add");
1311 if (!device)
1312 return_VALUE(-EINVAL);
1314 tz = kmalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1315 if (!tz)
1316 return_VALUE(-ENOMEM);
1317 memset(tz, 0, sizeof(struct acpi_thermal));
1319 tz->handle = device->handle;
1320 strcpy(tz->name, device->pnp.bus_id);
1321 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1322 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
1323 acpi_driver_data(device) = tz;
1325 result = acpi_thermal_get_info(tz);
1326 if (result)
1327 goto end;
1329 result = acpi_thermal_add_fs(device);
1330 if (result)
1331 return_VALUE(result);
1333 init_timer(&tz->timer);
1335 acpi_thermal_check(tz);
1337 status = acpi_install_notify_handler(tz->handle,
1338 ACPI_DEVICE_NOTIFY, acpi_thermal_notify, tz);
1339 if (ACPI_FAILURE(status)) {
1340 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1341 "Error installing notify handler\n"));
1342 result = -ENODEV;
1343 goto end;
1346 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
1347 acpi_device_name(device), acpi_device_bid(device),
1348 KELVIN_TO_CELSIUS(tz->temperature));
1350 end:
1351 if (result) {
1352 acpi_thermal_remove_fs(device);
1353 kfree(tz);
1356 return_VALUE(result);
1360 static int
1361 acpi_thermal_remove (
1362 struct acpi_device *device,
1363 int type)
1365 acpi_status status = AE_OK;
1366 struct acpi_thermal *tz = NULL;
1368 ACPI_FUNCTION_TRACE("acpi_thermal_remove");
1370 if (!device || !acpi_driver_data(device))
1371 return_VALUE(-EINVAL);
1373 tz = (struct acpi_thermal *) acpi_driver_data(device);
1375 /* avoid timer adding new defer task */
1376 tz->zombie = 1;
1377 /* wait for running timer (on other CPUs) finish */
1378 del_timer_sync(&(tz->timer));
1379 /* synchronize deferred task */
1380 acpi_os_wait_events_complete(NULL);
1381 /* deferred task may reinsert timer */
1382 del_timer_sync(&(tz->timer));
1384 status = acpi_remove_notify_handler(tz->handle,
1385 ACPI_DEVICE_NOTIFY, acpi_thermal_notify);
1386 if (ACPI_FAILURE(status))
1387 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1388 "Error removing notify handler\n"));
1390 /* Terminate policy */
1391 if (tz->trips.passive.flags.valid
1392 && tz->trips.passive.flags.enabled) {
1393 tz->trips.passive.flags.enabled = 0;
1394 acpi_thermal_passive(tz);
1396 if (tz->trips.active[0].flags.valid
1397 && tz->trips.active[0].flags.enabled) {
1398 tz->trips.active[0].flags.enabled = 0;
1399 acpi_thermal_active(tz);
1402 acpi_thermal_remove_fs(device);
1404 kfree(tz);
1405 return_VALUE(0);
1409 static int __init
1410 acpi_thermal_init (void)
1412 int result = 0;
1414 ACPI_FUNCTION_TRACE("acpi_thermal_init");
1416 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
1417 if (!acpi_thermal_dir)
1418 return_VALUE(-ENODEV);
1419 acpi_thermal_dir->owner = THIS_MODULE;
1421 result = acpi_bus_register_driver(&acpi_thermal_driver);
1422 if (result < 0) {
1423 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1424 return_VALUE(-ENODEV);
1427 return_VALUE(0);
1431 static void __exit
1432 acpi_thermal_exit (void)
1434 ACPI_FUNCTION_TRACE("acpi_thermal_exit");
1436 acpi_bus_unregister_driver(&acpi_thermal_driver);
1438 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1440 return_VOID;
1444 module_init(acpi_thermal_init);
1445 module_exit(acpi_thermal_exit);