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