blob: ad898e10c1a91162b42a18827678de93744a7a09 [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>
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"
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198};
199
Arjan van de Vend7508032006-07-04 13:06:00 -0400200static const struct file_operations acpi_thermal_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400201 .open = acpi_thermal_state_open_fs,
202 .read = seq_read,
203 .llseek = seq_lseek,
204 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205};
206
Arjan van de Vend7508032006-07-04 13:06:00 -0400207static const struct file_operations acpi_thermal_temp_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400208 .open = acpi_thermal_temp_open_fs,
209 .read = seq_read,
210 .llseek = seq_lseek,
211 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212};
213
Arjan van de Vend7508032006-07-04 13:06:00 -0400214static const struct file_operations acpi_thermal_trip_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400215 .open = acpi_thermal_trip_open_fs,
216 .read = seq_read,
Len Brown4be44fc2005-08-05 00:44:28 -0400217 .llseek = seq_lseek,
218 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219};
220
Arjan van de Vend7508032006-07-04 13:06:00 -0400221static const struct file_operations acpi_thermal_cooling_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400222 .open = acpi_thermal_cooling_open_fs,
223 .read = seq_read,
224 .write = acpi_thermal_write_cooling_mode,
225 .llseek = seq_lseek,
226 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227};
228
Arjan van de Vend7508032006-07-04 13:06:00 -0400229static const struct file_operations acpi_thermal_polling_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400230 .open = acpi_thermal_polling_open_fs,
231 .read = seq_read,
232 .write = acpi_thermal_write_polling,
233 .llseek = seq_lseek,
234 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235};
236
237/* --------------------------------------------------------------------------
238 Thermal Zone Management
239 -------------------------------------------------------------------------- */
240
Len Brown4be44fc2005-08-05 00:44:28 -0400241static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
Len Brown4be44fc2005-08-05 00:44:28 -0400243 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
246 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400247 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 tz->last_temperature = tz->temperature;
250
Len Brown4be44fc2005-08-05 00:44:28 -0400251 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400252 acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tz->temperature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400254 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Len Brown4be44fc2005-08-05 00:44:28 -0400256 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
257 tz->temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Patrick Mocheld550d982006-06-27 00:41:40 -0400259 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260}
261
Len Brown4be44fc2005-08-05 00:44:28 -0400262static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
Len Brown4be44fc2005-08-05 00:44:28 -0400264 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400268 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Len Brown4be44fc2005-08-05 00:44:28 -0400270 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400271 acpi_evaluate_integer(tz->device->handle, "_TZP", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400272 &tz->polling_frequency);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400274 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Len Brown4be44fc2005-08-05 00:44:28 -0400276 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
277 tz->polling_frequency));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Patrick Mocheld550d982006-06-27 00:41:40 -0400279 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280}
281
Len Brown4be44fc2005-08-05 00:44:28 -0400282static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400286 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
289
Len Brown4be44fc2005-08-05 00:44:28 -0400290 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
291 "Polling frequency set to %lu seconds\n",
Sanjoy Mahajan636cedf2007-02-16 01:24:43 -0500292 tz->polling_frequency/10));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Patrick Mocheld550d982006-06-27 00:41:40 -0400294 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295}
296
Len Brown4be44fc2005-08-05 00:44:28 -0400297static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298{
Len Brown4be44fc2005-08-05 00:44:28 -0400299 acpi_status status = AE_OK;
300 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
301 struct acpi_object_list arg_list = { 1, &arg0 };
302 acpi_handle handle = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
305 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400306 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400308 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 if (ACPI_FAILURE(status)) {
310 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400311 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 }
313
314 arg0.integer.value = mode;
315
316 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
317 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400318 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Patrick Mocheld550d982006-06-27 00:41:40 -0400320 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321}
322
Len Brown4be44fc2005-08-05 00:44:28 -0400323static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
Len Brown4be44fc2005-08-05 00:44:28 -0400325 acpi_status status = AE_OK;
326 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400330 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
332 /* Critical Shutdown (required) */
333
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400334 status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400335 &tz->trips.critical.temperature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 if (ACPI_FAILURE(status)) {
337 tz->trips.critical.flags.valid = 0;
Thomas Renningera6fc6722006-06-26 23:58:43 -0400338 ACPI_EXCEPTION((AE_INFO, status, "No critical threshold"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400339 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400340 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 tz->trips.critical.flags.valid = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400342 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
343 "Found critical threshold [%lu]\n",
344 tz->trips.critical.temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 }
346
Len Brownc52a7412007-08-14 15:49:32 -0400347 if (tz->trips.critical.flags.valid == 1) {
348 if (crt == -1) {
349 tz->trips.critical.flags.valid = 0;
350 } else if (crt > 0) {
351 unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
352
353 /*
354 * Allow override to lower critical threshold
355 */
356 if (crt_k < tz->trips.critical.temperature)
357 tz->trips.critical.temperature = crt_k;
358 }
359 }
360
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 /* Critical Sleep (optional) */
362
Len Brown4be44fc2005-08-05 00:44:28 -0400363 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400364 acpi_evaluate_integer(tz->device->handle, "_HOT", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400365 &tz->trips.hot.temperature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 if (ACPI_FAILURE(status)) {
367 tz->trips.hot.flags.valid = 0;
368 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No hot threshold\n"));
Len Brown4be44fc2005-08-05 00:44:28 -0400369 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 tz->trips.hot.flags.valid = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400371 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found hot threshold [%lu]\n",
372 tz->trips.hot.temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 }
374
375 /* Passive: Processors (optional) */
376
Len Browna70cdc52007-08-12 00:12:35 -0400377 if (psv == -1) {
378 status = AE_SUPPORT;
379 } else if (psv > 0) {
380 tz->trips.passive.temperature = CELSIUS_TO_KELVIN(psv);
381 status = AE_OK;
382 } else {
383 status = acpi_evaluate_integer(tz->device->handle,
384 "_PSV", NULL, &tz->trips.passive.temperature);
385 }
386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 if (ACPI_FAILURE(status)) {
388 tz->trips.passive.flags.valid = 0;
389 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No passive threshold\n"));
Len Brown4be44fc2005-08-05 00:44:28 -0400390 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 tz->trips.passive.flags.valid = 1;
392
Len Brown4be44fc2005-08-05 00:44:28 -0400393 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400394 acpi_evaluate_integer(tz->device->handle, "_TC1", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400395 &tz->trips.passive.tc1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 if (ACPI_FAILURE(status))
397 tz->trips.passive.flags.valid = 0;
398
Len Brown4be44fc2005-08-05 00:44:28 -0400399 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400400 acpi_evaluate_integer(tz->device->handle, "_TC2", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400401 &tz->trips.passive.tc2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 if (ACPI_FAILURE(status))
403 tz->trips.passive.flags.valid = 0;
404
Len Brown4be44fc2005-08-05 00:44:28 -0400405 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400406 acpi_evaluate_integer(tz->device->handle, "_TSP", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400407 &tz->trips.passive.tsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 if (ACPI_FAILURE(status))
409 tz->trips.passive.flags.valid = 0;
410
Len Brown4be44fc2005-08-05 00:44:28 -0400411 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400412 acpi_evaluate_reference(tz->device->handle, "_PSL", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400413 &tz->trips.passive.devices);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 if (ACPI_FAILURE(status))
415 tz->trips.passive.flags.valid = 0;
416
417 if (!tz->trips.passive.flags.valid)
Len Browncece9292006-06-26 23:04:31 -0400418 printk(KERN_WARNING PREFIX "Invalid passive threshold\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 else
Len Brown4be44fc2005-08-05 00:44:28 -0400420 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
421 "Found passive threshold [%lu]\n",
422 tz->trips.passive.temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 }
424
425 /* Active: Fans, etc. (optional) */
426
Len Brown4be44fc2005-08-05 00:44:28 -0400427 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Len Brown4be44fc2005-08-05 00:44:28 -0400429 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
Len Brownf8707ec2007-08-12 00:12:54 -0400431 if (act == -1)
432 break; /* disable all active trip points */
433
434 status = acpi_evaluate_integer(tz->device->handle,
435 name, NULL, &tz->trips.active[i].temperature);
436
437 if (ACPI_FAILURE(status)) {
438 if (i == 0) /* no active trip points */
439 break;
440 if (act <= 0) /* no override requested */
441 break;
442 if (i == 1) { /* 1 trip point */
443 tz->trips.active[0].temperature =
444 CELSIUS_TO_KELVIN(act);
445 } else { /* multiple trips */
446 /*
447 * Don't allow override higher than
448 * the next higher trip point
449 */
450 tz->trips.active[i - 1].temperature =
451 (tz->trips.active[i - 2].temperature <
452 CELSIUS_TO_KELVIN(act) ?
453 tz->trips.active[i - 2].temperature :
454 CELSIUS_TO_KELVIN(act));
455 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 break;
Len Brownf8707ec2007-08-12 00:12:54 -0400457 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
459 name[2] = 'L';
Len Brown4be44fc2005-08-05 00:44:28 -0400460 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400461 acpi_evaluate_reference(tz->device->handle, name, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400462 &tz->trips.active[i].devices);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 if (ACPI_SUCCESS(status)) {
464 tz->trips.active[i].flags.valid = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400465 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
466 "Found active threshold [%d]:[%lu]\n",
467 i, tz->trips.active[i].temperature));
468 } else
Thomas Renningera6fc6722006-06-26 23:58:43 -0400469 ACPI_EXCEPTION((AE_INFO, status,
470 "Invalid active threshold [%d]", i));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 }
472
Patrick Mocheld550d982006-06-27 00:41:40 -0400473 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474}
475
Len Brown4be44fc2005-08-05 00:44:28 -0400476static int acpi_thermal_get_devices(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
Len Brown4be44fc2005-08-05 00:44:28 -0400478 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
481 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400482 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Len Brown4be44fc2005-08-05 00:44:28 -0400484 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400485 acpi_evaluate_reference(tz->device->handle, "_TZD", NULL, &tz->devices);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400487 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Patrick Mocheld550d982006-06-27 00:41:40 -0400489 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490}
491
Len Brown4be44fc2005-08-05 00:44:28 -0400492static int acpi_thermal_critical(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
Len Brownf5487142007-08-12 00:12:44 -0400494 if (!tz || !tz->trips.critical.flags.valid || nocrt)
Patrick Mocheld550d982006-06-27 00:41:40 -0400495 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
497 if (tz->temperature >= tz->trips.critical.temperature) {
Len Browncece9292006-06-26 23:04:31 -0400498 printk(KERN_WARNING PREFIX "Critical trip point\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 tz->trips.critical.flags.enabled = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400500 } else if (tz->trips.critical.flags.enabled)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 tz->trips.critical.flags.enabled = 0;
502
Len Brown4be44fc2005-08-05 00:44:28 -0400503 printk(KERN_EMERG
504 "Critical temperature reached (%ld C), shutting down.\n",
505 KELVIN_TO_CELSIUS(tz->temperature));
Len Brown14e04fb2007-08-23 15:20:26 -0400506 acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL,
Len Brown4be44fc2005-08-05 00:44:28 -0400507 tz->trips.critical.flags.enabled);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800508 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
509 tz->device->dev.bus_id,
510 ACPI_THERMAL_NOTIFY_CRITICAL,
511 tz->trips.critical.flags.enabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700513 orderly_poweroff(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Patrick Mocheld550d982006-06-27 00:41:40 -0400515 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516}
517
Len Brown4be44fc2005-08-05 00:44:28 -0400518static int acpi_thermal_hot(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519{
Len Brownf5487142007-08-12 00:12:44 -0400520 if (!tz || !tz->trips.hot.flags.valid || nocrt)
Patrick Mocheld550d982006-06-27 00:41:40 -0400521 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
523 if (tz->temperature >= tz->trips.hot.temperature) {
Len Browncece9292006-06-26 23:04:31 -0400524 printk(KERN_WARNING PREFIX "Hot trip point\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 tz->trips.hot.flags.enabled = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400526 } else if (tz->trips.hot.flags.enabled)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 tz->trips.hot.flags.enabled = 0;
528
Len Brown14e04fb2007-08-23 15:20:26 -0400529 acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
Len Brown4be44fc2005-08-05 00:44:28 -0400530 tz->trips.hot.flags.enabled);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800531 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
532 tz->device->dev.bus_id,
533 ACPI_THERMAL_NOTIFY_HOT,
534 tz->trips.hot.flags.enabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536 /* TBD: Call user-mode "sleep(S4)" function */
537
Patrick Mocheld550d982006-06-27 00:41:40 -0400538 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539}
540
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400541static void acpi_thermal_passive(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542{
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400543 int result = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 struct acpi_thermal_passive *passive = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400545 int trend = 0;
546 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
549 if (!tz || !tz->trips.passive.flags.valid)
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400550 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
552 passive = &(tz->trips.passive);
553
554 /*
555 * Above Trip?
556 * -----------
557 * Calculate the thermal trend (using the passive cooling equation)
558 * and modify the performance limit for all passive cooling devices
559 * accordingly. Note that we assume symmetry.
560 */
561 if (tz->temperature >= passive->temperature) {
Len Brown4be44fc2005-08-05 00:44:28 -0400562 trend =
563 (passive->tc1 * (tz->temperature - tz->last_temperature)) +
564 (passive->tc2 * (tz->temperature - passive->temperature));
565 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
566 "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
567 trend, passive->tc1, tz->temperature,
568 tz->last_temperature, passive->tc2,
569 tz->temperature, passive->temperature));
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400570 passive->flags.enabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 /* Heating up? */
572 if (trend > 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400573 for (i = 0; i < passive->devices.count; i++)
574 acpi_processor_set_thermal_limit(passive->
575 devices.
576 handles[i],
577 ACPI_PROCESSOR_LIMIT_INCREMENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 /* Cooling off? */
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400579 else if (trend < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400580 for (i = 0; i < passive->devices.count; i++)
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400581 /*
582 * assume that we are on highest
583 * freq/lowest thrott and can leave
584 * passive mode, even in error case
585 */
586 if (!acpi_processor_set_thermal_limit
587 (passive->devices.handles[i],
588 ACPI_PROCESSOR_LIMIT_DECREMENT))
589 result = 0;
590 /*
591 * Leave cooling mode, even if the temp might
592 * higher than trip point This is because some
593 * machines might have long thermal polling
594 * frequencies (tsp) defined. We will fall back
595 * into passive mode in next cycle (probably quicker)
596 */
597 if (result) {
598 passive->flags.enabled = 0;
599 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
600 "Disabling passive cooling, still above threshold,"
601 " but we are cooling down\n"));
602 }
603 }
604 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 }
606
607 /*
608 * Below Trip?
609 * -----------
610 * Implement passive cooling hysteresis to slowly increase performance
611 * and avoid thrashing around the passive trip point. Note that we
612 * assume symmetry.
613 */
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400614 if (!passive->flags.enabled)
615 return;
616 for (i = 0; i < passive->devices.count; i++)
617 if (!acpi_processor_set_thermal_limit
618 (passive->devices.handles[i],
619 ACPI_PROCESSOR_LIMIT_DECREMENT))
620 result = 0;
621 if (result) {
622 passive->flags.enabled = 0;
623 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
624 "Disabling passive cooling (zone is cool)\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626}
627
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400628static void acpi_thermal_active(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629{
Len Brown4be44fc2005-08-05 00:44:28 -0400630 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 struct acpi_thermal_active *active = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400632 int i = 0;
633 int j = 0;
634 unsigned long maxtemp = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
637 if (!tz)
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400638 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
Len Brown4be44fc2005-08-05 00:44:28 -0400640 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 active = &(tz->trips.active[i]);
642 if (!active || !active->flags.valid)
643 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 if (tz->temperature >= active->temperature) {
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400645 /*
646 * Above Threshold?
647 * ----------------
648 * If not already enabled, turn ON all cooling devices
649 * associated with this active threshold.
650 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 if (active->temperature > maxtemp)
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400652 tz->state.active_index = i;
653 maxtemp = active->temperature;
654 if (active->flags.enabled)
655 continue;
656 for (j = 0; j < active->devices.count; j++) {
657 result =
658 acpi_bus_set_power(active->devices.
659 handles[j],
660 ACPI_STATE_D0);
661 if (result) {
Len Browncece9292006-06-26 23:04:31 -0400662 printk(KERN_WARNING PREFIX
663 "Unable to turn cooling device [%p] 'on'\n",
Thomas Renningera6fc6722006-06-26 23:58:43 -0400664 active->devices.
Len Browncece9292006-06-26 23:04:31 -0400665 handles[j]);
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400666 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 }
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400668 active->flags.enabled = 1;
669 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
670 "Cooling device [%p] now 'on'\n",
671 active->devices.handles[j]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 }
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400673 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 }
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400675 if (!active->flags.enabled)
676 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 /*
678 * Below Threshold?
679 * ----------------
680 * Turn OFF all cooling devices associated with this
681 * threshold.
682 */
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400683 for (j = 0; j < active->devices.count; j++) {
684 result = acpi_bus_set_power(active->devices.handles[j],
685 ACPI_STATE_D3);
686 if (result) {
Len Browncece9292006-06-26 23:04:31 -0400687 printk(KERN_WARNING PREFIX
688 "Unable to turn cooling device [%p] 'off'\n",
689 active->devices.handles[j]);
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400690 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 }
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400692 active->flags.enabled = 0;
693 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
694 "Cooling device [%p] now 'off'\n",
695 active->devices.handles[j]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 }
697 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698}
699
Len Brown4be44fc2005-08-05 00:44:28 -0400700static void acpi_thermal_check(void *context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
Len Brown4be44fc2005-08-05 00:44:28 -0400702static void acpi_thermal_run(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703{
704 struct acpi_thermal *tz = (struct acpi_thermal *)data;
705 if (!tz->zombie)
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400706 acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707}
708
Len Brown4be44fc2005-08-05 00:44:28 -0400709static void acpi_thermal_check(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710{
Len Brown4be44fc2005-08-05 00:44:28 -0400711 int result = 0;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200712 struct acpi_thermal *tz = data;
Len Brown4be44fc2005-08-05 00:44:28 -0400713 unsigned long sleep_time = 0;
714 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 struct acpi_thermal_state state;
716
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
718 if (!tz) {
Len Brown64684632006-06-26 23:41:38 -0400719 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400720 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 }
722
723 state = tz->state;
724
725 result = acpi_thermal_get_temperature(tz);
726 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400727 return;
Len Brown4be44fc2005-08-05 00:44:28 -0400728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 memset(&tz->state, 0, sizeof(tz->state));
Len Brown4be44fc2005-08-05 00:44:28 -0400730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 /*
732 * Check Trip Points
733 * -----------------
734 * Compare the current temperature to the trip point values to see
735 * if we've entered one of the thermal policy states. Note that
736 * this function determines when a state is entered, but the
737 * individual policy decides when it is exited (e.g. hysteresis).
738 */
739 if (tz->trips.critical.flags.valid)
Len Brown4be44fc2005-08-05 00:44:28 -0400740 state.critical |=
741 (tz->temperature >= tz->trips.critical.temperature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 if (tz->trips.hot.flags.valid)
743 state.hot |= (tz->temperature >= tz->trips.hot.temperature);
744 if (tz->trips.passive.flags.valid)
Len Brown4be44fc2005-08-05 00:44:28 -0400745 state.passive |=
746 (tz->temperature >= tz->trips.passive.temperature);
747 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 if (tz->trips.active[i].flags.valid)
Len Brown4be44fc2005-08-05 00:44:28 -0400749 state.active |=
750 (tz->temperature >=
751 tz->trips.active[i].temperature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
753 /*
754 * Invoke Policy
755 * -------------
756 * Separated from the above check to allow individual policy to
757 * determine when to exit a given state.
758 */
759 if (state.critical)
760 acpi_thermal_critical(tz);
761 if (state.hot)
762 acpi_thermal_hot(tz);
763 if (state.passive)
764 acpi_thermal_passive(tz);
765 if (state.active)
766 acpi_thermal_active(tz);
767
768 /*
769 * Calculate State
770 * ---------------
771 * Again, separated from the above two to allow independent policy
772 * decisions.
773 */
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400774 tz->state.critical = tz->trips.critical.flags.enabled;
775 tz->state.hot = tz->trips.hot.flags.enabled;
776 tz->state.passive = tz->trips.passive.flags.enabled;
777 tz->state.active = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400778 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400779 tz->state.active |= tz->trips.active[i].flags.enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
781 /*
782 * Calculate Sleep Time
783 * --------------------
784 * If we're in the passive state, use _TSP's value. Otherwise
785 * use the default polling frequency (e.g. _TZP). If no polling
786 * frequency is specified then we'll wait forever (at least until
787 * a thermal event occurs). Note that _TSP and _TZD values are
788 * given in 1/10th seconds (we must covert to milliseconds).
789 */
790 if (tz->state.passive)
791 sleep_time = tz->trips.passive.tsp * 100;
792 else if (tz->polling_frequency > 0)
793 sleep_time = tz->polling_frequency * 100;
794
Len Brown4be44fc2005-08-05 00:44:28 -0400795 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n",
796 tz->name, tz->temperature, sleep_time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
798 /*
799 * Schedule Next Poll
800 * ------------------
801 */
802 if (!sleep_time) {
803 if (timer_pending(&(tz->timer)))
804 del_timer(&(tz->timer));
Len Brown4be44fc2005-08-05 00:44:28 -0400805 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 if (timer_pending(&(tz->timer)))
Andrew Morton94e22e12007-04-23 14:41:13 -0700807 mod_timer(&(tz->timer),
808 jiffies + (HZ * sleep_time) / 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400810 tz->timer.data = (unsigned long)tz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 tz->timer.function = acpi_thermal_run;
812 tz->timer.expires = jiffies + (HZ * sleep_time) / 1000;
813 add_timer(&(tz->timer));
814 }
815 }
816
Patrick Mocheld550d982006-06-27 00:41:40 -0400817 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818}
819
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820/* --------------------------------------------------------------------------
821 FS Interface (/proc)
822 -------------------------------------------------------------------------- */
823
Len Brown4be44fc2005-08-05 00:44:28 -0400824static struct proc_dir_entry *acpi_thermal_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
827{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200828 struct acpi_thermal *tz = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
831 if (!tz)
832 goto end;
833
834 seq_puts(seq, "state: ");
835
Len Brown4be44fc2005-08-05 00:44:28 -0400836 if (!tz->state.critical && !tz->state.hot && !tz->state.passive
837 && !tz->state.active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 seq_puts(seq, "ok\n");
839 else {
840 if (tz->state.critical)
841 seq_puts(seq, "critical ");
842 if (tz->state.hot)
843 seq_puts(seq, "hot ");
844 if (tz->state.passive)
845 seq_puts(seq, "passive ");
846 if (tz->state.active)
847 seq_printf(seq, "active[%d]", tz->state.active_index);
848 seq_puts(seq, "\n");
849 }
850
Len Brown4be44fc2005-08-05 00:44:28 -0400851 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400852 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853}
854
855static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
856{
857 return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
858}
859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
861{
Len Brown4be44fc2005-08-05 00:44:28 -0400862 int result = 0;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200863 struct acpi_thermal *tz = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
866 if (!tz)
867 goto end;
868
869 result = acpi_thermal_get_temperature(tz);
870 if (result)
871 goto end;
872
Len Brown4be44fc2005-08-05 00:44:28 -0400873 seq_printf(seq, "temperature: %ld C\n",
874 KELVIN_TO_CELSIUS(tz->temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Len Brown4be44fc2005-08-05 00:44:28 -0400876 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400877 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878}
879
880static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
881{
882 return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
883}
884
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
886{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200887 struct acpi_thermal *tz = seq->private;
Thomas Renninger68ccfaa2006-11-19 23:01:40 +0100888 struct acpi_device *device;
Thomas Renningere7c746e2007-06-18 00:40:51 -0400889 acpi_status status;
890
Len Brown4be44fc2005-08-05 00:44:28 -0400891 int i = 0;
892 int j = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
895 if (!tz)
896 goto end;
897
898 if (tz->trips.critical.flags.valid)
Len Brownf5487142007-08-12 00:12:44 -0400899 seq_printf(seq, "critical (S5): %ld C%s",
900 KELVIN_TO_CELSIUS(tz->trips.critical.temperature),
901 nocrt ? " <disabled>\n" : "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
903 if (tz->trips.hot.flags.valid)
Len Brownf5487142007-08-12 00:12:44 -0400904 seq_printf(seq, "hot (S4): %ld C%s",
905 KELVIN_TO_CELSIUS(tz->trips.hot.temperature),
906 nocrt ? " <disabled>\n" : "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
908 if (tz->trips.passive.flags.valid) {
Len Brown4be44fc2005-08-05 00:44:28 -0400909 seq_printf(seq,
910 "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
911 KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
912 tz->trips.passive.tc1, tz->trips.passive.tc2,
913 tz->trips.passive.tsp);
914 for (j = 0; j < tz->trips.passive.devices.count; j++) {
Thomas Renningere7c746e2007-06-18 00:40:51 -0400915 status = acpi_bus_get_device(tz->trips.passive.devices.
916 handles[j], &device);
917 seq_printf(seq, "%4.4s ", status ? "" :
918 acpi_device_bid(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 }
920 seq_puts(seq, "\n");
921 }
922
923 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
924 if (!(tz->trips.active[i].flags.valid))
925 break;
926 seq_printf(seq, "active[%d]: %ld C: devices=",
Len Brown4be44fc2005-08-05 00:44:28 -0400927 i,
928 KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
Thomas Renninger68ccfaa2006-11-19 23:01:40 +0100929 for (j = 0; j < tz->trips.active[i].devices.count; j++){
Thomas Renningere7c746e2007-06-18 00:40:51 -0400930 status = acpi_bus_get_device(tz->trips.active[i].
931 devices.handles[j],
932 &device);
933 seq_printf(seq, "%4.4s ", status ? "" :
934 acpi_device_bid(device));
Thomas Renninger68ccfaa2006-11-19 23:01:40 +0100935 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 seq_puts(seq, "\n");
937 }
938
Len Brown4be44fc2005-08-05 00:44:28 -0400939 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400940 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941}
942
943static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
944{
945 return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
946}
947
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
949{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200950 struct acpi_thermal *tz = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
953 if (!tz)
954 goto end;
955
Len Browneaca2d32007-04-30 23:27:43 -0400956 if (!tz->flags.cooling_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 seq_puts(seq, "<setting not supported>\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 else
Len Browneaca2d32007-04-30 23:27:43 -0400959 seq_puts(seq, "0 - Active; 1 - Passive\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
Len Brown4be44fc2005-08-05 00:44:28 -0400961 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400962 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963}
964
965static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
966{
967 return single_open(file, acpi_thermal_cooling_seq_show,
Len Brown4be44fc2005-08-05 00:44:28 -0400968 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969}
970
971static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400972acpi_thermal_write_cooling_mode(struct file *file,
973 const char __user * buffer,
974 size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200976 struct seq_file *m = file->private_data;
977 struct acpi_thermal *tz = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400978 int result = 0;
979 char mode_string[12] = { '\0' };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
982 if (!tz || (count > sizeof(mode_string) - 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400983 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
985 if (!tz->flags.cooling_mode)
Patrick Mocheld550d982006-06-27 00:41:40 -0400986 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
988 if (copy_from_user(mode_string, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400989 return -EFAULT;
Len Brown4be44fc2005-08-05 00:44:28 -0400990
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 mode_string[count] = '\0';
Len Brown4be44fc2005-08-05 00:44:28 -0400992
993 result = acpi_thermal_set_cooling_mode(tz,
994 simple_strtoul(mode_string, NULL,
995 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400997 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
999 acpi_thermal_check(tz);
1000
Patrick Mocheld550d982006-06-27 00:41:40 -04001001 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002}
1003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
1005{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001006 struct acpi_thermal *tz = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
1009 if (!tz)
1010 goto end;
1011
1012 if (!tz->polling_frequency) {
1013 seq_puts(seq, "<polling disabled>\n");
1014 goto end;
1015 }
1016
1017 seq_printf(seq, "polling frequency: %lu seconds\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001018 (tz->polling_frequency / 10));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
Len Brown4be44fc2005-08-05 00:44:28 -04001020 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001021 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022}
1023
1024static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
1025{
1026 return single_open(file, acpi_thermal_polling_seq_show,
Len Brown4be44fc2005-08-05 00:44:28 -04001027 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028}
1029
1030static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001031acpi_thermal_write_polling(struct file *file,
1032 const char __user * buffer,
1033 size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001035 struct seq_file *m = file->private_data;
1036 struct acpi_thermal *tz = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001037 int result = 0;
1038 char polling_string[12] = { '\0' };
1039 int seconds = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
1042 if (!tz || (count > sizeof(polling_string) - 1))
Patrick Mocheld550d982006-06-27 00:41:40 -04001043 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -04001044
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 if (copy_from_user(polling_string, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001046 return -EFAULT;
Len Brown4be44fc2005-08-05 00:44:28 -04001047
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 polling_string[count] = '\0';
1049
1050 seconds = simple_strtoul(polling_string, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -04001051
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 result = acpi_thermal_set_polling(tz, seconds);
1053 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001054 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
1056 acpi_thermal_check(tz);
1057
Patrick Mocheld550d982006-06-27 00:41:40 -04001058 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059}
1060
Len Brown4be44fc2005-08-05 00:44:28 -04001061static int acpi_thermal_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062{
Len Brown4be44fc2005-08-05 00:44:28 -04001063 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
1066 if (!acpi_device_dir(device)) {
1067 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001068 acpi_thermal_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001070 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 acpi_device_dir(device)->owner = THIS_MODULE;
1072 }
1073
1074 /* 'state' [R] */
1075 entry = create_proc_entry(ACPI_THERMAL_FILE_STATE,
Len Brown4be44fc2005-08-05 00:44:28 -04001076 S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001078 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 else {
1080 entry->proc_fops = &acpi_thermal_state_fops;
1081 entry->data = acpi_driver_data(device);
1082 entry->owner = THIS_MODULE;
1083 }
1084
1085 /* 'temperature' [R] */
1086 entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
Len Brown4be44fc2005-08-05 00:44:28 -04001087 S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001089 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 else {
1091 entry->proc_fops = &acpi_thermal_temp_fops;
1092 entry->data = acpi_driver_data(device);
1093 entry->owner = THIS_MODULE;
1094 }
1095
Pavel Machek2db9ccb2007-08-24 11:45:50 +02001096 /* 'trip_points' [R] */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
Pavel Machek2db9ccb2007-08-24 11:45:50 +02001098 S_IRUGO,
Len Brown4be44fc2005-08-05 00:44:28 -04001099 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001101 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 else {
1103 entry->proc_fops = &acpi_thermal_trip_fops;
1104 entry->data = acpi_driver_data(device);
1105 entry->owner = THIS_MODULE;
1106 }
1107
1108 /* 'cooling_mode' [R/W] */
1109 entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
Len Brown4be44fc2005-08-05 00:44:28 -04001110 S_IFREG | S_IRUGO | S_IWUSR,
1111 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001113 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 else {
1115 entry->proc_fops = &acpi_thermal_cooling_fops;
1116 entry->data = acpi_driver_data(device);
1117 entry->owner = THIS_MODULE;
1118 }
1119
1120 /* 'polling_frequency' [R/W] */
1121 entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
Len Brown4be44fc2005-08-05 00:44:28 -04001122 S_IFREG | S_IRUGO | S_IWUSR,
1123 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001125 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 else {
1127 entry->proc_fops = &acpi_thermal_polling_fops;
1128 entry->data = acpi_driver_data(device);
1129 entry->owner = THIS_MODULE;
1130 }
1131
Patrick Mocheld550d982006-06-27 00:41:40 -04001132 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133}
1134
Len Brown4be44fc2005-08-05 00:44:28 -04001135static int acpi_thermal_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
1138 if (acpi_device_dir(device)) {
1139 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1140 acpi_device_dir(device));
1141 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1142 acpi_device_dir(device));
1143 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1144 acpi_device_dir(device));
1145 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1146 acpi_device_dir(device));
1147 remove_proc_entry(ACPI_THERMAL_FILE_STATE,
1148 acpi_device_dir(device));
1149 remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
1150 acpi_device_dir(device) = NULL;
1151 }
1152
Patrick Mocheld550d982006-06-27 00:41:40 -04001153 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154}
1155
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156/* --------------------------------------------------------------------------
1157 Driver Interface
1158 -------------------------------------------------------------------------- */
1159
Len Brown4be44fc2005-08-05 00:44:28 -04001160static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001162 struct acpi_thermal *tz = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001163 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
1166 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -04001167 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
Patrick Mochel8348e1b2006-05-19 16:54:40 -04001169 device = tz->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
1171 switch (event) {
1172 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
1173 acpi_thermal_check(tz);
1174 break;
1175 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
1176 acpi_thermal_get_trip_points(tz);
1177 acpi_thermal_check(tz);
Len Brown14e04fb2007-08-23 15:20:26 -04001178 acpi_bus_generate_proc_event(device, event, 0);
Zhang Rui962ce8c2007-08-23 01:24:31 +08001179 acpi_bus_generate_netlink_event(device->pnp.device_class,
1180 device->dev.bus_id, event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 break;
1182 case ACPI_THERMAL_NOTIFY_DEVICES:
1183 if (tz->flags.devices)
1184 acpi_thermal_get_devices(tz);
Len Brown14e04fb2007-08-23 15:20:26 -04001185 acpi_bus_generate_proc_event(device, event, 0);
Zhang Rui962ce8c2007-08-23 01:24:31 +08001186 acpi_bus_generate_netlink_event(device->pnp.device_class,
1187 device->dev.bus_id, event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 break;
1189 default:
1190 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001191 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 break;
1193 }
1194
Patrick Mocheld550d982006-06-27 00:41:40 -04001195 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196}
1197
Len Brown4be44fc2005-08-05 00:44:28 -04001198static int acpi_thermal_get_info(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199{
Len Brown4be44fc2005-08-05 00:44:28 -04001200 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
1203 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -04001204 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
1206 /* Get temperature [_TMP] (required) */
1207 result = acpi_thermal_get_temperature(tz);
1208 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001209 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
1211 /* Get trip points [_CRT, _PSV, etc.] (required) */
1212 result = acpi_thermal_get_trip_points(tz);
1213 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001214 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
1216 /* Set the cooling mode [_SCP] to active cooling (default) */
1217 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
Len Brown4be44fc2005-08-05 00:44:28 -04001218 if (!result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 tz->flags.cooling_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220
1221 /* Get default polling frequency [_TZP] (optional) */
1222 if (tzp)
1223 tz->polling_frequency = tzp;
1224 else
1225 acpi_thermal_get_polling_frequency(tz);
1226
1227 /* Get devices in this thermal zone [_TZD] (optional) */
1228 result = acpi_thermal_get_devices(tz);
1229 if (!result)
1230 tz->flags.devices = 1;
1231
Patrick Mocheld550d982006-06-27 00:41:40 -04001232 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233}
1234
Len Brown4be44fc2005-08-05 00:44:28 -04001235static int acpi_thermal_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236{
Len Brown4be44fc2005-08-05 00:44:28 -04001237 int result = 0;
1238 acpi_status status = AE_OK;
1239 struct acpi_thermal *tz = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
1242 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001243 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
Burman Yan36bcbec2006-12-19 12:56:11 -08001245 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -04001247 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
Patrick Mochel8348e1b2006-05-19 16:54:40 -04001249 tz->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 strcpy(tz->name, device->pnp.bus_id);
1251 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1252 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
1253 acpi_driver_data(device) = tz;
1254
1255 result = acpi_thermal_get_info(tz);
1256 if (result)
1257 goto end;
1258
1259 result = acpi_thermal_add_fs(device);
1260 if (result)
Vasily Averin09047e72006-04-27 05:25:00 -04001261 goto end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
1263 init_timer(&tz->timer);
1264
1265 acpi_thermal_check(tz);
1266
Patrick Mochel38ba7c92006-05-19 16:54:48 -04001267 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001268 ACPI_DEVICE_NOTIFY,
1269 acpi_thermal_notify, tz);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 result = -ENODEV;
1272 goto end;
1273 }
1274
1275 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001276 acpi_device_name(device), acpi_device_bid(device),
1277 KELVIN_TO_CELSIUS(tz->temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
Len Brown4be44fc2005-08-05 00:44:28 -04001279 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 if (result) {
1281 acpi_thermal_remove_fs(device);
1282 kfree(tz);
1283 }
1284
Patrick Mocheld550d982006-06-27 00:41:40 -04001285 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286}
1287
Len Brown4be44fc2005-08-05 00:44:28 -04001288static int acpi_thermal_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289{
Len Brown4be44fc2005-08-05 00:44:28 -04001290 acpi_status status = AE_OK;
1291 struct acpi_thermal *tz = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
1294 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001295 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001297 tz = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298
1299 /* avoid timer adding new defer task */
1300 tz->zombie = 1;
1301 /* wait for running timer (on other CPUs) finish */
1302 del_timer_sync(&(tz->timer));
1303 /* synchronize deferred task */
1304 acpi_os_wait_events_complete(NULL);
1305 /* deferred task may reinsert timer */
1306 del_timer_sync(&(tz->timer));
1307
Patrick Mochel38ba7c92006-05-19 16:54:48 -04001308 status = acpi_remove_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001309 ACPI_DEVICE_NOTIFY,
1310 acpi_thermal_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
1312 /* Terminate policy */
Len Brown4be44fc2005-08-05 00:44:28 -04001313 if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 tz->trips.passive.flags.enabled = 0;
1315 acpi_thermal_passive(tz);
1316 }
1317 if (tz->trips.active[0].flags.valid
Len Brown4be44fc2005-08-05 00:44:28 -04001318 && tz->trips.active[0].flags.enabled) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 tz->trips.active[0].flags.enabled = 0;
1320 acpi_thermal_active(tz);
1321 }
1322
1323 acpi_thermal_remove_fs(device);
1324
1325 kfree(tz);
Patrick Mocheld550d982006-06-27 00:41:40 -04001326 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327}
1328
Patrick Mochel5d9464a2006-12-07 20:56:27 +08001329static int acpi_thermal_resume(struct acpi_device *device)
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001330{
1331 struct acpi_thermal *tz = NULL;
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001332 int i, j, power_state, result;
1333
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001334
1335 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001336 return -EINVAL;
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001337
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001338 tz = acpi_driver_data(device);
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001339
Konstantin Karasyovbed936f2006-07-10 04:44:26 -07001340 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001341 if (!(&tz->trips.active[i]))
1342 break;
1343 if (!tz->trips.active[i].flags.valid)
1344 break;
1345 tz->trips.active[i].flags.enabled = 1;
1346 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1347 result = acpi_bus_get_power(tz->trips.active[i].devices.
1348 handles[j], &power_state);
1349 if (result || (power_state != ACPI_STATE_D0)) {
1350 tz->trips.active[i].flags.enabled = 0;
1351 break;
1352 }
Konstantin Karasyovbed936f2006-07-10 04:44:26 -07001353 }
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001354 tz->state.active |= tz->trips.active[i].flags.enabled;
Konstantin Karasyovbed936f2006-07-10 04:44:26 -07001355 }
1356
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001357 acpi_thermal_check(tz);
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001358
1359 return AE_OK;
1360}
1361
Len Brown0b5bfa12007-08-12 00:13:02 -04001362#ifdef CONFIG_DMI
Jeff Garzik18552562007-10-03 15:15:40 -04001363static int thermal_act(const struct dmi_system_id *d) {
Len Brown0b5bfa12007-08-12 00:13:02 -04001364
1365 if (act == 0) {
1366 printk(KERN_NOTICE "ACPI: %s detected: "
1367 "disabling all active thermal trip points\n", d->ident);
1368 act = -1;
1369 }
1370 return 0;
1371}
Jeff Garzik18552562007-10-03 15:15:40 -04001372static int thermal_nocrt(const struct dmi_system_id *d) {
Len Brown8c99fdc2007-08-20 18:46:50 -04001373
1374 printk(KERN_NOTICE "ACPI: %s detected: "
1375 "disabling all critical thermal trip point actions.\n", d->ident);
1376 nocrt = 1;
1377 return 0;
1378}
Jeff Garzik18552562007-10-03 15:15:40 -04001379static int thermal_tzp(const struct dmi_system_id *d) {
Len Brown0b5bfa12007-08-12 00:13:02 -04001380
1381 if (tzp == 0) {
1382 printk(KERN_NOTICE "ACPI: %s detected: "
1383 "enabling thermal zone polling\n", d->ident);
1384 tzp = 300; /* 300 dS = 30 Seconds */
1385 }
1386 return 0;
1387}
Jeff Garzik18552562007-10-03 15:15:40 -04001388static int thermal_psv(const struct dmi_system_id *d) {
Len Brown0b5bfa12007-08-12 00:13:02 -04001389
1390 if (psv == 0) {
1391 printk(KERN_NOTICE "ACPI: %s detected: "
1392 "disabling all passive thermal trip points\n", d->ident);
1393 psv = -1;
1394 }
1395 return 0;
1396}
1397
1398static struct dmi_system_id thermal_dmi_table[] __initdata = {
1399 /*
1400 * Award BIOS on this AOpen makes thermal control almost worthless.
1401 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1402 */
1403 {
1404 .callback = thermal_act,
1405 .ident = "AOpen i915GMm-HFS",
1406 .matches = {
1407 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1408 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1409 },
1410 },
1411 {
1412 .callback = thermal_psv,
1413 .ident = "AOpen i915GMm-HFS",
1414 .matches = {
1415 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1416 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1417 },
1418 },
1419 {
1420 .callback = thermal_tzp,
1421 .ident = "AOpen i915GMm-HFS",
1422 .matches = {
1423 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1424 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1425 },
1426 },
Len Brown8c99fdc2007-08-20 18:46:50 -04001427 {
1428 .callback = thermal_nocrt,
1429 .ident = "Gigabyte GA-7ZX",
1430 .matches = {
1431 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
1432 DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
1433 },
1434 },
Len Brown0b5bfa12007-08-12 00:13:02 -04001435 {}
1436};
1437#endif /* CONFIG_DMI */
1438
Len Brown4be44fc2005-08-05 00:44:28 -04001439static int __init acpi_thermal_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440{
Len Brown4be44fc2005-08-05 00:44:28 -04001441 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
Len Brown0b5bfa12007-08-12 00:13:02 -04001443 dmi_check_system(thermal_dmi_table);
1444
Len Brown72b33ef2007-08-12 00:12:17 -04001445 if (off) {
1446 printk(KERN_NOTICE "ACPI: thermal control disabled\n");
1447 return -ENODEV;
1448 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
1450 if (!acpi_thermal_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001451 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 acpi_thermal_dir->owner = THIS_MODULE;
1453
1454 result = acpi_bus_register_driver(&acpi_thermal_driver);
1455 if (result < 0) {
1456 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04001457 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 }
1459
Patrick Mocheld550d982006-06-27 00:41:40 -04001460 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461}
1462
Len Brown4be44fc2005-08-05 00:44:28 -04001463static void __exit acpi_thermal_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465
1466 acpi_bus_unregister_driver(&acpi_thermal_driver);
1467
1468 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1469
Patrick Mocheld550d982006-06-27 00:41:40 -04001470 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471}
1472
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473module_init(acpi_thermal_init);
1474module_exit(acpi_thermal_exit);