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/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/kmod.h> |
| 42 | #include <linux/seq_file.h> |
Jeremy Fitzhardinge | 10a0a8d | 2007-07-17 18:37:02 -0700 | [diff] [blame] | 43 | #include <linux/reboot.h> |
Stephen Rothwell | f6f5c45 | 2009-03-03 12:47:17 +1100 | [diff] [blame] | 44 | #include <linux/device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <asm/uaccess.h> |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 46 | #include <linux/thermal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <acpi/acpi_bus.h> |
| 48 | #include <acpi/acpi_drivers.h> |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #define ACPI_THERMAL_CLASS "thermal_zone" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone" |
| 52 | #define ACPI_THERMAL_FILE_STATE "state" |
| 53 | #define ACPI_THERMAL_FILE_TEMPERATURE "temperature" |
| 54 | #define ACPI_THERMAL_FILE_TRIP_POINTS "trip_points" |
| 55 | #define ACPI_THERMAL_FILE_COOLING_MODE "cooling_mode" |
| 56 | #define ACPI_THERMAL_FILE_POLLING_FREQ "polling_frequency" |
| 57 | #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80 |
| 58 | #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81 |
| 59 | #define ACPI_THERMAL_NOTIFY_DEVICES 0x82 |
| 60 | #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0 |
| 61 | #define ACPI_THERMAL_NOTIFY_HOT 0xF1 |
| 62 | #define ACPI_THERMAL_MODE_ACTIVE 0x00 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | #define ACPI_THERMAL_MAX_ACTIVE 10 |
| 65 | #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65 |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #define _COMPONENT ACPI_THERMAL_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 68 | ACPI_MODULE_NAME("thermal"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 70 | MODULE_AUTHOR("Paul Diefenbaugh"); |
Len Brown | 7cda93e | 2007-02-12 23:50:02 -0500 | [diff] [blame] | 71 | MODULE_DESCRIPTION("ACPI Thermal Zone Driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | MODULE_LICENSE("GPL"); |
| 73 | |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 74 | static int act; |
| 75 | module_param(act, int, 0644); |
Len Brown | 3c1d36d | 2007-08-14 15:12:56 -0400 | [diff] [blame] | 76 | MODULE_PARM_DESC(act, "Disable or override all lowest active trip points."); |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 77 | |
Len Brown | c52a741 | 2007-08-14 15:49:32 -0400 | [diff] [blame] | 78 | static int crt; |
| 79 | module_param(crt, int, 0644); |
| 80 | MODULE_PARM_DESC(crt, "Disable or lower all critical trip points."); |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | static int tzp; |
Len Brown | 730ff34 | 2007-08-12 00:12:26 -0400 | [diff] [blame] | 83 | module_param(tzp, int, 0444); |
Len Brown | 3c1d36d | 2007-08-14 15:12:56 -0400 | [diff] [blame] | 84 | MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
Len Brown | f548714 | 2007-08-12 00:12:44 -0400 | [diff] [blame] | 86 | static int nocrt; |
| 87 | module_param(nocrt, int, 0); |
Len Brown | 8c99fdc | 2007-08-20 18:46:50 -0400 | [diff] [blame] | 88 | 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] | 89 | |
Len Brown | 72b33ef | 2007-08-12 00:12:17 -0400 | [diff] [blame] | 90 | static int off; |
| 91 | module_param(off, int, 0); |
Len Brown | 3c1d36d | 2007-08-14 15:12:56 -0400 | [diff] [blame] | 92 | MODULE_PARM_DESC(off, "Set to disable ACPI thermal support."); |
Len Brown | 72b33ef | 2007-08-12 00:12:17 -0400 | [diff] [blame] | 93 | |
Len Brown | a70cdc5 | 2007-08-12 00:12:35 -0400 | [diff] [blame] | 94 | static int psv; |
| 95 | module_param(psv, int, 0644); |
Len Brown | 3c1d36d | 2007-08-14 15:12:56 -0400 | [diff] [blame] | 96 | MODULE_PARM_DESC(psv, "Disable or override all passive trip points."); |
Len Brown | a70cdc5 | 2007-08-12 00:12:35 -0400 | [diff] [blame] | 97 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 98 | static int acpi_thermal_add(struct acpi_device *device); |
| 99 | static int acpi_thermal_remove(struct acpi_device *device, int type); |
Patrick Mochel | 5d9464a | 2006-12-07 20:56:27 +0800 | [diff] [blame] | 100 | static int acpi_thermal_resume(struct acpi_device *device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file); |
| 102 | static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file); |
| 103 | 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] | 104 | 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] | 105 | static ssize_t acpi_thermal_write_cooling_mode(struct file *, |
| 106 | const char __user *, size_t, |
| 107 | loff_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | 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] | 109 | static ssize_t acpi_thermal_write_polling(struct file *, const char __user *, |
| 110 | size_t, loff_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 112 | static const struct acpi_device_id thermal_device_ids[] = { |
| 113 | {ACPI_THERMAL_HID, 0}, |
| 114 | {"", 0}, |
| 115 | }; |
| 116 | MODULE_DEVICE_TABLE(acpi, thermal_device_ids); |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | static struct acpi_driver acpi_thermal_driver = { |
Len Brown | c2b6705 | 2007-02-12 23:33:40 -0500 | [diff] [blame] | 119 | .name = "thermal", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 120 | .class = ACPI_THERMAL_CLASS, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 121 | .ids = thermal_device_ids, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 122 | .ops = { |
| 123 | .add = acpi_thermal_add, |
| 124 | .remove = acpi_thermal_remove, |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 125 | .resume = acpi_thermal_resume, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 126 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | struct acpi_thermal_state { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 130 | u8 critical:1; |
| 131 | u8 hot:1; |
| 132 | u8 passive:1; |
| 133 | u8 active:1; |
| 134 | u8 reserved:4; |
| 135 | int active_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | struct acpi_thermal_state_flags { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 139 | u8 valid:1; |
| 140 | u8 enabled:1; |
| 141 | u8 reserved:6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | struct acpi_thermal_critical { |
| 145 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 146 | unsigned long temperature; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | struct acpi_thermal_hot { |
| 150 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 151 | unsigned long temperature; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | struct acpi_thermal_passive { |
| 155 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | unsigned long temperature; |
| 157 | unsigned long tc1; |
| 158 | unsigned long tc2; |
| 159 | unsigned long tsp; |
| 160 | struct acpi_handle_list devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | struct acpi_thermal_active { |
| 164 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 165 | unsigned long temperature; |
| 166 | struct acpi_handle_list devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | struct acpi_thermal_trips { |
| 170 | struct acpi_thermal_critical critical; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 171 | struct acpi_thermal_hot hot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | struct acpi_thermal_passive passive; |
| 173 | struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE]; |
| 174 | }; |
| 175 | |
| 176 | struct acpi_thermal_flags { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 177 | u8 cooling_mode:1; /* _SCP */ |
| 178 | u8 devices:1; /* _TZD */ |
| 179 | u8 reserved:6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | struct acpi_thermal { |
Patrick Mochel | 8348e1b | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 183 | struct acpi_device * device; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 184 | acpi_bus_id name; |
| 185 | unsigned long temperature; |
| 186 | unsigned long last_temperature; |
| 187 | unsigned long polling_frequency; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 188 | volatile u8 zombie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | struct acpi_thermal_flags flags; |
| 190 | struct acpi_thermal_state state; |
| 191 | struct acpi_thermal_trips trips; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 192 | struct acpi_handle_list devices; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 193 | struct thermal_zone_device *thermal_zone; |
| 194 | int tz_enabled; |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame^] | 195 | int kelvin_offset; |
Alexey Starikovskiy | 6e21578 | 2007-09-01 00:11:59 +0400 | [diff] [blame] | 196 | struct mutex lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | }; |
| 198 | |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 199 | static const struct file_operations acpi_thermal_state_fops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 200 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | .open = acpi_thermal_state_open_fs, |
| 202 | .read = seq_read, |
| 203 | .llseek = seq_lseek, |
| 204 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | }; |
| 206 | |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 207 | static const struct file_operations acpi_thermal_temp_fops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 208 | .owner = THIS_MODULE, |
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 = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 216 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 217 | .open = acpi_thermal_trip_open_fs, |
| 218 | .read = seq_read, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 219 | .llseek = seq_lseek, |
| 220 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | }; |
| 222 | |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 223 | static const struct file_operations acpi_thermal_cooling_fops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 224 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 225 | .open = acpi_thermal_cooling_open_fs, |
| 226 | .read = seq_read, |
| 227 | .write = acpi_thermal_write_cooling_mode, |
| 228 | .llseek = seq_lseek, |
| 229 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | }; |
| 231 | |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 232 | static const struct file_operations acpi_thermal_polling_fops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 233 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 234 | .open = acpi_thermal_polling_open_fs, |
| 235 | .read = seq_read, |
| 236 | .write = acpi_thermal_write_polling, |
| 237 | .llseek = seq_lseek, |
| 238 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | }; |
| 240 | |
| 241 | /* -------------------------------------------------------------------------- |
| 242 | Thermal Zone Management |
| 243 | -------------------------------------------------------------------------- */ |
| 244 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 245 | static int acpi_thermal_get_temperature(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 247 | acpi_status status = AE_OK; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 248 | unsigned long long tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
| 250 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 251 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | tz->last_temperature = tz->temperature; |
| 254 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 255 | status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 257 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 259 | tz->temperature = tmp; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 260 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n", |
| 261 | tz->temperature)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 263 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 266 | static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 268 | acpi_status status = AE_OK; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 269 | unsigned long long tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
| 271 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 272 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 274 | status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 276 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 278 | tz->polling_frequency = tmp; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 279 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n", |
| 280 | tz->polling_frequency)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 282 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 285 | static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 289 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
| 291 | tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */ |
| 292 | |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 293 | tz->thermal_zone->polling_delay = seconds * 1000; |
| 294 | |
| 295 | if (tz->tz_enabled) |
| 296 | thermal_zone_device_update(tz->thermal_zone); |
| 297 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 298 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 299 | "Polling frequency set to %lu seconds\n", |
Sanjoy Mahajan | 636cedf | 2007-02-16 01:24:43 -0500 | [diff] [blame] | 300 | tz->polling_frequency/10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 302 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 305 | 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] | 306 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 307 | acpi_status status = AE_OK; |
| 308 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; |
| 309 | struct acpi_object_list arg_list = { 1, &arg0 }; |
| 310 | acpi_handle handle = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
| 313 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 314 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Patrick Mochel | 38ba7c9 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 316 | status = acpi_get_handle(tz->device->handle, "_SCP", &handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | if (ACPI_FAILURE(status)) { |
| 318 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n")); |
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 | } |
| 321 | |
| 322 | arg0.integer.value = mode; |
| 323 | |
| 324 | status = acpi_evaluate_object(handle, NULL, &arg_list, NULL); |
| 325 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 326 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 328 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 331 | #define ACPI_TRIPS_CRITICAL 0x01 |
| 332 | #define ACPI_TRIPS_HOT 0x02 |
| 333 | #define ACPI_TRIPS_PASSIVE 0x04 |
| 334 | #define ACPI_TRIPS_ACTIVE 0x08 |
| 335 | #define ACPI_TRIPS_DEVICES 0x10 |
| 336 | |
| 337 | #define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE) |
| 338 | #define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES |
| 339 | |
| 340 | #define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \ |
| 341 | ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \ |
| 342 | ACPI_TRIPS_DEVICES) |
| 343 | |
| 344 | /* |
| 345 | * This exception is thrown out in two cases: |
| 346 | * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid |
| 347 | * when re-evaluating the AML code. |
| 348 | * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change. |
| 349 | * We need to re-bind the cooling devices of a thermal zone when this occurs. |
| 350 | */ |
| 351 | #define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \ |
| 352 | do { \ |
| 353 | if (flags != ACPI_TRIPS_INIT) \ |
| 354 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, \ |
| 355 | "ACPI thermal trip point %s changed\n" \ |
| 356 | "Please send acpidump to linux-acpi@vger.kernel.org\n", str)); \ |
| 357 | } while (0) |
| 358 | |
| 359 | static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 361 | acpi_status status = AE_OK; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 362 | unsigned long long tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 363 | struct acpi_handle_list devices; |
| 364 | int valid = 0; |
| 365 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
| 367 | /* Critical Shutdown (required) */ |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 368 | if (flag & ACPI_TRIPS_CRITICAL) { |
| 369 | status = acpi_evaluate_integer(tz->device->handle, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 370 | "_CRT", NULL, &tmp); |
| 371 | tz->trips.critical.temperature = tmp; |
Arjan van de Ven | a39a2d7 | 2008-05-19 15:55:15 -0700 | [diff] [blame] | 372 | /* |
| 373 | * Treat freezing temperatures as invalid as well; some |
| 374 | * BIOSes return really low values and cause reboots at startup. |
Adam Buchbinder | b731d7b | 2009-03-13 12:15:26 -0400 | [diff] [blame] | 375 | * Below zero (Celsius) values clearly aren't right for sure.. |
Arjan van de Ven | a39a2d7 | 2008-05-19 15:55:15 -0700 | [diff] [blame] | 376 | * ... so lets discard those as invalid. |
| 377 | */ |
| 378 | if (ACPI_FAILURE(status) || |
| 379 | tz->trips.critical.temperature <= 2732) { |
Len Brown | c52a741 | 2007-08-14 15:49:32 -0400 | [diff] [blame] | 380 | tz->trips.critical.flags.valid = 0; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 381 | ACPI_EXCEPTION((AE_INFO, status, |
Arjan van de Ven | a39a2d7 | 2008-05-19 15:55:15 -0700 | [diff] [blame] | 382 | "No or invalid critical threshold")); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 383 | return -ENODEV; |
| 384 | } else { |
| 385 | tz->trips.critical.flags.valid = 1; |
| 386 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 387 | "Found critical threshold [%lu]\n", |
| 388 | tz->trips.critical.temperature)); |
| 389 | } |
| 390 | if (tz->trips.critical.flags.valid == 1) { |
| 391 | if (crt == -1) { |
| 392 | tz->trips.critical.flags.valid = 0; |
| 393 | } else if (crt > 0) { |
| 394 | unsigned long crt_k = CELSIUS_TO_KELVIN(crt); |
| 395 | /* |
Zhang Rui | 22a94d7 | 2008-10-17 02:41:20 -0400 | [diff] [blame] | 396 | * Allow override critical threshold |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 397 | */ |
Zhang Rui | 22a94d7 | 2008-10-17 02:41:20 -0400 | [diff] [blame] | 398 | if (crt_k > tz->trips.critical.temperature) |
| 399 | printk(KERN_WARNING PREFIX |
| 400 | "Critical threshold %d C\n", crt); |
| 401 | tz->trips.critical.temperature = crt_k; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 402 | } |
Len Brown | c52a741 | 2007-08-14 15:49:32 -0400 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | /* Critical Sleep (optional) */ |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 407 | if (flag & ACPI_TRIPS_HOT) { |
Len Brown | a70cdc5 | 2007-08-12 00:12:35 -0400 | [diff] [blame] | 408 | status = acpi_evaluate_integer(tz->device->handle, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 409 | "_HOT", NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 410 | if (ACPI_FAILURE(status)) { |
| 411 | tz->trips.hot.flags.valid = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 412 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 413 | "No hot threshold\n")); |
| 414 | } else { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 415 | tz->trips.hot.temperature = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 416 | tz->trips.hot.flags.valid = 1; |
| 417 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 418 | "Found hot threshold [%lu]\n", |
| 419 | tz->trips.critical.temperature)); |
| 420 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 423 | /* Passive (optional) */ |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 424 | if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) || |
| 425 | (flag == ACPI_TRIPS_INIT)) { |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 426 | valid = tz->trips.passive.flags.valid; |
| 427 | if (psv == -1) { |
| 428 | status = AE_SUPPORT; |
| 429 | } else if (psv > 0) { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 430 | tmp = CELSIUS_TO_KELVIN(psv); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 431 | status = AE_OK; |
| 432 | } else { |
| 433 | status = acpi_evaluate_integer(tz->device->handle, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 434 | "_PSV", NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 435 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 437 | if (ACPI_FAILURE(status)) |
| 438 | tz->trips.passive.flags.valid = 0; |
| 439 | else { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 440 | tz->trips.passive.temperature = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 441 | tz->trips.passive.flags.valid = 1; |
| 442 | if (flag == ACPI_TRIPS_INIT) { |
| 443 | status = acpi_evaluate_integer( |
| 444 | tz->device->handle, "_TC1", |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 445 | NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 446 | if (ACPI_FAILURE(status)) |
| 447 | tz->trips.passive.flags.valid = 0; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 448 | else |
| 449 | tz->trips.passive.tc1 = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 450 | status = acpi_evaluate_integer( |
| 451 | tz->device->handle, "_TC2", |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 452 | NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 453 | if (ACPI_FAILURE(status)) |
| 454 | tz->trips.passive.flags.valid = 0; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 455 | else |
| 456 | tz->trips.passive.tc2 = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 457 | status = acpi_evaluate_integer( |
| 458 | tz->device->handle, "_TSP", |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 459 | NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 460 | if (ACPI_FAILURE(status)) |
| 461 | tz->trips.passive.flags.valid = 0; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 462 | else |
| 463 | tz->trips.passive.tsp = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | } |
| 467 | if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) { |
| 468 | memset(&devices, 0, sizeof(struct acpi_handle_list)); |
| 469 | status = acpi_evaluate_reference(tz->device->handle, "_PSL", |
| 470 | NULL, &devices); |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 471 | if (ACPI_FAILURE(status)) { |
| 472 | printk(KERN_WARNING PREFIX |
| 473 | "Invalid passive threshold\n"); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 474 | tz->trips.passive.flags.valid = 0; |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 475 | } |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 476 | else |
| 477 | tz->trips.passive.flags.valid = 1; |
| 478 | |
| 479 | if (memcmp(&tz->trips.passive.devices, &devices, |
| 480 | sizeof(struct acpi_handle_list))) { |
| 481 | memcpy(&tz->trips.passive.devices, &devices, |
| 482 | sizeof(struct acpi_handle_list)); |
| 483 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); |
| 484 | } |
| 485 | } |
| 486 | if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) { |
| 487 | if (valid != tz->trips.passive.flags.valid) |
| 488 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state"); |
| 489 | } |
| 490 | |
| 491 | /* Active (optional) */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 492 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 493 | char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 494 | valid = tz->trips.active[i].flags.valid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 496 | if (act == -1) |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 497 | break; /* disable all active trip points */ |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 498 | |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 499 | if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) && |
| 500 | tz->trips.active[i].flags.valid)) { |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 501 | status = acpi_evaluate_integer(tz->device->handle, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 502 | name, NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 503 | if (ACPI_FAILURE(status)) { |
| 504 | tz->trips.active[i].flags.valid = 0; |
| 505 | if (i == 0) |
| 506 | break; |
| 507 | if (act <= 0) |
| 508 | break; |
| 509 | if (i == 1) |
| 510 | tz->trips.active[0].temperature = |
| 511 | CELSIUS_TO_KELVIN(act); |
| 512 | else |
| 513 | /* |
| 514 | * Don't allow override higher than |
| 515 | * the next higher trip point |
| 516 | */ |
| 517 | tz->trips.active[i - 1].temperature = |
| 518 | (tz->trips.active[i - 2].temperature < |
| 519 | CELSIUS_TO_KELVIN(act) ? |
| 520 | tz->trips.active[i - 2].temperature : |
| 521 | CELSIUS_TO_KELVIN(act)); |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 522 | break; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 523 | } else { |
| 524 | tz->trips.active[i].temperature = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 525 | tz->trips.active[i].flags.valid = 1; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 526 | } |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 527 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
| 529 | name[2] = 'L'; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 530 | if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) { |
| 531 | memset(&devices, 0, sizeof(struct acpi_handle_list)); |
| 532 | status = acpi_evaluate_reference(tz->device->handle, |
| 533 | name, NULL, &devices); |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 534 | if (ACPI_FAILURE(status)) { |
| 535 | printk(KERN_WARNING PREFIX |
| 536 | "Invalid active%d threshold\n", i); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 537 | tz->trips.active[i].flags.valid = 0; |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 538 | } |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 539 | else |
| 540 | tz->trips.active[i].flags.valid = 1; |
| 541 | |
| 542 | if (memcmp(&tz->trips.active[i].devices, &devices, |
| 543 | sizeof(struct acpi_handle_list))) { |
| 544 | memcpy(&tz->trips.active[i].devices, &devices, |
| 545 | sizeof(struct acpi_handle_list)); |
| 546 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); |
| 547 | } |
| 548 | } |
| 549 | if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES)) |
| 550 | if (valid != tz->trips.active[i].flags.valid) |
| 551 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state"); |
| 552 | |
| 553 | if (!tz->trips.active[i].flags.valid) |
| 554 | break; |
| 555 | } |
| 556 | |
| 557 | if (flag & ACPI_TRIPS_DEVICES) { |
| 558 | memset(&devices, 0, sizeof(struct acpi_handle_list)); |
| 559 | status = acpi_evaluate_reference(tz->device->handle, "_TZD", |
| 560 | NULL, &devices); |
| 561 | if (memcmp(&tz->devices, &devices, |
| 562 | sizeof(struct acpi_handle_list))) { |
| 563 | memcpy(&tz->devices, &devices, |
| 564 | sizeof(struct acpi_handle_list)); |
| 565 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); |
| 566 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 569 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 572 | static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | { |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 574 | return acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 577 | static void acpi_thermal_check(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 579 | struct acpi_thermal *tz = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 581 | thermal_zone_device_update(tz->thermal_zone); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 584 | /* sys I/F for generic thermal sysfs support */ |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame^] | 585 | #define KELVIN_TO_MILLICELSIUS(t, off) (((t) - (off)) * 100) |
Zhang, Rui | 5e01276 | 2008-02-28 07:51:30 +0800 | [diff] [blame] | 586 | |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 587 | static int thermal_get_temp(struct thermal_zone_device *thermal, |
| 588 | unsigned long *temp) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 589 | { |
| 590 | struct acpi_thermal *tz = thermal->devdata; |
Zhang, Rui | 76ecb4f | 2008-04-10 16:20:23 +0800 | [diff] [blame] | 591 | int result; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 592 | |
| 593 | if (!tz) |
| 594 | return -EINVAL; |
| 595 | |
Zhang, Rui | 76ecb4f | 2008-04-10 16:20:23 +0800 | [diff] [blame] | 596 | result = acpi_thermal_get_temperature(tz); |
| 597 | if (result) |
| 598 | return result; |
| 599 | |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame^] | 600 | *temp = KELVIN_TO_MILLICELSIUS(tz->temperature, tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 601 | return 0; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | static const char enabled[] = "kernel"; |
| 605 | static const char disabled[] = "user"; |
| 606 | static int thermal_get_mode(struct thermal_zone_device *thermal, |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 607 | enum thermal_device_mode *mode) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 608 | { |
| 609 | struct acpi_thermal *tz = thermal->devdata; |
| 610 | |
| 611 | if (!tz) |
| 612 | return -EINVAL; |
| 613 | |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 614 | *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : |
| 615 | THERMAL_DEVICE_DISABLED; |
| 616 | |
| 617 | return 0; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | static int thermal_set_mode(struct thermal_zone_device *thermal, |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 621 | enum thermal_device_mode mode) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 622 | { |
| 623 | struct acpi_thermal *tz = thermal->devdata; |
| 624 | int enable; |
| 625 | |
| 626 | if (!tz) |
| 627 | return -EINVAL; |
| 628 | |
| 629 | /* |
| 630 | * enable/disable thermal management from ACPI thermal driver |
| 631 | */ |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 632 | if (mode == THERMAL_DEVICE_ENABLED) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 633 | enable = 1; |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 634 | else if (mode == THERMAL_DEVICE_DISABLED) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 635 | enable = 0; |
| 636 | else |
| 637 | return -EINVAL; |
| 638 | |
| 639 | if (enable != tz->tz_enabled) { |
| 640 | tz->tz_enabled = enable; |
| 641 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 642 | "%s ACPI thermal control\n", |
| 643 | tz->tz_enabled ? enabled : disabled)); |
| 644 | acpi_thermal_check(tz); |
| 645 | } |
| 646 | return 0; |
| 647 | } |
| 648 | |
| 649 | static int thermal_get_trip_type(struct thermal_zone_device *thermal, |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 650 | int trip, enum thermal_trip_type *type) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 651 | { |
| 652 | struct acpi_thermal *tz = thermal->devdata; |
| 653 | int i; |
| 654 | |
| 655 | if (!tz || trip < 0) |
| 656 | return -EINVAL; |
| 657 | |
| 658 | if (tz->trips.critical.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 659 | if (!trip) { |
| 660 | *type = THERMAL_TRIP_CRITICAL; |
| 661 | return 0; |
| 662 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 663 | trip--; |
| 664 | } |
| 665 | |
| 666 | if (tz->trips.hot.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 667 | if (!trip) { |
| 668 | *type = THERMAL_TRIP_HOT; |
| 669 | return 0; |
| 670 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 671 | trip--; |
| 672 | } |
| 673 | |
| 674 | if (tz->trips.passive.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 675 | if (!trip) { |
| 676 | *type = THERMAL_TRIP_PASSIVE; |
| 677 | return 0; |
| 678 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 679 | trip--; |
| 680 | } |
| 681 | |
| 682 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && |
| 683 | tz->trips.active[i].flags.valid; i++) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 684 | if (!trip) { |
| 685 | *type = THERMAL_TRIP_ACTIVE; |
| 686 | return 0; |
| 687 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 688 | trip--; |
| 689 | } |
| 690 | |
| 691 | return -EINVAL; |
| 692 | } |
| 693 | |
| 694 | static int thermal_get_trip_temp(struct thermal_zone_device *thermal, |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 695 | int trip, unsigned long *temp) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 696 | { |
| 697 | struct acpi_thermal *tz = thermal->devdata; |
| 698 | int i; |
| 699 | |
| 700 | if (!tz || trip < 0) |
| 701 | return -EINVAL; |
| 702 | |
| 703 | if (tz->trips.critical.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 704 | if (!trip) { |
| 705 | *temp = KELVIN_TO_MILLICELSIUS( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame^] | 706 | tz->trips.critical.temperature, |
| 707 | tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 708 | return 0; |
| 709 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 710 | trip--; |
| 711 | } |
| 712 | |
| 713 | if (tz->trips.hot.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 714 | if (!trip) { |
| 715 | *temp = KELVIN_TO_MILLICELSIUS( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame^] | 716 | tz->trips.hot.temperature, |
| 717 | tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 718 | return 0; |
| 719 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 720 | trip--; |
| 721 | } |
| 722 | |
| 723 | if (tz->trips.passive.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 724 | if (!trip) { |
| 725 | *temp = KELVIN_TO_MILLICELSIUS( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame^] | 726 | tz->trips.passive.temperature, |
| 727 | tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 728 | return 0; |
| 729 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 730 | trip--; |
| 731 | } |
| 732 | |
| 733 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && |
| 734 | tz->trips.active[i].flags.valid; i++) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 735 | if (!trip) { |
| 736 | *temp = KELVIN_TO_MILLICELSIUS( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame^] | 737 | tz->trips.active[i].temperature, |
| 738 | tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 739 | return 0; |
| 740 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 741 | trip--; |
| 742 | } |
| 743 | |
| 744 | return -EINVAL; |
| 745 | } |
| 746 | |
Zhang, Rui | 9ec732f | 2008-04-10 16:13:10 +0800 | [diff] [blame] | 747 | static int thermal_get_crit_temp(struct thermal_zone_device *thermal, |
| 748 | unsigned long *temperature) { |
| 749 | struct acpi_thermal *tz = thermal->devdata; |
| 750 | |
| 751 | if (tz->trips.critical.flags.valid) { |
| 752 | *temperature = KELVIN_TO_MILLICELSIUS( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame^] | 753 | tz->trips.critical.temperature, |
| 754 | tz->kelvin_offset); |
Zhang, Rui | 9ec732f | 2008-04-10 16:13:10 +0800 | [diff] [blame] | 755 | return 0; |
| 756 | } else |
| 757 | return -EINVAL; |
| 758 | } |
| 759 | |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 760 | static int thermal_notify(struct thermal_zone_device *thermal, int trip, |
| 761 | enum thermal_trip_type trip_type) |
| 762 | { |
| 763 | u8 type = 0; |
| 764 | struct acpi_thermal *tz = thermal->devdata; |
| 765 | |
| 766 | if (trip_type == THERMAL_TRIP_CRITICAL) |
| 767 | type = ACPI_THERMAL_NOTIFY_CRITICAL; |
| 768 | else if (trip_type == THERMAL_TRIP_HOT) |
| 769 | type = ACPI_THERMAL_NOTIFY_HOT; |
| 770 | else |
| 771 | return 0; |
| 772 | |
| 773 | acpi_bus_generate_proc_event(tz->device, type, 1); |
| 774 | acpi_bus_generate_netlink_event(tz->device->pnp.device_class, |
Stephen Rothwell | f6f5c45 | 2009-03-03 12:47:17 +1100 | [diff] [blame] | 775 | dev_name(&tz->device->dev), type, 1); |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 776 | |
| 777 | if (trip_type == THERMAL_TRIP_CRITICAL && nocrt) |
| 778 | return 1; |
| 779 | |
| 780 | return 0; |
| 781 | } |
| 782 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 783 | typedef int (*cb)(struct thermal_zone_device *, int, |
| 784 | struct thermal_cooling_device *); |
| 785 | static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal, |
| 786 | struct thermal_cooling_device *cdev, |
| 787 | cb action) |
| 788 | { |
| 789 | struct acpi_device *device = cdev->devdata; |
| 790 | struct acpi_thermal *tz = thermal->devdata; |
Zhang Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 791 | struct acpi_device *dev; |
| 792 | acpi_status status; |
| 793 | acpi_handle handle; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 794 | int i; |
| 795 | int j; |
| 796 | int trip = -1; |
| 797 | int result = 0; |
| 798 | |
| 799 | if (tz->trips.critical.flags.valid) |
| 800 | trip++; |
| 801 | |
| 802 | if (tz->trips.hot.flags.valid) |
| 803 | trip++; |
| 804 | |
| 805 | if (tz->trips.passive.flags.valid) { |
| 806 | trip++; |
| 807 | for (i = 0; i < tz->trips.passive.devices.count; |
| 808 | i++) { |
Zhang Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 809 | handle = tz->trips.passive.devices.handles[i]; |
| 810 | status = acpi_bus_get_device(handle, &dev); |
| 811 | if (ACPI_SUCCESS(status) && (dev == device)) { |
| 812 | result = action(thermal, trip, cdev); |
| 813 | if (result) |
| 814 | goto failed; |
| 815 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 816 | } |
| 817 | } |
| 818 | |
| 819 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
| 820 | if (!tz->trips.active[i].flags.valid) |
| 821 | break; |
| 822 | trip++; |
| 823 | for (j = 0; |
| 824 | j < tz->trips.active[i].devices.count; |
| 825 | j++) { |
Zhang Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 826 | handle = tz->trips.active[i].devices.handles[j]; |
| 827 | status = acpi_bus_get_device(handle, &dev); |
| 828 | if (ACPI_SUCCESS(status) && (dev == device)) { |
| 829 | result = action(thermal, trip, cdev); |
| 830 | if (result) |
| 831 | goto failed; |
| 832 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 833 | } |
| 834 | } |
| 835 | |
| 836 | for (i = 0; i < tz->devices.count; i++) { |
Zhang Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 837 | handle = tz->devices.handles[i]; |
| 838 | status = acpi_bus_get_device(handle, &dev); |
| 839 | if (ACPI_SUCCESS(status) && (dev == device)) { |
| 840 | result = action(thermal, -1, cdev); |
| 841 | if (result) |
| 842 | goto failed; |
| 843 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | failed: |
| 847 | return result; |
| 848 | } |
| 849 | |
| 850 | static int |
| 851 | acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal, |
| 852 | struct thermal_cooling_device *cdev) |
| 853 | { |
| 854 | return acpi_thermal_cooling_device_cb(thermal, cdev, |
| 855 | thermal_zone_bind_cooling_device); |
| 856 | } |
| 857 | |
| 858 | static int |
| 859 | acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal, |
| 860 | struct thermal_cooling_device *cdev) |
| 861 | { |
| 862 | return acpi_thermal_cooling_device_cb(thermal, cdev, |
| 863 | thermal_zone_unbind_cooling_device); |
| 864 | } |
| 865 | |
| 866 | static struct thermal_zone_device_ops acpi_thermal_zone_ops = { |
| 867 | .bind = acpi_thermal_bind_cooling_device, |
| 868 | .unbind = acpi_thermal_unbind_cooling_device, |
| 869 | .get_temp = thermal_get_temp, |
| 870 | .get_mode = thermal_get_mode, |
| 871 | .set_mode = thermal_set_mode, |
| 872 | .get_trip_type = thermal_get_trip_type, |
| 873 | .get_trip_temp = thermal_get_trip_temp, |
Zhang, Rui | 9ec732f | 2008-04-10 16:13:10 +0800 | [diff] [blame] | 874 | .get_crit_temp = thermal_get_crit_temp, |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 875 | .notify = thermal_notify, |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 876 | }; |
| 877 | |
| 878 | static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) |
| 879 | { |
| 880 | int trips = 0; |
| 881 | int result; |
Zhang Rui | 2073393 | 2008-01-17 15:51:21 +0800 | [diff] [blame] | 882 | acpi_status status; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 883 | int i; |
| 884 | |
| 885 | if (tz->trips.critical.flags.valid) |
| 886 | trips++; |
| 887 | |
| 888 | if (tz->trips.hot.flags.valid) |
| 889 | trips++; |
| 890 | |
| 891 | if (tz->trips.passive.flags.valid) |
| 892 | trips++; |
| 893 | |
| 894 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && |
| 895 | tz->trips.active[i].flags.valid; i++, trips++); |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 896 | |
| 897 | if (tz->trips.passive.flags.valid) |
| 898 | tz->thermal_zone = |
| 899 | thermal_zone_device_register("acpitz", trips, tz, |
| 900 | &acpi_thermal_zone_ops, |
| 901 | tz->trips.passive.tc1, |
| 902 | tz->trips.passive.tc2, |
| 903 | tz->trips.passive.tsp*100, |
| 904 | tz->polling_frequency*100); |
| 905 | else |
| 906 | tz->thermal_zone = |
| 907 | thermal_zone_device_register("acpitz", trips, tz, |
| 908 | &acpi_thermal_zone_ops, |
| 909 | 0, 0, 0, |
| 910 | tz->polling_frequency); |
Krzysztof Helt | bb070e4 | 2008-04-08 17:41:52 -0700 | [diff] [blame] | 911 | if (IS_ERR(tz->thermal_zone)) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 912 | return -ENODEV; |
| 913 | |
| 914 | result = sysfs_create_link(&tz->device->dev.kobj, |
| 915 | &tz->thermal_zone->device.kobj, "thermal_zone"); |
| 916 | if (result) |
| 917 | return result; |
| 918 | |
| 919 | result = sysfs_create_link(&tz->thermal_zone->device.kobj, |
| 920 | &tz->device->dev.kobj, "device"); |
| 921 | if (result) |
| 922 | return result; |
| 923 | |
Zhang Rui | 2073393 | 2008-01-17 15:51:21 +0800 | [diff] [blame] | 924 | status = acpi_attach_data(tz->device->handle, |
| 925 | acpi_bus_private_data_handler, |
| 926 | tz->thermal_zone); |
| 927 | if (ACPI_FAILURE(status)) { |
Lin Ming | 55ac9a0 | 2008-09-28 14:51:56 +0800 | [diff] [blame] | 928 | printk(KERN_ERR PREFIX |
| 929 | "Error attaching device data\n"); |
Zhang Rui | 2073393 | 2008-01-17 15:51:21 +0800 | [diff] [blame] | 930 | return -ENODEV; |
| 931 | } |
| 932 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 933 | tz->tz_enabled = 1; |
| 934 | |
Greg Kroah-Hartman | fc3a882 | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 935 | dev_info(&tz->device->dev, "registered as thermal_zone%d\n", |
| 936 | tz->thermal_zone->id); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 937 | return 0; |
| 938 | } |
| 939 | |
| 940 | static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz) |
| 941 | { |
| 942 | sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); |
| 943 | sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); |
| 944 | thermal_zone_device_unregister(tz->thermal_zone); |
| 945 | tz->thermal_zone = NULL; |
Zhang Rui | 2073393 | 2008-01-17 15:51:21 +0800 | [diff] [blame] | 946 | acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | /* -------------------------------------------------------------------------- |
| 951 | FS Interface (/proc) |
| 952 | -------------------------------------------------------------------------- */ |
| 953 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 954 | static struct proc_dir_entry *acpi_thermal_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | |
| 956 | static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset) |
| 957 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 958 | struct acpi_thermal *tz = seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | |
| 961 | if (!tz) |
| 962 | goto end; |
| 963 | |
| 964 | seq_puts(seq, "state: "); |
| 965 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 966 | if (!tz->state.critical && !tz->state.hot && !tz->state.passive |
| 967 | && !tz->state.active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | seq_puts(seq, "ok\n"); |
| 969 | else { |
| 970 | if (tz->state.critical) |
| 971 | seq_puts(seq, "critical "); |
| 972 | if (tz->state.hot) |
| 973 | seq_puts(seq, "hot "); |
| 974 | if (tz->state.passive) |
| 975 | seq_puts(seq, "passive "); |
| 976 | if (tz->state.active) |
| 977 | seq_printf(seq, "active[%d]", tz->state.active_index); |
| 978 | seq_puts(seq, "\n"); |
| 979 | } |
| 980 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 981 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 982 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file) |
| 986 | { |
| 987 | return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data); |
| 988 | } |
| 989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset) |
| 991 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 992 | int result = 0; |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 993 | struct acpi_thermal *tz = seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | |
| 996 | if (!tz) |
| 997 | goto end; |
| 998 | |
| 999 | result = acpi_thermal_get_temperature(tz); |
| 1000 | if (result) |
| 1001 | goto end; |
| 1002 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1003 | seq_printf(seq, "temperature: %ld C\n", |
| 1004 | KELVIN_TO_CELSIUS(tz->temperature)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1006 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1007 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file) |
| 1011 | { |
| 1012 | return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data); |
| 1013 | } |
| 1014 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | static int acpi_thermal_trip_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; |
Thomas Renninger | 68ccfaa | 2006-11-19 23:01:40 +0100 | [diff] [blame] | 1018 | struct acpi_device *device; |
Thomas Renninger | e7c746e | 2007-06-18 00:40:51 -0400 | [diff] [blame] | 1019 | acpi_status status; |
| 1020 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1021 | int i = 0; |
| 1022 | int j = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | |
| 1025 | if (!tz) |
| 1026 | goto end; |
| 1027 | |
| 1028 | if (tz->trips.critical.flags.valid) |
Len Brown | f548714 | 2007-08-12 00:12:44 -0400 | [diff] [blame] | 1029 | seq_printf(seq, "critical (S5): %ld C%s", |
| 1030 | KELVIN_TO_CELSIUS(tz->trips.critical.temperature), |
| 1031 | nocrt ? " <disabled>\n" : "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | |
| 1033 | if (tz->trips.hot.flags.valid) |
Len Brown | f548714 | 2007-08-12 00:12:44 -0400 | [diff] [blame] | 1034 | seq_printf(seq, "hot (S4): %ld C%s", |
| 1035 | KELVIN_TO_CELSIUS(tz->trips.hot.temperature), |
| 1036 | nocrt ? " <disabled>\n" : "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
| 1038 | if (tz->trips.passive.flags.valid) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1039 | seq_printf(seq, |
| 1040 | "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=", |
| 1041 | KELVIN_TO_CELSIUS(tz->trips.passive.temperature), |
| 1042 | tz->trips.passive.tc1, tz->trips.passive.tc2, |
| 1043 | tz->trips.passive.tsp); |
| 1044 | for (j = 0; j < tz->trips.passive.devices.count; j++) { |
Thomas Renninger | e7c746e | 2007-06-18 00:40:51 -0400 | [diff] [blame] | 1045 | status = acpi_bus_get_device(tz->trips.passive.devices. |
| 1046 | handles[j], &device); |
| 1047 | seq_printf(seq, "%4.4s ", status ? "" : |
| 1048 | acpi_device_bid(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | } |
| 1050 | seq_puts(seq, "\n"); |
| 1051 | } |
| 1052 | |
| 1053 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
| 1054 | if (!(tz->trips.active[i].flags.valid)) |
| 1055 | break; |
| 1056 | seq_printf(seq, "active[%d]: %ld C: devices=", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1057 | i, |
| 1058 | KELVIN_TO_CELSIUS(tz->trips.active[i].temperature)); |
Thomas Renninger | 68ccfaa | 2006-11-19 23:01:40 +0100 | [diff] [blame] | 1059 | for (j = 0; j < tz->trips.active[i].devices.count; j++){ |
Thomas Renninger | e7c746e | 2007-06-18 00:40:51 -0400 | [diff] [blame] | 1060 | status = acpi_bus_get_device(tz->trips.active[i]. |
| 1061 | devices.handles[j], |
| 1062 | &device); |
| 1063 | seq_printf(seq, "%4.4s ", status ? "" : |
| 1064 | acpi_device_bid(device)); |
Thomas Renninger | 68ccfaa | 2006-11-19 23:01:40 +0100 | [diff] [blame] | 1065 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | seq_puts(seq, "\n"); |
| 1067 | } |
| 1068 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1069 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1070 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file) |
| 1074 | { |
| 1075 | return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data); |
| 1076 | } |
| 1077 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset) |
| 1079 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1080 | struct acpi_thermal *tz = seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | |
| 1083 | if (!tz) |
| 1084 | goto end; |
| 1085 | |
Len Brown | eaca2d3 | 2007-04-30 23:27:43 -0400 | [diff] [blame] | 1086 | if (!tz->flags.cooling_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | seq_puts(seq, "<setting not supported>\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | else |
Len Brown | eaca2d3 | 2007-04-30 23:27:43 -0400 | [diff] [blame] | 1089 | seq_puts(seq, "0 - Active; 1 - Passive\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1091 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1092 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file) |
| 1096 | { |
| 1097 | return single_open(file, acpi_thermal_cooling_seq_show, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1098 | PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1102 | acpi_thermal_write_cooling_mode(struct file *file, |
| 1103 | const char __user * buffer, |
| 1104 | size_t count, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1106 | struct seq_file *m = file->private_data; |
| 1107 | struct acpi_thermal *tz = m->private; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1108 | int result = 0; |
| 1109 | char mode_string[12] = { '\0' }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | |
| 1112 | if (!tz || (count > sizeof(mode_string) - 1)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1113 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | |
| 1115 | if (!tz->flags.cooling_mode) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1116 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | |
| 1118 | if (copy_from_user(mode_string, buffer, count)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1119 | return -EFAULT; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | mode_string[count] = '\0'; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1122 | |
| 1123 | result = acpi_thermal_set_cooling_mode(tz, |
| 1124 | simple_strtoul(mode_string, NULL, |
| 1125 | 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1127 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | |
| 1129 | acpi_thermal_check(tz); |
| 1130 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1131 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset) |
| 1135 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1136 | struct acpi_thermal *tz = seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | |
| 1139 | if (!tz) |
| 1140 | goto end; |
| 1141 | |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 1142 | if (!tz->thermal_zone->polling_delay) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | seq_puts(seq, "<polling disabled>\n"); |
| 1144 | goto end; |
| 1145 | } |
| 1146 | |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 1147 | seq_printf(seq, "polling frequency: %d seconds\n", |
| 1148 | (tz->thermal_zone->polling_delay / 1000)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1150 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1151 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file) |
| 1155 | { |
| 1156 | return single_open(file, acpi_thermal_polling_seq_show, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1157 | PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1161 | acpi_thermal_write_polling(struct file *file, |
| 1162 | const char __user * buffer, |
| 1163 | size_t count, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1165 | struct seq_file *m = file->private_data; |
| 1166 | struct acpi_thermal *tz = m->private; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1167 | int result = 0; |
| 1168 | char polling_string[12] = { '\0' }; |
| 1169 | int seconds = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | |
| 1172 | if (!tz || (count > sizeof(polling_string) - 1)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1173 | return -EINVAL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | if (copy_from_user(polling_string, buffer, count)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1176 | return -EFAULT; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | polling_string[count] = '\0'; |
| 1179 | |
| 1180 | seconds = simple_strtoul(polling_string, NULL, 0); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | result = acpi_thermal_set_polling(tz, seconds); |
| 1183 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1184 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | |
| 1186 | acpi_thermal_check(tz); |
| 1187 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1188 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | } |
| 1190 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1191 | static int acpi_thermal_add_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1193 | struct proc_dir_entry *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | |
| 1196 | if (!acpi_device_dir(device)) { |
| 1197 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1198 | acpi_thermal_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | if (!acpi_device_dir(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1200 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | /* 'state' [R] */ |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1204 | entry = proc_create_data(ACPI_THERMAL_FILE_STATE, |
| 1205 | S_IRUGO, acpi_device_dir(device), |
| 1206 | &acpi_thermal_state_fops, |
| 1207 | acpi_driver_data(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | if (!entry) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1209 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | |
| 1211 | /* 'temperature' [R] */ |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1212 | entry = proc_create_data(ACPI_THERMAL_FILE_TEMPERATURE, |
| 1213 | S_IRUGO, acpi_device_dir(device), |
| 1214 | &acpi_thermal_temp_fops, |
| 1215 | acpi_driver_data(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | if (!entry) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1217 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | |
Pavel Machek | 2db9ccb | 2007-08-24 11:45:50 +0200 | [diff] [blame] | 1219 | /* 'trip_points' [R] */ |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1220 | entry = proc_create_data(ACPI_THERMAL_FILE_TRIP_POINTS, |
| 1221 | S_IRUGO, |
| 1222 | acpi_device_dir(device), |
| 1223 | &acpi_thermal_trip_fops, |
| 1224 | acpi_driver_data(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | if (!entry) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1226 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | |
| 1228 | /* 'cooling_mode' [R/W] */ |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1229 | entry = proc_create_data(ACPI_THERMAL_FILE_COOLING_MODE, |
| 1230 | S_IFREG | S_IRUGO | S_IWUSR, |
| 1231 | acpi_device_dir(device), |
| 1232 | &acpi_thermal_cooling_fops, |
| 1233 | acpi_driver_data(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | if (!entry) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1235 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | |
| 1237 | /* 'polling_frequency' [R/W] */ |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1238 | entry = proc_create_data(ACPI_THERMAL_FILE_POLLING_FREQ, |
| 1239 | S_IFREG | S_IRUGO | S_IWUSR, |
| 1240 | acpi_device_dir(device), |
| 1241 | &acpi_thermal_polling_fops, |
| 1242 | acpi_driver_data(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | if (!entry) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1244 | return -ENODEV; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1245 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1248 | static int acpi_thermal_remove_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | |
| 1251 | if (acpi_device_dir(device)) { |
| 1252 | remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ, |
| 1253 | acpi_device_dir(device)); |
| 1254 | remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE, |
| 1255 | acpi_device_dir(device)); |
| 1256 | remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS, |
| 1257 | acpi_device_dir(device)); |
| 1258 | remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE, |
| 1259 | acpi_device_dir(device)); |
| 1260 | remove_proc_entry(ACPI_THERMAL_FILE_STATE, |
| 1261 | acpi_device_dir(device)); |
| 1262 | remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir); |
| 1263 | acpi_device_dir(device) = NULL; |
| 1264 | } |
| 1265 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1266 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | } |
| 1268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | /* -------------------------------------------------------------------------- |
| 1270 | Driver Interface |
| 1271 | -------------------------------------------------------------------------- */ |
| 1272 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1273 | static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1275 | struct acpi_thermal *tz = data; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1276 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | |
| 1279 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1280 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | |
Patrick Mochel | 8348e1b | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 1282 | device = tz->device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | |
| 1284 | switch (event) { |
| 1285 | case ACPI_THERMAL_NOTIFY_TEMPERATURE: |
| 1286 | acpi_thermal_check(tz); |
| 1287 | break; |
| 1288 | case ACPI_THERMAL_NOTIFY_THRESHOLDS: |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 1289 | acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | acpi_thermal_check(tz); |
Len Brown | 14e04fb3 | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 1291 | acpi_bus_generate_proc_event(device, event, 0); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 1292 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
Kay Sievers | 0794469 | 2008-10-30 01:18:59 +0100 | [diff] [blame] | 1293 | dev_name(&device->dev), event, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | break; |
| 1295 | case ACPI_THERMAL_NOTIFY_DEVICES: |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 1296 | acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES); |
| 1297 | acpi_thermal_check(tz); |
Len Brown | 14e04fb3 | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 1298 | acpi_bus_generate_proc_event(device, event, 0); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 1299 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
Kay Sievers | 0794469 | 2008-10-30 01:18:59 +0100 | [diff] [blame] | 1300 | dev_name(&device->dev), event, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | break; |
| 1302 | default: |
| 1303 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1304 | "Unsupported event [0x%x]\n", event)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | break; |
| 1306 | } |
| 1307 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1308 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | } |
| 1310 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1311 | static int acpi_thermal_get_info(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1313 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | |
| 1316 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1317 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | |
| 1319 | /* Get temperature [_TMP] (required) */ |
| 1320 | result = acpi_thermal_get_temperature(tz); |
| 1321 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1322 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | |
| 1324 | /* Get trip points [_CRT, _PSV, etc.] (required) */ |
| 1325 | result = acpi_thermal_get_trip_points(tz); |
| 1326 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1327 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | |
| 1329 | /* Set the cooling mode [_SCP] to active cooling (default) */ |
| 1330 | result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1331 | if (!result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | tz->flags.cooling_mode = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | |
| 1334 | /* Get default polling frequency [_TZP] (optional) */ |
| 1335 | if (tzp) |
| 1336 | tz->polling_frequency = tzp; |
| 1337 | else |
| 1338 | acpi_thermal_get_polling_frequency(tz); |
| 1339 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1340 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | } |
| 1342 | |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame^] | 1343 | /* |
| 1344 | * The exact offset between Kelvin and degree Celsius is 273.15. However ACPI |
| 1345 | * handles temperature values with a single decimal place. As a consequence, |
| 1346 | * some implementations use an offset of 273.1 and others use an offset of |
| 1347 | * 273.2. Try to find out which one is being used, to present the most |
| 1348 | * accurate and visually appealing number. |
| 1349 | * |
| 1350 | * The heuristic below should work for all ACPI thermal zones which have a |
| 1351 | * critical trip point with a value being a multiple of 0.5 degree Celsius. |
| 1352 | */ |
| 1353 | static void acpi_thermal_guess_offset(struct acpi_thermal *tz) |
| 1354 | { |
| 1355 | if (tz->trips.critical.flags.valid && |
| 1356 | (tz->trips.critical.temperature % 5) == 1) |
| 1357 | tz->kelvin_offset = 2731; |
| 1358 | else |
| 1359 | tz->kelvin_offset = 2732; |
| 1360 | } |
| 1361 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1362 | static int acpi_thermal_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1364 | int result = 0; |
| 1365 | acpi_status status = AE_OK; |
| 1366 | struct acpi_thermal *tz = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | |
| 1369 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1370 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 1372 | tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1374 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | |
Patrick Mochel | 8348e1b | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 1376 | tz->device = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | strcpy(tz->name, device->pnp.bus_id); |
| 1378 | strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME); |
| 1379 | strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS); |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 1380 | device->driver_data = tz; |
Alexey Starikovskiy | 6e21578 | 2007-09-01 00:11:59 +0400 | [diff] [blame] | 1381 | mutex_init(&tz->lock); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1382 | |
| 1383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | result = acpi_thermal_get_info(tz); |
| 1385 | if (result) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1386 | goto free_memory; |
| 1387 | |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame^] | 1388 | acpi_thermal_guess_offset(tz); |
| 1389 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1390 | result = acpi_thermal_register_thermal_zone(tz); |
| 1391 | if (result) |
| 1392 | goto free_memory; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | |
| 1394 | result = acpi_thermal_add_fs(device); |
| 1395 | if (result) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1396 | goto unregister_thermal_zone; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | |
Patrick Mochel | 38ba7c9 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 1398 | status = acpi_install_notify_handler(device->handle, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1399 | ACPI_DEVICE_NOTIFY, |
| 1400 | acpi_thermal_notify, tz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | result = -ENODEV; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1403 | goto remove_fs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1407 | acpi_device_name(device), acpi_device_bid(device), |
| 1408 | KELVIN_TO_CELSIUS(tz->temperature)); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1409 | goto end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1411 | remove_fs: |
| 1412 | acpi_thermal_remove_fs(device); |
| 1413 | unregister_thermal_zone: |
| 1414 | thermal_zone_device_unregister(tz->thermal_zone); |
| 1415 | free_memory: |
| 1416 | kfree(tz); |
| 1417 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1418 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | } |
| 1420 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1421 | static int acpi_thermal_remove(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1423 | acpi_status status = AE_OK; |
| 1424 | struct acpi_thermal *tz = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | if (!device || !acpi_driver_data(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1427 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1429 | tz = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | |
Patrick Mochel | 38ba7c9 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 1431 | status = acpi_remove_notify_handler(device->handle, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1432 | ACPI_DEVICE_NOTIFY, |
| 1433 | acpi_thermal_notify); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | acpi_thermal_remove_fs(device); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1436 | acpi_thermal_unregister_thermal_zone(tz); |
Alexey Starikovskiy | 6e21578 | 2007-09-01 00:11:59 +0400 | [diff] [blame] | 1437 | mutex_destroy(&tz->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | kfree(tz); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1439 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
Patrick Mochel | 5d9464a | 2006-12-07 20:56:27 +0800 | [diff] [blame] | 1442 | static int acpi_thermal_resume(struct acpi_device *device) |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1443 | { |
| 1444 | struct acpi_thermal *tz = NULL; |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1445 | int i, j, power_state, result; |
| 1446 | |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1447 | |
| 1448 | if (!device || !acpi_driver_data(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1449 | return -EINVAL; |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1450 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1451 | tz = acpi_driver_data(device); |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1452 | |
Konstantin Karasyov | bed936f | 2006-07-10 04:44:26 -0700 | [diff] [blame] | 1453 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1454 | if (!(&tz->trips.active[i])) |
| 1455 | break; |
| 1456 | if (!tz->trips.active[i].flags.valid) |
| 1457 | break; |
| 1458 | tz->trips.active[i].flags.enabled = 1; |
| 1459 | for (j = 0; j < tz->trips.active[i].devices.count; j++) { |
| 1460 | result = acpi_bus_get_power(tz->trips.active[i].devices. |
| 1461 | handles[j], &power_state); |
| 1462 | if (result || (power_state != ACPI_STATE_D0)) { |
| 1463 | tz->trips.active[i].flags.enabled = 0; |
| 1464 | break; |
| 1465 | } |
Konstantin Karasyov | bed936f | 2006-07-10 04:44:26 -0700 | [diff] [blame] | 1466 | } |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1467 | tz->state.active |= tz->trips.active[i].flags.enabled; |
Konstantin Karasyov | bed936f | 2006-07-10 04:44:26 -0700 | [diff] [blame] | 1468 | } |
| 1469 | |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1470 | acpi_thermal_check(tz); |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1471 | |
| 1472 | return AE_OK; |
| 1473 | } |
| 1474 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 1475 | static int thermal_act(const struct dmi_system_id *d) { |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1476 | |
| 1477 | if (act == 0) { |
| 1478 | printk(KERN_NOTICE "ACPI: %s detected: " |
| 1479 | "disabling all active thermal trip points\n", d->ident); |
| 1480 | act = -1; |
| 1481 | } |
| 1482 | return 0; |
| 1483 | } |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 1484 | static int thermal_nocrt(const struct dmi_system_id *d) { |
Len Brown | 8c99fdc | 2007-08-20 18:46:50 -0400 | [diff] [blame] | 1485 | |
| 1486 | printk(KERN_NOTICE "ACPI: %s detected: " |
| 1487 | "disabling all critical thermal trip point actions.\n", d->ident); |
| 1488 | nocrt = 1; |
| 1489 | return 0; |
| 1490 | } |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 1491 | static int thermal_tzp(const struct dmi_system_id *d) { |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1492 | |
| 1493 | if (tzp == 0) { |
| 1494 | printk(KERN_NOTICE "ACPI: %s detected: " |
| 1495 | "enabling thermal zone polling\n", d->ident); |
| 1496 | tzp = 300; /* 300 dS = 30 Seconds */ |
| 1497 | } |
| 1498 | return 0; |
| 1499 | } |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 1500 | static int thermal_psv(const struct dmi_system_id *d) { |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1501 | |
| 1502 | if (psv == 0) { |
| 1503 | printk(KERN_NOTICE "ACPI: %s detected: " |
| 1504 | "disabling all passive thermal trip points\n", d->ident); |
| 1505 | psv = -1; |
| 1506 | } |
| 1507 | return 0; |
| 1508 | } |
| 1509 | |
| 1510 | static struct dmi_system_id thermal_dmi_table[] __initdata = { |
| 1511 | /* |
| 1512 | * Award BIOS on this AOpen makes thermal control almost worthless. |
| 1513 | * http://bugzilla.kernel.org/show_bug.cgi?id=8842 |
| 1514 | */ |
| 1515 | { |
| 1516 | .callback = thermal_act, |
| 1517 | .ident = "AOpen i915GMm-HFS", |
| 1518 | .matches = { |
| 1519 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), |
| 1520 | DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), |
| 1521 | }, |
| 1522 | }, |
| 1523 | { |
| 1524 | .callback = thermal_psv, |
| 1525 | .ident = "AOpen i915GMm-HFS", |
| 1526 | .matches = { |
| 1527 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), |
| 1528 | DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), |
| 1529 | }, |
| 1530 | }, |
| 1531 | { |
| 1532 | .callback = thermal_tzp, |
| 1533 | .ident = "AOpen i915GMm-HFS", |
| 1534 | .matches = { |
| 1535 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), |
| 1536 | DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), |
| 1537 | }, |
| 1538 | }, |
Len Brown | 8c99fdc | 2007-08-20 18:46:50 -0400 | [diff] [blame] | 1539 | { |
| 1540 | .callback = thermal_nocrt, |
| 1541 | .ident = "Gigabyte GA-7ZX", |
| 1542 | .matches = { |
| 1543 | DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."), |
| 1544 | DMI_MATCH(DMI_BOARD_NAME, "7ZX"), |
| 1545 | }, |
| 1546 | }, |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1547 | {} |
| 1548 | }; |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1549 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1550 | static int __init acpi_thermal_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1552 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1554 | dmi_check_system(thermal_dmi_table); |
| 1555 | |
Len Brown | 72b33ef | 2007-08-12 00:12:17 -0400 | [diff] [blame] | 1556 | if (off) { |
| 1557 | printk(KERN_NOTICE "ACPI: thermal control disabled\n"); |
| 1558 | return -ENODEV; |
| 1559 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir); |
| 1561 | if (!acpi_thermal_dir) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1562 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | |
| 1564 | result = acpi_bus_register_driver(&acpi_thermal_driver); |
| 1565 | if (result < 0) { |
| 1566 | remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1567 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | } |
| 1569 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1570 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1573 | static void __exit acpi_thermal_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | |
| 1576 | acpi_bus_unregister_driver(&acpi_thermal_driver); |
| 1577 | |
| 1578 | remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir); |
| 1579 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1580 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 | } |
| 1582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | module_init(acpi_thermal_init); |
| 1584 | module_exit(acpi_thermal_exit); |