ACPI / osl: Kill macro INVALID_TABLE().
[deliverable/linux.git] / drivers / acpi / thermal.c
CommitLineData
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 37#include <linux/init.h>
5a0e3ad6 38#include <linux/slab.h>
1da177e4 39#include <linux/types.h>
cd354f1a 40#include <linux/jiffies.h>
1da177e4 41#include <linux/kmod.h>
10a0a8d4 42#include <linux/reboot.h>
f6f5c45e 43#include <linux/device.h>
1da177e4 44#include <asm/uaccess.h>
3f655ef8 45#include <linux/thermal.h>
1da177e4
LT
46#include <acpi/acpi_bus.h>
47#include <acpi/acpi_drivers.h>
48
a192a958
LB
49#define PREFIX "ACPI: "
50
1da177e4 51#define ACPI_THERMAL_CLASS "thermal_zone"
1da177e4 52#define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
1da177e4
LT
53#define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80
54#define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81
55#define ACPI_THERMAL_NOTIFY_DEVICES 0x82
56#define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0
57#define ACPI_THERMAL_NOTIFY_HOT 0xF1
58#define ACPI_THERMAL_MODE_ACTIVE 0x00
1da177e4
LT
59
60#define ACPI_THERMAL_MAX_ACTIVE 10
61#define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
62
1da177e4 63#define _COMPONENT ACPI_THERMAL_COMPONENT
f52fd66d 64ACPI_MODULE_NAME("thermal");
1da177e4 65
1cbf4c56 66MODULE_AUTHOR("Paul Diefenbaugh");
7cda93e0 67MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
1da177e4
LT
68MODULE_LICENSE("GPL");
69
f8707ec9
LB
70static int act;
71module_param(act, int, 0644);
3c1d36da 72MODULE_PARM_DESC(act, "Disable or override all lowest active trip points.");
f8707ec9 73
c52a7419
LB
74static int crt;
75module_param(crt, int, 0644);
76MODULE_PARM_DESC(crt, "Disable or lower all critical trip points.");
77
1da177e4 78static int tzp;
730ff34d 79module_param(tzp, int, 0444);
3c1d36da 80MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.");
1da177e4 81
f5487145
LB
82static int nocrt;
83module_param(nocrt, int, 0);
8c99fdce 84MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points.");
f5487145 85
72b33ef8
LB
86static int off;
87module_param(off, int, 0);
3c1d36da 88MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.");
72b33ef8 89
a70cdc52
LB
90static int psv;
91module_param(psv, int, 0644);
3c1d36da 92MODULE_PARM_DESC(psv, "Disable or override all passive trip points.");
a70cdc52 93
4be44fcd 94static int acpi_thermal_add(struct acpi_device *device);
51fac838 95static int acpi_thermal_remove(struct acpi_device *device);
342d550d 96static void acpi_thermal_notify(struct acpi_device *device, u32 event);
1da177e4 97
1ba90e3a
TR
98static const struct acpi_device_id thermal_device_ids[] = {
99 {ACPI_THERMAL_HID, 0},
100 {"", 0},
101};
102MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
103
90692404 104#ifdef CONFIG_PM_SLEEP
167cffb6 105static int acpi_thermal_resume(struct device *dev);
90692404 106#endif
167cffb6
RW
107static SIMPLE_DEV_PM_OPS(acpi_thermal_pm, NULL, acpi_thermal_resume);
108
1da177e4 109static struct acpi_driver acpi_thermal_driver = {
c2b6705b 110 .name = "thermal",
4be44fcd 111 .class = ACPI_THERMAL_CLASS,
1ba90e3a 112 .ids = thermal_device_ids,
4be44fcd
LB
113 .ops = {
114 .add = acpi_thermal_add,
115 .remove = acpi_thermal_remove,
342d550d 116 .notify = acpi_thermal_notify,
4be44fcd 117 },
167cffb6 118 .drv.pm = &acpi_thermal_pm,
1da177e4
LT
119};
120
121struct acpi_thermal_state {
4be44fcd
LB
122 u8 critical:1;
123 u8 hot:1;
124 u8 passive:1;
125 u8 active:1;
126 u8 reserved:4;
127 int active_index;
1da177e4
LT
128};
129
130struct acpi_thermal_state_flags {
4be44fcd
LB
131 u8 valid:1;
132 u8 enabled:1;
133 u8 reserved:6;
1da177e4
LT
134};
135
136struct acpi_thermal_critical {
137 struct acpi_thermal_state_flags flags;
4be44fcd 138 unsigned long temperature;
1da177e4
LT
139};
140
141struct acpi_thermal_hot {
142 struct acpi_thermal_state_flags flags;
4be44fcd 143 unsigned long temperature;
1da177e4
LT
144};
145
146struct acpi_thermal_passive {
147 struct acpi_thermal_state_flags flags;
4be44fcd
LB
148 unsigned long temperature;
149 unsigned long tc1;
150 unsigned long tc2;
151 unsigned long tsp;
152 struct acpi_handle_list devices;
1da177e4
LT
153};
154
155struct acpi_thermal_active {
156 struct acpi_thermal_state_flags flags;
4be44fcd
LB
157 unsigned long temperature;
158 struct acpi_handle_list devices;
1da177e4
LT
159};
160
161struct acpi_thermal_trips {
162 struct acpi_thermal_critical critical;
4be44fcd 163 struct acpi_thermal_hot hot;
1da177e4
LT
164 struct acpi_thermal_passive passive;
165 struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
166};
167
168struct acpi_thermal_flags {
4be44fcd
LB
169 u8 cooling_mode:1; /* _SCP */
170 u8 devices:1; /* _TZD */
171 u8 reserved:6;
1da177e4
LT
172};
173
174struct acpi_thermal {
8348e1b1 175 struct acpi_device * device;
4be44fcd
LB
176 acpi_bus_id name;
177 unsigned long temperature;
178 unsigned long last_temperature;
179 unsigned long polling_frequency;
4be44fcd 180 volatile u8 zombie;
1da177e4
LT
181 struct acpi_thermal_flags flags;
182 struct acpi_thermal_state state;
183 struct acpi_thermal_trips trips;
4be44fcd 184 struct acpi_handle_list devices;
3f655ef8
ZR
185 struct thermal_zone_device *thermal_zone;
186 int tz_enabled;
13614e37 187 int kelvin_offset;
1da177e4
LT
188};
189
1da177e4
LT
190/* --------------------------------------------------------------------------
191 Thermal Zone Management
192 -------------------------------------------------------------------------- */
193
4be44fcd 194static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
1da177e4 195{
4be44fcd 196 acpi_status status = AE_OK;
27663c58 197 unsigned long long tmp;
1da177e4
LT
198
199 if (!tz)
d550d98d 200 return -EINVAL;
1da177e4
LT
201
202 tz->last_temperature = tz->temperature;
203
27663c58 204 status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp);
1da177e4 205 if (ACPI_FAILURE(status))
d550d98d 206 return -ENODEV;
1da177e4 207
27663c58 208 tz->temperature = tmp;
4be44fcd
LB
209 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
210 tz->temperature));
1da177e4 211
d550d98d 212 return 0;
1da177e4
LT
213}
214
4be44fcd 215static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
1da177e4 216{
4be44fcd 217 acpi_status status = AE_OK;
27663c58 218 unsigned long long tmp;
1da177e4
LT
219
220 if (!tz)
d550d98d 221 return -EINVAL;
1da177e4 222
27663c58 223 status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp);
1da177e4 224 if (ACPI_FAILURE(status))
d550d98d 225 return -ENODEV;
1da177e4 226
27663c58 227 tz->polling_frequency = tmp;
4be44fcd
LB
228 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
229 tz->polling_frequency));
1da177e4 230
d550d98d 231 return 0;
1da177e4
LT
232}
233
4be44fcd 234static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
1da177e4 235{
4be44fcd
LB
236 acpi_status status = AE_OK;
237 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
238 struct acpi_object_list arg_list = { 1, &arg0 };
239 acpi_handle handle = NULL;
1da177e4 240
1da177e4
LT
241
242 if (!tz)
d550d98d 243 return -EINVAL;
1da177e4 244
38ba7c9e 245 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
1da177e4
LT
246 if (ACPI_FAILURE(status)) {
247 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
d550d98d 248 return -ENODEV;
1da177e4
LT
249 }
250
251 arg0.integer.value = mode;
252
253 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
254 if (ACPI_FAILURE(status))
d550d98d 255 return -ENODEV;
1da177e4 256
d550d98d 257 return 0;
1da177e4
LT
258}
259
ce44e197
ZR
260#define ACPI_TRIPS_CRITICAL 0x01
261#define ACPI_TRIPS_HOT 0x02
262#define ACPI_TRIPS_PASSIVE 0x04
263#define ACPI_TRIPS_ACTIVE 0x08
264#define ACPI_TRIPS_DEVICES 0x10
1da177e4 265
ce44e197
ZR
266#define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE)
267#define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES
1da177e4 268
ce44e197
ZR
269#define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \
270 ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \
271 ACPI_TRIPS_DEVICES)
1da177e4 272
ce44e197
ZR
273/*
274 * This exception is thrown out in two cases:
275 * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
276 * when re-evaluating the AML code.
277 * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change.
278 * We need to re-bind the cooling devices of a thermal zone when this occurs.
279 */
280#define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \
281do { \
282 if (flags != ACPI_TRIPS_INIT) \
283 ACPI_EXCEPTION((AE_INFO, AE_ERROR, \
284 "ACPI thermal trip point %s changed\n" \
7e3cf246 285 "Please send acpidump to linux-acpi@vger.kernel.org", str)); \
ce44e197
ZR
286} while (0)
287
288static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
289{
290 acpi_status status = AE_OK;
27663c58 291 unsigned long long tmp;
ce44e197
ZR
292 struct acpi_handle_list devices;
293 int valid = 0;
294 int i;
1da177e4 295
fa809452 296 /* Critical Shutdown */
ce44e197
ZR
297 if (flag & ACPI_TRIPS_CRITICAL) {
298 status = acpi_evaluate_integer(tz->device->handle,
27663c58
MW
299 "_CRT", NULL, &tmp);
300 tz->trips.critical.temperature = tmp;
a39a2d7c
AV
301 /*
302 * Treat freezing temperatures as invalid as well; some
303 * BIOSes return really low values and cause reboots at startup.
b731d7b6 304 * Below zero (Celsius) values clearly aren't right for sure..
a39a2d7c
AV
305 * ... so lets discard those as invalid.
306 */
fa809452
TR
307 if (ACPI_FAILURE(status)) {
308 tz->trips.critical.flags.valid = 0;
309 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
310 "No critical threshold\n"));
311 } else if (tmp <= 2732) {
312 printk(KERN_WARNING FW_BUG "Invalid critical threshold "
313 "(%llu)\n", tmp);
c52a7419 314 tz->trips.critical.flags.valid = 0;
ce44e197
ZR
315 } else {
316 tz->trips.critical.flags.valid = 1;
317 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
fa809452
TR
318 "Found critical threshold [%lu]\n",
319 tz->trips.critical.temperature));
ce44e197
ZR
320 }
321 if (tz->trips.critical.flags.valid == 1) {
322 if (crt == -1) {
323 tz->trips.critical.flags.valid = 0;
324 } else if (crt > 0) {
325 unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
326 /*
22a94d79 327 * Allow override critical threshold
ce44e197 328 */
22a94d79
ZR
329 if (crt_k > tz->trips.critical.temperature)
330 printk(KERN_WARNING PREFIX
331 "Critical threshold %d C\n", crt);
332 tz->trips.critical.temperature = crt_k;
ce44e197 333 }
c52a7419
LB
334 }
335 }
336
1da177e4 337 /* Critical Sleep (optional) */
ce44e197 338 if (flag & ACPI_TRIPS_HOT) {
a70cdc52 339 status = acpi_evaluate_integer(tz->device->handle,
27663c58 340 "_HOT", NULL, &tmp);
ce44e197
ZR
341 if (ACPI_FAILURE(status)) {
342 tz->trips.hot.flags.valid = 0;
343 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
344 "No hot threshold\n"));
345 } else {
27663c58 346 tz->trips.hot.temperature = tmp;
ce44e197
ZR
347 tz->trips.hot.flags.valid = 1;
348 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
349 "Found hot threshold [%lu]\n",
350 tz->trips.critical.temperature));
351 }
a70cdc52
LB
352 }
353
ce44e197 354 /* Passive (optional) */
0e4240d9
ZR
355 if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) ||
356 (flag == ACPI_TRIPS_INIT)) {
ce44e197
ZR
357 valid = tz->trips.passive.flags.valid;
358 if (psv == -1) {
359 status = AE_SUPPORT;
360 } else if (psv > 0) {
27663c58 361 tmp = CELSIUS_TO_KELVIN(psv);
ce44e197
ZR
362 status = AE_OK;
363 } else {
364 status = acpi_evaluate_integer(tz->device->handle,
27663c58 365 "_PSV", NULL, &tmp);
ce44e197 366 }
1da177e4 367
1da177e4
LT
368 if (ACPI_FAILURE(status))
369 tz->trips.passive.flags.valid = 0;
ce44e197 370 else {
27663c58 371 tz->trips.passive.temperature = tmp;
ce44e197
ZR
372 tz->trips.passive.flags.valid = 1;
373 if (flag == ACPI_TRIPS_INIT) {
374 status = acpi_evaluate_integer(
375 tz->device->handle, "_TC1",
27663c58 376 NULL, &tmp);
ce44e197
ZR
377 if (ACPI_FAILURE(status))
378 tz->trips.passive.flags.valid = 0;
27663c58
MW
379 else
380 tz->trips.passive.tc1 = tmp;
ce44e197
ZR
381 status = acpi_evaluate_integer(
382 tz->device->handle, "_TC2",
27663c58 383 NULL, &tmp);
ce44e197
ZR
384 if (ACPI_FAILURE(status))
385 tz->trips.passive.flags.valid = 0;
27663c58
MW
386 else
387 tz->trips.passive.tc2 = tmp;
ce44e197
ZR
388 status = acpi_evaluate_integer(
389 tz->device->handle, "_TSP",
27663c58 390 NULL, &tmp);
ce44e197
ZR
391 if (ACPI_FAILURE(status))
392 tz->trips.passive.flags.valid = 0;
27663c58
MW
393 else
394 tz->trips.passive.tsp = tmp;
ce44e197
ZR
395 }
396 }
397 }
398 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) {
399 memset(&devices, 0, sizeof(struct acpi_handle_list));
400 status = acpi_evaluate_reference(tz->device->handle, "_PSL",
401 NULL, &devices);
0e4240d9
ZR
402 if (ACPI_FAILURE(status)) {
403 printk(KERN_WARNING PREFIX
404 "Invalid passive threshold\n");
1da177e4 405 tz->trips.passive.flags.valid = 0;
0e4240d9 406 }
1da177e4 407 else
ce44e197 408 tz->trips.passive.flags.valid = 1;
1da177e4 409
ce44e197
ZR
410 if (memcmp(&tz->trips.passive.devices, &devices,
411 sizeof(struct acpi_handle_list))) {
412 memcpy(&tz->trips.passive.devices, &devices,
413 sizeof(struct acpi_handle_list));
414 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
415 }
416 }
417 if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) {
418 if (valid != tz->trips.passive.flags.valid)
419 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
420 }
1da177e4 421
ce44e197 422 /* Active (optional) */
4be44fcd 423 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
4be44fcd 424 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
ce44e197 425 valid = tz->trips.active[i].flags.valid;
1da177e4 426
f8707ec9 427 if (act == -1)
ce44e197
ZR
428 break; /* disable all active trip points */
429
0e4240d9
ZR
430 if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) &&
431 tz->trips.active[i].flags.valid)) {
ce44e197 432 status = acpi_evaluate_integer(tz->device->handle,
27663c58 433 name, NULL, &tmp);
ce44e197
ZR
434 if (ACPI_FAILURE(status)) {
435 tz->trips.active[i].flags.valid = 0;
436 if (i == 0)
437 break;
438 if (act <= 0)
439 break;
440 if (i == 1)
441 tz->trips.active[0].temperature =
442 CELSIUS_TO_KELVIN(act);
443 else
444 /*
445 * Don't allow override higher than
446 * the next higher trip point
447 */
448 tz->trips.active[i - 1].temperature =
449 (tz->trips.active[i - 2].temperature <
450 CELSIUS_TO_KELVIN(act) ?
451 tz->trips.active[i - 2].temperature :
452 CELSIUS_TO_KELVIN(act));
f8707ec9 453 break;
27663c58
MW
454 } else {
455 tz->trips.active[i].temperature = tmp;
ce44e197 456 tz->trips.active[i].flags.valid = 1;
27663c58 457 }
f8707ec9 458 }
1da177e4
LT
459
460 name[2] = 'L';
ce44e197
ZR
461 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) {
462 memset(&devices, 0, sizeof(struct acpi_handle_list));
463 status = acpi_evaluate_reference(tz->device->handle,
464 name, NULL, &devices);
0e4240d9
ZR
465 if (ACPI_FAILURE(status)) {
466 printk(KERN_WARNING PREFIX
467 "Invalid active%d threshold\n", i);
ce44e197 468 tz->trips.active[i].flags.valid = 0;
0e4240d9 469 }
ce44e197
ZR
470 else
471 tz->trips.active[i].flags.valid = 1;
472
473 if (memcmp(&tz->trips.active[i].devices, &devices,
474 sizeof(struct acpi_handle_list))) {
475 memcpy(&tz->trips.active[i].devices, &devices,
476 sizeof(struct acpi_handle_list));
477 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
478 }
479 }
480 if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES))
481 if (valid != tz->trips.active[i].flags.valid)
482 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
483
484 if (!tz->trips.active[i].flags.valid)
485 break;
486 }
487
488 if (flag & ACPI_TRIPS_DEVICES) {
489 memset(&devices, 0, sizeof(struct acpi_handle_list));
490 status = acpi_evaluate_reference(tz->device->handle, "_TZD",
491 NULL, &devices);
492 if (memcmp(&tz->devices, &devices,
493 sizeof(struct acpi_handle_list))) {
494 memcpy(&tz->devices, &devices,
495 sizeof(struct acpi_handle_list));
496 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
497 }
1da177e4
LT
498 }
499
d550d98d 500 return 0;
1da177e4
LT
501}
502
ce44e197 503static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
1da177e4 504{
8b7ef6d8
TR
505 int i, valid, ret = acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
506
507 if (ret)
508 return ret;
509
510 valid = tz->trips.critical.flags.valid |
511 tz->trips.hot.flags.valid |
512 tz->trips.passive.flags.valid;
513
514 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
515 valid |= tz->trips.active[i].flags.valid;
516
517 if (!valid) {
518 printk(KERN_WARNING FW_BUG "No valid trip found\n");
519 return -ENODEV;
520 }
521 return 0;
1da177e4
LT
522}
523
4be44fcd 524static void acpi_thermal_check(void *data)
1da177e4 525{
50dd0969 526 struct acpi_thermal *tz = data;
1da177e4 527
ca4e7130
SP
528 if (!tz->tz_enabled) {
529 pr_warn("thermal zone is disabled \n");
530 return;
531 }
b1569e99 532 thermal_zone_device_update(tz->thermal_zone);
1da177e4
LT
533}
534
3f655ef8 535/* sys I/F for generic thermal sysfs support */
13614e37 536#define KELVIN_TO_MILLICELSIUS(t, off) (((t) - (off)) * 100)
5e012760 537
6503e5df
MG
538static int thermal_get_temp(struct thermal_zone_device *thermal,
539 unsigned long *temp)
3f655ef8
ZR
540{
541 struct acpi_thermal *tz = thermal->devdata;
76ecb4f2 542 int result;
3f655ef8
ZR
543
544 if (!tz)
545 return -EINVAL;
546
76ecb4f2
ZR
547 result = acpi_thermal_get_temperature(tz);
548 if (result)
549 return result;
550
13614e37 551 *temp = KELVIN_TO_MILLICELSIUS(tz->temperature, tz->kelvin_offset);
6503e5df 552 return 0;
3f655ef8
ZR
553}
554
3f655ef8 555static int thermal_get_mode(struct thermal_zone_device *thermal,
6503e5df 556 enum thermal_device_mode *mode)
3f655ef8
ZR
557{
558 struct acpi_thermal *tz = thermal->devdata;
559
560 if (!tz)
561 return -EINVAL;
562
6503e5df
MG
563 *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
564 THERMAL_DEVICE_DISABLED;
565
566 return 0;
3f655ef8
ZR
567}
568
569static int thermal_set_mode(struct thermal_zone_device *thermal,
6503e5df 570 enum thermal_device_mode mode)
3f655ef8
ZR
571{
572 struct acpi_thermal *tz = thermal->devdata;
573 int enable;
574
575 if (!tz)
576 return -EINVAL;
577
578 /*
579 * enable/disable thermal management from ACPI thermal driver
580 */
6503e5df 581 if (mode == THERMAL_DEVICE_ENABLED)
3f655ef8 582 enable = 1;
6503e5df 583 else if (mode == THERMAL_DEVICE_DISABLED)
3f655ef8
ZR
584 enable = 0;
585 else
586 return -EINVAL;
587
588 if (enable != tz->tz_enabled) {
589 tz->tz_enabled = enable;
590 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
8eaa8d6c
ZR
591 "%s kernel ACPI thermal control\n",
592 tz->tz_enabled ? "Enable" : "Disable"));
3f655ef8
ZR
593 acpi_thermal_check(tz);
594 }
595 return 0;
596}
597
598static int thermal_get_trip_type(struct thermal_zone_device *thermal,
6503e5df 599 int trip, enum thermal_trip_type *type)
3f655ef8
ZR
600{
601 struct acpi_thermal *tz = thermal->devdata;
602 int i;
603
604 if (!tz || trip < 0)
605 return -EINVAL;
606
607 if (tz->trips.critical.flags.valid) {
6503e5df
MG
608 if (!trip) {
609 *type = THERMAL_TRIP_CRITICAL;
610 return 0;
611 }
3f655ef8
ZR
612 trip--;
613 }
614
615 if (tz->trips.hot.flags.valid) {
6503e5df
MG
616 if (!trip) {
617 *type = THERMAL_TRIP_HOT;
618 return 0;
619 }
3f655ef8
ZR
620 trip--;
621 }
622
623 if (tz->trips.passive.flags.valid) {
6503e5df
MG
624 if (!trip) {
625 *type = THERMAL_TRIP_PASSIVE;
626 return 0;
627 }
3f655ef8
ZR
628 trip--;
629 }
630
631 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
632 tz->trips.active[i].flags.valid; i++) {
6503e5df
MG
633 if (!trip) {
634 *type = THERMAL_TRIP_ACTIVE;
635 return 0;
636 }
3f655ef8
ZR
637 trip--;
638 }
639
640 return -EINVAL;
641}
642
643static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
6503e5df 644 int trip, unsigned long *temp)
3f655ef8
ZR
645{
646 struct acpi_thermal *tz = thermal->devdata;
647 int i;
648
649 if (!tz || trip < 0)
650 return -EINVAL;
651
652 if (tz->trips.critical.flags.valid) {
6503e5df
MG
653 if (!trip) {
654 *temp = KELVIN_TO_MILLICELSIUS(
13614e37
JD
655 tz->trips.critical.temperature,
656 tz->kelvin_offset);
6503e5df
MG
657 return 0;
658 }
3f655ef8
ZR
659 trip--;
660 }
661
662 if (tz->trips.hot.flags.valid) {
6503e5df
MG
663 if (!trip) {
664 *temp = KELVIN_TO_MILLICELSIUS(
13614e37
JD
665 tz->trips.hot.temperature,
666 tz->kelvin_offset);
6503e5df
MG
667 return 0;
668 }
3f655ef8
ZR
669 trip--;
670 }
671
672 if (tz->trips.passive.flags.valid) {
6503e5df
MG
673 if (!trip) {
674 *temp = KELVIN_TO_MILLICELSIUS(
13614e37
JD
675 tz->trips.passive.temperature,
676 tz->kelvin_offset);
6503e5df
MG
677 return 0;
678 }
3f655ef8
ZR
679 trip--;
680 }
681
682 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
683 tz->trips.active[i].flags.valid; i++) {
6503e5df
MG
684 if (!trip) {
685 *temp = KELVIN_TO_MILLICELSIUS(
13614e37
JD
686 tz->trips.active[i].temperature,
687 tz->kelvin_offset);
6503e5df
MG
688 return 0;
689 }
3f655ef8
ZR
690 trip--;
691 }
692
693 return -EINVAL;
694}
695
9ec732ff
ZR
696static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
697 unsigned long *temperature) {
698 struct acpi_thermal *tz = thermal->devdata;
699
700 if (tz->trips.critical.flags.valid) {
701 *temperature = KELVIN_TO_MILLICELSIUS(
13614e37
JD
702 tz->trips.critical.temperature,
703 tz->kelvin_offset);
9ec732ff
ZR
704 return 0;
705 } else
706 return -EINVAL;
707}
708
601f3d42
ZR
709static int thermal_get_trend(struct thermal_zone_device *thermal,
710 int trip, enum thermal_trend *trend)
711{
712 struct acpi_thermal *tz = thermal->devdata;
713 enum thermal_trip_type type;
714 int i;
715
716 if (thermal_get_trip_type(thermal, trip, &type))
717 return -EINVAL;
718
4ae46bef 719 if (type == THERMAL_TRIP_ACTIVE) {
94a40931
ZR
720 unsigned long trip_temp;
721 unsigned long temp = KELVIN_TO_MILLICELSIUS(tz->temperature,
722 tz->kelvin_offset);
723 if (thermal_get_trip_temp(thermal, trip, &trip_temp))
724 return -EINVAL;
725
726 if (temp > trip_temp) {
727 *trend = THERMAL_TREND_RAISING;
728 return 0;
729 } else {
730 /* Fall back on default trend */
731 return -EINVAL;
732 }
4ae46bef 733 }
601f3d42
ZR
734
735 /*
736 * tz->temperature has already been updated by generic thermal layer,
737 * before this callback being invoked
738 */
739 i = (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature))
740 + (tz->trips.passive.tc2
741 * (tz->temperature - tz->trips.passive.temperature));
742
743 if (i > 0)
744 *trend = THERMAL_TREND_RAISING;
745 else if (i < 0)
746 *trend = THERMAL_TREND_DROPPING;
747 else
748 *trend = THERMAL_TREND_STABLE;
749 return 0;
750}
751
752
b1569e99
MG
753static int thermal_notify(struct thermal_zone_device *thermal, int trip,
754 enum thermal_trip_type trip_type)
755{
756 u8 type = 0;
757 struct acpi_thermal *tz = thermal->devdata;
758
759 if (trip_type == THERMAL_TRIP_CRITICAL)
760 type = ACPI_THERMAL_NOTIFY_CRITICAL;
761 else if (trip_type == THERMAL_TRIP_HOT)
762 type = ACPI_THERMAL_NOTIFY_HOT;
763 else
764 return 0;
765
b1569e99 766 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
f6f5c45e 767 dev_name(&tz->device->dev), type, 1);
b1569e99
MG
768
769 if (trip_type == THERMAL_TRIP_CRITICAL && nocrt)
770 return 1;
771
772 return 0;
773}
774
3f655ef8
ZR
775static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
776 struct thermal_cooling_device *cdev,
9d99842f 777 bool bind)
3f655ef8
ZR
778{
779 struct acpi_device *device = cdev->devdata;
780 struct acpi_thermal *tz = thermal->devdata;
653a00c9
ZR
781 struct acpi_device *dev;
782 acpi_status status;
783 acpi_handle handle;
3f655ef8
ZR
784 int i;
785 int j;
786 int trip = -1;
787 int result = 0;
788
789 if (tz->trips.critical.flags.valid)
790 trip++;
791
792 if (tz->trips.hot.flags.valid)
793 trip++;
794
795 if (tz->trips.passive.flags.valid) {
796 trip++;
797 for (i = 0; i < tz->trips.passive.devices.count;
798 i++) {
653a00c9
ZR
799 handle = tz->trips.passive.devices.handles[i];
800 status = acpi_bus_get_device(handle, &dev);
9d99842f
ZR
801 if (ACPI_FAILURE(status) || dev != device)
802 continue;
803 if (bind)
804 result =
805 thermal_zone_bind_cooling_device
806 (thermal, trip, cdev,
807 THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
808 else
809 result =
810 thermal_zone_unbind_cooling_device
811 (thermal, trip, cdev);
812 if (result)
813 goto failed;
3f655ef8
ZR
814 }
815 }
816
817 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
818 if (!tz->trips.active[i].flags.valid)
819 break;
820 trip++;
821 for (j = 0;
822 j < tz->trips.active[i].devices.count;
823 j++) {
653a00c9
ZR
824 handle = tz->trips.active[i].devices.handles[j];
825 status = acpi_bus_get_device(handle, &dev);
9d99842f
ZR
826 if (ACPI_FAILURE(status) || dev != device)
827 continue;
828 if (bind)
829 result = thermal_zone_bind_cooling_device
830 (thermal, trip, cdev,
831 THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
832 else
833 result = thermal_zone_unbind_cooling_device
834 (thermal, trip, cdev);
835 if (result)
836 goto failed;
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)) {
9d99842f
ZR
844 if (bind)
845 result = thermal_zone_bind_cooling_device
70f2903b
LT
846 (thermal, THERMAL_TRIPS_NONE,
847 cdev, THERMAL_NO_LIMIT,
9d99842f
ZR
848 THERMAL_NO_LIMIT);
849 else
850 result = thermal_zone_unbind_cooling_device
70f2903b
LT
851 (thermal, THERMAL_TRIPS_NONE,
852 cdev);
653a00c9
ZR
853 if (result)
854 goto failed;
855 }
3f655ef8
ZR
856 }
857
858failed:
859 return result;
860}
861
862static int
863acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
864 struct thermal_cooling_device *cdev)
865{
9d99842f 866 return acpi_thermal_cooling_device_cb(thermal, cdev, true);
3f655ef8
ZR
867}
868
869static int
870acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
871 struct thermal_cooling_device *cdev)
872{
9d99842f 873 return acpi_thermal_cooling_device_cb(thermal, cdev, false);
3f655ef8
ZR
874}
875
9c8b04be 876static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
3f655ef8
ZR
877 .bind = acpi_thermal_bind_cooling_device,
878 .unbind = acpi_thermal_unbind_cooling_device,
879 .get_temp = thermal_get_temp,
880 .get_mode = thermal_get_mode,
881 .set_mode = thermal_set_mode,
882 .get_trip_type = thermal_get_trip_type,
883 .get_trip_temp = thermal_get_trip_temp,
9ec732ff 884 .get_crit_temp = thermal_get_crit_temp,
601f3d42 885 .get_trend = thermal_get_trend,
b1569e99 886 .notify = thermal_notify,
3f655ef8
ZR
887};
888
889static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
890{
891 int trips = 0;
892 int result;
20733939 893 acpi_status status;
3f655ef8
ZR
894 int i;
895
896 if (tz->trips.critical.flags.valid)
897 trips++;
898
899 if (tz->trips.hot.flags.valid)
900 trips++;
901
902 if (tz->trips.passive.flags.valid)
903 trips++;
904
905 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
906 tz->trips.active[i].flags.valid; i++, trips++);
b1569e99
MG
907
908 if (tz->trips.passive.flags.valid)
909 tz->thermal_zone =
c56f5c03 910 thermal_zone_device_register("acpitz", trips, 0, tz,
50125a9b 911 &acpi_thermal_zone_ops, NULL,
b1569e99
MG
912 tz->trips.passive.tsp*100,
913 tz->polling_frequency*100);
914 else
915 tz->thermal_zone =
c56f5c03 916 thermal_zone_device_register("acpitz", trips, 0, tz,
50125a9b
D
917 &acpi_thermal_zone_ops, NULL,
918 0, tz->polling_frequency*100);
bb070e43 919 if (IS_ERR(tz->thermal_zone))
3f655ef8
ZR
920 return -ENODEV;
921
922 result = sysfs_create_link(&tz->device->dev.kobj,
923 &tz->thermal_zone->device.kobj, "thermal_zone");
924 if (result)
925 return result;
926
927 result = sysfs_create_link(&tz->thermal_zone->device.kobj,
928 &tz->device->dev.kobj, "device");
929 if (result)
930 return result;
931
20733939
ZR
932 status = acpi_attach_data(tz->device->handle,
933 acpi_bus_private_data_handler,
934 tz->thermal_zone);
935 if (ACPI_FAILURE(status)) {
55ac9a01
LM
936 printk(KERN_ERR PREFIX
937 "Error attaching device data\n");
20733939
ZR
938 return -ENODEV;
939 }
940
3f655ef8
ZR
941 tz->tz_enabled = 1;
942
fc3a8828
GKH
943 dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
944 tz->thermal_zone->id);
3f655ef8
ZR
945 return 0;
946}
947
948static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
949{
950 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
951 sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
952 thermal_zone_device_unregister(tz->thermal_zone);
953 tz->thermal_zone = NULL;
20733939 954 acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler);
3f655ef8
ZR
955}
956
957
1da177e4
LT
958/* --------------------------------------------------------------------------
959 Driver Interface
960 -------------------------------------------------------------------------- */
961
342d550d 962static void acpi_thermal_notify(struct acpi_device *device, u32 event)
1da177e4 963{
342d550d 964 struct acpi_thermal *tz = acpi_driver_data(device);
1da177e4 965
1da177e4
LT
966
967 if (!tz)
d550d98d 968 return;
1da177e4 969
1da177e4
LT
970 switch (event) {
971 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
972 acpi_thermal_check(tz);
973 break;
974 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
ce44e197 975 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS);
1da177e4 976 acpi_thermal_check(tz);
962ce8ca 977 acpi_bus_generate_netlink_event(device->pnp.device_class,
0794469d 978 dev_name(&device->dev), event, 0);
1da177e4
LT
979 break;
980 case ACPI_THERMAL_NOTIFY_DEVICES:
ce44e197
ZR
981 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES);
982 acpi_thermal_check(tz);
962ce8ca 983 acpi_bus_generate_netlink_event(device->pnp.device_class,
0794469d 984 dev_name(&device->dev), event, 0);
1da177e4
LT
985 break;
986 default:
987 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
4be44fcd 988 "Unsupported event [0x%x]\n", event));
1da177e4
LT
989 break;
990 }
1da177e4
LT
991}
992
261cba2d
ZR
993/*
994 * On some platforms, the AML code has dependency about
995 * the evaluating order of _TMP and _CRT/_HOT/_PSV/_ACx.
996 * 1. On HP Pavilion G4-1016tx, _TMP must be invoked after
997 * /_CRT/_HOT/_PSV/_ACx, or else system will be power off.
998 * 2. On HP Compaq 6715b/6715s, the return value of _PSV is 0
999 * if _TMP has never been evaluated.
1000 *
1001 * As this dependency is totally transparent to OS, evaluate
1002 * all of them once, in the order of _CRT/_HOT/_PSV/_ACx,
1003 * _TMP, before they are actually used.
1004 */
1005static void acpi_thermal_aml_dependency_fix(struct acpi_thermal *tz)
1006{
1007 acpi_handle handle = tz->device->handle;
1008 unsigned long long value;
1009 int i;
1010
1011 acpi_evaluate_integer(handle, "_CRT", NULL, &value);
1012 acpi_evaluate_integer(handle, "_HOT", NULL, &value);
1013 acpi_evaluate_integer(handle, "_PSV", NULL, &value);
1014 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1015 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
1016 acpi_status status;
1017
1018 status = acpi_evaluate_integer(handle, name, NULL, &value);
1019 if (status == AE_NOT_FOUND)
1020 break;
1021 }
1022 acpi_evaluate_integer(handle, "_TMP", NULL, &value);
1023}
1024
4be44fcd 1025static int acpi_thermal_get_info(struct acpi_thermal *tz)
1da177e4 1026{
4be44fcd 1027 int result = 0;
1da177e4 1028
1da177e4
LT
1029
1030 if (!tz)
d550d98d 1031 return -EINVAL;
1da177e4 1032
261cba2d
ZR
1033 acpi_thermal_aml_dependency_fix(tz);
1034
9bcb8118
MG
1035 /* Get trip points [_CRT, _PSV, etc.] (required) */
1036 result = acpi_thermal_get_trip_points(tz);
1da177e4 1037 if (result)
d550d98d 1038 return result;
1da177e4 1039
9bcb8118
MG
1040 /* Get temperature [_TMP] (required) */
1041 result = acpi_thermal_get_temperature(tz);
1da177e4 1042 if (result)
d550d98d 1043 return result;
1da177e4
LT
1044
1045 /* Set the cooling mode [_SCP] to active cooling (default) */
1046 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
4be44fcd 1047 if (!result)
1da177e4 1048 tz->flags.cooling_mode = 1;
1da177e4
LT
1049
1050 /* Get default polling frequency [_TZP] (optional) */
1051 if (tzp)
1052 tz->polling_frequency = tzp;
1053 else
1054 acpi_thermal_get_polling_frequency(tz);
1055
d550d98d 1056 return 0;
1da177e4
LT
1057}
1058
13614e37
JD
1059/*
1060 * The exact offset between Kelvin and degree Celsius is 273.15. However ACPI
1061 * handles temperature values with a single decimal place. As a consequence,
1062 * some implementations use an offset of 273.1 and others use an offset of
1063 * 273.2. Try to find out which one is being used, to present the most
1064 * accurate and visually appealing number.
1065 *
1066 * The heuristic below should work for all ACPI thermal zones which have a
1067 * critical trip point with a value being a multiple of 0.5 degree Celsius.
1068 */
1069static void acpi_thermal_guess_offset(struct acpi_thermal *tz)
1070{
1071 if (tz->trips.critical.flags.valid &&
1072 (tz->trips.critical.temperature % 5) == 1)
1073 tz->kelvin_offset = 2731;
1074 else
1075 tz->kelvin_offset = 2732;
1076}
1077
4be44fcd 1078static int acpi_thermal_add(struct acpi_device *device)
1da177e4 1079{
4be44fcd 1080 int result = 0;
4be44fcd 1081 struct acpi_thermal *tz = NULL;
1da177e4 1082
1da177e4
LT
1083
1084 if (!device)
d550d98d 1085 return -EINVAL;
1da177e4 1086
36bcbec7 1087 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1da177e4 1088 if (!tz)
d550d98d 1089 return -ENOMEM;
1da177e4 1090
8348e1b1 1091 tz->device = device;
1da177e4
LT
1092 strcpy(tz->name, device->pnp.bus_id);
1093 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1094 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
db89b4f0 1095 device->driver_data = tz;
3f655ef8 1096
1da177e4
LT
1097 result = acpi_thermal_get_info(tz);
1098 if (result)
3f655ef8
ZR
1099 goto free_memory;
1100
13614e37
JD
1101 acpi_thermal_guess_offset(tz);
1102
3f655ef8
ZR
1103 result = acpi_thermal_register_thermal_zone(tz);
1104 if (result)
1105 goto free_memory;
1da177e4 1106
1da177e4 1107 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
4be44fcd
LB
1108 acpi_device_name(device), acpi_device_bid(device),
1109 KELVIN_TO_CELSIUS(tz->temperature));
3f655ef8 1110 goto end;
1da177e4 1111
3f655ef8
ZR
1112free_memory:
1113 kfree(tz);
1114end:
d550d98d 1115 return result;
1da177e4
LT
1116}
1117
51fac838 1118static int acpi_thermal_remove(struct acpi_device *device)
1da177e4 1119{
4be44fcd 1120 struct acpi_thermal *tz = NULL;
1da177e4 1121
1da177e4 1122 if (!device || !acpi_driver_data(device))
d550d98d 1123 return -EINVAL;
1da177e4 1124
50dd0969 1125 tz = acpi_driver_data(device);
1da177e4 1126
3f655ef8 1127 acpi_thermal_unregister_thermal_zone(tz);
1da177e4 1128 kfree(tz);
d550d98d 1129 return 0;
1da177e4
LT
1130}
1131
90692404 1132#ifdef CONFIG_PM_SLEEP
167cffb6 1133static int acpi_thermal_resume(struct device *dev)
74ce1468 1134{
167cffb6 1135 struct acpi_thermal *tz;
b1028c54
KK
1136 int i, j, power_state, result;
1137
167cffb6 1138 if (!dev)
d550d98d 1139 return -EINVAL;
74ce1468 1140
167cffb6
RW
1141 tz = acpi_driver_data(to_acpi_device(dev));
1142 if (!tz)
1143 return -EINVAL;
74ce1468 1144
bed936f7 1145 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
b1028c54
KK
1146 if (!(&tz->trips.active[i]))
1147 break;
1148 if (!tz->trips.active[i].flags.valid)
1149 break;
1150 tz->trips.active[i].flags.enabled = 1;
1151 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
488a76c5
RW
1152 result = acpi_bus_update_power(
1153 tz->trips.active[i].devices.handles[j],
1154 &power_state);
b1028c54
KK
1155 if (result || (power_state != ACPI_STATE_D0)) {
1156 tz->trips.active[i].flags.enabled = 0;
1157 break;
1158 }
bed936f7 1159 }
b1028c54 1160 tz->state.active |= tz->trips.active[i].flags.enabled;
bed936f7
KK
1161 }
1162
b1028c54 1163 acpi_thermal_check(tz);
74ce1468
KK
1164
1165 return AE_OK;
1166}
90692404 1167#endif
74ce1468 1168
1855256c 1169static int thermal_act(const struct dmi_system_id *d) {
0b5bfa1c
LB
1170
1171 if (act == 0) {
1172 printk(KERN_NOTICE "ACPI: %s detected: "
1173 "disabling all active thermal trip points\n", d->ident);
1174 act = -1;
1175 }
1176 return 0;
1177}
1855256c 1178static int thermal_nocrt(const struct dmi_system_id *d) {
8c99fdce
LB
1179
1180 printk(KERN_NOTICE "ACPI: %s detected: "
1181 "disabling all critical thermal trip point actions.\n", d->ident);
1182 nocrt = 1;
1183 return 0;
1184}
1855256c 1185static int thermal_tzp(const struct dmi_system_id *d) {
0b5bfa1c
LB
1186
1187 if (tzp == 0) {
1188 printk(KERN_NOTICE "ACPI: %s detected: "
1189 "enabling thermal zone polling\n", d->ident);
1190 tzp = 300; /* 300 dS = 30 Seconds */
1191 }
1192 return 0;
1193}
1855256c 1194static int thermal_psv(const struct dmi_system_id *d) {
0b5bfa1c
LB
1195
1196 if (psv == 0) {
1197 printk(KERN_NOTICE "ACPI: %s detected: "
1198 "disabling all passive thermal trip points\n", d->ident);
1199 psv = -1;
1200 }
1201 return 0;
1202}
1203
1204static struct dmi_system_id thermal_dmi_table[] __initdata = {
1205 /*
1206 * Award BIOS on this AOpen makes thermal control almost worthless.
1207 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1208 */
1209 {
1210 .callback = thermal_act,
1211 .ident = "AOpen i915GMm-HFS",
1212 .matches = {
1213 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1214 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1215 },
1216 },
1217 {
1218 .callback = thermal_psv,
1219 .ident = "AOpen i915GMm-HFS",
1220 .matches = {
1221 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1222 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1223 },
1224 },
1225 {
1226 .callback = thermal_tzp,
1227 .ident = "AOpen i915GMm-HFS",
1228 .matches = {
1229 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1230 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1231 },
1232 },
8c99fdce
LB
1233 {
1234 .callback = thermal_nocrt,
1235 .ident = "Gigabyte GA-7ZX",
1236 .matches = {
1237 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
1238 DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
1239 },
1240 },
0b5bfa1c
LB
1241 {}
1242};
0b5bfa1c 1243
4be44fcd 1244static int __init acpi_thermal_init(void)
1da177e4 1245{
4be44fcd 1246 int result = 0;
1da177e4 1247
0b5bfa1c
LB
1248 dmi_check_system(thermal_dmi_table);
1249
72b33ef8
LB
1250 if (off) {
1251 printk(KERN_NOTICE "ACPI: thermal control disabled\n");
1252 return -ENODEV;
1253 }
43d9f87b 1254
1da177e4 1255 result = acpi_bus_register_driver(&acpi_thermal_driver);
c57b62f5 1256 if (result < 0)
d550d98d 1257 return -ENODEV;
1da177e4 1258
d550d98d 1259 return 0;
1da177e4
LT
1260}
1261
4be44fcd 1262static void __exit acpi_thermal_exit(void)
1da177e4 1263{
1da177e4
LT
1264
1265 acpi_bus_unregister_driver(&acpi_thermal_driver);
1266
d550d98d 1267 return;
1da177e4
LT
1268}
1269
1da177e4
LT
1270module_init(acpi_thermal_init);
1271module_exit(acpi_thermal_exit);
This page took 0.854344 seconds and 5 git commands to generate.