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