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