Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * acpi_thermal.c - ACPI Thermal Zone Driver ($Revision: 41 $) | |
3 | * | |
4 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> | |
5 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | |
6 | * | |
7 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
8 | * | |
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. | |
13 | * | |
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. | |
18 | * | |
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. | |
22 | * | |
23 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
24 | * | |
25 | * This driver fully implements the ACPI thermal policy as described in the | |
26 | * ACPI 2.0 Specification. | |
27 | * | |
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. | |
31 | * | |
32 | */ | |
33 | ||
34 | #include <linux/kernel.h> | |
35 | #include <linux/module.h> | |
0b5bfa1c | 36 | #include <linux/dmi.h> |
1da177e4 LT |
37 | #include <linux/init.h> |
38 | #include <linux/types.h> | |
39 | #include <linux/proc_fs.h> | |
cd354f1a TS |
40 | #include <linux/timer.h> |
41 | #include <linux/jiffies.h> | |
1da177e4 LT |
42 | #include <linux/kmod.h> |
43 | #include <linux/seq_file.h> | |
10a0a8d4 | 44 | #include <linux/reboot.h> |
1da177e4 LT |
45 | #include <asm/uaccess.h> |
46 | ||
47 | #include <acpi/acpi_bus.h> | |
48 | #include <acpi/acpi_drivers.h> | |
49 | ||
50 | #define ACPI_THERMAL_COMPONENT 0x04000000 | |
51 | #define ACPI_THERMAL_CLASS "thermal_zone" | |
1da177e4 LT |
52 | #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone" |
53 | #define ACPI_THERMAL_FILE_STATE "state" | |
54 | #define ACPI_THERMAL_FILE_TEMPERATURE "temperature" | |
55 | #define ACPI_THERMAL_FILE_TRIP_POINTS "trip_points" | |
56 | #define ACPI_THERMAL_FILE_COOLING_MODE "cooling_mode" | |
57 | #define ACPI_THERMAL_FILE_POLLING_FREQ "polling_frequency" | |
58 | #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80 | |
59 | #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81 | |
60 | #define ACPI_THERMAL_NOTIFY_DEVICES 0x82 | |
61 | #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0 | |
62 | #define ACPI_THERMAL_NOTIFY_HOT 0xF1 | |
63 | #define ACPI_THERMAL_MODE_ACTIVE 0x00 | |
1da177e4 LT |
64 | |
65 | #define ACPI_THERMAL_MAX_ACTIVE 10 | |
66 | #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65 | |
67 | ||
68 | #define KELVIN_TO_CELSIUS(t) (long)(((long)t-2732>=0) ? ((long)t-2732+5)/10 : ((long)t-2732-5)/10) | |
69 | #define CELSIUS_TO_KELVIN(t) ((t+273)*10) | |
70 | ||
71 | #define _COMPONENT ACPI_THERMAL_COMPONENT | |
f52fd66d | 72 | ACPI_MODULE_NAME("thermal"); |
1da177e4 | 73 | |
1cbf4c56 | 74 | MODULE_AUTHOR("Paul Diefenbaugh"); |
7cda93e0 | 75 | MODULE_DESCRIPTION("ACPI Thermal Zone Driver"); |
1da177e4 LT |
76 | MODULE_LICENSE("GPL"); |
77 | ||
f8707ec9 LB |
78 | static int act; |
79 | module_param(act, int, 0644); | |
3c1d36da | 80 | MODULE_PARM_DESC(act, "Disable or override all lowest active trip points."); |
f8707ec9 | 81 | |
c52a7419 LB |
82 | static int crt; |
83 | module_param(crt, int, 0644); | |
84 | MODULE_PARM_DESC(crt, "Disable or lower all critical trip points."); | |
85 | ||
1da177e4 | 86 | static int tzp; |
730ff34d | 87 | module_param(tzp, int, 0444); |
3c1d36da | 88 | MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds."); |
1da177e4 | 89 | |
f5487145 LB |
90 | static int nocrt; |
91 | module_param(nocrt, int, 0); | |
8c99fdce | 92 | MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points."); |
f5487145 | 93 | |
72b33ef8 LB |
94 | static int off; |
95 | module_param(off, int, 0); | |
3c1d36da | 96 | MODULE_PARM_DESC(off, "Set to disable ACPI thermal support."); |
72b33ef8 | 97 | |
a70cdc52 LB |
98 | static int psv; |
99 | module_param(psv, int, 0644); | |
3c1d36da | 100 | MODULE_PARM_DESC(psv, "Disable or override all passive trip points."); |
a70cdc52 | 101 | |
4be44fcd LB |
102 | static int acpi_thermal_add(struct acpi_device *device); |
103 | static int acpi_thermal_remove(struct acpi_device *device, int type); | |
5d9464a4 | 104 | static int acpi_thermal_resume(struct acpi_device *device); |
1da177e4 LT |
105 | static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file); |
106 | static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file); | |
107 | static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file); | |
1da177e4 | 108 | static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file); |
4be44fcd LB |
109 | static ssize_t acpi_thermal_write_cooling_mode(struct file *, |
110 | const char __user *, size_t, | |
111 | loff_t *); | |
1da177e4 | 112 | static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file); |
4be44fcd LB |
113 | static ssize_t acpi_thermal_write_polling(struct file *, const char __user *, |
114 | size_t, loff_t *); | |
1da177e4 | 115 | |
1ba90e3a TR |
116 | static const struct acpi_device_id thermal_device_ids[] = { |
117 | {ACPI_THERMAL_HID, 0}, | |
118 | {"", 0}, | |
119 | }; | |
120 | MODULE_DEVICE_TABLE(acpi, thermal_device_ids); | |
121 | ||
1da177e4 | 122 | static struct acpi_driver acpi_thermal_driver = { |
c2b6705b | 123 | .name = "thermal", |
4be44fcd | 124 | .class = ACPI_THERMAL_CLASS, |
1ba90e3a | 125 | .ids = thermal_device_ids, |
4be44fcd LB |
126 | .ops = { |
127 | .add = acpi_thermal_add, | |
128 | .remove = acpi_thermal_remove, | |
74ce1468 | 129 | .resume = acpi_thermal_resume, |
4be44fcd | 130 | }, |
1da177e4 LT |
131 | }; |
132 | ||
133 | struct acpi_thermal_state { | |
4be44fcd LB |
134 | u8 critical:1; |
135 | u8 hot:1; | |
136 | u8 passive:1; | |
137 | u8 active:1; | |
138 | u8 reserved:4; | |
139 | int active_index; | |
1da177e4 LT |
140 | }; |
141 | ||
142 | struct acpi_thermal_state_flags { | |
4be44fcd LB |
143 | u8 valid:1; |
144 | u8 enabled:1; | |
145 | u8 reserved:6; | |
1da177e4 LT |
146 | }; |
147 | ||
148 | struct acpi_thermal_critical { | |
149 | struct acpi_thermal_state_flags flags; | |
4be44fcd | 150 | unsigned long temperature; |
1da177e4 LT |
151 | }; |
152 | ||
153 | struct acpi_thermal_hot { | |
154 | struct acpi_thermal_state_flags flags; | |
4be44fcd | 155 | unsigned long temperature; |
1da177e4 LT |
156 | }; |
157 | ||
158 | struct acpi_thermal_passive { | |
159 | struct acpi_thermal_state_flags flags; | |
4be44fcd LB |
160 | unsigned long temperature; |
161 | unsigned long tc1; | |
162 | unsigned long tc2; | |
163 | unsigned long tsp; | |
164 | struct acpi_handle_list devices; | |
1da177e4 LT |
165 | }; |
166 | ||
167 | struct acpi_thermal_active { | |
168 | struct acpi_thermal_state_flags flags; | |
4be44fcd LB |
169 | unsigned long temperature; |
170 | struct acpi_handle_list devices; | |
1da177e4 LT |
171 | }; |
172 | ||
173 | struct acpi_thermal_trips { | |
174 | struct acpi_thermal_critical critical; | |
4be44fcd | 175 | struct acpi_thermal_hot hot; |
1da177e4 LT |
176 | struct acpi_thermal_passive passive; |
177 | struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE]; | |
178 | }; | |
179 | ||
180 | struct acpi_thermal_flags { | |
4be44fcd LB |
181 | u8 cooling_mode:1; /* _SCP */ |
182 | u8 devices:1; /* _TZD */ | |
183 | u8 reserved:6; | |
1da177e4 LT |
184 | }; |
185 | ||
186 | struct acpi_thermal { | |
8348e1b1 | 187 | struct acpi_device * device; |
4be44fcd LB |
188 | acpi_bus_id name; |
189 | unsigned long temperature; | |
190 | unsigned long last_temperature; | |
191 | unsigned long polling_frequency; | |
4be44fcd | 192 | volatile u8 zombie; |
1da177e4 LT |
193 | struct acpi_thermal_flags flags; |
194 | struct acpi_thermal_state state; | |
195 | struct acpi_thermal_trips trips; | |
4be44fcd LB |
196 | struct acpi_handle_list devices; |
197 | struct timer_list timer; | |
1da177e4 LT |
198 | }; |
199 | ||
d7508032 | 200 | static const struct file_operations acpi_thermal_state_fops = { |
4be44fcd LB |
201 | .open = acpi_thermal_state_open_fs, |
202 | .read = seq_read, | |
203 | .llseek = seq_lseek, | |
204 | .release = single_release, | |
1da177e4 LT |
205 | }; |
206 | ||
d7508032 | 207 | static const struct file_operations acpi_thermal_temp_fops = { |
4be44fcd LB |
208 | .open = acpi_thermal_temp_open_fs, |
209 | .read = seq_read, | |
210 | .llseek = seq_lseek, | |
211 | .release = single_release, | |
1da177e4 LT |
212 | }; |
213 | ||
d7508032 | 214 | static const struct file_operations acpi_thermal_trip_fops = { |
4be44fcd LB |
215 | .open = acpi_thermal_trip_open_fs, |
216 | .read = seq_read, | |
4be44fcd LB |
217 | .llseek = seq_lseek, |
218 | .release = single_release, | |
1da177e4 LT |
219 | }; |
220 | ||
d7508032 | 221 | static const struct file_operations acpi_thermal_cooling_fops = { |
4be44fcd LB |
222 | .open = acpi_thermal_cooling_open_fs, |
223 | .read = seq_read, | |
224 | .write = acpi_thermal_write_cooling_mode, | |
225 | .llseek = seq_lseek, | |
226 | .release = single_release, | |
1da177e4 LT |
227 | }; |
228 | ||
d7508032 | 229 | static const struct file_operations acpi_thermal_polling_fops = { |
4be44fcd LB |
230 | .open = acpi_thermal_polling_open_fs, |
231 | .read = seq_read, | |
232 | .write = acpi_thermal_write_polling, | |
233 | .llseek = seq_lseek, | |
234 | .release = single_release, | |
1da177e4 LT |
235 | }; |
236 | ||
237 | /* -------------------------------------------------------------------------- | |
238 | Thermal Zone Management | |
239 | -------------------------------------------------------------------------- */ | |
240 | ||
4be44fcd | 241 | static int acpi_thermal_get_temperature(struct acpi_thermal *tz) |
1da177e4 | 242 | { |
4be44fcd | 243 | acpi_status status = AE_OK; |
1da177e4 | 244 | |
1da177e4 LT |
245 | |
246 | if (!tz) | |
d550d98d | 247 | return -EINVAL; |
1da177e4 LT |
248 | |
249 | tz->last_temperature = tz->temperature; | |
250 | ||
4be44fcd | 251 | status = |
38ba7c9e | 252 | acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tz->temperature); |
1da177e4 | 253 | if (ACPI_FAILURE(status)) |
d550d98d | 254 | return -ENODEV; |
1da177e4 | 255 | |
4be44fcd LB |
256 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n", |
257 | tz->temperature)); | |
1da177e4 | 258 | |
d550d98d | 259 | return 0; |
1da177e4 LT |
260 | } |
261 | ||
4be44fcd | 262 | static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz) |
1da177e4 | 263 | { |
4be44fcd | 264 | acpi_status status = AE_OK; |
1da177e4 | 265 | |
1da177e4 LT |
266 | |
267 | if (!tz) | |
d550d98d | 268 | return -EINVAL; |
1da177e4 | 269 | |
4be44fcd | 270 | status = |
38ba7c9e | 271 | acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, |
4be44fcd | 272 | &tz->polling_frequency); |
1da177e4 | 273 | if (ACPI_FAILURE(status)) |
d550d98d | 274 | return -ENODEV; |
1da177e4 | 275 | |
4be44fcd LB |
276 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n", |
277 | tz->polling_frequency)); | |
1da177e4 | 278 | |
d550d98d | 279 | return 0; |
1da177e4 LT |
280 | } |
281 | ||
4be44fcd | 282 | static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds) |
1da177e4 | 283 | { |
1da177e4 LT |
284 | |
285 | if (!tz) | |
d550d98d | 286 | return -EINVAL; |
1da177e4 LT |
287 | |
288 | tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */ | |
289 | ||
4be44fcd LB |
290 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
291 | "Polling frequency set to %lu seconds\n", | |
636cedf9 | 292 | tz->polling_frequency/10)); |
1da177e4 | 293 | |
d550d98d | 294 | return 0; |
1da177e4 LT |
295 | } |
296 | ||
4be44fcd | 297 | static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode) |
1da177e4 | 298 | { |
4be44fcd LB |
299 | acpi_status status = AE_OK; |
300 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | |
301 | struct acpi_object_list arg_list = { 1, &arg0 }; | |
302 | acpi_handle handle = NULL; | |
1da177e4 | 303 | |
1da177e4 LT |
304 | |
305 | if (!tz) | |
d550d98d | 306 | return -EINVAL; |
1da177e4 | 307 | |
38ba7c9e | 308 | status = acpi_get_handle(tz->device->handle, "_SCP", &handle); |
1da177e4 LT |
309 | if (ACPI_FAILURE(status)) { |
310 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n")); | |
d550d98d | 311 | return -ENODEV; |
1da177e4 LT |
312 | } |
313 | ||
314 | arg0.integer.value = mode; | |
315 | ||
316 | status = acpi_evaluate_object(handle, NULL, &arg_list, NULL); | |
317 | if (ACPI_FAILURE(status)) | |
d550d98d | 318 | return -ENODEV; |
1da177e4 | 319 | |
d550d98d | 320 | return 0; |
1da177e4 LT |
321 | } |
322 | ||
4be44fcd | 323 | static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) |
1da177e4 | 324 | { |
4be44fcd LB |
325 | acpi_status status = AE_OK; |
326 | int i = 0; | |
1da177e4 | 327 | |
1da177e4 LT |
328 | |
329 | if (!tz) | |
d550d98d | 330 | return -EINVAL; |
1da177e4 LT |
331 | |
332 | /* Critical Shutdown (required) */ | |
333 | ||
38ba7c9e | 334 | status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, |
4be44fcd | 335 | &tz->trips.critical.temperature); |
1da177e4 LT |
336 | if (ACPI_FAILURE(status)) { |
337 | tz->trips.critical.flags.valid = 0; | |
a6fc6720 | 338 | ACPI_EXCEPTION((AE_INFO, status, "No critical threshold")); |
d550d98d | 339 | return -ENODEV; |
4be44fcd | 340 | } else { |
1da177e4 | 341 | tz->trips.critical.flags.valid = 1; |
4be44fcd LB |
342 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
343 | "Found critical threshold [%lu]\n", | |
344 | tz->trips.critical.temperature)); | |
1da177e4 LT |
345 | } |
346 | ||
c52a7419 LB |
347 | if (tz->trips.critical.flags.valid == 1) { |
348 | if (crt == -1) { | |
349 | tz->trips.critical.flags.valid = 0; | |
350 | } else if (crt > 0) { | |
351 | unsigned long crt_k = CELSIUS_TO_KELVIN(crt); | |
352 | ||
353 | /* | |
354 | * Allow override to lower critical threshold | |
355 | */ | |
356 | if (crt_k < tz->trips.critical.temperature) | |
357 | tz->trips.critical.temperature = crt_k; | |
358 | } | |
359 | } | |
360 | ||
1da177e4 LT |
361 | /* Critical Sleep (optional) */ |
362 | ||
4be44fcd | 363 | status = |
38ba7c9e | 364 | acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, |
4be44fcd | 365 | &tz->trips.hot.temperature); |
1da177e4 LT |
366 | if (ACPI_FAILURE(status)) { |
367 | tz->trips.hot.flags.valid = 0; | |
368 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No hot threshold\n")); | |
4be44fcd | 369 | } else { |
1da177e4 | 370 | tz->trips.hot.flags.valid = 1; |
4be44fcd LB |
371 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found hot threshold [%lu]\n", |
372 | tz->trips.hot.temperature)); | |
1da177e4 LT |
373 | } |
374 | ||
375 | /* Passive: Processors (optional) */ | |
376 | ||
a70cdc52 LB |
377 | if (psv == -1) { |
378 | status = AE_SUPPORT; | |
379 | } else if (psv > 0) { | |
380 | tz->trips.passive.temperature = CELSIUS_TO_KELVIN(psv); | |
381 | status = AE_OK; | |
382 | } else { | |
383 | status = acpi_evaluate_integer(tz->device->handle, | |
384 | "_PSV", NULL, &tz->trips.passive.temperature); | |
385 | } | |
386 | ||
1da177e4 LT |
387 | if (ACPI_FAILURE(status)) { |
388 | tz->trips.passive.flags.valid = 0; | |
389 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No passive threshold\n")); | |
4be44fcd | 390 | } else { |
1da177e4 LT |
391 | tz->trips.passive.flags.valid = 1; |
392 | ||
4be44fcd | 393 | status = |
38ba7c9e | 394 | acpi_evaluate_integer(tz->device->handle, "_TC1", NULL, |
4be44fcd | 395 | &tz->trips.passive.tc1); |
1da177e4 LT |
396 | if (ACPI_FAILURE(status)) |
397 | tz->trips.passive.flags.valid = 0; | |
398 | ||
4be44fcd | 399 | status = |
38ba7c9e | 400 | acpi_evaluate_integer(tz->device->handle, "_TC2", NULL, |
4be44fcd | 401 | &tz->trips.passive.tc2); |
1da177e4 LT |
402 | if (ACPI_FAILURE(status)) |
403 | tz->trips.passive.flags.valid = 0; | |
404 | ||
4be44fcd | 405 | status = |
38ba7c9e | 406 | acpi_evaluate_integer(tz->device->handle, "_TSP", NULL, |
4be44fcd | 407 | &tz->trips.passive.tsp); |
1da177e4 LT |
408 | if (ACPI_FAILURE(status)) |
409 | tz->trips.passive.flags.valid = 0; | |
410 | ||
4be44fcd | 411 | status = |
38ba7c9e | 412 | acpi_evaluate_reference(tz->device->handle, "_PSL", NULL, |
4be44fcd | 413 | &tz->trips.passive.devices); |
1da177e4 LT |
414 | if (ACPI_FAILURE(status)) |
415 | tz->trips.passive.flags.valid = 0; | |
416 | ||
417 | if (!tz->trips.passive.flags.valid) | |
cece9296 | 418 | printk(KERN_WARNING PREFIX "Invalid passive threshold\n"); |
1da177e4 | 419 | else |
4be44fcd LB |
420 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
421 | "Found passive threshold [%lu]\n", | |
422 | tz->trips.passive.temperature)); | |
1da177e4 LT |
423 | } |
424 | ||
425 | /* Active: Fans, etc. (optional) */ | |
426 | ||
4be44fcd | 427 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
1da177e4 | 428 | |
4be44fcd | 429 | char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; |
1da177e4 | 430 | |
f8707ec9 LB |
431 | if (act == -1) |
432 | break; /* disable all active trip points */ | |
433 | ||
434 | status = acpi_evaluate_integer(tz->device->handle, | |
435 | name, NULL, &tz->trips.active[i].temperature); | |
436 | ||
437 | if (ACPI_FAILURE(status)) { | |
438 | if (i == 0) /* no active trip points */ | |
439 | break; | |
440 | if (act <= 0) /* no override requested */ | |
441 | break; | |
442 | if (i == 1) { /* 1 trip point */ | |
443 | tz->trips.active[0].temperature = | |
444 | CELSIUS_TO_KELVIN(act); | |
445 | } else { /* multiple trips */ | |
446 | /* | |
447 | * Don't allow override higher than | |
448 | * the next higher trip point | |
449 | */ | |
450 | tz->trips.active[i - 1].temperature = | |
451 | (tz->trips.active[i - 2].temperature < | |
452 | CELSIUS_TO_KELVIN(act) ? | |
453 | tz->trips.active[i - 2].temperature : | |
454 | CELSIUS_TO_KELVIN(act)); | |
455 | } | |
1da177e4 | 456 | break; |
f8707ec9 | 457 | } |
1da177e4 LT |
458 | |
459 | name[2] = 'L'; | |
4be44fcd | 460 | status = |
38ba7c9e | 461 | acpi_evaluate_reference(tz->device->handle, name, NULL, |
4be44fcd | 462 | &tz->trips.active[i].devices); |
1da177e4 LT |
463 | if (ACPI_SUCCESS(status)) { |
464 | tz->trips.active[i].flags.valid = 1; | |
4be44fcd LB |
465 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
466 | "Found active threshold [%d]:[%lu]\n", | |
467 | i, tz->trips.active[i].temperature)); | |
468 | } else | |
a6fc6720 TR |
469 | ACPI_EXCEPTION((AE_INFO, status, |
470 | "Invalid active threshold [%d]", i)); | |
1da177e4 LT |
471 | } |
472 | ||
d550d98d | 473 | return 0; |
1da177e4 LT |
474 | } |
475 | ||
4be44fcd | 476 | static int acpi_thermal_get_devices(struct acpi_thermal *tz) |
1da177e4 | 477 | { |
4be44fcd | 478 | acpi_status status = AE_OK; |
1da177e4 | 479 | |
1da177e4 LT |
480 | |
481 | if (!tz) | |
d550d98d | 482 | return -EINVAL; |
1da177e4 | 483 | |
4be44fcd | 484 | status = |
38ba7c9e | 485 | acpi_evaluate_reference(tz->device->handle, "_TZD", NULL, &tz->devices); |
1da177e4 | 486 | if (ACPI_FAILURE(status)) |
d550d98d | 487 | return -ENODEV; |
1da177e4 | 488 | |
d550d98d | 489 | return 0; |
1da177e4 LT |
490 | } |
491 | ||
4be44fcd | 492 | static int acpi_thermal_critical(struct acpi_thermal *tz) |
1da177e4 | 493 | { |
f5487145 | 494 | if (!tz || !tz->trips.critical.flags.valid || nocrt) |
d550d98d | 495 | return -EINVAL; |
1da177e4 LT |
496 | |
497 | if (tz->temperature >= tz->trips.critical.temperature) { | |
cece9296 | 498 | printk(KERN_WARNING PREFIX "Critical trip point\n"); |
1da177e4 | 499 | tz->trips.critical.flags.enabled = 1; |
4be44fcd | 500 | } else if (tz->trips.critical.flags.enabled) |
1da177e4 LT |
501 | tz->trips.critical.flags.enabled = 0; |
502 | ||
4be44fcd LB |
503 | printk(KERN_EMERG |
504 | "Critical temperature reached (%ld C), shutting down.\n", | |
505 | KELVIN_TO_CELSIUS(tz->temperature)); | |
14e04fb3 | 506 | acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL, |
4be44fcd | 507 | tz->trips.critical.flags.enabled); |
962ce8ca ZR |
508 | acpi_bus_generate_netlink_event(tz->device->pnp.device_class, |
509 | tz->device->dev.bus_id, | |
510 | ACPI_THERMAL_NOTIFY_CRITICAL, | |
511 | tz->trips.critical.flags.enabled); | |
1da177e4 | 512 | |
10a0a8d4 | 513 | orderly_poweroff(true); |
1da177e4 | 514 | |
d550d98d | 515 | return 0; |
1da177e4 LT |
516 | } |
517 | ||
4be44fcd | 518 | static int acpi_thermal_hot(struct acpi_thermal *tz) |
1da177e4 | 519 | { |
f5487145 | 520 | if (!tz || !tz->trips.hot.flags.valid || nocrt) |
d550d98d | 521 | return -EINVAL; |
1da177e4 LT |
522 | |
523 | if (tz->temperature >= tz->trips.hot.temperature) { | |
cece9296 | 524 | printk(KERN_WARNING PREFIX "Hot trip point\n"); |
1da177e4 | 525 | tz->trips.hot.flags.enabled = 1; |
4be44fcd | 526 | } else if (tz->trips.hot.flags.enabled) |
1da177e4 LT |
527 | tz->trips.hot.flags.enabled = 0; |
528 | ||
14e04fb3 | 529 | acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_HOT, |
4be44fcd | 530 | tz->trips.hot.flags.enabled); |
962ce8ca ZR |
531 | acpi_bus_generate_netlink_event(tz->device->pnp.device_class, |
532 | tz->device->dev.bus_id, | |
533 | ACPI_THERMAL_NOTIFY_HOT, | |
534 | tz->trips.hot.flags.enabled); | |
1da177e4 LT |
535 | |
536 | /* TBD: Call user-mode "sleep(S4)" function */ | |
537 | ||
d550d98d | 538 | return 0; |
1da177e4 LT |
539 | } |
540 | ||
1cbf4c56 | 541 | static void acpi_thermal_passive(struct acpi_thermal *tz) |
1da177e4 | 542 | { |
1cbf4c56 | 543 | int result = 1; |
1da177e4 | 544 | struct acpi_thermal_passive *passive = NULL; |
4be44fcd LB |
545 | int trend = 0; |
546 | int i = 0; | |
1da177e4 | 547 | |
1da177e4 LT |
548 | |
549 | if (!tz || !tz->trips.passive.flags.valid) | |
1cbf4c56 | 550 | return; |
1da177e4 LT |
551 | |
552 | passive = &(tz->trips.passive); | |
553 | ||
554 | /* | |
555 | * Above Trip? | |
556 | * ----------- | |
557 | * Calculate the thermal trend (using the passive cooling equation) | |
558 | * and modify the performance limit for all passive cooling devices | |
559 | * accordingly. Note that we assume symmetry. | |
560 | */ | |
561 | if (tz->temperature >= passive->temperature) { | |
4be44fcd LB |
562 | trend = |
563 | (passive->tc1 * (tz->temperature - tz->last_temperature)) + | |
564 | (passive->tc2 * (tz->temperature - passive->temperature)); | |
565 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
566 | "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n", | |
567 | trend, passive->tc1, tz->temperature, | |
568 | tz->last_temperature, passive->tc2, | |
569 | tz->temperature, passive->temperature)); | |
1cbf4c56 | 570 | passive->flags.enabled = 1; |
1da177e4 LT |
571 | /* Heating up? */ |
572 | if (trend > 0) | |
4be44fcd LB |
573 | for (i = 0; i < passive->devices.count; i++) |
574 | acpi_processor_set_thermal_limit(passive-> | |
575 | devices. | |
576 | handles[i], | |
577 | ACPI_PROCESSOR_LIMIT_INCREMENT); | |
1da177e4 | 578 | /* Cooling off? */ |
1cbf4c56 | 579 | else if (trend < 0) { |
4be44fcd | 580 | for (i = 0; i < passive->devices.count; i++) |
1cbf4c56 TR |
581 | /* |
582 | * assume that we are on highest | |
583 | * freq/lowest thrott and can leave | |
584 | * passive mode, even in error case | |
585 | */ | |
586 | if (!acpi_processor_set_thermal_limit | |
587 | (passive->devices.handles[i], | |
588 | ACPI_PROCESSOR_LIMIT_DECREMENT)) | |
589 | result = 0; | |
590 | /* | |
591 | * Leave cooling mode, even if the temp might | |
592 | * higher than trip point This is because some | |
593 | * machines might have long thermal polling | |
594 | * frequencies (tsp) defined. We will fall back | |
595 | * into passive mode in next cycle (probably quicker) | |
596 | */ | |
597 | if (result) { | |
598 | passive->flags.enabled = 0; | |
599 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
600 | "Disabling passive cooling, still above threshold," | |
601 | " but we are cooling down\n")); | |
602 | } | |
603 | } | |
604 | return; | |
1da177e4 LT |
605 | } |
606 | ||
607 | /* | |
608 | * Below Trip? | |
609 | * ----------- | |
610 | * Implement passive cooling hysteresis to slowly increase performance | |
611 | * and avoid thrashing around the passive trip point. Note that we | |
612 | * assume symmetry. | |
613 | */ | |
1cbf4c56 TR |
614 | if (!passive->flags.enabled) |
615 | return; | |
616 | for (i = 0; i < passive->devices.count; i++) | |
617 | if (!acpi_processor_set_thermal_limit | |
618 | (passive->devices.handles[i], | |
619 | ACPI_PROCESSOR_LIMIT_DECREMENT)) | |
620 | result = 0; | |
621 | if (result) { | |
622 | passive->flags.enabled = 0; | |
623 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
624 | "Disabling passive cooling (zone is cool)\n")); | |
1da177e4 | 625 | } |
1da177e4 LT |
626 | } |
627 | ||
1cbf4c56 | 628 | static void acpi_thermal_active(struct acpi_thermal *tz) |
1da177e4 | 629 | { |
4be44fcd | 630 | int result = 0; |
1da177e4 | 631 | struct acpi_thermal_active *active = NULL; |
4be44fcd LB |
632 | int i = 0; |
633 | int j = 0; | |
634 | unsigned long maxtemp = 0; | |
1da177e4 | 635 | |
1da177e4 LT |
636 | |
637 | if (!tz) | |
1cbf4c56 | 638 | return; |
1da177e4 | 639 | |
4be44fcd | 640 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
1da177e4 LT |
641 | active = &(tz->trips.active[i]); |
642 | if (!active || !active->flags.valid) | |
643 | break; | |
1da177e4 | 644 | if (tz->temperature >= active->temperature) { |
1cbf4c56 TR |
645 | /* |
646 | * Above Threshold? | |
647 | * ---------------- | |
648 | * If not already enabled, turn ON all cooling devices | |
649 | * associated with this active threshold. | |
650 | */ | |
1da177e4 | 651 | if (active->temperature > maxtemp) |
1cbf4c56 TR |
652 | tz->state.active_index = i; |
653 | maxtemp = active->temperature; | |
654 | if (active->flags.enabled) | |
655 | continue; | |
1da177e4 | 656 | for (j = 0; j < active->devices.count; j++) { |
4be44fcd LB |
657 | result = |
658 | acpi_bus_set_power(active->devices. | |
659 | handles[j], | |
1cbf4c56 | 660 | ACPI_STATE_D0); |
1da177e4 | 661 | if (result) { |
cece9296 LB |
662 | printk(KERN_WARNING PREFIX |
663 | "Unable to turn cooling device [%p] 'on'\n", | |
a6fc6720 | 664 | active->devices. |
cece9296 | 665 | handles[j]); |
1da177e4 LT |
666 | continue; |
667 | } | |
1cbf4c56 | 668 | active->flags.enabled = 1; |
4be44fcd | 669 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
1cbf4c56 | 670 | "Cooling device [%p] now 'on'\n", |
4be44fcd | 671 | active->devices.handles[j])); |
1da177e4 | 672 | } |
1cbf4c56 TR |
673 | continue; |
674 | } | |
675 | if (!active->flags.enabled) | |
676 | continue; | |
677 | /* | |
678 | * Below Threshold? | |
679 | * ---------------- | |
680 | * Turn OFF all cooling devices associated with this | |
681 | * threshold. | |
682 | */ | |
683 | for (j = 0; j < active->devices.count; j++) { | |
684 | result = acpi_bus_set_power(active->devices.handles[j], | |
685 | ACPI_STATE_D3); | |
686 | if (result) { | |
cece9296 LB |
687 | printk(KERN_WARNING PREFIX |
688 | "Unable to turn cooling device [%p] 'off'\n", | |
689 | active->devices.handles[j]); | |
1cbf4c56 TR |
690 | continue; |
691 | } | |
692 | active->flags.enabled = 0; | |
693 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
694 | "Cooling device [%p] now 'off'\n", | |
695 | active->devices.handles[j])); | |
1da177e4 LT |
696 | } |
697 | } | |
1da177e4 LT |
698 | } |
699 | ||
4be44fcd | 700 | static void acpi_thermal_check(void *context); |
1da177e4 | 701 | |
4be44fcd | 702 | static void acpi_thermal_run(unsigned long data) |
1da177e4 LT |
703 | { |
704 | struct acpi_thermal *tz = (struct acpi_thermal *)data; | |
705 | if (!tz->zombie) | |
b8d35192 | 706 | acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data); |
1da177e4 LT |
707 | } |
708 | ||
4be44fcd | 709 | static void acpi_thermal_check(void *data) |
1da177e4 | 710 | { |
4be44fcd | 711 | int result = 0; |
50dd0969 | 712 | struct acpi_thermal *tz = data; |
4be44fcd LB |
713 | unsigned long sleep_time = 0; |
714 | int i = 0; | |
1da177e4 LT |
715 | struct acpi_thermal_state state; |
716 | ||
1da177e4 LT |
717 | |
718 | if (!tz) { | |
6468463a | 719 | printk(KERN_ERR PREFIX "Invalid (NULL) context\n"); |
d550d98d | 720 | return; |
1da177e4 LT |
721 | } |
722 | ||
723 | state = tz->state; | |
724 | ||
725 | result = acpi_thermal_get_temperature(tz); | |
726 | if (result) | |
d550d98d | 727 | return; |
4be44fcd | 728 | |
1da177e4 | 729 | memset(&tz->state, 0, sizeof(tz->state)); |
4be44fcd | 730 | |
1da177e4 LT |
731 | /* |
732 | * Check Trip Points | |
733 | * ----------------- | |
734 | * Compare the current temperature to the trip point values to see | |
735 | * if we've entered one of the thermal policy states. Note that | |
736 | * this function determines when a state is entered, but the | |
737 | * individual policy decides when it is exited (e.g. hysteresis). | |
738 | */ | |
739 | if (tz->trips.critical.flags.valid) | |
4be44fcd LB |
740 | state.critical |= |
741 | (tz->temperature >= tz->trips.critical.temperature); | |
1da177e4 LT |
742 | if (tz->trips.hot.flags.valid) |
743 | state.hot |= (tz->temperature >= tz->trips.hot.temperature); | |
744 | if (tz->trips.passive.flags.valid) | |
4be44fcd LB |
745 | state.passive |= |
746 | (tz->temperature >= tz->trips.passive.temperature); | |
747 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) | |
1da177e4 | 748 | if (tz->trips.active[i].flags.valid) |
4be44fcd LB |
749 | state.active |= |
750 | (tz->temperature >= | |
751 | tz->trips.active[i].temperature); | |
1da177e4 LT |
752 | |
753 | /* | |
754 | * Invoke Policy | |
755 | * ------------- | |
756 | * Separated from the above check to allow individual policy to | |
757 | * determine when to exit a given state. | |
758 | */ | |
759 | if (state.critical) | |
760 | acpi_thermal_critical(tz); | |
761 | if (state.hot) | |
762 | acpi_thermal_hot(tz); | |
763 | if (state.passive) | |
764 | acpi_thermal_passive(tz); | |
765 | if (state.active) | |
766 | acpi_thermal_active(tz); | |
767 | ||
768 | /* | |
769 | * Calculate State | |
770 | * --------------- | |
771 | * Again, separated from the above two to allow independent policy | |
772 | * decisions. | |
773 | */ | |
1cbf4c56 TR |
774 | tz->state.critical = tz->trips.critical.flags.enabled; |
775 | tz->state.hot = tz->trips.hot.flags.enabled; | |
776 | tz->state.passive = tz->trips.passive.flags.enabled; | |
777 | tz->state.active = 0; | |
4be44fcd | 778 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) |
1cbf4c56 | 779 | tz->state.active |= tz->trips.active[i].flags.enabled; |
1da177e4 LT |
780 | |
781 | /* | |
782 | * Calculate Sleep Time | |
783 | * -------------------- | |
784 | * If we're in the passive state, use _TSP's value. Otherwise | |
785 | * use the default polling frequency (e.g. _TZP). If no polling | |
786 | * frequency is specified then we'll wait forever (at least until | |
787 | * a thermal event occurs). Note that _TSP and _TZD values are | |
788 | * given in 1/10th seconds (we must covert to milliseconds). | |
789 | */ | |
790 | if (tz->state.passive) | |
791 | sleep_time = tz->trips.passive.tsp * 100; | |
792 | else if (tz->polling_frequency > 0) | |
793 | sleep_time = tz->polling_frequency * 100; | |
794 | ||
4be44fcd LB |
795 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n", |
796 | tz->name, tz->temperature, sleep_time)); | |
1da177e4 LT |
797 | |
798 | /* | |
799 | * Schedule Next Poll | |
800 | * ------------------ | |
801 | */ | |
802 | if (!sleep_time) { | |
803 | if (timer_pending(&(tz->timer))) | |
804 | del_timer(&(tz->timer)); | |
4be44fcd | 805 | } else { |
1da177e4 | 806 | if (timer_pending(&(tz->timer))) |
94e22e13 AM |
807 | mod_timer(&(tz->timer), |
808 | jiffies + (HZ * sleep_time) / 1000); | |
1da177e4 | 809 | else { |
4be44fcd | 810 | tz->timer.data = (unsigned long)tz; |
1da177e4 LT |
811 | tz->timer.function = acpi_thermal_run; |
812 | tz->timer.expires = jiffies + (HZ * sleep_time) / 1000; | |
813 | add_timer(&(tz->timer)); | |
814 | } | |
815 | } | |
816 | ||
d550d98d | 817 | return; |
1da177e4 LT |
818 | } |
819 | ||
1da177e4 LT |
820 | /* -------------------------------------------------------------------------- |
821 | FS Interface (/proc) | |
822 | -------------------------------------------------------------------------- */ | |
823 | ||
4be44fcd | 824 | static struct proc_dir_entry *acpi_thermal_dir; |
1da177e4 LT |
825 | |
826 | static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset) | |
827 | { | |
50dd0969 | 828 | struct acpi_thermal *tz = seq->private; |
1da177e4 | 829 | |
1da177e4 LT |
830 | |
831 | if (!tz) | |
832 | goto end; | |
833 | ||
834 | seq_puts(seq, "state: "); | |
835 | ||
4be44fcd LB |
836 | if (!tz->state.critical && !tz->state.hot && !tz->state.passive |
837 | && !tz->state.active) | |
1da177e4 LT |
838 | seq_puts(seq, "ok\n"); |
839 | else { | |
840 | if (tz->state.critical) | |
841 | seq_puts(seq, "critical "); | |
842 | if (tz->state.hot) | |
843 | seq_puts(seq, "hot "); | |
844 | if (tz->state.passive) | |
845 | seq_puts(seq, "passive "); | |
846 | if (tz->state.active) | |
847 | seq_printf(seq, "active[%d]", tz->state.active_index); | |
848 | seq_puts(seq, "\n"); | |
849 | } | |
850 | ||
4be44fcd | 851 | end: |
d550d98d | 852 | return 0; |
1da177e4 LT |
853 | } |
854 | ||
855 | static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file) | |
856 | { | |
857 | return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data); | |
858 | } | |
859 | ||
1da177e4 LT |
860 | static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset) |
861 | { | |
4be44fcd | 862 | int result = 0; |
50dd0969 | 863 | struct acpi_thermal *tz = seq->private; |
1da177e4 | 864 | |
1da177e4 LT |
865 | |
866 | if (!tz) | |
867 | goto end; | |
868 | ||
869 | result = acpi_thermal_get_temperature(tz); | |
870 | if (result) | |
871 | goto end; | |
872 | ||
4be44fcd LB |
873 | seq_printf(seq, "temperature: %ld C\n", |
874 | KELVIN_TO_CELSIUS(tz->temperature)); | |
1da177e4 | 875 | |
4be44fcd | 876 | end: |
d550d98d | 877 | return 0; |
1da177e4 LT |
878 | } |
879 | ||
880 | static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file) | |
881 | { | |
882 | return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data); | |
883 | } | |
884 | ||
1da177e4 LT |
885 | static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset) |
886 | { | |
50dd0969 | 887 | struct acpi_thermal *tz = seq->private; |
68ccfaa8 | 888 | struct acpi_device *device; |
e7c746ef TR |
889 | acpi_status status; |
890 | ||
4be44fcd LB |
891 | int i = 0; |
892 | int j = 0; | |
1da177e4 | 893 | |
1da177e4 LT |
894 | |
895 | if (!tz) | |
896 | goto end; | |
897 | ||
898 | if (tz->trips.critical.flags.valid) | |
f5487145 LB |
899 | seq_printf(seq, "critical (S5): %ld C%s", |
900 | KELVIN_TO_CELSIUS(tz->trips.critical.temperature), | |
901 | nocrt ? " <disabled>\n" : "\n"); | |
1da177e4 LT |
902 | |
903 | if (tz->trips.hot.flags.valid) | |
f5487145 LB |
904 | seq_printf(seq, "hot (S4): %ld C%s", |
905 | KELVIN_TO_CELSIUS(tz->trips.hot.temperature), | |
906 | nocrt ? " <disabled>\n" : "\n"); | |
1da177e4 LT |
907 | |
908 | if (tz->trips.passive.flags.valid) { | |
4be44fcd LB |
909 | seq_printf(seq, |
910 | "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=", | |
911 | KELVIN_TO_CELSIUS(tz->trips.passive.temperature), | |
912 | tz->trips.passive.tc1, tz->trips.passive.tc2, | |
913 | tz->trips.passive.tsp); | |
914 | for (j = 0; j < tz->trips.passive.devices.count; j++) { | |
e7c746ef TR |
915 | status = acpi_bus_get_device(tz->trips.passive.devices. |
916 | handles[j], &device); | |
917 | seq_printf(seq, "%4.4s ", status ? "" : | |
918 | acpi_device_bid(device)); | |
1da177e4 LT |
919 | } |
920 | seq_puts(seq, "\n"); | |
921 | } | |
922 | ||
923 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { | |
924 | if (!(tz->trips.active[i].flags.valid)) | |
925 | break; | |
926 | seq_printf(seq, "active[%d]: %ld C: devices=", | |
4be44fcd LB |
927 | i, |
928 | KELVIN_TO_CELSIUS(tz->trips.active[i].temperature)); | |
68ccfaa8 | 929 | for (j = 0; j < tz->trips.active[i].devices.count; j++){ |
e7c746ef TR |
930 | status = acpi_bus_get_device(tz->trips.active[i]. |
931 | devices.handles[j], | |
932 | &device); | |
933 | seq_printf(seq, "%4.4s ", status ? "" : | |
934 | acpi_device_bid(device)); | |
68ccfaa8 | 935 | } |
1da177e4 LT |
936 | seq_puts(seq, "\n"); |
937 | } | |
938 | ||
4be44fcd | 939 | end: |
d550d98d | 940 | return 0; |
1da177e4 LT |
941 | } |
942 | ||
943 | static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file) | |
944 | { | |
945 | return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data); | |
946 | } | |
947 | ||
1da177e4 LT |
948 | static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset) |
949 | { | |
50dd0969 | 950 | struct acpi_thermal *tz = seq->private; |
1da177e4 | 951 | |
1da177e4 LT |
952 | |
953 | if (!tz) | |
954 | goto end; | |
955 | ||
eaca2d3f | 956 | if (!tz->flags.cooling_mode) |
1da177e4 | 957 | seq_puts(seq, "<setting not supported>\n"); |
1da177e4 | 958 | else |
eaca2d3f | 959 | seq_puts(seq, "0 - Active; 1 - Passive\n"); |
1da177e4 | 960 | |
4be44fcd | 961 | end: |
d550d98d | 962 | return 0; |
1da177e4 LT |
963 | } |
964 | ||
965 | static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file) | |
966 | { | |
967 | return single_open(file, acpi_thermal_cooling_seq_show, | |
4be44fcd | 968 | PDE(inode)->data); |
1da177e4 LT |
969 | } |
970 | ||
971 | static ssize_t | |
4be44fcd LB |
972 | acpi_thermal_write_cooling_mode(struct file *file, |
973 | const char __user * buffer, | |
974 | size_t count, loff_t * ppos) | |
1da177e4 | 975 | { |
50dd0969 JE |
976 | struct seq_file *m = file->private_data; |
977 | struct acpi_thermal *tz = m->private; | |
4be44fcd LB |
978 | int result = 0; |
979 | char mode_string[12] = { '\0' }; | |
1da177e4 | 980 | |
1da177e4 LT |
981 | |
982 | if (!tz || (count > sizeof(mode_string) - 1)) | |
d550d98d | 983 | return -EINVAL; |
1da177e4 LT |
984 | |
985 | if (!tz->flags.cooling_mode) | |
d550d98d | 986 | return -ENODEV; |
1da177e4 LT |
987 | |
988 | if (copy_from_user(mode_string, buffer, count)) | |
d550d98d | 989 | return -EFAULT; |
4be44fcd | 990 | |
1da177e4 | 991 | mode_string[count] = '\0'; |
4be44fcd LB |
992 | |
993 | result = acpi_thermal_set_cooling_mode(tz, | |
994 | simple_strtoul(mode_string, NULL, | |
995 | 0)); | |
1da177e4 | 996 | if (result) |
d550d98d | 997 | return result; |
1da177e4 LT |
998 | |
999 | acpi_thermal_check(tz); | |
1000 | ||
d550d98d | 1001 | return count; |
1da177e4 LT |
1002 | } |
1003 | ||
1da177e4 LT |
1004 | static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset) |
1005 | { | |
50dd0969 | 1006 | struct acpi_thermal *tz = seq->private; |
1da177e4 | 1007 | |
1da177e4 LT |
1008 | |
1009 | if (!tz) | |
1010 | goto end; | |
1011 | ||
1012 | if (!tz->polling_frequency) { | |
1013 | seq_puts(seq, "<polling disabled>\n"); | |
1014 | goto end; | |
1015 | } | |
1016 | ||
1017 | seq_printf(seq, "polling frequency: %lu seconds\n", | |
4be44fcd | 1018 | (tz->polling_frequency / 10)); |
1da177e4 | 1019 | |
4be44fcd | 1020 | end: |
d550d98d | 1021 | return 0; |
1da177e4 LT |
1022 | } |
1023 | ||
1024 | static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file) | |
1025 | { | |
1026 | return single_open(file, acpi_thermal_polling_seq_show, | |
4be44fcd | 1027 | PDE(inode)->data); |
1da177e4 LT |
1028 | } |
1029 | ||
1030 | static ssize_t | |
4be44fcd LB |
1031 | acpi_thermal_write_polling(struct file *file, |
1032 | const char __user * buffer, | |
1033 | size_t count, loff_t * ppos) | |
1da177e4 | 1034 | { |
50dd0969 JE |
1035 | struct seq_file *m = file->private_data; |
1036 | struct acpi_thermal *tz = m->private; | |
4be44fcd LB |
1037 | int result = 0; |
1038 | char polling_string[12] = { '\0' }; | |
1039 | int seconds = 0; | |
1da177e4 | 1040 | |
1da177e4 LT |
1041 | |
1042 | if (!tz || (count > sizeof(polling_string) - 1)) | |
d550d98d | 1043 | return -EINVAL; |
4be44fcd | 1044 | |
1da177e4 | 1045 | if (copy_from_user(polling_string, buffer, count)) |
d550d98d | 1046 | return -EFAULT; |
4be44fcd | 1047 | |
1da177e4 LT |
1048 | polling_string[count] = '\0'; |
1049 | ||
1050 | seconds = simple_strtoul(polling_string, NULL, 0); | |
4be44fcd | 1051 | |
1da177e4 LT |
1052 | result = acpi_thermal_set_polling(tz, seconds); |
1053 | if (result) | |
d550d98d | 1054 | return result; |
1da177e4 LT |
1055 | |
1056 | acpi_thermal_check(tz); | |
1057 | ||
d550d98d | 1058 | return count; |
1da177e4 LT |
1059 | } |
1060 | ||
4be44fcd | 1061 | static int acpi_thermal_add_fs(struct acpi_device *device) |
1da177e4 | 1062 | { |
4be44fcd | 1063 | struct proc_dir_entry *entry = NULL; |
1da177e4 | 1064 | |
1da177e4 LT |
1065 | |
1066 | if (!acpi_device_dir(device)) { | |
1067 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), | |
4be44fcd | 1068 | acpi_thermal_dir); |
1da177e4 | 1069 | if (!acpi_device_dir(device)) |
d550d98d | 1070 | return -ENODEV; |
1da177e4 LT |
1071 | acpi_device_dir(device)->owner = THIS_MODULE; |
1072 | } | |
1073 | ||
1074 | /* 'state' [R] */ | |
1075 | entry = create_proc_entry(ACPI_THERMAL_FILE_STATE, | |
4be44fcd | 1076 | S_IRUGO, acpi_device_dir(device)); |
1da177e4 | 1077 | if (!entry) |
d550d98d | 1078 | return -ENODEV; |
1da177e4 LT |
1079 | else { |
1080 | entry->proc_fops = &acpi_thermal_state_fops; | |
1081 | entry->data = acpi_driver_data(device); | |
1082 | entry->owner = THIS_MODULE; | |
1083 | } | |
1084 | ||
1085 | /* 'temperature' [R] */ | |
1086 | entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE, | |
4be44fcd | 1087 | S_IRUGO, acpi_device_dir(device)); |
1da177e4 | 1088 | if (!entry) |
d550d98d | 1089 | return -ENODEV; |
1da177e4 LT |
1090 | else { |
1091 | entry->proc_fops = &acpi_thermal_temp_fops; | |
1092 | entry->data = acpi_driver_data(device); | |
1093 | entry->owner = THIS_MODULE; | |
1094 | } | |
1095 | ||
2db9ccba | 1096 | /* 'trip_points' [R] */ |
1da177e4 | 1097 | entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS, |
2db9ccba | 1098 | S_IRUGO, |
4be44fcd | 1099 | acpi_device_dir(device)); |
1da177e4 | 1100 | if (!entry) |
d550d98d | 1101 | return -ENODEV; |
1da177e4 LT |
1102 | else { |
1103 | entry->proc_fops = &acpi_thermal_trip_fops; | |
1104 | entry->data = acpi_driver_data(device); | |
1105 | entry->owner = THIS_MODULE; | |
1106 | } | |
1107 | ||
1108 | /* 'cooling_mode' [R/W] */ | |
1109 | entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE, | |
4be44fcd LB |
1110 | S_IFREG | S_IRUGO | S_IWUSR, |
1111 | acpi_device_dir(device)); | |
1da177e4 | 1112 | if (!entry) |
d550d98d | 1113 | return -ENODEV; |
1da177e4 LT |
1114 | else { |
1115 | entry->proc_fops = &acpi_thermal_cooling_fops; | |
1116 | entry->data = acpi_driver_data(device); | |
1117 | entry->owner = THIS_MODULE; | |
1118 | } | |
1119 | ||
1120 | /* 'polling_frequency' [R/W] */ | |
1121 | entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ, | |
4be44fcd LB |
1122 | S_IFREG | S_IRUGO | S_IWUSR, |
1123 | acpi_device_dir(device)); | |
1da177e4 | 1124 | if (!entry) |
d550d98d | 1125 | return -ENODEV; |
1da177e4 LT |
1126 | else { |
1127 | entry->proc_fops = &acpi_thermal_polling_fops; | |
1128 | entry->data = acpi_driver_data(device); | |
1129 | entry->owner = THIS_MODULE; | |
1130 | } | |
1131 | ||
d550d98d | 1132 | return 0; |
1da177e4 LT |
1133 | } |
1134 | ||
4be44fcd | 1135 | static int acpi_thermal_remove_fs(struct acpi_device *device) |
1da177e4 | 1136 | { |
1da177e4 LT |
1137 | |
1138 | if (acpi_device_dir(device)) { | |
1139 | remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ, | |
1140 | acpi_device_dir(device)); | |
1141 | remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE, | |
1142 | acpi_device_dir(device)); | |
1143 | remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS, | |
1144 | acpi_device_dir(device)); | |
1145 | remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE, | |
1146 | acpi_device_dir(device)); | |
1147 | remove_proc_entry(ACPI_THERMAL_FILE_STATE, | |
1148 | acpi_device_dir(device)); | |
1149 | remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir); | |
1150 | acpi_device_dir(device) = NULL; | |
1151 | } | |
1152 | ||
d550d98d | 1153 | return 0; |
1da177e4 LT |
1154 | } |
1155 | ||
1da177e4 LT |
1156 | /* -------------------------------------------------------------------------- |
1157 | Driver Interface | |
1158 | -------------------------------------------------------------------------- */ | |
1159 | ||
4be44fcd | 1160 | static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data) |
1da177e4 | 1161 | { |
50dd0969 | 1162 | struct acpi_thermal *tz = data; |
4be44fcd | 1163 | struct acpi_device *device = NULL; |
1da177e4 | 1164 | |
1da177e4 LT |
1165 | |
1166 | if (!tz) | |
d550d98d | 1167 | return; |
1da177e4 | 1168 | |
8348e1b1 | 1169 | device = tz->device; |
1da177e4 LT |
1170 | |
1171 | switch (event) { | |
1172 | case ACPI_THERMAL_NOTIFY_TEMPERATURE: | |
1173 | acpi_thermal_check(tz); | |
1174 | break; | |
1175 | case ACPI_THERMAL_NOTIFY_THRESHOLDS: | |
1176 | acpi_thermal_get_trip_points(tz); | |
1177 | acpi_thermal_check(tz); | |
14e04fb3 | 1178 | acpi_bus_generate_proc_event(device, event, 0); |
962ce8ca ZR |
1179 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
1180 | device->dev.bus_id, event, 0); | |
1da177e4 LT |
1181 | break; |
1182 | case ACPI_THERMAL_NOTIFY_DEVICES: | |
1183 | if (tz->flags.devices) | |
1184 | acpi_thermal_get_devices(tz); | |
14e04fb3 | 1185 | acpi_bus_generate_proc_event(device, event, 0); |
962ce8ca ZR |
1186 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
1187 | device->dev.bus_id, event, 0); | |
1da177e4 LT |
1188 | break; |
1189 | default: | |
1190 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
4be44fcd | 1191 | "Unsupported event [0x%x]\n", event)); |
1da177e4 LT |
1192 | break; |
1193 | } | |
1194 | ||
d550d98d | 1195 | return; |
1da177e4 LT |
1196 | } |
1197 | ||
4be44fcd | 1198 | static int acpi_thermal_get_info(struct acpi_thermal *tz) |
1da177e4 | 1199 | { |
4be44fcd | 1200 | int result = 0; |
1da177e4 | 1201 | |
1da177e4 LT |
1202 | |
1203 | if (!tz) | |
d550d98d | 1204 | return -EINVAL; |
1da177e4 LT |
1205 | |
1206 | /* Get temperature [_TMP] (required) */ | |
1207 | result = acpi_thermal_get_temperature(tz); | |
1208 | if (result) | |
d550d98d | 1209 | return result; |
1da177e4 LT |
1210 | |
1211 | /* Get trip points [_CRT, _PSV, etc.] (required) */ | |
1212 | result = acpi_thermal_get_trip_points(tz); | |
1213 | if (result) | |
d550d98d | 1214 | return result; |
1da177e4 LT |
1215 | |
1216 | /* Set the cooling mode [_SCP] to active cooling (default) */ | |
1217 | result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE); | |
4be44fcd | 1218 | if (!result) |
1da177e4 | 1219 | tz->flags.cooling_mode = 1; |
1da177e4 LT |
1220 | |
1221 | /* Get default polling frequency [_TZP] (optional) */ | |
1222 | if (tzp) | |
1223 | tz->polling_frequency = tzp; | |
1224 | else | |
1225 | acpi_thermal_get_polling_frequency(tz); | |
1226 | ||
1227 | /* Get devices in this thermal zone [_TZD] (optional) */ | |
1228 | result = acpi_thermal_get_devices(tz); | |
1229 | if (!result) | |
1230 | tz->flags.devices = 1; | |
1231 | ||
d550d98d | 1232 | return 0; |
1da177e4 LT |
1233 | } |
1234 | ||
4be44fcd | 1235 | static int acpi_thermal_add(struct acpi_device *device) |
1da177e4 | 1236 | { |
4be44fcd LB |
1237 | int result = 0; |
1238 | acpi_status status = AE_OK; | |
1239 | struct acpi_thermal *tz = NULL; | |
1da177e4 | 1240 | |
1da177e4 LT |
1241 | |
1242 | if (!device) | |
d550d98d | 1243 | return -EINVAL; |
1da177e4 | 1244 | |
36bcbec7 | 1245 | tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL); |
1da177e4 | 1246 | if (!tz) |
d550d98d | 1247 | return -ENOMEM; |
1da177e4 | 1248 | |
8348e1b1 | 1249 | tz->device = device; |
1da177e4 LT |
1250 | strcpy(tz->name, device->pnp.bus_id); |
1251 | strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME); | |
1252 | strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS); | |
1253 | acpi_driver_data(device) = tz; | |
1254 | ||
1255 | result = acpi_thermal_get_info(tz); | |
1256 | if (result) | |
1257 | goto end; | |
1258 | ||
1259 | result = acpi_thermal_add_fs(device); | |
1260 | if (result) | |
09047e75 | 1261 | goto end; |
1da177e4 LT |
1262 | |
1263 | init_timer(&tz->timer); | |
1264 | ||
1265 | acpi_thermal_check(tz); | |
1266 | ||
38ba7c9e | 1267 | status = acpi_install_notify_handler(device->handle, |
4be44fcd LB |
1268 | ACPI_DEVICE_NOTIFY, |
1269 | acpi_thermal_notify, tz); | |
1da177e4 | 1270 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
1271 | result = -ENODEV; |
1272 | goto end; | |
1273 | } | |
1274 | ||
1275 | printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n", | |
4be44fcd LB |
1276 | acpi_device_name(device), acpi_device_bid(device), |
1277 | KELVIN_TO_CELSIUS(tz->temperature)); | |
1da177e4 | 1278 | |
4be44fcd | 1279 | end: |
1da177e4 LT |
1280 | if (result) { |
1281 | acpi_thermal_remove_fs(device); | |
1282 | kfree(tz); | |
1283 | } | |
1284 | ||
d550d98d | 1285 | return result; |
1da177e4 LT |
1286 | } |
1287 | ||
4be44fcd | 1288 | static int acpi_thermal_remove(struct acpi_device *device, int type) |
1da177e4 | 1289 | { |
4be44fcd LB |
1290 | acpi_status status = AE_OK; |
1291 | struct acpi_thermal *tz = NULL; | |
1da177e4 | 1292 | |
1da177e4 LT |
1293 | |
1294 | if (!device || !acpi_driver_data(device)) | |
d550d98d | 1295 | return -EINVAL; |
1da177e4 | 1296 | |
50dd0969 | 1297 | tz = acpi_driver_data(device); |
1da177e4 LT |
1298 | |
1299 | /* avoid timer adding new defer task */ | |
1300 | tz->zombie = 1; | |
1301 | /* wait for running timer (on other CPUs) finish */ | |
1302 | del_timer_sync(&(tz->timer)); | |
1303 | /* synchronize deferred task */ | |
1304 | acpi_os_wait_events_complete(NULL); | |
1305 | /* deferred task may reinsert timer */ | |
1306 | del_timer_sync(&(tz->timer)); | |
1307 | ||
38ba7c9e | 1308 | status = acpi_remove_notify_handler(device->handle, |
4be44fcd LB |
1309 | ACPI_DEVICE_NOTIFY, |
1310 | acpi_thermal_notify); | |
1da177e4 LT |
1311 | |
1312 | /* Terminate policy */ | |
4be44fcd | 1313 | if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) { |
1da177e4 LT |
1314 | tz->trips.passive.flags.enabled = 0; |
1315 | acpi_thermal_passive(tz); | |
1316 | } | |
1317 | if (tz->trips.active[0].flags.valid | |
4be44fcd | 1318 | && tz->trips.active[0].flags.enabled) { |
1da177e4 LT |
1319 | tz->trips.active[0].flags.enabled = 0; |
1320 | acpi_thermal_active(tz); | |
1321 | } | |
1322 | ||
1323 | acpi_thermal_remove_fs(device); | |
1324 | ||
1325 | kfree(tz); | |
d550d98d | 1326 | return 0; |
1da177e4 LT |
1327 | } |
1328 | ||
5d9464a4 | 1329 | static int acpi_thermal_resume(struct acpi_device *device) |
74ce1468 KK |
1330 | { |
1331 | struct acpi_thermal *tz = NULL; | |
b1028c54 KK |
1332 | int i, j, power_state, result; |
1333 | ||
74ce1468 KK |
1334 | |
1335 | if (!device || !acpi_driver_data(device)) | |
d550d98d | 1336 | return -EINVAL; |
74ce1468 | 1337 | |
50dd0969 | 1338 | tz = acpi_driver_data(device); |
74ce1468 | 1339 | |
bed936f7 | 1340 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
b1028c54 KK |
1341 | if (!(&tz->trips.active[i])) |
1342 | break; | |
1343 | if (!tz->trips.active[i].flags.valid) | |
1344 | break; | |
1345 | tz->trips.active[i].flags.enabled = 1; | |
1346 | for (j = 0; j < tz->trips.active[i].devices.count; j++) { | |
1347 | result = acpi_bus_get_power(tz->trips.active[i].devices. | |
1348 | handles[j], &power_state); | |
1349 | if (result || (power_state != ACPI_STATE_D0)) { | |
1350 | tz->trips.active[i].flags.enabled = 0; | |
1351 | break; | |
1352 | } | |
bed936f7 | 1353 | } |
b1028c54 | 1354 | tz->state.active |= tz->trips.active[i].flags.enabled; |
bed936f7 KK |
1355 | } |
1356 | ||
b1028c54 | 1357 | acpi_thermal_check(tz); |
74ce1468 KK |
1358 | |
1359 | return AE_OK; | |
1360 | } | |
1361 | ||
0b5bfa1c | 1362 | #ifdef CONFIG_DMI |
1855256c | 1363 | static int thermal_act(const struct dmi_system_id *d) { |
0b5bfa1c LB |
1364 | |
1365 | if (act == 0) { | |
1366 | printk(KERN_NOTICE "ACPI: %s detected: " | |
1367 | "disabling all active thermal trip points\n", d->ident); | |
1368 | act = -1; | |
1369 | } | |
1370 | return 0; | |
1371 | } | |
1855256c | 1372 | static int thermal_nocrt(const struct dmi_system_id *d) { |
8c99fdce LB |
1373 | |
1374 | printk(KERN_NOTICE "ACPI: %s detected: " | |
1375 | "disabling all critical thermal trip point actions.\n", d->ident); | |
1376 | nocrt = 1; | |
1377 | return 0; | |
1378 | } | |
1855256c | 1379 | static int thermal_tzp(const struct dmi_system_id *d) { |
0b5bfa1c LB |
1380 | |
1381 | if (tzp == 0) { | |
1382 | printk(KERN_NOTICE "ACPI: %s detected: " | |
1383 | "enabling thermal zone polling\n", d->ident); | |
1384 | tzp = 300; /* 300 dS = 30 Seconds */ | |
1385 | } | |
1386 | return 0; | |
1387 | } | |
1855256c | 1388 | static int thermal_psv(const struct dmi_system_id *d) { |
0b5bfa1c LB |
1389 | |
1390 | if (psv == 0) { | |
1391 | printk(KERN_NOTICE "ACPI: %s detected: " | |
1392 | "disabling all passive thermal trip points\n", d->ident); | |
1393 | psv = -1; | |
1394 | } | |
1395 | return 0; | |
1396 | } | |
1397 | ||
1398 | static struct dmi_system_id thermal_dmi_table[] __initdata = { | |
1399 | /* | |
1400 | * Award BIOS on this AOpen makes thermal control almost worthless. | |
1401 | * http://bugzilla.kernel.org/show_bug.cgi?id=8842 | |
1402 | */ | |
1403 | { | |
1404 | .callback = thermal_act, | |
1405 | .ident = "AOpen i915GMm-HFS", | |
1406 | .matches = { | |
1407 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), | |
1408 | DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), | |
1409 | }, | |
1410 | }, | |
1411 | { | |
1412 | .callback = thermal_psv, | |
1413 | .ident = "AOpen i915GMm-HFS", | |
1414 | .matches = { | |
1415 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), | |
1416 | DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), | |
1417 | }, | |
1418 | }, | |
1419 | { | |
1420 | .callback = thermal_tzp, | |
1421 | .ident = "AOpen i915GMm-HFS", | |
1422 | .matches = { | |
1423 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), | |
1424 | DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), | |
1425 | }, | |
1426 | }, | |
8c99fdce LB |
1427 | { |
1428 | .callback = thermal_nocrt, | |
1429 | .ident = "Gigabyte GA-7ZX", | |
1430 | .matches = { | |
1431 | DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."), | |
1432 | DMI_MATCH(DMI_BOARD_NAME, "7ZX"), | |
1433 | }, | |
1434 | }, | |
0b5bfa1c LB |
1435 | {} |
1436 | }; | |
1437 | #endif /* CONFIG_DMI */ | |
1438 | ||
4be44fcd | 1439 | static int __init acpi_thermal_init(void) |
1da177e4 | 1440 | { |
4be44fcd | 1441 | int result = 0; |
1da177e4 | 1442 | |
0b5bfa1c LB |
1443 | dmi_check_system(thermal_dmi_table); |
1444 | ||
72b33ef8 LB |
1445 | if (off) { |
1446 | printk(KERN_NOTICE "ACPI: thermal control disabled\n"); | |
1447 | return -ENODEV; | |
1448 | } | |
1da177e4 LT |
1449 | acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir); |
1450 | if (!acpi_thermal_dir) | |
d550d98d | 1451 | return -ENODEV; |
1da177e4 LT |
1452 | acpi_thermal_dir->owner = THIS_MODULE; |
1453 | ||
1454 | result = acpi_bus_register_driver(&acpi_thermal_driver); | |
1455 | if (result < 0) { | |
1456 | remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir); | |
d550d98d | 1457 | return -ENODEV; |
1da177e4 LT |
1458 | } |
1459 | ||
d550d98d | 1460 | return 0; |
1da177e4 LT |
1461 | } |
1462 | ||
4be44fcd | 1463 | static void __exit acpi_thermal_exit(void) |
1da177e4 | 1464 | { |
1da177e4 LT |
1465 | |
1466 | acpi_bus_unregister_driver(&acpi_thermal_driver); | |
1467 | ||
1468 | remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir); | |
1469 | ||
d550d98d | 1470 | return; |
1da177e4 LT |
1471 | } |
1472 | ||
1da177e4 LT |
1473 | module_init(acpi_thermal_init); |
1474 | module_exit(acpi_thermal_exit); |