blob: c6cfce4c0122bbfc78ade321b4d8816d0c40b018 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Len Brown0b5bfa12007-08-12 00:13:02 -040036#include <linux/dmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/init.h>
38#include <linux/types.h>
39#include <linux/proc_fs.h>
Tim Schmielaucd354f12007-02-14 00:33:14 -080040#include <linux/timer.h>
41#include <linux/jiffies.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/kmod.h>
43#include <linux/seq_file.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070044#include <linux/reboot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <asm/uaccess.h>
Zhang Rui3f655ef2008-01-17 15:51:11 +080046#include <linux/thermal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#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
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
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
Len Brownf52fd662007-02-12 22:42:12 -050072ACPI_MODULE_NAME("thermal");
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Thomas Renninger1cbf4c52004-09-16 11:07:00 -040074MODULE_AUTHOR("Paul Diefenbaugh");
Len Brown7cda93e2007-02-12 23:50:02 -050075MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070076MODULE_LICENSE("GPL");
77
Len Brownf8707ec2007-08-12 00:12:54 -040078static int act;
79module_param(act, int, 0644);
Len Brown3c1d36d2007-08-14 15:12:56 -040080MODULE_PARM_DESC(act, "Disable or override all lowest active trip points.");
Len Brownf8707ec2007-08-12 00:12:54 -040081
Len Brownc52a7412007-08-14 15:49:32 -040082static int crt;
83module_param(crt, int, 0644);
84MODULE_PARM_DESC(crt, "Disable or lower all critical trip points.");
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086static int tzp;
Len Brown730ff342007-08-12 00:12:26 -040087module_param(tzp, int, 0444);
Len Brown3c1d36d2007-08-14 15:12:56 -040088MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Len Brownf5487142007-08-12 00:12:44 -040090static int nocrt;
91module_param(nocrt, int, 0);
Len Brown8c99fdc2007-08-20 18:46:50 -040092MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points.");
Len Brownf5487142007-08-12 00:12:44 -040093
Len Brown72b33ef2007-08-12 00:12:17 -040094static int off;
95module_param(off, int, 0);
Len Brown3c1d36d2007-08-14 15:12:56 -040096MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.");
Len Brown72b33ef2007-08-12 00:12:17 -040097
Len Browna70cdc52007-08-12 00:12:35 -040098static int psv;
99module_param(psv, int, 0644);
Len Brown3c1d36d2007-08-14 15:12:56 -0400100MODULE_PARM_DESC(psv, "Disable or override all passive trip points.");
Len Browna70cdc52007-08-12 00:12:35 -0400101
Len Brown4be44fc2005-08-05 00:44:28 -0400102static int acpi_thermal_add(struct acpi_device *device);
103static int acpi_thermal_remove(struct acpi_device *device, int type);
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800104static int acpi_thermal_resume(struct acpi_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
106static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
107static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
Len Brown4be44fc2005-08-05 00:44:28 -0400109static ssize_t acpi_thermal_write_cooling_mode(struct file *,
110 const char __user *, size_t,
111 loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
Len Brown4be44fc2005-08-05 00:44:28 -0400113static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
114 size_t, loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200116static const struct acpi_device_id thermal_device_ids[] = {
117 {ACPI_THERMAL_HID, 0},
118 {"", 0},
119};
120MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122static struct acpi_driver acpi_thermal_driver = {
Len Brownc2b67052007-02-12 23:33:40 -0500123 .name = "thermal",
Len Brown4be44fc2005-08-05 00:44:28 -0400124 .class = ACPI_THERMAL_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200125 .ids = thermal_device_ids,
Len Brown4be44fc2005-08-05 00:44:28 -0400126 .ops = {
127 .add = acpi_thermal_add,
128 .remove = acpi_thermal_remove,
Konstantin Karasyov74ce14682006-05-08 08:32:00 -0400129 .resume = acpi_thermal_resume,
Len Brown4be44fc2005-08-05 00:44:28 -0400130 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131};
132
133struct acpi_thermal_state {
Len Brown4be44fc2005-08-05 00:44:28 -0400134 u8 critical:1;
135 u8 hot:1;
136 u8 passive:1;
137 u8 active:1;
138 u8 reserved:4;
139 int active_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140};
141
142struct acpi_thermal_state_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400143 u8 valid:1;
144 u8 enabled:1;
145 u8 reserved:6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146};
147
148struct acpi_thermal_critical {
149 struct acpi_thermal_state_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400150 unsigned long temperature;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151};
152
153struct acpi_thermal_hot {
154 struct acpi_thermal_state_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400155 unsigned long temperature;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156};
157
158struct acpi_thermal_passive {
159 struct acpi_thermal_state_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400160 unsigned long temperature;
161 unsigned long tc1;
162 unsigned long tc2;
163 unsigned long tsp;
164 struct acpi_handle_list devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165};
166
167struct acpi_thermal_active {
168 struct acpi_thermal_state_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400169 unsigned long temperature;
170 struct acpi_handle_list devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171};
172
173struct acpi_thermal_trips {
174 struct acpi_thermal_critical critical;
Len Brown4be44fc2005-08-05 00:44:28 -0400175 struct acpi_thermal_hot hot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 struct acpi_thermal_passive passive;
177 struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
178};
179
180struct acpi_thermal_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400181 u8 cooling_mode:1; /* _SCP */
182 u8 devices:1; /* _TZD */
183 u8 reserved:6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184};
185
186struct acpi_thermal {
Patrick Mochel8348e1b2006-05-19 16:54:40 -0400187 struct acpi_device * device;
Len Brown4be44fc2005-08-05 00:44:28 -0400188 acpi_bus_id name;
189 unsigned long temperature;
190 unsigned long last_temperature;
191 unsigned long polling_frequency;
Len Brown4be44fc2005-08-05 00:44:28 -0400192 volatile u8 zombie;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 struct acpi_thermal_flags flags;
194 struct acpi_thermal_state state;
195 struct acpi_thermal_trips trips;
Len Brown4be44fc2005-08-05 00:44:28 -0400196 struct acpi_handle_list devices;
197 struct timer_list timer;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800198 struct thermal_zone_device *thermal_zone;
199 int tz_enabled;
Alexey Starikovskiy6e215782007-09-01 00:11:59 +0400200 struct mutex lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201};
202
Arjan van de Vend7508032006-07-04 13:06:00 -0400203static const struct file_operations acpi_thermal_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400204 .open = acpi_thermal_state_open_fs,
205 .read = seq_read,
206 .llseek = seq_lseek,
207 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208};
209
Arjan van de Vend7508032006-07-04 13:06:00 -0400210static const struct file_operations acpi_thermal_temp_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400211 .open = acpi_thermal_temp_open_fs,
212 .read = seq_read,
213 .llseek = seq_lseek,
214 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215};
216
Arjan van de Vend7508032006-07-04 13:06:00 -0400217static const struct file_operations acpi_thermal_trip_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400218 .open = acpi_thermal_trip_open_fs,
219 .read = seq_read,
Len Brown4be44fc2005-08-05 00:44:28 -0400220 .llseek = seq_lseek,
221 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222};
223
Arjan van de Vend7508032006-07-04 13:06:00 -0400224static const struct file_operations acpi_thermal_cooling_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400225 .open = acpi_thermal_cooling_open_fs,
226 .read = seq_read,
227 .write = acpi_thermal_write_cooling_mode,
228 .llseek = seq_lseek,
229 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230};
231
Arjan van de Vend7508032006-07-04 13:06:00 -0400232static const struct file_operations acpi_thermal_polling_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400233 .open = acpi_thermal_polling_open_fs,
234 .read = seq_read,
235 .write = acpi_thermal_write_polling,
236 .llseek = seq_lseek,
237 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238};
239
240/* --------------------------------------------------------------------------
241 Thermal Zone Management
242 -------------------------------------------------------------------------- */
243
Len Brown4be44fc2005-08-05 00:44:28 -0400244static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
Len Brown4be44fc2005-08-05 00:44:28 -0400246 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400250 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
252 tz->last_temperature = tz->temperature;
253
Len Brown4be44fc2005-08-05 00:44:28 -0400254 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400255 acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tz->temperature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400257 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Len Brown4be44fc2005-08-05 00:44:28 -0400259 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
260 tz->temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Patrick Mocheld550d982006-06-27 00:41:40 -0400262 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263}
264
Len Brown4be44fc2005-08-05 00:44:28 -0400265static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
Len Brown4be44fc2005-08-05 00:44:28 -0400267 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400271 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Len Brown4be44fc2005-08-05 00:44:28 -0400273 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400274 acpi_evaluate_integer(tz->device->handle, "_TZP", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400275 &tz->polling_frequency);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400277 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Len Brown4be44fc2005-08-05 00:44:28 -0400279 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
280 tz->polling_frequency));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Patrick Mocheld550d982006-06-27 00:41:40 -0400282 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283}
284
Len Brown4be44fc2005-08-05 00:44:28 -0400285static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400289 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
292
Len Brown4be44fc2005-08-05 00:44:28 -0400293 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
294 "Polling frequency set to %lu seconds\n",
Sanjoy Mahajan636cedf2007-02-16 01:24:43 -0500295 tz->polling_frequency/10));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Patrick Mocheld550d982006-06-27 00:41:40 -0400297 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
299
Len Brown4be44fc2005-08-05 00:44:28 -0400300static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
Len Brown4be44fc2005-08-05 00:44:28 -0400302 acpi_status status = AE_OK;
303 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
304 struct acpi_object_list arg_list = { 1, &arg0 };
305 acpi_handle handle = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400309 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400311 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 if (ACPI_FAILURE(status)) {
313 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400314 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 }
316
317 arg0.integer.value = mode;
318
319 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
320 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400321 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Patrick Mocheld550d982006-06-27 00:41:40 -0400323 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324}
325
Len Brown4be44fc2005-08-05 00:44:28 -0400326static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
Len Brown4be44fc2005-08-05 00:44:28 -0400328 acpi_status status = AE_OK;
329 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
332 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400333 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335 /* Critical Shutdown (required) */
336
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400337 status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400338 &tz->trips.critical.temperature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 if (ACPI_FAILURE(status)) {
340 tz->trips.critical.flags.valid = 0;
Thomas Renningera6fc6722006-06-26 23:58:43 -0400341 ACPI_EXCEPTION((AE_INFO, status, "No critical threshold"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400342 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400343 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 tz->trips.critical.flags.valid = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400345 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
346 "Found critical threshold [%lu]\n",
347 tz->trips.critical.temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 }
349
Len Brownc52a7412007-08-14 15:49:32 -0400350 if (tz->trips.critical.flags.valid == 1) {
351 if (crt == -1) {
352 tz->trips.critical.flags.valid = 0;
353 } else if (crt > 0) {
354 unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
355
356 /*
357 * Allow override to lower critical threshold
358 */
359 if (crt_k < tz->trips.critical.temperature)
360 tz->trips.critical.temperature = crt_k;
361 }
362 }
363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 /* Critical Sleep (optional) */
365
Len Brown4be44fc2005-08-05 00:44:28 -0400366 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400367 acpi_evaluate_integer(tz->device->handle, "_HOT", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400368 &tz->trips.hot.temperature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 if (ACPI_FAILURE(status)) {
370 tz->trips.hot.flags.valid = 0;
371 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No hot threshold\n"));
Len Brown4be44fc2005-08-05 00:44:28 -0400372 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 tz->trips.hot.flags.valid = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400374 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found hot threshold [%lu]\n",
375 tz->trips.hot.temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 }
377
378 /* Passive: Processors (optional) */
379
Len Browna70cdc52007-08-12 00:12:35 -0400380 if (psv == -1) {
381 status = AE_SUPPORT;
382 } else if (psv > 0) {
383 tz->trips.passive.temperature = CELSIUS_TO_KELVIN(psv);
384 status = AE_OK;
385 } else {
386 status = acpi_evaluate_integer(tz->device->handle,
387 "_PSV", NULL, &tz->trips.passive.temperature);
388 }
389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 if (ACPI_FAILURE(status)) {
391 tz->trips.passive.flags.valid = 0;
392 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No passive threshold\n"));
Len Brown4be44fc2005-08-05 00:44:28 -0400393 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 tz->trips.passive.flags.valid = 1;
395
Len Brown4be44fc2005-08-05 00:44:28 -0400396 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400397 acpi_evaluate_integer(tz->device->handle, "_TC1", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400398 &tz->trips.passive.tc1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 if (ACPI_FAILURE(status))
400 tz->trips.passive.flags.valid = 0;
401
Len Brown4be44fc2005-08-05 00:44:28 -0400402 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400403 acpi_evaluate_integer(tz->device->handle, "_TC2", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400404 &tz->trips.passive.tc2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 if (ACPI_FAILURE(status))
406 tz->trips.passive.flags.valid = 0;
407
Len Brown4be44fc2005-08-05 00:44:28 -0400408 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400409 acpi_evaluate_integer(tz->device->handle, "_TSP", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400410 &tz->trips.passive.tsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 if (ACPI_FAILURE(status))
412 tz->trips.passive.flags.valid = 0;
413
Len Brown4be44fc2005-08-05 00:44:28 -0400414 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400415 acpi_evaluate_reference(tz->device->handle, "_PSL", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400416 &tz->trips.passive.devices);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 if (ACPI_FAILURE(status))
418 tz->trips.passive.flags.valid = 0;
419
420 if (!tz->trips.passive.flags.valid)
Len Browncece9292006-06-26 23:04:31 -0400421 printk(KERN_WARNING PREFIX "Invalid passive threshold\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 else
Len Brown4be44fc2005-08-05 00:44:28 -0400423 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
424 "Found passive threshold [%lu]\n",
425 tz->trips.passive.temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 }
427
428 /* Active: Fans, etc. (optional) */
429
Len Brown4be44fc2005-08-05 00:44:28 -0400430 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Len Brown4be44fc2005-08-05 00:44:28 -0400432 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Len Brownf8707ec2007-08-12 00:12:54 -0400434 if (act == -1)
435 break; /* disable all active trip points */
436
437 status = acpi_evaluate_integer(tz->device->handle,
438 name, NULL, &tz->trips.active[i].temperature);
439
440 if (ACPI_FAILURE(status)) {
441 if (i == 0) /* no active trip points */
442 break;
443 if (act <= 0) /* no override requested */
444 break;
445 if (i == 1) { /* 1 trip point */
446 tz->trips.active[0].temperature =
447 CELSIUS_TO_KELVIN(act);
448 } else { /* multiple trips */
449 /*
450 * Don't allow override higher than
451 * the next higher trip point
452 */
453 tz->trips.active[i - 1].temperature =
454 (tz->trips.active[i - 2].temperature <
455 CELSIUS_TO_KELVIN(act) ?
456 tz->trips.active[i - 2].temperature :
457 CELSIUS_TO_KELVIN(act));
458 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 break;
Len Brownf8707ec2007-08-12 00:12:54 -0400460 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
462 name[2] = 'L';
Len Brown4be44fc2005-08-05 00:44:28 -0400463 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400464 acpi_evaluate_reference(tz->device->handle, name, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400465 &tz->trips.active[i].devices);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 if (ACPI_SUCCESS(status)) {
467 tz->trips.active[i].flags.valid = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400468 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
469 "Found active threshold [%d]:[%lu]\n",
470 i, tz->trips.active[i].temperature));
471 } else
Thomas Renningera6fc6722006-06-26 23:58:43 -0400472 ACPI_EXCEPTION((AE_INFO, status,
473 "Invalid active threshold [%d]", i));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 }
475
Patrick Mocheld550d982006-06-27 00:41:40 -0400476 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477}
478
Len Brown4be44fc2005-08-05 00:44:28 -0400479static int acpi_thermal_get_devices(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
Len Brown4be44fc2005-08-05 00:44:28 -0400481 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
484 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400485 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Len Brown4be44fc2005-08-05 00:44:28 -0400487 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400488 acpi_evaluate_reference(tz->device->handle, "_TZD", NULL, &tz->devices);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400490 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Patrick Mocheld550d982006-06-27 00:41:40 -0400492 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493}
494
Len Brown4be44fc2005-08-05 00:44:28 -0400495static int acpi_thermal_critical(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
Len Brownf5487142007-08-12 00:12:44 -0400497 if (!tz || !tz->trips.critical.flags.valid || nocrt)
Patrick Mocheld550d982006-06-27 00:41:40 -0400498 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
500 if (tz->temperature >= tz->trips.critical.temperature) {
Len Browncece9292006-06-26 23:04:31 -0400501 printk(KERN_WARNING PREFIX "Critical trip point\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 tz->trips.critical.flags.enabled = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400503 } else if (tz->trips.critical.flags.enabled)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 tz->trips.critical.flags.enabled = 0;
505
Len Brown4be44fc2005-08-05 00:44:28 -0400506 printk(KERN_EMERG
507 "Critical temperature reached (%ld C), shutting down.\n",
508 KELVIN_TO_CELSIUS(tz->temperature));
Len Brown14e04fb2007-08-23 15:20:26 -0400509 acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL,
Len Brown4be44fc2005-08-05 00:44:28 -0400510 tz->trips.critical.flags.enabled);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800511 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
512 tz->device->dev.bus_id,
513 ACPI_THERMAL_NOTIFY_CRITICAL,
514 tz->trips.critical.flags.enabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700516 orderly_poweroff(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Patrick Mocheld550d982006-06-27 00:41:40 -0400518 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519}
520
Len Brown4be44fc2005-08-05 00:44:28 -0400521static int acpi_thermal_hot(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522{
Len Brownf5487142007-08-12 00:12:44 -0400523 if (!tz || !tz->trips.hot.flags.valid || nocrt)
Patrick Mocheld550d982006-06-27 00:41:40 -0400524 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526 if (tz->temperature >= tz->trips.hot.temperature) {
Len Browncece9292006-06-26 23:04:31 -0400527 printk(KERN_WARNING PREFIX "Hot trip point\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 tz->trips.hot.flags.enabled = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400529 } else if (tz->trips.hot.flags.enabled)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 tz->trips.hot.flags.enabled = 0;
531
Len Brown14e04fb2007-08-23 15:20:26 -0400532 acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
Len Brown4be44fc2005-08-05 00:44:28 -0400533 tz->trips.hot.flags.enabled);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800534 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
535 tz->device->dev.bus_id,
536 ACPI_THERMAL_NOTIFY_HOT,
537 tz->trips.hot.flags.enabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
539 /* TBD: Call user-mode "sleep(S4)" function */
540
Patrick Mocheld550d982006-06-27 00:41:40 -0400541 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542}
543
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400544static void acpi_thermal_passive(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545{
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400546 int result = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 struct acpi_thermal_passive *passive = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400548 int trend = 0;
549 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
552 if (!tz || !tz->trips.passive.flags.valid)
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400553 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
555 passive = &(tz->trips.passive);
556
557 /*
558 * Above Trip?
559 * -----------
560 * Calculate the thermal trend (using the passive cooling equation)
561 * and modify the performance limit for all passive cooling devices
562 * accordingly. Note that we assume symmetry.
563 */
564 if (tz->temperature >= passive->temperature) {
Len Brown4be44fc2005-08-05 00:44:28 -0400565 trend =
566 (passive->tc1 * (tz->temperature - tz->last_temperature)) +
567 (passive->tc2 * (tz->temperature - passive->temperature));
568 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
569 "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
570 trend, passive->tc1, tz->temperature,
571 tz->last_temperature, passive->tc2,
572 tz->temperature, passive->temperature));
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400573 passive->flags.enabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 /* Heating up? */
575 if (trend > 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400576 for (i = 0; i < passive->devices.count; i++)
577 acpi_processor_set_thermal_limit(passive->
578 devices.
579 handles[i],
580 ACPI_PROCESSOR_LIMIT_INCREMENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 /* Cooling off? */
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400582 else if (trend < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400583 for (i = 0; i < passive->devices.count; i++)
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400584 /*
585 * assume that we are on highest
586 * freq/lowest thrott and can leave
587 * passive mode, even in error case
588 */
589 if (!acpi_processor_set_thermal_limit
590 (passive->devices.handles[i],
591 ACPI_PROCESSOR_LIMIT_DECREMENT))
592 result = 0;
593 /*
594 * Leave cooling mode, even if the temp might
595 * higher than trip point This is because some
596 * machines might have long thermal polling
597 * frequencies (tsp) defined. We will fall back
598 * into passive mode in next cycle (probably quicker)
599 */
600 if (result) {
601 passive->flags.enabled = 0;
602 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
603 "Disabling passive cooling, still above threshold,"
604 " but we are cooling down\n"));
605 }
606 }
607 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 }
609
610 /*
611 * Below Trip?
612 * -----------
613 * Implement passive cooling hysteresis to slowly increase performance
614 * and avoid thrashing around the passive trip point. Note that we
615 * assume symmetry.
616 */
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400617 if (!passive->flags.enabled)
618 return;
619 for (i = 0; i < passive->devices.count; i++)
620 if (!acpi_processor_set_thermal_limit
621 (passive->devices.handles[i],
622 ACPI_PROCESSOR_LIMIT_DECREMENT))
623 result = 0;
624 if (result) {
625 passive->flags.enabled = 0;
626 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
627 "Disabling passive cooling (zone is cool)\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629}
630
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400631static void acpi_thermal_active(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632{
Len Brown4be44fc2005-08-05 00:44:28 -0400633 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 struct acpi_thermal_active *active = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400635 int i = 0;
636 int j = 0;
637 unsigned long maxtemp = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
640 if (!tz)
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400641 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Len Brown4be44fc2005-08-05 00:44:28 -0400643 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 active = &(tz->trips.active[i]);
645 if (!active || !active->flags.valid)
646 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 if (tz->temperature >= active->temperature) {
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400648 /*
649 * Above Threshold?
650 * ----------------
651 * If not already enabled, turn ON all cooling devices
652 * associated with this active threshold.
653 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 if (active->temperature > maxtemp)
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400655 tz->state.active_index = i;
656 maxtemp = active->temperature;
657 if (active->flags.enabled)
658 continue;
659 for (j = 0; j < active->devices.count; j++) {
660 result =
661 acpi_bus_set_power(active->devices.
662 handles[j],
663 ACPI_STATE_D0);
664 if (result) {
Len Browncece9292006-06-26 23:04:31 -0400665 printk(KERN_WARNING PREFIX
666 "Unable to turn cooling device [%p] 'on'\n",
Thomas Renningera6fc6722006-06-26 23:58:43 -0400667 active->devices.
Len Browncece9292006-06-26 23:04:31 -0400668 handles[j]);
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400669 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 }
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400671 active->flags.enabled = 1;
672 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
673 "Cooling device [%p] now 'on'\n",
674 active->devices.handles[j]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 }
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400676 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 }
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400678 if (!active->flags.enabled)
679 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 /*
681 * Below Threshold?
682 * ----------------
683 * Turn OFF all cooling devices associated with this
684 * threshold.
685 */
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400686 for (j = 0; j < active->devices.count; j++) {
687 result = acpi_bus_set_power(active->devices.handles[j],
688 ACPI_STATE_D3);
689 if (result) {
Len Browncece9292006-06-26 23:04:31 -0400690 printk(KERN_WARNING PREFIX
691 "Unable to turn cooling device [%p] 'off'\n",
692 active->devices.handles[j]);
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400693 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 }
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400695 active->flags.enabled = 0;
696 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
697 "Cooling device [%p] now 'off'\n",
698 active->devices.handles[j]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 }
700 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701}
702
Len Brown4be44fc2005-08-05 00:44:28 -0400703static void acpi_thermal_check(void *context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Len Brown4be44fc2005-08-05 00:44:28 -0400705static void acpi_thermal_run(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706{
707 struct acpi_thermal *tz = (struct acpi_thermal *)data;
708 if (!tz->zombie)
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400709 acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710}
711
Len Brown4be44fc2005-08-05 00:44:28 -0400712static void acpi_thermal_check(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713{
Len Brown4be44fc2005-08-05 00:44:28 -0400714 int result = 0;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200715 struct acpi_thermal *tz = data;
Len Brown4be44fc2005-08-05 00:44:28 -0400716 unsigned long sleep_time = 0;
Len Brown21bc42a2007-09-04 12:49:22 -0400717 unsigned long timeout_jiffies = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400718 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 struct acpi_thermal_state state;
720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
722 if (!tz) {
Len Brown64684632006-06-26 23:41:38 -0400723 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400724 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 }
726
Alexey Starikovskiy6e215782007-09-01 00:11:59 +0400727 /* Check if someone else is already running */
728 if (!mutex_trylock(&tz->lock))
729 return;
730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 state = tz->state;
732
733 result = acpi_thermal_get_temperature(tz);
734 if (result)
Alexey Starikovskiy6e215782007-09-01 00:11:59 +0400735 goto unlock;
Len Brown4be44fc2005-08-05 00:44:28 -0400736
Zhang Rui3f655ef2008-01-17 15:51:11 +0800737 if (!tz->tz_enabled)
738 goto unlock;
739
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 memset(&tz->state, 0, sizeof(tz->state));
Len Brown4be44fc2005-08-05 00:44:28 -0400741
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 /*
743 * Check Trip Points
744 * -----------------
745 * Compare the current temperature to the trip point values to see
746 * if we've entered one of the thermal policy states. Note that
747 * this function determines when a state is entered, but the
748 * individual policy decides when it is exited (e.g. hysteresis).
749 */
750 if (tz->trips.critical.flags.valid)
Len Brown4be44fc2005-08-05 00:44:28 -0400751 state.critical |=
752 (tz->temperature >= tz->trips.critical.temperature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 if (tz->trips.hot.flags.valid)
754 state.hot |= (tz->temperature >= tz->trips.hot.temperature);
755 if (tz->trips.passive.flags.valid)
Len Brown4be44fc2005-08-05 00:44:28 -0400756 state.passive |=
757 (tz->temperature >= tz->trips.passive.temperature);
758 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 if (tz->trips.active[i].flags.valid)
Len Brown4be44fc2005-08-05 00:44:28 -0400760 state.active |=
761 (tz->temperature >=
762 tz->trips.active[i].temperature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
764 /*
765 * Invoke Policy
766 * -------------
767 * Separated from the above check to allow individual policy to
768 * determine when to exit a given state.
769 */
770 if (state.critical)
771 acpi_thermal_critical(tz);
772 if (state.hot)
773 acpi_thermal_hot(tz);
774 if (state.passive)
775 acpi_thermal_passive(tz);
776 if (state.active)
777 acpi_thermal_active(tz);
778
779 /*
780 * Calculate State
781 * ---------------
782 * Again, separated from the above two to allow independent policy
783 * decisions.
784 */
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400785 tz->state.critical = tz->trips.critical.flags.enabled;
786 tz->state.hot = tz->trips.hot.flags.enabled;
787 tz->state.passive = tz->trips.passive.flags.enabled;
788 tz->state.active = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400789 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400790 tz->state.active |= tz->trips.active[i].flags.enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
792 /*
793 * Calculate Sleep Time
794 * --------------------
795 * If we're in the passive state, use _TSP's value. Otherwise
796 * use the default polling frequency (e.g. _TZP). If no polling
797 * frequency is specified then we'll wait forever (at least until
798 * a thermal event occurs). Note that _TSP and _TZD values are
799 * given in 1/10th seconds (we must covert to milliseconds).
800 */
Len Brown21bc42a2007-09-04 12:49:22 -0400801 if (tz->state.passive) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 sleep_time = tz->trips.passive.tsp * 100;
Len Brown21bc42a2007-09-04 12:49:22 -0400803 timeout_jiffies = jiffies + (HZ * sleep_time) / 1000;
804 } else if (tz->polling_frequency > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 sleep_time = tz->polling_frequency * 100;
Len Brown21bc42a2007-09-04 12:49:22 -0400806 timeout_jiffies = round_jiffies(jiffies + (HZ * sleep_time) / 1000);
807 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Len Brown4be44fc2005-08-05 00:44:28 -0400809 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n",
810 tz->name, tz->temperature, sleep_time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
812 /*
813 * Schedule Next Poll
814 * ------------------
815 */
816 if (!sleep_time) {
817 if (timer_pending(&(tz->timer)))
818 del_timer(&(tz->timer));
Len Brown4be44fc2005-08-05 00:44:28 -0400819 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 if (timer_pending(&(tz->timer)))
Len Brown21bc42a2007-09-04 12:49:22 -0400821 mod_timer(&(tz->timer), timeout_jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400823 tz->timer.data = (unsigned long)tz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 tz->timer.function = acpi_thermal_run;
Len Brown21bc42a2007-09-04 12:49:22 -0400825 tz->timer.expires = timeout_jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 add_timer(&(tz->timer));
827 }
828 }
Alexey Starikovskiy6e215782007-09-01 00:11:59 +0400829 unlock:
830 mutex_unlock(&tz->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831}
832
Zhang Rui3f655ef2008-01-17 15:51:11 +0800833/* sys I/F for generic thermal sysfs support */
834static int thermal_get_temp(struct thermal_zone_device *thermal, char *buf)
835{
836 struct acpi_thermal *tz = thermal->devdata;
837
838 if (!tz)
839 return -EINVAL;
840
841 return sprintf(buf, "%ld\n", KELVIN_TO_CELSIUS(tz->temperature));
842}
843
844static const char enabled[] = "kernel";
845static const char disabled[] = "user";
846static int thermal_get_mode(struct thermal_zone_device *thermal,
847 char *buf)
848{
849 struct acpi_thermal *tz = thermal->devdata;
850
851 if (!tz)
852 return -EINVAL;
853
854 return sprintf(buf, "%s\n", tz->tz_enabled ?
855 enabled : disabled);
856}
857
858static int thermal_set_mode(struct thermal_zone_device *thermal,
859 const char *buf)
860{
861 struct acpi_thermal *tz = thermal->devdata;
862 int enable;
863
864 if (!tz)
865 return -EINVAL;
866
867 /*
868 * enable/disable thermal management from ACPI thermal driver
869 */
870 if (!strncmp(buf, enabled, sizeof enabled - 1))
871 enable = 1;
872 else if (!strncmp(buf, disabled, sizeof disabled - 1))
873 enable = 0;
874 else
875 return -EINVAL;
876
877 if (enable != tz->tz_enabled) {
878 tz->tz_enabled = enable;
879 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
880 "%s ACPI thermal control\n",
881 tz->tz_enabled ? enabled : disabled));
882 acpi_thermal_check(tz);
883 }
884 return 0;
885}
886
887static int thermal_get_trip_type(struct thermal_zone_device *thermal,
888 int trip, char *buf)
889{
890 struct acpi_thermal *tz = thermal->devdata;
891 int i;
892
893 if (!tz || trip < 0)
894 return -EINVAL;
895
896 if (tz->trips.critical.flags.valid) {
897 if (!trip)
898 return sprintf(buf, "critical\n");
899 trip--;
900 }
901
902 if (tz->trips.hot.flags.valid) {
903 if (!trip)
904 return sprintf(buf, "hot\n");
905 trip--;
906 }
907
908 if (tz->trips.passive.flags.valid) {
909 if (!trip)
910 return sprintf(buf, "passive\n");
911 trip--;
912 }
913
914 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
915 tz->trips.active[i].flags.valid; i++) {
916 if (!trip)
917 return sprintf(buf, "active%d\n", i);
918 trip--;
919 }
920
921 return -EINVAL;
922}
923
924static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
925 int trip, char *buf)
926{
927 struct acpi_thermal *tz = thermal->devdata;
928 int i;
929
930 if (!tz || trip < 0)
931 return -EINVAL;
932
933 if (tz->trips.critical.flags.valid) {
934 if (!trip)
935 return sprintf(buf, "%ld\n", KELVIN_TO_CELSIUS(
936 tz->trips.critical.temperature));
937 trip--;
938 }
939
940 if (tz->trips.hot.flags.valid) {
941 if (!trip)
942 return sprintf(buf, "%ld\n", KELVIN_TO_CELSIUS(
943 tz->trips.hot.temperature));
944 trip--;
945 }
946
947 if (tz->trips.passive.flags.valid) {
948 if (!trip)
949 return sprintf(buf, "%ld\n", KELVIN_TO_CELSIUS(
950 tz->trips.passive.temperature));
951 trip--;
952 }
953
954 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
955 tz->trips.active[i].flags.valid; i++) {
956 if (!trip)
957 return sprintf(buf, "%ld\n", KELVIN_TO_CELSIUS(
958 tz->trips.active[i].temperature));
959 trip--;
960 }
961
962 return -EINVAL;
963}
964
965typedef int (*cb)(struct thermal_zone_device *, int,
966 struct thermal_cooling_device *);
967static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
968 struct thermal_cooling_device *cdev,
969 cb action)
970{
971 struct acpi_device *device = cdev->devdata;
972 struct acpi_thermal *tz = thermal->devdata;
973 acpi_handle handle = device->handle;
974 int i;
975 int j;
976 int trip = -1;
977 int result = 0;
978
979 if (tz->trips.critical.flags.valid)
980 trip++;
981
982 if (tz->trips.hot.flags.valid)
983 trip++;
984
985 if (tz->trips.passive.flags.valid) {
986 trip++;
987 for (i = 0; i < tz->trips.passive.devices.count;
988 i++) {
989 if (tz->trips.passive.devices.handles[i] !=
990 handle)
991 continue;
992 result = action(thermal, trip, cdev);
993 if (result)
994 goto failed;
995 }
996 }
997
998 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
999 if (!tz->trips.active[i].flags.valid)
1000 break;
1001 trip++;
1002 for (j = 0;
1003 j < tz->trips.active[i].devices.count;
1004 j++) {
1005 if (tz->trips.active[i].devices.
1006 handles[j] != handle)
1007 continue;
1008 result = action(thermal, trip, cdev);
1009 if (result)
1010 goto failed;
1011 }
1012 }
1013
1014 for (i = 0; i < tz->devices.count; i++) {
1015 if (tz->devices.handles[i] != handle)
1016 continue;
1017 result = action(thermal, -1, cdev);
1018 if (result)
1019 goto failed;
1020 }
1021
1022failed:
1023 return result;
1024}
1025
1026static int
1027acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
1028 struct thermal_cooling_device *cdev)
1029{
1030 return acpi_thermal_cooling_device_cb(thermal, cdev,
1031 thermal_zone_bind_cooling_device);
1032}
1033
1034static int
1035acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
1036 struct thermal_cooling_device *cdev)
1037{
1038 return acpi_thermal_cooling_device_cb(thermal, cdev,
1039 thermal_zone_unbind_cooling_device);
1040}
1041
1042static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
1043 .bind = acpi_thermal_bind_cooling_device,
1044 .unbind = acpi_thermal_unbind_cooling_device,
1045 .get_temp = thermal_get_temp,
1046 .get_mode = thermal_get_mode,
1047 .set_mode = thermal_set_mode,
1048 .get_trip_type = thermal_get_trip_type,
1049 .get_trip_temp = thermal_get_trip_temp,
1050};
1051
1052static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
1053{
1054 int trips = 0;
1055 int result;
1056 int i;
1057
1058 if (tz->trips.critical.flags.valid)
1059 trips++;
1060
1061 if (tz->trips.hot.flags.valid)
1062 trips++;
1063
1064 if (tz->trips.passive.flags.valid)
1065 trips++;
1066
1067 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
1068 tz->trips.active[i].flags.valid; i++, trips++);
1069 tz->thermal_zone = thermal_zone_device_register("ACPI thermal zone",
1070 trips, tz, &acpi_thermal_zone_ops);
1071 if (!tz->thermal_zone)
1072 return -ENODEV;
1073
1074 result = sysfs_create_link(&tz->device->dev.kobj,
1075 &tz->thermal_zone->device.kobj, "thermal_zone");
1076 if (result)
1077 return result;
1078
1079 result = sysfs_create_link(&tz->thermal_zone->device.kobj,
1080 &tz->device->dev.kobj, "device");
1081 if (result)
1082 return result;
1083
1084 tz->tz_enabled = 1;
1085
1086 printk(KERN_INFO PREFIX "%s is registered as thermal_zone%d\n",
1087 tz->device->dev.bus_id, tz->thermal_zone->id);
1088 return 0;
1089}
1090
1091static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
1092{
1093 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
1094 sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
1095 thermal_zone_device_unregister(tz->thermal_zone);
1096 tz->thermal_zone = NULL;
1097}
1098
1099
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100/* --------------------------------------------------------------------------
1101 FS Interface (/proc)
1102 -------------------------------------------------------------------------- */
1103
Len Brown4be44fc2005-08-05 00:44:28 -04001104static struct proc_dir_entry *acpi_thermal_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
1106static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
1107{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001108 struct acpi_thermal *tz = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110
1111 if (!tz)
1112 goto end;
1113
1114 seq_puts(seq, "state: ");
1115
Len Brown4be44fc2005-08-05 00:44:28 -04001116 if (!tz->state.critical && !tz->state.hot && !tz->state.passive
1117 && !tz->state.active)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 seq_puts(seq, "ok\n");
1119 else {
1120 if (tz->state.critical)
1121 seq_puts(seq, "critical ");
1122 if (tz->state.hot)
1123 seq_puts(seq, "hot ");
1124 if (tz->state.passive)
1125 seq_puts(seq, "passive ");
1126 if (tz->state.active)
1127 seq_printf(seq, "active[%d]", tz->state.active_index);
1128 seq_puts(seq, "\n");
1129 }
1130
Len Brown4be44fc2005-08-05 00:44:28 -04001131 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001132 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133}
1134
1135static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
1136{
1137 return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
1138}
1139
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
1141{
Len Brown4be44fc2005-08-05 00:44:28 -04001142 int result = 0;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001143 struct acpi_thermal *tz = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
1146 if (!tz)
1147 goto end;
1148
1149 result = acpi_thermal_get_temperature(tz);
1150 if (result)
1151 goto end;
1152
Len Brown4be44fc2005-08-05 00:44:28 -04001153 seq_printf(seq, "temperature: %ld C\n",
1154 KELVIN_TO_CELSIUS(tz->temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
Len Brown4be44fc2005-08-05 00:44:28 -04001156 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001157 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158}
1159
1160static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
1161{
1162 return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
1163}
1164
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
1166{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001167 struct acpi_thermal *tz = seq->private;
Thomas Renninger68ccfaa2006-11-19 23:01:40 +01001168 struct acpi_device *device;
Thomas Renningere7c746e2007-06-18 00:40:51 -04001169 acpi_status status;
1170
Len Brown4be44fc2005-08-05 00:44:28 -04001171 int i = 0;
1172 int j = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
1175 if (!tz)
1176 goto end;
1177
1178 if (tz->trips.critical.flags.valid)
Len Brownf5487142007-08-12 00:12:44 -04001179 seq_printf(seq, "critical (S5): %ld C%s",
1180 KELVIN_TO_CELSIUS(tz->trips.critical.temperature),
1181 nocrt ? " <disabled>\n" : "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
1183 if (tz->trips.hot.flags.valid)
Len Brownf5487142007-08-12 00:12:44 -04001184 seq_printf(seq, "hot (S4): %ld C%s",
1185 KELVIN_TO_CELSIUS(tz->trips.hot.temperature),
1186 nocrt ? " <disabled>\n" : "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
1188 if (tz->trips.passive.flags.valid) {
Len Brown4be44fc2005-08-05 00:44:28 -04001189 seq_printf(seq,
1190 "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
1191 KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
1192 tz->trips.passive.tc1, tz->trips.passive.tc2,
1193 tz->trips.passive.tsp);
1194 for (j = 0; j < tz->trips.passive.devices.count; j++) {
Thomas Renningere7c746e2007-06-18 00:40:51 -04001195 status = acpi_bus_get_device(tz->trips.passive.devices.
1196 handles[j], &device);
1197 seq_printf(seq, "%4.4s ", status ? "" :
1198 acpi_device_bid(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 }
1200 seq_puts(seq, "\n");
1201 }
1202
1203 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1204 if (!(tz->trips.active[i].flags.valid))
1205 break;
1206 seq_printf(seq, "active[%d]: %ld C: devices=",
Len Brown4be44fc2005-08-05 00:44:28 -04001207 i,
1208 KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
Thomas Renninger68ccfaa2006-11-19 23:01:40 +01001209 for (j = 0; j < tz->trips.active[i].devices.count; j++){
Thomas Renningere7c746e2007-06-18 00:40:51 -04001210 status = acpi_bus_get_device(tz->trips.active[i].
1211 devices.handles[j],
1212 &device);
1213 seq_printf(seq, "%4.4s ", status ? "" :
1214 acpi_device_bid(device));
Thomas Renninger68ccfaa2006-11-19 23:01:40 +01001215 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 seq_puts(seq, "\n");
1217 }
1218
Len Brown4be44fc2005-08-05 00:44:28 -04001219 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001220 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221}
1222
1223static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
1224{
1225 return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
1226}
1227
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
1229{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001230 struct acpi_thermal *tz = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
1233 if (!tz)
1234 goto end;
1235
Len Browneaca2d32007-04-30 23:27:43 -04001236 if (!tz->flags.cooling_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 seq_puts(seq, "<setting not supported>\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 else
Len Browneaca2d32007-04-30 23:27:43 -04001239 seq_puts(seq, "0 - Active; 1 - Passive\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
Len Brown4be44fc2005-08-05 00:44:28 -04001241 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001242 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243}
1244
1245static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
1246{
1247 return single_open(file, acpi_thermal_cooling_seq_show,
Len Brown4be44fc2005-08-05 00:44:28 -04001248 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249}
1250
1251static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001252acpi_thermal_write_cooling_mode(struct file *file,
1253 const char __user * buffer,
1254 size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001256 struct seq_file *m = file->private_data;
1257 struct acpi_thermal *tz = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001258 int result = 0;
1259 char mode_string[12] = { '\0' };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
1262 if (!tz || (count > sizeof(mode_string) - 1))
Patrick Mocheld550d982006-06-27 00:41:40 -04001263 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
1265 if (!tz->flags.cooling_mode)
Patrick Mocheld550d982006-06-27 00:41:40 -04001266 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
1268 if (copy_from_user(mode_string, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001269 return -EFAULT;
Len Brown4be44fc2005-08-05 00:44:28 -04001270
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 mode_string[count] = '\0';
Len Brown4be44fc2005-08-05 00:44:28 -04001272
1273 result = acpi_thermal_set_cooling_mode(tz,
1274 simple_strtoul(mode_string, NULL,
1275 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001277 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
1279 acpi_thermal_check(tz);
1280
Patrick Mocheld550d982006-06-27 00:41:40 -04001281 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282}
1283
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
1285{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001286 struct acpi_thermal *tz = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
1289 if (!tz)
1290 goto end;
1291
1292 if (!tz->polling_frequency) {
1293 seq_puts(seq, "<polling disabled>\n");
1294 goto end;
1295 }
1296
1297 seq_printf(seq, "polling frequency: %lu seconds\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001298 (tz->polling_frequency / 10));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
Len Brown4be44fc2005-08-05 00:44:28 -04001300 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001301 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302}
1303
1304static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
1305{
1306 return single_open(file, acpi_thermal_polling_seq_show,
Len Brown4be44fc2005-08-05 00:44:28 -04001307 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308}
1309
1310static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001311acpi_thermal_write_polling(struct file *file,
1312 const char __user * buffer,
1313 size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001315 struct seq_file *m = file->private_data;
1316 struct acpi_thermal *tz = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001317 int result = 0;
1318 char polling_string[12] = { '\0' };
1319 int seconds = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
1322 if (!tz || (count > sizeof(polling_string) - 1))
Patrick Mocheld550d982006-06-27 00:41:40 -04001323 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -04001324
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 if (copy_from_user(polling_string, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001326 return -EFAULT;
Len Brown4be44fc2005-08-05 00:44:28 -04001327
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 polling_string[count] = '\0';
1329
1330 seconds = simple_strtoul(polling_string, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -04001331
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 result = acpi_thermal_set_polling(tz, seconds);
1333 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001334 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335
1336 acpi_thermal_check(tz);
1337
Patrick Mocheld550d982006-06-27 00:41:40 -04001338 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339}
1340
Len Brown4be44fc2005-08-05 00:44:28 -04001341static int acpi_thermal_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342{
Len Brown4be44fc2005-08-05 00:44:28 -04001343 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
1346 if (!acpi_device_dir(device)) {
1347 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001348 acpi_thermal_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001350 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 acpi_device_dir(device)->owner = THIS_MODULE;
1352 }
1353
1354 /* 'state' [R] */
1355 entry = create_proc_entry(ACPI_THERMAL_FILE_STATE,
Len Brown4be44fc2005-08-05 00:44:28 -04001356 S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001358 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 else {
1360 entry->proc_fops = &acpi_thermal_state_fops;
1361 entry->data = acpi_driver_data(device);
1362 entry->owner = THIS_MODULE;
1363 }
1364
1365 /* 'temperature' [R] */
1366 entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
Len Brown4be44fc2005-08-05 00:44:28 -04001367 S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001369 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 else {
1371 entry->proc_fops = &acpi_thermal_temp_fops;
1372 entry->data = acpi_driver_data(device);
1373 entry->owner = THIS_MODULE;
1374 }
1375
Pavel Machek2db9ccb2007-08-24 11:45:50 +02001376 /* 'trip_points' [R] */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
Pavel Machek2db9ccb2007-08-24 11:45:50 +02001378 S_IRUGO,
Len Brown4be44fc2005-08-05 00:44:28 -04001379 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001381 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 else {
1383 entry->proc_fops = &acpi_thermal_trip_fops;
1384 entry->data = acpi_driver_data(device);
1385 entry->owner = THIS_MODULE;
1386 }
1387
1388 /* 'cooling_mode' [R/W] */
1389 entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
Len Brown4be44fc2005-08-05 00:44:28 -04001390 S_IFREG | S_IRUGO | S_IWUSR,
1391 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001393 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 else {
1395 entry->proc_fops = &acpi_thermal_cooling_fops;
1396 entry->data = acpi_driver_data(device);
1397 entry->owner = THIS_MODULE;
1398 }
1399
1400 /* 'polling_frequency' [R/W] */
1401 entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
Len Brown4be44fc2005-08-05 00:44:28 -04001402 S_IFREG | S_IRUGO | S_IWUSR,
1403 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001405 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 else {
1407 entry->proc_fops = &acpi_thermal_polling_fops;
1408 entry->data = acpi_driver_data(device);
1409 entry->owner = THIS_MODULE;
1410 }
1411
Patrick Mocheld550d982006-06-27 00:41:40 -04001412 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413}
1414
Len Brown4be44fc2005-08-05 00:44:28 -04001415static int acpi_thermal_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
1418 if (acpi_device_dir(device)) {
1419 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1420 acpi_device_dir(device));
1421 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1422 acpi_device_dir(device));
1423 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1424 acpi_device_dir(device));
1425 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1426 acpi_device_dir(device));
1427 remove_proc_entry(ACPI_THERMAL_FILE_STATE,
1428 acpi_device_dir(device));
1429 remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
1430 acpi_device_dir(device) = NULL;
1431 }
1432
Patrick Mocheld550d982006-06-27 00:41:40 -04001433 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434}
1435
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436/* --------------------------------------------------------------------------
1437 Driver Interface
1438 -------------------------------------------------------------------------- */
1439
Len Brown4be44fc2005-08-05 00:44:28 -04001440static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001442 struct acpi_thermal *tz = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001443 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
1446 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -04001447 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Patrick Mochel8348e1b2006-05-19 16:54:40 -04001449 device = tz->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
1451 switch (event) {
1452 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
1453 acpi_thermal_check(tz);
1454 break;
1455 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
1456 acpi_thermal_get_trip_points(tz);
1457 acpi_thermal_check(tz);
Len Brown14e04fb2007-08-23 15:20:26 -04001458 acpi_bus_generate_proc_event(device, event, 0);
Zhang Rui962ce8c2007-08-23 01:24:31 +08001459 acpi_bus_generate_netlink_event(device->pnp.device_class,
1460 device->dev.bus_id, event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 break;
1462 case ACPI_THERMAL_NOTIFY_DEVICES:
1463 if (tz->flags.devices)
1464 acpi_thermal_get_devices(tz);
Len Brown14e04fb2007-08-23 15:20:26 -04001465 acpi_bus_generate_proc_event(device, event, 0);
Zhang Rui962ce8c2007-08-23 01:24:31 +08001466 acpi_bus_generate_netlink_event(device->pnp.device_class,
1467 device->dev.bus_id, event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 break;
1469 default:
1470 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001471 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 break;
1473 }
1474
Patrick Mocheld550d982006-06-27 00:41:40 -04001475 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476}
1477
Len Brown4be44fc2005-08-05 00:44:28 -04001478static int acpi_thermal_get_info(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479{
Len Brown4be44fc2005-08-05 00:44:28 -04001480 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
1483 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -04001484 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485
1486 /* Get temperature [_TMP] (required) */
1487 result = acpi_thermal_get_temperature(tz);
1488 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001489 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
1491 /* Get trip points [_CRT, _PSV, etc.] (required) */
1492 result = acpi_thermal_get_trip_points(tz);
1493 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001494 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495
1496 /* Set the cooling mode [_SCP] to active cooling (default) */
1497 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
Len Brown4be44fc2005-08-05 00:44:28 -04001498 if (!result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 tz->flags.cooling_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
1501 /* Get default polling frequency [_TZP] (optional) */
1502 if (tzp)
1503 tz->polling_frequency = tzp;
1504 else
1505 acpi_thermal_get_polling_frequency(tz);
1506
1507 /* Get devices in this thermal zone [_TZD] (optional) */
1508 result = acpi_thermal_get_devices(tz);
1509 if (!result)
1510 tz->flags.devices = 1;
1511
Patrick Mocheld550d982006-06-27 00:41:40 -04001512 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513}
1514
Len Brown4be44fc2005-08-05 00:44:28 -04001515static int acpi_thermal_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516{
Len Brown4be44fc2005-08-05 00:44:28 -04001517 int result = 0;
1518 acpi_status status = AE_OK;
1519 struct acpi_thermal *tz = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
1522 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001523 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524
Burman Yan36bcbec2006-12-19 12:56:11 -08001525 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -04001527 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
Patrick Mochel8348e1b2006-05-19 16:54:40 -04001529 tz->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 strcpy(tz->name, device->pnp.bus_id);
1531 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1532 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
1533 acpi_driver_data(device) = tz;
Alexey Starikovskiy6e215782007-09-01 00:11:59 +04001534 mutex_init(&tz->lock);
Zhang Rui3f655ef2008-01-17 15:51:11 +08001535
1536
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 result = acpi_thermal_get_info(tz);
1538 if (result)
Zhang Rui3f655ef2008-01-17 15:51:11 +08001539 goto free_memory;
1540
1541 result = acpi_thermal_register_thermal_zone(tz);
1542 if (result)
1543 goto free_memory;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544
1545 result = acpi_thermal_add_fs(device);
1546 if (result)
Zhang Rui3f655ef2008-01-17 15:51:11 +08001547 goto unregister_thermal_zone;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
1549 init_timer(&tz->timer);
1550
1551 acpi_thermal_check(tz);
1552
Patrick Mochel38ba7c92006-05-19 16:54:48 -04001553 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001554 ACPI_DEVICE_NOTIFY,
1555 acpi_thermal_notify, tz);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 result = -ENODEV;
Zhang Rui3f655ef2008-01-17 15:51:11 +08001558 goto remove_fs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 }
1560
1561 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001562 acpi_device_name(device), acpi_device_bid(device),
1563 KELVIN_TO_CELSIUS(tz->temperature));
Zhang Rui3f655ef2008-01-17 15:51:11 +08001564 goto end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
Zhang Rui3f655ef2008-01-17 15:51:11 +08001566remove_fs:
1567 acpi_thermal_remove_fs(device);
1568unregister_thermal_zone:
1569 thermal_zone_device_unregister(tz->thermal_zone);
1570free_memory:
1571 kfree(tz);
1572end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001573 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574}
1575
Len Brown4be44fc2005-08-05 00:44:28 -04001576static int acpi_thermal_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577{
Len Brown4be44fc2005-08-05 00:44:28 -04001578 acpi_status status = AE_OK;
1579 struct acpi_thermal *tz = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
1582 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001583 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001585 tz = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586
1587 /* avoid timer adding new defer task */
1588 tz->zombie = 1;
1589 /* wait for running timer (on other CPUs) finish */
1590 del_timer_sync(&(tz->timer));
1591 /* synchronize deferred task */
1592 acpi_os_wait_events_complete(NULL);
1593 /* deferred task may reinsert timer */
1594 del_timer_sync(&(tz->timer));
1595
Patrick Mochel38ba7c92006-05-19 16:54:48 -04001596 status = acpi_remove_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001597 ACPI_DEVICE_NOTIFY,
1598 acpi_thermal_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
1600 /* Terminate policy */
Len Brown4be44fc2005-08-05 00:44:28 -04001601 if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 tz->trips.passive.flags.enabled = 0;
1603 acpi_thermal_passive(tz);
1604 }
1605 if (tz->trips.active[0].flags.valid
Len Brown4be44fc2005-08-05 00:44:28 -04001606 && tz->trips.active[0].flags.enabled) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 tz->trips.active[0].flags.enabled = 0;
1608 acpi_thermal_active(tz);
1609 }
1610
1611 acpi_thermal_remove_fs(device);
Zhang Rui3f655ef2008-01-17 15:51:11 +08001612 acpi_thermal_unregister_thermal_zone(tz);
Alexey Starikovskiy6e215782007-09-01 00:11:59 +04001613 mutex_destroy(&tz->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 kfree(tz);
Patrick Mocheld550d982006-06-27 00:41:40 -04001615 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616}
1617
Patrick Mochel5d9464a2006-12-07 20:56:27 +08001618static int acpi_thermal_resume(struct acpi_device *device)
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001619{
1620 struct acpi_thermal *tz = NULL;
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001621 int i, j, power_state, result;
1622
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001623
1624 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001625 return -EINVAL;
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001626
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001627 tz = acpi_driver_data(device);
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001628
Konstantin Karasyovbed936f2006-07-10 04:44:26 -07001629 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001630 if (!(&tz->trips.active[i]))
1631 break;
1632 if (!tz->trips.active[i].flags.valid)
1633 break;
1634 tz->trips.active[i].flags.enabled = 1;
1635 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1636 result = acpi_bus_get_power(tz->trips.active[i].devices.
1637 handles[j], &power_state);
1638 if (result || (power_state != ACPI_STATE_D0)) {
1639 tz->trips.active[i].flags.enabled = 0;
1640 break;
1641 }
Konstantin Karasyovbed936f2006-07-10 04:44:26 -07001642 }
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001643 tz->state.active |= tz->trips.active[i].flags.enabled;
Konstantin Karasyovbed936f2006-07-10 04:44:26 -07001644 }
1645
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001646 acpi_thermal_check(tz);
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001647
1648 return AE_OK;
1649}
1650
Len Brown0b5bfa12007-08-12 00:13:02 -04001651#ifdef CONFIG_DMI
Jeff Garzik18552562007-10-03 15:15:40 -04001652static int thermal_act(const struct dmi_system_id *d) {
Len Brown0b5bfa12007-08-12 00:13:02 -04001653
1654 if (act == 0) {
1655 printk(KERN_NOTICE "ACPI: %s detected: "
1656 "disabling all active thermal trip points\n", d->ident);
1657 act = -1;
1658 }
1659 return 0;
1660}
Jeff Garzik18552562007-10-03 15:15:40 -04001661static int thermal_nocrt(const struct dmi_system_id *d) {
Len Brown8c99fdc2007-08-20 18:46:50 -04001662
1663 printk(KERN_NOTICE "ACPI: %s detected: "
1664 "disabling all critical thermal trip point actions.\n", d->ident);
1665 nocrt = 1;
1666 return 0;
1667}
Jeff Garzik18552562007-10-03 15:15:40 -04001668static int thermal_tzp(const struct dmi_system_id *d) {
Len Brown0b5bfa12007-08-12 00:13:02 -04001669
1670 if (tzp == 0) {
1671 printk(KERN_NOTICE "ACPI: %s detected: "
1672 "enabling thermal zone polling\n", d->ident);
1673 tzp = 300; /* 300 dS = 30 Seconds */
1674 }
1675 return 0;
1676}
Jeff Garzik18552562007-10-03 15:15:40 -04001677static int thermal_psv(const struct dmi_system_id *d) {
Len Brown0b5bfa12007-08-12 00:13:02 -04001678
1679 if (psv == 0) {
1680 printk(KERN_NOTICE "ACPI: %s detected: "
1681 "disabling all passive thermal trip points\n", d->ident);
1682 psv = -1;
1683 }
1684 return 0;
1685}
1686
1687static struct dmi_system_id thermal_dmi_table[] __initdata = {
1688 /*
1689 * Award BIOS on this AOpen makes thermal control almost worthless.
1690 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1691 */
1692 {
1693 .callback = thermal_act,
1694 .ident = "AOpen i915GMm-HFS",
1695 .matches = {
1696 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1697 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1698 },
1699 },
1700 {
1701 .callback = thermal_psv,
1702 .ident = "AOpen i915GMm-HFS",
1703 .matches = {
1704 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1705 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1706 },
1707 },
1708 {
1709 .callback = thermal_tzp,
1710 .ident = "AOpen i915GMm-HFS",
1711 .matches = {
1712 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1713 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1714 },
1715 },
Len Brown8c99fdc2007-08-20 18:46:50 -04001716 {
1717 .callback = thermal_nocrt,
1718 .ident = "Gigabyte GA-7ZX",
1719 .matches = {
1720 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
1721 DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
1722 },
1723 },
Len Brown0b5bfa12007-08-12 00:13:02 -04001724 {}
1725};
1726#endif /* CONFIG_DMI */
1727
Len Brown4be44fc2005-08-05 00:44:28 -04001728static int __init acpi_thermal_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729{
Len Brown4be44fc2005-08-05 00:44:28 -04001730 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
Len Brown0b5bfa12007-08-12 00:13:02 -04001732 dmi_check_system(thermal_dmi_table);
1733
Len Brown72b33ef2007-08-12 00:12:17 -04001734 if (off) {
1735 printk(KERN_NOTICE "ACPI: thermal control disabled\n");
1736 return -ENODEV;
1737 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
1739 if (!acpi_thermal_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001740 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 acpi_thermal_dir->owner = THIS_MODULE;
1742
1743 result = acpi_bus_register_driver(&acpi_thermal_driver);
1744 if (result < 0) {
1745 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04001746 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 }
1748
Patrick Mocheld550d982006-06-27 00:41:40 -04001749 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750}
1751
Len Brown4be44fc2005-08-05 00:44:28 -04001752static void __exit acpi_thermal_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
1755 acpi_bus_unregister_driver(&acpi_thermal_driver);
1756
1757 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1758
Patrick Mocheld550d982006-06-27 00:41:40 -04001759 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760}
1761
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762module_init(acpi_thermal_init);
1763module_exit(acpi_thermal_exit);