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