blob: 0055c83c26c009eb59094f0678cad651ae201f36 [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{
Len Brown4be44fc2005-08-05 00:44:28 -0400236 acpi_status status = AE_OK;
237 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
238 struct acpi_object_list arg_list = { 1, &arg0 };
239 acpi_handle handle = NULL;
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
Patrick Mochel38ba7c92006-05-19 16:54:48 -0400245 status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 if (ACPI_FAILURE(status)) {
247 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400248 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 }
250
251 arg0.integer.value = mode;
252
253 status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
254 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400255 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Patrick Mocheld550d982006-06-27 00:41:40 -0400257 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258}
259
Zhang Ruice44e192008-01-17 15:51:25 +0800260#define ACPI_TRIPS_CRITICAL 0x01
261#define ACPI_TRIPS_HOT 0x02
262#define ACPI_TRIPS_PASSIVE 0x04
263#define ACPI_TRIPS_ACTIVE 0x08
264#define ACPI_TRIPS_DEVICES 0x10
265
266#define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE)
267#define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES
268
269#define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \
270 ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \
271 ACPI_TRIPS_DEVICES)
272
273/*
274 * This exception is thrown out in two cases:
275 * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
276 * when re-evaluating the AML code.
277 * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change.
278 * We need to re-bind the cooling devices of a thermal zone when this occurs.
279 */
280#define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \
281do { \
282 if (flags != ACPI_TRIPS_INIT) \
283 ACPI_EXCEPTION((AE_INFO, AE_ERROR, \
284 "ACPI thermal trip point %s changed\n" \
Colin Ian King7e3cf242012-11-29 11:53:16 +0000285 "Please send acpidump to linux-acpi@vger.kernel.org", str)); \
Zhang Ruice44e192008-01-17 15:51:25 +0800286} while (0)
287
288static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
Len Brown4be44fc2005-08-05 00:44:28 -0400290 acpi_status status = AE_OK;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400291 unsigned long long tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800292 struct acpi_handle_list devices;
293 int valid = 0;
294 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Thomas Renningerfa809452010-02-20 11:44:27 +0100296 /* Critical Shutdown */
Zhang Ruice44e192008-01-17 15:51:25 +0800297 if (flag & ACPI_TRIPS_CRITICAL) {
298 status = acpi_evaluate_integer(tz->device->handle,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400299 "_CRT", NULL, &tmp);
300 tz->trips.critical.temperature = tmp;
Arjan van de Vena39a2d72008-05-19 15:55:15 -0700301 /*
302 * Treat freezing temperatures as invalid as well; some
303 * BIOSes return really low values and cause reboots at startup.
Adam Buchbinderb731d7b2009-03-13 12:15:26 -0400304 * Below zero (Celsius) values clearly aren't right for sure..
Arjan van de Vena39a2d72008-05-19 15:55:15 -0700305 * ... so lets discard those as invalid.
306 */
Thomas Renningerfa809452010-02-20 11:44:27 +0100307 if (ACPI_FAILURE(status)) {
Len Brownc52a7412007-08-14 15:49:32 -0400308 tz->trips.critical.flags.valid = 0;
Thomas Renningerfa809452010-02-20 11:44:27 +0100309 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
310 "No critical threshold\n"));
311 } else if (tmp <= 2732) {
312 printk(KERN_WARNING FW_BUG "Invalid critical threshold "
313 "(%llu)\n", tmp);
314 tz->trips.critical.flags.valid = 0;
Zhang Ruice44e192008-01-17 15:51:25 +0800315 } else {
316 tz->trips.critical.flags.valid = 1;
317 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Thomas Renningerfa809452010-02-20 11:44:27 +0100318 "Found critical threshold [%lu]\n",
319 tz->trips.critical.temperature));
Zhang Ruice44e192008-01-17 15:51:25 +0800320 }
321 if (tz->trips.critical.flags.valid == 1) {
322 if (crt == -1) {
323 tz->trips.critical.flags.valid = 0;
324 } else if (crt > 0) {
325 unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
326 /*
Zhang Rui22a94d72008-10-17 02:41:20 -0400327 * Allow override critical threshold
Zhang Ruice44e192008-01-17 15:51:25 +0800328 */
Zhang Rui22a94d72008-10-17 02:41:20 -0400329 if (crt_k > tz->trips.critical.temperature)
330 printk(KERN_WARNING PREFIX
331 "Critical threshold %d C\n", crt);
332 tz->trips.critical.temperature = crt_k;
Zhang Ruice44e192008-01-17 15:51:25 +0800333 }
Len Brownc52a7412007-08-14 15:49:32 -0400334 }
335 }
336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 /* Critical Sleep (optional) */
Zhang Ruice44e192008-01-17 15:51:25 +0800338 if (flag & ACPI_TRIPS_HOT) {
Len Browna70cdc52007-08-12 00:12:35 -0400339 status = acpi_evaluate_integer(tz->device->handle,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400340 "_HOT", NULL, &tmp);
Zhang Ruice44e192008-01-17 15:51:25 +0800341 if (ACPI_FAILURE(status)) {
342 tz->trips.hot.flags.valid = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400343 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Zhang Ruice44e192008-01-17 15:51:25 +0800344 "No hot threshold\n"));
345 } else {
Matthew Wilcox27663c52008-10-10 02:22:59 -0400346 tz->trips.hot.temperature = tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800347 tz->trips.hot.flags.valid = 1;
348 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
349 "Found hot threshold [%lu]\n",
350 tz->trips.critical.temperature));
351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 }
353
Zhang Ruice44e192008-01-17 15:51:25 +0800354 /* Passive (optional) */
Zhang Rui0e4240d2009-01-16 12:53:42 -0500355 if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) ||
356 (flag == ACPI_TRIPS_INIT)) {
Zhang Ruice44e192008-01-17 15:51:25 +0800357 valid = tz->trips.passive.flags.valid;
358 if (psv == -1) {
359 status = AE_SUPPORT;
360 } else if (psv > 0) {
Matthew Wilcox27663c52008-10-10 02:22:59 -0400361 tmp = CELSIUS_TO_KELVIN(psv);
Zhang Ruice44e192008-01-17 15:51:25 +0800362 status = AE_OK;
363 } else {
364 status = acpi_evaluate_integer(tz->device->handle,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400365 "_PSV", NULL, &tmp);
Zhang Ruice44e192008-01-17 15:51:25 +0800366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Zhang Ruice44e192008-01-17 15:51:25 +0800368 if (ACPI_FAILURE(status))
369 tz->trips.passive.flags.valid = 0;
370 else {
Matthew Wilcox27663c52008-10-10 02:22:59 -0400371 tz->trips.passive.temperature = tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800372 tz->trips.passive.flags.valid = 1;
373 if (flag == ACPI_TRIPS_INIT) {
374 status = acpi_evaluate_integer(
375 tz->device->handle, "_TC1",
Matthew Wilcox27663c52008-10-10 02:22:59 -0400376 NULL, &tmp);
Zhang Ruice44e192008-01-17 15:51:25 +0800377 if (ACPI_FAILURE(status))
378 tz->trips.passive.flags.valid = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400379 else
380 tz->trips.passive.tc1 = tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800381 status = acpi_evaluate_integer(
382 tz->device->handle, "_TC2",
Matthew Wilcox27663c52008-10-10 02:22:59 -0400383 NULL, &tmp);
Zhang Ruice44e192008-01-17 15:51:25 +0800384 if (ACPI_FAILURE(status))
385 tz->trips.passive.flags.valid = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400386 else
387 tz->trips.passive.tc2 = tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800388 status = acpi_evaluate_integer(
389 tz->device->handle, "_TSP",
Matthew Wilcox27663c52008-10-10 02:22:59 -0400390 NULL, &tmp);
Zhang Ruice44e192008-01-17 15:51:25 +0800391 if (ACPI_FAILURE(status))
392 tz->trips.passive.flags.valid = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400393 else
394 tz->trips.passive.tsp = tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800395 }
396 }
397 }
398 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) {
399 memset(&devices, 0, sizeof(struct acpi_handle_list));
400 status = acpi_evaluate_reference(tz->device->handle, "_PSL",
401 NULL, &devices);
Zhang Rui0e4240d2009-01-16 12:53:42 -0500402 if (ACPI_FAILURE(status)) {
403 printk(KERN_WARNING PREFIX
404 "Invalid passive threshold\n");
Zhang Ruice44e192008-01-17 15:51:25 +0800405 tz->trips.passive.flags.valid = 0;
Zhang Rui0e4240d2009-01-16 12:53:42 -0500406 }
Zhang Ruice44e192008-01-17 15:51:25 +0800407 else
408 tz->trips.passive.flags.valid = 1;
409
410 if (memcmp(&tz->trips.passive.devices, &devices,
411 sizeof(struct acpi_handle_list))) {
412 memcpy(&tz->trips.passive.devices, &devices,
413 sizeof(struct acpi_handle_list));
414 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
415 }
416 }
417 if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) {
418 if (valid != tz->trips.passive.flags.valid)
419 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
420 }
421
422 /* Active (optional) */
Len Brown4be44fc2005-08-05 00:44:28 -0400423 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400424 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
Zhang Ruice44e192008-01-17 15:51:25 +0800425 valid = tz->trips.active[i].flags.valid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Len Brownf8707ec2007-08-12 00:12:54 -0400427 if (act == -1)
Zhang Ruice44e192008-01-17 15:51:25 +0800428 break; /* disable all active trip points */
Len Brownf8707ec2007-08-12 00:12:54 -0400429
Zhang Rui0e4240d2009-01-16 12:53:42 -0500430 if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) &&
431 tz->trips.active[i].flags.valid)) {
Zhang Ruice44e192008-01-17 15:51:25 +0800432 status = acpi_evaluate_integer(tz->device->handle,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400433 name, NULL, &tmp);
Zhang Ruice44e192008-01-17 15:51:25 +0800434 if (ACPI_FAILURE(status)) {
435 tz->trips.active[i].flags.valid = 0;
436 if (i == 0)
437 break;
438 if (act <= 0)
439 break;
440 if (i == 1)
441 tz->trips.active[0].temperature =
442 CELSIUS_TO_KELVIN(act);
443 else
444 /*
445 * Don't allow override higher than
446 * the next higher trip point
447 */
448 tz->trips.active[i - 1].temperature =
449 (tz->trips.active[i - 2].temperature <
450 CELSIUS_TO_KELVIN(act) ?
451 tz->trips.active[i - 2].temperature :
452 CELSIUS_TO_KELVIN(act));
Len Brownf8707ec2007-08-12 00:12:54 -0400453 break;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400454 } else {
455 tz->trips.active[i].temperature = tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800456 tz->trips.active[i].flags.valid = 1;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400457 }
Len Brownf8707ec2007-08-12 00:12:54 -0400458 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460 name[2] = 'L';
Zhang Ruice44e192008-01-17 15:51:25 +0800461 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) {
462 memset(&devices, 0, sizeof(struct acpi_handle_list));
463 status = acpi_evaluate_reference(tz->device->handle,
464 name, NULL, &devices);
Zhang Rui0e4240d2009-01-16 12:53:42 -0500465 if (ACPI_FAILURE(status)) {
466 printk(KERN_WARNING PREFIX
467 "Invalid active%d threshold\n", i);
Zhang Ruice44e192008-01-17 15:51:25 +0800468 tz->trips.active[i].flags.valid = 0;
Zhang Rui0e4240d2009-01-16 12:53:42 -0500469 }
Zhang Ruice44e192008-01-17 15:51:25 +0800470 else
471 tz->trips.active[i].flags.valid = 1;
472
473 if (memcmp(&tz->trips.active[i].devices, &devices,
474 sizeof(struct acpi_handle_list))) {
475 memcpy(&tz->trips.active[i].devices, &devices,
476 sizeof(struct acpi_handle_list));
477 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
478 }
479 }
480 if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES))
481 if (valid != tz->trips.active[i].flags.valid)
482 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
483
484 if (!tz->trips.active[i].flags.valid)
485 break;
486 }
487
Lan Tianyu668e0202013-08-27 16:29:31 +0800488 if ((flag & ACPI_TRIPS_DEVICES)
489 && acpi_has_method(tz->device->handle, "_TZD")) {
490 memset(&devices, 0, sizeof(devices));
Zhang Ruice44e192008-01-17 15:51:25 +0800491 status = acpi_evaluate_reference(tz->device->handle, "_TZD",
492 NULL, &devices);
Lan Tianyu668e0202013-08-27 16:29:31 +0800493 if (ACPI_SUCCESS(status)
494 && memcmp(&tz->devices, &devices, sizeof(devices))) {
495 tz->devices = devices;
Zhang Ruice44e192008-01-17 15:51:25 +0800496 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
497 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
499
Patrick Mocheld550d982006-06-27 00:41:40 -0400500 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501}
502
Zhang Ruice44e192008-01-17 15:51:25 +0800503static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
Thomas Renninger8b7ef6d2010-02-16 22:55:51 +0100505 int i, valid, ret = acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
506
507 if (ret)
508 return ret;
509
510 valid = tz->trips.critical.flags.valid |
511 tz->trips.hot.flags.valid |
512 tz->trips.passive.flags.valid;
513
514 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
515 valid |= tz->trips.active[i].flags.valid;
516
517 if (!valid) {
518 printk(KERN_WARNING FW_BUG "No valid trip found\n");
519 return -ENODEV;
520 }
521 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522}
523
Len Brown4be44fc2005-08-05 00:44:28 -0400524static void acpi_thermal_check(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200526 struct acpi_thermal *tz = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Srinivas Pandruvadaca4e7132013-01-15 23:57:16 +0100528 if (!tz->tz_enabled) {
529 pr_warn("thermal zone is disabled \n");
530 return;
531 }
Matthew Garrettb1569e92008-12-03 17:55:32 +0000532 thermal_zone_device_update(tz->thermal_zone);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533}
534
Zhang Rui3f655ef2008-01-17 15:51:11 +0800535/* sys I/F for generic thermal sysfs support */
Jean Delvare13614e32009-04-06 16:01:46 +0200536#define KELVIN_TO_MILLICELSIUS(t, off) (((t) - (off)) * 100)
Zhang, Rui5e012762008-02-28 07:51:30 +0800537
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000538static int thermal_get_temp(struct thermal_zone_device *thermal,
539 unsigned long *temp)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800540{
541 struct acpi_thermal *tz = thermal->devdata;
Zhang, Rui76ecb4f2008-04-10 16:20:23 +0800542 int result;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800543
544 if (!tz)
545 return -EINVAL;
546
Zhang, Rui76ecb4f2008-04-10 16:20:23 +0800547 result = acpi_thermal_get_temperature(tz);
548 if (result)
549 return result;
550
Jean Delvare13614e32009-04-06 16:01:46 +0200551 *temp = KELVIN_TO_MILLICELSIUS(tz->temperature, tz->kelvin_offset);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000552 return 0;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800553}
554
Zhang Rui3f655ef2008-01-17 15:51:11 +0800555static int thermal_get_mode(struct thermal_zone_device *thermal,
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000556 enum thermal_device_mode *mode)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800557{
558 struct acpi_thermal *tz = thermal->devdata;
559
560 if (!tz)
561 return -EINVAL;
562
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000563 *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
564 THERMAL_DEVICE_DISABLED;
565
566 return 0;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800567}
568
569static int thermal_set_mode(struct thermal_zone_device *thermal,
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000570 enum thermal_device_mode mode)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800571{
572 struct acpi_thermal *tz = thermal->devdata;
573 int enable;
574
575 if (!tz)
576 return -EINVAL;
577
578 /*
579 * enable/disable thermal management from ACPI thermal driver
580 */
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000581 if (mode == THERMAL_DEVICE_ENABLED)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800582 enable = 1;
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000583 else if (mode == THERMAL_DEVICE_DISABLED)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800584 enable = 0;
585 else
586 return -EINVAL;
587
588 if (enable != tz->tz_enabled) {
589 tz->tz_enabled = enable;
590 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Zhang Rui8eaa8d62012-07-25 10:11:00 +0800591 "%s kernel ACPI thermal control\n",
592 tz->tz_enabled ? "Enable" : "Disable"));
Zhang Rui3f655ef2008-01-17 15:51:11 +0800593 acpi_thermal_check(tz);
594 }
595 return 0;
596}
597
598static int thermal_get_trip_type(struct thermal_zone_device *thermal,
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000599 int trip, enum thermal_trip_type *type)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800600{
601 struct acpi_thermal *tz = thermal->devdata;
602 int i;
603
604 if (!tz || trip < 0)
605 return -EINVAL;
606
607 if (tz->trips.critical.flags.valid) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000608 if (!trip) {
609 *type = THERMAL_TRIP_CRITICAL;
610 return 0;
611 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800612 trip--;
613 }
614
615 if (tz->trips.hot.flags.valid) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000616 if (!trip) {
617 *type = THERMAL_TRIP_HOT;
618 return 0;
619 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800620 trip--;
621 }
622
623 if (tz->trips.passive.flags.valid) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000624 if (!trip) {
625 *type = THERMAL_TRIP_PASSIVE;
626 return 0;
627 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800628 trip--;
629 }
630
631 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
632 tz->trips.active[i].flags.valid; i++) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000633 if (!trip) {
634 *type = THERMAL_TRIP_ACTIVE;
635 return 0;
636 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800637 trip--;
638 }
639
640 return -EINVAL;
641}
642
643static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000644 int trip, unsigned long *temp)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800645{
646 struct acpi_thermal *tz = thermal->devdata;
647 int i;
648
649 if (!tz || trip < 0)
650 return -EINVAL;
651
652 if (tz->trips.critical.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.critical.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.hot.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.hot.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 if (tz->trips.passive.flags.valid) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000673 if (!trip) {
674 *temp = KELVIN_TO_MILLICELSIUS(
Jean Delvare13614e32009-04-06 16:01:46 +0200675 tz->trips.passive.temperature,
676 tz->kelvin_offset);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000677 return 0;
678 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800679 trip--;
680 }
681
682 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
683 tz->trips.active[i].flags.valid; i++) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000684 if (!trip) {
685 *temp = KELVIN_TO_MILLICELSIUS(
Jean Delvare13614e32009-04-06 16:01:46 +0200686 tz->trips.active[i].temperature,
687 tz->kelvin_offset);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000688 return 0;
689 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800690 trip--;
691 }
692
693 return -EINVAL;
694}
695
Zhang, Rui9ec732f2008-04-10 16:13:10 +0800696static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
697 unsigned long *temperature) {
698 struct acpi_thermal *tz = thermal->devdata;
699
700 if (tz->trips.critical.flags.valid) {
701 *temperature = KELVIN_TO_MILLICELSIUS(
Jean Delvare13614e32009-04-06 16:01:46 +0200702 tz->trips.critical.temperature,
703 tz->kelvin_offset);
Zhang, Rui9ec732f2008-04-10 16:13:10 +0800704 return 0;
705 } else
706 return -EINVAL;
707}
708
Zhang Rui601f3d42012-06-27 09:54:33 +0800709static int thermal_get_trend(struct thermal_zone_device *thermal,
710 int trip, enum thermal_trend *trend)
711{
712 struct acpi_thermal *tz = thermal->devdata;
713 enum thermal_trip_type type;
714 int i;
715
716 if (thermal_get_trip_type(thermal, trip, &type))
717 return -EINVAL;
718
Zhang Rui4ae46be2012-06-27 10:05:39 +0800719 if (type == THERMAL_TRIP_ACTIVE) {
Zhang Rui94a40932013-04-26 09:19:53 +0000720 unsigned long trip_temp;
721 unsigned long temp = KELVIN_TO_MILLICELSIUS(tz->temperature,
722 tz->kelvin_offset);
723 if (thermal_get_trip_temp(thermal, trip, &trip_temp))
724 return -EINVAL;
725
726 if (temp > trip_temp) {
727 *trend = THERMAL_TREND_RAISING;
728 return 0;
729 } else {
730 /* Fall back on default trend */
731 return -EINVAL;
732 }
Zhang Rui4ae46be2012-06-27 10:05:39 +0800733 }
Zhang Rui601f3d42012-06-27 09:54:33 +0800734
735 /*
736 * tz->temperature has already been updated by generic thermal layer,
737 * before this callback being invoked
738 */
739 i = (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature))
740 + (tz->trips.passive.tc2
741 * (tz->temperature - tz->trips.passive.temperature));
742
743 if (i > 0)
744 *trend = THERMAL_TREND_RAISING;
745 else if (i < 0)
746 *trend = THERMAL_TREND_DROPPING;
747 else
748 *trend = THERMAL_TREND_STABLE;
749 return 0;
750}
751
752
Matthew Garrettb1569e92008-12-03 17:55:32 +0000753static int thermal_notify(struct thermal_zone_device *thermal, int trip,
754 enum thermal_trip_type trip_type)
755{
756 u8 type = 0;
757 struct acpi_thermal *tz = thermal->devdata;
758
759 if (trip_type == THERMAL_TRIP_CRITICAL)
760 type = ACPI_THERMAL_NOTIFY_CRITICAL;
761 else if (trip_type == THERMAL_TRIP_HOT)
762 type = ACPI_THERMAL_NOTIFY_HOT;
763 else
764 return 0;
765
Matthew Garrettb1569e92008-12-03 17:55:32 +0000766 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
Stephen Rothwellf6f5c452009-03-03 12:47:17 +1100767 dev_name(&tz->device->dev), type, 1);
Matthew Garrettb1569e92008-12-03 17:55:32 +0000768
769 if (trip_type == THERMAL_TRIP_CRITICAL && nocrt)
770 return 1;
771
772 return 0;
773}
774
Zhang Rui3f655ef2008-01-17 15:51:11 +0800775static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
776 struct thermal_cooling_device *cdev,
Zhang Rui9d998422012-06-26 16:35:57 +0800777 bool bind)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800778{
779 struct acpi_device *device = cdev->devdata;
780 struct acpi_thermal *tz = thermal->devdata;
Zhang Rui653a00c2008-01-17 15:51:18 +0800781 struct acpi_device *dev;
782 acpi_status status;
783 acpi_handle handle;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800784 int i;
785 int j;
786 int trip = -1;
787 int result = 0;
788
789 if (tz->trips.critical.flags.valid)
790 trip++;
791
792 if (tz->trips.hot.flags.valid)
793 trip++;
794
795 if (tz->trips.passive.flags.valid) {
796 trip++;
797 for (i = 0; i < tz->trips.passive.devices.count;
798 i++) {
Zhang Rui653a00c2008-01-17 15:51:18 +0800799 handle = tz->trips.passive.devices.handles[i];
800 status = acpi_bus_get_device(handle, &dev);
Zhang Rui9d998422012-06-26 16:35:57 +0800801 if (ACPI_FAILURE(status) || dev != device)
802 continue;
803 if (bind)
804 result =
805 thermal_zone_bind_cooling_device
806 (thermal, trip, cdev,
807 THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
808 else
809 result =
810 thermal_zone_unbind_cooling_device
811 (thermal, trip, cdev);
812 if (result)
813 goto failed;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800814 }
815 }
816
817 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
818 if (!tz->trips.active[i].flags.valid)
819 break;
820 trip++;
821 for (j = 0;
822 j < tz->trips.active[i].devices.count;
823 j++) {
Zhang Rui653a00c2008-01-17 15:51:18 +0800824 handle = tz->trips.active[i].devices.handles[j];
825 status = acpi_bus_get_device(handle, &dev);
Zhang Rui9d998422012-06-26 16:35:57 +0800826 if (ACPI_FAILURE(status) || dev != device)
827 continue;
828 if (bind)
829 result = thermal_zone_bind_cooling_device
830 (thermal, trip, cdev,
831 THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
832 else
833 result = thermal_zone_unbind_cooling_device
834 (thermal, trip, cdev);
835 if (result)
836 goto failed;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800837 }
838 }
839
840 for (i = 0; i < tz->devices.count; i++) {
Zhang Rui653a00c2008-01-17 15:51:18 +0800841 handle = tz->devices.handles[i];
842 status = acpi_bus_get_device(handle, &dev);
843 if (ACPI_SUCCESS(status) && (dev == device)) {
Zhang Rui9d998422012-06-26 16:35:57 +0800844 if (bind)
845 result = thermal_zone_bind_cooling_device
Lan Tianyu70f29032013-08-14 21:00:39 +0800846 (thermal, THERMAL_TRIPS_NONE,
847 cdev, THERMAL_NO_LIMIT,
Zhang Rui9d998422012-06-26 16:35:57 +0800848 THERMAL_NO_LIMIT);
849 else
850 result = thermal_zone_unbind_cooling_device
Lan Tianyu70f29032013-08-14 21:00:39 +0800851 (thermal, THERMAL_TRIPS_NONE,
852 cdev);
Zhang Rui653a00c2008-01-17 15:51:18 +0800853 if (result)
854 goto failed;
855 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800856 }
857
858failed:
859 return result;
860}
861
862static int
863acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
864 struct thermal_cooling_device *cdev)
865{
Zhang Rui9d998422012-06-26 16:35:57 +0800866 return acpi_thermal_cooling_device_cb(thermal, cdev, true);
Zhang Rui3f655ef2008-01-17 15:51:11 +0800867}
868
869static int
870acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
871 struct thermal_cooling_device *cdev)
872{
Zhang Rui9d998422012-06-26 16:35:57 +0800873 return acpi_thermal_cooling_device_cb(thermal, cdev, false);
Zhang Rui3f655ef2008-01-17 15:51:11 +0800874}
875
Vasiliy Kulikov9c8b04b2011-06-25 21:07:52 +0400876static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
Zhang Rui3f655ef2008-01-17 15:51:11 +0800877 .bind = acpi_thermal_bind_cooling_device,
878 .unbind = acpi_thermal_unbind_cooling_device,
879 .get_temp = thermal_get_temp,
880 .get_mode = thermal_get_mode,
881 .set_mode = thermal_set_mode,
882 .get_trip_type = thermal_get_trip_type,
883 .get_trip_temp = thermal_get_trip_temp,
Zhang, Rui9ec732f2008-04-10 16:13:10 +0800884 .get_crit_temp = thermal_get_crit_temp,
Zhang Rui601f3d42012-06-27 09:54:33 +0800885 .get_trend = thermal_get_trend,
Matthew Garrettb1569e92008-12-03 17:55:32 +0000886 .notify = thermal_notify,
Zhang Rui3f655ef2008-01-17 15:51:11 +0800887};
888
889static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
890{
891 int trips = 0;
892 int result;
Zhang Rui20733932008-01-17 15:51:21 +0800893 acpi_status status;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800894 int i;
895
896 if (tz->trips.critical.flags.valid)
897 trips++;
898
899 if (tz->trips.hot.flags.valid)
900 trips++;
901
902 if (tz->trips.passive.flags.valid)
903 trips++;
904
905 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
906 tz->trips.active[i].flags.valid; i++, trips++);
Matthew Garrettb1569e92008-12-03 17:55:32 +0000907
908 if (tz->trips.passive.flags.valid)
909 tz->thermal_zone =
Durgadoss Rc56f5c02012-07-25 10:10:58 +0800910 thermal_zone_device_register("acpitz", trips, 0, tz,
Durgadoss R50125a92012-09-18 11:04:56 +0530911 &acpi_thermal_zone_ops, NULL,
Matthew Garrettb1569e92008-12-03 17:55:32 +0000912 tz->trips.passive.tsp*100,
913 tz->polling_frequency*100);
914 else
915 tz->thermal_zone =
Durgadoss Rc56f5c02012-07-25 10:10:58 +0800916 thermal_zone_device_register("acpitz", trips, 0, tz,
Durgadoss R50125a92012-09-18 11:04:56 +0530917 &acpi_thermal_zone_ops, NULL,
918 0, tz->polling_frequency*100);
Krzysztof Heltbb070e42008-04-08 17:41:52 -0700919 if (IS_ERR(tz->thermal_zone))
Zhang Rui3f655ef2008-01-17 15:51:11 +0800920 return -ENODEV;
921
922 result = sysfs_create_link(&tz->device->dev.kobj,
923 &tz->thermal_zone->device.kobj, "thermal_zone");
924 if (result)
925 return result;
926
927 result = sysfs_create_link(&tz->thermal_zone->device.kobj,
928 &tz->device->dev.kobj, "device");
929 if (result)
930 return result;
931
Zhang Rui20733932008-01-17 15:51:21 +0800932 status = acpi_attach_data(tz->device->handle,
933 acpi_bus_private_data_handler,
934 tz->thermal_zone);
935 if (ACPI_FAILURE(status)) {
Lin Ming55ac9a02008-09-28 14:51:56 +0800936 printk(KERN_ERR PREFIX
937 "Error attaching device data\n");
Zhang Rui20733932008-01-17 15:51:21 +0800938 return -ENODEV;
939 }
940
Zhang Rui3f655ef2008-01-17 15:51:11 +0800941 tz->tz_enabled = 1;
942
Greg Kroah-Hartmanfc3a8822008-05-02 06:02:41 +0200943 dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
944 tz->thermal_zone->id);
Zhang Rui3f655ef2008-01-17 15:51:11 +0800945 return 0;
946}
947
948static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
949{
950 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
951 sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
952 thermal_zone_device_unregister(tz->thermal_zone);
953 tz->thermal_zone = NULL;
Zhang Rui20733932008-01-17 15:51:21 +0800954 acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler);
Zhang Rui3f655ef2008-01-17 15:51:11 +0800955}
956
957
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958/* --------------------------------------------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 Driver Interface
960 -------------------------------------------------------------------------- */
961
Bjorn Helgaas342d5502009-04-07 15:37:06 +0000962static void acpi_thermal_notify(struct acpi_device *device, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963{
Bjorn Helgaas342d5502009-04-07 15:37:06 +0000964 struct acpi_thermal *tz = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
967 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400968 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 switch (event) {
971 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
972 acpi_thermal_check(tz);
973 break;
974 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
Zhang Ruice44e192008-01-17 15:51:25 +0800975 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 acpi_thermal_check(tz);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800977 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100978 dev_name(&device->dev), event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 break;
980 case ACPI_THERMAL_NOTIFY_DEVICES:
Zhang Ruice44e192008-01-17 15:51:25 +0800981 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES);
982 acpi_thermal_check(tz);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800983 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100984 dev_name(&device->dev), event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 break;
986 default:
987 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400988 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 break;
990 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991}
992
Zhang Rui261cba22012-11-27 20:42:11 +0100993/*
994 * On some platforms, the AML code has dependency about
995 * the evaluating order of _TMP and _CRT/_HOT/_PSV/_ACx.
996 * 1. On HP Pavilion G4-1016tx, _TMP must be invoked after
997 * /_CRT/_HOT/_PSV/_ACx, or else system will be power off.
998 * 2. On HP Compaq 6715b/6715s, the return value of _PSV is 0
999 * if _TMP has never been evaluated.
1000 *
1001 * As this dependency is totally transparent to OS, evaluate
1002 * all of them once, in the order of _CRT/_HOT/_PSV/_ACx,
1003 * _TMP, before they are actually used.
1004 */
1005static void acpi_thermal_aml_dependency_fix(struct acpi_thermal *tz)
1006{
1007 acpi_handle handle = tz->device->handle;
1008 unsigned long long value;
1009 int i;
1010
1011 acpi_evaluate_integer(handle, "_CRT", NULL, &value);
1012 acpi_evaluate_integer(handle, "_HOT", NULL, &value);
1013 acpi_evaluate_integer(handle, "_PSV", NULL, &value);
1014 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1015 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
1016 acpi_status status;
1017
1018 status = acpi_evaluate_integer(handle, name, NULL, &value);
1019 if (status == AE_NOT_FOUND)
1020 break;
1021 }
1022 acpi_evaluate_integer(handle, "_TMP", NULL, &value);
1023}
1024
Len Brown4be44fc2005-08-05 00:44:28 -04001025static int acpi_thermal_get_info(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026{
Len Brown4be44fc2005-08-05 00:44:28 -04001027 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
1030 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -04001031 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032
Zhang Rui261cba22012-11-27 20:42:11 +01001033 acpi_thermal_aml_dependency_fix(tz);
1034
Matthew Garrett9bcb8112012-02-01 10:26:54 -05001035 /* Get trip points [_CRT, _PSV, etc.] (required) */
1036 result = acpi_thermal_get_trip_points(tz);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001038 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
Matthew Garrett9bcb8112012-02-01 10:26:54 -05001040 /* Get temperature [_TMP] (required) */
1041 result = acpi_thermal_get_temperature(tz);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001043 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
1045 /* Set the cooling mode [_SCP] to active cooling (default) */
1046 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
Len Brown4be44fc2005-08-05 00:44:28 -04001047 if (!result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 tz->flags.cooling_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
1050 /* Get default polling frequency [_TZP] (optional) */
1051 if (tzp)
1052 tz->polling_frequency = tzp;
1053 else
1054 acpi_thermal_get_polling_frequency(tz);
1055
Patrick Mocheld550d982006-06-27 00:41:40 -04001056 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057}
1058
Jean Delvare13614e32009-04-06 16:01:46 +02001059/*
1060 * The exact offset between Kelvin and degree Celsius is 273.15. However ACPI
1061 * handles temperature values with a single decimal place. As a consequence,
1062 * some implementations use an offset of 273.1 and others use an offset of
1063 * 273.2. Try to find out which one is being used, to present the most
1064 * accurate and visually appealing number.
1065 *
1066 * The heuristic below should work for all ACPI thermal zones which have a
1067 * critical trip point with a value being a multiple of 0.5 degree Celsius.
1068 */
1069static void acpi_thermal_guess_offset(struct acpi_thermal *tz)
1070{
1071 if (tz->trips.critical.flags.valid &&
1072 (tz->trips.critical.temperature % 5) == 1)
1073 tz->kelvin_offset = 2731;
1074 else
1075 tz->kelvin_offset = 2732;
1076}
1077
Len Brown4be44fc2005-08-05 00:44:28 -04001078static int acpi_thermal_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079{
Len Brown4be44fc2005-08-05 00:44:28 -04001080 int result = 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001081 struct acpi_thermal *tz = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
1084 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001085 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
Burman Yan36bcbec2006-12-19 12:56:11 -08001087 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -04001089 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
Patrick Mochel8348e1b2006-05-19 16:54:40 -04001091 tz->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 strcpy(tz->name, device->pnp.bus_id);
1093 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1094 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07001095 device->driver_data = tz;
Zhang Rui3f655ef2008-01-17 15:51:11 +08001096
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 result = acpi_thermal_get_info(tz);
1098 if (result)
Zhang Rui3f655ef2008-01-17 15:51:11 +08001099 goto free_memory;
1100
Jean Delvare13614e32009-04-06 16:01:46 +02001101 acpi_thermal_guess_offset(tz);
1102
Zhang Rui3f655ef2008-01-17 15:51:11 +08001103 result = acpi_thermal_register_thermal_zone(tz);
1104 if (result)
1105 goto free_memory;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001108 acpi_device_name(device), acpi_device_bid(device),
1109 KELVIN_TO_CELSIUS(tz->temperature));
Zhang Rui3f655ef2008-01-17 15:51:11 +08001110 goto end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
Zhang Rui3f655ef2008-01-17 15:51:11 +08001112free_memory:
1113 kfree(tz);
1114end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001115 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01001118static int acpi_thermal_remove(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119{
Len Brown4be44fc2005-08-05 00:44:28 -04001120 struct acpi_thermal *tz = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001123 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001125 tz = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Zhang Rui3f655ef2008-01-17 15:51:11 +08001127 acpi_thermal_unregister_thermal_zone(tz);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 kfree(tz);
Patrick Mocheld550d982006-06-27 00:41:40 -04001129 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130}
1131
Rafael J. Wysocki90692402012-08-09 23:00:02 +02001132#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki167cffb2012-06-27 23:26:18 +02001133static int acpi_thermal_resume(struct device *dev)
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001134{
Rafael J. Wysocki167cffb2012-06-27 23:26:18 +02001135 struct acpi_thermal *tz;
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001136 int i, j, power_state, result;
1137
Rafael J. Wysocki167cffb2012-06-27 23:26:18 +02001138 if (!dev)
Patrick Mocheld550d982006-06-27 00:41:40 -04001139 return -EINVAL;
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001140
Rafael J. Wysocki167cffb2012-06-27 23:26:18 +02001141 tz = acpi_driver_data(to_acpi_device(dev));
1142 if (!tz)
1143 return -EINVAL;
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001144
Konstantin Karasyovbed936f2006-07-10 04:44:26 -07001145 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001146 if (!(&tz->trips.active[i]))
1147 break;
1148 if (!tz->trips.active[i].flags.valid)
1149 break;
1150 tz->trips.active[i].flags.enabled = 1;
1151 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
Rafael J. Wysocki488a76c2010-11-25 00:11:24 +01001152 result = acpi_bus_update_power(
1153 tz->trips.active[i].devices.handles[j],
1154 &power_state);
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001155 if (result || (power_state != ACPI_STATE_D0)) {
1156 tz->trips.active[i].flags.enabled = 0;
1157 break;
1158 }
Konstantin Karasyovbed936f2006-07-10 04:44:26 -07001159 }
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001160 tz->state.active |= tz->trips.active[i].flags.enabled;
Konstantin Karasyovbed936f2006-07-10 04:44:26 -07001161 }
1162
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001163 acpi_thermal_check(tz);
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001164
1165 return AE_OK;
1166}
Rafael J. Wysocki90692402012-08-09 23:00:02 +02001167#endif
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001168
Jeff Garzik18552562007-10-03 15:15:40 -04001169static int thermal_act(const struct dmi_system_id *d) {
Len Brown0b5bfa12007-08-12 00:13:02 -04001170
1171 if (act == 0) {
1172 printk(KERN_NOTICE "ACPI: %s detected: "
1173 "disabling all active thermal trip points\n", d->ident);
1174 act = -1;
1175 }
1176 return 0;
1177}
Jeff Garzik18552562007-10-03 15:15:40 -04001178static int thermal_nocrt(const struct dmi_system_id *d) {
Len Brown8c99fdc2007-08-20 18:46:50 -04001179
1180 printk(KERN_NOTICE "ACPI: %s detected: "
1181 "disabling all critical thermal trip point actions.\n", d->ident);
1182 nocrt = 1;
1183 return 0;
1184}
Jeff Garzik18552562007-10-03 15:15:40 -04001185static int thermal_tzp(const struct dmi_system_id *d) {
Len Brown0b5bfa12007-08-12 00:13:02 -04001186
1187 if (tzp == 0) {
1188 printk(KERN_NOTICE "ACPI: %s detected: "
1189 "enabling thermal zone polling\n", d->ident);
1190 tzp = 300; /* 300 dS = 30 Seconds */
1191 }
1192 return 0;
1193}
Jeff Garzik18552562007-10-03 15:15:40 -04001194static int thermal_psv(const struct dmi_system_id *d) {
Len Brown0b5bfa12007-08-12 00:13:02 -04001195
1196 if (psv == 0) {
1197 printk(KERN_NOTICE "ACPI: %s detected: "
1198 "disabling all passive thermal trip points\n", d->ident);
1199 psv = -1;
1200 }
1201 return 0;
1202}
1203
1204static struct dmi_system_id thermal_dmi_table[] __initdata = {
1205 /*
1206 * Award BIOS on this AOpen makes thermal control almost worthless.
1207 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1208 */
1209 {
1210 .callback = thermal_act,
1211 .ident = "AOpen i915GMm-HFS",
1212 .matches = {
1213 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1214 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1215 },
1216 },
1217 {
1218 .callback = thermal_psv,
1219 .ident = "AOpen i915GMm-HFS",
1220 .matches = {
1221 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1222 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1223 },
1224 },
1225 {
1226 .callback = thermal_tzp,
1227 .ident = "AOpen i915GMm-HFS",
1228 .matches = {
1229 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1230 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1231 },
1232 },
Len Brown8c99fdc2007-08-20 18:46:50 -04001233 {
1234 .callback = thermal_nocrt,
1235 .ident = "Gigabyte GA-7ZX",
1236 .matches = {
1237 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
1238 DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
1239 },
1240 },
Len Brown0b5bfa12007-08-12 00:13:02 -04001241 {}
1242};
Len Brown0b5bfa12007-08-12 00:13:02 -04001243
Len Brown4be44fc2005-08-05 00:44:28 -04001244static int __init acpi_thermal_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245{
Len Brown4be44fc2005-08-05 00:44:28 -04001246 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
Len Brown0b5bfa12007-08-12 00:13:02 -04001248 dmi_check_system(thermal_dmi_table);
1249
Len Brown72b33ef2007-08-12 00:12:17 -04001250 if (off) {
1251 printk(KERN_NOTICE "ACPI: thermal control disabled\n");
1252 return -ENODEV;
1253 }
Zhang Rui43d9f872010-07-15 10:46:44 +08001254
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 result = acpi_bus_register_driver(&acpi_thermal_driver);
Zhang Ruic57b62f2010-10-08 13:55:06 +08001256 if (result < 0)
Patrick Mocheld550d982006-06-27 00:41:40 -04001257 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258
Patrick Mocheld550d982006-06-27 00:41:40 -04001259 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260}
1261
Len Brown4be44fc2005-08-05 00:44:28 -04001262static void __exit acpi_thermal_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
1265 acpi_bus_unregister_driver(&acpi_thermal_driver);
1266
Patrick Mocheld550d982006-06-27 00:41:40 -04001267 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268}
1269
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270module_init(acpi_thermal_init);
1271module_exit(acpi_thermal_exit);