blob: 6a0329340b42ad188add760db66ebcc17ba9ab22 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090038#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/types.h>
Tim Schmielaucd354f12007-02-14 00:33:14 -080040#include <linux/jiffies.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/kmod.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070042#include <linux/reboot.h>
Stephen Rothwellf6f5c452009-03-03 12:47:17 +110043#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <asm/uaccess.h>
Zhang Rui3f655ef2008-01-17 15:51:11 +080045#include <linux/thermal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <acpi/acpi_bus.h>
47#include <acpi/acpi_drivers.h>
48
Len Browna192a952009-07-28 16:45:54 -040049#define PREFIX "ACPI: "
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define ACPI_THERMAL_CLASS "thermal_zone"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80
54#define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81
55#define ACPI_THERMAL_NOTIFY_DEVICES 0x82
56#define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0
57#define ACPI_THERMAL_NOTIFY_HOT 0xF1
58#define ACPI_THERMAL_MODE_ACTIVE 0x00
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#define ACPI_THERMAL_MAX_ACTIVE 10
61#define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#define _COMPONENT ACPI_THERMAL_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050064ACPI_MODULE_NAME("thermal");
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Thomas Renninger1cbf4c52004-09-16 11:07:00 -040066MODULE_AUTHOR("Paul Diefenbaugh");
Len Brown7cda93e2007-02-12 23:50:02 -050067MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070068MODULE_LICENSE("GPL");
69
Len Brownf8707ec2007-08-12 00:12:54 -040070static int act;
71module_param(act, int, 0644);
Len Brown3c1d36d2007-08-14 15:12:56 -040072MODULE_PARM_DESC(act, "Disable or override all lowest active trip points.");
Len Brownf8707ec2007-08-12 00:12:54 -040073
Len Brownc52a7412007-08-14 15:49:32 -040074static int crt;
75module_param(crt, int, 0644);
76MODULE_PARM_DESC(crt, "Disable or lower all critical trip points.");
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078static int tzp;
Len Brown730ff342007-08-12 00:12:26 -040079module_param(tzp, int, 0444);
Len Brown3c1d36d2007-08-14 15:12:56 -040080MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Len Brownf5487142007-08-12 00:12:44 -040082static int nocrt;
83module_param(nocrt, int, 0);
Len Brown8c99fdc2007-08-20 18:46:50 -040084MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points.");
Len Brownf5487142007-08-12 00:12:44 -040085
Len Brown72b33ef2007-08-12 00:12:17 -040086static int off;
87module_param(off, int, 0);
Len Brown3c1d36d2007-08-14 15:12:56 -040088MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.");
Len Brown72b33ef2007-08-12 00:12:17 -040089
Len Browna70cdc52007-08-12 00:12:35 -040090static int psv;
91module_param(psv, int, 0644);
Len Brown3c1d36d2007-08-14 15:12:56 -040092MODULE_PARM_DESC(psv, "Disable or override all passive trip points.");
Len Browna70cdc52007-08-12 00:12:35 -040093
Len Brown4be44fc2005-08-05 00:44:28 -040094static int acpi_thermal_add(struct acpi_device *device);
Rafael J. Wysocki51fac832013-01-24 00:24:48 +010095static int acpi_thermal_remove(struct acpi_device *device);
Bjorn Helgaas342d5502009-04-07 15:37:06 +000096static void acpi_thermal_notify(struct acpi_device *device, u32 event);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Thomas Renninger1ba90e32007-07-23 14:44:41 +020098static const struct acpi_device_id thermal_device_ids[] = {
99 {ACPI_THERMAL_HID, 0},
100 {"", 0},
101};
102MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
103
Rafael J. Wysocki90692402012-08-09 23:00:02 +0200104#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki167cffb2012-06-27 23:26:18 +0200105static int acpi_thermal_resume(struct device *dev);
Rafael J. Wysocki90692402012-08-09 23:00:02 +0200106#endif
Rafael J. Wysocki167cffb2012-06-27 23:26:18 +0200107static SIMPLE_DEV_PM_OPS(acpi_thermal_pm, NULL, acpi_thermal_resume);
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109static struct acpi_driver acpi_thermal_driver = {
Len Brownc2b67052007-02-12 23:33:40 -0500110 .name = "thermal",
Len Brown4be44fc2005-08-05 00:44:28 -0400111 .class = ACPI_THERMAL_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200112 .ids = thermal_device_ids,
Len Brown4be44fc2005-08-05 00:44:28 -0400113 .ops = {
114 .add = acpi_thermal_add,
115 .remove = acpi_thermal_remove,
Bjorn Helgaas342d5502009-04-07 15:37:06 +0000116 .notify = acpi_thermal_notify,
Len Brown4be44fc2005-08-05 00:44:28 -0400117 },
Rafael J. Wysocki167cffb2012-06-27 23:26:18 +0200118 .drv.pm = &acpi_thermal_pm,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119};
120
121struct acpi_thermal_state {
Len Brown4be44fc2005-08-05 00:44:28 -0400122 u8 critical:1;
123 u8 hot:1;
124 u8 passive:1;
125 u8 active:1;
126 u8 reserved:4;
127 int active_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128};
129
130struct acpi_thermal_state_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400131 u8 valid:1;
132 u8 enabled:1;
133 u8 reserved:6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134};
135
136struct acpi_thermal_critical {
137 struct acpi_thermal_state_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400138 unsigned long temperature;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139};
140
141struct acpi_thermal_hot {
142 struct acpi_thermal_state_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400143 unsigned long temperature;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144};
145
146struct acpi_thermal_passive {
147 struct acpi_thermal_state_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400148 unsigned long temperature;
149 unsigned long tc1;
150 unsigned long tc2;
151 unsigned long tsp;
152 struct acpi_handle_list devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153};
154
155struct acpi_thermal_active {
156 struct acpi_thermal_state_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400157 unsigned long temperature;
158 struct acpi_handle_list devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159};
160
161struct acpi_thermal_trips {
162 struct acpi_thermal_critical critical;
Len Brown4be44fc2005-08-05 00:44:28 -0400163 struct acpi_thermal_hot hot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 struct acpi_thermal_passive passive;
165 struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
166};
167
168struct acpi_thermal_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400169 u8 cooling_mode:1; /* _SCP */
170 u8 devices:1; /* _TZD */
171 u8 reserved:6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172};
173
174struct acpi_thermal {
Patrick Mochel8348e1b2006-05-19 16:54:40 -0400175 struct acpi_device * device;
Len Brown4be44fc2005-08-05 00:44:28 -0400176 acpi_bus_id name;
177 unsigned long temperature;
178 unsigned long last_temperature;
179 unsigned long polling_frequency;
Len Brown4be44fc2005-08-05 00:44:28 -0400180 volatile u8 zombie;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 struct acpi_thermal_flags flags;
182 struct acpi_thermal_state state;
183 struct acpi_thermal_trips trips;
Len Brown4be44fc2005-08-05 00:44:28 -0400184 struct acpi_handle_list devices;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800185 struct thermal_zone_device *thermal_zone;
186 int tz_enabled;
Jean Delvare13614e32009-04-06 16:01:46 +0200187 int kelvin_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188};
189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190/* --------------------------------------------------------------------------
191 Thermal Zone Management
192 -------------------------------------------------------------------------- */
193
Len Brown4be44fc2005-08-05 00:44:28 -0400194static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
Len Brown4be44fc2005-08-05 00:44:28 -0400196 acpi_status status = AE_OK;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400197 unsigned long long tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400200 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202 tz->last_temperature = tz->temperature;
203
Matthew Wilcox27663c52008-10-10 02:22:59 -0400204 status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400206 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Matthew Wilcox27663c52008-10-10 02:22:59 -0400208 tz->temperature = tmp;
Len Brown4be44fc2005-08-05 00:44:28 -0400209 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
210 tz->temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Patrick Mocheld550d982006-06-27 00:41:40 -0400212 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213}
214
Len Brown4be44fc2005-08-05 00:44:28 -0400215static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216{
Len Brown4be44fc2005-08-05 00:44:28 -0400217 acpi_status status = AE_OK;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400218 unsigned long long tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400221 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Matthew Wilcox27663c52008-10-10 02:22:59 -0400223 status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400225 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Matthew Wilcox27663c52008-10-10 02:22:59 -0400227 tz->polling_frequency = tmp;
Len Brown4be44fc2005-08-05 00:44:28 -0400228 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
229 tz->polling_frequency));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
Patrick Mocheld550d982006-06-27 00:41:40 -0400231 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232}
233
Len Brown4be44fc2005-08-05 00:44:28 -0400234static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400237 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Jiang Liu0db98202013-06-29 00:24:39 +0800239 if (!acpi_has_method(tz->device->handle, "_SCP")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400241 return -ENODEV;
Jiang Liu0db98202013-06-29 00:24:39 +0800242 } else if (ACPI_FAILURE(acpi_execute_simple_method(tz->device->handle,
243 "_SCP", mode))) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400244 return -ENODEV;
Jiang Liu0db98202013-06-29 00:24:39 +0800245 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
Patrick Mocheld550d982006-06-27 00:41:40 -0400247 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248}
249
Zhang Ruice44e192008-01-17 15:51:25 +0800250#define ACPI_TRIPS_CRITICAL 0x01
251#define ACPI_TRIPS_HOT 0x02
252#define ACPI_TRIPS_PASSIVE 0x04
253#define ACPI_TRIPS_ACTIVE 0x08
254#define ACPI_TRIPS_DEVICES 0x10
255
256#define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE)
257#define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES
258
259#define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \
260 ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \
261 ACPI_TRIPS_DEVICES)
262
263/*
264 * This exception is thrown out in two cases:
265 * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
266 * when re-evaluating the AML code.
267 * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change.
268 * We need to re-bind the cooling devices of a thermal zone when this occurs.
269 */
270#define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \
271do { \
272 if (flags != ACPI_TRIPS_INIT) \
273 ACPI_EXCEPTION((AE_INFO, AE_ERROR, \
274 "ACPI thermal trip point %s changed\n" \
Colin Ian King7e3cf242012-11-29 11:53:16 +0000275 "Please send acpidump to linux-acpi@vger.kernel.org", str)); \
Zhang Ruice44e192008-01-17 15:51:25 +0800276} while (0)
277
278static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
Len Brown4be44fc2005-08-05 00:44:28 -0400280 acpi_status status = AE_OK;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400281 unsigned long long tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800282 struct acpi_handle_list devices;
283 int valid = 0;
284 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Thomas Renningerfa809452010-02-20 11:44:27 +0100286 /* Critical Shutdown */
Zhang Ruice44e192008-01-17 15:51:25 +0800287 if (flag & ACPI_TRIPS_CRITICAL) {
288 status = acpi_evaluate_integer(tz->device->handle,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400289 "_CRT", NULL, &tmp);
290 tz->trips.critical.temperature = tmp;
Arjan van de Vena39a2d72008-05-19 15:55:15 -0700291 /*
292 * Treat freezing temperatures as invalid as well; some
293 * BIOSes return really low values and cause reboots at startup.
Adam Buchbinderb731d7b2009-03-13 12:15:26 -0400294 * Below zero (Celsius) values clearly aren't right for sure..
Arjan van de Vena39a2d72008-05-19 15:55:15 -0700295 * ... so lets discard those as invalid.
296 */
Thomas Renningerfa809452010-02-20 11:44:27 +0100297 if (ACPI_FAILURE(status)) {
Len Brownc52a7412007-08-14 15:49:32 -0400298 tz->trips.critical.flags.valid = 0;
Thomas Renningerfa809452010-02-20 11:44:27 +0100299 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
300 "No critical threshold\n"));
301 } else if (tmp <= 2732) {
302 printk(KERN_WARNING FW_BUG "Invalid critical threshold "
303 "(%llu)\n", tmp);
304 tz->trips.critical.flags.valid = 0;
Zhang Ruice44e192008-01-17 15:51:25 +0800305 } else {
306 tz->trips.critical.flags.valid = 1;
307 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Thomas Renningerfa809452010-02-20 11:44:27 +0100308 "Found critical threshold [%lu]\n",
309 tz->trips.critical.temperature));
Zhang Ruice44e192008-01-17 15:51:25 +0800310 }
311 if (tz->trips.critical.flags.valid == 1) {
312 if (crt == -1) {
313 tz->trips.critical.flags.valid = 0;
314 } else if (crt > 0) {
315 unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
316 /*
Zhang Rui22a94d72008-10-17 02:41:20 -0400317 * Allow override critical threshold
Zhang Ruice44e192008-01-17 15:51:25 +0800318 */
Zhang Rui22a94d72008-10-17 02:41:20 -0400319 if (crt_k > tz->trips.critical.temperature)
320 printk(KERN_WARNING PREFIX
321 "Critical threshold %d C\n", crt);
322 tz->trips.critical.temperature = crt_k;
Zhang Ruice44e192008-01-17 15:51:25 +0800323 }
Len Brownc52a7412007-08-14 15:49:32 -0400324 }
325 }
326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 /* Critical Sleep (optional) */
Zhang Ruice44e192008-01-17 15:51:25 +0800328 if (flag & ACPI_TRIPS_HOT) {
Len Browna70cdc52007-08-12 00:12:35 -0400329 status = acpi_evaluate_integer(tz->device->handle,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400330 "_HOT", NULL, &tmp);
Zhang Ruice44e192008-01-17 15:51:25 +0800331 if (ACPI_FAILURE(status)) {
332 tz->trips.hot.flags.valid = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400333 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Zhang Ruice44e192008-01-17 15:51:25 +0800334 "No hot threshold\n"));
335 } else {
Matthew Wilcox27663c52008-10-10 02:22:59 -0400336 tz->trips.hot.temperature = tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800337 tz->trips.hot.flags.valid = 1;
338 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
339 "Found hot threshold [%lu]\n",
340 tz->trips.critical.temperature));
341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 }
343
Zhang Ruice44e192008-01-17 15:51:25 +0800344 /* Passive (optional) */
Zhang Rui0e4240d2009-01-16 12:53:42 -0500345 if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) ||
346 (flag == ACPI_TRIPS_INIT)) {
Zhang Ruice44e192008-01-17 15:51:25 +0800347 valid = tz->trips.passive.flags.valid;
348 if (psv == -1) {
349 status = AE_SUPPORT;
350 } else if (psv > 0) {
Matthew Wilcox27663c52008-10-10 02:22:59 -0400351 tmp = CELSIUS_TO_KELVIN(psv);
Zhang Ruice44e192008-01-17 15:51:25 +0800352 status = AE_OK;
353 } else {
354 status = acpi_evaluate_integer(tz->device->handle,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400355 "_PSV", NULL, &tmp);
Zhang Ruice44e192008-01-17 15:51:25 +0800356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Zhang Ruice44e192008-01-17 15:51:25 +0800358 if (ACPI_FAILURE(status))
359 tz->trips.passive.flags.valid = 0;
360 else {
Matthew Wilcox27663c52008-10-10 02:22:59 -0400361 tz->trips.passive.temperature = tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800362 tz->trips.passive.flags.valid = 1;
363 if (flag == ACPI_TRIPS_INIT) {
364 status = acpi_evaluate_integer(
365 tz->device->handle, "_TC1",
Matthew Wilcox27663c52008-10-10 02:22:59 -0400366 NULL, &tmp);
Zhang Ruice44e192008-01-17 15:51:25 +0800367 if (ACPI_FAILURE(status))
368 tz->trips.passive.flags.valid = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400369 else
370 tz->trips.passive.tc1 = tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800371 status = acpi_evaluate_integer(
372 tz->device->handle, "_TC2",
Matthew Wilcox27663c52008-10-10 02:22:59 -0400373 NULL, &tmp);
Zhang Ruice44e192008-01-17 15:51:25 +0800374 if (ACPI_FAILURE(status))
375 tz->trips.passive.flags.valid = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400376 else
377 tz->trips.passive.tc2 = tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800378 status = acpi_evaluate_integer(
379 tz->device->handle, "_TSP",
Matthew Wilcox27663c52008-10-10 02:22:59 -0400380 NULL, &tmp);
Zhang Ruice44e192008-01-17 15:51:25 +0800381 if (ACPI_FAILURE(status))
382 tz->trips.passive.flags.valid = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400383 else
384 tz->trips.passive.tsp = tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800385 }
386 }
387 }
388 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) {
389 memset(&devices, 0, sizeof(struct acpi_handle_list));
390 status = acpi_evaluate_reference(tz->device->handle, "_PSL",
391 NULL, &devices);
Zhang Rui0e4240d2009-01-16 12:53:42 -0500392 if (ACPI_FAILURE(status)) {
393 printk(KERN_WARNING PREFIX
394 "Invalid passive threshold\n");
Zhang Ruice44e192008-01-17 15:51:25 +0800395 tz->trips.passive.flags.valid = 0;
Zhang Rui0e4240d2009-01-16 12:53:42 -0500396 }
Zhang Ruice44e192008-01-17 15:51:25 +0800397 else
398 tz->trips.passive.flags.valid = 1;
399
400 if (memcmp(&tz->trips.passive.devices, &devices,
401 sizeof(struct acpi_handle_list))) {
402 memcpy(&tz->trips.passive.devices, &devices,
403 sizeof(struct acpi_handle_list));
404 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
405 }
406 }
407 if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) {
408 if (valid != tz->trips.passive.flags.valid)
409 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
410 }
411
412 /* Active (optional) */
Len Brown4be44fc2005-08-05 00:44:28 -0400413 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400414 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
Zhang Ruice44e192008-01-17 15:51:25 +0800415 valid = tz->trips.active[i].flags.valid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Len Brownf8707ec2007-08-12 00:12:54 -0400417 if (act == -1)
Zhang Ruice44e192008-01-17 15:51:25 +0800418 break; /* disable all active trip points */
Len Brownf8707ec2007-08-12 00:12:54 -0400419
Zhang Rui0e4240d2009-01-16 12:53:42 -0500420 if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) &&
421 tz->trips.active[i].flags.valid)) {
Zhang Ruice44e192008-01-17 15:51:25 +0800422 status = acpi_evaluate_integer(tz->device->handle,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400423 name, NULL, &tmp);
Zhang Ruice44e192008-01-17 15:51:25 +0800424 if (ACPI_FAILURE(status)) {
425 tz->trips.active[i].flags.valid = 0;
426 if (i == 0)
427 break;
428 if (act <= 0)
429 break;
430 if (i == 1)
431 tz->trips.active[0].temperature =
432 CELSIUS_TO_KELVIN(act);
433 else
434 /*
435 * Don't allow override higher than
436 * the next higher trip point
437 */
438 tz->trips.active[i - 1].temperature =
439 (tz->trips.active[i - 2].temperature <
440 CELSIUS_TO_KELVIN(act) ?
441 tz->trips.active[i - 2].temperature :
442 CELSIUS_TO_KELVIN(act));
Len Brownf8707ec2007-08-12 00:12:54 -0400443 break;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400444 } else {
445 tz->trips.active[i].temperature = tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800446 tz->trips.active[i].flags.valid = 1;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400447 }
Len Brownf8707ec2007-08-12 00:12:54 -0400448 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 name[2] = 'L';
Zhang Ruice44e192008-01-17 15:51:25 +0800451 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) {
452 memset(&devices, 0, sizeof(struct acpi_handle_list));
453 status = acpi_evaluate_reference(tz->device->handle,
454 name, NULL, &devices);
Zhang Rui0e4240d2009-01-16 12:53:42 -0500455 if (ACPI_FAILURE(status)) {
456 printk(KERN_WARNING PREFIX
457 "Invalid active%d threshold\n", i);
Zhang Ruice44e192008-01-17 15:51:25 +0800458 tz->trips.active[i].flags.valid = 0;
Zhang Rui0e4240d2009-01-16 12:53:42 -0500459 }
Zhang Ruice44e192008-01-17 15:51:25 +0800460 else
461 tz->trips.active[i].flags.valid = 1;
462
463 if (memcmp(&tz->trips.active[i].devices, &devices,
464 sizeof(struct acpi_handle_list))) {
465 memcpy(&tz->trips.active[i].devices, &devices,
466 sizeof(struct acpi_handle_list));
467 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
468 }
469 }
470 if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES))
471 if (valid != tz->trips.active[i].flags.valid)
472 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
473
474 if (!tz->trips.active[i].flags.valid)
475 break;
476 }
477
Lan Tianyu668e0202013-08-27 16:29:31 +0800478 if ((flag & ACPI_TRIPS_DEVICES)
479 && acpi_has_method(tz->device->handle, "_TZD")) {
480 memset(&devices, 0, sizeof(devices));
Zhang Ruice44e192008-01-17 15:51:25 +0800481 status = acpi_evaluate_reference(tz->device->handle, "_TZD",
482 NULL, &devices);
Lan Tianyu668e0202013-08-27 16:29:31 +0800483 if (ACPI_SUCCESS(status)
484 && memcmp(&tz->devices, &devices, sizeof(devices))) {
485 tz->devices = devices;
Zhang Ruice44e192008-01-17 15:51:25 +0800486 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
487 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 }
489
Patrick Mocheld550d982006-06-27 00:41:40 -0400490 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491}
492
Zhang Ruice44e192008-01-17 15:51:25 +0800493static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494{
Thomas Renninger8b7ef6d2010-02-16 22:55:51 +0100495 int i, valid, ret = acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
496
497 if (ret)
498 return ret;
499
500 valid = tz->trips.critical.flags.valid |
501 tz->trips.hot.flags.valid |
502 tz->trips.passive.flags.valid;
503
504 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
505 valid |= tz->trips.active[i].flags.valid;
506
507 if (!valid) {
508 printk(KERN_WARNING FW_BUG "No valid trip found\n");
509 return -ENODEV;
510 }
511 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512}
513
Len Brown4be44fc2005-08-05 00:44:28 -0400514static void acpi_thermal_check(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200516 struct acpi_thermal *tz = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Srinivas Pandruvadaca4e7132013-01-15 23:57:16 +0100518 if (!tz->tz_enabled) {
519 pr_warn("thermal zone is disabled \n");
520 return;
521 }
Matthew Garrettb1569e92008-12-03 17:55:32 +0000522 thermal_zone_device_update(tz->thermal_zone);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523}
524
Zhang Rui3f655ef2008-01-17 15:51:11 +0800525/* sys I/F for generic thermal sysfs support */
Jean Delvare13614e32009-04-06 16:01:46 +0200526#define KELVIN_TO_MILLICELSIUS(t, off) (((t) - (off)) * 100)
Zhang, Rui5e012762008-02-28 07:51:30 +0800527
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000528static int thermal_get_temp(struct thermal_zone_device *thermal,
529 unsigned long *temp)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800530{
531 struct acpi_thermal *tz = thermal->devdata;
Zhang, Rui76ecb4f2008-04-10 16:20:23 +0800532 int result;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800533
534 if (!tz)
535 return -EINVAL;
536
Zhang, Rui76ecb4f2008-04-10 16:20:23 +0800537 result = acpi_thermal_get_temperature(tz);
538 if (result)
539 return result;
540
Jean Delvare13614e32009-04-06 16:01:46 +0200541 *temp = KELVIN_TO_MILLICELSIUS(tz->temperature, tz->kelvin_offset);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000542 return 0;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800543}
544
Zhang Rui3f655ef2008-01-17 15:51:11 +0800545static int thermal_get_mode(struct thermal_zone_device *thermal,
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000546 enum thermal_device_mode *mode)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800547{
548 struct acpi_thermal *tz = thermal->devdata;
549
550 if (!tz)
551 return -EINVAL;
552
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000553 *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
554 THERMAL_DEVICE_DISABLED;
555
556 return 0;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800557}
558
559static int thermal_set_mode(struct thermal_zone_device *thermal,
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000560 enum thermal_device_mode mode)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800561{
562 struct acpi_thermal *tz = thermal->devdata;
563 int enable;
564
565 if (!tz)
566 return -EINVAL;
567
568 /*
569 * enable/disable thermal management from ACPI thermal driver
570 */
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000571 if (mode == THERMAL_DEVICE_ENABLED)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800572 enable = 1;
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000573 else if (mode == THERMAL_DEVICE_DISABLED)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800574 enable = 0;
575 else
576 return -EINVAL;
577
578 if (enable != tz->tz_enabled) {
579 tz->tz_enabled = enable;
580 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Zhang Rui8eaa8d62012-07-25 10:11:00 +0800581 "%s kernel ACPI thermal control\n",
582 tz->tz_enabled ? "Enable" : "Disable"));
Zhang Rui3f655ef2008-01-17 15:51:11 +0800583 acpi_thermal_check(tz);
584 }
585 return 0;
586}
587
588static int thermal_get_trip_type(struct thermal_zone_device *thermal,
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000589 int trip, enum thermal_trip_type *type)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800590{
591 struct acpi_thermal *tz = thermal->devdata;
592 int i;
593
594 if (!tz || trip < 0)
595 return -EINVAL;
596
597 if (tz->trips.critical.flags.valid) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000598 if (!trip) {
599 *type = THERMAL_TRIP_CRITICAL;
600 return 0;
601 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800602 trip--;
603 }
604
605 if (tz->trips.hot.flags.valid) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000606 if (!trip) {
607 *type = THERMAL_TRIP_HOT;
608 return 0;
609 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800610 trip--;
611 }
612
613 if (tz->trips.passive.flags.valid) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000614 if (!trip) {
615 *type = THERMAL_TRIP_PASSIVE;
616 return 0;
617 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800618 trip--;
619 }
620
621 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
622 tz->trips.active[i].flags.valid; i++) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000623 if (!trip) {
624 *type = THERMAL_TRIP_ACTIVE;
625 return 0;
626 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800627 trip--;
628 }
629
630 return -EINVAL;
631}
632
633static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000634 int trip, unsigned long *temp)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800635{
636 struct acpi_thermal *tz = thermal->devdata;
637 int i;
638
639 if (!tz || trip < 0)
640 return -EINVAL;
641
642 if (tz->trips.critical.flags.valid) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000643 if (!trip) {
644 *temp = KELVIN_TO_MILLICELSIUS(
Jean Delvare13614e32009-04-06 16:01:46 +0200645 tz->trips.critical.temperature,
646 tz->kelvin_offset);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000647 return 0;
648 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800649 trip--;
650 }
651
652 if (tz->trips.hot.flags.valid) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000653 if (!trip) {
654 *temp = KELVIN_TO_MILLICELSIUS(
Jean Delvare13614e32009-04-06 16:01:46 +0200655 tz->trips.hot.temperature,
656 tz->kelvin_offset);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000657 return 0;
658 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800659 trip--;
660 }
661
662 if (tz->trips.passive.flags.valid) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000663 if (!trip) {
664 *temp = KELVIN_TO_MILLICELSIUS(
Jean Delvare13614e32009-04-06 16:01:46 +0200665 tz->trips.passive.temperature,
666 tz->kelvin_offset);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000667 return 0;
668 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800669 trip--;
670 }
671
672 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
673 tz->trips.active[i].flags.valid; i++) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000674 if (!trip) {
675 *temp = KELVIN_TO_MILLICELSIUS(
Jean Delvare13614e32009-04-06 16:01:46 +0200676 tz->trips.active[i].temperature,
677 tz->kelvin_offset);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000678 return 0;
679 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800680 trip--;
681 }
682
683 return -EINVAL;
684}
685
Zhang, Rui9ec732f2008-04-10 16:13:10 +0800686static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
687 unsigned long *temperature) {
688 struct acpi_thermal *tz = thermal->devdata;
689
690 if (tz->trips.critical.flags.valid) {
691 *temperature = KELVIN_TO_MILLICELSIUS(
Jean Delvare13614e32009-04-06 16:01:46 +0200692 tz->trips.critical.temperature,
693 tz->kelvin_offset);
Zhang, Rui9ec732f2008-04-10 16:13:10 +0800694 return 0;
695 } else
696 return -EINVAL;
697}
698
Zhang Rui601f3d42012-06-27 09:54:33 +0800699static int thermal_get_trend(struct thermal_zone_device *thermal,
700 int trip, enum thermal_trend *trend)
701{
702 struct acpi_thermal *tz = thermal->devdata;
703 enum thermal_trip_type type;
704 int i;
705
706 if (thermal_get_trip_type(thermal, trip, &type))
707 return -EINVAL;
708
Zhang Rui4ae46be2012-06-27 10:05:39 +0800709 if (type == THERMAL_TRIP_ACTIVE) {
Zhang Rui94a40932013-04-26 09:19:53 +0000710 unsigned long trip_temp;
711 unsigned long temp = KELVIN_TO_MILLICELSIUS(tz->temperature,
712 tz->kelvin_offset);
713 if (thermal_get_trip_temp(thermal, trip, &trip_temp))
714 return -EINVAL;
715
716 if (temp > trip_temp) {
717 *trend = THERMAL_TREND_RAISING;
718 return 0;
719 } else {
720 /* Fall back on default trend */
721 return -EINVAL;
722 }
Zhang Rui4ae46be2012-06-27 10:05:39 +0800723 }
Zhang Rui601f3d42012-06-27 09:54:33 +0800724
725 /*
726 * tz->temperature has already been updated by generic thermal layer,
727 * before this callback being invoked
728 */
729 i = (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature))
730 + (tz->trips.passive.tc2
731 * (tz->temperature - tz->trips.passive.temperature));
732
733 if (i > 0)
734 *trend = THERMAL_TREND_RAISING;
735 else if (i < 0)
736 *trend = THERMAL_TREND_DROPPING;
737 else
738 *trend = THERMAL_TREND_STABLE;
739 return 0;
740}
741
742
Matthew Garrettb1569e92008-12-03 17:55:32 +0000743static int thermal_notify(struct thermal_zone_device *thermal, int trip,
744 enum thermal_trip_type trip_type)
745{
746 u8 type = 0;
747 struct acpi_thermal *tz = thermal->devdata;
748
749 if (trip_type == THERMAL_TRIP_CRITICAL)
750 type = ACPI_THERMAL_NOTIFY_CRITICAL;
751 else if (trip_type == THERMAL_TRIP_HOT)
752 type = ACPI_THERMAL_NOTIFY_HOT;
753 else
754 return 0;
755
Matthew Garrettb1569e92008-12-03 17:55:32 +0000756 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
Stephen Rothwellf6f5c452009-03-03 12:47:17 +1100757 dev_name(&tz->device->dev), type, 1);
Matthew Garrettb1569e92008-12-03 17:55:32 +0000758
759 if (trip_type == THERMAL_TRIP_CRITICAL && nocrt)
760 return 1;
761
762 return 0;
763}
764
Zhang Rui3f655ef2008-01-17 15:51:11 +0800765static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
766 struct thermal_cooling_device *cdev,
Zhang Rui9d998422012-06-26 16:35:57 +0800767 bool bind)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800768{
769 struct acpi_device *device = cdev->devdata;
770 struct acpi_thermal *tz = thermal->devdata;
Zhang Rui653a00c2008-01-17 15:51:18 +0800771 struct acpi_device *dev;
772 acpi_status status;
773 acpi_handle handle;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800774 int i;
775 int j;
776 int trip = -1;
777 int result = 0;
778
779 if (tz->trips.critical.flags.valid)
780 trip++;
781
782 if (tz->trips.hot.flags.valid)
783 trip++;
784
785 if (tz->trips.passive.flags.valid) {
786 trip++;
787 for (i = 0; i < tz->trips.passive.devices.count;
788 i++) {
Zhang Rui653a00c2008-01-17 15:51:18 +0800789 handle = tz->trips.passive.devices.handles[i];
790 status = acpi_bus_get_device(handle, &dev);
Zhang Rui9d998422012-06-26 16:35:57 +0800791 if (ACPI_FAILURE(status) || dev != device)
792 continue;
793 if (bind)
794 result =
795 thermal_zone_bind_cooling_device
796 (thermal, trip, cdev,
797 THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
798 else
799 result =
800 thermal_zone_unbind_cooling_device
801 (thermal, trip, cdev);
802 if (result)
803 goto failed;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800804 }
805 }
806
807 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
808 if (!tz->trips.active[i].flags.valid)
809 break;
810 trip++;
811 for (j = 0;
812 j < tz->trips.active[i].devices.count;
813 j++) {
Zhang Rui653a00c2008-01-17 15:51:18 +0800814 handle = tz->trips.active[i].devices.handles[j];
815 status = acpi_bus_get_device(handle, &dev);
Zhang Rui9d998422012-06-26 16:35:57 +0800816 if (ACPI_FAILURE(status) || dev != device)
817 continue;
818 if (bind)
819 result = thermal_zone_bind_cooling_device
820 (thermal, trip, cdev,
821 THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
822 else
823 result = thermal_zone_unbind_cooling_device
824 (thermal, trip, cdev);
825 if (result)
826 goto failed;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800827 }
828 }
829
830 for (i = 0; i < tz->devices.count; i++) {
Zhang Rui653a00c2008-01-17 15:51:18 +0800831 handle = tz->devices.handles[i];
832 status = acpi_bus_get_device(handle, &dev);
833 if (ACPI_SUCCESS(status) && (dev == device)) {
Zhang Rui9d998422012-06-26 16:35:57 +0800834 if (bind)
835 result = thermal_zone_bind_cooling_device
Lan Tianyu70f29032013-08-14 21:00:39 +0800836 (thermal, THERMAL_TRIPS_NONE,
837 cdev, THERMAL_NO_LIMIT,
Zhang Rui9d998422012-06-26 16:35:57 +0800838 THERMAL_NO_LIMIT);
839 else
840 result = thermal_zone_unbind_cooling_device
Lan Tianyu70f29032013-08-14 21:00:39 +0800841 (thermal, THERMAL_TRIPS_NONE,
842 cdev);
Zhang Rui653a00c2008-01-17 15:51:18 +0800843 if (result)
844 goto failed;
845 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800846 }
847
848failed:
849 return result;
850}
851
852static int
853acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
854 struct thermal_cooling_device *cdev)
855{
Zhang Rui9d998422012-06-26 16:35:57 +0800856 return acpi_thermal_cooling_device_cb(thermal, cdev, true);
Zhang Rui3f655ef2008-01-17 15:51:11 +0800857}
858
859static int
860acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
861 struct thermal_cooling_device *cdev)
862{
Zhang Rui9d998422012-06-26 16:35:57 +0800863 return acpi_thermal_cooling_device_cb(thermal, cdev, false);
Zhang Rui3f655ef2008-01-17 15:51:11 +0800864}
865
Vasiliy Kulikov9c8b04b2011-06-25 21:07:52 +0400866static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
Zhang Rui3f655ef2008-01-17 15:51:11 +0800867 .bind = acpi_thermal_bind_cooling_device,
868 .unbind = acpi_thermal_unbind_cooling_device,
869 .get_temp = thermal_get_temp,
870 .get_mode = thermal_get_mode,
871 .set_mode = thermal_set_mode,
872 .get_trip_type = thermal_get_trip_type,
873 .get_trip_temp = thermal_get_trip_temp,
Zhang, Rui9ec732f2008-04-10 16:13:10 +0800874 .get_crit_temp = thermal_get_crit_temp,
Zhang Rui601f3d42012-06-27 09:54:33 +0800875 .get_trend = thermal_get_trend,
Matthew Garrettb1569e92008-12-03 17:55:32 +0000876 .notify = thermal_notify,
Zhang Rui3f655ef2008-01-17 15:51:11 +0800877};
878
879static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
880{
881 int trips = 0;
882 int result;
Zhang Rui20733932008-01-17 15:51:21 +0800883 acpi_status status;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800884 int i;
885
886 if (tz->trips.critical.flags.valid)
887 trips++;
888
889 if (tz->trips.hot.flags.valid)
890 trips++;
891
892 if (tz->trips.passive.flags.valid)
893 trips++;
894
895 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
896 tz->trips.active[i].flags.valid; i++, trips++);
Matthew Garrettb1569e92008-12-03 17:55:32 +0000897
898 if (tz->trips.passive.flags.valid)
899 tz->thermal_zone =
Durgadoss Rc56f5c02012-07-25 10:10:58 +0800900 thermal_zone_device_register("acpitz", trips, 0, tz,
Durgadoss R50125a92012-09-18 11:04:56 +0530901 &acpi_thermal_zone_ops, NULL,
Matthew Garrettb1569e92008-12-03 17:55:32 +0000902 tz->trips.passive.tsp*100,
903 tz->polling_frequency*100);
904 else
905 tz->thermal_zone =
Durgadoss Rc56f5c02012-07-25 10:10:58 +0800906 thermal_zone_device_register("acpitz", trips, 0, tz,
Durgadoss R50125a92012-09-18 11:04:56 +0530907 &acpi_thermal_zone_ops, NULL,
908 0, tz->polling_frequency*100);
Krzysztof Heltbb070e42008-04-08 17:41:52 -0700909 if (IS_ERR(tz->thermal_zone))
Zhang Rui3f655ef2008-01-17 15:51:11 +0800910 return -ENODEV;
911
912 result = sysfs_create_link(&tz->device->dev.kobj,
913 &tz->thermal_zone->device.kobj, "thermal_zone");
914 if (result)
915 return result;
916
917 result = sysfs_create_link(&tz->thermal_zone->device.kobj,
918 &tz->device->dev.kobj, "device");
919 if (result)
920 return result;
921
Zhang Rui20733932008-01-17 15:51:21 +0800922 status = acpi_attach_data(tz->device->handle,
923 acpi_bus_private_data_handler,
924 tz->thermal_zone);
925 if (ACPI_FAILURE(status)) {
Lin Ming55ac9a02008-09-28 14:51:56 +0800926 printk(KERN_ERR PREFIX
927 "Error attaching device data\n");
Zhang Rui20733932008-01-17 15:51:21 +0800928 return -ENODEV;
929 }
930
Zhang Rui3f655ef2008-01-17 15:51:11 +0800931 tz->tz_enabled = 1;
932
Greg Kroah-Hartmanfc3a8822008-05-02 06:02:41 +0200933 dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
934 tz->thermal_zone->id);
Zhang Rui3f655ef2008-01-17 15:51:11 +0800935 return 0;
936}
937
938static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
939{
940 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
941 sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
942 thermal_zone_device_unregister(tz->thermal_zone);
943 tz->thermal_zone = NULL;
Zhang Rui20733932008-01-17 15:51:21 +0800944 acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler);
Zhang Rui3f655ef2008-01-17 15:51:11 +0800945}
946
947
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948/* --------------------------------------------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 Driver Interface
950 -------------------------------------------------------------------------- */
951
Bjorn Helgaas342d5502009-04-07 15:37:06 +0000952static void acpi_thermal_notify(struct acpi_device *device, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953{
Bjorn Helgaas342d5502009-04-07 15:37:06 +0000954 struct acpi_thermal *tz = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
957 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400958 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 switch (event) {
961 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
962 acpi_thermal_check(tz);
963 break;
964 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
Zhang Ruice44e192008-01-17 15:51:25 +0800965 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 acpi_thermal_check(tz);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800967 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100968 dev_name(&device->dev), event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 break;
970 case ACPI_THERMAL_NOTIFY_DEVICES:
Zhang Ruice44e192008-01-17 15:51:25 +0800971 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES);
972 acpi_thermal_check(tz);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800973 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100974 dev_name(&device->dev), event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 break;
976 default:
977 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400978 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 break;
980 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981}
982
Zhang Rui261cba22012-11-27 20:42:11 +0100983/*
984 * On some platforms, the AML code has dependency about
985 * the evaluating order of _TMP and _CRT/_HOT/_PSV/_ACx.
986 * 1. On HP Pavilion G4-1016tx, _TMP must be invoked after
987 * /_CRT/_HOT/_PSV/_ACx, or else system will be power off.
988 * 2. On HP Compaq 6715b/6715s, the return value of _PSV is 0
989 * if _TMP has never been evaluated.
990 *
991 * As this dependency is totally transparent to OS, evaluate
992 * all of them once, in the order of _CRT/_HOT/_PSV/_ACx,
993 * _TMP, before they are actually used.
994 */
995static void acpi_thermal_aml_dependency_fix(struct acpi_thermal *tz)
996{
997 acpi_handle handle = tz->device->handle;
998 unsigned long long value;
999 int i;
1000
1001 acpi_evaluate_integer(handle, "_CRT", NULL, &value);
1002 acpi_evaluate_integer(handle, "_HOT", NULL, &value);
1003 acpi_evaluate_integer(handle, "_PSV", NULL, &value);
1004 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1005 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
1006 acpi_status status;
1007
1008 status = acpi_evaluate_integer(handle, name, NULL, &value);
1009 if (status == AE_NOT_FOUND)
1010 break;
1011 }
1012 acpi_evaluate_integer(handle, "_TMP", NULL, &value);
1013}
1014
Len Brown4be44fc2005-08-05 00:44:28 -04001015static int acpi_thermal_get_info(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016{
Len Brown4be44fc2005-08-05 00:44:28 -04001017 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
1020 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -04001021 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
Zhang Rui261cba22012-11-27 20:42:11 +01001023 acpi_thermal_aml_dependency_fix(tz);
1024
Matthew Garrett9bcb8112012-02-01 10:26:54 -05001025 /* Get trip points [_CRT, _PSV, etc.] (required) */
1026 result = acpi_thermal_get_trip_points(tz);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001028 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
Matthew Garrett9bcb8112012-02-01 10:26:54 -05001030 /* Get temperature [_TMP] (required) */
1031 result = acpi_thermal_get_temperature(tz);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001033 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034
1035 /* Set the cooling mode [_SCP] to active cooling (default) */
1036 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
Len Brown4be44fc2005-08-05 00:44:28 -04001037 if (!result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 tz->flags.cooling_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
1040 /* Get default polling frequency [_TZP] (optional) */
1041 if (tzp)
1042 tz->polling_frequency = tzp;
1043 else
1044 acpi_thermal_get_polling_frequency(tz);
1045
Patrick Mocheld550d982006-06-27 00:41:40 -04001046 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047}
1048
Jean Delvare13614e32009-04-06 16:01:46 +02001049/*
1050 * The exact offset between Kelvin and degree Celsius is 273.15. However ACPI
1051 * handles temperature values with a single decimal place. As a consequence,
1052 * some implementations use an offset of 273.1 and others use an offset of
1053 * 273.2. Try to find out which one is being used, to present the most
1054 * accurate and visually appealing number.
1055 *
1056 * The heuristic below should work for all ACPI thermal zones which have a
1057 * critical trip point with a value being a multiple of 0.5 degree Celsius.
1058 */
1059static void acpi_thermal_guess_offset(struct acpi_thermal *tz)
1060{
1061 if (tz->trips.critical.flags.valid &&
1062 (tz->trips.critical.temperature % 5) == 1)
1063 tz->kelvin_offset = 2731;
1064 else
1065 tz->kelvin_offset = 2732;
1066}
1067
Len Brown4be44fc2005-08-05 00:44:28 -04001068static int acpi_thermal_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069{
Len Brown4be44fc2005-08-05 00:44:28 -04001070 int result = 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001071 struct acpi_thermal *tz = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
1074 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001075 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
Burman Yan36bcbec2006-12-19 12:56:11 -08001077 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -04001079 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
Patrick Mochel8348e1b2006-05-19 16:54:40 -04001081 tz->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 strcpy(tz->name, device->pnp.bus_id);
1083 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1084 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07001085 device->driver_data = tz;
Zhang Rui3f655ef2008-01-17 15:51:11 +08001086
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 result = acpi_thermal_get_info(tz);
1088 if (result)
Zhang Rui3f655ef2008-01-17 15:51:11 +08001089 goto free_memory;
1090
Jean Delvare13614e32009-04-06 16:01:46 +02001091 acpi_thermal_guess_offset(tz);
1092
Zhang Rui3f655ef2008-01-17 15:51:11 +08001093 result = acpi_thermal_register_thermal_zone(tz);
1094 if (result)
1095 goto free_memory;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001098 acpi_device_name(device), acpi_device_bid(device),
1099 KELVIN_TO_CELSIUS(tz->temperature));
Zhang Rui3f655ef2008-01-17 15:51:11 +08001100 goto end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
Zhang Rui3f655ef2008-01-17 15:51:11 +08001102free_memory:
1103 kfree(tz);
1104end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001105 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106}
1107
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01001108static int acpi_thermal_remove(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109{
Len Brown4be44fc2005-08-05 00:44:28 -04001110 struct acpi_thermal *tz = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001113 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001115 tz = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
Zhang Rui3f655ef2008-01-17 15:51:11 +08001117 acpi_thermal_unregister_thermal_zone(tz);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 kfree(tz);
Patrick Mocheld550d982006-06-27 00:41:40 -04001119 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120}
1121
Rafael J. Wysocki90692402012-08-09 23:00:02 +02001122#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki167cffb2012-06-27 23:26:18 +02001123static int acpi_thermal_resume(struct device *dev)
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001124{
Rafael J. Wysocki167cffb2012-06-27 23:26:18 +02001125 struct acpi_thermal *tz;
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001126 int i, j, power_state, result;
1127
Rafael J. Wysocki167cffb2012-06-27 23:26:18 +02001128 if (!dev)
Patrick Mocheld550d982006-06-27 00:41:40 -04001129 return -EINVAL;
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001130
Rafael J. Wysocki167cffb2012-06-27 23:26:18 +02001131 tz = acpi_driver_data(to_acpi_device(dev));
1132 if (!tz)
1133 return -EINVAL;
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001134
Konstantin Karasyovbed936f2006-07-10 04:44:26 -07001135 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001136 if (!(&tz->trips.active[i]))
1137 break;
1138 if (!tz->trips.active[i].flags.valid)
1139 break;
1140 tz->trips.active[i].flags.enabled = 1;
1141 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
Rafael J. Wysocki488a76c2010-11-25 00:11:24 +01001142 result = acpi_bus_update_power(
1143 tz->trips.active[i].devices.handles[j],
1144 &power_state);
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001145 if (result || (power_state != ACPI_STATE_D0)) {
1146 tz->trips.active[i].flags.enabled = 0;
1147 break;
1148 }
Konstantin Karasyovbed936f2006-07-10 04:44:26 -07001149 }
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001150 tz->state.active |= tz->trips.active[i].flags.enabled;
Konstantin Karasyovbed936f2006-07-10 04:44:26 -07001151 }
1152
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001153 acpi_thermal_check(tz);
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001154
1155 return AE_OK;
1156}
Rafael J. Wysocki90692402012-08-09 23:00:02 +02001157#endif
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001158
Jeff Garzik18552562007-10-03 15:15:40 -04001159static int thermal_act(const struct dmi_system_id *d) {
Len Brown0b5bfa12007-08-12 00:13:02 -04001160
1161 if (act == 0) {
1162 printk(KERN_NOTICE "ACPI: %s detected: "
1163 "disabling all active thermal trip points\n", d->ident);
1164 act = -1;
1165 }
1166 return 0;
1167}
Jeff Garzik18552562007-10-03 15:15:40 -04001168static int thermal_nocrt(const struct dmi_system_id *d) {
Len Brown8c99fdc2007-08-20 18:46:50 -04001169
1170 printk(KERN_NOTICE "ACPI: %s detected: "
1171 "disabling all critical thermal trip point actions.\n", d->ident);
1172 nocrt = 1;
1173 return 0;
1174}
Jeff Garzik18552562007-10-03 15:15:40 -04001175static int thermal_tzp(const struct dmi_system_id *d) {
Len Brown0b5bfa12007-08-12 00:13:02 -04001176
1177 if (tzp == 0) {
1178 printk(KERN_NOTICE "ACPI: %s detected: "
1179 "enabling thermal zone polling\n", d->ident);
1180 tzp = 300; /* 300 dS = 30 Seconds */
1181 }
1182 return 0;
1183}
Jeff Garzik18552562007-10-03 15:15:40 -04001184static int thermal_psv(const struct dmi_system_id *d) {
Len Brown0b5bfa12007-08-12 00:13:02 -04001185
1186 if (psv == 0) {
1187 printk(KERN_NOTICE "ACPI: %s detected: "
1188 "disabling all passive thermal trip points\n", d->ident);
1189 psv = -1;
1190 }
1191 return 0;
1192}
1193
1194static struct dmi_system_id thermal_dmi_table[] __initdata = {
1195 /*
1196 * Award BIOS on this AOpen makes thermal control almost worthless.
1197 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1198 */
1199 {
1200 .callback = thermal_act,
1201 .ident = "AOpen i915GMm-HFS",
1202 .matches = {
1203 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1204 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1205 },
1206 },
1207 {
1208 .callback = thermal_psv,
1209 .ident = "AOpen i915GMm-HFS",
1210 .matches = {
1211 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1212 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1213 },
1214 },
1215 {
1216 .callback = thermal_tzp,
1217 .ident = "AOpen i915GMm-HFS",
1218 .matches = {
1219 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1220 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1221 },
1222 },
Len Brown8c99fdc2007-08-20 18:46:50 -04001223 {
1224 .callback = thermal_nocrt,
1225 .ident = "Gigabyte GA-7ZX",
1226 .matches = {
1227 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
1228 DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
1229 },
1230 },
Len Brown0b5bfa12007-08-12 00:13:02 -04001231 {}
1232};
Len Brown0b5bfa12007-08-12 00:13:02 -04001233
Len Brown4be44fc2005-08-05 00:44:28 -04001234static int __init acpi_thermal_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235{
Len Brown4be44fc2005-08-05 00:44:28 -04001236 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
Len Brown0b5bfa12007-08-12 00:13:02 -04001238 dmi_check_system(thermal_dmi_table);
1239
Len Brown72b33ef2007-08-12 00:12:17 -04001240 if (off) {
1241 printk(KERN_NOTICE "ACPI: thermal control disabled\n");
1242 return -ENODEV;
1243 }
Zhang Rui43d9f872010-07-15 10:46:44 +08001244
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 result = acpi_bus_register_driver(&acpi_thermal_driver);
Zhang Ruic57b62f2010-10-08 13:55:06 +08001246 if (result < 0)
Patrick Mocheld550d982006-06-27 00:41:40 -04001247 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
Patrick Mocheld550d982006-06-27 00:41:40 -04001249 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250}
1251
Len Brown4be44fc2005-08-05 00:44:28 -04001252static void __exit acpi_thermal_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
1255 acpi_bus_unregister_driver(&acpi_thermal_driver);
1256
Patrick Mocheld550d982006-06-27 00:41:40 -04001257 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258}
1259
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260module_init(acpi_thermal_init);
1261module_exit(acpi_thermal_exit);