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