blob: 8349a555b92b8aa6d6584f9c2c5c9ccf7a27737f [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>
Zhang Rui3f655ef2008-01-17 15:51:11 +080044#include <linux/thermal.h>
Lv Zheng8b484632013-12-03 08:49:16 +080045#include <linux/acpi.h>
46#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Len Browna192a952009-07-28 16:45:54 -040048#define PREFIX "ACPI: "
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define ACPI_THERMAL_CLASS "thermal_zone"
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80
53#define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81
54#define ACPI_THERMAL_NOTIFY_DEVICES 0x82
55#define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0
56#define ACPI_THERMAL_NOTIFY_HOT 0xF1
57#define ACPI_THERMAL_MODE_ACTIVE 0x00
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59#define ACPI_THERMAL_MAX_ACTIVE 10
60#define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#define _COMPONENT ACPI_THERMAL_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050063ACPI_MODULE_NAME("thermal");
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Thomas Renninger1cbf4c52004-09-16 11:07:00 -040065MODULE_AUTHOR("Paul Diefenbaugh");
Len Brown7cda93e2007-02-12 23:50:02 -050066MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070067MODULE_LICENSE("GPL");
68
Len Brownf8707ec2007-08-12 00:12:54 -040069static int act;
70module_param(act, int, 0644);
Len Brown3c1d36d2007-08-14 15:12:56 -040071MODULE_PARM_DESC(act, "Disable or override all lowest active trip points.");
Len Brownf8707ec2007-08-12 00:12:54 -040072
Len Brownc52a7412007-08-14 15:49:32 -040073static int crt;
74module_param(crt, int, 0644);
75MODULE_PARM_DESC(crt, "Disable or lower all critical trip points.");
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077static int tzp;
Len Brown730ff342007-08-12 00:12:26 -040078module_param(tzp, int, 0444);
Len Brown3c1d36d2007-08-14 15:12:56 -040079MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Len Brownf5487142007-08-12 00:12:44 -040081static int nocrt;
82module_param(nocrt, int, 0);
Len Brown8c99fdc2007-08-20 18:46:50 -040083MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points.");
Len Brownf5487142007-08-12 00:12:44 -040084
Len Brown72b33ef2007-08-12 00:12:17 -040085static int off;
86module_param(off, int, 0);
Len Brown3c1d36d2007-08-14 15:12:56 -040087MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.");
Len Brown72b33ef2007-08-12 00:12:17 -040088
Len Browna70cdc52007-08-12 00:12:35 -040089static int psv;
90module_param(psv, int, 0644);
Len Brown3c1d36d2007-08-14 15:12:56 -040091MODULE_PARM_DESC(psv, "Disable or override all passive trip points.");
Len Browna70cdc52007-08-12 00:12:35 -040092
Len Brown4be44fc2005-08-05 00:44:28 -040093static int acpi_thermal_add(struct acpi_device *device);
Rafael J. Wysocki51fac832013-01-24 00:24:48 +010094static int acpi_thermal_remove(struct acpi_device *device);
Bjorn Helgaas342d5502009-04-07 15:37:06 +000095static void acpi_thermal_notify(struct acpi_device *device, u32 event);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Thomas Renninger1ba90e32007-07-23 14:44:41 +020097static const struct acpi_device_id thermal_device_ids[] = {
98 {ACPI_THERMAL_HID, 0},
99 {"", 0},
100};
101MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
102
Rafael J. Wysocki90692402012-08-09 23:00:02 +0200103#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki167cffb2012-06-27 23:26:18 +0200104static int acpi_thermal_resume(struct device *dev);
Rafael J. Wysocki90692402012-08-09 23:00:02 +0200105#endif
Rafael J. Wysocki167cffb2012-06-27 23:26:18 +0200106static SIMPLE_DEV_PM_OPS(acpi_thermal_pm, NULL, acpi_thermal_resume);
107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static struct acpi_driver acpi_thermal_driver = {
Len Brownc2b67052007-02-12 23:33:40 -0500109 .name = "thermal",
Len Brown4be44fc2005-08-05 00:44:28 -0400110 .class = ACPI_THERMAL_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200111 .ids = thermal_device_ids,
Len Brown4be44fc2005-08-05 00:44:28 -0400112 .ops = {
113 .add = acpi_thermal_add,
114 .remove = acpi_thermal_remove,
Bjorn Helgaas342d5502009-04-07 15:37:06 +0000115 .notify = acpi_thermal_notify,
Len Brown4be44fc2005-08-05 00:44:28 -0400116 },
Rafael J. Wysocki167cffb2012-06-27 23:26:18 +0200117 .drv.pm = &acpi_thermal_pm,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118};
119
120struct acpi_thermal_state {
Len Brown4be44fc2005-08-05 00:44:28 -0400121 u8 critical:1;
122 u8 hot:1;
123 u8 passive:1;
124 u8 active:1;
125 u8 reserved:4;
126 int active_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127};
128
129struct acpi_thermal_state_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400130 u8 valid:1;
131 u8 enabled:1;
132 u8 reserved:6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133};
134
135struct acpi_thermal_critical {
136 struct acpi_thermal_state_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400137 unsigned long temperature;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138};
139
140struct acpi_thermal_hot {
141 struct acpi_thermal_state_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400142 unsigned long temperature;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143};
144
145struct acpi_thermal_passive {
146 struct acpi_thermal_state_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400147 unsigned long temperature;
148 unsigned long tc1;
149 unsigned long tc2;
150 unsigned long tsp;
151 struct acpi_handle_list devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152};
153
154struct acpi_thermal_active {
155 struct acpi_thermal_state_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400156 unsigned long temperature;
157 struct acpi_handle_list devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158};
159
160struct acpi_thermal_trips {
161 struct acpi_thermal_critical critical;
Len Brown4be44fc2005-08-05 00:44:28 -0400162 struct acpi_thermal_hot hot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 struct acpi_thermal_passive passive;
164 struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
165};
166
167struct acpi_thermal_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400168 u8 cooling_mode:1; /* _SCP */
169 u8 devices:1; /* _TZD */
170 u8 reserved:6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171};
172
173struct acpi_thermal {
Patrick Mochel8348e1b2006-05-19 16:54:40 -0400174 struct acpi_device * device;
Len Brown4be44fc2005-08-05 00:44:28 -0400175 acpi_bus_id name;
176 unsigned long temperature;
177 unsigned long last_temperature;
178 unsigned long polling_frequency;
Len Brown4be44fc2005-08-05 00:44:28 -0400179 volatile u8 zombie;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 struct acpi_thermal_flags flags;
181 struct acpi_thermal_state state;
182 struct acpi_thermal_trips trips;
Len Brown4be44fc2005-08-05 00:44:28 -0400183 struct acpi_handle_list devices;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800184 struct thermal_zone_device *thermal_zone;
185 int tz_enabled;
Jean Delvare13614e32009-04-06 16:01:46 +0200186 int kelvin_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187};
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189/* --------------------------------------------------------------------------
190 Thermal Zone Management
191 -------------------------------------------------------------------------- */
192
Len Brown4be44fc2005-08-05 00:44:28 -0400193static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
Len Brown4be44fc2005-08-05 00:44:28 -0400195 acpi_status status = AE_OK;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400196 unsigned long long tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400199 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 tz->last_temperature = tz->temperature;
202
Matthew Wilcox27663c52008-10-10 02:22:59 -0400203 status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400205 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Matthew Wilcox27663c52008-10-10 02:22:59 -0400207 tz->temperature = tmp;
Len Brown4be44fc2005-08-05 00:44:28 -0400208 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
209 tz->temperature));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Patrick Mocheld550d982006-06-27 00:41:40 -0400211 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212}
213
Len Brown4be44fc2005-08-05 00:44:28 -0400214static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215{
Len Brown4be44fc2005-08-05 00:44:28 -0400216 acpi_status status = AE_OK;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400217 unsigned long long tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400220 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Matthew Wilcox27663c52008-10-10 02:22:59 -0400222 status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400224 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Matthew Wilcox27663c52008-10-10 02:22:59 -0400226 tz->polling_frequency = tmp;
Len Brown4be44fc2005-08-05 00:44:28 -0400227 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
228 tz->polling_frequency));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Patrick Mocheld550d982006-06-27 00:41:40 -0400230 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231}
232
Len Brown4be44fc2005-08-05 00:44:28 -0400233static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400236 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Jiang Liu0db98202013-06-29 00:24:39 +0800238 if (!acpi_has_method(tz->device->handle, "_SCP")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400240 return -ENODEV;
Jiang Liu0db98202013-06-29 00:24:39 +0800241 } else if (ACPI_FAILURE(acpi_execute_simple_method(tz->device->handle,
242 "_SCP", mode))) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400243 return -ENODEV;
Jiang Liu0db98202013-06-29 00:24:39 +0800244 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Patrick Mocheld550d982006-06-27 00:41:40 -0400246 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247}
248
Zhang Ruice44e192008-01-17 15:51:25 +0800249#define ACPI_TRIPS_CRITICAL 0x01
250#define ACPI_TRIPS_HOT 0x02
251#define ACPI_TRIPS_PASSIVE 0x04
252#define ACPI_TRIPS_ACTIVE 0x08
253#define ACPI_TRIPS_DEVICES 0x10
254
255#define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE)
256#define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES
257
258#define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \
259 ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \
260 ACPI_TRIPS_DEVICES)
261
262/*
263 * This exception is thrown out in two cases:
264 * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
265 * when re-evaluating the AML code.
266 * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change.
267 * We need to re-bind the cooling devices of a thermal zone when this occurs.
268 */
269#define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \
270do { \
271 if (flags != ACPI_TRIPS_INIT) \
272 ACPI_EXCEPTION((AE_INFO, AE_ERROR, \
273 "ACPI thermal trip point %s changed\n" \
Colin Ian King7e3cf242012-11-29 11:53:16 +0000274 "Please send acpidump to linux-acpi@vger.kernel.org", str)); \
Zhang Ruice44e192008-01-17 15:51:25 +0800275} while (0)
276
277static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
Len Brown4be44fc2005-08-05 00:44:28 -0400279 acpi_status status = AE_OK;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400280 unsigned long long tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800281 struct acpi_handle_list devices;
282 int valid = 0;
283 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Thomas Renningerfa809452010-02-20 11:44:27 +0100285 /* Critical Shutdown */
Zhang Ruice44e192008-01-17 15:51:25 +0800286 if (flag & ACPI_TRIPS_CRITICAL) {
287 status = acpi_evaluate_integer(tz->device->handle,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400288 "_CRT", NULL, &tmp);
289 tz->trips.critical.temperature = tmp;
Arjan van de Vena39a2d72008-05-19 15:55:15 -0700290 /*
291 * Treat freezing temperatures as invalid as well; some
292 * BIOSes return really low values and cause reboots at startup.
Adam Buchbinderb731d7b2009-03-13 12:15:26 -0400293 * Below zero (Celsius) values clearly aren't right for sure..
Arjan van de Vena39a2d72008-05-19 15:55:15 -0700294 * ... so lets discard those as invalid.
295 */
Thomas Renningerfa809452010-02-20 11:44:27 +0100296 if (ACPI_FAILURE(status)) {
Len Brownc52a7412007-08-14 15:49:32 -0400297 tz->trips.critical.flags.valid = 0;
Thomas Renningerfa809452010-02-20 11:44:27 +0100298 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
299 "No critical threshold\n"));
300 } else if (tmp <= 2732) {
Andy Shevchenko766a8a62013-09-13 18:15:46 +0300301 pr_warn(FW_BUG "Invalid critical threshold (%llu)\n",
302 tmp);
Thomas Renningerfa809452010-02-20 11:44:27 +0100303 tz->trips.critical.flags.valid = 0;
Zhang Ruice44e192008-01-17 15:51:25 +0800304 } else {
305 tz->trips.critical.flags.valid = 1;
306 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Thomas Renningerfa809452010-02-20 11:44:27 +0100307 "Found critical threshold [%lu]\n",
308 tz->trips.critical.temperature));
Zhang Ruice44e192008-01-17 15:51:25 +0800309 }
310 if (tz->trips.critical.flags.valid == 1) {
311 if (crt == -1) {
312 tz->trips.critical.flags.valid = 0;
313 } else if (crt > 0) {
314 unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
315 /*
Zhang Rui22a94d72008-10-17 02:41:20 -0400316 * Allow override critical threshold
Zhang Ruice44e192008-01-17 15:51:25 +0800317 */
Zhang Rui22a94d72008-10-17 02:41:20 -0400318 if (crt_k > tz->trips.critical.temperature)
Andy Shevchenko766a8a62013-09-13 18:15:46 +0300319 pr_warn(PREFIX "Critical threshold %d C\n",
320 crt);
Zhang Rui22a94d72008-10-17 02:41:20 -0400321 tz->trips.critical.temperature = crt_k;
Zhang Ruice44e192008-01-17 15:51:25 +0800322 }
Len Brownc52a7412007-08-14 15:49:32 -0400323 }
324 }
325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 /* Critical Sleep (optional) */
Zhang Ruice44e192008-01-17 15:51:25 +0800327 if (flag & ACPI_TRIPS_HOT) {
Len Browna70cdc52007-08-12 00:12:35 -0400328 status = acpi_evaluate_integer(tz->device->handle,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400329 "_HOT", NULL, &tmp);
Zhang Ruice44e192008-01-17 15:51:25 +0800330 if (ACPI_FAILURE(status)) {
331 tz->trips.hot.flags.valid = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400332 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Zhang Ruice44e192008-01-17 15:51:25 +0800333 "No hot threshold\n"));
334 } else {
Matthew Wilcox27663c52008-10-10 02:22:59 -0400335 tz->trips.hot.temperature = tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800336 tz->trips.hot.flags.valid = 1;
337 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
338 "Found hot threshold [%lu]\n",
339 tz->trips.critical.temperature));
340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
342
Zhang Ruice44e192008-01-17 15:51:25 +0800343 /* Passive (optional) */
Zhang Rui0e4240d2009-01-16 12:53:42 -0500344 if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) ||
345 (flag == ACPI_TRIPS_INIT)) {
Zhang Ruice44e192008-01-17 15:51:25 +0800346 valid = tz->trips.passive.flags.valid;
347 if (psv == -1) {
348 status = AE_SUPPORT;
349 } else if (psv > 0) {
Matthew Wilcox27663c52008-10-10 02:22:59 -0400350 tmp = CELSIUS_TO_KELVIN(psv);
Zhang Ruice44e192008-01-17 15:51:25 +0800351 status = AE_OK;
352 } else {
353 status = acpi_evaluate_integer(tz->device->handle,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400354 "_PSV", NULL, &tmp);
Zhang Ruice44e192008-01-17 15:51:25 +0800355 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Zhang Ruice44e192008-01-17 15:51:25 +0800357 if (ACPI_FAILURE(status))
358 tz->trips.passive.flags.valid = 0;
359 else {
Matthew Wilcox27663c52008-10-10 02:22:59 -0400360 tz->trips.passive.temperature = tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800361 tz->trips.passive.flags.valid = 1;
362 if (flag == ACPI_TRIPS_INIT) {
363 status = acpi_evaluate_integer(
364 tz->device->handle, "_TC1",
Matthew Wilcox27663c52008-10-10 02:22:59 -0400365 NULL, &tmp);
Zhang Ruice44e192008-01-17 15:51:25 +0800366 if (ACPI_FAILURE(status))
367 tz->trips.passive.flags.valid = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400368 else
369 tz->trips.passive.tc1 = tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800370 status = acpi_evaluate_integer(
371 tz->device->handle, "_TC2",
Matthew Wilcox27663c52008-10-10 02:22:59 -0400372 NULL, &tmp);
Zhang Ruice44e192008-01-17 15:51:25 +0800373 if (ACPI_FAILURE(status))
374 tz->trips.passive.flags.valid = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400375 else
376 tz->trips.passive.tc2 = tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800377 status = acpi_evaluate_integer(
378 tz->device->handle, "_TSP",
Matthew Wilcox27663c52008-10-10 02:22:59 -0400379 NULL, &tmp);
Zhang Ruice44e192008-01-17 15:51:25 +0800380 if (ACPI_FAILURE(status))
381 tz->trips.passive.flags.valid = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400382 else
383 tz->trips.passive.tsp = tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800384 }
385 }
386 }
387 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) {
388 memset(&devices, 0, sizeof(struct acpi_handle_list));
389 status = acpi_evaluate_reference(tz->device->handle, "_PSL",
390 NULL, &devices);
Zhang Rui0e4240d2009-01-16 12:53:42 -0500391 if (ACPI_FAILURE(status)) {
Andy Shevchenko766a8a62013-09-13 18:15:46 +0300392 pr_warn(PREFIX "Invalid passive threshold\n");
Zhang Ruice44e192008-01-17 15:51:25 +0800393 tz->trips.passive.flags.valid = 0;
Zhang Rui0e4240d2009-01-16 12:53:42 -0500394 }
Zhang Ruice44e192008-01-17 15:51:25 +0800395 else
396 tz->trips.passive.flags.valid = 1;
397
398 if (memcmp(&tz->trips.passive.devices, &devices,
399 sizeof(struct acpi_handle_list))) {
400 memcpy(&tz->trips.passive.devices, &devices,
401 sizeof(struct acpi_handle_list));
402 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
403 }
404 }
405 if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) {
406 if (valid != tz->trips.passive.flags.valid)
407 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
408 }
409
410 /* Active (optional) */
Len Brown4be44fc2005-08-05 00:44:28 -0400411 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400412 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
Zhang Ruice44e192008-01-17 15:51:25 +0800413 valid = tz->trips.active[i].flags.valid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Len Brownf8707ec2007-08-12 00:12:54 -0400415 if (act == -1)
Zhang Ruice44e192008-01-17 15:51:25 +0800416 break; /* disable all active trip points */
Len Brownf8707ec2007-08-12 00:12:54 -0400417
Zhang Rui0e4240d2009-01-16 12:53:42 -0500418 if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) &&
419 tz->trips.active[i].flags.valid)) {
Zhang Ruice44e192008-01-17 15:51:25 +0800420 status = acpi_evaluate_integer(tz->device->handle,
Matthew Wilcox27663c52008-10-10 02:22:59 -0400421 name, NULL, &tmp);
Zhang Ruice44e192008-01-17 15:51:25 +0800422 if (ACPI_FAILURE(status)) {
423 tz->trips.active[i].flags.valid = 0;
424 if (i == 0)
425 break;
426 if (act <= 0)
427 break;
428 if (i == 1)
429 tz->trips.active[0].temperature =
430 CELSIUS_TO_KELVIN(act);
431 else
432 /*
433 * Don't allow override higher than
434 * the next higher trip point
435 */
436 tz->trips.active[i - 1].temperature =
437 (tz->trips.active[i - 2].temperature <
438 CELSIUS_TO_KELVIN(act) ?
439 tz->trips.active[i - 2].temperature :
440 CELSIUS_TO_KELVIN(act));
Len Brownf8707ec2007-08-12 00:12:54 -0400441 break;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400442 } else {
443 tz->trips.active[i].temperature = tmp;
Zhang Ruice44e192008-01-17 15:51:25 +0800444 tz->trips.active[i].flags.valid = 1;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400445 }
Len Brownf8707ec2007-08-12 00:12:54 -0400446 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448 name[2] = 'L';
Zhang Ruice44e192008-01-17 15:51:25 +0800449 if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) {
450 memset(&devices, 0, sizeof(struct acpi_handle_list));
451 status = acpi_evaluate_reference(tz->device->handle,
452 name, NULL, &devices);
Zhang Rui0e4240d2009-01-16 12:53:42 -0500453 if (ACPI_FAILURE(status)) {
Andy Shevchenko766a8a62013-09-13 18:15:46 +0300454 pr_warn(PREFIX "Invalid active%d threshold\n",
455 i);
Zhang Ruice44e192008-01-17 15:51:25 +0800456 tz->trips.active[i].flags.valid = 0;
Zhang Rui0e4240d2009-01-16 12:53:42 -0500457 }
Zhang Ruice44e192008-01-17 15:51:25 +0800458 else
459 tz->trips.active[i].flags.valid = 1;
460
461 if (memcmp(&tz->trips.active[i].devices, &devices,
462 sizeof(struct acpi_handle_list))) {
463 memcpy(&tz->trips.active[i].devices, &devices,
464 sizeof(struct acpi_handle_list));
465 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
466 }
467 }
468 if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES))
469 if (valid != tz->trips.active[i].flags.valid)
470 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
471
472 if (!tz->trips.active[i].flags.valid)
473 break;
474 }
475
Lan Tianyu668e0202013-08-27 16:29:31 +0800476 if ((flag & ACPI_TRIPS_DEVICES)
477 && acpi_has_method(tz->device->handle, "_TZD")) {
478 memset(&devices, 0, sizeof(devices));
Zhang Ruice44e192008-01-17 15:51:25 +0800479 status = acpi_evaluate_reference(tz->device->handle, "_TZD",
480 NULL, &devices);
Lan Tianyu668e0202013-08-27 16:29:31 +0800481 if (ACPI_SUCCESS(status)
482 && memcmp(&tz->devices, &devices, sizeof(devices))) {
483 tz->devices = devices;
Zhang Ruice44e192008-01-17 15:51:25 +0800484 ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
485 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 }
487
Patrick Mocheld550d982006-06-27 00:41:40 -0400488 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489}
490
Zhang Ruice44e192008-01-17 15:51:25 +0800491static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492{
Thomas Renninger8b7ef6d2010-02-16 22:55:51 +0100493 int i, valid, ret = acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
494
495 if (ret)
496 return ret;
497
498 valid = tz->trips.critical.flags.valid |
499 tz->trips.hot.flags.valid |
500 tz->trips.passive.flags.valid;
501
502 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
503 valid |= tz->trips.active[i].flags.valid;
504
505 if (!valid) {
Andy Shevchenko766a8a62013-09-13 18:15:46 +0300506 pr_warn(FW_BUG "No valid trip found\n");
Thomas Renninger8b7ef6d2010-02-16 22:55:51 +0100507 return -ENODEV;
508 }
509 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510}
511
Len Brown4be44fc2005-08-05 00:44:28 -0400512static void acpi_thermal_check(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200514 struct acpi_thermal *tz = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Srinivas Pandruvadae994d712013-09-25 09:29:50 -0700516 if (!tz->tz_enabled)
Srinivas Pandruvadaca4e7132013-01-15 23:57:16 +0100517 return;
Srinivas Pandruvadae994d712013-09-25 09:29:50 -0700518
Matthew Garrettb1569e92008-12-03 17:55:32 +0000519 thermal_zone_device_update(tz->thermal_zone);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520}
521
Zhang Rui3f655ef2008-01-17 15:51:11 +0800522/* sys I/F for generic thermal sysfs support */
Jean Delvare13614e32009-04-06 16:01:46 +0200523#define KELVIN_TO_MILLICELSIUS(t, off) (((t) - (off)) * 100)
Zhang, Rui5e012762008-02-28 07:51:30 +0800524
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000525static int thermal_get_temp(struct thermal_zone_device *thermal,
526 unsigned long *temp)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800527{
528 struct acpi_thermal *tz = thermal->devdata;
Zhang, Rui76ecb4f2008-04-10 16:20:23 +0800529 int result;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800530
531 if (!tz)
532 return -EINVAL;
533
Zhang, Rui76ecb4f2008-04-10 16:20:23 +0800534 result = acpi_thermal_get_temperature(tz);
535 if (result)
536 return result;
537
Jean Delvare13614e32009-04-06 16:01:46 +0200538 *temp = KELVIN_TO_MILLICELSIUS(tz->temperature, tz->kelvin_offset);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000539 return 0;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800540}
541
Zhang Rui3f655ef2008-01-17 15:51:11 +0800542static int thermal_get_mode(struct thermal_zone_device *thermal,
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000543 enum thermal_device_mode *mode)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800544{
545 struct acpi_thermal *tz = thermal->devdata;
546
547 if (!tz)
548 return -EINVAL;
549
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000550 *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
551 THERMAL_DEVICE_DISABLED;
552
553 return 0;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800554}
555
556static int thermal_set_mode(struct thermal_zone_device *thermal,
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000557 enum thermal_device_mode mode)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800558{
559 struct acpi_thermal *tz = thermal->devdata;
560 int enable;
561
562 if (!tz)
563 return -EINVAL;
564
565 /*
566 * enable/disable thermal management from ACPI thermal driver
567 */
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000568 if (mode == THERMAL_DEVICE_ENABLED)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800569 enable = 1;
Srinivas Pandruvadae994d712013-09-25 09:29:50 -0700570 else if (mode == THERMAL_DEVICE_DISABLED) {
Zhang Rui3f655ef2008-01-17 15:51:11 +0800571 enable = 0;
Srinivas Pandruvadae994d712013-09-25 09:29:50 -0700572 pr_warn("thermal zone will be disabled\n");
573 } else
Zhang Rui3f655ef2008-01-17 15:51:11 +0800574 return -EINVAL;
575
576 if (enable != tz->tz_enabled) {
577 tz->tz_enabled = enable;
578 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Zhang Rui8eaa8d62012-07-25 10:11:00 +0800579 "%s kernel ACPI thermal control\n",
580 tz->tz_enabled ? "Enable" : "Disable"));
Zhang Rui3f655ef2008-01-17 15:51:11 +0800581 acpi_thermal_check(tz);
582 }
583 return 0;
584}
585
586static int thermal_get_trip_type(struct thermal_zone_device *thermal,
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000587 int trip, enum thermal_trip_type *type)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800588{
589 struct acpi_thermal *tz = thermal->devdata;
590 int i;
591
592 if (!tz || trip < 0)
593 return -EINVAL;
594
595 if (tz->trips.critical.flags.valid) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000596 if (!trip) {
597 *type = THERMAL_TRIP_CRITICAL;
598 return 0;
599 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800600 trip--;
601 }
602
603 if (tz->trips.hot.flags.valid) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000604 if (!trip) {
605 *type = THERMAL_TRIP_HOT;
606 return 0;
607 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800608 trip--;
609 }
610
611 if (tz->trips.passive.flags.valid) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000612 if (!trip) {
613 *type = THERMAL_TRIP_PASSIVE;
614 return 0;
615 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800616 trip--;
617 }
618
619 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
620 tz->trips.active[i].flags.valid; i++) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000621 if (!trip) {
622 *type = THERMAL_TRIP_ACTIVE;
623 return 0;
624 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800625 trip--;
626 }
627
628 return -EINVAL;
629}
630
631static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000632 int trip, unsigned long *temp)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800633{
634 struct acpi_thermal *tz = thermal->devdata;
635 int i;
636
637 if (!tz || trip < 0)
638 return -EINVAL;
639
640 if (tz->trips.critical.flags.valid) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000641 if (!trip) {
642 *temp = KELVIN_TO_MILLICELSIUS(
Jean Delvare13614e32009-04-06 16:01:46 +0200643 tz->trips.critical.temperature,
644 tz->kelvin_offset);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000645 return 0;
646 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800647 trip--;
648 }
649
650 if (tz->trips.hot.flags.valid) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000651 if (!trip) {
652 *temp = KELVIN_TO_MILLICELSIUS(
Jean Delvare13614e32009-04-06 16:01:46 +0200653 tz->trips.hot.temperature,
654 tz->kelvin_offset);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000655 return 0;
656 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800657 trip--;
658 }
659
660 if (tz->trips.passive.flags.valid) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000661 if (!trip) {
662 *temp = KELVIN_TO_MILLICELSIUS(
Jean Delvare13614e32009-04-06 16:01:46 +0200663 tz->trips.passive.temperature,
664 tz->kelvin_offset);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000665 return 0;
666 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800667 trip--;
668 }
669
670 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
671 tz->trips.active[i].flags.valid; i++) {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000672 if (!trip) {
673 *temp = KELVIN_TO_MILLICELSIUS(
Jean Delvare13614e32009-04-06 16:01:46 +0200674 tz->trips.active[i].temperature,
675 tz->kelvin_offset);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000676 return 0;
677 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800678 trip--;
679 }
680
681 return -EINVAL;
682}
683
Zhang, Rui9ec732f2008-04-10 16:13:10 +0800684static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
685 unsigned long *temperature) {
686 struct acpi_thermal *tz = thermal->devdata;
687
688 if (tz->trips.critical.flags.valid) {
689 *temperature = KELVIN_TO_MILLICELSIUS(
Jean Delvare13614e32009-04-06 16:01:46 +0200690 tz->trips.critical.temperature,
691 tz->kelvin_offset);
Zhang, Rui9ec732f2008-04-10 16:13:10 +0800692 return 0;
693 } else
694 return -EINVAL;
695}
696
Zhang Rui601f3d42012-06-27 09:54:33 +0800697static int thermal_get_trend(struct thermal_zone_device *thermal,
698 int trip, enum thermal_trend *trend)
699{
700 struct acpi_thermal *tz = thermal->devdata;
701 enum thermal_trip_type type;
702 int i;
703
704 if (thermal_get_trip_type(thermal, trip, &type))
705 return -EINVAL;
706
Zhang Rui4ae46be2012-06-27 10:05:39 +0800707 if (type == THERMAL_TRIP_ACTIVE) {
Zhang Rui94a40932013-04-26 09:19:53 +0000708 unsigned long trip_temp;
709 unsigned long temp = KELVIN_TO_MILLICELSIUS(tz->temperature,
710 tz->kelvin_offset);
711 if (thermal_get_trip_temp(thermal, trip, &trip_temp))
712 return -EINVAL;
713
714 if (temp > trip_temp) {
715 *trend = THERMAL_TREND_RAISING;
716 return 0;
717 } else {
718 /* Fall back on default trend */
719 return -EINVAL;
720 }
Zhang Rui4ae46be2012-06-27 10:05:39 +0800721 }
Zhang Rui601f3d42012-06-27 09:54:33 +0800722
723 /*
724 * tz->temperature has already been updated by generic thermal layer,
725 * before this callback being invoked
726 */
727 i = (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature))
728 + (tz->trips.passive.tc2
729 * (tz->temperature - tz->trips.passive.temperature));
730
731 if (i > 0)
732 *trend = THERMAL_TREND_RAISING;
733 else if (i < 0)
734 *trend = THERMAL_TREND_DROPPING;
735 else
736 *trend = THERMAL_TREND_STABLE;
737 return 0;
738}
739
740
Matthew Garrettb1569e92008-12-03 17:55:32 +0000741static int thermal_notify(struct thermal_zone_device *thermal, int trip,
742 enum thermal_trip_type trip_type)
743{
744 u8 type = 0;
745 struct acpi_thermal *tz = thermal->devdata;
746
747 if (trip_type == THERMAL_TRIP_CRITICAL)
748 type = ACPI_THERMAL_NOTIFY_CRITICAL;
749 else if (trip_type == THERMAL_TRIP_HOT)
750 type = ACPI_THERMAL_NOTIFY_HOT;
751 else
752 return 0;
753
Matthew Garrettb1569e92008-12-03 17:55:32 +0000754 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
Stephen Rothwellf6f5c452009-03-03 12:47:17 +1100755 dev_name(&tz->device->dev), type, 1);
Matthew Garrettb1569e92008-12-03 17:55:32 +0000756
757 if (trip_type == THERMAL_TRIP_CRITICAL && nocrt)
758 return 1;
759
760 return 0;
761}
762
Zhang Rui3f655ef2008-01-17 15:51:11 +0800763static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
764 struct thermal_cooling_device *cdev,
Zhang Rui9d998422012-06-26 16:35:57 +0800765 bool bind)
Zhang Rui3f655ef2008-01-17 15:51:11 +0800766{
767 struct acpi_device *device = cdev->devdata;
768 struct acpi_thermal *tz = thermal->devdata;
Zhang Rui653a00c2008-01-17 15:51:18 +0800769 struct acpi_device *dev;
770 acpi_status status;
771 acpi_handle handle;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800772 int i;
773 int j;
774 int trip = -1;
775 int result = 0;
776
777 if (tz->trips.critical.flags.valid)
778 trip++;
779
780 if (tz->trips.hot.flags.valid)
781 trip++;
782
783 if (tz->trips.passive.flags.valid) {
784 trip++;
785 for (i = 0; i < tz->trips.passive.devices.count;
786 i++) {
Zhang Rui653a00c2008-01-17 15:51:18 +0800787 handle = tz->trips.passive.devices.handles[i];
788 status = acpi_bus_get_device(handle, &dev);
Zhang Rui9d998422012-06-26 16:35:57 +0800789 if (ACPI_FAILURE(status) || dev != device)
790 continue;
791 if (bind)
792 result =
793 thermal_zone_bind_cooling_device
794 (thermal, trip, cdev,
795 THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
796 else
797 result =
798 thermal_zone_unbind_cooling_device
799 (thermal, trip, cdev);
800 if (result)
801 goto failed;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800802 }
803 }
804
805 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
806 if (!tz->trips.active[i].flags.valid)
807 break;
808 trip++;
809 for (j = 0;
810 j < tz->trips.active[i].devices.count;
811 j++) {
Zhang Rui653a00c2008-01-17 15:51:18 +0800812 handle = tz->trips.active[i].devices.handles[j];
813 status = acpi_bus_get_device(handle, &dev);
Zhang Rui9d998422012-06-26 16:35:57 +0800814 if (ACPI_FAILURE(status) || dev != device)
815 continue;
816 if (bind)
817 result = thermal_zone_bind_cooling_device
818 (thermal, trip, cdev,
819 THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
820 else
821 result = thermal_zone_unbind_cooling_device
822 (thermal, trip, cdev);
823 if (result)
824 goto failed;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800825 }
826 }
827
828 for (i = 0; i < tz->devices.count; i++) {
Zhang Rui653a00c2008-01-17 15:51:18 +0800829 handle = tz->devices.handles[i];
830 status = acpi_bus_get_device(handle, &dev);
831 if (ACPI_SUCCESS(status) && (dev == device)) {
Zhang Rui9d998422012-06-26 16:35:57 +0800832 if (bind)
833 result = thermal_zone_bind_cooling_device
Lan Tianyu70f29032013-08-14 21:00:39 +0800834 (thermal, THERMAL_TRIPS_NONE,
835 cdev, THERMAL_NO_LIMIT,
Zhang Rui9d998422012-06-26 16:35:57 +0800836 THERMAL_NO_LIMIT);
837 else
838 result = thermal_zone_unbind_cooling_device
Lan Tianyu70f29032013-08-14 21:00:39 +0800839 (thermal, THERMAL_TRIPS_NONE,
840 cdev);
Zhang Rui653a00c2008-01-17 15:51:18 +0800841 if (result)
842 goto failed;
843 }
Zhang Rui3f655ef2008-01-17 15:51:11 +0800844 }
845
846failed:
847 return result;
848}
849
850static int
851acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
852 struct thermal_cooling_device *cdev)
853{
Zhang Rui9d998422012-06-26 16:35:57 +0800854 return acpi_thermal_cooling_device_cb(thermal, cdev, true);
Zhang Rui3f655ef2008-01-17 15:51:11 +0800855}
856
857static int
858acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
859 struct thermal_cooling_device *cdev)
860{
Zhang Rui9d998422012-06-26 16:35:57 +0800861 return acpi_thermal_cooling_device_cb(thermal, cdev, false);
Zhang Rui3f655ef2008-01-17 15:51:11 +0800862}
863
Emil Goodeec9c9c22014-01-07 17:24:55 +0100864static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
Zhang Rui3f655ef2008-01-17 15:51:11 +0800865 .bind = acpi_thermal_bind_cooling_device,
866 .unbind = acpi_thermal_unbind_cooling_device,
867 .get_temp = thermal_get_temp,
868 .get_mode = thermal_get_mode,
869 .set_mode = thermal_set_mode,
870 .get_trip_type = thermal_get_trip_type,
871 .get_trip_temp = thermal_get_trip_temp,
Zhang, Rui9ec732f2008-04-10 16:13:10 +0800872 .get_crit_temp = thermal_get_crit_temp,
Zhang Rui601f3d42012-06-27 09:54:33 +0800873 .get_trend = thermal_get_trend,
Matthew Garrettb1569e92008-12-03 17:55:32 +0000874 .notify = thermal_notify,
Zhang Rui3f655ef2008-01-17 15:51:11 +0800875};
876
877static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
878{
879 int trips = 0;
880 int result;
Zhang Rui20733932008-01-17 15:51:21 +0800881 acpi_status status;
Zhang Rui3f655ef2008-01-17 15:51:11 +0800882 int i;
883
884 if (tz->trips.critical.flags.valid)
885 trips++;
886
887 if (tz->trips.hot.flags.valid)
888 trips++;
889
890 if (tz->trips.passive.flags.valid)
891 trips++;
892
893 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
894 tz->trips.active[i].flags.valid; i++, trips++);
Matthew Garrettb1569e92008-12-03 17:55:32 +0000895
896 if (tz->trips.passive.flags.valid)
897 tz->thermal_zone =
Durgadoss Rc56f5c02012-07-25 10:10:58 +0800898 thermal_zone_device_register("acpitz", trips, 0, tz,
Durgadoss R50125a92012-09-18 11:04:56 +0530899 &acpi_thermal_zone_ops, NULL,
Matthew Garrettb1569e92008-12-03 17:55:32 +0000900 tz->trips.passive.tsp*100,
901 tz->polling_frequency*100);
902 else
903 tz->thermal_zone =
Durgadoss Rc56f5c02012-07-25 10:10:58 +0800904 thermal_zone_device_register("acpitz", trips, 0, tz,
Durgadoss R50125a92012-09-18 11:04:56 +0530905 &acpi_thermal_zone_ops, NULL,
906 0, tz->polling_frequency*100);
Krzysztof Heltbb070e42008-04-08 17:41:52 -0700907 if (IS_ERR(tz->thermal_zone))
Zhang Rui3f655ef2008-01-17 15:51:11 +0800908 return -ENODEV;
909
910 result = sysfs_create_link(&tz->device->dev.kobj,
911 &tz->thermal_zone->device.kobj, "thermal_zone");
912 if (result)
913 return result;
914
915 result = sysfs_create_link(&tz->thermal_zone->device.kobj,
916 &tz->device->dev.kobj, "device");
917 if (result)
918 return result;
919
Zhang Rui20733932008-01-17 15:51:21 +0800920 status = acpi_attach_data(tz->device->handle,
921 acpi_bus_private_data_handler,
922 tz->thermal_zone);
923 if (ACPI_FAILURE(status)) {
Andy Shevchenko766a8a62013-09-13 18:15:46 +0300924 pr_err(PREFIX "Error attaching device data\n");
Zhang Rui20733932008-01-17 15:51:21 +0800925 return -ENODEV;
926 }
927
Zhang Rui3f655ef2008-01-17 15:51:11 +0800928 tz->tz_enabled = 1;
929
Greg Kroah-Hartmanfc3a8822008-05-02 06:02:41 +0200930 dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
931 tz->thermal_zone->id);
Zhang Rui3f655ef2008-01-17 15:51:11 +0800932 return 0;
933}
934
935static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
936{
937 sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
938 sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
939 thermal_zone_device_unregister(tz->thermal_zone);
940 tz->thermal_zone = NULL;
Zhang Rui20733932008-01-17 15:51:21 +0800941 acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler);
Zhang Rui3f655ef2008-01-17 15:51:11 +0800942}
943
944
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945/* --------------------------------------------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 Driver Interface
947 -------------------------------------------------------------------------- */
948
Bjorn Helgaas342d5502009-04-07 15:37:06 +0000949static void acpi_thermal_notify(struct acpi_device *device, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950{
Bjorn Helgaas342d5502009-04-07 15:37:06 +0000951 struct acpi_thermal *tz = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
954 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -0400955 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 switch (event) {
958 case ACPI_THERMAL_NOTIFY_TEMPERATURE:
959 acpi_thermal_check(tz);
960 break;
961 case ACPI_THERMAL_NOTIFY_THRESHOLDS:
Zhang Ruice44e192008-01-17 15:51:25 +0800962 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 acpi_thermal_check(tz);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800964 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100965 dev_name(&device->dev), event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 break;
967 case ACPI_THERMAL_NOTIFY_DEVICES:
Zhang Ruice44e192008-01-17 15:51:25 +0800968 acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES);
969 acpi_thermal_check(tz);
Zhang Rui962ce8c2007-08-23 01:24:31 +0800970 acpi_bus_generate_netlink_event(device->pnp.device_class,
Kay Sievers07944692008-10-30 01:18:59 +0100971 dev_name(&device->dev), event, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 break;
973 default:
974 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400975 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 break;
977 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978}
979
Zhang Rui261cba22012-11-27 20:42:11 +0100980/*
981 * On some platforms, the AML code has dependency about
982 * the evaluating order of _TMP and _CRT/_HOT/_PSV/_ACx.
983 * 1. On HP Pavilion G4-1016tx, _TMP must be invoked after
984 * /_CRT/_HOT/_PSV/_ACx, or else system will be power off.
985 * 2. On HP Compaq 6715b/6715s, the return value of _PSV is 0
986 * if _TMP has never been evaluated.
987 *
988 * As this dependency is totally transparent to OS, evaluate
989 * all of them once, in the order of _CRT/_HOT/_PSV/_ACx,
990 * _TMP, before they are actually used.
991 */
992static void acpi_thermal_aml_dependency_fix(struct acpi_thermal *tz)
993{
994 acpi_handle handle = tz->device->handle;
995 unsigned long long value;
996 int i;
997
998 acpi_evaluate_integer(handle, "_CRT", NULL, &value);
999 acpi_evaluate_integer(handle, "_HOT", NULL, &value);
1000 acpi_evaluate_integer(handle, "_PSV", NULL, &value);
1001 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1002 char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
1003 acpi_status status;
1004
1005 status = acpi_evaluate_integer(handle, name, NULL, &value);
1006 if (status == AE_NOT_FOUND)
1007 break;
1008 }
1009 acpi_evaluate_integer(handle, "_TMP", NULL, &value);
1010}
1011
Len Brown4be44fc2005-08-05 00:44:28 -04001012static int acpi_thermal_get_info(struct acpi_thermal *tz)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013{
Len Brown4be44fc2005-08-05 00:44:28 -04001014 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
1017 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -04001018 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
Zhang Rui261cba22012-11-27 20:42:11 +01001020 acpi_thermal_aml_dependency_fix(tz);
1021
Matthew Garrett9bcb8112012-02-01 10:26:54 -05001022 /* Get trip points [_CRT, _PSV, etc.] (required) */
1023 result = acpi_thermal_get_trip_points(tz);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001025 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
Matthew Garrett9bcb8112012-02-01 10:26:54 -05001027 /* Get temperature [_TMP] (required) */
1028 result = acpi_thermal_get_temperature(tz);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001030 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
1032 /* Set the cooling mode [_SCP] to active cooling (default) */
1033 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
Len Brown4be44fc2005-08-05 00:44:28 -04001034 if (!result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 tz->flags.cooling_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
1037 /* Get default polling frequency [_TZP] (optional) */
1038 if (tzp)
1039 tz->polling_frequency = tzp;
1040 else
1041 acpi_thermal_get_polling_frequency(tz);
1042
Patrick Mocheld550d982006-06-27 00:41:40 -04001043 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044}
1045
Jean Delvare13614e32009-04-06 16:01:46 +02001046/*
1047 * The exact offset between Kelvin and degree Celsius is 273.15. However ACPI
1048 * handles temperature values with a single decimal place. As a consequence,
1049 * some implementations use an offset of 273.1 and others use an offset of
1050 * 273.2. Try to find out which one is being used, to present the most
1051 * accurate and visually appealing number.
1052 *
1053 * The heuristic below should work for all ACPI thermal zones which have a
1054 * critical trip point with a value being a multiple of 0.5 degree Celsius.
1055 */
1056static void acpi_thermal_guess_offset(struct acpi_thermal *tz)
1057{
1058 if (tz->trips.critical.flags.valid &&
1059 (tz->trips.critical.temperature % 5) == 1)
1060 tz->kelvin_offset = 2731;
1061 else
1062 tz->kelvin_offset = 2732;
1063}
1064
Len Brown4be44fc2005-08-05 00:44:28 -04001065static int acpi_thermal_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066{
Len Brown4be44fc2005-08-05 00:44:28 -04001067 int result = 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001068 struct acpi_thermal *tz = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
1071 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001072 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
Burman Yan36bcbec2006-12-19 12:56:11 -08001074 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 if (!tz)
Patrick Mocheld550d982006-06-27 00:41:40 -04001076 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
Patrick Mochel8348e1b2006-05-19 16:54:40 -04001078 tz->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 strcpy(tz->name, device->pnp.bus_id);
1080 strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
1081 strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07001082 device->driver_data = tz;
Zhang Rui3f655ef2008-01-17 15:51:11 +08001083
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 result = acpi_thermal_get_info(tz);
1085 if (result)
Zhang Rui3f655ef2008-01-17 15:51:11 +08001086 goto free_memory;
1087
Jean Delvare13614e32009-04-06 16:01:46 +02001088 acpi_thermal_guess_offset(tz);
1089
Zhang Rui3f655ef2008-01-17 15:51:11 +08001090 result = acpi_thermal_register_thermal_zone(tz);
1091 if (result)
1092 goto free_memory;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Andy Shevchenko766a8a62013-09-13 18:15:46 +03001094 pr_info(PREFIX "%s [%s] (%ld C)\n", acpi_device_name(device),
1095 acpi_device_bid(device), KELVIN_TO_CELSIUS(tz->temperature));
Zhang Rui3f655ef2008-01-17 15:51:11 +08001096 goto end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
Zhang Rui3f655ef2008-01-17 15:51:11 +08001098free_memory:
1099 kfree(tz);
1100end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001101 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102}
1103
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01001104static int acpi_thermal_remove(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105{
Len Brown4be44fc2005-08-05 00:44:28 -04001106 struct acpi_thermal *tz = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001109 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001111 tz = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
Zhang Rui3f655ef2008-01-17 15:51:11 +08001113 acpi_thermal_unregister_thermal_zone(tz);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 kfree(tz);
Patrick Mocheld550d982006-06-27 00:41:40 -04001115 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
Rafael J. Wysocki90692402012-08-09 23:00:02 +02001118#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki167cffb2012-06-27 23:26:18 +02001119static int acpi_thermal_resume(struct device *dev)
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001120{
Rafael J. Wysocki167cffb2012-06-27 23:26:18 +02001121 struct acpi_thermal *tz;
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001122 int i, j, power_state, result;
1123
Rafael J. Wysocki167cffb2012-06-27 23:26:18 +02001124 if (!dev)
Patrick Mocheld550d982006-06-27 00:41:40 -04001125 return -EINVAL;
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001126
Rafael J. Wysocki167cffb2012-06-27 23:26:18 +02001127 tz = acpi_driver_data(to_acpi_device(dev));
1128 if (!tz)
1129 return -EINVAL;
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001130
Konstantin Karasyovbed936f2006-07-10 04:44:26 -07001131 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001132 if (!(&tz->trips.active[i]))
1133 break;
1134 if (!tz->trips.active[i].flags.valid)
1135 break;
1136 tz->trips.active[i].flags.enabled = 1;
1137 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
Rafael J. Wysocki488a76c2010-11-25 00:11:24 +01001138 result = acpi_bus_update_power(
1139 tz->trips.active[i].devices.handles[j],
1140 &power_state);
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001141 if (result || (power_state != ACPI_STATE_D0)) {
1142 tz->trips.active[i].flags.enabled = 0;
1143 break;
1144 }
Konstantin Karasyovbed936f2006-07-10 04:44:26 -07001145 }
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001146 tz->state.active |= tz->trips.active[i].flags.enabled;
Konstantin Karasyovbed936f2006-07-10 04:44:26 -07001147 }
1148
Konstantin Karasyovb1028c52007-02-16 02:23:07 -05001149 acpi_thermal_check(tz);
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001150
1151 return AE_OK;
1152}
Rafael J. Wysocki90692402012-08-09 23:00:02 +02001153#endif
Konstantin Karasyov74ce14682006-05-08 08:32:00 -04001154
Jeff Garzik18552562007-10-03 15:15:40 -04001155static int thermal_act(const struct dmi_system_id *d) {
Len Brown0b5bfa12007-08-12 00:13:02 -04001156
1157 if (act == 0) {
Andy Shevchenko766a8a62013-09-13 18:15:46 +03001158 pr_notice(PREFIX "%s detected: "
1159 "disabling all active thermal trip points\n", d->ident);
Len Brown0b5bfa12007-08-12 00:13:02 -04001160 act = -1;
1161 }
1162 return 0;
1163}
Jeff Garzik18552562007-10-03 15:15:40 -04001164static int thermal_nocrt(const struct dmi_system_id *d) {
Len Brown8c99fdc2007-08-20 18:46:50 -04001165
Andy Shevchenko766a8a62013-09-13 18:15:46 +03001166 pr_notice(PREFIX "%s detected: "
1167 "disabling all critical thermal trip point actions.\n", d->ident);
Len Brown8c99fdc2007-08-20 18:46:50 -04001168 nocrt = 1;
1169 return 0;
1170}
Jeff Garzik18552562007-10-03 15:15:40 -04001171static int thermal_tzp(const struct dmi_system_id *d) {
Len Brown0b5bfa12007-08-12 00:13:02 -04001172
1173 if (tzp == 0) {
Andy Shevchenko766a8a62013-09-13 18:15:46 +03001174 pr_notice(PREFIX "%s detected: "
1175 "enabling thermal zone polling\n", d->ident);
Len Brown0b5bfa12007-08-12 00:13:02 -04001176 tzp = 300; /* 300 dS = 30 Seconds */
1177 }
1178 return 0;
1179}
Jeff Garzik18552562007-10-03 15:15:40 -04001180static int thermal_psv(const struct dmi_system_id *d) {
Len Brown0b5bfa12007-08-12 00:13:02 -04001181
1182 if (psv == 0) {
Andy Shevchenko766a8a62013-09-13 18:15:46 +03001183 pr_notice(PREFIX "%s detected: "
1184 "disabling all passive thermal trip points\n", d->ident);
Len Brown0b5bfa12007-08-12 00:13:02 -04001185 psv = -1;
1186 }
1187 return 0;
1188}
1189
1190static struct dmi_system_id thermal_dmi_table[] __initdata = {
1191 /*
1192 * Award BIOS on this AOpen makes thermal control almost worthless.
1193 * http://bugzilla.kernel.org/show_bug.cgi?id=8842
1194 */
1195 {
1196 .callback = thermal_act,
1197 .ident = "AOpen i915GMm-HFS",
1198 .matches = {
1199 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1200 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1201 },
1202 },
1203 {
1204 .callback = thermal_psv,
1205 .ident = "AOpen i915GMm-HFS",
1206 .matches = {
1207 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1208 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1209 },
1210 },
1211 {
1212 .callback = thermal_tzp,
1213 .ident = "AOpen i915GMm-HFS",
1214 .matches = {
1215 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
1216 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
1217 },
1218 },
Len Brown8c99fdc2007-08-20 18:46:50 -04001219 {
1220 .callback = thermal_nocrt,
1221 .ident = "Gigabyte GA-7ZX",
1222 .matches = {
1223 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
1224 DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
1225 },
1226 },
Len Brown0b5bfa12007-08-12 00:13:02 -04001227 {}
1228};
Len Brown0b5bfa12007-08-12 00:13:02 -04001229
Len Brown4be44fc2005-08-05 00:44:28 -04001230static int __init acpi_thermal_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231{
Len Brown4be44fc2005-08-05 00:44:28 -04001232 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
Len Brown0b5bfa12007-08-12 00:13:02 -04001234 dmi_check_system(thermal_dmi_table);
1235
Len Brown72b33ef2007-08-12 00:12:17 -04001236 if (off) {
Andy Shevchenko766a8a62013-09-13 18:15:46 +03001237 pr_notice(PREFIX "thermal control disabled\n");
Len Brown72b33ef2007-08-12 00:12:17 -04001238 return -ENODEV;
1239 }
Zhang Rui43d9f872010-07-15 10:46:44 +08001240
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 result = acpi_bus_register_driver(&acpi_thermal_driver);
Zhang Ruic57b62f2010-10-08 13:55:06 +08001242 if (result < 0)
Patrick Mocheld550d982006-06-27 00:41:40 -04001243 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
Patrick Mocheld550d982006-06-27 00:41:40 -04001245 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246}
1247
Len Brown4be44fc2005-08-05 00:44:28 -04001248static void __exit acpi_thermal_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
1251 acpi_bus_unregister_driver(&acpi_thermal_driver);
1252
Patrick Mocheld550d982006-06-27 00:41:40 -04001253 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254}
1255
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256module_init(acpi_thermal_init);
1257module_exit(acpi_thermal_exit);