blob: 1e06159fd9c4a529435615646aedce6c77c0fa96 [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);
80MODULE_PARM_DESC(act, "Disable or override all lowest active trip points.\n");
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082static int tzp;
Len Brown730ff342007-08-12 00:12:26 -040083module_param(tzp, int, 0444);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.\n");
85
Len Brownf5487142007-08-12 00:12:44 -040086static int nocrt;
87module_param(nocrt, int, 0);
88MODULE_PARM_DESC(nocrt, "Set to disable action on ACPI thermal zone critical and hot trips.\n");
89
Len Brown72b33ef2007-08-12 00:12:17 -040090static int off;
91module_param(off, int, 0);
92MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.\n");
93
Len Browna70cdc52007-08-12 00:12:35 -040094static int psv;
95module_param(psv, int, 0644);
96MODULE_PARM_DESC(psv, "Disable or override all passive trip points.\n");
97
Len Brown4be44fc2005-08-05 00:44:28 -040098static int acpi_thermal_add(struct acpi_device *device);
99static int acpi_thermal_remove(struct acpi_device *device, int type);
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800100static int acpi_thermal_resume(struct acpi_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
102static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
103static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
Len Brown4be44fc2005-08-05 00:44:28 -0400105static ssize_t acpi_thermal_write_cooling_mode(struct file *,
106 const char __user *, size_t,
107 loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
Len Brown4be44fc2005-08-05 00:44:28 -0400109static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
110 size_t, loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200112static const struct acpi_device_id thermal_device_ids[] = {
113 {ACPI_THERMAL_HID, 0},
114 {"", 0},
115};
116MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118static struct acpi_driver acpi_thermal_driver = {
Len Brownc2b67052007-02-12 23:33:40 -0500119 .name = "thermal",
Len Brown4be44fc2005-08-05 00:44:28 -0400120 .class = ACPI_THERMAL_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200121 .ids = thermal_device_ids,
Len Brown4be44fc2005-08-05 00:44:28 -0400122 .ops = {
123 .add = acpi_thermal_add,
124 .remove = acpi_thermal_remove,
Konstantin Karasyov74ce14682006-05-08 08:32:00 -0400125 .resume = acpi_thermal_resume,
Len Brown4be44fc2005-08-05 00:44:28 -0400126 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127};
128
129struct acpi_thermal_state {
Len Brown4be44fc2005-08-05 00:44:28 -0400130 u8 critical:1;
131 u8 hot:1;
132 u8 passive:1;
133 u8 active:1;
134 u8 reserved:4;
135 int active_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136};
137
138struct acpi_thermal_state_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400139 u8 valid:1;
140 u8 enabled:1;
141 u8 reserved:6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142};
143
144struct acpi_thermal_critical {
145 struct acpi_thermal_state_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400146 unsigned long temperature;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147};
148
149struct acpi_thermal_hot {
150 struct acpi_thermal_state_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400151 unsigned long temperature;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152};
153
154struct acpi_thermal_passive {
155 struct acpi_thermal_state_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400156 unsigned long temperature;
157 unsigned long tc1;
158 unsigned long tc2;
159 unsigned long tsp;
160 struct acpi_handle_list devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161};
162
163struct acpi_thermal_active {
164 struct acpi_thermal_state_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400165 unsigned long temperature;
166 struct acpi_handle_list devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167};
168
169struct acpi_thermal_trips {
170 struct acpi_thermal_critical critical;
Len Brown4be44fc2005-08-05 00:44:28 -0400171 struct acpi_thermal_hot hot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 struct acpi_thermal_passive passive;
173 struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
174};
175
176struct acpi_thermal_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400177 u8 cooling_mode:1; /* _SCP */
178 u8 devices:1; /* _TZD */
179 u8 reserved:6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180};
181
182struct acpi_thermal {
Patrick Mochel8348e1b2006-05-19 16:54:40 -0400183 struct acpi_device * device;
Len Brown4be44fc2005-08-05 00:44:28 -0400184 acpi_bus_id name;
185 unsigned long temperature;
186 unsigned long last_temperature;
187 unsigned long polling_frequency;
Len Brown4be44fc2005-08-05 00:44:28 -0400188 volatile u8 zombie;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 struct acpi_thermal_flags flags;
190 struct acpi_thermal_state state;
191 struct acpi_thermal_trips trips;
Len Brown4be44fc2005-08-05 00:44:28 -0400192 struct acpi_handle_list devices;
193 struct timer_list timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194};
195
Arjan van de Vend7508032006-07-04 13:06:00 -0400196static const struct file_operations acpi_thermal_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400197 .open = acpi_thermal_state_open_fs,
198 .read = seq_read,
199 .llseek = seq_lseek,
200 .release = single_release,
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_temp_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400204 .open = acpi_thermal_temp_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_trip_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400211 .open = acpi_thermal_trip_open_fs,
212 .read = seq_read,
Len Brown4be44fc2005-08-05 00:44:28 -0400213 .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_cooling_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400218 .open = acpi_thermal_cooling_open_fs,
219 .read = seq_read,
220 .write = acpi_thermal_write_cooling_mode,
221 .llseek = seq_lseek,
222 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223};
224
Arjan van de Vend7508032006-07-04 13:06:00 -0400225static const struct file_operations acpi_thermal_polling_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400226 .open = acpi_thermal_polling_open_fs,
227 .read = seq_read,
228 .write = acpi_thermal_write_polling,
229 .llseek = seq_lseek,
230 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231};
232
233/* --------------------------------------------------------------------------
234 Thermal Zone Management
235 -------------------------------------------------------------------------- */
236
Len Brown4be44fc2005-08-05 00:44:28 -0400237static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238{
Len Brown4be44fc2005-08-05 00:44:28 -0400239 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400243 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245 tz->last_temperature = tz->temperature;
246
Len Brown4be44fc2005-08-05 00:44:28 -0400247 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400248 acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tz->temperature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400250 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Len Brown4be44fc2005-08-05 00:44:28 -0400252 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
253 tz->temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Patrick Mocheld550d982006-06-27 00:41:40 -0400255 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256}
257
Len Brown4be44fc2005-08-05 00:44:28 -0400258static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
Len Brown4be44fc2005-08-05 00:44:28 -0400260 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400264 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Len Brown4be44fc2005-08-05 00:44:28 -0400266 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400267 acpi_evaluate_integer(tz->device->handle, "_TZP", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400268 &tz->polling_frequency);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400270 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Len Brown4be44fc2005-08-05 00:44:28 -0400272 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
273 tz->polling_frequency));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Patrick Mocheld550d982006-06-27 00:41:40 -0400275 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}
277
Len Brown4be44fc2005-08-05 00:44:28 -0400278static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400282 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
285
Len Brown4be44fc2005-08-05 00:44:28 -0400286 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
287 "Polling frequency set to %lu seconds\n",
Sanjoy Mahajan636cedf2007-02-16 01:24:43 -0500288 tz->polling_frequency/10));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Patrick Mocheld550d982006-06-27 00:41:40 -0400290 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291}
292
Len Brown4be44fc2005-08-05 00:44:28 -0400293static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
Len Brown4be44fc2005-08-05 00:44:28 -0400295 acpi_status status = AE_OK;
296 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
297 struct acpi_object_list arg_list = { 1, &arg0 };
298 acpi_handle handle = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400302 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400304 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 if (ACPI_FAILURE(status)) {
306 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400307 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 }
309
310 arg0.integer.value = mode;
311
312 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
313 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400314 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Patrick Mocheld550d982006-06-27 00:41:40 -0400316 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317}
318
Len Brown4be44fc2005-08-05 00:44:28 -0400319static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
Len Brown4be44fc2005-08-05 00:44:28 -0400321 acpi_status status = AE_OK;
322 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400326 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328 /* Critical Shutdown (required) */
329
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400330 status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400331 &tz->trips.critical.temperature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 if (ACPI_FAILURE(status)) {
333 tz->trips.critical.flags.valid = 0;
Thomas Renningera6fc6722006-06-26 23:58:43 -0400334 ACPI_EXCEPTION((AE_INFO, status, "No critical threshold"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400335 return -ENODEV;
Len Brown4be44fc2005-08-05 00:44:28 -0400336 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 tz->trips.critical.flags.valid = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400338 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
339 "Found critical threshold [%lu]\n",
340 tz->trips.critical.temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
342
343 /* Critical Sleep (optional) */
344
Len Brown4be44fc2005-08-05 00:44:28 -0400345 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400346 acpi_evaluate_integer(tz->device->handle, "_HOT", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400347 &tz->trips.hot.temperature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 if (ACPI_FAILURE(status)) {
349 tz->trips.hot.flags.valid = 0;
350 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No hot threshold\n"));
Len Brown4be44fc2005-08-05 00:44:28 -0400351 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 tz->trips.hot.flags.valid = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400353 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found hot threshold [%lu]\n",
354 tz->trips.hot.temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 }
356
357 /* Passive: Processors (optional) */
358
Len Browna70cdc52007-08-12 00:12:35 -0400359 if (psv == -1) {
360 status = AE_SUPPORT;
361 } else if (psv > 0) {
362 tz->trips.passive.temperature = CELSIUS_TO_KELVIN(psv);
363 status = AE_OK;
364 } else {
365 status = acpi_evaluate_integer(tz->device->handle,
366 "_PSV", NULL, &tz->trips.passive.temperature);
367 }
368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 if (ACPI_FAILURE(status)) {
370 tz->trips.passive.flags.valid = 0;
371 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No passive threshold\n"));
Len Brown4be44fc2005-08-05 00:44:28 -0400372 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 tz->trips.passive.flags.valid = 1;
374
Len Brown4be44fc2005-08-05 00:44:28 -0400375 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400376 acpi_evaluate_integer(tz->device->handle, "_TC1", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400377 &tz->trips.passive.tc1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 if (ACPI_FAILURE(status))
379 tz->trips.passive.flags.valid = 0;
380
Len Brown4be44fc2005-08-05 00:44:28 -0400381 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400382 acpi_evaluate_integer(tz->device->handle, "_TC2", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400383 &tz->trips.passive.tc2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 if (ACPI_FAILURE(status))
385 tz->trips.passive.flags.valid = 0;
386
Len Brown4be44fc2005-08-05 00:44:28 -0400387 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400388 acpi_evaluate_integer(tz->device->handle, "_TSP", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400389 &tz->trips.passive.tsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 if (ACPI_FAILURE(status))
391 tz->trips.passive.flags.valid = 0;
392
Len Brown4be44fc2005-08-05 00:44:28 -0400393 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400394 acpi_evaluate_reference(tz->device->handle, "_PSL", NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400395 &tz->trips.passive.devices);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 if (ACPI_FAILURE(status))
397 tz->trips.passive.flags.valid = 0;
398
399 if (!tz->trips.passive.flags.valid)
Len Browncece9292006-06-26 23:04:31 -0400400 printk(KERN_WARNING PREFIX "Invalid passive threshold\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 else
Len Brown4be44fc2005-08-05 00:44:28 -0400402 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
403 "Found passive threshold [%lu]\n",
404 tz->trips.passive.temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 }
406
407 /* Active: Fans, etc. (optional) */
408
Len Brown4be44fc2005-08-05 00:44:28 -0400409 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Len Brown4be44fc2005-08-05 00:44:28 -0400411 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Len Brownf8707ec2007-08-12 00:12:54 -0400413 if (act == -1)
414 break; /* disable all active trip points */
415
416 status = acpi_evaluate_integer(tz->device->handle,
417 name, NULL, &tz->trips.active[i].temperature);
418
419 if (ACPI_FAILURE(status)) {
420 if (i == 0) /* no active trip points */
421 break;
422 if (act <= 0) /* no override requested */
423 break;
424 if (i == 1) { /* 1 trip point */
425 tz->trips.active[0].temperature =
426 CELSIUS_TO_KELVIN(act);
427 } else { /* multiple trips */
428 /*
429 * Don't allow override higher than
430 * the next higher trip point
431 */
432 tz->trips.active[i - 1].temperature =
433 (tz->trips.active[i - 2].temperature <
434 CELSIUS_TO_KELVIN(act) ?
435 tz->trips.active[i - 2].temperature :
436 CELSIUS_TO_KELVIN(act));
437 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 break;
Len Brownf8707ec2007-08-12 00:12:54 -0400439 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441 name[2] = 'L';
Len Brown4be44fc2005-08-05 00:44:28 -0400442 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400443 acpi_evaluate_reference(tz->device->handle, name, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400444 &tz->trips.active[i].devices);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 if (ACPI_SUCCESS(status)) {
446 tz->trips.active[i].flags.valid = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400447 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
448 "Found active threshold [%d]:[%lu]\n",
449 i, tz->trips.active[i].temperature));
450 } else
Thomas Renningera6fc6722006-06-26 23:58:43 -0400451 ACPI_EXCEPTION((AE_INFO, status,
452 "Invalid active threshold [%d]", i));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 }
454
Patrick Mocheld550d982006-06-27 00:41:40 -0400455 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456}
457
Len Brown4be44fc2005-08-05 00:44:28 -0400458static int acpi_thermal_get_devices(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459{
Len Brown4be44fc2005-08-05 00:44:28 -0400460 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400464 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Len Brown4be44fc2005-08-05 00:44:28 -0400466 status =
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400467 acpi_evaluate_reference(tz->device->handle, "_TZD", NULL, &tz->devices);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400469 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Patrick Mocheld550d982006-06-27 00:41:40 -0400471 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472}
473
Len Brown4be44fc2005-08-05 00:44:28 -0400474static int acpi_thermal_critical(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475{
Len Brownf5487142007-08-12 00:12:44 -0400476 if (!tz || !tz->trips.critical.flags.valid || nocrt)
Patrick Mocheld550d982006-06-27 00:41:40 -0400477 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
479 if (tz->temperature >= tz->trips.critical.temperature) {
Len Browncece9292006-06-26 23:04:31 -0400480 printk(KERN_WARNING PREFIX "Critical trip point\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 tz->trips.critical.flags.enabled = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400482 } else if (tz->trips.critical.flags.enabled)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 tz->trips.critical.flags.enabled = 0;
484
Len Brown4be44fc2005-08-05 00:44:28 -0400485 printk(KERN_EMERG
486 "Critical temperature reached (%ld C), shutting down.\n",
487 KELVIN_TO_CELSIUS(tz->temperature));
Patrick Mochel8348e1b2006-05-19 16:54:40 -0400488 acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL,
Len Brown4be44fc2005-08-05 00:44:28 -0400489 tz->trips.critical.flags.enabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700491 orderly_poweroff(true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Patrick Mocheld550d982006-06-27 00:41:40 -0400493 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494}
495
Len Brown4be44fc2005-08-05 00:44:28 -0400496static int acpi_thermal_hot(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497{
Len Brownf5487142007-08-12 00:12:44 -0400498 if (!tz || !tz->trips.hot.flags.valid || nocrt)
Patrick Mocheld550d982006-06-27 00:41:40 -0400499 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
501 if (tz->temperature >= tz->trips.hot.temperature) {
Len Browncece9292006-06-26 23:04:31 -0400502 printk(KERN_WARNING PREFIX "Hot trip point\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 tz->trips.hot.flags.enabled = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400504 } else if (tz->trips.hot.flags.enabled)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 tz->trips.hot.flags.enabled = 0;
506
Patrick Mochel8348e1b2006-05-19 16:54:40 -0400507 acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
Len Brown4be44fc2005-08-05 00:44:28 -0400508 tz->trips.hot.flags.enabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510 /* TBD: Call user-mode "sleep(S4)" function */
511
Patrick Mocheld550d982006-06-27 00:41:40 -0400512 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513}
514
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400515static void acpi_thermal_passive(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516{
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400517 int result = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 struct acpi_thermal_passive *passive = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400519 int trend = 0;
520 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
523 if (!tz || !tz->trips.passive.flags.valid)
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400524 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526 passive = &(tz->trips.passive);
527
528 /*
529 * Above Trip?
530 * -----------
531 * Calculate the thermal trend (using the passive cooling equation)
532 * and modify the performance limit for all passive cooling devices
533 * accordingly. Note that we assume symmetry.
534 */
535 if (tz->temperature >= passive->temperature) {
Len Brown4be44fc2005-08-05 00:44:28 -0400536 trend =
537 (passive->tc1 * (tz->temperature - tz->last_temperature)) +
538 (passive->tc2 * (tz->temperature - passive->temperature));
539 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
540 "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
541 trend, passive->tc1, tz->temperature,
542 tz->last_temperature, passive->tc2,
543 tz->temperature, passive->temperature));
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400544 passive->flags.enabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 /* Heating up? */
546 if (trend > 0)
Len Brown4be44fc2005-08-05 00:44:28 -0400547 for (i = 0; i < passive->devices.count; i++)
548 acpi_processor_set_thermal_limit(passive->
549 devices.
550 handles[i],
551 ACPI_PROCESSOR_LIMIT_INCREMENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 /* Cooling off? */
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400553 else if (trend < 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400554 for (i = 0; i < passive->devices.count; i++)
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400555 /*
556 * assume that we are on highest
557 * freq/lowest thrott and can leave
558 * passive mode, even in error case
559 */
560 if (!acpi_processor_set_thermal_limit
561 (passive->devices.handles[i],
562 ACPI_PROCESSOR_LIMIT_DECREMENT))
563 result = 0;
564 /*
565 * Leave cooling mode, even if the temp might
566 * higher than trip point This is because some
567 * machines might have long thermal polling
568 * frequencies (tsp) defined. We will fall back
569 * into passive mode in next cycle (probably quicker)
570 */
571 if (result) {
572 passive->flags.enabled = 0;
573 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
574 "Disabling passive cooling, still above threshold,"
575 " but we are cooling down\n"));
576 }
577 }
578 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 }
580
581 /*
582 * Below Trip?
583 * -----------
584 * Implement passive cooling hysteresis to slowly increase performance
585 * and avoid thrashing around the passive trip point. Note that we
586 * assume symmetry.
587 */
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400588 if (!passive->flags.enabled)
589 return;
590 for (i = 0; i < passive->devices.count; i++)
591 if (!acpi_processor_set_thermal_limit
592 (passive->devices.handles[i],
593 ACPI_PROCESSOR_LIMIT_DECREMENT))
594 result = 0;
595 if (result) {
596 passive->flags.enabled = 0;
597 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
598 "Disabling passive cooling (zone is cool)\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600}
601
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400602static void acpi_thermal_active(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
Len Brown4be44fc2005-08-05 00:44:28 -0400604 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 struct acpi_thermal_active *active = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400606 int i = 0;
607 int j = 0;
608 unsigned long maxtemp = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
611 if (!tz)
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400612 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
Len Brown4be44fc2005-08-05 00:44:28 -0400614 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 active = &(tz->trips.active[i]);
616 if (!active || !active->flags.valid)
617 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 if (tz->temperature >= active->temperature) {
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400619 /*
620 * Above Threshold?
621 * ----------------
622 * If not already enabled, turn ON all cooling devices
623 * associated with this active threshold.
624 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 if (active->temperature > maxtemp)
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400626 tz->state.active_index = i;
627 maxtemp = active->temperature;
628 if (active->flags.enabled)
629 continue;
630 for (j = 0; j < active->devices.count; j++) {
631 result =
632 acpi_bus_set_power(active->devices.
633 handles[j],
634 ACPI_STATE_D0);
635 if (result) {
Len Browncece9292006-06-26 23:04:31 -0400636 printk(KERN_WARNING PREFIX
637 "Unable to turn cooling device [%p] 'on'\n",
Thomas Renningera6fc6722006-06-26 23:58:43 -0400638 active->devices.
Len Browncece9292006-06-26 23:04:31 -0400639 handles[j]);
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400640 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 }
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400642 active->flags.enabled = 1;
643 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
644 "Cooling device [%p] now 'on'\n",
645 active->devices.handles[j]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 }
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400647 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 }
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400649 if (!active->flags.enabled)
650 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 /*
652 * Below Threshold?
653 * ----------------
654 * Turn OFF all cooling devices associated with this
655 * threshold.
656 */
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400657 for (j = 0; j < active->devices.count; j++) {
658 result = acpi_bus_set_power(active->devices.handles[j],
659 ACPI_STATE_D3);
660 if (result) {
Len Browncece9292006-06-26 23:04:31 -0400661 printk(KERN_WARNING PREFIX
662 "Unable to turn cooling device [%p] 'off'\n",
663 active->devices.handles[j]);
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400664 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 }
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400666 active->flags.enabled = 0;
667 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
668 "Cooling device [%p] now 'off'\n",
669 active->devices.handles[j]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 }
671 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672}
673
Len Brown4be44fc2005-08-05 00:44:28 -0400674static void acpi_thermal_check(void *context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Len Brown4be44fc2005-08-05 00:44:28 -0400676static void acpi_thermal_run(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677{
678 struct acpi_thermal *tz = (struct acpi_thermal *)data;
679 if (!tz->zombie)
Alexey Starikovskiyb8d35192006-05-05 03:23:00 -0400680 acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
Len Brown4be44fc2005-08-05 00:44:28 -0400683static void acpi_thermal_check(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684{
Len Brown4be44fc2005-08-05 00:44:28 -0400685 int result = 0;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200686 struct acpi_thermal *tz = data;
Len Brown4be44fc2005-08-05 00:44:28 -0400687 unsigned long sleep_time = 0;
688 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 struct acpi_thermal_state state;
690
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
692 if (!tz) {
Len Brown64684632006-06-26 23:41:38 -0400693 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400694 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 }
696
697 state = tz->state;
698
699 result = acpi_thermal_get_temperature(tz);
700 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400701 return;
Len Brown4be44fc2005-08-05 00:44:28 -0400702
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 memset(&tz->state, 0, sizeof(tz->state));
Len Brown4be44fc2005-08-05 00:44:28 -0400704
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 /*
706 * Check Trip Points
707 * -----------------
708 * Compare the current temperature to the trip point values to see
709 * if we've entered one of the thermal policy states. Note that
710 * this function determines when a state is entered, but the
711 * individual policy decides when it is exited (e.g. hysteresis).
712 */
713 if (tz->trips.critical.flags.valid)
Len Brown4be44fc2005-08-05 00:44:28 -0400714 state.critical |=
715 (tz->temperature >= tz->trips.critical.temperature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 if (tz->trips.hot.flags.valid)
717 state.hot |= (tz->temperature >= tz->trips.hot.temperature);
718 if (tz->trips.passive.flags.valid)
Len Brown4be44fc2005-08-05 00:44:28 -0400719 state.passive |=
720 (tz->temperature >= tz->trips.passive.temperature);
721 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 if (tz->trips.active[i].flags.valid)
Len Brown4be44fc2005-08-05 00:44:28 -0400723 state.active |=
724 (tz->temperature >=
725 tz->trips.active[i].temperature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
727 /*
728 * Invoke Policy
729 * -------------
730 * Separated from the above check to allow individual policy to
731 * determine when to exit a given state.
732 */
733 if (state.critical)
734 acpi_thermal_critical(tz);
735 if (state.hot)
736 acpi_thermal_hot(tz);
737 if (state.passive)
738 acpi_thermal_passive(tz);
739 if (state.active)
740 acpi_thermal_active(tz);
741
742 /*
743 * Calculate State
744 * ---------------
745 * Again, separated from the above two to allow independent policy
746 * decisions.
747 */
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400748 tz->state.critical = tz->trips.critical.flags.enabled;
749 tz->state.hot = tz->trips.hot.flags.enabled;
750 tz->state.passive = tz->trips.passive.flags.enabled;
751 tz->state.active = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400752 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
Thomas Renninger1cbf4c52004-09-16 11:07:00 -0400753 tz->state.active |= tz->trips.active[i].flags.enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
755 /*
756 * Calculate Sleep Time
757 * --------------------
758 * If we're in the passive state, use _TSP's value. Otherwise
759 * use the default polling frequency (e.g. _TZP). If no polling
760 * frequency is specified then we'll wait forever (at least until
761 * a thermal event occurs). Note that _TSP and _TZD values are
762 * given in 1/10th seconds (we must covert to milliseconds).
763 */
764 if (tz->state.passive)
765 sleep_time = tz->trips.passive.tsp * 100;
766 else if (tz->polling_frequency > 0)
767 sleep_time = tz->polling_frequency * 100;
768
Len Brown4be44fc2005-08-05 00:44:28 -0400769 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n",
770 tz->name, tz->temperature, sleep_time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
772 /*
773 * Schedule Next Poll
774 * ------------------
775 */
776 if (!sleep_time) {
777 if (timer_pending(&(tz->timer)))
778 del_timer(&(tz->timer));
Len Brown4be44fc2005-08-05 00:44:28 -0400779 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 if (timer_pending(&(tz->timer)))
Andrew Morton94e22e12007-04-23 14:41:13 -0700781 mod_timer(&(tz->timer),
782 jiffies + (HZ * sleep_time) / 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 else {
Len Brown4be44fc2005-08-05 00:44:28 -0400784 tz->timer.data = (unsigned long)tz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 tz->timer.function = acpi_thermal_run;
786 tz->timer.expires = jiffies + (HZ * sleep_time) / 1000;
787 add_timer(&(tz->timer));
788 }
789 }
790
Patrick Mocheld550d982006-06-27 00:41:40 -0400791 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792}
793
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794/* --------------------------------------------------------------------------
795 FS Interface (/proc)
796 -------------------------------------------------------------------------- */
797
Len Brown4be44fc2005-08-05 00:44:28 -0400798static struct proc_dir_entry *acpi_thermal_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
800static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
801{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200802 struct acpi_thermal *tz = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 if (!tz)
806 goto end;
807
808 seq_puts(seq, "state: ");
809
Len Brown4be44fc2005-08-05 00:44:28 -0400810 if (!tz->state.critical && !tz->state.hot && !tz->state.passive
811 && !tz->state.active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 seq_puts(seq, "ok\n");
813 else {
814 if (tz->state.critical)
815 seq_puts(seq, "critical ");
816 if (tz->state.hot)
817 seq_puts(seq, "hot ");
818 if (tz->state.passive)
819 seq_puts(seq, "passive ");
820 if (tz->state.active)
821 seq_printf(seq, "active[%d]", tz->state.active_index);
822 seq_puts(seq, "\n");
823 }
824
Len Brown4be44fc2005-08-05 00:44:28 -0400825 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400826 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827}
828
829static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
830{
831 return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
832}
833
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
835{
Len Brown4be44fc2005-08-05 00:44:28 -0400836 int result = 0;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200837 struct acpi_thermal *tz = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
840 if (!tz)
841 goto end;
842
843 result = acpi_thermal_get_temperature(tz);
844 if (result)
845 goto end;
846
Len Brown4be44fc2005-08-05 00:44:28 -0400847 seq_printf(seq, "temperature: %ld C\n",
848 KELVIN_TO_CELSIUS(tz->temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
Len Brown4be44fc2005-08-05 00:44:28 -0400850 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400851 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852}
853
854static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
855{
856 return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
857}
858
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
860{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200861 struct acpi_thermal *tz = seq->private;
Thomas Renninger68ccfaa2006-11-19 23:01:40 +0100862 struct acpi_device *device;
Thomas Renningere7c746e2007-06-18 00:40:51 -0400863 acpi_status status;
864
Len Brown4be44fc2005-08-05 00:44:28 -0400865 int i = 0;
866 int j = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
869 if (!tz)
870 goto end;
871
872 if (tz->trips.critical.flags.valid)
Len Brownf5487142007-08-12 00:12:44 -0400873 seq_printf(seq, "critical (S5): %ld C%s",
874 KELVIN_TO_CELSIUS(tz->trips.critical.temperature),
875 nocrt ? " <disabled>\n" : "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
877 if (tz->trips.hot.flags.valid)
Len Brownf5487142007-08-12 00:12:44 -0400878 seq_printf(seq, "hot (S4): %ld C%s",
879 KELVIN_TO_CELSIUS(tz->trips.hot.temperature),
880 nocrt ? " <disabled>\n" : "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
882 if (tz->trips.passive.flags.valid) {
Len Brown4be44fc2005-08-05 00:44:28 -0400883 seq_printf(seq,
884 "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
885 KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
886 tz->trips.passive.tc1, tz->trips.passive.tc2,
887 tz->trips.passive.tsp);
888 for (j = 0; j < tz->trips.passive.devices.count; j++) {
Thomas Renningere7c746e2007-06-18 00:40:51 -0400889 status = acpi_bus_get_device(tz->trips.passive.devices.
890 handles[j], &device);
891 seq_printf(seq, "%4.4s ", status ? "" :
892 acpi_device_bid(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 }
894 seq_puts(seq, "\n");
895 }
896
897 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
898 if (!(tz->trips.active[i].flags.valid))
899 break;
900 seq_printf(seq, "active[%d]: %ld C: devices=",
Len Brown4be44fc2005-08-05 00:44:28 -0400901 i,
902 KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
Thomas Renninger68ccfaa2006-11-19 23:01:40 +0100903 for (j = 0; j < tz->trips.active[i].devices.count; j++){
Thomas Renningere7c746e2007-06-18 00:40:51 -0400904 status = acpi_bus_get_device(tz->trips.active[i].
905 devices.handles[j],
906 &device);
907 seq_printf(seq, "%4.4s ", status ? "" :
908 acpi_device_bid(device));
Thomas Renninger68ccfaa2006-11-19 23:01:40 +0100909 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 seq_puts(seq, "\n");
911 }
912
Len Brown4be44fc2005-08-05 00:44:28 -0400913 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400914 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915}
916
917static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
918{
919 return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
920}
921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
923{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200924 struct acpi_thermal *tz = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
927 if (!tz)
928 goto end;
929
Len Browneaca2d32007-04-30 23:27:43 -0400930 if (!tz->flags.cooling_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 seq_puts(seq, "<setting not supported>\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 else
Len Browneaca2d32007-04-30 23:27:43 -0400933 seq_puts(seq, "0 - Active; 1 - Passive\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
Len Brown4be44fc2005-08-05 00:44:28 -0400935 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400936 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937}
938
939static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
940{
941 return single_open(file, acpi_thermal_cooling_seq_show,
Len Brown4be44fc2005-08-05 00:44:28 -0400942 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943}
944
945static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400946acpi_thermal_write_cooling_mode(struct file *file,
947 const char __user * buffer,
948 size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200950 struct seq_file *m = file->private_data;
951 struct acpi_thermal *tz = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400952 int result = 0;
953 char mode_string[12] = { '\0' };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
956 if (!tz || (count > sizeof(mode_string) - 1))
Patrick Mocheld550d982006-06-27 00:41:40 -0400957 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
959 if (!tz->flags.cooling_mode)
Patrick Mocheld550d982006-06-27 00:41:40 -0400960 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
962 if (copy_from_user(mode_string, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400963 return -EFAULT;
Len Brown4be44fc2005-08-05 00:44:28 -0400964
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 mode_string[count] = '\0';
Len Brown4be44fc2005-08-05 00:44:28 -0400966
967 result = acpi_thermal_set_cooling_mode(tz,
968 simple_strtoul(mode_string, NULL,
969 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -0400971 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
973 acpi_thermal_check(tz);
974
Patrick Mocheld550d982006-06-27 00:41:40 -0400975 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976}
977
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
979{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200980 struct acpi_thermal *tz = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
983 if (!tz)
984 goto end;
985
986 if (!tz->polling_frequency) {
987 seq_puts(seq, "<polling disabled>\n");
988 goto end;
989 }
990
991 seq_printf(seq, "polling frequency: %lu seconds\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400992 (tz->polling_frequency / 10));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
Len Brown4be44fc2005-08-05 00:44:28 -0400994 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400995 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996}
997
998static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
999{
1000 return single_open(file, acpi_thermal_polling_seq_show,
Len Brown4be44fc2005-08-05 00:44:28 -04001001 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002}
1003
1004static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001005acpi_thermal_write_polling(struct file *file,
1006 const char __user * buffer,
1007 size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001009 struct seq_file *m = file->private_data;
1010 struct acpi_thermal *tz = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001011 int result = 0;
1012 char polling_string[12] = { '\0' };
1013 int seconds = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
1016 if (!tz || (count > sizeof(polling_string) - 1))
Patrick Mocheld550d982006-06-27 00:41:40 -04001017 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -04001018
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 if (copy_from_user(polling_string, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001020 return -EFAULT;
Len Brown4be44fc2005-08-05 00:44:28 -04001021
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 polling_string[count] = '\0';
1023
1024 seconds = simple_strtoul(polling_string, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -04001025
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 result = acpi_thermal_set_polling(tz, seconds);
1027 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001028 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
1030 acpi_thermal_check(tz);
1031
Patrick Mocheld550d982006-06-27 00:41:40 -04001032 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033}
1034
Len Brown4be44fc2005-08-05 00:44:28 -04001035static int acpi_thermal_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036{
Len Brown4be44fc2005-08-05 00:44:28 -04001037 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
1040 if (!acpi_device_dir(device)) {
1041 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001042 acpi_thermal_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001044 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 acpi_device_dir(device)->owner = THIS_MODULE;
1046 }
1047
1048 /* 'state' [R] */
1049 entry = create_proc_entry(ACPI_THERMAL_FILE_STATE,
Len Brown4be44fc2005-08-05 00:44:28 -04001050 S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001052 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 else {
1054 entry->proc_fops = &acpi_thermal_state_fops;
1055 entry->data = acpi_driver_data(device);
1056 entry->owner = THIS_MODULE;
1057 }
1058
1059 /* 'temperature' [R] */
1060 entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
Len Brown4be44fc2005-08-05 00:44:28 -04001061 S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001063 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 else {
1065 entry->proc_fops = &acpi_thermal_temp_fops;
1066 entry->data = acpi_driver_data(device);
1067 entry->owner = THIS_MODULE;
1068 }
1069
1070 /* 'trip_points' [R/W] */
1071 entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
Len Brown4be44fc2005-08-05 00:44:28 -04001072 S_IFREG | S_IRUGO | S_IWUSR,
1073 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001075 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 else {
1077 entry->proc_fops = &acpi_thermal_trip_fops;
1078 entry->data = acpi_driver_data(device);
1079 entry->owner = THIS_MODULE;
1080 }
1081
1082 /* 'cooling_mode' [R/W] */
1083 entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
Len Brown4be44fc2005-08-05 00:44:28 -04001084 S_IFREG | S_IRUGO | S_IWUSR,
1085 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001087 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 else {
1089 entry->proc_fops = &acpi_thermal_cooling_fops;
1090 entry->data = acpi_driver_data(device);
1091 entry->owner = THIS_MODULE;
1092 }
1093
1094 /* 'polling_frequency' [R/W] */
1095 entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
Len Brown4be44fc2005-08-05 00:44:28 -04001096 S_IFREG | S_IRUGO | S_IWUSR,
1097 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001099 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 else {
1101 entry->proc_fops = &acpi_thermal_polling_fops;
1102 entry->data = acpi_driver_data(device);
1103 entry->owner = THIS_MODULE;
1104 }
1105
Patrick Mocheld550d982006-06-27 00:41:40 -04001106 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107}
1108
Len Brown4be44fc2005-08-05 00:44:28 -04001109static int acpi_thermal_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
1112 if (acpi_device_dir(device)) {
1113 remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
1114 acpi_device_dir(device));
1115 remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
1116 acpi_device_dir(device));
1117 remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
1118 acpi_device_dir(device));
1119 remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
1120 acpi_device_dir(device));
1121 remove_proc_entry(ACPI_THERMAL_FILE_STATE,
1122 acpi_device_dir(device));
1123 remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
1124 acpi_device_dir(device) = NULL;
1125 }
1126
Patrick Mocheld550d982006-06-27 00:41:40 -04001127 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128}
1129
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130/* --------------------------------------------------------------------------
1131 Driver Interface
1132 -------------------------------------------------------------------------- */
1133
Len Brown4be44fc2005-08-05 00:44:28 -04001134static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001136 struct acpi_thermal *tz = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001137 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
1140 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -04001141 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
Patrick Mochel8348e1b2006-05-19 16:54:40 -04001143 device = tz->device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
1145 switch (event) {
1146 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
1147 acpi_thermal_check(tz);
1148 break;
1149 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
1150 acpi_thermal_get_trip_points(tz);
1151 acpi_thermal_check(tz);
1152 acpi_bus_generate_event(device, event, 0);
1153 break;
1154 case ACPI_THERMAL_NOTIFY_DEVICES:
1155 if (tz->flags.devices)
1156 acpi_thermal_get_devices(tz);
1157 acpi_bus_generate_event(device, event, 0);
1158 break;
1159 default:
1160 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001161 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 break;
1163 }
1164
Patrick Mocheld550d982006-06-27 00:41:40 -04001165 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166}
1167
Len Brown4be44fc2005-08-05 00:44:28 -04001168static int acpi_thermal_get_info(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169{
Len Brown4be44fc2005-08-05 00:44:28 -04001170 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
1173 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -04001174 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
1176 /* Get temperature [_TMP] (required) */
1177 result = acpi_thermal_get_temperature(tz);
1178 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001179 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
1181 /* Get trip points [_CRT, _PSV, etc.] (required) */
1182 result = acpi_thermal_get_trip_points(tz);
1183 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001184 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185
1186 /* Set the cooling mode [_SCP] to active cooling (default) */
1187 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
Len Brown4be44fc2005-08-05 00:44:28 -04001188 if (!result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 tz->flags.cooling_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
1191 /* Get default polling frequency [_TZP] (optional) */
1192 if (tzp)
1193 tz->polling_frequency = tzp;
1194 else
1195 acpi_thermal_get_polling_frequency(tz);
1196
1197 /* Get devices in this thermal zone [_TZD] (optional) */
1198 result = acpi_thermal_get_devices(tz);
1199 if (!result)
1200 tz->flags.devices = 1;
1201
Patrick Mocheld550d982006-06-27 00:41:40 -04001202 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203}
1204
Len Brown4be44fc2005-08-05 00:44:28 -04001205static int acpi_thermal_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206{
Len Brown4be44fc2005-08-05 00:44:28 -04001207 int result = 0;
1208 acpi_status status = AE_OK;
1209 struct acpi_thermal *tz = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
1212 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001213 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
Burman Yan36bcbec2006-12-19 12:56:11 -08001215 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -04001217 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
Patrick Mochel8348e1b2006-05-19 16:54:40 -04001219 tz->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 strcpy(tz->name, device->pnp.bus_id);
1221 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1222 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
1223 acpi_driver_data(device) = tz;
1224
1225 result = acpi_thermal_get_info(tz);
1226 if (result)
1227 goto end;
1228
1229 result = acpi_thermal_add_fs(device);
1230 if (result)
Vasily Averin09047e72006-04-27 05:25:00 -04001231 goto end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
1233 init_timer(&tz->timer);
1234
1235 acpi_thermal_check(tz);
1236
Patrick Mochel38ba7c92006-05-19 16:54:48 -04001237 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001238 ACPI_DEVICE_NOTIFY,
1239 acpi_thermal_notify, tz);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 result = -ENODEV;
1242 goto end;
1243 }
1244
1245 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001246 acpi_device_name(device), acpi_device_bid(device),
1247 KELVIN_TO_CELSIUS(tz->temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
Len Brown4be44fc2005-08-05 00:44:28 -04001249 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 if (result) {
1251 acpi_thermal_remove_fs(device);
1252 kfree(tz);
1253 }
1254
Patrick Mocheld550d982006-06-27 00:41:40 -04001255 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256}
1257
Len Brown4be44fc2005-08-05 00:44:28 -04001258static int acpi_thermal_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259{
Len Brown4be44fc2005-08-05 00:44:28 -04001260 acpi_status status = AE_OK;
1261 struct acpi_thermal *tz = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
1264 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001265 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001267 tz = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
1269 /* avoid timer adding new defer task */
1270 tz->zombie = 1;
1271 /* wait for running timer (on other CPUs) finish */
1272 del_timer_sync(&(tz->timer));
1273 /* synchronize deferred task */
1274 acpi_os_wait_events_complete(NULL);
1275 /* deferred task may reinsert timer */
1276 del_timer_sync(&(tz->timer));
1277
Patrick Mochel38ba7c92006-05-19 16:54:48 -04001278 status = acpi_remove_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001279 ACPI_DEVICE_NOTIFY,
1280 acpi_thermal_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
1282 /* Terminate policy */
Len Brown4be44fc2005-08-05 00:44:28 -04001283 if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 tz->trips.passive.flags.enabled = 0;
1285 acpi_thermal_passive(tz);
1286 }
1287 if (tz->trips.active[0].flags.valid
Len Brown4be44fc2005-08-05 00:44:28 -04001288 && tz->trips.active[0].flags.enabled) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 tz->trips.active[0].flags.enabled = 0;
1290 acpi_thermal_active(tz);
1291 }
1292
1293 acpi_thermal_remove_fs(device);
1294
1295 kfree(tz);
Patrick Mocheld550d982006-06-27 00:41:40 -04001296 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297}
1298
Patrick Mochel5d9464a2006-12-07 20:56:27 +08001299static int acpi_thermal_resume(struct acpi_device *device)
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001300{
1301 struct acpi_thermal *tz = NULL;
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001302 int i, j, power_state, result;
1303
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001304
1305 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001306 return -EINVAL;
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001307
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001308 tz = acpi_driver_data(device);
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001309
Konstantin Karasyovbed936f2006-07-10 04:44:26 -07001310 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001311 if (!(&tz->trips.active[i]))
1312 break;
1313 if (!tz->trips.active[i].flags.valid)
1314 break;
1315 tz->trips.active[i].flags.enabled = 1;
1316 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1317 result = acpi_bus_get_power(tz->trips.active[i].devices.
1318 handles[j], &power_state);
1319 if (result || (power_state != ACPI_STATE_D0)) {
1320 tz->trips.active[i].flags.enabled = 0;
1321 break;
1322 }
Konstantin Karasyovbed936f2006-07-10 04:44:26 -07001323 }
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001324 tz->state.active |= tz->trips.active[i].flags.enabled;
Konstantin Karasyovbed936f2006-07-10 04:44:26 -07001325 }
1326
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001327 acpi_thermal_check(tz);
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001328
1329 return AE_OK;
1330}
1331
Len Brown0b5bfa12007-08-12 00:13:02 -04001332#ifdef CONFIG_DMI
1333static int thermal_act(struct dmi_system_id *d) {
1334
1335 if (act == 0) {
1336 printk(KERN_NOTICE "ACPI: %s detected: "
1337 "disabling all active thermal trip points\n", d->ident);
1338 act = -1;
1339 }
1340 return 0;
1341}
1342static int thermal_tzp(struct dmi_system_id *d) {
1343
1344 if (tzp == 0) {
1345 printk(KERN_NOTICE "ACPI: %s detected: "
1346 "enabling thermal zone polling\n", d->ident);
1347 tzp = 300; /* 300 dS = 30 Seconds */
1348 }
1349 return 0;
1350}
1351static int thermal_psv(struct dmi_system_id *d) {
1352
1353 if (psv == 0) {
1354 printk(KERN_NOTICE "ACPI: %s detected: "
1355 "disabling all passive thermal trip points\n", d->ident);
1356 psv = -1;
1357 }
1358 return 0;
1359}
1360
1361static struct dmi_system_id thermal_dmi_table[] __initdata = {
1362 /*
1363 * Award BIOS on this AOpen makes thermal control almost worthless.
1364 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1365 */
1366 {
1367 .callback = thermal_act,
1368 .ident = "AOpen i915GMm-HFS",
1369 .matches = {
1370 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1371 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1372 },
1373 },
1374 {
1375 .callback = thermal_psv,
1376 .ident = "AOpen i915GMm-HFS",
1377 .matches = {
1378 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1379 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1380 },
1381 },
1382 {
1383 .callback = thermal_tzp,
1384 .ident = "AOpen i915GMm-HFS",
1385 .matches = {
1386 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1387 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1388 },
1389 },
1390 {}
1391};
1392#endif /* CONFIG_DMI */
1393
Len Brown4be44fc2005-08-05 00:44:28 -04001394static int __init acpi_thermal_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395{
Len Brown4be44fc2005-08-05 00:44:28 -04001396 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
Len Brown0b5bfa12007-08-12 00:13:02 -04001398 dmi_check_system(thermal_dmi_table);
1399
Len Brown72b33ef2007-08-12 00:12:17 -04001400 if (off) {
1401 printk(KERN_NOTICE "ACPI: thermal control disabled\n");
1402 return -ENODEV;
1403 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
1405 if (!acpi_thermal_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001406 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 acpi_thermal_dir->owner = THIS_MODULE;
1408
1409 result = acpi_bus_register_driver(&acpi_thermal_driver);
1410 if (result < 0) {
1411 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04001412 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 }
1414
Patrick Mocheld550d982006-06-27 00:41:40 -04001415 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416}
1417
Len Brown4be44fc2005-08-05 00:44:28 -04001418static void __exit acpi_thermal_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
1421 acpi_bus_unregister_driver(&acpi_thermal_driver);
1422
1423 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1424
Patrick Mocheld550d982006-06-27 00:41:40 -04001425 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426}
1427
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428module_init(acpi_thermal_init);
1429module_exit(acpi_thermal_exit);