ACPI: Schedule /proc/acpi/event for removal
[safe/jmp/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_proc_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL,
489                                 tz->trips.critical.flags.enabled);
490         acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
491                                           tz->device->dev.bus_id,
492                                           ACPI_THERMAL_NOTIFY_CRITICAL,
493                                           tz->trips.critical.flags.enabled);
494
495         orderly_poweroff(true);
496
497         return 0;
498 }
499
500 static int acpi_thermal_hot(struct acpi_thermal *tz)
501 {
502         if (!tz || !tz->trips.hot.flags.valid || nocrt)
503                 return -EINVAL;
504
505         if (tz->temperature >= tz->trips.hot.temperature) {
506                 printk(KERN_WARNING PREFIX "Hot trip point\n");
507                 tz->trips.hot.flags.enabled = 1;
508         } else if (tz->trips.hot.flags.enabled)
509                 tz->trips.hot.flags.enabled = 0;
510
511         acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
512                                 tz->trips.hot.flags.enabled);
513         acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
514                                           tz->device->dev.bus_id,
515                                           ACPI_THERMAL_NOTIFY_HOT,
516                                           tz->trips.hot.flags.enabled);
517
518         /* TBD: Call user-mode "sleep(S4)" function */
519
520         return 0;
521 }
522
523 static void acpi_thermal_passive(struct acpi_thermal *tz)
524 {
525         int result = 1;
526         struct acpi_thermal_passive *passive = NULL;
527         int trend = 0;
528         int i = 0;
529
530
531         if (!tz || !tz->trips.passive.flags.valid)
532                 return;
533
534         passive = &(tz->trips.passive);
535
536         /*
537          * Above Trip?
538          * -----------
539          * Calculate the thermal trend (using the passive cooling equation)
540          * and modify the performance limit for all passive cooling devices
541          * accordingly.  Note that we assume symmetry.
542          */
543         if (tz->temperature >= passive->temperature) {
544                 trend =
545                     (passive->tc1 * (tz->temperature - tz->last_temperature)) +
546                     (passive->tc2 * (tz->temperature - passive->temperature));
547                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
548                                   "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
549                                   trend, passive->tc1, tz->temperature,
550                                   tz->last_temperature, passive->tc2,
551                                   tz->temperature, passive->temperature));
552                 passive->flags.enabled = 1;
553                 /* Heating up? */
554                 if (trend > 0)
555                         for (i = 0; i < passive->devices.count; i++)
556                                 acpi_processor_set_thermal_limit(passive->
557                                                                  devices.
558                                                                  handles[i],
559                                                                  ACPI_PROCESSOR_LIMIT_INCREMENT);
560                 /* Cooling off? */
561                 else if (trend < 0) {
562                         for (i = 0; i < passive->devices.count; i++)
563                                 /*
564                                  * assume that we are on highest
565                                  * freq/lowest thrott and can leave
566                                  * passive mode, even in error case
567                                  */
568                                 if (!acpi_processor_set_thermal_limit
569                                     (passive->devices.handles[i],
570                                      ACPI_PROCESSOR_LIMIT_DECREMENT))
571                                         result = 0;
572                         /*
573                          * Leave cooling mode, even if the temp might
574                          * higher than trip point This is because some
575                          * machines might have long thermal polling
576                          * frequencies (tsp) defined. We will fall back
577                          * into passive mode in next cycle (probably quicker)
578                          */
579                         if (result) {
580                                 passive->flags.enabled = 0;
581                                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
582                                                   "Disabling passive cooling, still above threshold,"
583                                                   " but we are cooling down\n"));
584                         }
585                 }
586                 return;
587         }
588
589         /*
590          * Below Trip?
591          * -----------
592          * Implement passive cooling hysteresis to slowly increase performance
593          * and avoid thrashing around the passive trip point.  Note that we
594          * assume symmetry.
595          */
596         if (!passive->flags.enabled)
597                 return;
598         for (i = 0; i < passive->devices.count; i++)
599                 if (!acpi_processor_set_thermal_limit
600                     (passive->devices.handles[i],
601                      ACPI_PROCESSOR_LIMIT_DECREMENT))
602                         result = 0;
603         if (result) {
604                 passive->flags.enabled = 0;
605                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
606                                   "Disabling passive cooling (zone is cool)\n"));
607         }
608 }
609
610 static void acpi_thermal_active(struct acpi_thermal *tz)
611 {
612         int result = 0;
613         struct acpi_thermal_active *active = NULL;
614         int i = 0;
615         int j = 0;
616         unsigned long maxtemp = 0;
617
618
619         if (!tz)
620                 return;
621
622         for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
623                 active = &(tz->trips.active[i]);
624                 if (!active || !active->flags.valid)
625                         break;
626                 if (tz->temperature >= active->temperature) {
627                         /*
628                          * Above Threshold?
629                          * ----------------
630                          * If not already enabled, turn ON all cooling devices
631                          * associated with this active threshold.
632                          */
633                         if (active->temperature > maxtemp)
634                                 tz->state.active_index = i;
635                         maxtemp = active->temperature;
636                         if (active->flags.enabled)
637                                 continue;
638                         for (j = 0; j < active->devices.count; j++) {
639                                 result =
640                                     acpi_bus_set_power(active->devices.
641                                                        handles[j],
642                                                        ACPI_STATE_D0);
643                                 if (result) {
644                                         printk(KERN_WARNING PREFIX
645                                                       "Unable to turn cooling device [%p] 'on'\n",
646                                                       active->devices.
647                                                       handles[j]);
648                                         continue;
649                                 }
650                                 active->flags.enabled = 1;
651                                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
652                                                   "Cooling device [%p] now 'on'\n",
653                                                   active->devices.handles[j]));
654                         }
655                         continue;
656                 }
657                 if (!active->flags.enabled)
658                         continue;
659                 /*
660                  * Below Threshold?
661                  * ----------------
662                  * Turn OFF all cooling devices associated with this
663                  * threshold.
664                  */
665                 for (j = 0; j < active->devices.count; j++) {
666                         result = acpi_bus_set_power(active->devices.handles[j],
667                                                     ACPI_STATE_D3);
668                         if (result) {
669                                 printk(KERN_WARNING PREFIX
670                                               "Unable to turn cooling device [%p] 'off'\n",
671                                               active->devices.handles[j]);
672                                 continue;
673                         }
674                         active->flags.enabled = 0;
675                         ACPI_DEBUG_PRINT((ACPI_DB_INFO,
676                                           "Cooling device [%p] now 'off'\n",
677                                           active->devices.handles[j]));
678                 }
679         }
680 }
681
682 static void acpi_thermal_check(void *context);
683
684 static void acpi_thermal_run(unsigned long data)
685 {
686         struct acpi_thermal *tz = (struct acpi_thermal *)data;
687         if (!tz->zombie)
688                 acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data);
689 }
690
691 static void acpi_thermal_check(void *data)
692 {
693         int result = 0;
694         struct acpi_thermal *tz = data;
695         unsigned long sleep_time = 0;
696         int i = 0;
697         struct acpi_thermal_state state;
698
699
700         if (!tz) {
701                 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
702                 return;
703         }
704
705         state = tz->state;
706
707         result = acpi_thermal_get_temperature(tz);
708         if (result)
709                 return;
710
711         memset(&tz->state, 0, sizeof(tz->state));
712
713         /*
714          * Check Trip Points
715          * -----------------
716          * Compare the current temperature to the trip point values to see
717          * if we've entered one of the thermal policy states.  Note that
718          * this function determines when a state is entered, but the 
719          * individual policy decides when it is exited (e.g. hysteresis).
720          */
721         if (tz->trips.critical.flags.valid)
722                 state.critical |=
723                     (tz->temperature >= tz->trips.critical.temperature);
724         if (tz->trips.hot.flags.valid)
725                 state.hot |= (tz->temperature >= tz->trips.hot.temperature);
726         if (tz->trips.passive.flags.valid)
727                 state.passive |=
728                     (tz->temperature >= tz->trips.passive.temperature);
729         for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
730                 if (tz->trips.active[i].flags.valid)
731                         state.active |=
732                             (tz->temperature >=
733                              tz->trips.active[i].temperature);
734
735         /*
736          * Invoke Policy
737          * -------------
738          * Separated from the above check to allow individual policy to 
739          * determine when to exit a given state.
740          */
741         if (state.critical)
742                 acpi_thermal_critical(tz);
743         if (state.hot)
744                 acpi_thermal_hot(tz);
745         if (state.passive)
746                 acpi_thermal_passive(tz);
747         if (state.active)
748                 acpi_thermal_active(tz);
749
750         /*
751          * Calculate State
752          * ---------------
753          * Again, separated from the above two to allow independent policy
754          * decisions.
755          */
756         tz->state.critical = tz->trips.critical.flags.enabled;
757         tz->state.hot = tz->trips.hot.flags.enabled;
758         tz->state.passive = tz->trips.passive.flags.enabled;
759         tz->state.active = 0;
760         for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
761                 tz->state.active |= tz->trips.active[i].flags.enabled;
762
763         /*
764          * Calculate Sleep Time
765          * --------------------
766          * If we're in the passive state, use _TSP's value.  Otherwise
767          * use the default polling frequency (e.g. _TZP).  If no polling
768          * frequency is specified then we'll wait forever (at least until
769          * a thermal event occurs).  Note that _TSP and _TZD values are
770          * given in 1/10th seconds (we must covert to milliseconds).
771          */
772         if (tz->state.passive)
773                 sleep_time = tz->trips.passive.tsp * 100;
774         else if (tz->polling_frequency > 0)
775                 sleep_time = tz->polling_frequency * 100;
776
777         ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n",
778                           tz->name, tz->temperature, sleep_time));
779
780         /*
781          * Schedule Next Poll
782          * ------------------
783          */
784         if (!sleep_time) {
785                 if (timer_pending(&(tz->timer)))
786                         del_timer(&(tz->timer));
787         } else {
788                 if (timer_pending(&(tz->timer)))
789                         mod_timer(&(tz->timer),
790                                         jiffies + (HZ * sleep_time) / 1000);
791                 else {
792                         tz->timer.data = (unsigned long)tz;
793                         tz->timer.function = acpi_thermal_run;
794                         tz->timer.expires = jiffies + (HZ * sleep_time) / 1000;
795                         add_timer(&(tz->timer));
796                 }
797         }
798
799         return;
800 }
801
802 /* --------------------------------------------------------------------------
803                               FS Interface (/proc)
804    -------------------------------------------------------------------------- */
805
806 static struct proc_dir_entry *acpi_thermal_dir;
807
808 static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
809 {
810         struct acpi_thermal *tz = seq->private;
811
812
813         if (!tz)
814                 goto end;
815
816         seq_puts(seq, "state:                   ");
817
818         if (!tz->state.critical && !tz->state.hot && !tz->state.passive
819             && !tz->state.active)
820                 seq_puts(seq, "ok\n");
821         else {
822                 if (tz->state.critical)
823                         seq_puts(seq, "critical ");
824                 if (tz->state.hot)
825                         seq_puts(seq, "hot ");
826                 if (tz->state.passive)
827                         seq_puts(seq, "passive ");
828                 if (tz->state.active)
829                         seq_printf(seq, "active[%d]", tz->state.active_index);
830                 seq_puts(seq, "\n");
831         }
832
833       end:
834         return 0;
835 }
836
837 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
838 {
839         return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
840 }
841
842 static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
843 {
844         int result = 0;
845         struct acpi_thermal *tz = seq->private;
846
847
848         if (!tz)
849                 goto end;
850
851         result = acpi_thermal_get_temperature(tz);
852         if (result)
853                 goto end;
854
855         seq_printf(seq, "temperature:             %ld C\n",
856                    KELVIN_TO_CELSIUS(tz->temperature));
857
858       end:
859         return 0;
860 }
861
862 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
863 {
864         return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
865 }
866
867 static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
868 {
869         struct acpi_thermal *tz = seq->private;
870         struct acpi_device *device;
871         acpi_status status;
872
873         int i = 0;
874         int j = 0;
875
876
877         if (!tz)
878                 goto end;
879
880         if (tz->trips.critical.flags.valid)
881                 seq_printf(seq, "critical (S5):           %ld C%s",
882                            KELVIN_TO_CELSIUS(tz->trips.critical.temperature),
883                            nocrt ? " <disabled>\n" : "\n");
884
885         if (tz->trips.hot.flags.valid)
886                 seq_printf(seq, "hot (S4):                %ld C%s",
887                            KELVIN_TO_CELSIUS(tz->trips.hot.temperature),
888                            nocrt ? " <disabled>\n" : "\n");
889
890         if (tz->trips.passive.flags.valid) {
891                 seq_printf(seq,
892                            "passive:                 %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
893                            KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
894                            tz->trips.passive.tc1, tz->trips.passive.tc2,
895                            tz->trips.passive.tsp);
896                 for (j = 0; j < tz->trips.passive.devices.count; j++) {
897                         status = acpi_bus_get_device(tz->trips.passive.devices.
898                                                      handles[j], &device);
899                         seq_printf(seq, "%4.4s ", status ? "" :
900                                    acpi_device_bid(device));
901                 }
902                 seq_puts(seq, "\n");
903         }
904
905         for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
906                 if (!(tz->trips.active[i].flags.valid))
907                         break;
908                 seq_printf(seq, "active[%d]:               %ld C: devices=",
909                            i,
910                            KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
911                 for (j = 0; j < tz->trips.active[i].devices.count; j++){
912                         status = acpi_bus_get_device(tz->trips.active[i].
913                                                      devices.handles[j],
914                                                      &device);
915                         seq_printf(seq, "%4.4s ", status ? "" :
916                                    acpi_device_bid(device));
917                 }
918                 seq_puts(seq, "\n");
919         }
920
921       end:
922         return 0;
923 }
924
925 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
926 {
927         return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
928 }
929
930 static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
931 {
932         struct acpi_thermal *tz = seq->private;
933
934
935         if (!tz)
936                 goto end;
937
938         if (!tz->flags.cooling_mode)
939                 seq_puts(seq, "<setting not supported>\n");
940         else
941                 seq_puts(seq, "0 - Active; 1 - Passive\n");
942
943       end:
944         return 0;
945 }
946
947 static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
948 {
949         return single_open(file, acpi_thermal_cooling_seq_show,
950                            PDE(inode)->data);
951 }
952
953 static ssize_t
954 acpi_thermal_write_cooling_mode(struct file *file,
955                                 const char __user * buffer,
956                                 size_t count, loff_t * ppos)
957 {
958         struct seq_file *m = file->private_data;
959         struct acpi_thermal *tz = m->private;
960         int result = 0;
961         char mode_string[12] = { '\0' };
962
963
964         if (!tz || (count > sizeof(mode_string) - 1))
965                 return -EINVAL;
966
967         if (!tz->flags.cooling_mode)
968                 return -ENODEV;
969
970         if (copy_from_user(mode_string, buffer, count))
971                 return -EFAULT;
972
973         mode_string[count] = '\0';
974
975         result = acpi_thermal_set_cooling_mode(tz,
976                                                simple_strtoul(mode_string, NULL,
977                                                               0));
978         if (result)
979                 return result;
980
981         acpi_thermal_check(tz);
982
983         return count;
984 }
985
986 static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
987 {
988         struct acpi_thermal *tz = seq->private;
989
990
991         if (!tz)
992                 goto end;
993
994         if (!tz->polling_frequency) {
995                 seq_puts(seq, "<polling disabled>\n");
996                 goto end;
997         }
998
999         seq_printf(seq, "polling frequency:       %lu seconds\n",
1000                    (tz->polling_frequency / 10));
1001
1002       end:
1003         return 0;
1004 }
1005
1006 static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
1007 {
1008         return single_open(file, acpi_thermal_polling_seq_show,
1009                            PDE(inode)->data);
1010 }
1011
1012 static ssize_t
1013 acpi_thermal_write_polling(struct file *file,
1014                            const char __user * buffer,
1015                            size_t count, loff_t * ppos)
1016 {
1017         struct seq_file *m = file->private_data;
1018         struct acpi_thermal *tz = m->private;
1019         int result = 0;
1020         char polling_string[12] = { '\0' };
1021         int seconds = 0;
1022
1023
1024         if (!tz || (count > sizeof(polling_string) - 1))
1025                 return -EINVAL;
1026
1027         if (copy_from_user(polling_string, buffer, count))
1028                 return -EFAULT;
1029
1030         polling_string[count] = '\0';
1031
1032         seconds = simple_strtoul(polling_string, NULL, 0);
1033
1034         result = acpi_thermal_set_polling(tz, seconds);
1035         if (result)
1036                 return result;
1037
1038         acpi_thermal_check(tz);
1039
1040         return count;
1041 }
1042
1043 static int acpi_thermal_add_fs(struct acpi_device *device)
1044 {
1045         struct proc_dir_entry *entry = NULL;
1046
1047
1048         if (!acpi_device_dir(device)) {
1049                 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1050                                                      acpi_thermal_dir);
1051                 if (!acpi_device_dir(device))
1052                         return -ENODEV;
1053                 acpi_device_dir(device)->owner = THIS_MODULE;
1054         }
1055
1056         /* 'state' [R] */
1057         entry = create_proc_entry(ACPI_THERMAL_FILE_STATE,
1058                                   S_IRUGO, acpi_device_dir(device));
1059         if (!entry)
1060                 return -ENODEV;
1061         else {
1062                 entry->proc_fops = &acpi_thermal_state_fops;
1063                 entry->data = acpi_driver_data(device);
1064                 entry->owner = THIS_MODULE;
1065         }
1066
1067         /* 'temperature' [R] */
1068         entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1069                                   S_IRUGO, acpi_device_dir(device));
1070         if (!entry)
1071                 return -ENODEV;
1072         else {
1073                 entry->proc_fops = &acpi_thermal_temp_fops;
1074                 entry->data = acpi_driver_data(device);
1075                 entry->owner = THIS_MODULE;
1076         }
1077
1078         /* 'trip_points' [R/W] */
1079         entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1080                                   S_IFREG | S_IRUGO | S_IWUSR,
1081                                   acpi_device_dir(device));
1082         if (!entry)
1083                 return -ENODEV;
1084         else {
1085                 entry->proc_fops = &acpi_thermal_trip_fops;
1086                 entry->data = acpi_driver_data(device);
1087                 entry->owner = THIS_MODULE;
1088         }
1089
1090         /* 'cooling_mode' [R/W] */
1091         entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1092                                   S_IFREG | S_IRUGO | S_IWUSR,
1093                                   acpi_device_dir(device));
1094         if (!entry)
1095                 return -ENODEV;
1096         else {
1097                 entry->proc_fops = &acpi_thermal_cooling_fops;
1098                 entry->data = acpi_driver_data(device);
1099                 entry->owner = THIS_MODULE;
1100         }
1101
1102         /* 'polling_frequency' [R/W] */
1103         entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1104                                   S_IFREG | S_IRUGO | S_IWUSR,
1105                                   acpi_device_dir(device));
1106         if (!entry)
1107                 return -ENODEV;
1108         else {
1109                 entry->proc_fops = &acpi_thermal_polling_fops;
1110                 entry->data = acpi_driver_data(device);
1111                 entry->owner = THIS_MODULE;
1112         }
1113
1114         return 0;
1115 }
1116
1117 static int acpi_thermal_remove_fs(struct acpi_device *device)
1118 {
1119
1120         if (acpi_device_dir(device)) {
1121                 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1122                                   acpi_device_dir(device));
1123                 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1124                                   acpi_device_dir(device));
1125                 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1126                                   acpi_device_dir(device));
1127                 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1128                                   acpi_device_dir(device));
1129                 remove_proc_entry(ACPI_THERMAL_FILE_STATE,
1130                                   acpi_device_dir(device));
1131                 remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
1132                 acpi_device_dir(device) = NULL;
1133         }
1134
1135         return 0;
1136 }
1137
1138 /* --------------------------------------------------------------------------
1139                                  Driver Interface
1140    -------------------------------------------------------------------------- */
1141
1142 static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
1143 {
1144         struct acpi_thermal *tz = data;
1145         struct acpi_device *device = NULL;
1146
1147
1148         if (!tz)
1149                 return;
1150
1151         device = tz->device;
1152
1153         switch (event) {
1154         case ACPI_THERMAL_NOTIFY_TEMPERATURE:
1155                 acpi_thermal_check(tz);
1156                 break;
1157         case ACPI_THERMAL_NOTIFY_THRESHOLDS:
1158                 acpi_thermal_get_trip_points(tz);
1159                 acpi_thermal_check(tz);
1160                 acpi_bus_generate_proc_event(device, event, 0);
1161                 acpi_bus_generate_netlink_event(device->pnp.device_class,
1162                                                   device->dev.bus_id, event, 0);
1163                 break;
1164         case ACPI_THERMAL_NOTIFY_DEVICES:
1165                 if (tz->flags.devices)
1166                         acpi_thermal_get_devices(tz);
1167                 acpi_bus_generate_proc_event(device, event, 0);
1168                 acpi_bus_generate_netlink_event(device->pnp.device_class,
1169                                                   device->dev.bus_id, event, 0);
1170                 break;
1171         default:
1172                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1173                                   "Unsupported event [0x%x]\n", event));
1174                 break;
1175         }
1176
1177         return;
1178 }
1179
1180 static int acpi_thermal_get_info(struct acpi_thermal *tz)
1181 {
1182         int result = 0;
1183
1184
1185         if (!tz)
1186                 return -EINVAL;
1187
1188         /* Get temperature [_TMP] (required) */
1189         result = acpi_thermal_get_temperature(tz);
1190         if (result)
1191                 return result;
1192
1193         /* Get trip points [_CRT, _PSV, etc.] (required) */
1194         result = acpi_thermal_get_trip_points(tz);
1195         if (result)
1196                 return result;
1197
1198         /* Set the cooling mode [_SCP] to active cooling (default) */
1199         result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
1200         if (!result)
1201                 tz->flags.cooling_mode = 1;
1202
1203         /* Get default polling frequency [_TZP] (optional) */
1204         if (tzp)
1205                 tz->polling_frequency = tzp;
1206         else
1207                 acpi_thermal_get_polling_frequency(tz);
1208
1209         /* Get devices in this thermal zone [_TZD] (optional) */
1210         result = acpi_thermal_get_devices(tz);
1211         if (!result)
1212                 tz->flags.devices = 1;
1213
1214         return 0;
1215 }
1216
1217 static int acpi_thermal_add(struct acpi_device *device)
1218 {
1219         int result = 0;
1220         acpi_status status = AE_OK;
1221         struct acpi_thermal *tz = NULL;
1222
1223
1224         if (!device)
1225                 return -EINVAL;
1226
1227         tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1228         if (!tz)
1229                 return -ENOMEM;
1230
1231         tz->device = device;
1232         strcpy(tz->name, device->pnp.bus_id);
1233         strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1234         strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
1235         acpi_driver_data(device) = tz;
1236
1237         result = acpi_thermal_get_info(tz);
1238         if (result)
1239                 goto end;
1240
1241         result = acpi_thermal_add_fs(device);
1242         if (result)
1243                 goto end;
1244
1245         init_timer(&tz->timer);
1246
1247         acpi_thermal_check(tz);
1248
1249         status = acpi_install_notify_handler(device->handle,
1250                                              ACPI_DEVICE_NOTIFY,
1251                                              acpi_thermal_notify, tz);
1252         if (ACPI_FAILURE(status)) {
1253                 result = -ENODEV;
1254                 goto end;
1255         }
1256
1257         printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
1258                acpi_device_name(device), acpi_device_bid(device),
1259                KELVIN_TO_CELSIUS(tz->temperature));
1260
1261       end:
1262         if (result) {
1263                 acpi_thermal_remove_fs(device);
1264                 kfree(tz);
1265         }
1266
1267         return result;
1268 }
1269
1270 static int acpi_thermal_remove(struct acpi_device *device, int type)
1271 {
1272         acpi_status status = AE_OK;
1273         struct acpi_thermal *tz = NULL;
1274
1275
1276         if (!device || !acpi_driver_data(device))
1277                 return -EINVAL;
1278
1279         tz = acpi_driver_data(device);
1280
1281         /* avoid timer adding new defer task */
1282         tz->zombie = 1;
1283         /* wait for running timer (on other CPUs) finish */
1284         del_timer_sync(&(tz->timer));
1285         /* synchronize deferred task */
1286         acpi_os_wait_events_complete(NULL);
1287         /* deferred task may reinsert timer */
1288         del_timer_sync(&(tz->timer));
1289
1290         status = acpi_remove_notify_handler(device->handle,
1291                                             ACPI_DEVICE_NOTIFY,
1292                                             acpi_thermal_notify);
1293
1294         /* Terminate policy */
1295         if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
1296                 tz->trips.passive.flags.enabled = 0;
1297                 acpi_thermal_passive(tz);
1298         }
1299         if (tz->trips.active[0].flags.valid
1300             && tz->trips.active[0].flags.enabled) {
1301                 tz->trips.active[0].flags.enabled = 0;
1302                 acpi_thermal_active(tz);
1303         }
1304
1305         acpi_thermal_remove_fs(device);
1306
1307         kfree(tz);
1308         return 0;
1309 }
1310
1311 static int acpi_thermal_resume(struct acpi_device *device)
1312 {
1313         struct acpi_thermal *tz = NULL;
1314         int i, j, power_state, result;
1315
1316
1317         if (!device || !acpi_driver_data(device))
1318                 return -EINVAL;
1319
1320         tz = acpi_driver_data(device);
1321
1322         for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1323                 if (!(&tz->trips.active[i]))
1324                         break;
1325                 if (!tz->trips.active[i].flags.valid)
1326                         break;
1327                 tz->trips.active[i].flags.enabled = 1;
1328                 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1329                         result = acpi_bus_get_power(tz->trips.active[i].devices.
1330                             handles[j], &power_state);
1331                         if (result || (power_state != ACPI_STATE_D0)) {
1332                                 tz->trips.active[i].flags.enabled = 0;
1333                                 break;
1334                         }
1335                 }
1336                 tz->state.active |= tz->trips.active[i].flags.enabled;
1337         }
1338
1339         acpi_thermal_check(tz);
1340
1341         return AE_OK;
1342 }
1343
1344 #ifdef CONFIG_DMI
1345 static int thermal_act(struct dmi_system_id *d) {
1346
1347         if (act == 0) {
1348                 printk(KERN_NOTICE "ACPI: %s detected: "
1349                         "disabling all active thermal trip points\n", d->ident);
1350                 act = -1;
1351         }
1352         return 0;
1353 }
1354 static int thermal_tzp(struct dmi_system_id *d) {
1355
1356         if (tzp == 0) {
1357                 printk(KERN_NOTICE "ACPI: %s detected: "
1358                         "enabling thermal zone polling\n", d->ident);
1359                 tzp = 300;      /* 300 dS = 30 Seconds */
1360         }
1361         return 0;
1362 }
1363 static int thermal_psv(struct dmi_system_id *d) {
1364
1365         if (psv == 0) {
1366                 printk(KERN_NOTICE "ACPI: %s detected: "
1367                         "disabling all passive thermal trip points\n", d->ident);
1368                 psv = -1;
1369         }
1370         return 0;
1371 }
1372
1373 static struct dmi_system_id thermal_dmi_table[] __initdata = {
1374         /*
1375          * Award BIOS on this AOpen makes thermal control almost worthless.
1376          * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1377          */
1378         {
1379          .callback = thermal_act,
1380          .ident = "AOpen i915GMm-HFS",
1381          .matches = {
1382                 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1383                 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1384                 },
1385         },
1386         {
1387          .callback = thermal_psv,
1388          .ident = "AOpen i915GMm-HFS",
1389          .matches = {
1390                 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1391                 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1392                 },
1393         },
1394         {
1395          .callback = thermal_tzp,
1396          .ident = "AOpen i915GMm-HFS",
1397          .matches = {
1398                 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1399                 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1400                 },
1401         },
1402         {}
1403 };
1404 #endif /* CONFIG_DMI */
1405
1406 static int __init acpi_thermal_init(void)
1407 {
1408         int result = 0;
1409
1410         dmi_check_system(thermal_dmi_table);
1411
1412         if (off) {
1413                 printk(KERN_NOTICE "ACPI: thermal control disabled\n");
1414                 return -ENODEV;
1415         }
1416         acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
1417         if (!acpi_thermal_dir)
1418                 return -ENODEV;
1419         acpi_thermal_dir->owner = THIS_MODULE;
1420
1421         result = acpi_bus_register_driver(&acpi_thermal_driver);
1422         if (result < 0) {
1423                 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1424                 return -ENODEV;
1425         }
1426
1427         return 0;
1428 }
1429
1430 static void __exit acpi_thermal_exit(void)
1431 {
1432
1433         acpi_bus_unregister_driver(&acpi_thermal_driver);
1434
1435         remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1436
1437         return;
1438 }
1439
1440 module_init(acpi_thermal_init);
1441 module_exit(acpi_thermal_exit);