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