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> |
| 36 | #include <linux/init.h> |
| 37 | #include <linux/types.h> |
| 38 | #include <linux/proc_fs.h> |
| 39 | #include <linux/sched.h> |
| 40 | #include <linux/kmod.h> |
| 41 | #include <linux/seq_file.h> |
| 42 | #include <asm/uaccess.h> |
| 43 | |
| 44 | #include <acpi/acpi_bus.h> |
| 45 | #include <acpi/acpi_drivers.h> |
| 46 | |
| 47 | #define ACPI_THERMAL_COMPONENT 0x04000000 |
| 48 | #define ACPI_THERMAL_CLASS "thermal_zone" |
| 49 | #define ACPI_THERMAL_DRIVER_NAME "ACPI Thermal Zone Driver" |
| 50 | #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone" |
| 51 | #define ACPI_THERMAL_FILE_STATE "state" |
| 52 | #define ACPI_THERMAL_FILE_TEMPERATURE "temperature" |
| 53 | #define ACPI_THERMAL_FILE_TRIP_POINTS "trip_points" |
| 54 | #define ACPI_THERMAL_FILE_COOLING_MODE "cooling_mode" |
| 55 | #define ACPI_THERMAL_FILE_POLLING_FREQ "polling_frequency" |
| 56 | #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80 |
| 57 | #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81 |
| 58 | #define ACPI_THERMAL_NOTIFY_DEVICES 0x82 |
| 59 | #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0 |
| 60 | #define ACPI_THERMAL_NOTIFY_HOT 0xF1 |
| 61 | #define ACPI_THERMAL_MODE_ACTIVE 0x00 |
| 62 | #define ACPI_THERMAL_MODE_PASSIVE 0x01 |
| 63 | #define ACPI_THERMAL_MODE_CRITICAL 0xff |
| 64 | #define ACPI_THERMAL_PATH_POWEROFF "/sbin/poweroff" |
| 65 | |
| 66 | #define ACPI_THERMAL_MAX_ACTIVE 10 |
| 67 | #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65 |
| 68 | |
| 69 | #define KELVIN_TO_CELSIUS(t) (long)(((long)t-2732>=0) ? ((long)t-2732+5)/10 : ((long)t-2732-5)/10) |
| 70 | #define CELSIUS_TO_KELVIN(t) ((t+273)*10) |
| 71 | |
| 72 | #define _COMPONENT ACPI_THERMAL_COMPONENT |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 73 | ACPI_MODULE_NAME("acpi_thermal") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 75 | MODULE_AUTHOR("Paul Diefenbaugh"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | MODULE_DESCRIPTION(ACPI_THERMAL_DRIVER_NAME); |
| 77 | MODULE_LICENSE("GPL"); |
| 78 | |
| 79 | static int tzp; |
| 80 | module_param(tzp, int, 0); |
| 81 | MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.\n"); |
| 82 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 83 | static int acpi_thermal_add(struct acpi_device *device); |
| 84 | static int acpi_thermal_remove(struct acpi_device *device, int type); |
Konstantin Karasyov | 74ce146 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 85 | static int acpi_thermal_resume(struct acpi_device *device, int state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file); |
| 87 | static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file); |
| 88 | static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 89 | static ssize_t acpi_thermal_write_trip_points(struct file *, |
| 90 | const char __user *, size_t, |
| 91 | loff_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 93 | static ssize_t acpi_thermal_write_cooling_mode(struct file *, |
| 94 | const char __user *, size_t, |
| 95 | loff_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 97 | static ssize_t acpi_thermal_write_polling(struct file *, const char __user *, |
| 98 | size_t, loff_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | static struct acpi_driver acpi_thermal_driver = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 101 | .name = ACPI_THERMAL_DRIVER_NAME, |
| 102 | .class = ACPI_THERMAL_CLASS, |
| 103 | .ids = ACPI_THERMAL_HID, |
| 104 | .ops = { |
| 105 | .add = acpi_thermal_add, |
| 106 | .remove = acpi_thermal_remove, |
Konstantin Karasyov | 74ce146 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 107 | .resume = acpi_thermal_resume, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 108 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | struct acpi_thermal_state { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 112 | u8 critical:1; |
| 113 | u8 hot:1; |
| 114 | u8 passive:1; |
| 115 | u8 active:1; |
| 116 | u8 reserved:4; |
| 117 | int active_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | struct acpi_thermal_state_flags { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 121 | u8 valid:1; |
| 122 | u8 enabled:1; |
| 123 | u8 reserved:6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | struct acpi_thermal_critical { |
| 127 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 128 | unsigned long temperature; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | struct acpi_thermal_hot { |
| 132 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 133 | unsigned long temperature; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | struct acpi_thermal_passive { |
| 137 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 | unsigned long temperature; |
| 139 | unsigned long tc1; |
| 140 | unsigned long tc2; |
| 141 | unsigned long tsp; |
| 142 | struct acpi_handle_list devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | struct acpi_thermal_active { |
| 146 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 147 | unsigned long temperature; |
| 148 | struct acpi_handle_list devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | struct acpi_thermal_trips { |
| 152 | struct acpi_thermal_critical critical; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 153 | struct acpi_thermal_hot hot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | struct acpi_thermal_passive passive; |
| 155 | struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE]; |
| 156 | }; |
| 157 | |
| 158 | struct acpi_thermal_flags { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 159 | u8 cooling_mode:1; /* _SCP */ |
| 160 | u8 devices:1; /* _TZD */ |
| 161 | u8 reserved:6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | struct acpi_thermal { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 165 | acpi_handle handle; |
| 166 | acpi_bus_id name; |
| 167 | unsigned long temperature; |
| 168 | unsigned long last_temperature; |
| 169 | unsigned long polling_frequency; |
| 170 | u8 cooling_mode; |
| 171 | volatile u8 zombie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | struct acpi_thermal_flags flags; |
| 173 | struct acpi_thermal_state state; |
| 174 | struct acpi_thermal_trips trips; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 175 | struct acpi_handle_list devices; |
| 176 | struct timer_list timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | static struct file_operations acpi_thermal_state_fops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 180 | .open = acpi_thermal_state_open_fs, |
| 181 | .read = seq_read, |
| 182 | .llseek = seq_lseek, |
| 183 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | }; |
| 185 | |
| 186 | static struct file_operations acpi_thermal_temp_fops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 187 | .open = acpi_thermal_temp_open_fs, |
| 188 | .read = seq_read, |
| 189 | .llseek = seq_lseek, |
| 190 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | static struct file_operations acpi_thermal_trip_fops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 194 | .open = acpi_thermal_trip_open_fs, |
| 195 | .read = seq_read, |
| 196 | .write = acpi_thermal_write_trip_points, |
| 197 | .llseek = seq_lseek, |
| 198 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | }; |
| 200 | |
| 201 | static struct file_operations acpi_thermal_cooling_fops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 202 | .open = acpi_thermal_cooling_open_fs, |
| 203 | .read = seq_read, |
| 204 | .write = acpi_thermal_write_cooling_mode, |
| 205 | .llseek = seq_lseek, |
| 206 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | }; |
| 208 | |
| 209 | static struct file_operations acpi_thermal_polling_fops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 210 | .open = acpi_thermal_polling_open_fs, |
| 211 | .read = seq_read, |
| 212 | .write = acpi_thermal_write_polling, |
| 213 | .llseek = seq_lseek, |
| 214 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | }; |
| 216 | |
| 217 | /* -------------------------------------------------------------------------- |
| 218 | Thermal Zone Management |
| 219 | -------------------------------------------------------------------------- */ |
| 220 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 221 | static int acpi_thermal_get_temperature(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 223 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
| 225 | ACPI_FUNCTION_TRACE("acpi_thermal_get_temperature"); |
| 226 | |
| 227 | if (!tz) |
| 228 | return_VALUE(-EINVAL); |
| 229 | |
| 230 | tz->last_temperature = tz->temperature; |
| 231 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 232 | status = |
| 233 | acpi_evaluate_integer(tz->handle, "_TMP", NULL, &tz->temperature); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | if (ACPI_FAILURE(status)) |
| 235 | return_VALUE(-ENODEV); |
| 236 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 237 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n", |
| 238 | tz->temperature)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
| 240 | return_VALUE(0); |
| 241 | } |
| 242 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 243 | static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 245 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
| 247 | ACPI_FUNCTION_TRACE("acpi_thermal_get_polling_frequency"); |
| 248 | |
| 249 | if (!tz) |
| 250 | return_VALUE(-EINVAL); |
| 251 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 252 | status = |
| 253 | acpi_evaluate_integer(tz->handle, "_TZP", NULL, |
| 254 | &tz->polling_frequency); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | if (ACPI_FAILURE(status)) |
| 256 | return_VALUE(-ENODEV); |
| 257 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 258 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n", |
| 259 | tz->polling_frequency)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
| 261 | return_VALUE(0); |
| 262 | } |
| 263 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 264 | static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | { |
| 266 | ACPI_FUNCTION_TRACE("acpi_thermal_set_polling"); |
| 267 | |
| 268 | if (!tz) |
| 269 | return_VALUE(-EINVAL); |
| 270 | |
| 271 | tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */ |
| 272 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 273 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 274 | "Polling frequency set to %lu seconds\n", |
| 275 | tz->polling_frequency)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
| 277 | return_VALUE(0); |
| 278 | } |
| 279 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 280 | 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] | 281 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 282 | acpi_status status = AE_OK; |
| 283 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; |
| 284 | struct acpi_object_list arg_list = { 1, &arg0 }; |
| 285 | acpi_handle handle = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
| 287 | ACPI_FUNCTION_TRACE("acpi_thermal_set_cooling_mode"); |
| 288 | |
| 289 | if (!tz) |
| 290 | return_VALUE(-EINVAL); |
| 291 | |
| 292 | status = acpi_get_handle(tz->handle, "_SCP", &handle); |
| 293 | if (ACPI_FAILURE(status)) { |
| 294 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n")); |
| 295 | return_VALUE(-ENODEV); |
| 296 | } |
| 297 | |
| 298 | arg0.integer.value = mode; |
| 299 | |
| 300 | status = acpi_evaluate_object(handle, NULL, &arg_list, NULL); |
| 301 | if (ACPI_FAILURE(status)) |
| 302 | return_VALUE(-ENODEV); |
| 303 | |
| 304 | tz->cooling_mode = mode; |
| 305 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 306 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Cooling mode [%s]\n", |
| 307 | mode ? "passive" : "active")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | return_VALUE(0); |
| 310 | } |
| 311 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 312 | static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 314 | acpi_status status = AE_OK; |
| 315 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
| 317 | ACPI_FUNCTION_TRACE("acpi_thermal_get_trip_points"); |
| 318 | |
| 319 | if (!tz) |
| 320 | return_VALUE(-EINVAL); |
| 321 | |
| 322 | /* Critical Shutdown (required) */ |
| 323 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 324 | status = acpi_evaluate_integer(tz->handle, "_CRT", NULL, |
| 325 | &tz->trips.critical.temperature); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | if (ACPI_FAILURE(status)) { |
| 327 | tz->trips.critical.flags.valid = 0; |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 328 | ACPI_EXCEPTION((AE_INFO, status, "No critical threshold")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | return_VALUE(-ENODEV); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 330 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | tz->trips.critical.flags.valid = 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 332 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 333 | "Found critical threshold [%lu]\n", |
| 334 | tz->trips.critical.temperature)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | /* Critical Sleep (optional) */ |
| 338 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 339 | status = |
| 340 | acpi_evaluate_integer(tz->handle, "_HOT", NULL, |
| 341 | &tz->trips.hot.temperature); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | if (ACPI_FAILURE(status)) { |
| 343 | tz->trips.hot.flags.valid = 0; |
| 344 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No hot threshold\n")); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 345 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | tz->trips.hot.flags.valid = 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 347 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found hot threshold [%lu]\n", |
| 348 | tz->trips.hot.temperature)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /* Passive: Processors (optional) */ |
| 352 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 353 | status = |
| 354 | acpi_evaluate_integer(tz->handle, "_PSV", NULL, |
| 355 | &tz->trips.passive.temperature); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | if (ACPI_FAILURE(status)) { |
| 357 | tz->trips.passive.flags.valid = 0; |
| 358 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No passive threshold\n")); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 359 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | tz->trips.passive.flags.valid = 1; |
| 361 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 362 | status = |
| 363 | acpi_evaluate_integer(tz->handle, "_TC1", NULL, |
| 364 | &tz->trips.passive.tc1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | if (ACPI_FAILURE(status)) |
| 366 | tz->trips.passive.flags.valid = 0; |
| 367 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 368 | status = |
| 369 | acpi_evaluate_integer(tz->handle, "_TC2", NULL, |
| 370 | &tz->trips.passive.tc2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | if (ACPI_FAILURE(status)) |
| 372 | tz->trips.passive.flags.valid = 0; |
| 373 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 374 | status = |
| 375 | acpi_evaluate_integer(tz->handle, "_TSP", NULL, |
| 376 | &tz->trips.passive.tsp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | if (ACPI_FAILURE(status)) |
| 378 | tz->trips.passive.flags.valid = 0; |
| 379 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 380 | status = |
| 381 | acpi_evaluate_reference(tz->handle, "_PSL", NULL, |
| 382 | &tz->trips.passive.devices); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | if (ACPI_FAILURE(status)) |
| 384 | tz->trips.passive.flags.valid = 0; |
| 385 | |
| 386 | if (!tz->trips.passive.flags.valid) |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame^] | 387 | printk(KERN_WARNING PREFIX "Invalid passive threshold\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | else |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 389 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 390 | "Found passive threshold [%lu]\n", |
| 391 | tz->trips.passive.temperature)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /* Active: Fans, etc. (optional) */ |
| 395 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 396 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 398 | char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 400 | status = |
| 401 | acpi_evaluate_integer(tz->handle, name, NULL, |
| 402 | &tz->trips.active[i].temperature); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | if (ACPI_FAILURE(status)) |
| 404 | break; |
| 405 | |
| 406 | name[2] = 'L'; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 407 | status = |
| 408 | acpi_evaluate_reference(tz->handle, name, NULL, |
| 409 | &tz->trips.active[i].devices); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | if (ACPI_SUCCESS(status)) { |
| 411 | tz->trips.active[i].flags.valid = 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 412 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 413 | "Found active threshold [%d]:[%lu]\n", |
| 414 | i, tz->trips.active[i].temperature)); |
| 415 | } else |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 416 | ACPI_EXCEPTION((AE_INFO, status, |
| 417 | "Invalid active threshold [%d]", i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | return_VALUE(0); |
| 421 | } |
| 422 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 423 | static int acpi_thermal_get_devices(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 425 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
| 427 | ACPI_FUNCTION_TRACE("acpi_thermal_get_devices"); |
| 428 | |
| 429 | if (!tz) |
| 430 | return_VALUE(-EINVAL); |
| 431 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 432 | status = |
| 433 | acpi_evaluate_reference(tz->handle, "_TZD", NULL, &tz->devices); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | if (ACPI_FAILURE(status)) |
| 435 | return_VALUE(-ENODEV); |
| 436 | |
| 437 | return_VALUE(0); |
| 438 | } |
| 439 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 440 | static int acpi_thermal_call_usermode(char *path) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 442 | char *argv[2] = { NULL, NULL }; |
| 443 | char *envp[3] = { NULL, NULL, NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
| 445 | ACPI_FUNCTION_TRACE("acpi_thermal_call_usermode"); |
| 446 | |
| 447 | if (!path) |
| 448 | return_VALUE(-EINVAL); |
| 449 | |
| 450 | argv[0] = path; |
| 451 | |
| 452 | /* minimal command environment */ |
| 453 | envp[0] = "HOME=/"; |
| 454 | envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin"; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | call_usermodehelper(argv[0], argv, envp, 0); |
| 457 | |
| 458 | return_VALUE(0); |
| 459 | } |
| 460 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 461 | static int acpi_thermal_critical(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 463 | int result = 0; |
| 464 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
| 466 | ACPI_FUNCTION_TRACE("acpi_thermal_critical"); |
| 467 | |
| 468 | if (!tz || !tz->trips.critical.flags.valid) |
| 469 | return_VALUE(-EINVAL); |
| 470 | |
| 471 | if (tz->temperature >= tz->trips.critical.temperature) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame^] | 472 | printk(KERN_WARNING PREFIX "Critical trip point\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | tz->trips.critical.flags.enabled = 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 474 | } else if (tz->trips.critical.flags.enabled) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | tz->trips.critical.flags.enabled = 0; |
| 476 | |
| 477 | result = acpi_bus_get_device(tz->handle, &device); |
| 478 | if (result) |
| 479 | return_VALUE(result); |
| 480 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 481 | printk(KERN_EMERG |
| 482 | "Critical temperature reached (%ld C), shutting down.\n", |
| 483 | KELVIN_TO_CELSIUS(tz->temperature)); |
| 484 | acpi_bus_generate_event(device, ACPI_THERMAL_NOTIFY_CRITICAL, |
| 485 | tz->trips.critical.flags.enabled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
| 487 | acpi_thermal_call_usermode(ACPI_THERMAL_PATH_POWEROFF); |
| 488 | |
| 489 | return_VALUE(0); |
| 490 | } |
| 491 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 492 | static int acpi_thermal_hot(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 494 | int result = 0; |
| 495 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
| 497 | ACPI_FUNCTION_TRACE("acpi_thermal_hot"); |
| 498 | |
| 499 | if (!tz || !tz->trips.hot.flags.valid) |
| 500 | return_VALUE(-EINVAL); |
| 501 | |
| 502 | if (tz->temperature >= tz->trips.hot.temperature) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame^] | 503 | printk(KERN_WARNING PREFIX "Hot trip point\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | tz->trips.hot.flags.enabled = 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 505 | } else if (tz->trips.hot.flags.enabled) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | tz->trips.hot.flags.enabled = 0; |
| 507 | |
| 508 | result = acpi_bus_get_device(tz->handle, &device); |
| 509 | if (result) |
| 510 | return_VALUE(result); |
| 511 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 512 | acpi_bus_generate_event(device, ACPI_THERMAL_NOTIFY_HOT, |
| 513 | tz->trips.hot.flags.enabled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
| 515 | /* TBD: Call user-mode "sleep(S4)" function */ |
| 516 | |
| 517 | return_VALUE(0); |
| 518 | } |
| 519 | |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 520 | static void acpi_thermal_passive(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | { |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 522 | int result = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | struct acpi_thermal_passive *passive = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 524 | int trend = 0; |
| 525 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
| 527 | ACPI_FUNCTION_TRACE("acpi_thermal_passive"); |
| 528 | |
| 529 | if (!tz || !tz->trips.passive.flags.valid) |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 530 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
| 532 | passive = &(tz->trips.passive); |
| 533 | |
| 534 | /* |
| 535 | * Above Trip? |
| 536 | * ----------- |
| 537 | * Calculate the thermal trend (using the passive cooling equation) |
| 538 | * and modify the performance limit for all passive cooling devices |
| 539 | * accordingly. Note that we assume symmetry. |
| 540 | */ |
| 541 | if (tz->temperature >= passive->temperature) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 542 | trend = |
| 543 | (passive->tc1 * (tz->temperature - tz->last_temperature)) + |
| 544 | (passive->tc2 * (tz->temperature - passive->temperature)); |
| 545 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 546 | "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n", |
| 547 | trend, passive->tc1, tz->temperature, |
| 548 | tz->last_temperature, passive->tc2, |
| 549 | tz->temperature, passive->temperature)); |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 550 | passive->flags.enabled = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | /* Heating up? */ |
| 552 | if (trend > 0) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 553 | for (i = 0; i < passive->devices.count; i++) |
| 554 | acpi_processor_set_thermal_limit(passive-> |
| 555 | devices. |
| 556 | handles[i], |
| 557 | ACPI_PROCESSOR_LIMIT_INCREMENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | /* Cooling off? */ |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 559 | else if (trend < 0) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 560 | for (i = 0; i < passive->devices.count; i++) |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 561 | /* |
| 562 | * assume that we are on highest |
| 563 | * freq/lowest thrott and can leave |
| 564 | * passive mode, even in error case |
| 565 | */ |
| 566 | if (!acpi_processor_set_thermal_limit |
| 567 | (passive->devices.handles[i], |
| 568 | ACPI_PROCESSOR_LIMIT_DECREMENT)) |
| 569 | result = 0; |
| 570 | /* |
| 571 | * Leave cooling mode, even if the temp might |
| 572 | * higher than trip point This is because some |
| 573 | * machines might have long thermal polling |
| 574 | * frequencies (tsp) defined. We will fall back |
| 575 | * into passive mode in next cycle (probably quicker) |
| 576 | */ |
| 577 | if (result) { |
| 578 | passive->flags.enabled = 0; |
| 579 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 580 | "Disabling passive cooling, still above threshold," |
| 581 | " but we are cooling down\n")); |
| 582 | } |
| 583 | } |
| 584 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /* |
| 588 | * Below Trip? |
| 589 | * ----------- |
| 590 | * Implement passive cooling hysteresis to slowly increase performance |
| 591 | * and avoid thrashing around the passive trip point. Note that we |
| 592 | * assume symmetry. |
| 593 | */ |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 594 | if (!passive->flags.enabled) |
| 595 | return; |
| 596 | for (i = 0; i < passive->devices.count; i++) |
| 597 | if (!acpi_processor_set_thermal_limit |
| 598 | (passive->devices.handles[i], |
| 599 | ACPI_PROCESSOR_LIMIT_DECREMENT)) |
| 600 | result = 0; |
| 601 | if (result) { |
| 602 | passive->flags.enabled = 0; |
| 603 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 604 | "Disabling passive cooling (zone is cool)\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 608 | static void acpi_thermal_active(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 610 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | struct acpi_thermal_active *active = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 612 | int i = 0; |
| 613 | int j = 0; |
| 614 | unsigned long maxtemp = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
| 616 | ACPI_FUNCTION_TRACE("acpi_thermal_active"); |
| 617 | |
| 618 | if (!tz) |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 619 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 621 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | active = &(tz->trips.active[i]); |
| 623 | if (!active || !active->flags.valid) |
| 624 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | if (tz->temperature >= active->temperature) { |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 626 | /* |
| 627 | * Above Threshold? |
| 628 | * ---------------- |
| 629 | * If not already enabled, turn ON all cooling devices |
| 630 | * associated with this active threshold. |
| 631 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | if (active->temperature > maxtemp) |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 633 | tz->state.active_index = i; |
| 634 | maxtemp = active->temperature; |
| 635 | if (active->flags.enabled) |
| 636 | continue; |
| 637 | for (j = 0; j < active->devices.count; j++) { |
| 638 | result = |
| 639 | acpi_bus_set_power(active->devices. |
| 640 | handles[j], |
| 641 | ACPI_STATE_D0); |
| 642 | if (result) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame^] | 643 | printk(KERN_WARNING PREFIX |
| 644 | "Unable to turn cooling device [%p] 'on'\n", |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 645 | active->devices. |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame^] | 646 | handles[j]); |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 647 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | } |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 649 | active->flags.enabled = 1; |
| 650 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 651 | "Cooling device [%p] now 'on'\n", |
| 652 | active->devices.handles[j])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | } |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 654 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | } |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 656 | if (!active->flags.enabled) |
| 657 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | /* |
| 659 | * Below Threshold? |
| 660 | * ---------------- |
| 661 | * Turn OFF all cooling devices associated with this |
| 662 | * threshold. |
| 663 | */ |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 664 | for (j = 0; j < active->devices.count; j++) { |
| 665 | result = acpi_bus_set_power(active->devices.handles[j], |
| 666 | ACPI_STATE_D3); |
| 667 | if (result) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame^] | 668 | printk(KERN_WARNING PREFIX |
| 669 | "Unable to turn cooling device [%p] 'off'\n", |
| 670 | active->devices.handles[j]); |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 671 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | } |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 673 | active->flags.enabled = 0; |
| 674 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 675 | "Cooling device [%p] now 'off'\n", |
| 676 | active->devices.handles[j])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | } |
| 678 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 681 | static void acpi_thermal_check(void *context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 683 | static void acpi_thermal_run(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | { |
| 685 | struct acpi_thermal *tz = (struct acpi_thermal *)data; |
| 686 | if (!tz->zombie) |
Alexey Starikovskiy | b8d3519 | 2006-05-05 03:23:00 -0400 | [diff] [blame] | 687 | acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | } |
| 689 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 690 | static void acpi_thermal_check(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 692 | int result = 0; |
| 693 | struct acpi_thermal *tz = (struct acpi_thermal *)data; |
| 694 | unsigned long sleep_time = 0; |
| 695 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | struct acpi_thermal_state state; |
| 697 | |
| 698 | ACPI_FUNCTION_TRACE("acpi_thermal_check"); |
| 699 | |
| 700 | if (!tz) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 701 | ACPI_ERROR((AE_INFO, "Invalid (NULL) context")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | return_VOID; |
| 703 | } |
| 704 | |
| 705 | state = tz->state; |
| 706 | |
| 707 | result = acpi_thermal_get_temperature(tz); |
| 708 | if (result) |
| 709 | return_VOID; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 710 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | memset(&tz->state, 0, sizeof(tz->state)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 712 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | /* |
| 714 | * Check Trip Points |
| 715 | * ----------------- |
| 716 | * Compare the current temperature to the trip point values to see |
| 717 | * if we've entered one of the thermal policy states. Note that |
| 718 | * this function determines when a state is entered, but the |
| 719 | * individual policy decides when it is exited (e.g. hysteresis). |
| 720 | */ |
| 721 | if (tz->trips.critical.flags.valid) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 722 | state.critical |= |
| 723 | (tz->temperature >= tz->trips.critical.temperature); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | if (tz->trips.hot.flags.valid) |
| 725 | state.hot |= (tz->temperature >= tz->trips.hot.temperature); |
| 726 | if (tz->trips.passive.flags.valid) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 727 | state.passive |= |
| 728 | (tz->temperature >= tz->trips.passive.temperature); |
| 729 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | if (tz->trips.active[i].flags.valid) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 731 | state.active |= |
| 732 | (tz->temperature >= |
| 733 | tz->trips.active[i].temperature); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
| 735 | /* |
| 736 | * Invoke Policy |
| 737 | * ------------- |
| 738 | * Separated from the above check to allow individual policy to |
| 739 | * determine when to exit a given state. |
| 740 | */ |
| 741 | if (state.critical) |
| 742 | acpi_thermal_critical(tz); |
| 743 | if (state.hot) |
| 744 | acpi_thermal_hot(tz); |
| 745 | if (state.passive) |
| 746 | acpi_thermal_passive(tz); |
| 747 | if (state.active) |
| 748 | acpi_thermal_active(tz); |
| 749 | |
| 750 | /* |
| 751 | * Calculate State |
| 752 | * --------------- |
| 753 | * Again, separated from the above two to allow independent policy |
| 754 | * decisions. |
| 755 | */ |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 756 | tz->state.critical = tz->trips.critical.flags.enabled; |
| 757 | tz->state.hot = tz->trips.hot.flags.enabled; |
| 758 | tz->state.passive = tz->trips.passive.flags.enabled; |
| 759 | tz->state.active = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 760 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 761 | tz->state.active |= tz->trips.active[i].flags.enabled; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | |
| 763 | /* |
| 764 | * Calculate Sleep Time |
| 765 | * -------------------- |
| 766 | * If we're in the passive state, use _TSP's value. Otherwise |
| 767 | * use the default polling frequency (e.g. _TZP). If no polling |
| 768 | * frequency is specified then we'll wait forever (at least until |
| 769 | * a thermal event occurs). Note that _TSP and _TZD values are |
| 770 | * given in 1/10th seconds (we must covert to milliseconds). |
| 771 | */ |
| 772 | if (tz->state.passive) |
| 773 | sleep_time = tz->trips.passive.tsp * 100; |
| 774 | else if (tz->polling_frequency > 0) |
| 775 | sleep_time = tz->polling_frequency * 100; |
| 776 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 777 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n", |
| 778 | tz->name, tz->temperature, sleep_time)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | |
| 780 | /* |
| 781 | * Schedule Next Poll |
| 782 | * ------------------ |
| 783 | */ |
| 784 | if (!sleep_time) { |
| 785 | if (timer_pending(&(tz->timer))) |
| 786 | del_timer(&(tz->timer)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 787 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | if (timer_pending(&(tz->timer))) |
| 789 | mod_timer(&(tz->timer), (HZ * sleep_time) / 1000); |
| 790 | else { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 791 | tz->timer.data = (unsigned long)tz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | tz->timer.function = acpi_thermal_run; |
| 793 | tz->timer.expires = jiffies + (HZ * sleep_time) / 1000; |
| 794 | add_timer(&(tz->timer)); |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | return_VOID; |
| 799 | } |
| 800 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | /* -------------------------------------------------------------------------- |
| 802 | FS Interface (/proc) |
| 803 | -------------------------------------------------------------------------- */ |
| 804 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 805 | static struct proc_dir_entry *acpi_thermal_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | |
| 807 | static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset) |
| 808 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 809 | struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | |
| 811 | ACPI_FUNCTION_TRACE("acpi_thermal_state_seq_show"); |
| 812 | |
| 813 | if (!tz) |
| 814 | goto end; |
| 815 | |
| 816 | seq_puts(seq, "state: "); |
| 817 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 818 | if (!tz->state.critical && !tz->state.hot && !tz->state.passive |
| 819 | && !tz->state.active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | seq_puts(seq, "ok\n"); |
| 821 | else { |
| 822 | if (tz->state.critical) |
| 823 | seq_puts(seq, "critical "); |
| 824 | if (tz->state.hot) |
| 825 | seq_puts(seq, "hot "); |
| 826 | if (tz->state.passive) |
| 827 | seq_puts(seq, "passive "); |
| 828 | if (tz->state.active) |
| 829 | seq_printf(seq, "active[%d]", tz->state.active_index); |
| 830 | seq_puts(seq, "\n"); |
| 831 | } |
| 832 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 833 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | return_VALUE(0); |
| 835 | } |
| 836 | |
| 837 | static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file) |
| 838 | { |
| 839 | return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data); |
| 840 | } |
| 841 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset) |
| 843 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 844 | int result = 0; |
| 845 | struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | |
| 847 | ACPI_FUNCTION_TRACE("acpi_thermal_temp_seq_show"); |
| 848 | |
| 849 | if (!tz) |
| 850 | goto end; |
| 851 | |
| 852 | result = acpi_thermal_get_temperature(tz); |
| 853 | if (result) |
| 854 | goto end; |
| 855 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 856 | seq_printf(seq, "temperature: %ld C\n", |
| 857 | KELVIN_TO_CELSIUS(tz->temperature)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 859 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | return_VALUE(0); |
| 861 | } |
| 862 | |
| 863 | static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file) |
| 864 | { |
| 865 | return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data); |
| 866 | } |
| 867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset) |
| 869 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 870 | struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; |
| 871 | int i = 0; |
| 872 | int j = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | |
| 874 | ACPI_FUNCTION_TRACE("acpi_thermal_trip_seq_show"); |
| 875 | |
| 876 | if (!tz) |
| 877 | goto end; |
| 878 | |
| 879 | if (tz->trips.critical.flags.valid) |
| 880 | seq_printf(seq, "critical (S5): %ld C\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 881 | KELVIN_TO_CELSIUS(tz->trips.critical.temperature)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | |
| 883 | if (tz->trips.hot.flags.valid) |
| 884 | seq_printf(seq, "hot (S4): %ld C\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 885 | KELVIN_TO_CELSIUS(tz->trips.hot.temperature)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | |
| 887 | if (tz->trips.passive.flags.valid) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 888 | seq_printf(seq, |
| 889 | "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=", |
| 890 | KELVIN_TO_CELSIUS(tz->trips.passive.temperature), |
| 891 | tz->trips.passive.tc1, tz->trips.passive.tc2, |
| 892 | tz->trips.passive.tsp); |
| 893 | for (j = 0; j < tz->trips.passive.devices.count; j++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 895 | seq_printf(seq, "0x%p ", |
| 896 | tz->trips.passive.devices.handles[j]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | } |
| 898 | seq_puts(seq, "\n"); |
| 899 | } |
| 900 | |
| 901 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
| 902 | if (!(tz->trips.active[i].flags.valid)) |
| 903 | break; |
| 904 | seq_printf(seq, "active[%d]: %ld C: devices=", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 905 | i, |
| 906 | KELVIN_TO_CELSIUS(tz->trips.active[i].temperature)); |
| 907 | for (j = 0; j < tz->trips.active[i].devices.count; j++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | seq_printf(seq, "0x%p ", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 909 | tz->trips.active[i].devices.handles[j]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | seq_puts(seq, "\n"); |
| 911 | } |
| 912 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 913 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | return_VALUE(0); |
| 915 | } |
| 916 | |
| 917 | static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file) |
| 918 | { |
| 919 | return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data); |
| 920 | } |
| 921 | |
| 922 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 923 | acpi_thermal_write_trip_points(struct file *file, |
| 924 | const char __user * buffer, |
| 925 | size_t count, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 927 | struct seq_file *m = (struct seq_file *)file->private_data; |
| 928 | struct acpi_thermal *tz = (struct acpi_thermal *)m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 930 | char *limit_string; |
| 931 | int num, critical, hot, passive; |
| 932 | int *active; |
| 933 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | |
| 935 | ACPI_FUNCTION_TRACE("acpi_thermal_write_trip_points"); |
| 936 | |
| 937 | limit_string = kmalloc(ACPI_THERMAL_MAX_LIMIT_STR_LEN, GFP_KERNEL); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 938 | if (!limit_string) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | return_VALUE(-ENOMEM); |
| 940 | |
| 941 | memset(limit_string, 0, ACPI_THERMAL_MAX_LIMIT_STR_LEN); |
| 942 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 943 | active = kmalloc(ACPI_THERMAL_MAX_ACTIVE * sizeof(int), GFP_KERNEL); |
Dave Jones | fdc136c | 2006-03-08 22:12:00 -0500 | [diff] [blame] | 944 | if (!active) { |
| 945 | kfree(limit_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | return_VALUE(-ENOMEM); |
Dave Jones | fdc136c | 2006-03-08 22:12:00 -0500 | [diff] [blame] | 947 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | |
| 949 | if (!tz || (count > ACPI_THERMAL_MAX_LIMIT_STR_LEN - 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | count = -EINVAL; |
| 951 | goto end; |
| 952 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | if (copy_from_user(limit_string, buffer, count)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | count = -EFAULT; |
| 956 | goto end; |
| 957 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 958 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | limit_string[count] = '\0'; |
| 960 | |
| 961 | num = sscanf(limit_string, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 962 | &critical, &hot, &passive, |
| 963 | &active[0], &active[1], &active[2], &active[3], &active[4], |
| 964 | &active[5], &active[6], &active[7], &active[8], |
| 965 | &active[9]); |
| 966 | if (!(num >= 5 && num < (ACPI_THERMAL_MAX_ACTIVE + 3))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | count = -EINVAL; |
| 968 | goto end; |
| 969 | } |
| 970 | |
| 971 | tz->trips.critical.temperature = CELSIUS_TO_KELVIN(critical); |
| 972 | tz->trips.hot.temperature = CELSIUS_TO_KELVIN(hot); |
| 973 | tz->trips.passive.temperature = CELSIUS_TO_KELVIN(passive); |
| 974 | for (i = 0; i < num - 3; i++) { |
| 975 | if (!(tz->trips.active[i].flags.valid)) |
| 976 | break; |
| 977 | tz->trips.active[i].temperature = CELSIUS_TO_KELVIN(active[i]); |
| 978 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 979 | |
| 980 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | kfree(active); |
| 982 | kfree(limit_string); |
| 983 | return_VALUE(count); |
| 984 | } |
| 985 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset) |
| 987 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 988 | struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | |
| 990 | ACPI_FUNCTION_TRACE("acpi_thermal_cooling_seq_show"); |
| 991 | |
| 992 | if (!tz) |
| 993 | goto end; |
| 994 | |
| 995 | if (!tz->flags.cooling_mode) { |
| 996 | seq_puts(seq, "<setting not supported>\n"); |
| 997 | } |
| 998 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 999 | if (tz->cooling_mode == ACPI_THERMAL_MODE_CRITICAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | seq_printf(seq, "cooling mode: critical\n"); |
| 1001 | else |
| 1002 | seq_printf(seq, "cooling mode: %s\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1003 | tz->cooling_mode ? "passive" : "active"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1005 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | return_VALUE(0); |
| 1007 | } |
| 1008 | |
| 1009 | static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file) |
| 1010 | { |
| 1011 | return single_open(file, acpi_thermal_cooling_seq_show, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1012 | PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1016 | acpi_thermal_write_cooling_mode(struct file *file, |
| 1017 | const char __user * buffer, |
| 1018 | size_t count, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1020 | struct seq_file *m = (struct seq_file *)file->private_data; |
| 1021 | struct acpi_thermal *tz = (struct acpi_thermal *)m->private; |
| 1022 | int result = 0; |
| 1023 | char mode_string[12] = { '\0' }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | |
| 1025 | ACPI_FUNCTION_TRACE("acpi_thermal_write_cooling_mode"); |
| 1026 | |
| 1027 | if (!tz || (count > sizeof(mode_string) - 1)) |
| 1028 | return_VALUE(-EINVAL); |
| 1029 | |
| 1030 | if (!tz->flags.cooling_mode) |
| 1031 | return_VALUE(-ENODEV); |
| 1032 | |
| 1033 | if (copy_from_user(mode_string, buffer, count)) |
| 1034 | return_VALUE(-EFAULT); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1035 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | mode_string[count] = '\0'; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1037 | |
| 1038 | result = acpi_thermal_set_cooling_mode(tz, |
| 1039 | simple_strtoul(mode_string, NULL, |
| 1040 | 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | if (result) |
| 1042 | return_VALUE(result); |
| 1043 | |
| 1044 | acpi_thermal_check(tz); |
| 1045 | |
| 1046 | return_VALUE(count); |
| 1047 | } |
| 1048 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset) |
| 1050 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1051 | struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | |
| 1053 | ACPI_FUNCTION_TRACE("acpi_thermal_polling_seq_show"); |
| 1054 | |
| 1055 | if (!tz) |
| 1056 | goto end; |
| 1057 | |
| 1058 | if (!tz->polling_frequency) { |
| 1059 | seq_puts(seq, "<polling disabled>\n"); |
| 1060 | goto end; |
| 1061 | } |
| 1062 | |
| 1063 | seq_printf(seq, "polling frequency: %lu seconds\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1064 | (tz->polling_frequency / 10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1066 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | return_VALUE(0); |
| 1068 | } |
| 1069 | |
| 1070 | static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file) |
| 1071 | { |
| 1072 | return single_open(file, acpi_thermal_polling_seq_show, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1073 | PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1077 | acpi_thermal_write_polling(struct file *file, |
| 1078 | const char __user * buffer, |
| 1079 | size_t count, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1081 | struct seq_file *m = (struct seq_file *)file->private_data; |
| 1082 | struct acpi_thermal *tz = (struct acpi_thermal *)m->private; |
| 1083 | int result = 0; |
| 1084 | char polling_string[12] = { '\0' }; |
| 1085 | int seconds = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | |
| 1087 | ACPI_FUNCTION_TRACE("acpi_thermal_write_polling"); |
| 1088 | |
| 1089 | if (!tz || (count > sizeof(polling_string) - 1)) |
| 1090 | return_VALUE(-EINVAL); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1091 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | if (copy_from_user(polling_string, buffer, count)) |
| 1093 | return_VALUE(-EFAULT); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1094 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | polling_string[count] = '\0'; |
| 1096 | |
| 1097 | seconds = simple_strtoul(polling_string, NULL, 0); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1098 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | result = acpi_thermal_set_polling(tz, seconds); |
| 1100 | if (result) |
| 1101 | return_VALUE(result); |
| 1102 | |
| 1103 | acpi_thermal_check(tz); |
| 1104 | |
| 1105 | return_VALUE(count); |
| 1106 | } |
| 1107 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1108 | static int acpi_thermal_add_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1110 | struct proc_dir_entry *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | |
| 1112 | ACPI_FUNCTION_TRACE("acpi_thermal_add_fs"); |
| 1113 | |
| 1114 | if (!acpi_device_dir(device)) { |
| 1115 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1116 | acpi_thermal_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | if (!acpi_device_dir(device)) |
| 1118 | return_VALUE(-ENODEV); |
| 1119 | acpi_device_dir(device)->owner = THIS_MODULE; |
| 1120 | } |
| 1121 | |
| 1122 | /* 'state' [R] */ |
| 1123 | entry = create_proc_entry(ACPI_THERMAL_FILE_STATE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1124 | S_IRUGO, acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | if (!entry) |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 1126 | return_VALUE(-ENODEV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | else { |
| 1128 | entry->proc_fops = &acpi_thermal_state_fops; |
| 1129 | entry->data = acpi_driver_data(device); |
| 1130 | entry->owner = THIS_MODULE; |
| 1131 | } |
| 1132 | |
| 1133 | /* 'temperature' [R] */ |
| 1134 | entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1135 | S_IRUGO, acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | if (!entry) |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 1137 | return_VALUE(-ENODEV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | else { |
| 1139 | entry->proc_fops = &acpi_thermal_temp_fops; |
| 1140 | entry->data = acpi_driver_data(device); |
| 1141 | entry->owner = THIS_MODULE; |
| 1142 | } |
| 1143 | |
| 1144 | /* 'trip_points' [R/W] */ |
| 1145 | entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1146 | S_IFREG | S_IRUGO | S_IWUSR, |
| 1147 | acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | if (!entry) |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 1149 | return_VALUE(-ENODEV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | else { |
| 1151 | entry->proc_fops = &acpi_thermal_trip_fops; |
| 1152 | entry->data = acpi_driver_data(device); |
| 1153 | entry->owner = THIS_MODULE; |
| 1154 | } |
| 1155 | |
| 1156 | /* 'cooling_mode' [R/W] */ |
| 1157 | entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1158 | S_IFREG | S_IRUGO | S_IWUSR, |
| 1159 | acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | if (!entry) |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 1161 | return_VALUE(-ENODEV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | else { |
| 1163 | entry->proc_fops = &acpi_thermal_cooling_fops; |
| 1164 | entry->data = acpi_driver_data(device); |
| 1165 | entry->owner = THIS_MODULE; |
| 1166 | } |
| 1167 | |
| 1168 | /* 'polling_frequency' [R/W] */ |
| 1169 | entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1170 | S_IFREG | S_IRUGO | S_IWUSR, |
| 1171 | acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | if (!entry) |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 1173 | return_VALUE(-ENODEV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | else { |
| 1175 | entry->proc_fops = &acpi_thermal_polling_fops; |
| 1176 | entry->data = acpi_driver_data(device); |
| 1177 | entry->owner = THIS_MODULE; |
| 1178 | } |
| 1179 | |
| 1180 | return_VALUE(0); |
| 1181 | } |
| 1182 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1183 | static int acpi_thermal_remove_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | { |
| 1185 | ACPI_FUNCTION_TRACE("acpi_thermal_remove_fs"); |
| 1186 | |
| 1187 | if (acpi_device_dir(device)) { |
| 1188 | remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ, |
| 1189 | acpi_device_dir(device)); |
| 1190 | remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE, |
| 1191 | acpi_device_dir(device)); |
| 1192 | remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS, |
| 1193 | acpi_device_dir(device)); |
| 1194 | remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE, |
| 1195 | acpi_device_dir(device)); |
| 1196 | remove_proc_entry(ACPI_THERMAL_FILE_STATE, |
| 1197 | acpi_device_dir(device)); |
| 1198 | remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir); |
| 1199 | acpi_device_dir(device) = NULL; |
| 1200 | } |
| 1201 | |
| 1202 | return_VALUE(0); |
| 1203 | } |
| 1204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | /* -------------------------------------------------------------------------- |
| 1206 | Driver Interface |
| 1207 | -------------------------------------------------------------------------- */ |
| 1208 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1209 | static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1211 | struct acpi_thermal *tz = (struct acpi_thermal *)data; |
| 1212 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | |
| 1214 | ACPI_FUNCTION_TRACE("acpi_thermal_notify"); |
| 1215 | |
| 1216 | if (!tz) |
| 1217 | return_VOID; |
| 1218 | |
| 1219 | if (acpi_bus_get_device(tz->handle, &device)) |
| 1220 | return_VOID; |
| 1221 | |
| 1222 | switch (event) { |
| 1223 | case ACPI_THERMAL_NOTIFY_TEMPERATURE: |
| 1224 | acpi_thermal_check(tz); |
| 1225 | break; |
| 1226 | case ACPI_THERMAL_NOTIFY_THRESHOLDS: |
| 1227 | acpi_thermal_get_trip_points(tz); |
| 1228 | acpi_thermal_check(tz); |
| 1229 | acpi_bus_generate_event(device, event, 0); |
| 1230 | break; |
| 1231 | case ACPI_THERMAL_NOTIFY_DEVICES: |
| 1232 | if (tz->flags.devices) |
| 1233 | acpi_thermal_get_devices(tz); |
| 1234 | acpi_bus_generate_event(device, event, 0); |
| 1235 | break; |
| 1236 | default: |
| 1237 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1238 | "Unsupported event [0x%x]\n", event)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | break; |
| 1240 | } |
| 1241 | |
| 1242 | return_VOID; |
| 1243 | } |
| 1244 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1245 | static int acpi_thermal_get_info(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1247 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | |
| 1249 | ACPI_FUNCTION_TRACE("acpi_thermal_get_info"); |
| 1250 | |
| 1251 | if (!tz) |
| 1252 | return_VALUE(-EINVAL); |
| 1253 | |
| 1254 | /* Get temperature [_TMP] (required) */ |
| 1255 | result = acpi_thermal_get_temperature(tz); |
| 1256 | if (result) |
| 1257 | return_VALUE(result); |
| 1258 | |
| 1259 | /* Get trip points [_CRT, _PSV, etc.] (required) */ |
| 1260 | result = acpi_thermal_get_trip_points(tz); |
| 1261 | if (result) |
| 1262 | return_VALUE(result); |
| 1263 | |
| 1264 | /* Set the cooling mode [_SCP] to active cooling (default) */ |
| 1265 | result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1266 | if (!result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | tz->flags.cooling_mode = 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1268 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | /* Oh,we have not _SCP method. |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1270 | Generally show cooling_mode by _ACx, _PSV,spec 12.2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | tz->flags.cooling_mode = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1272 | if (tz->trips.active[0].flags.valid |
| 1273 | && tz->trips.passive.flags.valid) { |
| 1274 | if (tz->trips.passive.temperature > |
| 1275 | tz->trips.active[0].temperature) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | tz->cooling_mode = ACPI_THERMAL_MODE_ACTIVE; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1277 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | tz->cooling_mode = ACPI_THERMAL_MODE_PASSIVE; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1279 | } else if (!tz->trips.active[0].flags.valid |
| 1280 | && tz->trips.passive.flags.valid) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | tz->cooling_mode = ACPI_THERMAL_MODE_PASSIVE; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1282 | } else if (tz->trips.active[0].flags.valid |
| 1283 | && !tz->trips.passive.flags.valid) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | tz->cooling_mode = ACPI_THERMAL_MODE_ACTIVE; |
| 1285 | } else { |
| 1286 | /* _ACx and _PSV are optional, but _CRT is required */ |
| 1287 | tz->cooling_mode = ACPI_THERMAL_MODE_CRITICAL; |
| 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | /* Get default polling frequency [_TZP] (optional) */ |
| 1292 | if (tzp) |
| 1293 | tz->polling_frequency = tzp; |
| 1294 | else |
| 1295 | acpi_thermal_get_polling_frequency(tz); |
| 1296 | |
| 1297 | /* Get devices in this thermal zone [_TZD] (optional) */ |
| 1298 | result = acpi_thermal_get_devices(tz); |
| 1299 | if (!result) |
| 1300 | tz->flags.devices = 1; |
| 1301 | |
| 1302 | return_VALUE(0); |
| 1303 | } |
| 1304 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1305 | static int acpi_thermal_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1307 | int result = 0; |
| 1308 | acpi_status status = AE_OK; |
| 1309 | struct acpi_thermal *tz = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | |
| 1311 | ACPI_FUNCTION_TRACE("acpi_thermal_add"); |
| 1312 | |
| 1313 | if (!device) |
| 1314 | return_VALUE(-EINVAL); |
| 1315 | |
| 1316 | tz = kmalloc(sizeof(struct acpi_thermal), GFP_KERNEL); |
| 1317 | if (!tz) |
| 1318 | return_VALUE(-ENOMEM); |
| 1319 | memset(tz, 0, sizeof(struct acpi_thermal)); |
| 1320 | |
| 1321 | tz->handle = device->handle; |
| 1322 | strcpy(tz->name, device->pnp.bus_id); |
| 1323 | strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME); |
| 1324 | strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS); |
| 1325 | acpi_driver_data(device) = tz; |
| 1326 | |
| 1327 | result = acpi_thermal_get_info(tz); |
| 1328 | if (result) |
| 1329 | goto end; |
| 1330 | |
| 1331 | result = acpi_thermal_add_fs(device); |
| 1332 | if (result) |
Vasily Averin | 09047e7 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 1333 | goto end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | |
| 1335 | init_timer(&tz->timer); |
| 1336 | |
| 1337 | acpi_thermal_check(tz); |
| 1338 | |
| 1339 | status = acpi_install_notify_handler(tz->handle, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1340 | ACPI_DEVICE_NOTIFY, |
| 1341 | acpi_thermal_notify, tz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | result = -ENODEV; |
| 1344 | goto end; |
| 1345 | } |
| 1346 | |
| 1347 | printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1348 | acpi_device_name(device), acpi_device_bid(device), |
| 1349 | KELVIN_TO_CELSIUS(tz->temperature)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1351 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | if (result) { |
| 1353 | acpi_thermal_remove_fs(device); |
| 1354 | kfree(tz); |
| 1355 | } |
| 1356 | |
| 1357 | return_VALUE(result); |
| 1358 | } |
| 1359 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1360 | static int acpi_thermal_remove(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1362 | acpi_status status = AE_OK; |
| 1363 | struct acpi_thermal *tz = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | |
| 1365 | ACPI_FUNCTION_TRACE("acpi_thermal_remove"); |
| 1366 | |
| 1367 | if (!device || !acpi_driver_data(device)) |
| 1368 | return_VALUE(-EINVAL); |
| 1369 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1370 | tz = (struct acpi_thermal *)acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | |
| 1372 | /* avoid timer adding new defer task */ |
| 1373 | tz->zombie = 1; |
| 1374 | /* wait for running timer (on other CPUs) finish */ |
| 1375 | del_timer_sync(&(tz->timer)); |
| 1376 | /* synchronize deferred task */ |
| 1377 | acpi_os_wait_events_complete(NULL); |
| 1378 | /* deferred task may reinsert timer */ |
| 1379 | del_timer_sync(&(tz->timer)); |
| 1380 | |
| 1381 | status = acpi_remove_notify_handler(tz->handle, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1382 | ACPI_DEVICE_NOTIFY, |
| 1383 | acpi_thermal_notify); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | |
| 1385 | /* Terminate policy */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1386 | if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | tz->trips.passive.flags.enabled = 0; |
| 1388 | acpi_thermal_passive(tz); |
| 1389 | } |
| 1390 | if (tz->trips.active[0].flags.valid |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1391 | && tz->trips.active[0].flags.enabled) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | tz->trips.active[0].flags.enabled = 0; |
| 1393 | acpi_thermal_active(tz); |
| 1394 | } |
| 1395 | |
| 1396 | acpi_thermal_remove_fs(device); |
| 1397 | |
| 1398 | kfree(tz); |
| 1399 | return_VALUE(0); |
| 1400 | } |
| 1401 | |
Konstantin Karasyov | 74ce146 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1402 | static int acpi_thermal_resume(struct acpi_device *device, int state) |
| 1403 | { |
| 1404 | struct acpi_thermal *tz = NULL; |
| 1405 | |
| 1406 | if (!device || !acpi_driver_data(device)) |
| 1407 | return_VALUE(-EINVAL); |
| 1408 | |
| 1409 | tz = (struct acpi_thermal *)acpi_driver_data(device); |
| 1410 | |
| 1411 | acpi_thermal_check(tz); |
| 1412 | |
| 1413 | return AE_OK; |
| 1414 | } |
| 1415 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1416 | static int __init acpi_thermal_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1418 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | |
| 1420 | ACPI_FUNCTION_TRACE("acpi_thermal_init"); |
| 1421 | |
| 1422 | acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir); |
| 1423 | if (!acpi_thermal_dir) |
| 1424 | return_VALUE(-ENODEV); |
| 1425 | acpi_thermal_dir->owner = THIS_MODULE; |
| 1426 | |
| 1427 | result = acpi_bus_register_driver(&acpi_thermal_driver); |
| 1428 | if (result < 0) { |
| 1429 | remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir); |
| 1430 | return_VALUE(-ENODEV); |
| 1431 | } |
| 1432 | |
| 1433 | return_VALUE(0); |
| 1434 | } |
| 1435 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1436 | static void __exit acpi_thermal_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | { |
| 1438 | ACPI_FUNCTION_TRACE("acpi_thermal_exit"); |
| 1439 | |
| 1440 | acpi_bus_unregister_driver(&acpi_thermal_driver); |
| 1441 | |
| 1442 | remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir); |
| 1443 | |
| 1444 | return_VOID; |
| 1445 | } |
| 1446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | module_init(acpi_thermal_init); |
| 1448 | module_exit(acpi_thermal_exit); |