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