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