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