Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 36 | #include <linux/dmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 38 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/types.h> |
Tim Schmielau | cd354f1 | 2007-02-14 00:33:14 -0800 | [diff] [blame] | 40 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/kmod.h> |
Jeremy Fitzhardinge | 10a0a8d | 2007-07-17 18:37:02 -0700 | [diff] [blame] | 42 | #include <linux/reboot.h> |
Stephen Rothwell | f6f5c45 | 2009-03-03 12:47:17 +1100 | [diff] [blame] | 43 | #include <linux/device.h> |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 44 | #include <linux/thermal.h> |
Lv Zheng | 8b48463 | 2013-12-03 08:49:16 +0800 | [diff] [blame] | 45 | #include <linux/acpi.h> |
| 46 | #include <asm/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Len Brown | a192a95 | 2009-07-28 16:45:54 -0400 | [diff] [blame] | 48 | #define PREFIX "ACPI: " |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #define ACPI_THERMAL_CLASS "thermal_zone" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | #define ACPI_THERMAL_MAX_ACTIVE 10 |
| 60 | #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65 |
| 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #define _COMPONENT ACPI_THERMAL_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 63 | ACPI_MODULE_NAME("thermal"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 65 | MODULE_AUTHOR("Paul Diefenbaugh"); |
Len Brown | 7cda93e | 2007-02-12 23:50:02 -0500 | [diff] [blame] | 66 | MODULE_DESCRIPTION("ACPI Thermal Zone Driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | MODULE_LICENSE("GPL"); |
| 68 | |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 69 | static int act; |
| 70 | module_param(act, int, 0644); |
Len Brown | 3c1d36d | 2007-08-14 15:12:56 -0400 | [diff] [blame] | 71 | MODULE_PARM_DESC(act, "Disable or override all lowest active trip points."); |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 72 | |
Len Brown | c52a741 | 2007-08-14 15:49:32 -0400 | [diff] [blame] | 73 | static int crt; |
| 74 | module_param(crt, int, 0644); |
| 75 | MODULE_PARM_DESC(crt, "Disable or lower all critical trip points."); |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | static int tzp; |
Len Brown | 730ff34 | 2007-08-12 00:12:26 -0400 | [diff] [blame] | 78 | module_param(tzp, int, 0444); |
Len Brown | 3c1d36d | 2007-08-14 15:12:56 -0400 | [diff] [blame] | 79 | MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Len Brown | f548714 | 2007-08-12 00:12:44 -0400 | [diff] [blame] | 81 | static int nocrt; |
| 82 | module_param(nocrt, int, 0); |
Len Brown | 8c99fdc | 2007-08-20 18:46:50 -0400 | [diff] [blame] | 83 | MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points."); |
Len Brown | f548714 | 2007-08-12 00:12:44 -0400 | [diff] [blame] | 84 | |
Len Brown | 72b33ef | 2007-08-12 00:12:17 -0400 | [diff] [blame] | 85 | static int off; |
| 86 | module_param(off, int, 0); |
Len Brown | 3c1d36d | 2007-08-14 15:12:56 -0400 | [diff] [blame] | 87 | MODULE_PARM_DESC(off, "Set to disable ACPI thermal support."); |
Len Brown | 72b33ef | 2007-08-12 00:12:17 -0400 | [diff] [blame] | 88 | |
Len Brown | a70cdc5 | 2007-08-12 00:12:35 -0400 | [diff] [blame] | 89 | static int psv; |
| 90 | module_param(psv, int, 0644); |
Len Brown | 3c1d36d | 2007-08-14 15:12:56 -0400 | [diff] [blame] | 91 | MODULE_PARM_DESC(psv, "Disable or override all passive trip points."); |
Len Brown | a70cdc5 | 2007-08-12 00:12:35 -0400 | [diff] [blame] | 92 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 93 | static int acpi_thermal_add(struct acpi_device *device); |
Rafael J. Wysocki | 51fac83 | 2013-01-24 00:24:48 +0100 | [diff] [blame] | 94 | static int acpi_thermal_remove(struct acpi_device *device); |
Bjorn Helgaas | 342d550 | 2009-04-07 15:37:06 +0000 | [diff] [blame] | 95 | static void acpi_thermal_notify(struct acpi_device *device, u32 event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 97 | static const struct acpi_device_id thermal_device_ids[] = { |
| 98 | {ACPI_THERMAL_HID, 0}, |
| 99 | {"", 0}, |
| 100 | }; |
| 101 | MODULE_DEVICE_TABLE(acpi, thermal_device_ids); |
| 102 | |
Rafael J. Wysocki | 9069240 | 2012-08-09 23:00:02 +0200 | [diff] [blame] | 103 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 104 | static int acpi_thermal_resume(struct device *dev); |
Rafael J. Wysocki | 9069240 | 2012-08-09 23:00:02 +0200 | [diff] [blame] | 105 | #endif |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 106 | static SIMPLE_DEV_PM_OPS(acpi_thermal_pm, NULL, acpi_thermal_resume); |
| 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | static struct acpi_driver acpi_thermal_driver = { |
Len Brown | c2b6705 | 2007-02-12 23:33:40 -0500 | [diff] [blame] | 109 | .name = "thermal", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 110 | .class = ACPI_THERMAL_CLASS, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 111 | .ids = thermal_device_ids, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 112 | .ops = { |
| 113 | .add = acpi_thermal_add, |
| 114 | .remove = acpi_thermal_remove, |
Bjorn Helgaas | 342d550 | 2009-04-07 15:37:06 +0000 | [diff] [blame] | 115 | .notify = acpi_thermal_notify, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 116 | }, |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 117 | .drv.pm = &acpi_thermal_pm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | struct acpi_thermal_state { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 121 | u8 critical:1; |
| 122 | u8 hot:1; |
| 123 | u8 passive:1; |
| 124 | u8 active:1; |
| 125 | u8 reserved:4; |
| 126 | int active_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | struct acpi_thermal_state_flags { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 130 | u8 valid:1; |
| 131 | u8 enabled:1; |
| 132 | u8 reserved:6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | struct acpi_thermal_critical { |
| 136 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 137 | unsigned long temperature; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | struct acpi_thermal_hot { |
| 141 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 142 | unsigned long temperature; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | struct acpi_thermal_passive { |
| 146 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 147 | unsigned long temperature; |
| 148 | unsigned long tc1; |
| 149 | unsigned long tc2; |
| 150 | unsigned long tsp; |
| 151 | struct acpi_handle_list devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | struct acpi_thermal_active { |
| 155 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | unsigned long temperature; |
| 157 | struct acpi_handle_list devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | struct acpi_thermal_trips { |
| 161 | struct acpi_thermal_critical critical; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 162 | struct acpi_thermal_hot hot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | struct acpi_thermal_passive passive; |
| 164 | struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE]; |
| 165 | }; |
| 166 | |
| 167 | struct acpi_thermal_flags { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 168 | u8 cooling_mode:1; /* _SCP */ |
| 169 | u8 devices:1; /* _TZD */ |
| 170 | u8 reserved:6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | }; |
| 172 | |
| 173 | struct acpi_thermal { |
Patrick Mochel | 8348e1b | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 174 | struct acpi_device * device; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 175 | acpi_bus_id name; |
| 176 | unsigned long temperature; |
| 177 | unsigned long last_temperature; |
| 178 | unsigned long polling_frequency; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 179 | volatile u8 zombie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | struct acpi_thermal_flags flags; |
| 181 | struct acpi_thermal_state state; |
| 182 | struct acpi_thermal_trips trips; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 183 | struct acpi_handle_list devices; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 184 | struct thermal_zone_device *thermal_zone; |
| 185 | int tz_enabled; |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 186 | int kelvin_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | }; |
| 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | /* -------------------------------------------------------------------------- |
| 190 | Thermal Zone Management |
| 191 | -------------------------------------------------------------------------- */ |
| 192 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 193 | static int acpi_thermal_get_temperature(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 195 | acpi_status status = AE_OK; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 196 | unsigned long long tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 199 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
| 201 | tz->last_temperature = tz->temperature; |
| 202 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 203 | status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 205 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 207 | tz->temperature = tmp; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 208 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n", |
| 209 | tz->temperature)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 211 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 214 | static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | acpi_status status = AE_OK; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 217 | unsigned long long tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
| 219 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 220 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 222 | status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 224 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 226 | tz->polling_frequency = tmp; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 227 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n", |
| 228 | tz->polling_frequency)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 230 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 233 | static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 236 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
Jiang Liu | 0db9820 | 2013-06-29 00:24:39 +0800 | [diff] [blame] | 238 | if (!acpi_has_method(tz->device->handle, "_SCP")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 240 | return -ENODEV; |
Jiang Liu | 0db9820 | 2013-06-29 00:24:39 +0800 | [diff] [blame] | 241 | } else if (ACPI_FAILURE(acpi_execute_simple_method(tz->device->handle, |
| 242 | "_SCP", mode))) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 243 | return -ENODEV; |
Jiang Liu | 0db9820 | 2013-06-29 00:24:39 +0800 | [diff] [blame] | 244 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 246 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 249 | #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) \ |
| 270 | do { \ |
| 271 | if (flags != ACPI_TRIPS_INIT) \ |
| 272 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, \ |
| 273 | "ACPI thermal trip point %s changed\n" \ |
Colin Ian King | 7e3cf24 | 2012-11-29 11:53:16 +0000 | [diff] [blame] | 274 | "Please send acpidump to linux-acpi@vger.kernel.org", str)); \ |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 275 | } while (0) |
| 276 | |
| 277 | static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 279 | acpi_status status = AE_OK; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 280 | unsigned long long tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 281 | struct acpi_handle_list devices; |
| 282 | int valid = 0; |
| 283 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Thomas Renninger | fa80945 | 2010-02-20 11:44:27 +0100 | [diff] [blame] | 285 | /* Critical Shutdown */ |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 286 | if (flag & ACPI_TRIPS_CRITICAL) { |
| 287 | status = acpi_evaluate_integer(tz->device->handle, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 288 | "_CRT", NULL, &tmp); |
| 289 | tz->trips.critical.temperature = tmp; |
Arjan van de Ven | a39a2d7 | 2008-05-19 15:55:15 -0700 | [diff] [blame] | 290 | /* |
| 291 | * Treat freezing temperatures as invalid as well; some |
| 292 | * BIOSes return really low values and cause reboots at startup. |
Adam Buchbinder | b731d7b | 2009-03-13 12:15:26 -0400 | [diff] [blame] | 293 | * Below zero (Celsius) values clearly aren't right for sure.. |
Arjan van de Ven | a39a2d7 | 2008-05-19 15:55:15 -0700 | [diff] [blame] | 294 | * ... so lets discard those as invalid. |
| 295 | */ |
Thomas Renninger | fa80945 | 2010-02-20 11:44:27 +0100 | [diff] [blame] | 296 | if (ACPI_FAILURE(status)) { |
Len Brown | c52a741 | 2007-08-14 15:49:32 -0400 | [diff] [blame] | 297 | tz->trips.critical.flags.valid = 0; |
Thomas Renninger | fa80945 | 2010-02-20 11:44:27 +0100 | [diff] [blame] | 298 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 299 | "No critical threshold\n")); |
| 300 | } else if (tmp <= 2732) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 301 | pr_warn(FW_BUG "Invalid critical threshold (%llu)\n", |
| 302 | tmp); |
Thomas Renninger | fa80945 | 2010-02-20 11:44:27 +0100 | [diff] [blame] | 303 | tz->trips.critical.flags.valid = 0; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 304 | } else { |
| 305 | tz->trips.critical.flags.valid = 1; |
| 306 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Thomas Renninger | fa80945 | 2010-02-20 11:44:27 +0100 | [diff] [blame] | 307 | "Found critical threshold [%lu]\n", |
| 308 | tz->trips.critical.temperature)); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 309 | } |
| 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 Rui | 22a94d7 | 2008-10-17 02:41:20 -0400 | [diff] [blame] | 316 | * Allow override critical threshold |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 317 | */ |
Zhang Rui | 22a94d7 | 2008-10-17 02:41:20 -0400 | [diff] [blame] | 318 | if (crt_k > tz->trips.critical.temperature) |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 319 | pr_warn(PREFIX "Critical threshold %d C\n", |
| 320 | crt); |
Zhang Rui | 22a94d7 | 2008-10-17 02:41:20 -0400 | [diff] [blame] | 321 | tz->trips.critical.temperature = crt_k; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 322 | } |
Len Brown | c52a741 | 2007-08-14 15:49:32 -0400 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | /* Critical Sleep (optional) */ |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 327 | if (flag & ACPI_TRIPS_HOT) { |
Len Brown | a70cdc5 | 2007-08-12 00:12:35 -0400 | [diff] [blame] | 328 | status = acpi_evaluate_integer(tz->device->handle, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 329 | "_HOT", NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 330 | if (ACPI_FAILURE(status)) { |
| 331 | tz->trips.hot.flags.valid = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 332 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 333 | "No hot threshold\n")); |
| 334 | } else { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 335 | tz->trips.hot.temperature = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 336 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 343 | /* Passive (optional) */ |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 344 | if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) || |
| 345 | (flag == ACPI_TRIPS_INIT)) { |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 346 | valid = tz->trips.passive.flags.valid; |
| 347 | if (psv == -1) { |
| 348 | status = AE_SUPPORT; |
| 349 | } else if (psv > 0) { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 350 | tmp = CELSIUS_TO_KELVIN(psv); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 351 | status = AE_OK; |
| 352 | } else { |
| 353 | status = acpi_evaluate_integer(tz->device->handle, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 354 | "_PSV", NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 357 | if (ACPI_FAILURE(status)) |
| 358 | tz->trips.passive.flags.valid = 0; |
| 359 | else { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 360 | tz->trips.passive.temperature = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 361 | tz->trips.passive.flags.valid = 1; |
| 362 | if (flag == ACPI_TRIPS_INIT) { |
| 363 | status = acpi_evaluate_integer( |
| 364 | tz->device->handle, "_TC1", |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 365 | NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 366 | if (ACPI_FAILURE(status)) |
| 367 | tz->trips.passive.flags.valid = 0; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 368 | else |
| 369 | tz->trips.passive.tc1 = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 370 | status = acpi_evaluate_integer( |
| 371 | tz->device->handle, "_TC2", |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 372 | NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 373 | if (ACPI_FAILURE(status)) |
| 374 | tz->trips.passive.flags.valid = 0; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 375 | else |
| 376 | tz->trips.passive.tc2 = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 377 | status = acpi_evaluate_integer( |
| 378 | tz->device->handle, "_TSP", |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 379 | NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 380 | if (ACPI_FAILURE(status)) |
| 381 | tz->trips.passive.flags.valid = 0; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 382 | else |
| 383 | tz->trips.passive.tsp = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 384 | } |
| 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 Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 391 | if (ACPI_FAILURE(status)) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 392 | pr_warn(PREFIX "Invalid passive threshold\n"); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 393 | tz->trips.passive.flags.valid = 0; |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 394 | } |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 395 | 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 411 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 412 | char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 413 | valid = tz->trips.active[i].flags.valid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 415 | if (act == -1) |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 416 | break; /* disable all active trip points */ |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 417 | |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 418 | if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) && |
| 419 | tz->trips.active[i].flags.valid)) { |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 420 | status = acpi_evaluate_integer(tz->device->handle, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 421 | name, NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 422 | 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 Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 441 | break; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 442 | } else { |
| 443 | tz->trips.active[i].temperature = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 444 | tz->trips.active[i].flags.valid = 1; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 445 | } |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 446 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
| 448 | name[2] = 'L'; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 449 | 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 Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 453 | if (ACPI_FAILURE(status)) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 454 | pr_warn(PREFIX "Invalid active%d threshold\n", |
| 455 | i); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 456 | tz->trips.active[i].flags.valid = 0; |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 457 | } |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 458 | 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 Tianyu | 668e020 | 2013-08-27 16:29:31 +0800 | [diff] [blame] | 476 | if ((flag & ACPI_TRIPS_DEVICES) |
| 477 | && acpi_has_method(tz->device->handle, "_TZD")) { |
| 478 | memset(&devices, 0, sizeof(devices)); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 479 | status = acpi_evaluate_reference(tz->device->handle, "_TZD", |
| 480 | NULL, &devices); |
Lan Tianyu | 668e020 | 2013-08-27 16:29:31 +0800 | [diff] [blame] | 481 | if (ACPI_SUCCESS(status) |
| 482 | && memcmp(&tz->devices, &devices, sizeof(devices))) { |
| 483 | tz->devices = devices; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 484 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); |
| 485 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 488 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 491 | static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | { |
Thomas Renninger | 8b7ef6d | 2010-02-16 22:55:51 +0100 | [diff] [blame] | 493 | 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 Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 506 | pr_warn(FW_BUG "No valid trip found\n"); |
Thomas Renninger | 8b7ef6d | 2010-02-16 22:55:51 +0100 | [diff] [blame] | 507 | return -ENODEV; |
| 508 | } |
| 509 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 512 | static void acpi_thermal_check(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 514 | struct acpi_thermal *tz = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
Srinivas Pandruvada | e994d71 | 2013-09-25 09:29:50 -0700 | [diff] [blame] | 516 | if (!tz->tz_enabled) |
Srinivas Pandruvada | ca4e713 | 2013-01-15 23:57:16 +0100 | [diff] [blame] | 517 | return; |
Srinivas Pandruvada | e994d71 | 2013-09-25 09:29:50 -0700 | [diff] [blame] | 518 | |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 519 | thermal_zone_device_update(tz->thermal_zone); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 522 | /* sys I/F for generic thermal sysfs support */ |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 523 | #define KELVIN_TO_MILLICELSIUS(t, off) (((t) - (off)) * 100) |
Zhang, Rui | 5e01276 | 2008-02-28 07:51:30 +0800 | [diff] [blame] | 524 | |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 525 | static int thermal_get_temp(struct thermal_zone_device *thermal, |
| 526 | unsigned long *temp) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 527 | { |
| 528 | struct acpi_thermal *tz = thermal->devdata; |
Zhang, Rui | 76ecb4f | 2008-04-10 16:20:23 +0800 | [diff] [blame] | 529 | int result; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 530 | |
| 531 | if (!tz) |
| 532 | return -EINVAL; |
| 533 | |
Zhang, Rui | 76ecb4f | 2008-04-10 16:20:23 +0800 | [diff] [blame] | 534 | result = acpi_thermal_get_temperature(tz); |
| 535 | if (result) |
| 536 | return result; |
| 537 | |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 538 | *temp = KELVIN_TO_MILLICELSIUS(tz->temperature, tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 539 | return 0; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 540 | } |
| 541 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 542 | static int thermal_get_mode(struct thermal_zone_device *thermal, |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 543 | enum thermal_device_mode *mode) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 544 | { |
| 545 | struct acpi_thermal *tz = thermal->devdata; |
| 546 | |
| 547 | if (!tz) |
| 548 | return -EINVAL; |
| 549 | |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 550 | *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : |
| 551 | THERMAL_DEVICE_DISABLED; |
| 552 | |
| 553 | return 0; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | static int thermal_set_mode(struct thermal_zone_device *thermal, |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 557 | enum thermal_device_mode mode) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 558 | { |
| 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 Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 568 | if (mode == THERMAL_DEVICE_ENABLED) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 569 | enable = 1; |
Srinivas Pandruvada | e994d71 | 2013-09-25 09:29:50 -0700 | [diff] [blame] | 570 | else if (mode == THERMAL_DEVICE_DISABLED) { |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 571 | enable = 0; |
Srinivas Pandruvada | e994d71 | 2013-09-25 09:29:50 -0700 | [diff] [blame] | 572 | pr_warn("thermal zone will be disabled\n"); |
| 573 | } else |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 574 | return -EINVAL; |
| 575 | |
| 576 | if (enable != tz->tz_enabled) { |
| 577 | tz->tz_enabled = enable; |
| 578 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Zhang Rui | 8eaa8d6 | 2012-07-25 10:11:00 +0800 | [diff] [blame] | 579 | "%s kernel ACPI thermal control\n", |
| 580 | tz->tz_enabled ? "Enable" : "Disable")); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 581 | acpi_thermal_check(tz); |
| 582 | } |
| 583 | return 0; |
| 584 | } |
| 585 | |
| 586 | static int thermal_get_trip_type(struct thermal_zone_device *thermal, |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 587 | int trip, enum thermal_trip_type *type) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 588 | { |
| 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 Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 596 | if (!trip) { |
| 597 | *type = THERMAL_TRIP_CRITICAL; |
| 598 | return 0; |
| 599 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 600 | trip--; |
| 601 | } |
| 602 | |
| 603 | if (tz->trips.hot.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 604 | if (!trip) { |
| 605 | *type = THERMAL_TRIP_HOT; |
| 606 | return 0; |
| 607 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 608 | trip--; |
| 609 | } |
| 610 | |
| 611 | if (tz->trips.passive.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 612 | if (!trip) { |
| 613 | *type = THERMAL_TRIP_PASSIVE; |
| 614 | return 0; |
| 615 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 616 | trip--; |
| 617 | } |
| 618 | |
| 619 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && |
| 620 | tz->trips.active[i].flags.valid; i++) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 621 | if (!trip) { |
| 622 | *type = THERMAL_TRIP_ACTIVE; |
| 623 | return 0; |
| 624 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 625 | trip--; |
| 626 | } |
| 627 | |
| 628 | return -EINVAL; |
| 629 | } |
| 630 | |
| 631 | static int thermal_get_trip_temp(struct thermal_zone_device *thermal, |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 632 | int trip, unsigned long *temp) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 633 | { |
| 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 Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 641 | if (!trip) { |
| 642 | *temp = KELVIN_TO_MILLICELSIUS( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 643 | tz->trips.critical.temperature, |
| 644 | tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 645 | return 0; |
| 646 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 647 | trip--; |
| 648 | } |
| 649 | |
| 650 | if (tz->trips.hot.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 651 | if (!trip) { |
| 652 | *temp = KELVIN_TO_MILLICELSIUS( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 653 | tz->trips.hot.temperature, |
| 654 | tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 655 | return 0; |
| 656 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 657 | trip--; |
| 658 | } |
| 659 | |
| 660 | if (tz->trips.passive.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 661 | if (!trip) { |
| 662 | *temp = KELVIN_TO_MILLICELSIUS( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 663 | tz->trips.passive.temperature, |
| 664 | tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 665 | return 0; |
| 666 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 667 | trip--; |
| 668 | } |
| 669 | |
| 670 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && |
| 671 | tz->trips.active[i].flags.valid; i++) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 672 | if (!trip) { |
| 673 | *temp = KELVIN_TO_MILLICELSIUS( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 674 | tz->trips.active[i].temperature, |
| 675 | tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 676 | return 0; |
| 677 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 678 | trip--; |
| 679 | } |
| 680 | |
| 681 | return -EINVAL; |
| 682 | } |
| 683 | |
Zhang, Rui | 9ec732f | 2008-04-10 16:13:10 +0800 | [diff] [blame] | 684 | static 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 Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 690 | tz->trips.critical.temperature, |
| 691 | tz->kelvin_offset); |
Zhang, Rui | 9ec732f | 2008-04-10 16:13:10 +0800 | [diff] [blame] | 692 | return 0; |
| 693 | } else |
| 694 | return -EINVAL; |
| 695 | } |
| 696 | |
Zhang Rui | 601f3d4 | 2012-06-27 09:54:33 +0800 | [diff] [blame] | 697 | static 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 Rui | 4ae46be | 2012-06-27 10:05:39 +0800 | [diff] [blame] | 707 | if (type == THERMAL_TRIP_ACTIVE) { |
Zhang Rui | 94a4093 | 2013-04-26 09:19:53 +0000 | [diff] [blame] | 708 | 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 Rui | 4ae46be | 2012-06-27 10:05:39 +0800 | [diff] [blame] | 721 | } |
Zhang Rui | 601f3d4 | 2012-06-27 09:54:33 +0800 | [diff] [blame] | 722 | |
| 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 Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 741 | static 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 Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 754 | acpi_bus_generate_netlink_event(tz->device->pnp.device_class, |
Stephen Rothwell | f6f5c45 | 2009-03-03 12:47:17 +1100 | [diff] [blame] | 755 | dev_name(&tz->device->dev), type, 1); |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 756 | |
| 757 | if (trip_type == THERMAL_TRIP_CRITICAL && nocrt) |
| 758 | return 1; |
| 759 | |
| 760 | return 0; |
| 761 | } |
| 762 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 763 | static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal, |
| 764 | struct thermal_cooling_device *cdev, |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 765 | bool bind) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 766 | { |
| 767 | struct acpi_device *device = cdev->devdata; |
| 768 | struct acpi_thermal *tz = thermal->devdata; |
Zhang Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 769 | struct acpi_device *dev; |
| 770 | acpi_status status; |
| 771 | acpi_handle handle; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 772 | 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 Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 787 | handle = tz->trips.passive.devices.handles[i]; |
| 788 | status = acpi_bus_get_device(handle, &dev); |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 789 | 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 Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 802 | } |
| 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 Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 812 | handle = tz->trips.active[i].devices.handles[j]; |
| 813 | status = acpi_bus_get_device(handle, &dev); |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 814 | 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 Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 825 | } |
| 826 | } |
| 827 | |
| 828 | for (i = 0; i < tz->devices.count; i++) { |
Zhang Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 829 | handle = tz->devices.handles[i]; |
| 830 | status = acpi_bus_get_device(handle, &dev); |
| 831 | if (ACPI_SUCCESS(status) && (dev == device)) { |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 832 | if (bind) |
| 833 | result = thermal_zone_bind_cooling_device |
Lan Tianyu | 70f2903 | 2013-08-14 21:00:39 +0800 | [diff] [blame] | 834 | (thermal, THERMAL_TRIPS_NONE, |
| 835 | cdev, THERMAL_NO_LIMIT, |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 836 | THERMAL_NO_LIMIT); |
| 837 | else |
| 838 | result = thermal_zone_unbind_cooling_device |
Lan Tianyu | 70f2903 | 2013-08-14 21:00:39 +0800 | [diff] [blame] | 839 | (thermal, THERMAL_TRIPS_NONE, |
| 840 | cdev); |
Zhang Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 841 | if (result) |
| 842 | goto failed; |
| 843 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | failed: |
| 847 | return result; |
| 848 | } |
| 849 | |
| 850 | static int |
| 851 | acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal, |
| 852 | struct thermal_cooling_device *cdev) |
| 853 | { |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 854 | return acpi_thermal_cooling_device_cb(thermal, cdev, true); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | static int |
| 858 | acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal, |
| 859 | struct thermal_cooling_device *cdev) |
| 860 | { |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 861 | return acpi_thermal_cooling_device_cb(thermal, cdev, false); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 862 | } |
| 863 | |
Emil Goode | ec9c9c2 | 2014-01-07 17:24:55 +0100 | [diff] [blame] | 864 | static struct thermal_zone_device_ops acpi_thermal_zone_ops = { |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 865 | .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, Rui | 9ec732f | 2008-04-10 16:13:10 +0800 | [diff] [blame] | 872 | .get_crit_temp = thermal_get_crit_temp, |
Zhang Rui | 601f3d4 | 2012-06-27 09:54:33 +0800 | [diff] [blame] | 873 | .get_trend = thermal_get_trend, |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 874 | .notify = thermal_notify, |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 875 | }; |
| 876 | |
| 877 | static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) |
| 878 | { |
| 879 | int trips = 0; |
| 880 | int result; |
Zhang Rui | 2073393 | 2008-01-17 15:51:21 +0800 | [diff] [blame] | 881 | acpi_status status; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 882 | 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 Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 895 | |
| 896 | if (tz->trips.passive.flags.valid) |
| 897 | tz->thermal_zone = |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 898 | thermal_zone_device_register("acpitz", trips, 0, tz, |
Durgadoss R | 50125a9 | 2012-09-18 11:04:56 +0530 | [diff] [blame] | 899 | &acpi_thermal_zone_ops, NULL, |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 900 | tz->trips.passive.tsp*100, |
| 901 | tz->polling_frequency*100); |
| 902 | else |
| 903 | tz->thermal_zone = |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 904 | thermal_zone_device_register("acpitz", trips, 0, tz, |
Durgadoss R | 50125a9 | 2012-09-18 11:04:56 +0530 | [diff] [blame] | 905 | &acpi_thermal_zone_ops, NULL, |
| 906 | 0, tz->polling_frequency*100); |
Krzysztof Helt | bb070e4 | 2008-04-08 17:41:52 -0700 | [diff] [blame] | 907 | if (IS_ERR(tz->thermal_zone)) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 908 | 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 Rui | 2073393 | 2008-01-17 15:51:21 +0800 | [diff] [blame] | 920 | status = acpi_attach_data(tz->device->handle, |
| 921 | acpi_bus_private_data_handler, |
| 922 | tz->thermal_zone); |
| 923 | if (ACPI_FAILURE(status)) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 924 | pr_err(PREFIX "Error attaching device data\n"); |
Zhang Rui | 2073393 | 2008-01-17 15:51:21 +0800 | [diff] [blame] | 925 | return -ENODEV; |
| 926 | } |
| 927 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 928 | tz->tz_enabled = 1; |
| 929 | |
Greg Kroah-Hartman | fc3a882 | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 930 | dev_info(&tz->device->dev, "registered as thermal_zone%d\n", |
| 931 | tz->thermal_zone->id); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 932 | return 0; |
| 933 | } |
| 934 | |
| 935 | static 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 Rui | 2073393 | 2008-01-17 15:51:21 +0800 | [diff] [blame] | 941 | acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | /* -------------------------------------------------------------------------- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | Driver Interface |
| 947 | -------------------------------------------------------------------------- */ |
| 948 | |
Bjorn Helgaas | 342d550 | 2009-04-07 15:37:06 +0000 | [diff] [blame] | 949 | static void acpi_thermal_notify(struct acpi_device *device, u32 event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | { |
Bjorn Helgaas | 342d550 | 2009-04-07 15:37:06 +0000 | [diff] [blame] | 951 | struct acpi_thermal *tz = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | |
| 954 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 955 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | switch (event) { |
| 958 | case ACPI_THERMAL_NOTIFY_TEMPERATURE: |
| 959 | acpi_thermal_check(tz); |
| 960 | break; |
| 961 | case ACPI_THERMAL_NOTIFY_THRESHOLDS: |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 962 | acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | acpi_thermal_check(tz); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 964 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
Kay Sievers | 0794469 | 2008-10-30 01:18:59 +0100 | [diff] [blame] | 965 | dev_name(&device->dev), event, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | break; |
| 967 | case ACPI_THERMAL_NOTIFY_DEVICES: |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 968 | acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES); |
| 969 | acpi_thermal_check(tz); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 970 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
Kay Sievers | 0794469 | 2008-10-30 01:18:59 +0100 | [diff] [blame] | 971 | dev_name(&device->dev), event, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | break; |
| 973 | default: |
| 974 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 975 | "Unsupported event [0x%x]\n", event)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | break; |
| 977 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | } |
| 979 | |
Zhang Rui | 261cba2 | 2012-11-27 20:42:11 +0100 | [diff] [blame] | 980 | /* |
| 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 | */ |
| 992 | static 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1012 | static int acpi_thermal_get_info(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1014 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | |
| 1017 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1018 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | |
Zhang Rui | 261cba2 | 2012-11-27 20:42:11 +0100 | [diff] [blame] | 1020 | acpi_thermal_aml_dependency_fix(tz); |
| 1021 | |
Matthew Garrett | 9bcb811 | 2012-02-01 10:26:54 -0500 | [diff] [blame] | 1022 | /* Get trip points [_CRT, _PSV, etc.] (required) */ |
| 1023 | result = acpi_thermal_get_trip_points(tz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1025 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | |
Matthew Garrett | 9bcb811 | 2012-02-01 10:26:54 -0500 | [diff] [blame] | 1027 | /* Get temperature [_TMP] (required) */ |
| 1028 | result = acpi_thermal_get_temperature(tz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1030 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | |
| 1032 | /* Set the cooling mode [_SCP] to active cooling (default) */ |
| 1033 | result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1034 | if (!result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | tz->flags.cooling_mode = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | |
| 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 Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1043 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | } |
| 1045 | |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 1046 | /* |
| 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 | */ |
| 1056 | static 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1065 | static int acpi_thermal_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1067 | int result = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1068 | struct acpi_thermal *tz = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | |
| 1071 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1072 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 1074 | tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1076 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | |
Patrick Mochel | 8348e1b | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 1078 | tz->device = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | 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 Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 1082 | device->driver_data = tz; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1083 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | result = acpi_thermal_get_info(tz); |
| 1085 | if (result) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1086 | goto free_memory; |
| 1087 | |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 1088 | acpi_thermal_guess_offset(tz); |
| 1089 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1090 | result = acpi_thermal_register_thermal_zone(tz); |
| 1091 | if (result) |
| 1092 | goto free_memory; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 1094 | pr_info(PREFIX "%s [%s] (%ld C)\n", acpi_device_name(device), |
| 1095 | acpi_device_bid(device), KELVIN_TO_CELSIUS(tz->temperature)); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1096 | goto end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1098 | free_memory: |
| 1099 | kfree(tz); |
| 1100 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1101 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
Rafael J. Wysocki | 51fac83 | 2013-01-24 00:24:48 +0100 | [diff] [blame] | 1104 | static int acpi_thermal_remove(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1106 | struct acpi_thermal *tz = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | if (!device || !acpi_driver_data(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1109 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1111 | tz = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1113 | acpi_thermal_unregister_thermal_zone(tz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | kfree(tz); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1115 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | } |
| 1117 | |
Rafael J. Wysocki | 9069240 | 2012-08-09 23:00:02 +0200 | [diff] [blame] | 1118 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 1119 | static int acpi_thermal_resume(struct device *dev) |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1120 | { |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 1121 | struct acpi_thermal *tz; |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1122 | int i, j, power_state, result; |
| 1123 | |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 1124 | if (!dev) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1125 | return -EINVAL; |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1126 | |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 1127 | tz = acpi_driver_data(to_acpi_device(dev)); |
| 1128 | if (!tz) |
| 1129 | return -EINVAL; |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1130 | |
Konstantin Karasyov | bed936f | 2006-07-10 04:44:26 -0700 | [diff] [blame] | 1131 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1132 | 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. Wysocki | 488a76c | 2010-11-25 00:11:24 +0100 | [diff] [blame] | 1138 | result = acpi_bus_update_power( |
| 1139 | tz->trips.active[i].devices.handles[j], |
| 1140 | &power_state); |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1141 | if (result || (power_state != ACPI_STATE_D0)) { |
| 1142 | tz->trips.active[i].flags.enabled = 0; |
| 1143 | break; |
| 1144 | } |
Konstantin Karasyov | bed936f | 2006-07-10 04:44:26 -0700 | [diff] [blame] | 1145 | } |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1146 | tz->state.active |= tz->trips.active[i].flags.enabled; |
Konstantin Karasyov | bed936f | 2006-07-10 04:44:26 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1149 | acpi_thermal_check(tz); |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1150 | |
| 1151 | return AE_OK; |
| 1152 | } |
Rafael J. Wysocki | 9069240 | 2012-08-09 23:00:02 +0200 | [diff] [blame] | 1153 | #endif |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1154 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 1155 | static int thermal_act(const struct dmi_system_id *d) { |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1156 | |
| 1157 | if (act == 0) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 1158 | pr_notice(PREFIX "%s detected: " |
| 1159 | "disabling all active thermal trip points\n", d->ident); |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1160 | act = -1; |
| 1161 | } |
| 1162 | return 0; |
| 1163 | } |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 1164 | static int thermal_nocrt(const struct dmi_system_id *d) { |
Len Brown | 8c99fdc | 2007-08-20 18:46:50 -0400 | [diff] [blame] | 1165 | |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 1166 | pr_notice(PREFIX "%s detected: " |
| 1167 | "disabling all critical thermal trip point actions.\n", d->ident); |
Len Brown | 8c99fdc | 2007-08-20 18:46:50 -0400 | [diff] [blame] | 1168 | nocrt = 1; |
| 1169 | return 0; |
| 1170 | } |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 1171 | static int thermal_tzp(const struct dmi_system_id *d) { |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1172 | |
| 1173 | if (tzp == 0) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 1174 | pr_notice(PREFIX "%s detected: " |
| 1175 | "enabling thermal zone polling\n", d->ident); |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1176 | tzp = 300; /* 300 dS = 30 Seconds */ |
| 1177 | } |
| 1178 | return 0; |
| 1179 | } |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 1180 | static int thermal_psv(const struct dmi_system_id *d) { |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1181 | |
| 1182 | if (psv == 0) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 1183 | pr_notice(PREFIX "%s detected: " |
| 1184 | "disabling all passive thermal trip points\n", d->ident); |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1185 | psv = -1; |
| 1186 | } |
| 1187 | return 0; |
| 1188 | } |
| 1189 | |
| 1190 | static 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 Brown | 8c99fdc | 2007-08-20 18:46:50 -0400 | [diff] [blame] | 1219 | { |
| 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 Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1227 | {} |
| 1228 | }; |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1229 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1230 | static int __init acpi_thermal_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1232 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1234 | dmi_check_system(thermal_dmi_table); |
| 1235 | |
Len Brown | 72b33ef | 2007-08-12 00:12:17 -0400 | [diff] [blame] | 1236 | if (off) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 1237 | pr_notice(PREFIX "thermal control disabled\n"); |
Len Brown | 72b33ef | 2007-08-12 00:12:17 -0400 | [diff] [blame] | 1238 | return -ENODEV; |
| 1239 | } |
Zhang Rui | 43d9f87 | 2010-07-15 10:46:44 +0800 | [diff] [blame] | 1240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | result = acpi_bus_register_driver(&acpi_thermal_driver); |
Zhang Rui | c57b62f | 2010-10-08 13:55:06 +0800 | [diff] [blame] | 1242 | if (result < 0) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1243 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1245 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1248 | static void __exit acpi_thermal_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | |
| 1251 | acpi_bus_unregister_driver(&acpi_thermal_driver); |
| 1252 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1253 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | } |
| 1255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | module_init(acpi_thermal_init); |
| 1257 | module_exit(acpi_thermal_exit); |