]>
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 | 40 | #include <linux/jiffies.h> |
1da177e4 LT |
41 | #include <linux/kmod.h> |
42 | #include <linux/seq_file.h> | |
10a0a8d4 | 43 | #include <linux/reboot.h> |
f6f5c45e | 44 | #include <linux/device.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 | ||
a192a958 LB |
50 | #define PREFIX "ACPI: " |
51 | ||
1da177e4 | 52 | #define ACPI_THERMAL_CLASS "thermal_zone" |
1da177e4 LT |
53 | #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone" |
54 | #define ACPI_THERMAL_FILE_STATE "state" | |
55 | #define ACPI_THERMAL_FILE_TEMPERATURE "temperature" | |
56 | #define ACPI_THERMAL_FILE_TRIP_POINTS "trip_points" | |
57 | #define ACPI_THERMAL_FILE_COOLING_MODE "cooling_mode" | |
58 | #define ACPI_THERMAL_FILE_POLLING_FREQ "polling_frequency" | |
59 | #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80 | |
60 | #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81 | |
61 | #define ACPI_THERMAL_NOTIFY_DEVICES 0x82 | |
62 | #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0 | |
63 | #define ACPI_THERMAL_NOTIFY_HOT 0xF1 | |
64 | #define ACPI_THERMAL_MODE_ACTIVE 0x00 | |
1da177e4 LT |
65 | |
66 | #define ACPI_THERMAL_MAX_ACTIVE 10 | |
67 | #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65 | |
68 | ||
1da177e4 | 69 | #define _COMPONENT ACPI_THERMAL_COMPONENT |
f52fd66d | 70 | ACPI_MODULE_NAME("thermal"); |
1da177e4 | 71 | |
1cbf4c56 | 72 | MODULE_AUTHOR("Paul Diefenbaugh"); |
7cda93e0 | 73 | MODULE_DESCRIPTION("ACPI Thermal Zone Driver"); |
1da177e4 LT |
74 | MODULE_LICENSE("GPL"); |
75 | ||
f8707ec9 LB |
76 | static int act; |
77 | module_param(act, int, 0644); | |
3c1d36da | 78 | MODULE_PARM_DESC(act, "Disable or override all lowest active trip points."); |
f8707ec9 | 79 | |
c52a7419 LB |
80 | static int crt; |
81 | module_param(crt, int, 0644); | |
82 | MODULE_PARM_DESC(crt, "Disable or lower all critical trip points."); | |
83 | ||
1da177e4 | 84 | static int tzp; |
730ff34d | 85 | module_param(tzp, int, 0444); |
3c1d36da | 86 | MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds."); |
1da177e4 | 87 | |
f5487145 LB |
88 | static int nocrt; |
89 | module_param(nocrt, int, 0); | |
8c99fdce | 90 | MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points."); |
f5487145 | 91 | |
72b33ef8 LB |
92 | static int off; |
93 | module_param(off, int, 0); | |
3c1d36da | 94 | MODULE_PARM_DESC(off, "Set to disable ACPI thermal support."); |
72b33ef8 | 95 | |
a70cdc52 LB |
96 | static int psv; |
97 | module_param(psv, int, 0644); | |
3c1d36da | 98 | MODULE_PARM_DESC(psv, "Disable or override all passive trip points."); |
a70cdc52 | 99 | |
4be44fcd LB |
100 | static int acpi_thermal_add(struct acpi_device *device); |
101 | static int acpi_thermal_remove(struct acpi_device *device, int type); | |
5d9464a4 | 102 | static int acpi_thermal_resume(struct acpi_device *device); |
342d550d | 103 | static void acpi_thermal_notify(struct acpi_device *device, u32 event); |
1da177e4 LT |
104 | static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file); |
105 | static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file); | |
106 | static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file); | |
1da177e4 | 107 | static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file); |
4be44fcd LB |
108 | static ssize_t acpi_thermal_write_cooling_mode(struct file *, |
109 | const char __user *, size_t, | |
110 | loff_t *); | |
1da177e4 | 111 | static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file); |
4be44fcd LB |
112 | static ssize_t acpi_thermal_write_polling(struct file *, const char __user *, |
113 | size_t, loff_t *); | |
1da177e4 | 114 | |
1ba90e3a TR |
115 | static const struct acpi_device_id thermal_device_ids[] = { |
116 | {ACPI_THERMAL_HID, 0}, | |
117 | {"", 0}, | |
118 | }; | |
119 | MODULE_DEVICE_TABLE(acpi, thermal_device_ids); | |
120 | ||
1da177e4 | 121 | static struct acpi_driver acpi_thermal_driver = { |
c2b6705b | 122 | .name = "thermal", |
4be44fcd | 123 | .class = ACPI_THERMAL_CLASS, |
1ba90e3a | 124 | .ids = thermal_device_ids, |
4be44fcd LB |
125 | .ops = { |
126 | .add = acpi_thermal_add, | |
127 | .remove = acpi_thermal_remove, | |
74ce1468 | 128 | .resume = acpi_thermal_resume, |
342d550d | 129 | .notify = acpi_thermal_notify, |
4be44fcd | 130 | }, |
1da177e4 LT |
131 | }; |
132 | ||
133 | struct acpi_thermal_state { | |
4be44fcd LB |
134 | u8 critical:1; |
135 | u8 hot:1; | |
136 | u8 passive:1; | |
137 | u8 active:1; | |
138 | u8 reserved:4; | |
139 | int active_index; | |
1da177e4 LT |
140 | }; |
141 | ||
142 | struct acpi_thermal_state_flags { | |
4be44fcd LB |
143 | u8 valid:1; |
144 | u8 enabled:1; | |
145 | u8 reserved:6; | |
1da177e4 LT |
146 | }; |
147 | ||
148 | struct acpi_thermal_critical { | |
149 | struct acpi_thermal_state_flags flags; | |
4be44fcd | 150 | unsigned long temperature; |
1da177e4 LT |
151 | }; |
152 | ||
153 | struct acpi_thermal_hot { | |
154 | struct acpi_thermal_state_flags flags; | |
4be44fcd | 155 | unsigned long temperature; |
1da177e4 LT |
156 | }; |
157 | ||
158 | struct acpi_thermal_passive { | |
159 | struct acpi_thermal_state_flags flags; | |
4be44fcd LB |
160 | unsigned long temperature; |
161 | unsigned long tc1; | |
162 | unsigned long tc2; | |
163 | unsigned long tsp; | |
164 | struct acpi_handle_list devices; | |
1da177e4 LT |
165 | }; |
166 | ||
167 | struct acpi_thermal_active { | |
168 | struct acpi_thermal_state_flags flags; | |
4be44fcd LB |
169 | unsigned long temperature; |
170 | struct acpi_handle_list devices; | |
1da177e4 LT |
171 | }; |
172 | ||
173 | struct acpi_thermal_trips { | |
174 | struct acpi_thermal_critical critical; | |
4be44fcd | 175 | struct acpi_thermal_hot hot; |
1da177e4 LT |
176 | struct acpi_thermal_passive passive; |
177 | struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE]; | |
178 | }; | |
179 | ||
180 | struct acpi_thermal_flags { | |
4be44fcd LB |
181 | u8 cooling_mode:1; /* _SCP */ |
182 | u8 devices:1; /* _TZD */ | |
183 | u8 reserved:6; | |
1da177e4 LT |
184 | }; |
185 | ||
186 | struct acpi_thermal { | |
8348e1b1 | 187 | struct acpi_device * device; |
4be44fcd LB |
188 | acpi_bus_id name; |
189 | unsigned long temperature; | |
190 | unsigned long last_temperature; | |
191 | unsigned long polling_frequency; | |
4be44fcd | 192 | volatile u8 zombie; |
1da177e4 LT |
193 | struct acpi_thermal_flags flags; |
194 | struct acpi_thermal_state state; | |
195 | struct acpi_thermal_trips trips; | |
4be44fcd | 196 | struct acpi_handle_list devices; |
3f655ef8 ZR |
197 | struct thermal_zone_device *thermal_zone; |
198 | int tz_enabled; | |
13614e37 | 199 | int kelvin_offset; |
6e215785 | 200 | struct mutex lock; |
1da177e4 LT |
201 | }; |
202 | ||
d7508032 | 203 | static const struct file_operations acpi_thermal_state_fops = { |
cf7acfab | 204 | .owner = THIS_MODULE, |
4be44fcd LB |
205 | .open = acpi_thermal_state_open_fs, |
206 | .read = seq_read, | |
207 | .llseek = seq_lseek, | |
208 | .release = single_release, | |
1da177e4 LT |
209 | }; |
210 | ||
d7508032 | 211 | static const struct file_operations acpi_thermal_temp_fops = { |
cf7acfab | 212 | .owner = THIS_MODULE, |
4be44fcd LB |
213 | .open = acpi_thermal_temp_open_fs, |
214 | .read = seq_read, | |
215 | .llseek = seq_lseek, | |
216 | .release = single_release, | |
1da177e4 LT |
217 | }; |
218 | ||
d7508032 | 219 | static const struct file_operations acpi_thermal_trip_fops = { |
cf7acfab | 220 | .owner = THIS_MODULE, |
4be44fcd LB |
221 | .open = acpi_thermal_trip_open_fs, |
222 | .read = seq_read, | |
4be44fcd LB |
223 | .llseek = seq_lseek, |
224 | .release = single_release, | |
1da177e4 LT |
225 | }; |
226 | ||
d7508032 | 227 | static const struct file_operations acpi_thermal_cooling_fops = { |
cf7acfab | 228 | .owner = THIS_MODULE, |
4be44fcd LB |
229 | .open = acpi_thermal_cooling_open_fs, |
230 | .read = seq_read, | |
231 | .write = acpi_thermal_write_cooling_mode, | |
232 | .llseek = seq_lseek, | |
233 | .release = single_release, | |
1da177e4 LT |
234 | }; |
235 | ||
d7508032 | 236 | static const struct file_operations acpi_thermal_polling_fops = { |
cf7acfab | 237 | .owner = THIS_MODULE, |
4be44fcd LB |
238 | .open = acpi_thermal_polling_open_fs, |
239 | .read = seq_read, | |
240 | .write = acpi_thermal_write_polling, | |
241 | .llseek = seq_lseek, | |
242 | .release = single_release, | |
1da177e4 LT |
243 | }; |
244 | ||
245 | /* -------------------------------------------------------------------------- | |
246 | Thermal Zone Management | |
247 | -------------------------------------------------------------------------- */ | |
248 | ||
4be44fcd | 249 | static int acpi_thermal_get_temperature(struct acpi_thermal *tz) |
1da177e4 | 250 | { |
4be44fcd | 251 | acpi_status status = AE_OK; |
27663c58 | 252 | unsigned long long tmp; |
1da177e4 LT |
253 | |
254 | if (!tz) | |
d550d98d | 255 | return -EINVAL; |
1da177e4 LT |
256 | |
257 | tz->last_temperature = tz->temperature; | |
258 | ||
27663c58 | 259 | status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp); |
1da177e4 | 260 | if (ACPI_FAILURE(status)) |
d550d98d | 261 | return -ENODEV; |
1da177e4 | 262 | |
27663c58 | 263 | tz->temperature = tmp; |
4be44fcd LB |
264 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n", |
265 | tz->temperature)); | |
1da177e4 | 266 | |
d550d98d | 267 | return 0; |
1da177e4 LT |
268 | } |
269 | ||
4be44fcd | 270 | static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz) |
1da177e4 | 271 | { |
4be44fcd | 272 | acpi_status status = AE_OK; |
27663c58 | 273 | unsigned long long tmp; |
1da177e4 LT |
274 | |
275 | if (!tz) | |
d550d98d | 276 | return -EINVAL; |
1da177e4 | 277 | |
27663c58 | 278 | status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp); |
1da177e4 | 279 | if (ACPI_FAILURE(status)) |
d550d98d | 280 | return -ENODEV; |
1da177e4 | 281 | |
27663c58 | 282 | tz->polling_frequency = tmp; |
4be44fcd LB |
283 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n", |
284 | tz->polling_frequency)); | |
1da177e4 | 285 | |
d550d98d | 286 | return 0; |
1da177e4 LT |
287 | } |
288 | ||
4be44fcd | 289 | static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds) |
1da177e4 | 290 | { |
1da177e4 LT |
291 | |
292 | if (!tz) | |
d550d98d | 293 | return -EINVAL; |
1da177e4 LT |
294 | |
295 | tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */ | |
296 | ||
b1569e99 MG |
297 | tz->thermal_zone->polling_delay = seconds * 1000; |
298 | ||
299 | if (tz->tz_enabled) | |
300 | thermal_zone_device_update(tz->thermal_zone); | |
301 | ||
4be44fcd LB |
302 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
303 | "Polling frequency set to %lu seconds\n", | |
636cedf9 | 304 | tz->polling_frequency/10)); |
1da177e4 | 305 | |
d550d98d | 306 | return 0; |
1da177e4 LT |
307 | } |
308 | ||
4be44fcd | 309 | static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode) |
1da177e4 | 310 | { |
4be44fcd LB |
311 | acpi_status status = AE_OK; |
312 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | |
313 | struct acpi_object_list arg_list = { 1, &arg0 }; | |
314 | acpi_handle handle = NULL; | |
1da177e4 | 315 | |
1da177e4 LT |
316 | |
317 | if (!tz) | |
d550d98d | 318 | return -EINVAL; |
1da177e4 | 319 | |
38ba7c9e | 320 | status = acpi_get_handle(tz->device->handle, "_SCP", &handle); |
1da177e4 LT |
321 | if (ACPI_FAILURE(status)) { |
322 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n")); | |
d550d98d | 323 | return -ENODEV; |
1da177e4 LT |
324 | } |
325 | ||
326 | arg0.integer.value = mode; | |
327 | ||
328 | status = acpi_evaluate_object(handle, NULL, &arg_list, NULL); | |
329 | if (ACPI_FAILURE(status)) | |
d550d98d | 330 | return -ENODEV; |
1da177e4 | 331 | |
d550d98d | 332 | return 0; |
1da177e4 LT |
333 | } |
334 | ||
ce44e197 ZR |
335 | #define ACPI_TRIPS_CRITICAL 0x01 |
336 | #define ACPI_TRIPS_HOT 0x02 | |
337 | #define ACPI_TRIPS_PASSIVE 0x04 | |
338 | #define ACPI_TRIPS_ACTIVE 0x08 | |
339 | #define ACPI_TRIPS_DEVICES 0x10 | |
1da177e4 | 340 | |
ce44e197 ZR |
341 | #define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE) |
342 | #define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES | |
1da177e4 | 343 | |
ce44e197 ZR |
344 | #define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \ |
345 | ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \ | |
346 | ACPI_TRIPS_DEVICES) | |
1da177e4 | 347 | |
ce44e197 ZR |
348 | /* |
349 | * This exception is thrown out in two cases: | |
350 | * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid | |
351 | * when re-evaluating the AML code. | |
352 | * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change. | |
353 | * We need to re-bind the cooling devices of a thermal zone when this occurs. | |
354 | */ | |
355 | #define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \ | |
356 | do { \ | |
357 | if (flags != ACPI_TRIPS_INIT) \ | |
358 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, \ | |
359 | "ACPI thermal trip point %s changed\n" \ | |
360 | "Please send acpidump to linux-acpi@vger.kernel.org\n", str)); \ | |
361 | } while (0) | |
362 | ||
363 | static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) | |
364 | { | |
365 | acpi_status status = AE_OK; | |
27663c58 | 366 | unsigned long long tmp; |
ce44e197 ZR |
367 | struct acpi_handle_list devices; |
368 | int valid = 0; | |
369 | int i; | |
1da177e4 | 370 | |
ce44e197 ZR |
371 | /* Critical Shutdown (required) */ |
372 | if (flag & ACPI_TRIPS_CRITICAL) { | |
373 | status = acpi_evaluate_integer(tz->device->handle, | |
27663c58 MW |
374 | "_CRT", NULL, &tmp); |
375 | tz->trips.critical.temperature = tmp; | |
a39a2d7c AV |
376 | /* |
377 | * Treat freezing temperatures as invalid as well; some | |
378 | * BIOSes return really low values and cause reboots at startup. | |
b731d7b6 | 379 | * Below zero (Celsius) values clearly aren't right for sure.. |
a39a2d7c AV |
380 | * ... so lets discard those as invalid. |
381 | */ | |
382 | if (ACPI_FAILURE(status) || | |
383 | tz->trips.critical.temperature <= 2732) { | |
c52a7419 | 384 | tz->trips.critical.flags.valid = 0; |
ce44e197 | 385 | ACPI_EXCEPTION((AE_INFO, status, |
a39a2d7c | 386 | "No or invalid critical threshold")); |
ce44e197 ZR |
387 | return -ENODEV; |
388 | } else { | |
389 | tz->trips.critical.flags.valid = 1; | |
390 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
391 | "Found critical threshold [%lu]\n", | |
392 | tz->trips.critical.temperature)); | |
393 | } | |
394 | if (tz->trips.critical.flags.valid == 1) { | |
395 | if (crt == -1) { | |
396 | tz->trips.critical.flags.valid = 0; | |
397 | } else if (crt > 0) { | |
398 | unsigned long crt_k = CELSIUS_TO_KELVIN(crt); | |
399 | /* | |
22a94d79 | 400 | * Allow override critical threshold |
ce44e197 | 401 | */ |
22a94d79 ZR |
402 | if (crt_k > tz->trips.critical.temperature) |
403 | printk(KERN_WARNING PREFIX | |
404 | "Critical threshold %d C\n", crt); | |
405 | tz->trips.critical.temperature = crt_k; | |
ce44e197 | 406 | } |
c52a7419 LB |
407 | } |
408 | } | |
409 | ||
1da177e4 | 410 | /* Critical Sleep (optional) */ |
ce44e197 | 411 | if (flag & ACPI_TRIPS_HOT) { |
a70cdc52 | 412 | status = acpi_evaluate_integer(tz->device->handle, |
27663c58 | 413 | "_HOT", NULL, &tmp); |
ce44e197 ZR |
414 | if (ACPI_FAILURE(status)) { |
415 | tz->trips.hot.flags.valid = 0; | |
416 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
417 | "No hot threshold\n")); | |
418 | } else { | |
27663c58 | 419 | tz->trips.hot.temperature = tmp; |
ce44e197 ZR |
420 | tz->trips.hot.flags.valid = 1; |
421 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
422 | "Found hot threshold [%lu]\n", | |
423 | tz->trips.critical.temperature)); | |
424 | } | |
a70cdc52 LB |
425 | } |
426 | ||
ce44e197 | 427 | /* Passive (optional) */ |
0e4240d9 ZR |
428 | if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) || |
429 | (flag == ACPI_TRIPS_INIT)) { | |
ce44e197 ZR |
430 | valid = tz->trips.passive.flags.valid; |
431 | if (psv == -1) { | |
432 | status = AE_SUPPORT; | |
433 | } else if (psv > 0) { | |
27663c58 | 434 | tmp = CELSIUS_TO_KELVIN(psv); |
ce44e197 ZR |
435 | status = AE_OK; |
436 | } else { | |
437 | status = acpi_evaluate_integer(tz->device->handle, | |
27663c58 | 438 | "_PSV", NULL, &tmp); |
ce44e197 | 439 | } |
1da177e4 | 440 | |
1da177e4 LT |
441 | if (ACPI_FAILURE(status)) |
442 | tz->trips.passive.flags.valid = 0; | |
ce44e197 | 443 | else { |
27663c58 | 444 | tz->trips.passive.temperature = tmp; |
ce44e197 ZR |
445 | tz->trips.passive.flags.valid = 1; |
446 | if (flag == ACPI_TRIPS_INIT) { | |
447 | status = acpi_evaluate_integer( | |
448 | tz->device->handle, "_TC1", | |
27663c58 | 449 | NULL, &tmp); |
ce44e197 ZR |
450 | if (ACPI_FAILURE(status)) |
451 | tz->trips.passive.flags.valid = 0; | |
27663c58 MW |
452 | else |
453 | tz->trips.passive.tc1 = tmp; | |
ce44e197 ZR |
454 | status = acpi_evaluate_integer( |
455 | tz->device->handle, "_TC2", | |
27663c58 | 456 | NULL, &tmp); |
ce44e197 ZR |
457 | if (ACPI_FAILURE(status)) |
458 | tz->trips.passive.flags.valid = 0; | |
27663c58 MW |
459 | else |
460 | tz->trips.passive.tc2 = tmp; | |
ce44e197 ZR |
461 | status = acpi_evaluate_integer( |
462 | tz->device->handle, "_TSP", | |
27663c58 | 463 | NULL, &tmp); |
ce44e197 ZR |
464 | if (ACPI_FAILURE(status)) |
465 | tz->trips.passive.flags.valid = 0; | |
27663c58 MW |
466 | else |
467 | tz->trips.passive.tsp = tmp; | |
ce44e197 ZR |
468 | } |
469 | } | |
470 | } | |
471 | if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) { | |
472 | memset(&devices, 0, sizeof(struct acpi_handle_list)); | |
473 | status = acpi_evaluate_reference(tz->device->handle, "_PSL", | |
474 | NULL, &devices); | |
0e4240d9 ZR |
475 | if (ACPI_FAILURE(status)) { |
476 | printk(KERN_WARNING PREFIX | |
477 | "Invalid passive threshold\n"); | |
1da177e4 | 478 | tz->trips.passive.flags.valid = 0; |
0e4240d9 | 479 | } |
1da177e4 | 480 | else |
ce44e197 | 481 | tz->trips.passive.flags.valid = 1; |
1da177e4 | 482 | |
ce44e197 ZR |
483 | if (memcmp(&tz->trips.passive.devices, &devices, |
484 | sizeof(struct acpi_handle_list))) { | |
485 | memcpy(&tz->trips.passive.devices, &devices, | |
486 | sizeof(struct acpi_handle_list)); | |
487 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); | |
488 | } | |
489 | } | |
490 | if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) { | |
491 | if (valid != tz->trips.passive.flags.valid) | |
492 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state"); | |
493 | } | |
1da177e4 | 494 | |
ce44e197 | 495 | /* Active (optional) */ |
4be44fcd | 496 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
4be44fcd | 497 | char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; |
ce44e197 | 498 | valid = tz->trips.active[i].flags.valid; |
1da177e4 | 499 | |
f8707ec9 | 500 | if (act == -1) |
ce44e197 ZR |
501 | break; /* disable all active trip points */ |
502 | ||
0e4240d9 ZR |
503 | if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) && |
504 | tz->trips.active[i].flags.valid)) { | |
ce44e197 | 505 | status = acpi_evaluate_integer(tz->device->handle, |
27663c58 | 506 | name, NULL, &tmp); |
ce44e197 ZR |
507 | if (ACPI_FAILURE(status)) { |
508 | tz->trips.active[i].flags.valid = 0; | |
509 | if (i == 0) | |
510 | break; | |
511 | if (act <= 0) | |
512 | break; | |
513 | if (i == 1) | |
514 | tz->trips.active[0].temperature = | |
515 | CELSIUS_TO_KELVIN(act); | |
516 | else | |
517 | /* | |
518 | * Don't allow override higher than | |
519 | * the next higher trip point | |
520 | */ | |
521 | tz->trips.active[i - 1].temperature = | |
522 | (tz->trips.active[i - 2].temperature < | |
523 | CELSIUS_TO_KELVIN(act) ? | |
524 | tz->trips.active[i - 2].temperature : | |
525 | CELSIUS_TO_KELVIN(act)); | |
f8707ec9 | 526 | break; |
27663c58 MW |
527 | } else { |
528 | tz->trips.active[i].temperature = tmp; | |
ce44e197 | 529 | tz->trips.active[i].flags.valid = 1; |
27663c58 | 530 | } |
f8707ec9 | 531 | } |
1da177e4 LT |
532 | |
533 | name[2] = 'L'; | |
ce44e197 ZR |
534 | if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) { |
535 | memset(&devices, 0, sizeof(struct acpi_handle_list)); | |
536 | status = acpi_evaluate_reference(tz->device->handle, | |
537 | name, NULL, &devices); | |
0e4240d9 ZR |
538 | if (ACPI_FAILURE(status)) { |
539 | printk(KERN_WARNING PREFIX | |
540 | "Invalid active%d threshold\n", i); | |
ce44e197 | 541 | tz->trips.active[i].flags.valid = 0; |
0e4240d9 | 542 | } |
ce44e197 ZR |
543 | else |
544 | tz->trips.active[i].flags.valid = 1; | |
545 | ||
546 | if (memcmp(&tz->trips.active[i].devices, &devices, | |
547 | sizeof(struct acpi_handle_list))) { | |
548 | memcpy(&tz->trips.active[i].devices, &devices, | |
549 | sizeof(struct acpi_handle_list)); | |
550 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); | |
551 | } | |
552 | } | |
553 | if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES)) | |
554 | if (valid != tz->trips.active[i].flags.valid) | |
555 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state"); | |
556 | ||
557 | if (!tz->trips.active[i].flags.valid) | |
558 | break; | |
559 | } | |
560 | ||
561 | if (flag & ACPI_TRIPS_DEVICES) { | |
562 | memset(&devices, 0, sizeof(struct acpi_handle_list)); | |
563 | status = acpi_evaluate_reference(tz->device->handle, "_TZD", | |
564 | NULL, &devices); | |
565 | if (memcmp(&tz->devices, &devices, | |
566 | sizeof(struct acpi_handle_list))) { | |
567 | memcpy(&tz->devices, &devices, | |
568 | sizeof(struct acpi_handle_list)); | |
569 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); | |
570 | } | |
1da177e4 LT |
571 | } |
572 | ||
d550d98d | 573 | return 0; |
1da177e4 LT |
574 | } |
575 | ||
ce44e197 | 576 | static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) |
1da177e4 | 577 | { |
ce44e197 | 578 | return acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); |
1da177e4 LT |
579 | } |
580 | ||
4be44fcd | 581 | static void acpi_thermal_check(void *data) |
1da177e4 | 582 | { |
50dd0969 | 583 | struct acpi_thermal *tz = data; |
1da177e4 | 584 | |
b1569e99 | 585 | thermal_zone_device_update(tz->thermal_zone); |
1da177e4 LT |
586 | } |
587 | ||
3f655ef8 | 588 | /* sys I/F for generic thermal sysfs support */ |
13614e37 | 589 | #define KELVIN_TO_MILLICELSIUS(t, off) (((t) - (off)) * 100) |
5e012760 | 590 | |
6503e5df MG |
591 | static int thermal_get_temp(struct thermal_zone_device *thermal, |
592 | unsigned long *temp) | |
3f655ef8 ZR |
593 | { |
594 | struct acpi_thermal *tz = thermal->devdata; | |
76ecb4f2 | 595 | int result; |
3f655ef8 ZR |
596 | |
597 | if (!tz) | |
598 | return -EINVAL; | |
599 | ||
76ecb4f2 ZR |
600 | result = acpi_thermal_get_temperature(tz); |
601 | if (result) | |
602 | return result; | |
603 | ||
13614e37 | 604 | *temp = KELVIN_TO_MILLICELSIUS(tz->temperature, tz->kelvin_offset); |
6503e5df | 605 | return 0; |
3f655ef8 ZR |
606 | } |
607 | ||
608 | static const char enabled[] = "kernel"; | |
609 | static const char disabled[] = "user"; | |
610 | static int thermal_get_mode(struct thermal_zone_device *thermal, | |
6503e5df | 611 | enum thermal_device_mode *mode) |
3f655ef8 ZR |
612 | { |
613 | struct acpi_thermal *tz = thermal->devdata; | |
614 | ||
615 | if (!tz) | |
616 | return -EINVAL; | |
617 | ||
6503e5df MG |
618 | *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : |
619 | THERMAL_DEVICE_DISABLED; | |
620 | ||
621 | return 0; | |
3f655ef8 ZR |
622 | } |
623 | ||
624 | static int thermal_set_mode(struct thermal_zone_device *thermal, | |
6503e5df | 625 | enum thermal_device_mode mode) |
3f655ef8 ZR |
626 | { |
627 | struct acpi_thermal *tz = thermal->devdata; | |
628 | int enable; | |
629 | ||
630 | if (!tz) | |
631 | return -EINVAL; | |
632 | ||
633 | /* | |
634 | * enable/disable thermal management from ACPI thermal driver | |
635 | */ | |
6503e5df | 636 | if (mode == THERMAL_DEVICE_ENABLED) |
3f655ef8 | 637 | enable = 1; |
6503e5df | 638 | else if (mode == THERMAL_DEVICE_DISABLED) |
3f655ef8 ZR |
639 | enable = 0; |
640 | else | |
641 | return -EINVAL; | |
642 | ||
643 | if (enable != tz->tz_enabled) { | |
644 | tz->tz_enabled = enable; | |
645 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
646 | "%s ACPI thermal control\n", | |
647 | tz->tz_enabled ? enabled : disabled)); | |
648 | acpi_thermal_check(tz); | |
649 | } | |
650 | return 0; | |
651 | } | |
652 | ||
653 | static int thermal_get_trip_type(struct thermal_zone_device *thermal, | |
6503e5df | 654 | int trip, enum thermal_trip_type *type) |
3f655ef8 ZR |
655 | { |
656 | struct acpi_thermal *tz = thermal->devdata; | |
657 | int i; | |
658 | ||
659 | if (!tz || trip < 0) | |
660 | return -EINVAL; | |
661 | ||
662 | if (tz->trips.critical.flags.valid) { | |
6503e5df MG |
663 | if (!trip) { |
664 | *type = THERMAL_TRIP_CRITICAL; | |
665 | return 0; | |
666 | } | |
3f655ef8 ZR |
667 | trip--; |
668 | } | |
669 | ||
670 | if (tz->trips.hot.flags.valid) { | |
6503e5df MG |
671 | if (!trip) { |
672 | *type = THERMAL_TRIP_HOT; | |
673 | return 0; | |
674 | } | |
3f655ef8 ZR |
675 | trip--; |
676 | } | |
677 | ||
678 | if (tz->trips.passive.flags.valid) { | |
6503e5df MG |
679 | if (!trip) { |
680 | *type = THERMAL_TRIP_PASSIVE; | |
681 | return 0; | |
682 | } | |
3f655ef8 ZR |
683 | trip--; |
684 | } | |
685 | ||
686 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && | |
687 | tz->trips.active[i].flags.valid; i++) { | |
6503e5df MG |
688 | if (!trip) { |
689 | *type = THERMAL_TRIP_ACTIVE; | |
690 | return 0; | |
691 | } | |
3f655ef8 ZR |
692 | trip--; |
693 | } | |
694 | ||
695 | return -EINVAL; | |
696 | } | |
697 | ||
698 | static int thermal_get_trip_temp(struct thermal_zone_device *thermal, | |
6503e5df | 699 | int trip, unsigned long *temp) |
3f655ef8 ZR |
700 | { |
701 | struct acpi_thermal *tz = thermal->devdata; | |
702 | int i; | |
703 | ||
704 | if (!tz || trip < 0) | |
705 | return -EINVAL; | |
706 | ||
707 | if (tz->trips.critical.flags.valid) { | |
6503e5df MG |
708 | if (!trip) { |
709 | *temp = KELVIN_TO_MILLICELSIUS( | |
13614e37 JD |
710 | tz->trips.critical.temperature, |
711 | tz->kelvin_offset); | |
6503e5df MG |
712 | return 0; |
713 | } | |
3f655ef8 ZR |
714 | trip--; |
715 | } | |
716 | ||
717 | if (tz->trips.hot.flags.valid) { | |
6503e5df MG |
718 | if (!trip) { |
719 | *temp = KELVIN_TO_MILLICELSIUS( | |
13614e37 JD |
720 | tz->trips.hot.temperature, |
721 | tz->kelvin_offset); | |
6503e5df MG |
722 | return 0; |
723 | } | |
3f655ef8 ZR |
724 | trip--; |
725 | } | |
726 | ||
727 | if (tz->trips.passive.flags.valid) { | |
6503e5df MG |
728 | if (!trip) { |
729 | *temp = KELVIN_TO_MILLICELSIUS( | |
13614e37 JD |
730 | tz->trips.passive.temperature, |
731 | tz->kelvin_offset); | |
6503e5df MG |
732 | return 0; |
733 | } | |
3f655ef8 ZR |
734 | trip--; |
735 | } | |
736 | ||
737 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && | |
738 | tz->trips.active[i].flags.valid; i++) { | |
6503e5df MG |
739 | if (!trip) { |
740 | *temp = KELVIN_TO_MILLICELSIUS( | |
13614e37 JD |
741 | tz->trips.active[i].temperature, |
742 | tz->kelvin_offset); | |
6503e5df MG |
743 | return 0; |
744 | } | |
3f655ef8 ZR |
745 | trip--; |
746 | } | |
747 | ||
748 | return -EINVAL; | |
749 | } | |
750 | ||
9ec732ff ZR |
751 | static int thermal_get_crit_temp(struct thermal_zone_device *thermal, |
752 | unsigned long *temperature) { | |
753 | struct acpi_thermal *tz = thermal->devdata; | |
754 | ||
755 | if (tz->trips.critical.flags.valid) { | |
756 | *temperature = KELVIN_TO_MILLICELSIUS( | |
13614e37 JD |
757 | tz->trips.critical.temperature, |
758 | tz->kelvin_offset); | |
9ec732ff ZR |
759 | return 0; |
760 | } else | |
761 | return -EINVAL; | |
762 | } | |
763 | ||
b1569e99 MG |
764 | static int thermal_notify(struct thermal_zone_device *thermal, int trip, |
765 | enum thermal_trip_type trip_type) | |
766 | { | |
767 | u8 type = 0; | |
768 | struct acpi_thermal *tz = thermal->devdata; | |
769 | ||
770 | if (trip_type == THERMAL_TRIP_CRITICAL) | |
771 | type = ACPI_THERMAL_NOTIFY_CRITICAL; | |
772 | else if (trip_type == THERMAL_TRIP_HOT) | |
773 | type = ACPI_THERMAL_NOTIFY_HOT; | |
774 | else | |
775 | return 0; | |
776 | ||
777 | acpi_bus_generate_proc_event(tz->device, type, 1); | |
778 | acpi_bus_generate_netlink_event(tz->device->pnp.device_class, | |
f6f5c45e | 779 | dev_name(&tz->device->dev), type, 1); |
b1569e99 MG |
780 | |
781 | if (trip_type == THERMAL_TRIP_CRITICAL && nocrt) | |
782 | return 1; | |
783 | ||
784 | return 0; | |
785 | } | |
786 | ||
3f655ef8 ZR |
787 | typedef int (*cb)(struct thermal_zone_device *, int, |
788 | struct thermal_cooling_device *); | |
789 | static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal, | |
790 | struct thermal_cooling_device *cdev, | |
791 | cb action) | |
792 | { | |
793 | struct acpi_device *device = cdev->devdata; | |
794 | struct acpi_thermal *tz = thermal->devdata; | |
653a00c9 ZR |
795 | struct acpi_device *dev; |
796 | acpi_status status; | |
797 | acpi_handle handle; | |
3f655ef8 ZR |
798 | int i; |
799 | int j; | |
800 | int trip = -1; | |
801 | int result = 0; | |
802 | ||
803 | if (tz->trips.critical.flags.valid) | |
804 | trip++; | |
805 | ||
806 | if (tz->trips.hot.flags.valid) | |
807 | trip++; | |
808 | ||
809 | if (tz->trips.passive.flags.valid) { | |
810 | trip++; | |
811 | for (i = 0; i < tz->trips.passive.devices.count; | |
812 | i++) { | |
653a00c9 ZR |
813 | handle = tz->trips.passive.devices.handles[i]; |
814 | status = acpi_bus_get_device(handle, &dev); | |
815 | if (ACPI_SUCCESS(status) && (dev == device)) { | |
816 | result = action(thermal, trip, cdev); | |
817 | if (result) | |
818 | goto failed; | |
819 | } | |
3f655ef8 ZR |
820 | } |
821 | } | |
822 | ||
823 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { | |
824 | if (!tz->trips.active[i].flags.valid) | |
825 | break; | |
826 | trip++; | |
827 | for (j = 0; | |
828 | j < tz->trips.active[i].devices.count; | |
829 | j++) { | |
653a00c9 ZR |
830 | handle = tz->trips.active[i].devices.handles[j]; |
831 | status = acpi_bus_get_device(handle, &dev); | |
832 | if (ACPI_SUCCESS(status) && (dev == device)) { | |
833 | result = action(thermal, trip, cdev); | |
834 | if (result) | |
835 | goto failed; | |
836 | } | |
3f655ef8 ZR |
837 | } |
838 | } | |
839 | ||
840 | for (i = 0; i < tz->devices.count; i++) { | |
653a00c9 ZR |
841 | handle = tz->devices.handles[i]; |
842 | status = acpi_bus_get_device(handle, &dev); | |
843 | if (ACPI_SUCCESS(status) && (dev == device)) { | |
844 | result = action(thermal, -1, cdev); | |
845 | if (result) | |
846 | goto failed; | |
847 | } | |
3f655ef8 ZR |
848 | } |
849 | ||
850 | failed: | |
851 | return result; | |
852 | } | |
853 | ||
854 | static int | |
855 | acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal, | |
856 | struct thermal_cooling_device *cdev) | |
857 | { | |
858 | return acpi_thermal_cooling_device_cb(thermal, cdev, | |
859 | thermal_zone_bind_cooling_device); | |
860 | } | |
861 | ||
862 | static int | |
863 | acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal, | |
864 | struct thermal_cooling_device *cdev) | |
865 | { | |
866 | return acpi_thermal_cooling_device_cb(thermal, cdev, | |
867 | thermal_zone_unbind_cooling_device); | |
868 | } | |
869 | ||
870 | static struct thermal_zone_device_ops acpi_thermal_zone_ops = { | |
871 | .bind = acpi_thermal_bind_cooling_device, | |
872 | .unbind = acpi_thermal_unbind_cooling_device, | |
873 | .get_temp = thermal_get_temp, | |
874 | .get_mode = thermal_get_mode, | |
875 | .set_mode = thermal_set_mode, | |
876 | .get_trip_type = thermal_get_trip_type, | |
877 | .get_trip_temp = thermal_get_trip_temp, | |
9ec732ff | 878 | .get_crit_temp = thermal_get_crit_temp, |
b1569e99 | 879 | .notify = thermal_notify, |
3f655ef8 ZR |
880 | }; |
881 | ||
882 | static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) | |
883 | { | |
884 | int trips = 0; | |
885 | int result; | |
20733939 | 886 | acpi_status status; |
3f655ef8 ZR |
887 | int i; |
888 | ||
889 | if (tz->trips.critical.flags.valid) | |
890 | trips++; | |
891 | ||
892 | if (tz->trips.hot.flags.valid) | |
893 | trips++; | |
894 | ||
895 | if (tz->trips.passive.flags.valid) | |
896 | trips++; | |
897 | ||
898 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && | |
899 | tz->trips.active[i].flags.valid; i++, trips++); | |
b1569e99 MG |
900 | |
901 | if (tz->trips.passive.flags.valid) | |
902 | tz->thermal_zone = | |
903 | thermal_zone_device_register("acpitz", trips, tz, | |
904 | &acpi_thermal_zone_ops, | |
905 | tz->trips.passive.tc1, | |
906 | tz->trips.passive.tc2, | |
907 | tz->trips.passive.tsp*100, | |
908 | tz->polling_frequency*100); | |
909 | else | |
910 | tz->thermal_zone = | |
911 | thermal_zone_device_register("acpitz", trips, tz, | |
912 | &acpi_thermal_zone_ops, | |
913 | 0, 0, 0, | |
67405439 | 914 | tz->polling_frequency*100); |
bb070e43 | 915 | if (IS_ERR(tz->thermal_zone)) |
3f655ef8 ZR |
916 | return -ENODEV; |
917 | ||
918 | result = sysfs_create_link(&tz->device->dev.kobj, | |
919 | &tz->thermal_zone->device.kobj, "thermal_zone"); | |
920 | if (result) | |
921 | return result; | |
922 | ||
923 | result = sysfs_create_link(&tz->thermal_zone->device.kobj, | |
924 | &tz->device->dev.kobj, "device"); | |
925 | if (result) | |
926 | return result; | |
927 | ||
20733939 ZR |
928 | status = acpi_attach_data(tz->device->handle, |
929 | acpi_bus_private_data_handler, | |
930 | tz->thermal_zone); | |
931 | if (ACPI_FAILURE(status)) { | |
55ac9a01 LM |
932 | printk(KERN_ERR PREFIX |
933 | "Error attaching device data\n"); | |
20733939 ZR |
934 | return -ENODEV; |
935 | } | |
936 | ||
3f655ef8 ZR |
937 | tz->tz_enabled = 1; |
938 | ||
fc3a8828 GKH |
939 | dev_info(&tz->device->dev, "registered as thermal_zone%d\n", |
940 | tz->thermal_zone->id); | |
3f655ef8 ZR |
941 | return 0; |
942 | } | |
943 | ||
944 | static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz) | |
945 | { | |
946 | sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); | |
947 | sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); | |
948 | thermal_zone_device_unregister(tz->thermal_zone); | |
949 | tz->thermal_zone = NULL; | |
20733939 | 950 | acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler); |
3f655ef8 ZR |
951 | } |
952 | ||
953 | ||
1da177e4 LT |
954 | /* -------------------------------------------------------------------------- |
955 | FS Interface (/proc) | |
956 | -------------------------------------------------------------------------- */ | |
957 | ||
4be44fcd | 958 | static struct proc_dir_entry *acpi_thermal_dir; |
1da177e4 LT |
959 | |
960 | static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset) | |
961 | { | |
50dd0969 | 962 | struct acpi_thermal *tz = seq->private; |
1da177e4 | 963 | |
1da177e4 LT |
964 | |
965 | if (!tz) | |
966 | goto end; | |
967 | ||
968 | seq_puts(seq, "state: "); | |
969 | ||
4be44fcd LB |
970 | if (!tz->state.critical && !tz->state.hot && !tz->state.passive |
971 | && !tz->state.active) | |
1da177e4 LT |
972 | seq_puts(seq, "ok\n"); |
973 | else { | |
974 | if (tz->state.critical) | |
975 | seq_puts(seq, "critical "); | |
976 | if (tz->state.hot) | |
977 | seq_puts(seq, "hot "); | |
978 | if (tz->state.passive) | |
979 | seq_puts(seq, "passive "); | |
980 | if (tz->state.active) | |
981 | seq_printf(seq, "active[%d]", tz->state.active_index); | |
982 | seq_puts(seq, "\n"); | |
983 | } | |
984 | ||
4be44fcd | 985 | end: |
d550d98d | 986 | return 0; |
1da177e4 LT |
987 | } |
988 | ||
989 | static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file) | |
990 | { | |
991 | return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data); | |
992 | } | |
993 | ||
1da177e4 LT |
994 | static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset) |
995 | { | |
4be44fcd | 996 | int result = 0; |
50dd0969 | 997 | struct acpi_thermal *tz = seq->private; |
1da177e4 | 998 | |
1da177e4 LT |
999 | |
1000 | if (!tz) | |
1001 | goto end; | |
1002 | ||
1003 | result = acpi_thermal_get_temperature(tz); | |
1004 | if (result) | |
1005 | goto end; | |
1006 | ||
4be44fcd LB |
1007 | seq_printf(seq, "temperature: %ld C\n", |
1008 | KELVIN_TO_CELSIUS(tz->temperature)); | |
1da177e4 | 1009 | |
4be44fcd | 1010 | end: |
d550d98d | 1011 | return 0; |
1da177e4 LT |
1012 | } |
1013 | ||
1014 | static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file) | |
1015 | { | |
1016 | return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data); | |
1017 | } | |
1018 | ||
1da177e4 LT |
1019 | static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset) |
1020 | { | |
50dd0969 | 1021 | struct acpi_thermal *tz = seq->private; |
68ccfaa8 | 1022 | struct acpi_device *device; |
e7c746ef TR |
1023 | acpi_status status; |
1024 | ||
4be44fcd LB |
1025 | int i = 0; |
1026 | int j = 0; | |
1da177e4 | 1027 | |
1da177e4 LT |
1028 | |
1029 | if (!tz) | |
1030 | goto end; | |
1031 | ||
1032 | if (tz->trips.critical.flags.valid) | |
f5487145 LB |
1033 | seq_printf(seq, "critical (S5): %ld C%s", |
1034 | KELVIN_TO_CELSIUS(tz->trips.critical.temperature), | |
1035 | nocrt ? " <disabled>\n" : "\n"); | |
1da177e4 LT |
1036 | |
1037 | if (tz->trips.hot.flags.valid) | |
f5487145 LB |
1038 | seq_printf(seq, "hot (S4): %ld C%s", |
1039 | KELVIN_TO_CELSIUS(tz->trips.hot.temperature), | |
1040 | nocrt ? " <disabled>\n" : "\n"); | |
1da177e4 LT |
1041 | |
1042 | if (tz->trips.passive.flags.valid) { | |
4be44fcd LB |
1043 | seq_printf(seq, |
1044 | "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=", | |
1045 | KELVIN_TO_CELSIUS(tz->trips.passive.temperature), | |
1046 | tz->trips.passive.tc1, tz->trips.passive.tc2, | |
1047 | tz->trips.passive.tsp); | |
1048 | for (j = 0; j < tz->trips.passive.devices.count; j++) { | |
e7c746ef TR |
1049 | status = acpi_bus_get_device(tz->trips.passive.devices. |
1050 | handles[j], &device); | |
1051 | seq_printf(seq, "%4.4s ", status ? "" : | |
1052 | acpi_device_bid(device)); | |
1da177e4 LT |
1053 | } |
1054 | seq_puts(seq, "\n"); | |
1055 | } | |
1056 | ||
1057 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { | |
1058 | if (!(tz->trips.active[i].flags.valid)) | |
1059 | break; | |
1060 | seq_printf(seq, "active[%d]: %ld C: devices=", | |
4be44fcd LB |
1061 | i, |
1062 | KELVIN_TO_CELSIUS(tz->trips.active[i].temperature)); | |
68ccfaa8 | 1063 | for (j = 0; j < tz->trips.active[i].devices.count; j++){ |
e7c746ef TR |
1064 | status = acpi_bus_get_device(tz->trips.active[i]. |
1065 | devices.handles[j], | |
1066 | &device); | |
1067 | seq_printf(seq, "%4.4s ", status ? "" : | |
1068 | acpi_device_bid(device)); | |
68ccfaa8 | 1069 | } |
1da177e4 LT |
1070 | seq_puts(seq, "\n"); |
1071 | } | |
1072 | ||
4be44fcd | 1073 | end: |
d550d98d | 1074 | return 0; |
1da177e4 LT |
1075 | } |
1076 | ||
1077 | static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file) | |
1078 | { | |
1079 | return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data); | |
1080 | } | |
1081 | ||
1da177e4 LT |
1082 | static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset) |
1083 | { | |
50dd0969 | 1084 | struct acpi_thermal *tz = seq->private; |
1da177e4 | 1085 | |
1da177e4 LT |
1086 | |
1087 | if (!tz) | |
1088 | goto end; | |
1089 | ||
eaca2d3f | 1090 | if (!tz->flags.cooling_mode) |
1da177e4 | 1091 | seq_puts(seq, "<setting not supported>\n"); |
1da177e4 | 1092 | else |
eaca2d3f | 1093 | seq_puts(seq, "0 - Active; 1 - Passive\n"); |
1da177e4 | 1094 | |
4be44fcd | 1095 | end: |
d550d98d | 1096 | return 0; |
1da177e4 LT |
1097 | } |
1098 | ||
1099 | static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file) | |
1100 | { | |
1101 | return single_open(file, acpi_thermal_cooling_seq_show, | |
4be44fcd | 1102 | PDE(inode)->data); |
1da177e4 LT |
1103 | } |
1104 | ||
1105 | static ssize_t | |
4be44fcd LB |
1106 | acpi_thermal_write_cooling_mode(struct file *file, |
1107 | const char __user * buffer, | |
1108 | size_t count, loff_t * ppos) | |
1da177e4 | 1109 | { |
50dd0969 JE |
1110 | struct seq_file *m = file->private_data; |
1111 | struct acpi_thermal *tz = m->private; | |
4be44fcd LB |
1112 | int result = 0; |
1113 | char mode_string[12] = { '\0' }; | |
1da177e4 | 1114 | |
1da177e4 LT |
1115 | |
1116 | if (!tz || (count > sizeof(mode_string) - 1)) | |
d550d98d | 1117 | return -EINVAL; |
1da177e4 LT |
1118 | |
1119 | if (!tz->flags.cooling_mode) | |
d550d98d | 1120 | return -ENODEV; |
1da177e4 LT |
1121 | |
1122 | if (copy_from_user(mode_string, buffer, count)) | |
d550d98d | 1123 | return -EFAULT; |
4be44fcd | 1124 | |
1da177e4 | 1125 | mode_string[count] = '\0'; |
4be44fcd LB |
1126 | |
1127 | result = acpi_thermal_set_cooling_mode(tz, | |
1128 | simple_strtoul(mode_string, NULL, | |
1129 | 0)); | |
1da177e4 | 1130 | if (result) |
d550d98d | 1131 | return result; |
1da177e4 LT |
1132 | |
1133 | acpi_thermal_check(tz); | |
1134 | ||
d550d98d | 1135 | return count; |
1da177e4 LT |
1136 | } |
1137 | ||
1da177e4 LT |
1138 | static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset) |
1139 | { | |
50dd0969 | 1140 | struct acpi_thermal *tz = seq->private; |
1da177e4 | 1141 | |
1da177e4 LT |
1142 | |
1143 | if (!tz) | |
1144 | goto end; | |
1145 | ||
b1569e99 | 1146 | if (!tz->thermal_zone->polling_delay) { |
1da177e4 LT |
1147 | seq_puts(seq, "<polling disabled>\n"); |
1148 | goto end; | |
1149 | } | |
1150 | ||
b1569e99 MG |
1151 | seq_printf(seq, "polling frequency: %d seconds\n", |
1152 | (tz->thermal_zone->polling_delay / 1000)); | |
1da177e4 | 1153 | |
4be44fcd | 1154 | end: |
d550d98d | 1155 | return 0; |
1da177e4 LT |
1156 | } |
1157 | ||
1158 | static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file) | |
1159 | { | |
1160 | return single_open(file, acpi_thermal_polling_seq_show, | |
4be44fcd | 1161 | PDE(inode)->data); |
1da177e4 LT |
1162 | } |
1163 | ||
1164 | static ssize_t | |
4be44fcd LB |
1165 | acpi_thermal_write_polling(struct file *file, |
1166 | const char __user * buffer, | |
1167 | size_t count, loff_t * ppos) | |
1da177e4 | 1168 | { |
50dd0969 JE |
1169 | struct seq_file *m = file->private_data; |
1170 | struct acpi_thermal *tz = m->private; | |
4be44fcd LB |
1171 | int result = 0; |
1172 | char polling_string[12] = { '\0' }; | |
1173 | int seconds = 0; | |
1da177e4 | 1174 | |
1da177e4 LT |
1175 | |
1176 | if (!tz || (count > sizeof(polling_string) - 1)) | |
d550d98d | 1177 | return -EINVAL; |
4be44fcd | 1178 | |
1da177e4 | 1179 | if (copy_from_user(polling_string, buffer, count)) |
d550d98d | 1180 | return -EFAULT; |
4be44fcd | 1181 | |
1da177e4 LT |
1182 | polling_string[count] = '\0'; |
1183 | ||
1184 | seconds = simple_strtoul(polling_string, NULL, 0); | |
4be44fcd | 1185 | |
1da177e4 LT |
1186 | result = acpi_thermal_set_polling(tz, seconds); |
1187 | if (result) | |
d550d98d | 1188 | return result; |
1da177e4 LT |
1189 | |
1190 | acpi_thermal_check(tz); | |
1191 | ||
d550d98d | 1192 | return count; |
1da177e4 LT |
1193 | } |
1194 | ||
4be44fcd | 1195 | static int acpi_thermal_add_fs(struct acpi_device *device) |
1da177e4 | 1196 | { |
4be44fcd | 1197 | struct proc_dir_entry *entry = NULL; |
1da177e4 | 1198 | |
1da177e4 LT |
1199 | |
1200 | if (!acpi_device_dir(device)) { | |
1201 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), | |
4be44fcd | 1202 | acpi_thermal_dir); |
1da177e4 | 1203 | if (!acpi_device_dir(device)) |
d550d98d | 1204 | return -ENODEV; |
1da177e4 LT |
1205 | } |
1206 | ||
1207 | /* 'state' [R] */ | |
cf7acfab DL |
1208 | entry = proc_create_data(ACPI_THERMAL_FILE_STATE, |
1209 | S_IRUGO, acpi_device_dir(device), | |
1210 | &acpi_thermal_state_fops, | |
1211 | acpi_driver_data(device)); | |
1da177e4 | 1212 | if (!entry) |
d550d98d | 1213 | return -ENODEV; |
1da177e4 LT |
1214 | |
1215 | /* 'temperature' [R] */ | |
cf7acfab DL |
1216 | entry = proc_create_data(ACPI_THERMAL_FILE_TEMPERATURE, |
1217 | S_IRUGO, acpi_device_dir(device), | |
1218 | &acpi_thermal_temp_fops, | |
1219 | acpi_driver_data(device)); | |
1da177e4 | 1220 | if (!entry) |
d550d98d | 1221 | return -ENODEV; |
1da177e4 | 1222 | |
2db9ccba | 1223 | /* 'trip_points' [R] */ |
cf7acfab DL |
1224 | entry = proc_create_data(ACPI_THERMAL_FILE_TRIP_POINTS, |
1225 | S_IRUGO, | |
1226 | acpi_device_dir(device), | |
1227 | &acpi_thermal_trip_fops, | |
1228 | acpi_driver_data(device)); | |
1da177e4 | 1229 | if (!entry) |
d550d98d | 1230 | return -ENODEV; |
1da177e4 LT |
1231 | |
1232 | /* 'cooling_mode' [R/W] */ | |
cf7acfab DL |
1233 | entry = proc_create_data(ACPI_THERMAL_FILE_COOLING_MODE, |
1234 | S_IFREG | S_IRUGO | S_IWUSR, | |
1235 | acpi_device_dir(device), | |
1236 | &acpi_thermal_cooling_fops, | |
1237 | acpi_driver_data(device)); | |
1da177e4 | 1238 | if (!entry) |
d550d98d | 1239 | return -ENODEV; |
1da177e4 LT |
1240 | |
1241 | /* 'polling_frequency' [R/W] */ | |
cf7acfab DL |
1242 | entry = proc_create_data(ACPI_THERMAL_FILE_POLLING_FREQ, |
1243 | S_IFREG | S_IRUGO | S_IWUSR, | |
1244 | acpi_device_dir(device), | |
1245 | &acpi_thermal_polling_fops, | |
1246 | acpi_driver_data(device)); | |
1da177e4 | 1247 | if (!entry) |
d550d98d | 1248 | return -ENODEV; |
d550d98d | 1249 | return 0; |
1da177e4 LT |
1250 | } |
1251 | ||
4be44fcd | 1252 | static int acpi_thermal_remove_fs(struct acpi_device *device) |
1da177e4 | 1253 | { |
1da177e4 LT |
1254 | |
1255 | if (acpi_device_dir(device)) { | |
1256 | remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ, | |
1257 | acpi_device_dir(device)); | |
1258 | remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE, | |
1259 | acpi_device_dir(device)); | |
1260 | remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS, | |
1261 | acpi_device_dir(device)); | |
1262 | remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE, | |
1263 | acpi_device_dir(device)); | |
1264 | remove_proc_entry(ACPI_THERMAL_FILE_STATE, | |
1265 | acpi_device_dir(device)); | |
1266 | remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir); | |
1267 | acpi_device_dir(device) = NULL; | |
1268 | } | |
1269 | ||
d550d98d | 1270 | return 0; |
1da177e4 LT |
1271 | } |
1272 | ||
1da177e4 LT |
1273 | /* -------------------------------------------------------------------------- |
1274 | Driver Interface | |
1275 | -------------------------------------------------------------------------- */ | |
1276 | ||
342d550d | 1277 | static void acpi_thermal_notify(struct acpi_device *device, u32 event) |
1da177e4 | 1278 | { |
342d550d | 1279 | struct acpi_thermal *tz = acpi_driver_data(device); |
1da177e4 | 1280 | |
1da177e4 LT |
1281 | |
1282 | if (!tz) | |
d550d98d | 1283 | return; |
1da177e4 | 1284 | |
1da177e4 LT |
1285 | switch (event) { |
1286 | case ACPI_THERMAL_NOTIFY_TEMPERATURE: | |
1287 | acpi_thermal_check(tz); | |
1288 | break; | |
1289 | case ACPI_THERMAL_NOTIFY_THRESHOLDS: | |
ce44e197 | 1290 | acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS); |
1da177e4 | 1291 | acpi_thermal_check(tz); |
14e04fb3 | 1292 | acpi_bus_generate_proc_event(device, event, 0); |
962ce8ca | 1293 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
0794469d | 1294 | dev_name(&device->dev), event, 0); |
1da177e4 LT |
1295 | break; |
1296 | case ACPI_THERMAL_NOTIFY_DEVICES: | |
ce44e197 ZR |
1297 | acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES); |
1298 | acpi_thermal_check(tz); | |
14e04fb3 | 1299 | acpi_bus_generate_proc_event(device, event, 0); |
962ce8ca | 1300 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
0794469d | 1301 | dev_name(&device->dev), event, 0); |
1da177e4 LT |
1302 | break; |
1303 | default: | |
1304 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
4be44fcd | 1305 | "Unsupported event [0x%x]\n", event)); |
1da177e4 LT |
1306 | break; |
1307 | } | |
1da177e4 LT |
1308 | } |
1309 | ||
4be44fcd | 1310 | static int acpi_thermal_get_info(struct acpi_thermal *tz) |
1da177e4 | 1311 | { |
4be44fcd | 1312 | int result = 0; |
1da177e4 | 1313 | |
1da177e4 LT |
1314 | |
1315 | if (!tz) | |
d550d98d | 1316 | return -EINVAL; |
1da177e4 LT |
1317 | |
1318 | /* Get temperature [_TMP] (required) */ | |
1319 | result = acpi_thermal_get_temperature(tz); | |
1320 | if (result) | |
d550d98d | 1321 | return result; |
1da177e4 LT |
1322 | |
1323 | /* Get trip points [_CRT, _PSV, etc.] (required) */ | |
1324 | result = acpi_thermal_get_trip_points(tz); | |
1325 | if (result) | |
d550d98d | 1326 | return result; |
1da177e4 LT |
1327 | |
1328 | /* Set the cooling mode [_SCP] to active cooling (default) */ | |
1329 | result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE); | |
4be44fcd | 1330 | if (!result) |
1da177e4 | 1331 | tz->flags.cooling_mode = 1; |
1da177e4 LT |
1332 | |
1333 | /* Get default polling frequency [_TZP] (optional) */ | |
1334 | if (tzp) | |
1335 | tz->polling_frequency = tzp; | |
1336 | else | |
1337 | acpi_thermal_get_polling_frequency(tz); | |
1338 | ||
d550d98d | 1339 | return 0; |
1da177e4 LT |
1340 | } |
1341 | ||
13614e37 JD |
1342 | /* |
1343 | * The exact offset between Kelvin and degree Celsius is 273.15. However ACPI | |
1344 | * handles temperature values with a single decimal place. As a consequence, | |
1345 | * some implementations use an offset of 273.1 and others use an offset of | |
1346 | * 273.2. Try to find out which one is being used, to present the most | |
1347 | * accurate and visually appealing number. | |
1348 | * | |
1349 | * The heuristic below should work for all ACPI thermal zones which have a | |
1350 | * critical trip point with a value being a multiple of 0.5 degree Celsius. | |
1351 | */ | |
1352 | static void acpi_thermal_guess_offset(struct acpi_thermal *tz) | |
1353 | { | |
1354 | if (tz->trips.critical.flags.valid && | |
1355 | (tz->trips.critical.temperature % 5) == 1) | |
1356 | tz->kelvin_offset = 2731; | |
1357 | else | |
1358 | tz->kelvin_offset = 2732; | |
1359 | } | |
1360 | ||
4be44fcd | 1361 | static int acpi_thermal_add(struct acpi_device *device) |
1da177e4 | 1362 | { |
4be44fcd | 1363 | int result = 0; |
4be44fcd | 1364 | struct acpi_thermal *tz = NULL; |
1da177e4 | 1365 | |
1da177e4 LT |
1366 | |
1367 | if (!device) | |
d550d98d | 1368 | return -EINVAL; |
1da177e4 | 1369 | |
36bcbec7 | 1370 | tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL); |
1da177e4 | 1371 | if (!tz) |
d550d98d | 1372 | return -ENOMEM; |
1da177e4 | 1373 | |
8348e1b1 | 1374 | tz->device = device; |
1da177e4 LT |
1375 | strcpy(tz->name, device->pnp.bus_id); |
1376 | strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME); | |
1377 | strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS); | |
db89b4f0 | 1378 | device->driver_data = tz; |
6e215785 | 1379 | mutex_init(&tz->lock); |
3f655ef8 ZR |
1380 | |
1381 | ||
1da177e4 LT |
1382 | result = acpi_thermal_get_info(tz); |
1383 | if (result) | |
3f655ef8 ZR |
1384 | goto free_memory; |
1385 | ||
13614e37 JD |
1386 | acpi_thermal_guess_offset(tz); |
1387 | ||
3f655ef8 ZR |
1388 | result = acpi_thermal_register_thermal_zone(tz); |
1389 | if (result) | |
1390 | goto free_memory; | |
1da177e4 LT |
1391 | |
1392 | result = acpi_thermal_add_fs(device); | |
1393 | if (result) | |
3f655ef8 | 1394 | goto unregister_thermal_zone; |
1da177e4 | 1395 | |
1da177e4 | 1396 | printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n", |
4be44fcd LB |
1397 | acpi_device_name(device), acpi_device_bid(device), |
1398 | KELVIN_TO_CELSIUS(tz->temperature)); | |
3f655ef8 | 1399 | goto end; |
1da177e4 | 1400 | |
3f655ef8 ZR |
1401 | unregister_thermal_zone: |
1402 | thermal_zone_device_unregister(tz->thermal_zone); | |
1403 | free_memory: | |
1404 | kfree(tz); | |
1405 | end: | |
d550d98d | 1406 | return result; |
1da177e4 LT |
1407 | } |
1408 | ||
4be44fcd | 1409 | static int acpi_thermal_remove(struct acpi_device *device, int type) |
1da177e4 | 1410 | { |
4be44fcd | 1411 | struct acpi_thermal *tz = NULL; |
1da177e4 | 1412 | |
1da177e4 | 1413 | if (!device || !acpi_driver_data(device)) |
d550d98d | 1414 | return -EINVAL; |
1da177e4 | 1415 | |
50dd0969 | 1416 | tz = acpi_driver_data(device); |
1da177e4 | 1417 | |
1da177e4 | 1418 | acpi_thermal_remove_fs(device); |
3f655ef8 | 1419 | acpi_thermal_unregister_thermal_zone(tz); |
6e215785 | 1420 | mutex_destroy(&tz->lock); |
1da177e4 | 1421 | kfree(tz); |
d550d98d | 1422 | return 0; |
1da177e4 LT |
1423 | } |
1424 | ||
5d9464a4 | 1425 | static int acpi_thermal_resume(struct acpi_device *device) |
74ce1468 KK |
1426 | { |
1427 | struct acpi_thermal *tz = NULL; | |
b1028c54 KK |
1428 | int i, j, power_state, result; |
1429 | ||
74ce1468 KK |
1430 | |
1431 | if (!device || !acpi_driver_data(device)) | |
d550d98d | 1432 | return -EINVAL; |
74ce1468 | 1433 | |
50dd0969 | 1434 | tz = acpi_driver_data(device); |
74ce1468 | 1435 | |
bed936f7 | 1436 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
b1028c54 KK |
1437 | if (!(&tz->trips.active[i])) |
1438 | break; | |
1439 | if (!tz->trips.active[i].flags.valid) | |
1440 | break; | |
1441 | tz->trips.active[i].flags.enabled = 1; | |
1442 | for (j = 0; j < tz->trips.active[i].devices.count; j++) { | |
1443 | result = acpi_bus_get_power(tz->trips.active[i].devices. | |
1444 | handles[j], &power_state); | |
1445 | if (result || (power_state != ACPI_STATE_D0)) { | |
1446 | tz->trips.active[i].flags.enabled = 0; | |
1447 | break; | |
1448 | } | |
bed936f7 | 1449 | } |
b1028c54 | 1450 | tz->state.active |= tz->trips.active[i].flags.enabled; |
bed936f7 KK |
1451 | } |
1452 | ||
b1028c54 | 1453 | acpi_thermal_check(tz); |
74ce1468 KK |
1454 | |
1455 | return AE_OK; | |
1456 | } | |
1457 | ||
1855256c | 1458 | static int thermal_act(const struct dmi_system_id *d) { |
0b5bfa1c LB |
1459 | |
1460 | if (act == 0) { | |
1461 | printk(KERN_NOTICE "ACPI: %s detected: " | |
1462 | "disabling all active thermal trip points\n", d->ident); | |
1463 | act = -1; | |
1464 | } | |
1465 | return 0; | |
1466 | } | |
1855256c | 1467 | static int thermal_nocrt(const struct dmi_system_id *d) { |
8c99fdce LB |
1468 | |
1469 | printk(KERN_NOTICE "ACPI: %s detected: " | |
1470 | "disabling all critical thermal trip point actions.\n", d->ident); | |
1471 | nocrt = 1; | |
1472 | return 0; | |
1473 | } | |
1855256c | 1474 | static int thermal_tzp(const struct dmi_system_id *d) { |
0b5bfa1c LB |
1475 | |
1476 | if (tzp == 0) { | |
1477 | printk(KERN_NOTICE "ACPI: %s detected: " | |
1478 | "enabling thermal zone polling\n", d->ident); | |
1479 | tzp = 300; /* 300 dS = 30 Seconds */ | |
1480 | } | |
1481 | return 0; | |
1482 | } | |
1855256c | 1483 | static int thermal_psv(const struct dmi_system_id *d) { |
0b5bfa1c LB |
1484 | |
1485 | if (psv == 0) { | |
1486 | printk(KERN_NOTICE "ACPI: %s detected: " | |
1487 | "disabling all passive thermal trip points\n", d->ident); | |
1488 | psv = -1; | |
1489 | } | |
1490 | return 0; | |
1491 | } | |
1492 | ||
1493 | static struct dmi_system_id thermal_dmi_table[] __initdata = { | |
1494 | /* | |
1495 | * Award BIOS on this AOpen makes thermal control almost worthless. | |
1496 | * http://bugzilla.kernel.org/show_bug.cgi?id=8842 | |
1497 | */ | |
1498 | { | |
1499 | .callback = thermal_act, | |
1500 | .ident = "AOpen i915GMm-HFS", | |
1501 | .matches = { | |
1502 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), | |
1503 | DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), | |
1504 | }, | |
1505 | }, | |
1506 | { | |
1507 | .callback = thermal_psv, | |
1508 | .ident = "AOpen i915GMm-HFS", | |
1509 | .matches = { | |
1510 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), | |
1511 | DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), | |
1512 | }, | |
1513 | }, | |
1514 | { | |
1515 | .callback = thermal_tzp, | |
1516 | .ident = "AOpen i915GMm-HFS", | |
1517 | .matches = { | |
1518 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), | |
1519 | DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), | |
1520 | }, | |
1521 | }, | |
8c99fdce LB |
1522 | { |
1523 | .callback = thermal_nocrt, | |
1524 | .ident = "Gigabyte GA-7ZX", | |
1525 | .matches = { | |
1526 | DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."), | |
1527 | DMI_MATCH(DMI_BOARD_NAME, "7ZX"), | |
1528 | }, | |
1529 | }, | |
0b5bfa1c LB |
1530 | {} |
1531 | }; | |
0b5bfa1c | 1532 | |
4be44fcd | 1533 | static int __init acpi_thermal_init(void) |
1da177e4 | 1534 | { |
4be44fcd | 1535 | int result = 0; |
1da177e4 | 1536 | |
0b5bfa1c LB |
1537 | dmi_check_system(thermal_dmi_table); |
1538 | ||
72b33ef8 LB |
1539 | if (off) { |
1540 | printk(KERN_NOTICE "ACPI: thermal control disabled\n"); | |
1541 | return -ENODEV; | |
1542 | } | |
1da177e4 LT |
1543 | acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir); |
1544 | if (!acpi_thermal_dir) | |
d550d98d | 1545 | return -ENODEV; |
1da177e4 LT |
1546 | |
1547 | result = acpi_bus_register_driver(&acpi_thermal_driver); | |
1548 | if (result < 0) { | |
1549 | remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir); | |
d550d98d | 1550 | return -ENODEV; |
1da177e4 LT |
1551 | } |
1552 | ||
d550d98d | 1553 | return 0; |
1da177e4 LT |
1554 | } |
1555 | ||
4be44fcd | 1556 | static void __exit acpi_thermal_exit(void) |
1da177e4 | 1557 | { |
1da177e4 LT |
1558 | |
1559 | acpi_bus_unregister_driver(&acpi_thermal_driver); | |
1560 | ||
1561 | remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir); | |
1562 | ||
d550d98d | 1563 | return; |
1da177e4 LT |
1564 | } |
1565 | ||
1da177e4 LT |
1566 | module_init(acpi_thermal_init); |
1567 | module_exit(acpi_thermal_exit); |