]>
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 | 45 | #include <asm/uaccess.h> |
3f655ef8 | 46 | #include <linux/thermal.h> |
1da177e4 LT |
47 | #include <acpi/acpi_bus.h> |
48 | #include <acpi/acpi_drivers.h> | |
49 | ||
1da177e4 | 50 | #define ACPI_THERMAL_CLASS "thermal_zone" |
1da177e4 LT |
51 | #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone" |
52 | #define ACPI_THERMAL_FILE_STATE "state" | |
53 | #define ACPI_THERMAL_FILE_TEMPERATURE "temperature" | |
54 | #define ACPI_THERMAL_FILE_TRIP_POINTS "trip_points" | |
55 | #define ACPI_THERMAL_FILE_COOLING_MODE "cooling_mode" | |
56 | #define ACPI_THERMAL_FILE_POLLING_FREQ "polling_frequency" | |
57 | #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80 | |
58 | #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81 | |
59 | #define ACPI_THERMAL_NOTIFY_DEVICES 0x82 | |
60 | #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0 | |
61 | #define ACPI_THERMAL_NOTIFY_HOT 0xF1 | |
62 | #define ACPI_THERMAL_MODE_ACTIVE 0x00 | |
1da177e4 LT |
63 | |
64 | #define ACPI_THERMAL_MAX_ACTIVE 10 | |
65 | #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65 | |
66 | ||
1da177e4 | 67 | #define _COMPONENT ACPI_THERMAL_COMPONENT |
f52fd66d | 68 | ACPI_MODULE_NAME("thermal"); |
1da177e4 | 69 | |
1cbf4c56 | 70 | MODULE_AUTHOR("Paul Diefenbaugh"); |
7cda93e0 | 71 | MODULE_DESCRIPTION("ACPI Thermal Zone Driver"); |
1da177e4 LT |
72 | MODULE_LICENSE("GPL"); |
73 | ||
f8707ec9 LB |
74 | static int act; |
75 | module_param(act, int, 0644); | |
3c1d36da | 76 | MODULE_PARM_DESC(act, "Disable or override all lowest active trip points."); |
f8707ec9 | 77 | |
c52a7419 LB |
78 | static int crt; |
79 | module_param(crt, int, 0644); | |
80 | MODULE_PARM_DESC(crt, "Disable or lower all critical trip points."); | |
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); | |
8c99fdce | 88 | MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points."); |
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; | |
3f655ef8 ZR |
194 | struct thermal_zone_device *thermal_zone; |
195 | int tz_enabled; | |
6e215785 | 196 | struct mutex lock; |
1da177e4 LT |
197 | }; |
198 | ||
d7508032 | 199 | static const struct file_operations acpi_thermal_state_fops = { |
cf7acfab | 200 | .owner = THIS_MODULE, |
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 = { |
cf7acfab | 208 | .owner = THIS_MODULE, |
4be44fcd LB |
209 | .open = acpi_thermal_temp_open_fs, |
210 | .read = seq_read, | |
211 | .llseek = seq_lseek, | |
212 | .release = single_release, | |
1da177e4 LT |
213 | }; |
214 | ||
d7508032 | 215 | static const struct file_operations acpi_thermal_trip_fops = { |
cf7acfab | 216 | .owner = THIS_MODULE, |
4be44fcd LB |
217 | .open = acpi_thermal_trip_open_fs, |
218 | .read = seq_read, | |
4be44fcd LB |
219 | .llseek = seq_lseek, |
220 | .release = single_release, | |
1da177e4 LT |
221 | }; |
222 | ||
d7508032 | 223 | static const struct file_operations acpi_thermal_cooling_fops = { |
cf7acfab | 224 | .owner = THIS_MODULE, |
4be44fcd LB |
225 | .open = acpi_thermal_cooling_open_fs, |
226 | .read = seq_read, | |
227 | .write = acpi_thermal_write_cooling_mode, | |
228 | .llseek = seq_lseek, | |
229 | .release = single_release, | |
1da177e4 LT |
230 | }; |
231 | ||
d7508032 | 232 | static const struct file_operations acpi_thermal_polling_fops = { |
cf7acfab | 233 | .owner = THIS_MODULE, |
4be44fcd LB |
234 | .open = acpi_thermal_polling_open_fs, |
235 | .read = seq_read, | |
236 | .write = acpi_thermal_write_polling, | |
237 | .llseek = seq_lseek, | |
238 | .release = single_release, | |
1da177e4 LT |
239 | }; |
240 | ||
241 | /* -------------------------------------------------------------------------- | |
242 | Thermal Zone Management | |
243 | -------------------------------------------------------------------------- */ | |
244 | ||
4be44fcd | 245 | static int acpi_thermal_get_temperature(struct acpi_thermal *tz) |
1da177e4 | 246 | { |
4be44fcd | 247 | acpi_status status = AE_OK; |
27663c58 | 248 | unsigned long long tmp; |
1da177e4 LT |
249 | |
250 | if (!tz) | |
d550d98d | 251 | return -EINVAL; |
1da177e4 LT |
252 | |
253 | tz->last_temperature = tz->temperature; | |
254 | ||
27663c58 | 255 | status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp); |
1da177e4 | 256 | if (ACPI_FAILURE(status)) |
d550d98d | 257 | return -ENODEV; |
1da177e4 | 258 | |
27663c58 | 259 | tz->temperature = tmp; |
4be44fcd LB |
260 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n", |
261 | tz->temperature)); | |
1da177e4 | 262 | |
d550d98d | 263 | return 0; |
1da177e4 LT |
264 | } |
265 | ||
4be44fcd | 266 | static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz) |
1da177e4 | 267 | { |
4be44fcd | 268 | acpi_status status = AE_OK; |
27663c58 | 269 | unsigned long long tmp; |
1da177e4 LT |
270 | |
271 | if (!tz) | |
d550d98d | 272 | return -EINVAL; |
1da177e4 | 273 | |
27663c58 | 274 | status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp); |
1da177e4 | 275 | if (ACPI_FAILURE(status)) |
d550d98d | 276 | return -ENODEV; |
1da177e4 | 277 | |
27663c58 | 278 | tz->polling_frequency = tmp; |
4be44fcd LB |
279 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n", |
280 | tz->polling_frequency)); | |
1da177e4 | 281 | |
d550d98d | 282 | return 0; |
1da177e4 LT |
283 | } |
284 | ||
4be44fcd | 285 | static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds) |
1da177e4 | 286 | { |
1da177e4 LT |
287 | |
288 | if (!tz) | |
d550d98d | 289 | return -EINVAL; |
1da177e4 LT |
290 | |
291 | tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */ | |
292 | ||
4be44fcd LB |
293 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
294 | "Polling frequency set to %lu seconds\n", | |
636cedf9 | 295 | tz->polling_frequency/10)); |
1da177e4 | 296 | |
d550d98d | 297 | return 0; |
1da177e4 LT |
298 | } |
299 | ||
4be44fcd | 300 | static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode) |
1da177e4 | 301 | { |
4be44fcd LB |
302 | acpi_status status = AE_OK; |
303 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | |
304 | struct acpi_object_list arg_list = { 1, &arg0 }; | |
305 | acpi_handle handle = NULL; | |
1da177e4 | 306 | |
1da177e4 LT |
307 | |
308 | if (!tz) | |
d550d98d | 309 | return -EINVAL; |
1da177e4 | 310 | |
38ba7c9e | 311 | status = acpi_get_handle(tz->device->handle, "_SCP", &handle); |
1da177e4 LT |
312 | if (ACPI_FAILURE(status)) { |
313 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n")); | |
d550d98d | 314 | return -ENODEV; |
1da177e4 LT |
315 | } |
316 | ||
317 | arg0.integer.value = mode; | |
318 | ||
319 | status = acpi_evaluate_object(handle, NULL, &arg_list, NULL); | |
320 | if (ACPI_FAILURE(status)) | |
d550d98d | 321 | return -ENODEV; |
1da177e4 | 322 | |
d550d98d | 323 | return 0; |
1da177e4 LT |
324 | } |
325 | ||
ce44e197 ZR |
326 | #define ACPI_TRIPS_CRITICAL 0x01 |
327 | #define ACPI_TRIPS_HOT 0x02 | |
328 | #define ACPI_TRIPS_PASSIVE 0x04 | |
329 | #define ACPI_TRIPS_ACTIVE 0x08 | |
330 | #define ACPI_TRIPS_DEVICES 0x10 | |
1da177e4 | 331 | |
ce44e197 ZR |
332 | #define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE) |
333 | #define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES | |
1da177e4 | 334 | |
ce44e197 ZR |
335 | #define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \ |
336 | ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \ | |
337 | ACPI_TRIPS_DEVICES) | |
1da177e4 | 338 | |
ce44e197 ZR |
339 | /* |
340 | * This exception is thrown out in two cases: | |
341 | * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid | |
342 | * when re-evaluating the AML code. | |
343 | * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change. | |
344 | * We need to re-bind the cooling devices of a thermal zone when this occurs. | |
345 | */ | |
346 | #define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \ | |
347 | do { \ | |
348 | if (flags != ACPI_TRIPS_INIT) \ | |
349 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, \ | |
350 | "ACPI thermal trip point %s changed\n" \ | |
351 | "Please send acpidump to linux-acpi@vger.kernel.org\n", str)); \ | |
352 | } while (0) | |
353 | ||
354 | static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) | |
355 | { | |
356 | acpi_status status = AE_OK; | |
27663c58 | 357 | unsigned long long tmp; |
ce44e197 ZR |
358 | struct acpi_handle_list devices; |
359 | int valid = 0; | |
360 | int i; | |
1da177e4 | 361 | |
ce44e197 ZR |
362 | /* Critical Shutdown (required) */ |
363 | if (flag & ACPI_TRIPS_CRITICAL) { | |
364 | status = acpi_evaluate_integer(tz->device->handle, | |
27663c58 MW |
365 | "_CRT", NULL, &tmp); |
366 | tz->trips.critical.temperature = tmp; | |
a39a2d7c AV |
367 | /* |
368 | * Treat freezing temperatures as invalid as well; some | |
369 | * BIOSes return really low values and cause reboots at startup. | |
370 | * Below zero (Celcius) values clearly aren't right for sure.. | |
371 | * ... so lets discard those as invalid. | |
372 | */ | |
373 | if (ACPI_FAILURE(status) || | |
374 | tz->trips.critical.temperature <= 2732) { | |
c52a7419 | 375 | tz->trips.critical.flags.valid = 0; |
ce44e197 | 376 | ACPI_EXCEPTION((AE_INFO, status, |
a39a2d7c | 377 | "No or invalid critical threshold")); |
ce44e197 ZR |
378 | return -ENODEV; |
379 | } else { | |
380 | tz->trips.critical.flags.valid = 1; | |
381 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
382 | "Found critical threshold [%lu]\n", | |
383 | tz->trips.critical.temperature)); | |
384 | } | |
385 | if (tz->trips.critical.flags.valid == 1) { | |
386 | if (crt == -1) { | |
387 | tz->trips.critical.flags.valid = 0; | |
388 | } else if (crt > 0) { | |
389 | unsigned long crt_k = CELSIUS_TO_KELVIN(crt); | |
390 | /* | |
22a94d79 | 391 | * Allow override critical threshold |
ce44e197 | 392 | */ |
22a94d79 ZR |
393 | if (crt_k > tz->trips.critical.temperature) |
394 | printk(KERN_WARNING PREFIX | |
395 | "Critical threshold %d C\n", crt); | |
396 | tz->trips.critical.temperature = crt_k; | |
ce44e197 | 397 | } |
c52a7419 LB |
398 | } |
399 | } | |
400 | ||
1da177e4 | 401 | /* Critical Sleep (optional) */ |
ce44e197 | 402 | if (flag & ACPI_TRIPS_HOT) { |
a70cdc52 | 403 | status = acpi_evaluate_integer(tz->device->handle, |
27663c58 | 404 | "_HOT", NULL, &tmp); |
ce44e197 ZR |
405 | if (ACPI_FAILURE(status)) { |
406 | tz->trips.hot.flags.valid = 0; | |
407 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
408 | "No hot threshold\n")); | |
409 | } else { | |
27663c58 | 410 | tz->trips.hot.temperature = tmp; |
ce44e197 ZR |
411 | tz->trips.hot.flags.valid = 1; |
412 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
413 | "Found hot threshold [%lu]\n", | |
414 | tz->trips.critical.temperature)); | |
415 | } | |
a70cdc52 LB |
416 | } |
417 | ||
ce44e197 | 418 | /* Passive (optional) */ |
0e4240d9 ZR |
419 | if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) || |
420 | (flag == ACPI_TRIPS_INIT)) { | |
ce44e197 ZR |
421 | valid = tz->trips.passive.flags.valid; |
422 | if (psv == -1) { | |
423 | status = AE_SUPPORT; | |
424 | } else if (psv > 0) { | |
27663c58 | 425 | tmp = CELSIUS_TO_KELVIN(psv); |
ce44e197 ZR |
426 | status = AE_OK; |
427 | } else { | |
428 | status = acpi_evaluate_integer(tz->device->handle, | |
27663c58 | 429 | "_PSV", NULL, &tmp); |
ce44e197 | 430 | } |
1da177e4 | 431 | |
1da177e4 LT |
432 | if (ACPI_FAILURE(status)) |
433 | tz->trips.passive.flags.valid = 0; | |
ce44e197 | 434 | else { |
27663c58 | 435 | tz->trips.passive.temperature = tmp; |
ce44e197 ZR |
436 | tz->trips.passive.flags.valid = 1; |
437 | if (flag == ACPI_TRIPS_INIT) { | |
438 | status = acpi_evaluate_integer( | |
439 | tz->device->handle, "_TC1", | |
27663c58 | 440 | NULL, &tmp); |
ce44e197 ZR |
441 | if (ACPI_FAILURE(status)) |
442 | tz->trips.passive.flags.valid = 0; | |
27663c58 MW |
443 | else |
444 | tz->trips.passive.tc1 = tmp; | |
ce44e197 ZR |
445 | status = acpi_evaluate_integer( |
446 | tz->device->handle, "_TC2", | |
27663c58 | 447 | NULL, &tmp); |
ce44e197 ZR |
448 | if (ACPI_FAILURE(status)) |
449 | tz->trips.passive.flags.valid = 0; | |
27663c58 MW |
450 | else |
451 | tz->trips.passive.tc2 = tmp; | |
ce44e197 ZR |
452 | status = acpi_evaluate_integer( |
453 | tz->device->handle, "_TSP", | |
27663c58 | 454 | NULL, &tmp); |
ce44e197 ZR |
455 | if (ACPI_FAILURE(status)) |
456 | tz->trips.passive.flags.valid = 0; | |
27663c58 MW |
457 | else |
458 | tz->trips.passive.tsp = tmp; | |
ce44e197 ZR |
459 | } |
460 | } | |
461 | } | |
462 | if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) { | |
463 | memset(&devices, 0, sizeof(struct acpi_handle_list)); | |
464 | status = acpi_evaluate_reference(tz->device->handle, "_PSL", | |
465 | NULL, &devices); | |
0e4240d9 ZR |
466 | if (ACPI_FAILURE(status)) { |
467 | printk(KERN_WARNING PREFIX | |
468 | "Invalid passive threshold\n"); | |
1da177e4 | 469 | tz->trips.passive.flags.valid = 0; |
0e4240d9 | 470 | } |
1da177e4 | 471 | else |
ce44e197 | 472 | tz->trips.passive.flags.valid = 1; |
1da177e4 | 473 | |
ce44e197 ZR |
474 | if (memcmp(&tz->trips.passive.devices, &devices, |
475 | sizeof(struct acpi_handle_list))) { | |
476 | memcpy(&tz->trips.passive.devices, &devices, | |
477 | sizeof(struct acpi_handle_list)); | |
478 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); | |
479 | } | |
480 | } | |
481 | if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) { | |
482 | if (valid != tz->trips.passive.flags.valid) | |
483 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state"); | |
484 | } | |
1da177e4 | 485 | |
ce44e197 | 486 | /* Active (optional) */ |
4be44fcd | 487 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
4be44fcd | 488 | char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; |
ce44e197 | 489 | valid = tz->trips.active[i].flags.valid; |
1da177e4 | 490 | |
f8707ec9 | 491 | if (act == -1) |
ce44e197 ZR |
492 | break; /* disable all active trip points */ |
493 | ||
0e4240d9 ZR |
494 | if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) && |
495 | tz->trips.active[i].flags.valid)) { | |
ce44e197 | 496 | status = acpi_evaluate_integer(tz->device->handle, |
27663c58 | 497 | name, NULL, &tmp); |
ce44e197 ZR |
498 | if (ACPI_FAILURE(status)) { |
499 | tz->trips.active[i].flags.valid = 0; | |
500 | if (i == 0) | |
501 | break; | |
502 | if (act <= 0) | |
503 | break; | |
504 | if (i == 1) | |
505 | tz->trips.active[0].temperature = | |
506 | CELSIUS_TO_KELVIN(act); | |
507 | else | |
508 | /* | |
509 | * Don't allow override higher than | |
510 | * the next higher trip point | |
511 | */ | |
512 | tz->trips.active[i - 1].temperature = | |
513 | (tz->trips.active[i - 2].temperature < | |
514 | CELSIUS_TO_KELVIN(act) ? | |
515 | tz->trips.active[i - 2].temperature : | |
516 | CELSIUS_TO_KELVIN(act)); | |
f8707ec9 | 517 | break; |
27663c58 MW |
518 | } else { |
519 | tz->trips.active[i].temperature = tmp; | |
ce44e197 | 520 | tz->trips.active[i].flags.valid = 1; |
27663c58 | 521 | } |
f8707ec9 | 522 | } |
1da177e4 LT |
523 | |
524 | name[2] = 'L'; | |
ce44e197 ZR |
525 | if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) { |
526 | memset(&devices, 0, sizeof(struct acpi_handle_list)); | |
527 | status = acpi_evaluate_reference(tz->device->handle, | |
528 | name, NULL, &devices); | |
0e4240d9 ZR |
529 | if (ACPI_FAILURE(status)) { |
530 | printk(KERN_WARNING PREFIX | |
531 | "Invalid active%d threshold\n", i); | |
ce44e197 | 532 | tz->trips.active[i].flags.valid = 0; |
0e4240d9 | 533 | } |
ce44e197 ZR |
534 | else |
535 | tz->trips.active[i].flags.valid = 1; | |
536 | ||
537 | if (memcmp(&tz->trips.active[i].devices, &devices, | |
538 | sizeof(struct acpi_handle_list))) { | |
539 | memcpy(&tz->trips.active[i].devices, &devices, | |
540 | sizeof(struct acpi_handle_list)); | |
541 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); | |
542 | } | |
543 | } | |
544 | if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES)) | |
545 | if (valid != tz->trips.active[i].flags.valid) | |
546 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state"); | |
547 | ||
548 | if (!tz->trips.active[i].flags.valid) | |
549 | break; | |
550 | } | |
551 | ||
552 | if (flag & ACPI_TRIPS_DEVICES) { | |
553 | memset(&devices, 0, sizeof(struct acpi_handle_list)); | |
554 | status = acpi_evaluate_reference(tz->device->handle, "_TZD", | |
555 | NULL, &devices); | |
556 | if (memcmp(&tz->devices, &devices, | |
557 | sizeof(struct acpi_handle_list))) { | |
558 | memcpy(&tz->devices, &devices, | |
559 | sizeof(struct acpi_handle_list)); | |
560 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); | |
561 | } | |
1da177e4 LT |
562 | } |
563 | ||
d550d98d | 564 | return 0; |
1da177e4 LT |
565 | } |
566 | ||
ce44e197 | 567 | static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) |
1da177e4 | 568 | { |
ce44e197 | 569 | return acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); |
1da177e4 LT |
570 | } |
571 | ||
4be44fcd | 572 | static int acpi_thermal_critical(struct acpi_thermal *tz) |
1da177e4 | 573 | { |
223630fe | 574 | if (!tz || !tz->trips.critical.flags.valid) |
d550d98d | 575 | return -EINVAL; |
1da177e4 LT |
576 | |
577 | if (tz->temperature >= tz->trips.critical.temperature) { | |
cece9296 | 578 | printk(KERN_WARNING PREFIX "Critical trip point\n"); |
1da177e4 | 579 | tz->trips.critical.flags.enabled = 1; |
4be44fcd | 580 | } else if (tz->trips.critical.flags.enabled) |
1da177e4 LT |
581 | tz->trips.critical.flags.enabled = 0; |
582 | ||
14e04fb3 | 583 | acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL, |
4be44fcd | 584 | tz->trips.critical.flags.enabled); |
962ce8ca | 585 | acpi_bus_generate_netlink_event(tz->device->pnp.device_class, |
0794469d | 586 | dev_name(&tz->device->dev), |
962ce8ca ZR |
587 | ACPI_THERMAL_NOTIFY_CRITICAL, |
588 | tz->trips.critical.flags.enabled); | |
1da177e4 | 589 | |
223630fe ZR |
590 | /* take no action if nocrt is set */ |
591 | if(!nocrt) { | |
592 | printk(KERN_EMERG | |
593 | "Critical temperature reached (%ld C), shutting down.\n", | |
594 | KELVIN_TO_CELSIUS(tz->temperature)); | |
595 | orderly_poweroff(true); | |
596 | } | |
1da177e4 | 597 | |
d550d98d | 598 | return 0; |
1da177e4 LT |
599 | } |
600 | ||
4be44fcd | 601 | static int acpi_thermal_hot(struct acpi_thermal *tz) |
1da177e4 | 602 | { |
223630fe | 603 | if (!tz || !tz->trips.hot.flags.valid) |
d550d98d | 604 | return -EINVAL; |
1da177e4 LT |
605 | |
606 | if (tz->temperature >= tz->trips.hot.temperature) { | |
cece9296 | 607 | printk(KERN_WARNING PREFIX "Hot trip point\n"); |
1da177e4 | 608 | tz->trips.hot.flags.enabled = 1; |
4be44fcd | 609 | } else if (tz->trips.hot.flags.enabled) |
1da177e4 LT |
610 | tz->trips.hot.flags.enabled = 0; |
611 | ||
14e04fb3 | 612 | acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_HOT, |
4be44fcd | 613 | tz->trips.hot.flags.enabled); |
962ce8ca | 614 | acpi_bus_generate_netlink_event(tz->device->pnp.device_class, |
0794469d | 615 | dev_name(&tz->device->dev), |
962ce8ca ZR |
616 | ACPI_THERMAL_NOTIFY_HOT, |
617 | tz->trips.hot.flags.enabled); | |
1da177e4 | 618 | |
223630fe | 619 | /* TBD: Call user-mode "sleep(S4)" function if nocrt is cleared */ |
1da177e4 | 620 | |
d550d98d | 621 | return 0; |
1da177e4 LT |
622 | } |
623 | ||
1cbf4c56 | 624 | static void acpi_thermal_passive(struct acpi_thermal *tz) |
1da177e4 | 625 | { |
1cbf4c56 | 626 | int result = 1; |
1da177e4 | 627 | struct acpi_thermal_passive *passive = NULL; |
4be44fcd LB |
628 | int trend = 0; |
629 | int i = 0; | |
1da177e4 | 630 | |
1da177e4 LT |
631 | |
632 | if (!tz || !tz->trips.passive.flags.valid) | |
1cbf4c56 | 633 | return; |
1da177e4 LT |
634 | |
635 | passive = &(tz->trips.passive); | |
636 | ||
637 | /* | |
638 | * Above Trip? | |
639 | * ----------- | |
640 | * Calculate the thermal trend (using the passive cooling equation) | |
641 | * and modify the performance limit for all passive cooling devices | |
642 | * accordingly. Note that we assume symmetry. | |
643 | */ | |
644 | if (tz->temperature >= passive->temperature) { | |
4be44fcd LB |
645 | trend = |
646 | (passive->tc1 * (tz->temperature - tz->last_temperature)) + | |
647 | (passive->tc2 * (tz->temperature - passive->temperature)); | |
648 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
649 | "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n", | |
650 | trend, passive->tc1, tz->temperature, | |
651 | tz->last_temperature, passive->tc2, | |
652 | tz->temperature, passive->temperature)); | |
1cbf4c56 | 653 | passive->flags.enabled = 1; |
1da177e4 LT |
654 | /* Heating up? */ |
655 | if (trend > 0) | |
4be44fcd LB |
656 | for (i = 0; i < passive->devices.count; i++) |
657 | acpi_processor_set_thermal_limit(passive-> | |
658 | devices. | |
659 | handles[i], | |
660 | ACPI_PROCESSOR_LIMIT_INCREMENT); | |
1da177e4 | 661 | /* Cooling off? */ |
1cbf4c56 | 662 | else if (trend < 0) { |
4be44fcd | 663 | for (i = 0; i < passive->devices.count; i++) |
1cbf4c56 TR |
664 | /* |
665 | * assume that we are on highest | |
666 | * freq/lowest thrott and can leave | |
667 | * passive mode, even in error case | |
668 | */ | |
669 | if (!acpi_processor_set_thermal_limit | |
670 | (passive->devices.handles[i], | |
671 | ACPI_PROCESSOR_LIMIT_DECREMENT)) | |
672 | result = 0; | |
673 | /* | |
674 | * Leave cooling mode, even if the temp might | |
675 | * higher than trip point This is because some | |
676 | * machines might have long thermal polling | |
677 | * frequencies (tsp) defined. We will fall back | |
678 | * into passive mode in next cycle (probably quicker) | |
679 | */ | |
680 | if (result) { | |
681 | passive->flags.enabled = 0; | |
682 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
683 | "Disabling passive cooling, still above threshold," | |
684 | " but we are cooling down\n")); | |
685 | } | |
686 | } | |
687 | return; | |
1da177e4 LT |
688 | } |
689 | ||
690 | /* | |
691 | * Below Trip? | |
692 | * ----------- | |
693 | * Implement passive cooling hysteresis to slowly increase performance | |
694 | * and avoid thrashing around the passive trip point. Note that we | |
695 | * assume symmetry. | |
696 | */ | |
1cbf4c56 TR |
697 | if (!passive->flags.enabled) |
698 | return; | |
699 | for (i = 0; i < passive->devices.count; i++) | |
700 | if (!acpi_processor_set_thermal_limit | |
701 | (passive->devices.handles[i], | |
702 | ACPI_PROCESSOR_LIMIT_DECREMENT)) | |
703 | result = 0; | |
704 | if (result) { | |
705 | passive->flags.enabled = 0; | |
706 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
707 | "Disabling passive cooling (zone is cool)\n")); | |
1da177e4 | 708 | } |
1da177e4 LT |
709 | } |
710 | ||
1cbf4c56 | 711 | static void acpi_thermal_active(struct acpi_thermal *tz) |
1da177e4 | 712 | { |
4be44fcd | 713 | int result = 0; |
1da177e4 | 714 | struct acpi_thermal_active *active = NULL; |
4be44fcd LB |
715 | int i = 0; |
716 | int j = 0; | |
717 | unsigned long maxtemp = 0; | |
1da177e4 | 718 | |
1da177e4 LT |
719 | |
720 | if (!tz) | |
1cbf4c56 | 721 | return; |
1da177e4 | 722 | |
4be44fcd | 723 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
1da177e4 LT |
724 | active = &(tz->trips.active[i]); |
725 | if (!active || !active->flags.valid) | |
726 | break; | |
1da177e4 | 727 | if (tz->temperature >= active->temperature) { |
1cbf4c56 TR |
728 | /* |
729 | * Above Threshold? | |
730 | * ---------------- | |
731 | * If not already enabled, turn ON all cooling devices | |
732 | * associated with this active threshold. | |
733 | */ | |
1da177e4 | 734 | if (active->temperature > maxtemp) |
1cbf4c56 TR |
735 | tz->state.active_index = i; |
736 | maxtemp = active->temperature; | |
737 | if (active->flags.enabled) | |
738 | continue; | |
1da177e4 | 739 | for (j = 0; j < active->devices.count; j++) { |
4be44fcd LB |
740 | result = |
741 | acpi_bus_set_power(active->devices. | |
742 | handles[j], | |
1cbf4c56 | 743 | ACPI_STATE_D0); |
1da177e4 | 744 | if (result) { |
cece9296 LB |
745 | printk(KERN_WARNING PREFIX |
746 | "Unable to turn cooling device [%p] 'on'\n", | |
a6fc6720 | 747 | active->devices. |
cece9296 | 748 | handles[j]); |
1da177e4 LT |
749 | continue; |
750 | } | |
1cbf4c56 | 751 | active->flags.enabled = 1; |
4be44fcd | 752 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
1cbf4c56 | 753 | "Cooling device [%p] now 'on'\n", |
4be44fcd | 754 | active->devices.handles[j])); |
1da177e4 | 755 | } |
1cbf4c56 TR |
756 | continue; |
757 | } | |
758 | if (!active->flags.enabled) | |
759 | continue; | |
760 | /* | |
761 | * Below Threshold? | |
762 | * ---------------- | |
763 | * Turn OFF all cooling devices associated with this | |
764 | * threshold. | |
765 | */ | |
766 | for (j = 0; j < active->devices.count; j++) { | |
767 | result = acpi_bus_set_power(active->devices.handles[j], | |
768 | ACPI_STATE_D3); | |
769 | if (result) { | |
cece9296 LB |
770 | printk(KERN_WARNING PREFIX |
771 | "Unable to turn cooling device [%p] 'off'\n", | |
772 | active->devices.handles[j]); | |
1cbf4c56 TR |
773 | continue; |
774 | } | |
775 | active->flags.enabled = 0; | |
776 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
777 | "Cooling device [%p] now 'off'\n", | |
778 | active->devices.handles[j])); | |
1da177e4 LT |
779 | } |
780 | } | |
1da177e4 LT |
781 | } |
782 | ||
4be44fcd | 783 | static void acpi_thermal_check(void *context); |
1da177e4 | 784 | |
4be44fcd | 785 | static void acpi_thermal_run(unsigned long data) |
1da177e4 LT |
786 | { |
787 | struct acpi_thermal *tz = (struct acpi_thermal *)data; | |
788 | if (!tz->zombie) | |
b8d35192 | 789 | acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data); |
1da177e4 LT |
790 | } |
791 | ||
ea51011a ZY |
792 | static void acpi_thermal_active_off(void *data) |
793 | { | |
794 | int result = 0; | |
795 | struct acpi_thermal *tz = data; | |
796 | int i = 0; | |
797 | int j = 0; | |
798 | struct acpi_thermal_active *active = NULL; | |
799 | ||
800 | if (!tz) { | |
801 | printk(KERN_ERR PREFIX "Invalid (NULL) context\n"); | |
802 | return; | |
803 | } | |
804 | ||
805 | result = acpi_thermal_get_temperature(tz); | |
806 | if (result) | |
807 | return; | |
808 | ||
809 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { | |
810 | active = &(tz->trips.active[i]); | |
811 | if (!active || !active->flags.valid) | |
812 | break; | |
813 | if (tz->temperature >= active->temperature) { | |
814 | /* | |
815 | * If the thermal temperature is greater than the | |
816 | * active threshod, unnecessary to turn off the | |
817 | * the active cooling device. | |
818 | */ | |
819 | continue; | |
820 | } | |
821 | /* | |
822 | * Below Threshold? | |
823 | * ---------------- | |
824 | * Turn OFF all cooling devices associated with this | |
825 | * threshold. | |
826 | */ | |
827 | for (j = 0; j < active->devices.count; j++) | |
828 | result = acpi_bus_set_power(active->devices.handles[j], | |
829 | ACPI_STATE_D3); | |
830 | } | |
831 | } | |
832 | ||
4be44fcd | 833 | static void acpi_thermal_check(void *data) |
1da177e4 | 834 | { |
4be44fcd | 835 | int result = 0; |
50dd0969 | 836 | struct acpi_thermal *tz = data; |
4be44fcd | 837 | unsigned long sleep_time = 0; |
21bc42ab | 838 | unsigned long timeout_jiffies = 0; |
4be44fcd | 839 | int i = 0; |
1da177e4 LT |
840 | struct acpi_thermal_state state; |
841 | ||
1da177e4 LT |
842 | |
843 | if (!tz) { | |
6468463a | 844 | printk(KERN_ERR PREFIX "Invalid (NULL) context\n"); |
d550d98d | 845 | return; |
1da177e4 LT |
846 | } |
847 | ||
6e215785 AS |
848 | /* Check if someone else is already running */ |
849 | if (!mutex_trylock(&tz->lock)) | |
850 | return; | |
851 | ||
1da177e4 LT |
852 | state = tz->state; |
853 | ||
854 | result = acpi_thermal_get_temperature(tz); | |
855 | if (result) | |
6e215785 | 856 | goto unlock; |
4be44fcd | 857 | |
3f655ef8 ZR |
858 | if (!tz->tz_enabled) |
859 | goto unlock; | |
860 | ||
1da177e4 | 861 | memset(&tz->state, 0, sizeof(tz->state)); |
4be44fcd | 862 | |
1da177e4 LT |
863 | /* |
864 | * Check Trip Points | |
865 | * ----------------- | |
866 | * Compare the current temperature to the trip point values to see | |
867 | * if we've entered one of the thermal policy states. Note that | |
868 | * this function determines when a state is entered, but the | |
869 | * individual policy decides when it is exited (e.g. hysteresis). | |
870 | */ | |
871 | if (tz->trips.critical.flags.valid) | |
4be44fcd LB |
872 | state.critical |= |
873 | (tz->temperature >= tz->trips.critical.temperature); | |
1da177e4 LT |
874 | if (tz->trips.hot.flags.valid) |
875 | state.hot |= (tz->temperature >= tz->trips.hot.temperature); | |
876 | if (tz->trips.passive.flags.valid) | |
4be44fcd LB |
877 | state.passive |= |
878 | (tz->temperature >= tz->trips.passive.temperature); | |
879 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) | |
1da177e4 | 880 | if (tz->trips.active[i].flags.valid) |
4be44fcd LB |
881 | state.active |= |
882 | (tz->temperature >= | |
883 | tz->trips.active[i].temperature); | |
1da177e4 LT |
884 | |
885 | /* | |
886 | * Invoke Policy | |
887 | * ------------- | |
888 | * Separated from the above check to allow individual policy to | |
889 | * determine when to exit a given state. | |
890 | */ | |
891 | if (state.critical) | |
892 | acpi_thermal_critical(tz); | |
893 | if (state.hot) | |
894 | acpi_thermal_hot(tz); | |
895 | if (state.passive) | |
896 | acpi_thermal_passive(tz); | |
897 | if (state.active) | |
898 | acpi_thermal_active(tz); | |
899 | ||
900 | /* | |
901 | * Calculate State | |
902 | * --------------- | |
903 | * Again, separated from the above two to allow independent policy | |
904 | * decisions. | |
905 | */ | |
1cbf4c56 TR |
906 | tz->state.critical = tz->trips.critical.flags.enabled; |
907 | tz->state.hot = tz->trips.hot.flags.enabled; | |
908 | tz->state.passive = tz->trips.passive.flags.enabled; | |
909 | tz->state.active = 0; | |
4be44fcd | 910 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) |
1cbf4c56 | 911 | tz->state.active |= tz->trips.active[i].flags.enabled; |
1da177e4 LT |
912 | |
913 | /* | |
914 | * Calculate Sleep Time | |
915 | * -------------------- | |
916 | * If we're in the passive state, use _TSP's value. Otherwise | |
917 | * use the default polling frequency (e.g. _TZP). If no polling | |
918 | * frequency is specified then we'll wait forever (at least until | |
919 | * a thermal event occurs). Note that _TSP and _TZD values are | |
920 | * given in 1/10th seconds (we must covert to milliseconds). | |
921 | */ | |
21bc42ab | 922 | if (tz->state.passive) { |
1da177e4 | 923 | sleep_time = tz->trips.passive.tsp * 100; |
21bc42ab LB |
924 | timeout_jiffies = jiffies + (HZ * sleep_time) / 1000; |
925 | } else if (tz->polling_frequency > 0) { | |
1da177e4 | 926 | sleep_time = tz->polling_frequency * 100; |
21bc42ab LB |
927 | timeout_jiffies = round_jiffies(jiffies + (HZ * sleep_time) / 1000); |
928 | } | |
1da177e4 | 929 | |
4be44fcd LB |
930 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n", |
931 | tz->name, tz->temperature, sleep_time)); | |
1da177e4 LT |
932 | |
933 | /* | |
934 | * Schedule Next Poll | |
935 | * ------------------ | |
936 | */ | |
937 | if (!sleep_time) { | |
938 | if (timer_pending(&(tz->timer))) | |
939 | del_timer(&(tz->timer)); | |
4be44fcd | 940 | } else { |
1da177e4 | 941 | if (timer_pending(&(tz->timer))) |
21bc42ab | 942 | mod_timer(&(tz->timer), timeout_jiffies); |
1da177e4 | 943 | else { |
4be44fcd | 944 | tz->timer.data = (unsigned long)tz; |
1da177e4 | 945 | tz->timer.function = acpi_thermal_run; |
21bc42ab | 946 | tz->timer.expires = timeout_jiffies; |
1da177e4 LT |
947 | add_timer(&(tz->timer)); |
948 | } | |
949 | } | |
6e215785 AS |
950 | unlock: |
951 | mutex_unlock(&tz->lock); | |
1da177e4 LT |
952 | } |
953 | ||
3f655ef8 | 954 | /* sys I/F for generic thermal sysfs support */ |
5e012760 ZR |
955 | #define KELVIN_TO_MILLICELSIUS(t) (t * 100 - 273200) |
956 | ||
6503e5df MG |
957 | static int thermal_get_temp(struct thermal_zone_device *thermal, |
958 | unsigned long *temp) | |
3f655ef8 ZR |
959 | { |
960 | struct acpi_thermal *tz = thermal->devdata; | |
76ecb4f2 | 961 | int result; |
3f655ef8 ZR |
962 | |
963 | if (!tz) | |
964 | return -EINVAL; | |
965 | ||
76ecb4f2 ZR |
966 | result = acpi_thermal_get_temperature(tz); |
967 | if (result) | |
968 | return result; | |
969 | ||
6503e5df MG |
970 | *temp = KELVIN_TO_MILLICELSIUS(tz->temperature); |
971 | return 0; | |
3f655ef8 ZR |
972 | } |
973 | ||
974 | static const char enabled[] = "kernel"; | |
975 | static const char disabled[] = "user"; | |
976 | static int thermal_get_mode(struct thermal_zone_device *thermal, | |
6503e5df | 977 | enum thermal_device_mode *mode) |
3f655ef8 ZR |
978 | { |
979 | struct acpi_thermal *tz = thermal->devdata; | |
980 | ||
981 | if (!tz) | |
982 | return -EINVAL; | |
983 | ||
6503e5df MG |
984 | *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : |
985 | THERMAL_DEVICE_DISABLED; | |
986 | ||
987 | return 0; | |
3f655ef8 ZR |
988 | } |
989 | ||
990 | static int thermal_set_mode(struct thermal_zone_device *thermal, | |
6503e5df | 991 | enum thermal_device_mode mode) |
3f655ef8 ZR |
992 | { |
993 | struct acpi_thermal *tz = thermal->devdata; | |
994 | int enable; | |
995 | ||
996 | if (!tz) | |
997 | return -EINVAL; | |
998 | ||
999 | /* | |
1000 | * enable/disable thermal management from ACPI thermal driver | |
1001 | */ | |
6503e5df | 1002 | if (mode == THERMAL_DEVICE_ENABLED) |
3f655ef8 | 1003 | enable = 1; |
6503e5df | 1004 | else if (mode == THERMAL_DEVICE_DISABLED) |
3f655ef8 ZR |
1005 | enable = 0; |
1006 | else | |
1007 | return -EINVAL; | |
1008 | ||
1009 | if (enable != tz->tz_enabled) { | |
1010 | tz->tz_enabled = enable; | |
1011 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
1012 | "%s ACPI thermal control\n", | |
1013 | tz->tz_enabled ? enabled : disabled)); | |
1014 | acpi_thermal_check(tz); | |
1015 | } | |
1016 | return 0; | |
1017 | } | |
1018 | ||
1019 | static int thermal_get_trip_type(struct thermal_zone_device *thermal, | |
6503e5df | 1020 | int trip, enum thermal_trip_type *type) |
3f655ef8 ZR |
1021 | { |
1022 | struct acpi_thermal *tz = thermal->devdata; | |
1023 | int i; | |
1024 | ||
1025 | if (!tz || trip < 0) | |
1026 | return -EINVAL; | |
1027 | ||
1028 | if (tz->trips.critical.flags.valid) { | |
6503e5df MG |
1029 | if (!trip) { |
1030 | *type = THERMAL_TRIP_CRITICAL; | |
1031 | return 0; | |
1032 | } | |
3f655ef8 ZR |
1033 | trip--; |
1034 | } | |
1035 | ||
1036 | if (tz->trips.hot.flags.valid) { | |
6503e5df MG |
1037 | if (!trip) { |
1038 | *type = THERMAL_TRIP_HOT; | |
1039 | return 0; | |
1040 | } | |
3f655ef8 ZR |
1041 | trip--; |
1042 | } | |
1043 | ||
1044 | if (tz->trips.passive.flags.valid) { | |
6503e5df MG |
1045 | if (!trip) { |
1046 | *type = THERMAL_TRIP_PASSIVE; | |
1047 | return 0; | |
1048 | } | |
3f655ef8 ZR |
1049 | trip--; |
1050 | } | |
1051 | ||
1052 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && | |
1053 | tz->trips.active[i].flags.valid; i++) { | |
6503e5df MG |
1054 | if (!trip) { |
1055 | *type = THERMAL_TRIP_ACTIVE; | |
1056 | return 0; | |
1057 | } | |
3f655ef8 ZR |
1058 | trip--; |
1059 | } | |
1060 | ||
1061 | return -EINVAL; | |
1062 | } | |
1063 | ||
1064 | static int thermal_get_trip_temp(struct thermal_zone_device *thermal, | |
6503e5df | 1065 | int trip, unsigned long *temp) |
3f655ef8 ZR |
1066 | { |
1067 | struct acpi_thermal *tz = thermal->devdata; | |
1068 | int i; | |
1069 | ||
1070 | if (!tz || trip < 0) | |
1071 | return -EINVAL; | |
1072 | ||
1073 | if (tz->trips.critical.flags.valid) { | |
6503e5df MG |
1074 | if (!trip) { |
1075 | *temp = KELVIN_TO_MILLICELSIUS( | |
1076 | tz->trips.critical.temperature); | |
1077 | return 0; | |
1078 | } | |
3f655ef8 ZR |
1079 | trip--; |
1080 | } | |
1081 | ||
1082 | if (tz->trips.hot.flags.valid) { | |
6503e5df MG |
1083 | if (!trip) { |
1084 | *temp = KELVIN_TO_MILLICELSIUS( | |
1085 | tz->trips.hot.temperature); | |
1086 | return 0; | |
1087 | } | |
3f655ef8 ZR |
1088 | trip--; |
1089 | } | |
1090 | ||
1091 | if (tz->trips.passive.flags.valid) { | |
6503e5df MG |
1092 | if (!trip) { |
1093 | *temp = KELVIN_TO_MILLICELSIUS( | |
1094 | tz->trips.passive.temperature); | |
1095 | return 0; | |
1096 | } | |
3f655ef8 ZR |
1097 | trip--; |
1098 | } | |
1099 | ||
1100 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && | |
1101 | tz->trips.active[i].flags.valid; i++) { | |
6503e5df MG |
1102 | if (!trip) { |
1103 | *temp = KELVIN_TO_MILLICELSIUS( | |
1104 | tz->trips.active[i].temperature); | |
1105 | return 0; | |
1106 | } | |
3f655ef8 ZR |
1107 | trip--; |
1108 | } | |
1109 | ||
1110 | return -EINVAL; | |
1111 | } | |
1112 | ||
9ec732ff ZR |
1113 | static int thermal_get_crit_temp(struct thermal_zone_device *thermal, |
1114 | unsigned long *temperature) { | |
1115 | struct acpi_thermal *tz = thermal->devdata; | |
1116 | ||
1117 | if (tz->trips.critical.flags.valid) { | |
1118 | *temperature = KELVIN_TO_MILLICELSIUS( | |
1119 | tz->trips.critical.temperature); | |
1120 | return 0; | |
1121 | } else | |
1122 | return -EINVAL; | |
1123 | } | |
1124 | ||
3f655ef8 ZR |
1125 | typedef int (*cb)(struct thermal_zone_device *, int, |
1126 | struct thermal_cooling_device *); | |
1127 | static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal, | |
1128 | struct thermal_cooling_device *cdev, | |
1129 | cb action) | |
1130 | { | |
1131 | struct acpi_device *device = cdev->devdata; | |
1132 | struct acpi_thermal *tz = thermal->devdata; | |
653a00c9 ZR |
1133 | struct acpi_device *dev; |
1134 | acpi_status status; | |
1135 | acpi_handle handle; | |
3f655ef8 ZR |
1136 | int i; |
1137 | int j; | |
1138 | int trip = -1; | |
1139 | int result = 0; | |
1140 | ||
1141 | if (tz->trips.critical.flags.valid) | |
1142 | trip++; | |
1143 | ||
1144 | if (tz->trips.hot.flags.valid) | |
1145 | trip++; | |
1146 | ||
1147 | if (tz->trips.passive.flags.valid) { | |
1148 | trip++; | |
1149 | for (i = 0; i < tz->trips.passive.devices.count; | |
1150 | i++) { | |
653a00c9 ZR |
1151 | handle = tz->trips.passive.devices.handles[i]; |
1152 | status = acpi_bus_get_device(handle, &dev); | |
1153 | if (ACPI_SUCCESS(status) && (dev == device)) { | |
1154 | result = action(thermal, trip, cdev); | |
1155 | if (result) | |
1156 | goto failed; | |
1157 | } | |
3f655ef8 ZR |
1158 | } |
1159 | } | |
1160 | ||
1161 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { | |
1162 | if (!tz->trips.active[i].flags.valid) | |
1163 | break; | |
1164 | trip++; | |
1165 | for (j = 0; | |
1166 | j < tz->trips.active[i].devices.count; | |
1167 | j++) { | |
653a00c9 ZR |
1168 | handle = tz->trips.active[i].devices.handles[j]; |
1169 | status = acpi_bus_get_device(handle, &dev); | |
1170 | if (ACPI_SUCCESS(status) && (dev == device)) { | |
1171 | result = action(thermal, trip, cdev); | |
1172 | if (result) | |
1173 | goto failed; | |
1174 | } | |
3f655ef8 ZR |
1175 | } |
1176 | } | |
1177 | ||
1178 | for (i = 0; i < tz->devices.count; i++) { | |
653a00c9 ZR |
1179 | handle = tz->devices.handles[i]; |
1180 | status = acpi_bus_get_device(handle, &dev); | |
1181 | if (ACPI_SUCCESS(status) && (dev == device)) { | |
1182 | result = action(thermal, -1, cdev); | |
1183 | if (result) | |
1184 | goto failed; | |
1185 | } | |
3f655ef8 ZR |
1186 | } |
1187 | ||
1188 | failed: | |
1189 | return result; | |
1190 | } | |
1191 | ||
1192 | static int | |
1193 | acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal, | |
1194 | struct thermal_cooling_device *cdev) | |
1195 | { | |
1196 | return acpi_thermal_cooling_device_cb(thermal, cdev, | |
1197 | thermal_zone_bind_cooling_device); | |
1198 | } | |
1199 | ||
1200 | static int | |
1201 | acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal, | |
1202 | struct thermal_cooling_device *cdev) | |
1203 | { | |
1204 | return acpi_thermal_cooling_device_cb(thermal, cdev, | |
1205 | thermal_zone_unbind_cooling_device); | |
1206 | } | |
1207 | ||
1208 | static struct thermal_zone_device_ops acpi_thermal_zone_ops = { | |
1209 | .bind = acpi_thermal_bind_cooling_device, | |
1210 | .unbind = acpi_thermal_unbind_cooling_device, | |
1211 | .get_temp = thermal_get_temp, | |
1212 | .get_mode = thermal_get_mode, | |
1213 | .set_mode = thermal_set_mode, | |
1214 | .get_trip_type = thermal_get_trip_type, | |
1215 | .get_trip_temp = thermal_get_trip_temp, | |
9ec732ff | 1216 | .get_crit_temp = thermal_get_crit_temp, |
3f655ef8 ZR |
1217 | }; |
1218 | ||
1219 | static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) | |
1220 | { | |
1221 | int trips = 0; | |
1222 | int result; | |
20733939 | 1223 | acpi_status status; |
3f655ef8 ZR |
1224 | int i; |
1225 | ||
1226 | if (tz->trips.critical.flags.valid) | |
1227 | trips++; | |
1228 | ||
1229 | if (tz->trips.hot.flags.valid) | |
1230 | trips++; | |
1231 | ||
1232 | if (tz->trips.passive.flags.valid) | |
1233 | trips++; | |
1234 | ||
1235 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && | |
1236 | tz->trips.active[i].flags.valid; i++, trips++); | |
e9ae7107 | 1237 | tz->thermal_zone = thermal_zone_device_register("acpitz", |
3f655ef8 | 1238 | trips, tz, &acpi_thermal_zone_ops); |
bb070e43 | 1239 | if (IS_ERR(tz->thermal_zone)) |
3f655ef8 ZR |
1240 | return -ENODEV; |
1241 | ||
1242 | result = sysfs_create_link(&tz->device->dev.kobj, | |
1243 | &tz->thermal_zone->device.kobj, "thermal_zone"); | |
1244 | if (result) | |
1245 | return result; | |
1246 | ||
1247 | result = sysfs_create_link(&tz->thermal_zone->device.kobj, | |
1248 | &tz->device->dev.kobj, "device"); | |
1249 | if (result) | |
1250 | return result; | |
1251 | ||
20733939 ZR |
1252 | status = acpi_attach_data(tz->device->handle, |
1253 | acpi_bus_private_data_handler, | |
1254 | tz->thermal_zone); | |
1255 | if (ACPI_FAILURE(status)) { | |
55ac9a01 LM |
1256 | printk(KERN_ERR PREFIX |
1257 | "Error attaching device data\n"); | |
20733939 ZR |
1258 | return -ENODEV; |
1259 | } | |
1260 | ||
3f655ef8 ZR |
1261 | tz->tz_enabled = 1; |
1262 | ||
fc3a8828 GKH |
1263 | dev_info(&tz->device->dev, "registered as thermal_zone%d\n", |
1264 | tz->thermal_zone->id); | |
3f655ef8 ZR |
1265 | return 0; |
1266 | } | |
1267 | ||
1268 | static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz) | |
1269 | { | |
1270 | sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); | |
1271 | sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); | |
1272 | thermal_zone_device_unregister(tz->thermal_zone); | |
1273 | tz->thermal_zone = NULL; | |
20733939 | 1274 | acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler); |
3f655ef8 ZR |
1275 | } |
1276 | ||
1277 | ||
1da177e4 LT |
1278 | /* -------------------------------------------------------------------------- |
1279 | FS Interface (/proc) | |
1280 | -------------------------------------------------------------------------- */ | |
1281 | ||
4be44fcd | 1282 | static struct proc_dir_entry *acpi_thermal_dir; |
1da177e4 LT |
1283 | |
1284 | static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset) | |
1285 | { | |
50dd0969 | 1286 | struct acpi_thermal *tz = seq->private; |
1da177e4 | 1287 | |
1da177e4 LT |
1288 | |
1289 | if (!tz) | |
1290 | goto end; | |
1291 | ||
1292 | seq_puts(seq, "state: "); | |
1293 | ||
4be44fcd LB |
1294 | if (!tz->state.critical && !tz->state.hot && !tz->state.passive |
1295 | && !tz->state.active) | |
1da177e4 LT |
1296 | seq_puts(seq, "ok\n"); |
1297 | else { | |
1298 | if (tz->state.critical) | |
1299 | seq_puts(seq, "critical "); | |
1300 | if (tz->state.hot) | |
1301 | seq_puts(seq, "hot "); | |
1302 | if (tz->state.passive) | |
1303 | seq_puts(seq, "passive "); | |
1304 | if (tz->state.active) | |
1305 | seq_printf(seq, "active[%d]", tz->state.active_index); | |
1306 | seq_puts(seq, "\n"); | |
1307 | } | |
1308 | ||
4be44fcd | 1309 | end: |
d550d98d | 1310 | return 0; |
1da177e4 LT |
1311 | } |
1312 | ||
1313 | static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file) | |
1314 | { | |
1315 | return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data); | |
1316 | } | |
1317 | ||
1da177e4 LT |
1318 | static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset) |
1319 | { | |
4be44fcd | 1320 | int result = 0; |
50dd0969 | 1321 | struct acpi_thermal *tz = seq->private; |
1da177e4 | 1322 | |
1da177e4 LT |
1323 | |
1324 | if (!tz) | |
1325 | goto end; | |
1326 | ||
1327 | result = acpi_thermal_get_temperature(tz); | |
1328 | if (result) | |
1329 | goto end; | |
1330 | ||
4be44fcd LB |
1331 | seq_printf(seq, "temperature: %ld C\n", |
1332 | KELVIN_TO_CELSIUS(tz->temperature)); | |
1da177e4 | 1333 | |
4be44fcd | 1334 | end: |
d550d98d | 1335 | return 0; |
1da177e4 LT |
1336 | } |
1337 | ||
1338 | static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file) | |
1339 | { | |
1340 | return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data); | |
1341 | } | |
1342 | ||
1da177e4 LT |
1343 | static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset) |
1344 | { | |
50dd0969 | 1345 | struct acpi_thermal *tz = seq->private; |
68ccfaa8 | 1346 | struct acpi_device *device; |
e7c746ef TR |
1347 | acpi_status status; |
1348 | ||
4be44fcd LB |
1349 | int i = 0; |
1350 | int j = 0; | |
1da177e4 | 1351 | |
1da177e4 LT |
1352 | |
1353 | if (!tz) | |
1354 | goto end; | |
1355 | ||
1356 | if (tz->trips.critical.flags.valid) | |
f5487145 LB |
1357 | seq_printf(seq, "critical (S5): %ld C%s", |
1358 | KELVIN_TO_CELSIUS(tz->trips.critical.temperature), | |
1359 | nocrt ? " <disabled>\n" : "\n"); | |
1da177e4 LT |
1360 | |
1361 | if (tz->trips.hot.flags.valid) | |
f5487145 LB |
1362 | seq_printf(seq, "hot (S4): %ld C%s", |
1363 | KELVIN_TO_CELSIUS(tz->trips.hot.temperature), | |
1364 | nocrt ? " <disabled>\n" : "\n"); | |
1da177e4 LT |
1365 | |
1366 | if (tz->trips.passive.flags.valid) { | |
4be44fcd LB |
1367 | seq_printf(seq, |
1368 | "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=", | |
1369 | KELVIN_TO_CELSIUS(tz->trips.passive.temperature), | |
1370 | tz->trips.passive.tc1, tz->trips.passive.tc2, | |
1371 | tz->trips.passive.tsp); | |
1372 | for (j = 0; j < tz->trips.passive.devices.count; j++) { | |
e7c746ef TR |
1373 | status = acpi_bus_get_device(tz->trips.passive.devices. |
1374 | handles[j], &device); | |
1375 | seq_printf(seq, "%4.4s ", status ? "" : | |
1376 | acpi_device_bid(device)); | |
1da177e4 LT |
1377 | } |
1378 | seq_puts(seq, "\n"); | |
1379 | } | |
1380 | ||
1381 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { | |
1382 | if (!(tz->trips.active[i].flags.valid)) | |
1383 | break; | |
1384 | seq_printf(seq, "active[%d]: %ld C: devices=", | |
4be44fcd LB |
1385 | i, |
1386 | KELVIN_TO_CELSIUS(tz->trips.active[i].temperature)); | |
68ccfaa8 | 1387 | for (j = 0; j < tz->trips.active[i].devices.count; j++){ |
e7c746ef TR |
1388 | status = acpi_bus_get_device(tz->trips.active[i]. |
1389 | devices.handles[j], | |
1390 | &device); | |
1391 | seq_printf(seq, "%4.4s ", status ? "" : | |
1392 | acpi_device_bid(device)); | |
68ccfaa8 | 1393 | } |
1da177e4 LT |
1394 | seq_puts(seq, "\n"); |
1395 | } | |
1396 | ||
4be44fcd | 1397 | end: |
d550d98d | 1398 | return 0; |
1da177e4 LT |
1399 | } |
1400 | ||
1401 | static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file) | |
1402 | { | |
1403 | return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data); | |
1404 | } | |
1405 | ||
1da177e4 LT |
1406 | static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset) |
1407 | { | |
50dd0969 | 1408 | struct acpi_thermal *tz = seq->private; |
1da177e4 | 1409 | |
1da177e4 LT |
1410 | |
1411 | if (!tz) | |
1412 | goto end; | |
1413 | ||
eaca2d3f | 1414 | if (!tz->flags.cooling_mode) |
1da177e4 | 1415 | seq_puts(seq, "<setting not supported>\n"); |
1da177e4 | 1416 | else |
eaca2d3f | 1417 | seq_puts(seq, "0 - Active; 1 - Passive\n"); |
1da177e4 | 1418 | |
4be44fcd | 1419 | end: |
d550d98d | 1420 | return 0; |
1da177e4 LT |
1421 | } |
1422 | ||
1423 | static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file) | |
1424 | { | |
1425 | return single_open(file, acpi_thermal_cooling_seq_show, | |
4be44fcd | 1426 | PDE(inode)->data); |
1da177e4 LT |
1427 | } |
1428 | ||
1429 | static ssize_t | |
4be44fcd LB |
1430 | acpi_thermal_write_cooling_mode(struct file *file, |
1431 | const char __user * buffer, | |
1432 | size_t count, loff_t * ppos) | |
1da177e4 | 1433 | { |
50dd0969 JE |
1434 | struct seq_file *m = file->private_data; |
1435 | struct acpi_thermal *tz = m->private; | |
4be44fcd LB |
1436 | int result = 0; |
1437 | char mode_string[12] = { '\0' }; | |
1da177e4 | 1438 | |
1da177e4 LT |
1439 | |
1440 | if (!tz || (count > sizeof(mode_string) - 1)) | |
d550d98d | 1441 | return -EINVAL; |
1da177e4 LT |
1442 | |
1443 | if (!tz->flags.cooling_mode) | |
d550d98d | 1444 | return -ENODEV; |
1da177e4 LT |
1445 | |
1446 | if (copy_from_user(mode_string, buffer, count)) | |
d550d98d | 1447 | return -EFAULT; |
4be44fcd | 1448 | |
1da177e4 | 1449 | mode_string[count] = '\0'; |
4be44fcd LB |
1450 | |
1451 | result = acpi_thermal_set_cooling_mode(tz, | |
1452 | simple_strtoul(mode_string, NULL, | |
1453 | 0)); | |
1da177e4 | 1454 | if (result) |
d550d98d | 1455 | return result; |
1da177e4 LT |
1456 | |
1457 | acpi_thermal_check(tz); | |
1458 | ||
d550d98d | 1459 | return count; |
1da177e4 LT |
1460 | } |
1461 | ||
1da177e4 LT |
1462 | static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset) |
1463 | { | |
50dd0969 | 1464 | struct acpi_thermal *tz = seq->private; |
1da177e4 | 1465 | |
1da177e4 LT |
1466 | |
1467 | if (!tz) | |
1468 | goto end; | |
1469 | ||
1470 | if (!tz->polling_frequency) { | |
1471 | seq_puts(seq, "<polling disabled>\n"); | |
1472 | goto end; | |
1473 | } | |
1474 | ||
1475 | seq_printf(seq, "polling frequency: %lu seconds\n", | |
4be44fcd | 1476 | (tz->polling_frequency / 10)); |
1da177e4 | 1477 | |
4be44fcd | 1478 | end: |
d550d98d | 1479 | return 0; |
1da177e4 LT |
1480 | } |
1481 | ||
1482 | static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file) | |
1483 | { | |
1484 | return single_open(file, acpi_thermal_polling_seq_show, | |
4be44fcd | 1485 | PDE(inode)->data); |
1da177e4 LT |
1486 | } |
1487 | ||
1488 | static ssize_t | |
4be44fcd LB |
1489 | acpi_thermal_write_polling(struct file *file, |
1490 | const char __user * buffer, | |
1491 | size_t count, loff_t * ppos) | |
1da177e4 | 1492 | { |
50dd0969 JE |
1493 | struct seq_file *m = file->private_data; |
1494 | struct acpi_thermal *tz = m->private; | |
4be44fcd LB |
1495 | int result = 0; |
1496 | char polling_string[12] = { '\0' }; | |
1497 | int seconds = 0; | |
1da177e4 | 1498 | |
1da177e4 LT |
1499 | |
1500 | if (!tz || (count > sizeof(polling_string) - 1)) | |
d550d98d | 1501 | return -EINVAL; |
4be44fcd | 1502 | |
1da177e4 | 1503 | if (copy_from_user(polling_string, buffer, count)) |
d550d98d | 1504 | return -EFAULT; |
4be44fcd | 1505 | |
1da177e4 LT |
1506 | polling_string[count] = '\0'; |
1507 | ||
1508 | seconds = simple_strtoul(polling_string, NULL, 0); | |
4be44fcd | 1509 | |
1da177e4 LT |
1510 | result = acpi_thermal_set_polling(tz, seconds); |
1511 | if (result) | |
d550d98d | 1512 | return result; |
1da177e4 LT |
1513 | |
1514 | acpi_thermal_check(tz); | |
1515 | ||
d550d98d | 1516 | return count; |
1da177e4 LT |
1517 | } |
1518 | ||
4be44fcd | 1519 | static int acpi_thermal_add_fs(struct acpi_device *device) |
1da177e4 | 1520 | { |
4be44fcd | 1521 | struct proc_dir_entry *entry = NULL; |
1da177e4 | 1522 | |
1da177e4 LT |
1523 | |
1524 | if (!acpi_device_dir(device)) { | |
1525 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), | |
4be44fcd | 1526 | acpi_thermal_dir); |
1da177e4 | 1527 | if (!acpi_device_dir(device)) |
d550d98d | 1528 | return -ENODEV; |
1da177e4 LT |
1529 | acpi_device_dir(device)->owner = THIS_MODULE; |
1530 | } | |
1531 | ||
1532 | /* 'state' [R] */ | |
cf7acfab DL |
1533 | entry = proc_create_data(ACPI_THERMAL_FILE_STATE, |
1534 | S_IRUGO, acpi_device_dir(device), | |
1535 | &acpi_thermal_state_fops, | |
1536 | acpi_driver_data(device)); | |
1da177e4 | 1537 | if (!entry) |
d550d98d | 1538 | return -ENODEV; |
1da177e4 LT |
1539 | |
1540 | /* 'temperature' [R] */ | |
cf7acfab DL |
1541 | entry = proc_create_data(ACPI_THERMAL_FILE_TEMPERATURE, |
1542 | S_IRUGO, acpi_device_dir(device), | |
1543 | &acpi_thermal_temp_fops, | |
1544 | acpi_driver_data(device)); | |
1da177e4 | 1545 | if (!entry) |
d550d98d | 1546 | return -ENODEV; |
1da177e4 | 1547 | |
2db9ccba | 1548 | /* 'trip_points' [R] */ |
cf7acfab DL |
1549 | entry = proc_create_data(ACPI_THERMAL_FILE_TRIP_POINTS, |
1550 | S_IRUGO, | |
1551 | acpi_device_dir(device), | |
1552 | &acpi_thermal_trip_fops, | |
1553 | acpi_driver_data(device)); | |
1da177e4 | 1554 | if (!entry) |
d550d98d | 1555 | return -ENODEV; |
1da177e4 LT |
1556 | |
1557 | /* 'cooling_mode' [R/W] */ | |
cf7acfab DL |
1558 | entry = proc_create_data(ACPI_THERMAL_FILE_COOLING_MODE, |
1559 | S_IFREG | S_IRUGO | S_IWUSR, | |
1560 | acpi_device_dir(device), | |
1561 | &acpi_thermal_cooling_fops, | |
1562 | acpi_driver_data(device)); | |
1da177e4 | 1563 | if (!entry) |
d550d98d | 1564 | return -ENODEV; |
1da177e4 LT |
1565 | |
1566 | /* 'polling_frequency' [R/W] */ | |
cf7acfab DL |
1567 | entry = proc_create_data(ACPI_THERMAL_FILE_POLLING_FREQ, |
1568 | S_IFREG | S_IRUGO | S_IWUSR, | |
1569 | acpi_device_dir(device), | |
1570 | &acpi_thermal_polling_fops, | |
1571 | acpi_driver_data(device)); | |
1da177e4 | 1572 | if (!entry) |
d550d98d | 1573 | return -ENODEV; |
d550d98d | 1574 | return 0; |
1da177e4 LT |
1575 | } |
1576 | ||
4be44fcd | 1577 | static int acpi_thermal_remove_fs(struct acpi_device *device) |
1da177e4 | 1578 | { |
1da177e4 LT |
1579 | |
1580 | if (acpi_device_dir(device)) { | |
1581 | remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ, | |
1582 | acpi_device_dir(device)); | |
1583 | remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE, | |
1584 | acpi_device_dir(device)); | |
1585 | remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS, | |
1586 | acpi_device_dir(device)); | |
1587 | remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE, | |
1588 | acpi_device_dir(device)); | |
1589 | remove_proc_entry(ACPI_THERMAL_FILE_STATE, | |
1590 | acpi_device_dir(device)); | |
1591 | remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir); | |
1592 | acpi_device_dir(device) = NULL; | |
1593 | } | |
1594 | ||
d550d98d | 1595 | return 0; |
1da177e4 LT |
1596 | } |
1597 | ||
1da177e4 LT |
1598 | /* -------------------------------------------------------------------------- |
1599 | Driver Interface | |
1600 | -------------------------------------------------------------------------- */ | |
1601 | ||
4be44fcd | 1602 | static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data) |
1da177e4 | 1603 | { |
50dd0969 | 1604 | struct acpi_thermal *tz = data; |
4be44fcd | 1605 | struct acpi_device *device = NULL; |
1da177e4 | 1606 | |
1da177e4 LT |
1607 | |
1608 | if (!tz) | |
d550d98d | 1609 | return; |
1da177e4 | 1610 | |
8348e1b1 | 1611 | device = tz->device; |
1da177e4 LT |
1612 | |
1613 | switch (event) { | |
1614 | case ACPI_THERMAL_NOTIFY_TEMPERATURE: | |
1615 | acpi_thermal_check(tz); | |
1616 | break; | |
1617 | case ACPI_THERMAL_NOTIFY_THRESHOLDS: | |
ce44e197 | 1618 | acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS); |
1da177e4 | 1619 | acpi_thermal_check(tz); |
14e04fb3 | 1620 | acpi_bus_generate_proc_event(device, event, 0); |
962ce8ca | 1621 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
0794469d | 1622 | dev_name(&device->dev), event, 0); |
1da177e4 LT |
1623 | break; |
1624 | case ACPI_THERMAL_NOTIFY_DEVICES: | |
ce44e197 ZR |
1625 | acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES); |
1626 | acpi_thermal_check(tz); | |
14e04fb3 | 1627 | acpi_bus_generate_proc_event(device, event, 0); |
962ce8ca | 1628 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
0794469d | 1629 | dev_name(&device->dev), event, 0); |
1da177e4 LT |
1630 | break; |
1631 | default: | |
1632 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
4be44fcd | 1633 | "Unsupported event [0x%x]\n", event)); |
1da177e4 LT |
1634 | break; |
1635 | } | |
1636 | ||
d550d98d | 1637 | return; |
1da177e4 LT |
1638 | } |
1639 | ||
4be44fcd | 1640 | static int acpi_thermal_get_info(struct acpi_thermal *tz) |
1da177e4 | 1641 | { |
4be44fcd | 1642 | int result = 0; |
1da177e4 | 1643 | |
1da177e4 LT |
1644 | |
1645 | if (!tz) | |
d550d98d | 1646 | return -EINVAL; |
1da177e4 LT |
1647 | |
1648 | /* Get temperature [_TMP] (required) */ | |
1649 | result = acpi_thermal_get_temperature(tz); | |
1650 | if (result) | |
d550d98d | 1651 | return result; |
1da177e4 LT |
1652 | |
1653 | /* Get trip points [_CRT, _PSV, etc.] (required) */ | |
1654 | result = acpi_thermal_get_trip_points(tz); | |
1655 | if (result) | |
d550d98d | 1656 | return result; |
1da177e4 LT |
1657 | |
1658 | /* Set the cooling mode [_SCP] to active cooling (default) */ | |
1659 | result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE); | |
4be44fcd | 1660 | if (!result) |
1da177e4 | 1661 | tz->flags.cooling_mode = 1; |
1da177e4 LT |
1662 | |
1663 | /* Get default polling frequency [_TZP] (optional) */ | |
1664 | if (tzp) | |
1665 | tz->polling_frequency = tzp; | |
1666 | else | |
1667 | acpi_thermal_get_polling_frequency(tz); | |
1668 | ||
d550d98d | 1669 | return 0; |
1da177e4 LT |
1670 | } |
1671 | ||
4be44fcd | 1672 | static int acpi_thermal_add(struct acpi_device *device) |
1da177e4 | 1673 | { |
4be44fcd LB |
1674 | int result = 0; |
1675 | acpi_status status = AE_OK; | |
1676 | struct acpi_thermal *tz = NULL; | |
1da177e4 | 1677 | |
1da177e4 LT |
1678 | |
1679 | if (!device) | |
d550d98d | 1680 | return -EINVAL; |
1da177e4 | 1681 | |
36bcbec7 | 1682 | tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL); |
1da177e4 | 1683 | if (!tz) |
d550d98d | 1684 | return -ENOMEM; |
1da177e4 | 1685 | |
8348e1b1 | 1686 | tz->device = device; |
1da177e4 LT |
1687 | strcpy(tz->name, device->pnp.bus_id); |
1688 | strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME); | |
1689 | strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS); | |
db89b4f0 | 1690 | device->driver_data = tz; |
6e215785 | 1691 | mutex_init(&tz->lock); |
3f655ef8 ZR |
1692 | |
1693 | ||
1da177e4 LT |
1694 | result = acpi_thermal_get_info(tz); |
1695 | if (result) | |
3f655ef8 ZR |
1696 | goto free_memory; |
1697 | ||
1698 | result = acpi_thermal_register_thermal_zone(tz); | |
1699 | if (result) | |
1700 | goto free_memory; | |
1da177e4 LT |
1701 | |
1702 | result = acpi_thermal_add_fs(device); | |
1703 | if (result) | |
3f655ef8 | 1704 | goto unregister_thermal_zone; |
1da177e4 LT |
1705 | |
1706 | init_timer(&tz->timer); | |
1707 | ||
ea51011a ZY |
1708 | acpi_thermal_active_off(tz); |
1709 | ||
1da177e4 LT |
1710 | acpi_thermal_check(tz); |
1711 | ||
38ba7c9e | 1712 | status = acpi_install_notify_handler(device->handle, |
4be44fcd LB |
1713 | ACPI_DEVICE_NOTIFY, |
1714 | acpi_thermal_notify, tz); | |
1da177e4 | 1715 | if (ACPI_FAILURE(status)) { |
1da177e4 | 1716 | result = -ENODEV; |
3f655ef8 | 1717 | goto remove_fs; |
1da177e4 LT |
1718 | } |
1719 | ||
1720 | printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n", | |
4be44fcd LB |
1721 | acpi_device_name(device), acpi_device_bid(device), |
1722 | KELVIN_TO_CELSIUS(tz->temperature)); | |
3f655ef8 | 1723 | goto end; |
1da177e4 | 1724 | |
3f655ef8 ZR |
1725 | remove_fs: |
1726 | acpi_thermal_remove_fs(device); | |
1727 | unregister_thermal_zone: | |
1728 | thermal_zone_device_unregister(tz->thermal_zone); | |
1729 | free_memory: | |
1730 | kfree(tz); | |
1731 | end: | |
d550d98d | 1732 | return result; |
1da177e4 LT |
1733 | } |
1734 | ||
4be44fcd | 1735 | static int acpi_thermal_remove(struct acpi_device *device, int type) |
1da177e4 | 1736 | { |
4be44fcd LB |
1737 | acpi_status status = AE_OK; |
1738 | struct acpi_thermal *tz = NULL; | |
1da177e4 | 1739 | |
1da177e4 LT |
1740 | |
1741 | if (!device || !acpi_driver_data(device)) | |
d550d98d | 1742 | return -EINVAL; |
1da177e4 | 1743 | |
50dd0969 | 1744 | tz = acpi_driver_data(device); |
1da177e4 LT |
1745 | |
1746 | /* avoid timer adding new defer task */ | |
1747 | tz->zombie = 1; | |
1748 | /* wait for running timer (on other CPUs) finish */ | |
1749 | del_timer_sync(&(tz->timer)); | |
1750 | /* synchronize deferred task */ | |
1751 | acpi_os_wait_events_complete(NULL); | |
1752 | /* deferred task may reinsert timer */ | |
1753 | del_timer_sync(&(tz->timer)); | |
1754 | ||
38ba7c9e | 1755 | status = acpi_remove_notify_handler(device->handle, |
4be44fcd LB |
1756 | ACPI_DEVICE_NOTIFY, |
1757 | acpi_thermal_notify); | |
1da177e4 LT |
1758 | |
1759 | /* Terminate policy */ | |
4be44fcd | 1760 | if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) { |
1da177e4 LT |
1761 | tz->trips.passive.flags.enabled = 0; |
1762 | acpi_thermal_passive(tz); | |
1763 | } | |
1764 | if (tz->trips.active[0].flags.valid | |
4be44fcd | 1765 | && tz->trips.active[0].flags.enabled) { |
1da177e4 LT |
1766 | tz->trips.active[0].flags.enabled = 0; |
1767 | acpi_thermal_active(tz); | |
1768 | } | |
1769 | ||
1770 | acpi_thermal_remove_fs(device); | |
3f655ef8 | 1771 | acpi_thermal_unregister_thermal_zone(tz); |
6e215785 | 1772 | mutex_destroy(&tz->lock); |
1da177e4 | 1773 | kfree(tz); |
d550d98d | 1774 | return 0; |
1da177e4 LT |
1775 | } |
1776 | ||
5d9464a4 | 1777 | static int acpi_thermal_resume(struct acpi_device *device) |
74ce1468 KK |
1778 | { |
1779 | struct acpi_thermal *tz = NULL; | |
b1028c54 KK |
1780 | int i, j, power_state, result; |
1781 | ||
74ce1468 KK |
1782 | |
1783 | if (!device || !acpi_driver_data(device)) | |
d550d98d | 1784 | return -EINVAL; |
74ce1468 | 1785 | |
50dd0969 | 1786 | tz = acpi_driver_data(device); |
74ce1468 | 1787 | |
bed936f7 | 1788 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
b1028c54 KK |
1789 | if (!(&tz->trips.active[i])) |
1790 | break; | |
1791 | if (!tz->trips.active[i].flags.valid) | |
1792 | break; | |
1793 | tz->trips.active[i].flags.enabled = 1; | |
1794 | for (j = 0; j < tz->trips.active[i].devices.count; j++) { | |
1795 | result = acpi_bus_get_power(tz->trips.active[i].devices. | |
1796 | handles[j], &power_state); | |
1797 | if (result || (power_state != ACPI_STATE_D0)) { | |
1798 | tz->trips.active[i].flags.enabled = 0; | |
1799 | break; | |
1800 | } | |
bed936f7 | 1801 | } |
b1028c54 | 1802 | tz->state.active |= tz->trips.active[i].flags.enabled; |
bed936f7 KK |
1803 | } |
1804 | ||
b1028c54 | 1805 | acpi_thermal_check(tz); |
74ce1468 KK |
1806 | |
1807 | return AE_OK; | |
1808 | } | |
1809 | ||
1855256c | 1810 | static int thermal_act(const struct dmi_system_id *d) { |
0b5bfa1c LB |
1811 | |
1812 | if (act == 0) { | |
1813 | printk(KERN_NOTICE "ACPI: %s detected: " | |
1814 | "disabling all active thermal trip points\n", d->ident); | |
1815 | act = -1; | |
1816 | } | |
1817 | return 0; | |
1818 | } | |
1855256c | 1819 | static int thermal_nocrt(const struct dmi_system_id *d) { |
8c99fdce LB |
1820 | |
1821 | printk(KERN_NOTICE "ACPI: %s detected: " | |
1822 | "disabling all critical thermal trip point actions.\n", d->ident); | |
1823 | nocrt = 1; | |
1824 | return 0; | |
1825 | } | |
1855256c | 1826 | static int thermal_tzp(const struct dmi_system_id *d) { |
0b5bfa1c LB |
1827 | |
1828 | if (tzp == 0) { | |
1829 | printk(KERN_NOTICE "ACPI: %s detected: " | |
1830 | "enabling thermal zone polling\n", d->ident); | |
1831 | tzp = 300; /* 300 dS = 30 Seconds */ | |
1832 | } | |
1833 | return 0; | |
1834 | } | |
1855256c | 1835 | static int thermal_psv(const struct dmi_system_id *d) { |
0b5bfa1c LB |
1836 | |
1837 | if (psv == 0) { | |
1838 | printk(KERN_NOTICE "ACPI: %s detected: " | |
1839 | "disabling all passive thermal trip points\n", d->ident); | |
1840 | psv = -1; | |
1841 | } | |
1842 | return 0; | |
1843 | } | |
1844 | ||
1845 | static struct dmi_system_id thermal_dmi_table[] __initdata = { | |
1846 | /* | |
1847 | * Award BIOS on this AOpen makes thermal control almost worthless. | |
1848 | * http://bugzilla.kernel.org/show_bug.cgi?id=8842 | |
1849 | */ | |
1850 | { | |
1851 | .callback = thermal_act, | |
1852 | .ident = "AOpen i915GMm-HFS", | |
1853 | .matches = { | |
1854 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), | |
1855 | DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), | |
1856 | }, | |
1857 | }, | |
1858 | { | |
1859 | .callback = thermal_psv, | |
1860 | .ident = "AOpen i915GMm-HFS", | |
1861 | .matches = { | |
1862 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), | |
1863 | DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), | |
1864 | }, | |
1865 | }, | |
1866 | { | |
1867 | .callback = thermal_tzp, | |
1868 | .ident = "AOpen i915GMm-HFS", | |
1869 | .matches = { | |
1870 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), | |
1871 | DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), | |
1872 | }, | |
1873 | }, | |
8c99fdce LB |
1874 | { |
1875 | .callback = thermal_nocrt, | |
1876 | .ident = "Gigabyte GA-7ZX", | |
1877 | .matches = { | |
1878 | DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."), | |
1879 | DMI_MATCH(DMI_BOARD_NAME, "7ZX"), | |
1880 | }, | |
1881 | }, | |
0b5bfa1c LB |
1882 | {} |
1883 | }; | |
0b5bfa1c | 1884 | |
4be44fcd | 1885 | static int __init acpi_thermal_init(void) |
1da177e4 | 1886 | { |
4be44fcd | 1887 | int result = 0; |
1da177e4 | 1888 | |
0b5bfa1c LB |
1889 | dmi_check_system(thermal_dmi_table); |
1890 | ||
72b33ef8 LB |
1891 | if (off) { |
1892 | printk(KERN_NOTICE "ACPI: thermal control disabled\n"); | |
1893 | return -ENODEV; | |
1894 | } | |
1da177e4 LT |
1895 | acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir); |
1896 | if (!acpi_thermal_dir) | |
d550d98d | 1897 | return -ENODEV; |
1da177e4 LT |
1898 | acpi_thermal_dir->owner = THIS_MODULE; |
1899 | ||
1900 | result = acpi_bus_register_driver(&acpi_thermal_driver); | |
1901 | if (result < 0) { | |
1902 | remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir); | |
d550d98d | 1903 | return -ENODEV; |
1da177e4 LT |
1904 | } |
1905 | ||
d550d98d | 1906 | return 0; |
1da177e4 LT |
1907 | } |
1908 | ||
4be44fcd | 1909 | static void __exit acpi_thermal_exit(void) |
1da177e4 | 1910 | { |
1da177e4 LT |
1911 | |
1912 | acpi_bus_unregister_driver(&acpi_thermal_driver); | |
1913 | ||
1914 | remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir); | |
1915 | ||
d550d98d | 1916 | return; |
1da177e4 LT |
1917 | } |
1918 | ||
1da177e4 LT |
1919 | module_init(acpi_thermal_init); |
1920 | module_exit(acpi_thermal_exit); |