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