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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <asm/uaccess.h> |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 45 | #include <linux/thermal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <acpi/acpi_bus.h> |
| 47 | #include <acpi/acpi_drivers.h> |
| 48 | |
Len Brown | a192a95 | 2009-07-28 16:45:54 -0400 | [diff] [blame] | 49 | #define PREFIX "ACPI: " |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define ACPI_THERMAL_CLASS "thermal_zone" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80 |
| 54 | #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81 |
| 55 | #define ACPI_THERMAL_NOTIFY_DEVICES 0x82 |
| 56 | #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0 |
| 57 | #define ACPI_THERMAL_NOTIFY_HOT 0xF1 |
| 58 | #define ACPI_THERMAL_MODE_ACTIVE 0x00 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | #define ACPI_THERMAL_MAX_ACTIVE 10 |
| 61 | #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65 |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #define _COMPONENT ACPI_THERMAL_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 64 | ACPI_MODULE_NAME("thermal"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 66 | MODULE_AUTHOR("Paul Diefenbaugh"); |
Len Brown | 7cda93e | 2007-02-12 23:50:02 -0500 | [diff] [blame] | 67 | MODULE_DESCRIPTION("ACPI Thermal Zone Driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | MODULE_LICENSE("GPL"); |
| 69 | |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 70 | static int act; |
| 71 | module_param(act, int, 0644); |
Len Brown | 3c1d36d | 2007-08-14 15:12:56 -0400 | [diff] [blame] | 72 | MODULE_PARM_DESC(act, "Disable or override all lowest active trip points."); |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 73 | |
Len Brown | c52a741 | 2007-08-14 15:49:32 -0400 | [diff] [blame] | 74 | static int crt; |
| 75 | module_param(crt, int, 0644); |
| 76 | MODULE_PARM_DESC(crt, "Disable or lower all critical trip points."); |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | static int tzp; |
Len Brown | 730ff34 | 2007-08-12 00:12:26 -0400 | [diff] [blame] | 79 | module_param(tzp, int, 0444); |
Len Brown | 3c1d36d | 2007-08-14 15:12:56 -0400 | [diff] [blame] | 80 | MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Len Brown | f548714 | 2007-08-12 00:12:44 -0400 | [diff] [blame] | 82 | static int nocrt; |
| 83 | module_param(nocrt, int, 0); |
Len Brown | 8c99fdc | 2007-08-20 18:46:50 -0400 | [diff] [blame] | 84 | 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] | 85 | |
Len Brown | 72b33ef | 2007-08-12 00:12:17 -0400 | [diff] [blame] | 86 | static int off; |
| 87 | module_param(off, int, 0); |
Len Brown | 3c1d36d | 2007-08-14 15:12:56 -0400 | [diff] [blame] | 88 | MODULE_PARM_DESC(off, "Set to disable ACPI thermal support."); |
Len Brown | 72b33ef | 2007-08-12 00:12:17 -0400 | [diff] [blame] | 89 | |
Len Brown | a70cdc5 | 2007-08-12 00:12:35 -0400 | [diff] [blame] | 90 | static int psv; |
| 91 | module_param(psv, int, 0644); |
Len Brown | 3c1d36d | 2007-08-14 15:12:56 -0400 | [diff] [blame] | 92 | MODULE_PARM_DESC(psv, "Disable or override all passive trip points."); |
Len Brown | a70cdc5 | 2007-08-12 00:12:35 -0400 | [diff] [blame] | 93 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 94 | static int acpi_thermal_add(struct acpi_device *device); |
Rafael J. Wysocki | 51fac83 | 2013-01-24 00:24:48 +0100 | [diff] [blame] | 95 | static int acpi_thermal_remove(struct acpi_device *device); |
Bjorn Helgaas | 342d550 | 2009-04-07 15:37:06 +0000 | [diff] [blame] | 96 | static void acpi_thermal_notify(struct acpi_device *device, u32 event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 98 | static const struct acpi_device_id thermal_device_ids[] = { |
| 99 | {ACPI_THERMAL_HID, 0}, |
| 100 | {"", 0}, |
| 101 | }; |
| 102 | MODULE_DEVICE_TABLE(acpi, thermal_device_ids); |
| 103 | |
Rafael J. Wysocki | 9069240 | 2012-08-09 23:00:02 +0200 | [diff] [blame] | 104 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 105 | static int acpi_thermal_resume(struct device *dev); |
Rafael J. Wysocki | 9069240 | 2012-08-09 23:00:02 +0200 | [diff] [blame] | 106 | #endif |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 107 | static SIMPLE_DEV_PM_OPS(acpi_thermal_pm, NULL, acpi_thermal_resume); |
| 108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | static struct acpi_driver acpi_thermal_driver = { |
Len Brown | c2b6705 | 2007-02-12 23:33:40 -0500 | [diff] [blame] | 110 | .name = "thermal", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 111 | .class = ACPI_THERMAL_CLASS, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 112 | .ids = thermal_device_ids, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 113 | .ops = { |
| 114 | .add = acpi_thermal_add, |
| 115 | .remove = acpi_thermal_remove, |
Bjorn Helgaas | 342d550 | 2009-04-07 15:37:06 +0000 | [diff] [blame] | 116 | .notify = acpi_thermal_notify, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 117 | }, |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 118 | .drv.pm = &acpi_thermal_pm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | struct acpi_thermal_state { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 122 | u8 critical:1; |
| 123 | u8 hot:1; |
| 124 | u8 passive:1; |
| 125 | u8 active:1; |
| 126 | u8 reserved:4; |
| 127 | int active_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | struct acpi_thermal_state_flags { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 131 | u8 valid:1; |
| 132 | u8 enabled:1; |
| 133 | u8 reserved:6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | struct acpi_thermal_critical { |
| 137 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 | unsigned long temperature; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | struct acpi_thermal_hot { |
| 142 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 143 | unsigned long temperature; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | struct acpi_thermal_passive { |
| 147 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 148 | unsigned long temperature; |
| 149 | unsigned long tc1; |
| 150 | unsigned long tc2; |
| 151 | unsigned long tsp; |
| 152 | struct acpi_handle_list devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | struct acpi_thermal_active { |
| 156 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 157 | unsigned long temperature; |
| 158 | struct acpi_handle_list devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | struct acpi_thermal_trips { |
| 162 | struct acpi_thermal_critical critical; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 163 | struct acpi_thermal_hot hot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | struct acpi_thermal_passive passive; |
| 165 | struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE]; |
| 166 | }; |
| 167 | |
| 168 | struct acpi_thermal_flags { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 169 | u8 cooling_mode:1; /* _SCP */ |
| 170 | u8 devices:1; /* _TZD */ |
| 171 | u8 reserved:6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | struct acpi_thermal { |
Patrick Mochel | 8348e1b | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 175 | struct acpi_device * device; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 176 | acpi_bus_id name; |
| 177 | unsigned long temperature; |
| 178 | unsigned long last_temperature; |
| 179 | unsigned long polling_frequency; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 180 | volatile u8 zombie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | struct acpi_thermal_flags flags; |
| 182 | struct acpi_thermal_state state; |
| 183 | struct acpi_thermal_trips trips; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 184 | struct acpi_handle_list devices; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 185 | struct thermal_zone_device *thermal_zone; |
| 186 | int tz_enabled; |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 187 | int kelvin_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | }; |
| 189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | /* -------------------------------------------------------------------------- |
| 191 | Thermal Zone Management |
| 192 | -------------------------------------------------------------------------- */ |
| 193 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 194 | static int acpi_thermal_get_temperature(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | acpi_status status = AE_OK; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 197 | unsigned long long tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
| 199 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 200 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | tz->last_temperature = tz->temperature; |
| 203 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 204 | status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 206 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 208 | tz->temperature = tmp; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 209 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n", |
| 210 | tz->temperature)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 212 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 215 | static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 217 | acpi_status status = AE_OK; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 218 | unsigned long long tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 221 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 223 | status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 225 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 227 | tz->polling_frequency = tmp; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 228 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n", |
| 229 | tz->polling_frequency)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 231 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 234 | 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] | 235 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 237 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Jiang Liu | 0db9820 | 2013-06-29 00:24:39 +0800 | [diff] [blame] | 239 | if (!acpi_has_method(tz->device->handle, "_SCP")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 241 | return -ENODEV; |
Jiang Liu | 0db9820 | 2013-06-29 00:24:39 +0800 | [diff] [blame] | 242 | } else if (ACPI_FAILURE(acpi_execute_simple_method(tz->device->handle, |
| 243 | "_SCP", mode))) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 244 | return -ENODEV; |
Jiang Liu | 0db9820 | 2013-06-29 00:24:39 +0800 | [diff] [blame] | 245 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 247 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 250 | #define ACPI_TRIPS_CRITICAL 0x01 |
| 251 | #define ACPI_TRIPS_HOT 0x02 |
| 252 | #define ACPI_TRIPS_PASSIVE 0x04 |
| 253 | #define ACPI_TRIPS_ACTIVE 0x08 |
| 254 | #define ACPI_TRIPS_DEVICES 0x10 |
| 255 | |
| 256 | #define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE) |
| 257 | #define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES |
| 258 | |
| 259 | #define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \ |
| 260 | ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \ |
| 261 | ACPI_TRIPS_DEVICES) |
| 262 | |
| 263 | /* |
| 264 | * This exception is thrown out in two cases: |
| 265 | * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid |
| 266 | * when re-evaluating the AML code. |
| 267 | * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change. |
| 268 | * We need to re-bind the cooling devices of a thermal zone when this occurs. |
| 269 | */ |
| 270 | #define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \ |
| 271 | do { \ |
| 272 | if (flags != ACPI_TRIPS_INIT) \ |
| 273 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, \ |
| 274 | "ACPI thermal trip point %s changed\n" \ |
Colin Ian King | 7e3cf24 | 2012-11-29 11:53:16 +0000 | [diff] [blame] | 275 | "Please send acpidump to linux-acpi@vger.kernel.org", str)); \ |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 276 | } while (0) |
| 277 | |
| 278 | static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 280 | acpi_status status = AE_OK; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 281 | unsigned long long tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 282 | struct acpi_handle_list devices; |
| 283 | int valid = 0; |
| 284 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
Thomas Renninger | fa80945 | 2010-02-20 11:44:27 +0100 | [diff] [blame] | 286 | /* Critical Shutdown */ |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 287 | if (flag & ACPI_TRIPS_CRITICAL) { |
| 288 | status = acpi_evaluate_integer(tz->device->handle, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 289 | "_CRT", NULL, &tmp); |
| 290 | tz->trips.critical.temperature = tmp; |
Arjan van de Ven | a39a2d7 | 2008-05-19 15:55:15 -0700 | [diff] [blame] | 291 | /* |
| 292 | * Treat freezing temperatures as invalid as well; some |
| 293 | * BIOSes return really low values and cause reboots at startup. |
Adam Buchbinder | b731d7b | 2009-03-13 12:15:26 -0400 | [diff] [blame] | 294 | * Below zero (Celsius) values clearly aren't right for sure.. |
Arjan van de Ven | a39a2d7 | 2008-05-19 15:55:15 -0700 | [diff] [blame] | 295 | * ... so lets discard those as invalid. |
| 296 | */ |
Thomas Renninger | fa80945 | 2010-02-20 11:44:27 +0100 | [diff] [blame] | 297 | if (ACPI_FAILURE(status)) { |
Len Brown | c52a741 | 2007-08-14 15:49:32 -0400 | [diff] [blame] | 298 | tz->trips.critical.flags.valid = 0; |
Thomas Renninger | fa80945 | 2010-02-20 11:44:27 +0100 | [diff] [blame] | 299 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 300 | "No critical threshold\n")); |
| 301 | } else if (tmp <= 2732) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 302 | pr_warn(FW_BUG "Invalid critical threshold (%llu)\n", |
| 303 | tmp); |
Thomas Renninger | fa80945 | 2010-02-20 11:44:27 +0100 | [diff] [blame] | 304 | tz->trips.critical.flags.valid = 0; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 305 | } else { |
| 306 | tz->trips.critical.flags.valid = 1; |
| 307 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Thomas Renninger | fa80945 | 2010-02-20 11:44:27 +0100 | [diff] [blame] | 308 | "Found critical threshold [%lu]\n", |
| 309 | tz->trips.critical.temperature)); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 310 | } |
| 311 | if (tz->trips.critical.flags.valid == 1) { |
| 312 | if (crt == -1) { |
| 313 | tz->trips.critical.flags.valid = 0; |
| 314 | } else if (crt > 0) { |
| 315 | unsigned long crt_k = CELSIUS_TO_KELVIN(crt); |
| 316 | /* |
Zhang Rui | 22a94d7 | 2008-10-17 02:41:20 -0400 | [diff] [blame] | 317 | * Allow override critical threshold |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 318 | */ |
Zhang Rui | 22a94d7 | 2008-10-17 02:41:20 -0400 | [diff] [blame] | 319 | if (crt_k > tz->trips.critical.temperature) |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 320 | pr_warn(PREFIX "Critical threshold %d C\n", |
| 321 | crt); |
Zhang Rui | 22a94d7 | 2008-10-17 02:41:20 -0400 | [diff] [blame] | 322 | tz->trips.critical.temperature = crt_k; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 323 | } |
Len Brown | c52a741 | 2007-08-14 15:49:32 -0400 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | /* Critical Sleep (optional) */ |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 328 | if (flag & ACPI_TRIPS_HOT) { |
Len Brown | a70cdc5 | 2007-08-12 00:12:35 -0400 | [diff] [blame] | 329 | status = acpi_evaluate_integer(tz->device->handle, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 330 | "_HOT", NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 331 | if (ACPI_FAILURE(status)) { |
| 332 | tz->trips.hot.flags.valid = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 333 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 334 | "No hot threshold\n")); |
| 335 | } else { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 336 | tz->trips.hot.temperature = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 337 | tz->trips.hot.flags.valid = 1; |
| 338 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 339 | "Found hot threshold [%lu]\n", |
| 340 | tz->trips.critical.temperature)); |
| 341 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 344 | /* Passive (optional) */ |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 345 | if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) || |
| 346 | (flag == ACPI_TRIPS_INIT)) { |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 347 | valid = tz->trips.passive.flags.valid; |
| 348 | if (psv == -1) { |
| 349 | status = AE_SUPPORT; |
| 350 | } else if (psv > 0) { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 351 | tmp = CELSIUS_TO_KELVIN(psv); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 352 | status = AE_OK; |
| 353 | } else { |
| 354 | status = acpi_evaluate_integer(tz->device->handle, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 355 | "_PSV", NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 356 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 358 | if (ACPI_FAILURE(status)) |
| 359 | tz->trips.passive.flags.valid = 0; |
| 360 | else { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 361 | tz->trips.passive.temperature = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 362 | tz->trips.passive.flags.valid = 1; |
| 363 | if (flag == ACPI_TRIPS_INIT) { |
| 364 | status = acpi_evaluate_integer( |
| 365 | tz->device->handle, "_TC1", |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 366 | NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 367 | if (ACPI_FAILURE(status)) |
| 368 | tz->trips.passive.flags.valid = 0; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 369 | else |
| 370 | tz->trips.passive.tc1 = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 371 | status = acpi_evaluate_integer( |
| 372 | tz->device->handle, "_TC2", |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 373 | NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 374 | if (ACPI_FAILURE(status)) |
| 375 | tz->trips.passive.flags.valid = 0; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 376 | else |
| 377 | tz->trips.passive.tc2 = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 378 | status = acpi_evaluate_integer( |
| 379 | tz->device->handle, "_TSP", |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 380 | NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 381 | if (ACPI_FAILURE(status)) |
| 382 | tz->trips.passive.flags.valid = 0; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 383 | else |
| 384 | tz->trips.passive.tsp = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | } |
| 388 | if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) { |
| 389 | memset(&devices, 0, sizeof(struct acpi_handle_list)); |
| 390 | status = acpi_evaluate_reference(tz->device->handle, "_PSL", |
| 391 | NULL, &devices); |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 392 | if (ACPI_FAILURE(status)) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 393 | pr_warn(PREFIX "Invalid passive threshold\n"); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 394 | tz->trips.passive.flags.valid = 0; |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 395 | } |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 396 | else |
| 397 | tz->trips.passive.flags.valid = 1; |
| 398 | |
| 399 | if (memcmp(&tz->trips.passive.devices, &devices, |
| 400 | sizeof(struct acpi_handle_list))) { |
| 401 | memcpy(&tz->trips.passive.devices, &devices, |
| 402 | sizeof(struct acpi_handle_list)); |
| 403 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); |
| 404 | } |
| 405 | } |
| 406 | if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) { |
| 407 | if (valid != tz->trips.passive.flags.valid) |
| 408 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state"); |
| 409 | } |
| 410 | |
| 411 | /* Active (optional) */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 412 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 413 | char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 414 | valid = tz->trips.active[i].flags.valid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 416 | if (act == -1) |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 417 | break; /* disable all active trip points */ |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 418 | |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 419 | if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) && |
| 420 | tz->trips.active[i].flags.valid)) { |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 421 | status = acpi_evaluate_integer(tz->device->handle, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 422 | name, NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 423 | if (ACPI_FAILURE(status)) { |
| 424 | tz->trips.active[i].flags.valid = 0; |
| 425 | if (i == 0) |
| 426 | break; |
| 427 | if (act <= 0) |
| 428 | break; |
| 429 | if (i == 1) |
| 430 | tz->trips.active[0].temperature = |
| 431 | CELSIUS_TO_KELVIN(act); |
| 432 | else |
| 433 | /* |
| 434 | * Don't allow override higher than |
| 435 | * the next higher trip point |
| 436 | */ |
| 437 | tz->trips.active[i - 1].temperature = |
| 438 | (tz->trips.active[i - 2].temperature < |
| 439 | CELSIUS_TO_KELVIN(act) ? |
| 440 | tz->trips.active[i - 2].temperature : |
| 441 | CELSIUS_TO_KELVIN(act)); |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 442 | break; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 443 | } else { |
| 444 | tz->trips.active[i].temperature = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 445 | tz->trips.active[i].flags.valid = 1; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 446 | } |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 447 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
| 449 | name[2] = 'L'; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 450 | if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) { |
| 451 | memset(&devices, 0, sizeof(struct acpi_handle_list)); |
| 452 | status = acpi_evaluate_reference(tz->device->handle, |
| 453 | name, NULL, &devices); |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 454 | if (ACPI_FAILURE(status)) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 455 | pr_warn(PREFIX "Invalid active%d threshold\n", |
| 456 | i); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 457 | tz->trips.active[i].flags.valid = 0; |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 458 | } |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 459 | else |
| 460 | tz->trips.active[i].flags.valid = 1; |
| 461 | |
| 462 | if (memcmp(&tz->trips.active[i].devices, &devices, |
| 463 | sizeof(struct acpi_handle_list))) { |
| 464 | memcpy(&tz->trips.active[i].devices, &devices, |
| 465 | sizeof(struct acpi_handle_list)); |
| 466 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); |
| 467 | } |
| 468 | } |
| 469 | if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES)) |
| 470 | if (valid != tz->trips.active[i].flags.valid) |
| 471 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state"); |
| 472 | |
| 473 | if (!tz->trips.active[i].flags.valid) |
| 474 | break; |
| 475 | } |
| 476 | |
Lan Tianyu | 668e020 | 2013-08-27 16:29:31 +0800 | [diff] [blame] | 477 | if ((flag & ACPI_TRIPS_DEVICES) |
| 478 | && acpi_has_method(tz->device->handle, "_TZD")) { |
| 479 | memset(&devices, 0, sizeof(devices)); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 480 | status = acpi_evaluate_reference(tz->device->handle, "_TZD", |
| 481 | NULL, &devices); |
Lan Tianyu | 668e020 | 2013-08-27 16:29:31 +0800 | [diff] [blame] | 482 | if (ACPI_SUCCESS(status) |
| 483 | && memcmp(&tz->devices, &devices, sizeof(devices))) { |
| 484 | tz->devices = devices; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 485 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); |
| 486 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | } |
| 488 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 489 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 492 | static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | { |
Thomas Renninger | 8b7ef6d | 2010-02-16 22:55:51 +0100 | [diff] [blame] | 494 | int i, valid, ret = acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); |
| 495 | |
| 496 | if (ret) |
| 497 | return ret; |
| 498 | |
| 499 | valid = tz->trips.critical.flags.valid | |
| 500 | tz->trips.hot.flags.valid | |
| 501 | tz->trips.passive.flags.valid; |
| 502 | |
| 503 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) |
| 504 | valid |= tz->trips.active[i].flags.valid; |
| 505 | |
| 506 | if (!valid) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 507 | pr_warn(FW_BUG "No valid trip found\n"); |
Thomas Renninger | 8b7ef6d | 2010-02-16 22:55:51 +0100 | [diff] [blame] | 508 | return -ENODEV; |
| 509 | } |
| 510 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 513 | static void acpi_thermal_check(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 515 | struct acpi_thermal *tz = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
Srinivas Pandruvada | e994d71 | 2013-09-25 09:29:50 -0700 | [diff] [blame] | 517 | if (!tz->tz_enabled) |
Srinivas Pandruvada | ca4e713 | 2013-01-15 23:57:16 +0100 | [diff] [blame] | 518 | return; |
Srinivas Pandruvada | e994d71 | 2013-09-25 09:29:50 -0700 | [diff] [blame] | 519 | |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 520 | thermal_zone_device_update(tz->thermal_zone); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 523 | /* sys I/F for generic thermal sysfs support */ |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 524 | #define KELVIN_TO_MILLICELSIUS(t, off) (((t) - (off)) * 100) |
Zhang, Rui | 5e01276 | 2008-02-28 07:51:30 +0800 | [diff] [blame] | 525 | |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 526 | static int thermal_get_temp(struct thermal_zone_device *thermal, |
| 527 | unsigned long *temp) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 528 | { |
| 529 | struct acpi_thermal *tz = thermal->devdata; |
Zhang, Rui | 76ecb4f | 2008-04-10 16:20:23 +0800 | [diff] [blame] | 530 | int result; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 531 | |
| 532 | if (!tz) |
| 533 | return -EINVAL; |
| 534 | |
Zhang, Rui | 76ecb4f | 2008-04-10 16:20:23 +0800 | [diff] [blame] | 535 | result = acpi_thermal_get_temperature(tz); |
| 536 | if (result) |
| 537 | return result; |
| 538 | |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 539 | *temp = KELVIN_TO_MILLICELSIUS(tz->temperature, tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 540 | return 0; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 541 | } |
| 542 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 543 | static int thermal_get_mode(struct thermal_zone_device *thermal, |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 544 | enum thermal_device_mode *mode) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 545 | { |
| 546 | struct acpi_thermal *tz = thermal->devdata; |
| 547 | |
| 548 | if (!tz) |
| 549 | return -EINVAL; |
| 550 | |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 551 | *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : |
| 552 | THERMAL_DEVICE_DISABLED; |
| 553 | |
| 554 | return 0; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | static int thermal_set_mode(struct thermal_zone_device *thermal, |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 558 | enum thermal_device_mode mode) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 559 | { |
| 560 | struct acpi_thermal *tz = thermal->devdata; |
| 561 | int enable; |
| 562 | |
| 563 | if (!tz) |
| 564 | return -EINVAL; |
| 565 | |
| 566 | /* |
| 567 | * enable/disable thermal management from ACPI thermal driver |
| 568 | */ |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 569 | if (mode == THERMAL_DEVICE_ENABLED) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 570 | enable = 1; |
Srinivas Pandruvada | e994d71 | 2013-09-25 09:29:50 -0700 | [diff] [blame] | 571 | else if (mode == THERMAL_DEVICE_DISABLED) { |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 572 | enable = 0; |
Srinivas Pandruvada | e994d71 | 2013-09-25 09:29:50 -0700 | [diff] [blame] | 573 | pr_warn("thermal zone will be disabled\n"); |
| 574 | } else |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 575 | return -EINVAL; |
| 576 | |
| 577 | if (enable != tz->tz_enabled) { |
| 578 | tz->tz_enabled = enable; |
| 579 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Zhang Rui | 8eaa8d6 | 2012-07-25 10:11:00 +0800 | [diff] [blame] | 580 | "%s kernel ACPI thermal control\n", |
| 581 | tz->tz_enabled ? "Enable" : "Disable")); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 582 | acpi_thermal_check(tz); |
| 583 | } |
| 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | static int thermal_get_trip_type(struct thermal_zone_device *thermal, |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 588 | int trip, enum thermal_trip_type *type) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 589 | { |
| 590 | struct acpi_thermal *tz = thermal->devdata; |
| 591 | int i; |
| 592 | |
| 593 | if (!tz || trip < 0) |
| 594 | return -EINVAL; |
| 595 | |
| 596 | if (tz->trips.critical.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 597 | if (!trip) { |
| 598 | *type = THERMAL_TRIP_CRITICAL; |
| 599 | return 0; |
| 600 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 601 | trip--; |
| 602 | } |
| 603 | |
| 604 | if (tz->trips.hot.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 605 | if (!trip) { |
| 606 | *type = THERMAL_TRIP_HOT; |
| 607 | return 0; |
| 608 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 609 | trip--; |
| 610 | } |
| 611 | |
| 612 | if (tz->trips.passive.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 613 | if (!trip) { |
| 614 | *type = THERMAL_TRIP_PASSIVE; |
| 615 | return 0; |
| 616 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 617 | trip--; |
| 618 | } |
| 619 | |
| 620 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && |
| 621 | tz->trips.active[i].flags.valid; i++) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 622 | if (!trip) { |
| 623 | *type = THERMAL_TRIP_ACTIVE; |
| 624 | return 0; |
| 625 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 626 | trip--; |
| 627 | } |
| 628 | |
| 629 | return -EINVAL; |
| 630 | } |
| 631 | |
| 632 | static int thermal_get_trip_temp(struct thermal_zone_device *thermal, |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 633 | int trip, unsigned long *temp) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 634 | { |
| 635 | struct acpi_thermal *tz = thermal->devdata; |
| 636 | int i; |
| 637 | |
| 638 | if (!tz || trip < 0) |
| 639 | return -EINVAL; |
| 640 | |
| 641 | if (tz->trips.critical.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 642 | if (!trip) { |
| 643 | *temp = KELVIN_TO_MILLICELSIUS( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 644 | tz->trips.critical.temperature, |
| 645 | tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 646 | return 0; |
| 647 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 648 | trip--; |
| 649 | } |
| 650 | |
| 651 | if (tz->trips.hot.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 652 | if (!trip) { |
| 653 | *temp = KELVIN_TO_MILLICELSIUS( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 654 | tz->trips.hot.temperature, |
| 655 | tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 656 | return 0; |
| 657 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 658 | trip--; |
| 659 | } |
| 660 | |
| 661 | if (tz->trips.passive.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 662 | if (!trip) { |
| 663 | *temp = KELVIN_TO_MILLICELSIUS( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 664 | tz->trips.passive.temperature, |
| 665 | tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 666 | return 0; |
| 667 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 668 | trip--; |
| 669 | } |
| 670 | |
| 671 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && |
| 672 | tz->trips.active[i].flags.valid; i++) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 673 | if (!trip) { |
| 674 | *temp = KELVIN_TO_MILLICELSIUS( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 675 | tz->trips.active[i].temperature, |
| 676 | tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 677 | return 0; |
| 678 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 679 | trip--; |
| 680 | } |
| 681 | |
| 682 | return -EINVAL; |
| 683 | } |
| 684 | |
Zhang, Rui | 9ec732f | 2008-04-10 16:13:10 +0800 | [diff] [blame] | 685 | static int thermal_get_crit_temp(struct thermal_zone_device *thermal, |
| 686 | unsigned long *temperature) { |
| 687 | struct acpi_thermal *tz = thermal->devdata; |
| 688 | |
| 689 | if (tz->trips.critical.flags.valid) { |
| 690 | *temperature = KELVIN_TO_MILLICELSIUS( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 691 | tz->trips.critical.temperature, |
| 692 | tz->kelvin_offset); |
Zhang, Rui | 9ec732f | 2008-04-10 16:13:10 +0800 | [diff] [blame] | 693 | return 0; |
| 694 | } else |
| 695 | return -EINVAL; |
| 696 | } |
| 697 | |
Zhang Rui | 601f3d4 | 2012-06-27 09:54:33 +0800 | [diff] [blame] | 698 | static int thermal_get_trend(struct thermal_zone_device *thermal, |
| 699 | int trip, enum thermal_trend *trend) |
| 700 | { |
| 701 | struct acpi_thermal *tz = thermal->devdata; |
| 702 | enum thermal_trip_type type; |
| 703 | int i; |
| 704 | |
| 705 | if (thermal_get_trip_type(thermal, trip, &type)) |
| 706 | return -EINVAL; |
| 707 | |
Zhang Rui | 4ae46be | 2012-06-27 10:05:39 +0800 | [diff] [blame] | 708 | if (type == THERMAL_TRIP_ACTIVE) { |
Zhang Rui | 94a4093 | 2013-04-26 09:19:53 +0000 | [diff] [blame] | 709 | unsigned long trip_temp; |
| 710 | unsigned long temp = KELVIN_TO_MILLICELSIUS(tz->temperature, |
| 711 | tz->kelvin_offset); |
| 712 | if (thermal_get_trip_temp(thermal, trip, &trip_temp)) |
| 713 | return -EINVAL; |
| 714 | |
| 715 | if (temp > trip_temp) { |
| 716 | *trend = THERMAL_TREND_RAISING; |
| 717 | return 0; |
| 718 | } else { |
| 719 | /* Fall back on default trend */ |
| 720 | return -EINVAL; |
| 721 | } |
Zhang Rui | 4ae46be | 2012-06-27 10:05:39 +0800 | [diff] [blame] | 722 | } |
Zhang Rui | 601f3d4 | 2012-06-27 09:54:33 +0800 | [diff] [blame] | 723 | |
| 724 | /* |
| 725 | * tz->temperature has already been updated by generic thermal layer, |
| 726 | * before this callback being invoked |
| 727 | */ |
| 728 | i = (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature)) |
| 729 | + (tz->trips.passive.tc2 |
| 730 | * (tz->temperature - tz->trips.passive.temperature)); |
| 731 | |
| 732 | if (i > 0) |
| 733 | *trend = THERMAL_TREND_RAISING; |
| 734 | else if (i < 0) |
| 735 | *trend = THERMAL_TREND_DROPPING; |
| 736 | else |
| 737 | *trend = THERMAL_TREND_STABLE; |
| 738 | return 0; |
| 739 | } |
| 740 | |
| 741 | |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 742 | static int thermal_notify(struct thermal_zone_device *thermal, int trip, |
| 743 | enum thermal_trip_type trip_type) |
| 744 | { |
| 745 | u8 type = 0; |
| 746 | struct acpi_thermal *tz = thermal->devdata; |
| 747 | |
| 748 | if (trip_type == THERMAL_TRIP_CRITICAL) |
| 749 | type = ACPI_THERMAL_NOTIFY_CRITICAL; |
| 750 | else if (trip_type == THERMAL_TRIP_HOT) |
| 751 | type = ACPI_THERMAL_NOTIFY_HOT; |
| 752 | else |
| 753 | return 0; |
| 754 | |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 755 | acpi_bus_generate_netlink_event(tz->device->pnp.device_class, |
Stephen Rothwell | f6f5c45 | 2009-03-03 12:47:17 +1100 | [diff] [blame] | 756 | dev_name(&tz->device->dev), type, 1); |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 757 | |
| 758 | if (trip_type == THERMAL_TRIP_CRITICAL && nocrt) |
| 759 | return 1; |
| 760 | |
| 761 | return 0; |
| 762 | } |
| 763 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 764 | static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal, |
| 765 | struct thermal_cooling_device *cdev, |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 766 | bool bind) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 767 | { |
| 768 | struct acpi_device *device = cdev->devdata; |
| 769 | struct acpi_thermal *tz = thermal->devdata; |
Zhang Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 770 | struct acpi_device *dev; |
| 771 | acpi_status status; |
| 772 | acpi_handle handle; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 773 | int i; |
| 774 | int j; |
| 775 | int trip = -1; |
| 776 | int result = 0; |
| 777 | |
| 778 | if (tz->trips.critical.flags.valid) |
| 779 | trip++; |
| 780 | |
| 781 | if (tz->trips.hot.flags.valid) |
| 782 | trip++; |
| 783 | |
| 784 | if (tz->trips.passive.flags.valid) { |
| 785 | trip++; |
| 786 | for (i = 0; i < tz->trips.passive.devices.count; |
| 787 | i++) { |
Zhang Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 788 | handle = tz->trips.passive.devices.handles[i]; |
| 789 | status = acpi_bus_get_device(handle, &dev); |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 790 | if (ACPI_FAILURE(status) || dev != device) |
| 791 | continue; |
| 792 | if (bind) |
| 793 | result = |
| 794 | thermal_zone_bind_cooling_device |
| 795 | (thermal, trip, cdev, |
| 796 | THERMAL_NO_LIMIT, THERMAL_NO_LIMIT); |
| 797 | else |
| 798 | result = |
| 799 | thermal_zone_unbind_cooling_device |
| 800 | (thermal, trip, cdev); |
| 801 | if (result) |
| 802 | goto failed; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 803 | } |
| 804 | } |
| 805 | |
| 806 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
| 807 | if (!tz->trips.active[i].flags.valid) |
| 808 | break; |
| 809 | trip++; |
| 810 | for (j = 0; |
| 811 | j < tz->trips.active[i].devices.count; |
| 812 | j++) { |
Zhang Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 813 | handle = tz->trips.active[i].devices.handles[j]; |
| 814 | status = acpi_bus_get_device(handle, &dev); |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 815 | if (ACPI_FAILURE(status) || dev != device) |
| 816 | continue; |
| 817 | if (bind) |
| 818 | result = thermal_zone_bind_cooling_device |
| 819 | (thermal, trip, cdev, |
| 820 | THERMAL_NO_LIMIT, THERMAL_NO_LIMIT); |
| 821 | else |
| 822 | result = thermal_zone_unbind_cooling_device |
| 823 | (thermal, trip, cdev); |
| 824 | if (result) |
| 825 | goto failed; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | |
| 829 | for (i = 0; i < tz->devices.count; i++) { |
Zhang Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 830 | handle = tz->devices.handles[i]; |
| 831 | status = acpi_bus_get_device(handle, &dev); |
| 832 | if (ACPI_SUCCESS(status) && (dev == device)) { |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 833 | if (bind) |
| 834 | result = thermal_zone_bind_cooling_device |
Lan Tianyu | 70f2903 | 2013-08-14 21:00:39 +0800 | [diff] [blame] | 835 | (thermal, THERMAL_TRIPS_NONE, |
| 836 | cdev, THERMAL_NO_LIMIT, |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 837 | THERMAL_NO_LIMIT); |
| 838 | else |
| 839 | result = thermal_zone_unbind_cooling_device |
Lan Tianyu | 70f2903 | 2013-08-14 21:00:39 +0800 | [diff] [blame] | 840 | (thermal, THERMAL_TRIPS_NONE, |
| 841 | cdev); |
Zhang Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 842 | if (result) |
| 843 | goto failed; |
| 844 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | failed: |
| 848 | return result; |
| 849 | } |
| 850 | |
| 851 | static int |
| 852 | acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal, |
| 853 | struct thermal_cooling_device *cdev) |
| 854 | { |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 855 | return acpi_thermal_cooling_device_cb(thermal, cdev, true); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | static int |
| 859 | acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal, |
| 860 | struct thermal_cooling_device *cdev) |
| 861 | { |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 862 | return acpi_thermal_cooling_device_cb(thermal, cdev, false); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 863 | } |
| 864 | |
Vasiliy Kulikov | 9c8b04b | 2011-06-25 21:07:52 +0400 | [diff] [blame] | 865 | static const struct thermal_zone_device_ops acpi_thermal_zone_ops = { |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 866 | .bind = acpi_thermal_bind_cooling_device, |
| 867 | .unbind = acpi_thermal_unbind_cooling_device, |
| 868 | .get_temp = thermal_get_temp, |
| 869 | .get_mode = thermal_get_mode, |
| 870 | .set_mode = thermal_set_mode, |
| 871 | .get_trip_type = thermal_get_trip_type, |
| 872 | .get_trip_temp = thermal_get_trip_temp, |
Zhang, Rui | 9ec732f | 2008-04-10 16:13:10 +0800 | [diff] [blame] | 873 | .get_crit_temp = thermal_get_crit_temp, |
Zhang Rui | 601f3d4 | 2012-06-27 09:54:33 +0800 | [diff] [blame] | 874 | .get_trend = thermal_get_trend, |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 875 | .notify = thermal_notify, |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 876 | }; |
| 877 | |
| 878 | static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) |
| 879 | { |
| 880 | int trips = 0; |
| 881 | int result; |
Zhang Rui | 2073393 | 2008-01-17 15:51:21 +0800 | [diff] [blame] | 882 | acpi_status status; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 883 | int i; |
| 884 | |
| 885 | if (tz->trips.critical.flags.valid) |
| 886 | trips++; |
| 887 | |
| 888 | if (tz->trips.hot.flags.valid) |
| 889 | trips++; |
| 890 | |
| 891 | if (tz->trips.passive.flags.valid) |
| 892 | trips++; |
| 893 | |
| 894 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && |
| 895 | tz->trips.active[i].flags.valid; i++, trips++); |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 896 | |
| 897 | if (tz->trips.passive.flags.valid) |
| 898 | tz->thermal_zone = |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 899 | thermal_zone_device_register("acpitz", trips, 0, tz, |
Durgadoss R | 50125a9 | 2012-09-18 11:04:56 +0530 | [diff] [blame] | 900 | &acpi_thermal_zone_ops, NULL, |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 901 | tz->trips.passive.tsp*100, |
| 902 | tz->polling_frequency*100); |
| 903 | else |
| 904 | tz->thermal_zone = |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 905 | thermal_zone_device_register("acpitz", trips, 0, tz, |
Durgadoss R | 50125a9 | 2012-09-18 11:04:56 +0530 | [diff] [blame] | 906 | &acpi_thermal_zone_ops, NULL, |
| 907 | 0, tz->polling_frequency*100); |
Krzysztof Helt | bb070e4 | 2008-04-08 17:41:52 -0700 | [diff] [blame] | 908 | if (IS_ERR(tz->thermal_zone)) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 909 | return -ENODEV; |
| 910 | |
| 911 | result = sysfs_create_link(&tz->device->dev.kobj, |
| 912 | &tz->thermal_zone->device.kobj, "thermal_zone"); |
| 913 | if (result) |
| 914 | return result; |
| 915 | |
| 916 | result = sysfs_create_link(&tz->thermal_zone->device.kobj, |
| 917 | &tz->device->dev.kobj, "device"); |
| 918 | if (result) |
| 919 | return result; |
| 920 | |
Zhang Rui | 2073393 | 2008-01-17 15:51:21 +0800 | [diff] [blame] | 921 | status = acpi_attach_data(tz->device->handle, |
| 922 | acpi_bus_private_data_handler, |
| 923 | tz->thermal_zone); |
| 924 | if (ACPI_FAILURE(status)) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 925 | pr_err(PREFIX "Error attaching device data\n"); |
Zhang Rui | 2073393 | 2008-01-17 15:51:21 +0800 | [diff] [blame] | 926 | return -ENODEV; |
| 927 | } |
| 928 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 929 | tz->tz_enabled = 1; |
| 930 | |
Greg Kroah-Hartman | fc3a882 | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 931 | dev_info(&tz->device->dev, "registered as thermal_zone%d\n", |
| 932 | tz->thermal_zone->id); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 933 | return 0; |
| 934 | } |
| 935 | |
| 936 | static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz) |
| 937 | { |
| 938 | sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); |
| 939 | sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); |
| 940 | thermal_zone_device_unregister(tz->thermal_zone); |
| 941 | tz->thermal_zone = NULL; |
Zhang Rui | 2073393 | 2008-01-17 15:51:21 +0800 | [diff] [blame] | 942 | acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | /* -------------------------------------------------------------------------- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | Driver Interface |
| 948 | -------------------------------------------------------------------------- */ |
| 949 | |
Bjorn Helgaas | 342d550 | 2009-04-07 15:37:06 +0000 | [diff] [blame] | 950 | static void acpi_thermal_notify(struct acpi_device *device, u32 event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | { |
Bjorn Helgaas | 342d550 | 2009-04-07 15:37:06 +0000 | [diff] [blame] | 952 | struct acpi_thermal *tz = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
| 955 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 956 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | switch (event) { |
| 959 | case ACPI_THERMAL_NOTIFY_TEMPERATURE: |
| 960 | acpi_thermal_check(tz); |
| 961 | break; |
| 962 | case ACPI_THERMAL_NOTIFY_THRESHOLDS: |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 963 | acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | acpi_thermal_check(tz); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 965 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
Kay Sievers | 0794469 | 2008-10-30 01:18:59 +0100 | [diff] [blame] | 966 | dev_name(&device->dev), event, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | break; |
| 968 | case ACPI_THERMAL_NOTIFY_DEVICES: |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 969 | acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES); |
| 970 | acpi_thermal_check(tz); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 971 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
Kay Sievers | 0794469 | 2008-10-30 01:18:59 +0100 | [diff] [blame] | 972 | dev_name(&device->dev), event, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | break; |
| 974 | default: |
| 975 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 976 | "Unsupported event [0x%x]\n", event)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | break; |
| 978 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | } |
| 980 | |
Zhang Rui | 261cba2 | 2012-11-27 20:42:11 +0100 | [diff] [blame] | 981 | /* |
| 982 | * On some platforms, the AML code has dependency about |
| 983 | * the evaluating order of _TMP and _CRT/_HOT/_PSV/_ACx. |
| 984 | * 1. On HP Pavilion G4-1016tx, _TMP must be invoked after |
| 985 | * /_CRT/_HOT/_PSV/_ACx, or else system will be power off. |
| 986 | * 2. On HP Compaq 6715b/6715s, the return value of _PSV is 0 |
| 987 | * if _TMP has never been evaluated. |
| 988 | * |
| 989 | * As this dependency is totally transparent to OS, evaluate |
| 990 | * all of them once, in the order of _CRT/_HOT/_PSV/_ACx, |
| 991 | * _TMP, before they are actually used. |
| 992 | */ |
| 993 | static void acpi_thermal_aml_dependency_fix(struct acpi_thermal *tz) |
| 994 | { |
| 995 | acpi_handle handle = tz->device->handle; |
| 996 | unsigned long long value; |
| 997 | int i; |
| 998 | |
| 999 | acpi_evaluate_integer(handle, "_CRT", NULL, &value); |
| 1000 | acpi_evaluate_integer(handle, "_HOT", NULL, &value); |
| 1001 | acpi_evaluate_integer(handle, "_PSV", NULL, &value); |
| 1002 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
| 1003 | char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; |
| 1004 | acpi_status status; |
| 1005 | |
| 1006 | status = acpi_evaluate_integer(handle, name, NULL, &value); |
| 1007 | if (status == AE_NOT_FOUND) |
| 1008 | break; |
| 1009 | } |
| 1010 | acpi_evaluate_integer(handle, "_TMP", NULL, &value); |
| 1011 | } |
| 1012 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1013 | static int acpi_thermal_get_info(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1015 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | |
| 1018 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1019 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | |
Zhang Rui | 261cba2 | 2012-11-27 20:42:11 +0100 | [diff] [blame] | 1021 | acpi_thermal_aml_dependency_fix(tz); |
| 1022 | |
Matthew Garrett | 9bcb811 | 2012-02-01 10:26:54 -0500 | [diff] [blame] | 1023 | /* Get trip points [_CRT, _PSV, etc.] (required) */ |
| 1024 | result = acpi_thermal_get_trip_points(tz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1026 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | |
Matthew Garrett | 9bcb811 | 2012-02-01 10:26:54 -0500 | [diff] [blame] | 1028 | /* Get temperature [_TMP] (required) */ |
| 1029 | result = acpi_thermal_get_temperature(tz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1031 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | |
| 1033 | /* Set the cooling mode [_SCP] to active cooling (default) */ |
| 1034 | result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1035 | if (!result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | tz->flags.cooling_mode = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
| 1038 | /* Get default polling frequency [_TZP] (optional) */ |
| 1039 | if (tzp) |
| 1040 | tz->polling_frequency = tzp; |
| 1041 | else |
| 1042 | acpi_thermal_get_polling_frequency(tz); |
| 1043 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1044 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 1047 | /* |
| 1048 | * The exact offset between Kelvin and degree Celsius is 273.15. However ACPI |
| 1049 | * handles temperature values with a single decimal place. As a consequence, |
| 1050 | * some implementations use an offset of 273.1 and others use an offset of |
| 1051 | * 273.2. Try to find out which one is being used, to present the most |
| 1052 | * accurate and visually appealing number. |
| 1053 | * |
| 1054 | * The heuristic below should work for all ACPI thermal zones which have a |
| 1055 | * critical trip point with a value being a multiple of 0.5 degree Celsius. |
| 1056 | */ |
| 1057 | static void acpi_thermal_guess_offset(struct acpi_thermal *tz) |
| 1058 | { |
| 1059 | if (tz->trips.critical.flags.valid && |
| 1060 | (tz->trips.critical.temperature % 5) == 1) |
| 1061 | tz->kelvin_offset = 2731; |
| 1062 | else |
| 1063 | tz->kelvin_offset = 2732; |
| 1064 | } |
| 1065 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1066 | static int acpi_thermal_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1068 | int result = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1069 | struct acpi_thermal *tz = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | |
| 1072 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1073 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 1075 | tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1077 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | |
Patrick Mochel | 8348e1b | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 1079 | tz->device = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | strcpy(tz->name, device->pnp.bus_id); |
| 1081 | strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME); |
| 1082 | strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS); |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 1083 | device->driver_data = tz; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1084 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | result = acpi_thermal_get_info(tz); |
| 1086 | if (result) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1087 | goto free_memory; |
| 1088 | |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 1089 | acpi_thermal_guess_offset(tz); |
| 1090 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1091 | result = acpi_thermal_register_thermal_zone(tz); |
| 1092 | if (result) |
| 1093 | goto free_memory; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 1095 | pr_info(PREFIX "%s [%s] (%ld C)\n", acpi_device_name(device), |
| 1096 | acpi_device_bid(device), KELVIN_TO_CELSIUS(tz->temperature)); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1097 | goto end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1099 | free_memory: |
| 1100 | kfree(tz); |
| 1101 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1102 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
Rafael J. Wysocki | 51fac83 | 2013-01-24 00:24:48 +0100 | [diff] [blame] | 1105 | static int acpi_thermal_remove(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1107 | struct acpi_thermal *tz = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | if (!device || !acpi_driver_data(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1110 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1112 | tz = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1114 | acpi_thermal_unregister_thermal_zone(tz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | kfree(tz); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1116 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
Rafael J. Wysocki | 9069240 | 2012-08-09 23:00:02 +0200 | [diff] [blame] | 1119 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 1120 | static int acpi_thermal_resume(struct device *dev) |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1121 | { |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 1122 | struct acpi_thermal *tz; |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1123 | int i, j, power_state, result; |
| 1124 | |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 1125 | if (!dev) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1126 | return -EINVAL; |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1127 | |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 1128 | tz = acpi_driver_data(to_acpi_device(dev)); |
| 1129 | if (!tz) |
| 1130 | return -EINVAL; |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1131 | |
Konstantin Karasyov | bed936f | 2006-07-10 04:44:26 -0700 | [diff] [blame] | 1132 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1133 | if (!(&tz->trips.active[i])) |
| 1134 | break; |
| 1135 | if (!tz->trips.active[i].flags.valid) |
| 1136 | break; |
| 1137 | tz->trips.active[i].flags.enabled = 1; |
| 1138 | for (j = 0; j < tz->trips.active[i].devices.count; j++) { |
Rafael J. Wysocki | 488a76c | 2010-11-25 00:11:24 +0100 | [diff] [blame] | 1139 | result = acpi_bus_update_power( |
| 1140 | tz->trips.active[i].devices.handles[j], |
| 1141 | &power_state); |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1142 | if (result || (power_state != ACPI_STATE_D0)) { |
| 1143 | tz->trips.active[i].flags.enabled = 0; |
| 1144 | break; |
| 1145 | } |
Konstantin Karasyov | bed936f | 2006-07-10 04:44:26 -0700 | [diff] [blame] | 1146 | } |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1147 | tz->state.active |= tz->trips.active[i].flags.enabled; |
Konstantin Karasyov | bed936f | 2006-07-10 04:44:26 -0700 | [diff] [blame] | 1148 | } |
| 1149 | |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1150 | acpi_thermal_check(tz); |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1151 | |
| 1152 | return AE_OK; |
| 1153 | } |
Rafael J. Wysocki | 9069240 | 2012-08-09 23:00:02 +0200 | [diff] [blame] | 1154 | #endif |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1155 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 1156 | static int thermal_act(const struct dmi_system_id *d) { |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1157 | |
| 1158 | if (act == 0) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 1159 | pr_notice(PREFIX "%s detected: " |
| 1160 | "disabling all active thermal trip points\n", d->ident); |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1161 | act = -1; |
| 1162 | } |
| 1163 | return 0; |
| 1164 | } |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 1165 | static int thermal_nocrt(const struct dmi_system_id *d) { |
Len Brown | 8c99fdc | 2007-08-20 18:46:50 -0400 | [diff] [blame] | 1166 | |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 1167 | pr_notice(PREFIX "%s detected: " |
| 1168 | "disabling all critical thermal trip point actions.\n", d->ident); |
Len Brown | 8c99fdc | 2007-08-20 18:46:50 -0400 | [diff] [blame] | 1169 | nocrt = 1; |
| 1170 | return 0; |
| 1171 | } |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 1172 | static int thermal_tzp(const struct dmi_system_id *d) { |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1173 | |
| 1174 | if (tzp == 0) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 1175 | pr_notice(PREFIX "%s detected: " |
| 1176 | "enabling thermal zone polling\n", d->ident); |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1177 | tzp = 300; /* 300 dS = 30 Seconds */ |
| 1178 | } |
| 1179 | return 0; |
| 1180 | } |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 1181 | static int thermal_psv(const struct dmi_system_id *d) { |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1182 | |
| 1183 | if (psv == 0) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 1184 | pr_notice(PREFIX "%s detected: " |
| 1185 | "disabling all passive thermal trip points\n", d->ident); |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1186 | psv = -1; |
| 1187 | } |
| 1188 | return 0; |
| 1189 | } |
| 1190 | |
| 1191 | static struct dmi_system_id thermal_dmi_table[] __initdata = { |
| 1192 | /* |
| 1193 | * Award BIOS on this AOpen makes thermal control almost worthless. |
| 1194 | * http://bugzilla.kernel.org/show_bug.cgi?id=8842 |
| 1195 | */ |
| 1196 | { |
| 1197 | .callback = thermal_act, |
| 1198 | .ident = "AOpen i915GMm-HFS", |
| 1199 | .matches = { |
| 1200 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), |
| 1201 | DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), |
| 1202 | }, |
| 1203 | }, |
| 1204 | { |
| 1205 | .callback = thermal_psv, |
| 1206 | .ident = "AOpen i915GMm-HFS", |
| 1207 | .matches = { |
| 1208 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), |
| 1209 | DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), |
| 1210 | }, |
| 1211 | }, |
| 1212 | { |
| 1213 | .callback = thermal_tzp, |
| 1214 | .ident = "AOpen i915GMm-HFS", |
| 1215 | .matches = { |
| 1216 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), |
| 1217 | DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), |
| 1218 | }, |
| 1219 | }, |
Len Brown | 8c99fdc | 2007-08-20 18:46:50 -0400 | [diff] [blame] | 1220 | { |
| 1221 | .callback = thermal_nocrt, |
| 1222 | .ident = "Gigabyte GA-7ZX", |
| 1223 | .matches = { |
| 1224 | DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."), |
| 1225 | DMI_MATCH(DMI_BOARD_NAME, "7ZX"), |
| 1226 | }, |
| 1227 | }, |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1228 | {} |
| 1229 | }; |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1230 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1231 | static int __init acpi_thermal_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1233 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1235 | dmi_check_system(thermal_dmi_table); |
| 1236 | |
Len Brown | 72b33ef | 2007-08-12 00:12:17 -0400 | [diff] [blame] | 1237 | if (off) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 1238 | pr_notice(PREFIX "thermal control disabled\n"); |
Len Brown | 72b33ef | 2007-08-12 00:12:17 -0400 | [diff] [blame] | 1239 | return -ENODEV; |
| 1240 | } |
Zhang Rui | 43d9f87 | 2010-07-15 10:46:44 +0800 | [diff] [blame] | 1241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | result = acpi_bus_register_driver(&acpi_thermal_driver); |
Zhang Rui | c57b62f | 2010-10-08 13:55:06 +0800 | [diff] [blame] | 1243 | if (result < 0) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1244 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1246 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | } |
| 1248 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1249 | static void __exit acpi_thermal_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | |
| 1252 | acpi_bus_unregister_driver(&acpi_thermal_driver); |
| 1253 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1254 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | } |
| 1256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | module_init(acpi_thermal_init); |
| 1258 | module_exit(acpi_thermal_exit); |