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