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