| 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> | 
 | 36 | #include <linux/init.h> | 
 | 37 | #include <linux/types.h> | 
 | 38 | #include <linux/proc_fs.h> | 
| Tim Schmielau | cd354f1 | 2007-02-14 00:33:14 -0800 | [diff] [blame] | 39 | #include <linux/timer.h> | 
 | 40 | #include <linux/jiffies.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/kmod.h> | 
 | 42 | #include <linux/seq_file.h> | 
 | 43 | #include <asm/uaccess.h> | 
 | 44 |  | 
 | 45 | #include <acpi/acpi_bus.h> | 
 | 46 | #include <acpi/acpi_drivers.h> | 
 | 47 |  | 
 | 48 | #define ACPI_THERMAL_COMPONENT		0x04000000 | 
 | 49 | #define ACPI_THERMAL_CLASS		"thermal_zone" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #define ACPI_THERMAL_DEVICE_NAME	"Thermal Zone" | 
 | 51 | #define ACPI_THERMAL_FILE_STATE		"state" | 
 | 52 | #define ACPI_THERMAL_FILE_TEMPERATURE	"temperature" | 
 | 53 | #define ACPI_THERMAL_FILE_TRIP_POINTS	"trip_points" | 
 | 54 | #define ACPI_THERMAL_FILE_COOLING_MODE	"cooling_mode" | 
 | 55 | #define ACPI_THERMAL_FILE_POLLING_FREQ	"polling_frequency" | 
 | 56 | #define ACPI_THERMAL_NOTIFY_TEMPERATURE	0x80 | 
 | 57 | #define ACPI_THERMAL_NOTIFY_THRESHOLDS	0x81 | 
 | 58 | #define ACPI_THERMAL_NOTIFY_DEVICES	0x82 | 
 | 59 | #define ACPI_THERMAL_NOTIFY_CRITICAL	0xF0 | 
 | 60 | #define ACPI_THERMAL_NOTIFY_HOT		0xF1 | 
 | 61 | #define ACPI_THERMAL_MODE_ACTIVE	0x00 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #define ACPI_THERMAL_PATH_POWEROFF	"/sbin/poweroff" | 
 | 63 |  | 
 | 64 | #define ACPI_THERMAL_MAX_ACTIVE	10 | 
 | 65 | #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65 | 
 | 66 |  | 
 | 67 | #define KELVIN_TO_CELSIUS(t)    (long)(((long)t-2732>=0) ? ((long)t-2732+5)/10 : ((long)t-2732-5)/10) | 
 | 68 | #define CELSIUS_TO_KELVIN(t)	((t+273)*10) | 
 | 69 |  | 
 | 70 | #define _COMPONENT		ACPI_THERMAL_COMPONENT | 
| Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 71 | ACPI_MODULE_NAME("thermal"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 |  | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 73 | MODULE_AUTHOR("Paul Diefenbaugh"); | 
| Len Brown | 7cda93e | 2007-02-12 23:50:02 -0500 | [diff] [blame] | 74 | MODULE_DESCRIPTION("ACPI Thermal Zone Driver"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | MODULE_LICENSE("GPL"); | 
 | 76 |  | 
 | 77 | static int tzp; | 
 | 78 | module_param(tzp, int, 0); | 
 | 79 | MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.\n"); | 
 | 80 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 81 | static int acpi_thermal_add(struct acpi_device *device); | 
 | 82 | static int acpi_thermal_remove(struct acpi_device *device, int type); | 
| Patrick Mochel | 5d9464a | 2006-12-07 20:56:27 +0800 | [diff] [blame] | 83 | static int acpi_thermal_resume(struct acpi_device *device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file); | 
 | 85 | static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file); | 
 | 86 | 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] | 87 | 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] | 88 | static ssize_t acpi_thermal_write_cooling_mode(struct file *, | 
 | 89 | 					       const char __user *, size_t, | 
 | 90 | 					       loff_t *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | 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] | 92 | static ssize_t acpi_thermal_write_polling(struct file *, const char __user *, | 
 | 93 | 					  size_t, loff_t *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 |  | 
 | 95 | static struct acpi_driver acpi_thermal_driver = { | 
| Len Brown | c2b6705b | 2007-02-12 23:33:40 -0500 | [diff] [blame] | 96 | 	.name = "thermal", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 97 | 	.class = ACPI_THERMAL_CLASS, | 
 | 98 | 	.ids = ACPI_THERMAL_HID, | 
 | 99 | 	.ops = { | 
 | 100 | 		.add = acpi_thermal_add, | 
 | 101 | 		.remove = acpi_thermal_remove, | 
| Konstantin Karasyov | 74ce146 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 102 | 		.resume = acpi_thermal_resume, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 103 | 		}, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | }; | 
 | 105 |  | 
 | 106 | struct acpi_thermal_state { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 107 | 	u8 critical:1; | 
 | 108 | 	u8 hot:1; | 
 | 109 | 	u8 passive:1; | 
 | 110 | 	u8 active:1; | 
 | 111 | 	u8 reserved:4; | 
 | 112 | 	int active_index; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | }; | 
 | 114 |  | 
 | 115 | struct acpi_thermal_state_flags { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 116 | 	u8 valid:1; | 
 | 117 | 	u8 enabled:1; | 
 | 118 | 	u8 reserved:6; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | }; | 
 | 120 |  | 
 | 121 | struct acpi_thermal_critical { | 
 | 122 | 	struct acpi_thermal_state_flags flags; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 123 | 	unsigned long temperature; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | }; | 
 | 125 |  | 
 | 126 | struct acpi_thermal_hot { | 
 | 127 | 	struct acpi_thermal_state_flags flags; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 128 | 	unsigned long temperature; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | }; | 
 | 130 |  | 
 | 131 | struct acpi_thermal_passive { | 
 | 132 | 	struct acpi_thermal_state_flags flags; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 133 | 	unsigned long temperature; | 
 | 134 | 	unsigned long tc1; | 
 | 135 | 	unsigned long tc2; | 
 | 136 | 	unsigned long tsp; | 
 | 137 | 	struct acpi_handle_list devices; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | }; | 
 | 139 |  | 
 | 140 | struct acpi_thermal_active { | 
 | 141 | 	struct acpi_thermal_state_flags flags; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 142 | 	unsigned long temperature; | 
 | 143 | 	struct acpi_handle_list devices; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | }; | 
 | 145 |  | 
 | 146 | struct acpi_thermal_trips { | 
 | 147 | 	struct acpi_thermal_critical critical; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 148 | 	struct acpi_thermal_hot hot; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | 	struct acpi_thermal_passive passive; | 
 | 150 | 	struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE]; | 
 | 151 | }; | 
 | 152 |  | 
 | 153 | struct acpi_thermal_flags { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 154 | 	u8 cooling_mode:1;	/* _SCP */ | 
 | 155 | 	u8 devices:1;		/* _TZD */ | 
 | 156 | 	u8 reserved:6; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | }; | 
 | 158 |  | 
 | 159 | struct acpi_thermal { | 
| Patrick Mochel | 8348e1b | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 160 | 	struct acpi_device * device; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 161 | 	acpi_bus_id name; | 
 | 162 | 	unsigned long temperature; | 
 | 163 | 	unsigned long last_temperature; | 
 | 164 | 	unsigned long polling_frequency; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 165 | 	volatile u8 zombie; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | 	struct acpi_thermal_flags flags; | 
 | 167 | 	struct acpi_thermal_state state; | 
 | 168 | 	struct acpi_thermal_trips trips; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 169 | 	struct acpi_handle_list devices; | 
 | 170 | 	struct timer_list timer; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | }; | 
 | 172 |  | 
| Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 173 | static const struct file_operations acpi_thermal_state_fops = { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 174 | 	.open = acpi_thermal_state_open_fs, | 
 | 175 | 	.read = seq_read, | 
 | 176 | 	.llseek = seq_lseek, | 
 | 177 | 	.release = single_release, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | }; | 
 | 179 |  | 
| Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 180 | static const struct file_operations acpi_thermal_temp_fops = { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 181 | 	.open = acpi_thermal_temp_open_fs, | 
 | 182 | 	.read = seq_read, | 
 | 183 | 	.llseek = seq_lseek, | 
 | 184 | 	.release = single_release, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | }; | 
 | 186 |  | 
| Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 187 | static const struct file_operations acpi_thermal_trip_fops = { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 188 | 	.open = acpi_thermal_trip_open_fs, | 
 | 189 | 	.read = seq_read, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 190 | 	.llseek = seq_lseek, | 
 | 191 | 	.release = single_release, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | }; | 
 | 193 |  | 
| Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 194 | static const struct file_operations acpi_thermal_cooling_fops = { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 195 | 	.open = acpi_thermal_cooling_open_fs, | 
 | 196 | 	.read = seq_read, | 
 | 197 | 	.write = acpi_thermal_write_cooling_mode, | 
 | 198 | 	.llseek = seq_lseek, | 
 | 199 | 	.release = single_release, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | }; | 
 | 201 |  | 
| Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 202 | static const struct file_operations acpi_thermal_polling_fops = { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 203 | 	.open = acpi_thermal_polling_open_fs, | 
 | 204 | 	.read = seq_read, | 
 | 205 | 	.write = acpi_thermal_write_polling, | 
 | 206 | 	.llseek = seq_lseek, | 
 | 207 | 	.release = single_release, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | }; | 
 | 209 |  | 
 | 210 | /* -------------------------------------------------------------------------- | 
 | 211 |                              Thermal Zone Management | 
 | 212 |    -------------------------------------------------------------------------- */ | 
 | 213 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 214 | static int acpi_thermal_get_temperature(struct acpi_thermal *tz) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | 	acpi_status status = AE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 |  | 
 | 219 | 	if (!tz) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 220 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 |  | 
 | 222 | 	tz->last_temperature = tz->temperature; | 
 | 223 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 224 | 	status = | 
| Patrick Mochel | 38ba7c9 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 225 | 	    acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tz->temperature); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | 	if (ACPI_FAILURE(status)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 227 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 229 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n", | 
 | 230 | 			  tz->temperature)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 232 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | } | 
 | 234 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 235 | static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 237 | 	acpi_status status = AE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 |  | 
 | 240 | 	if (!tz) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 241 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 243 | 	status = | 
| Patrick Mochel | 38ba7c9 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 244 | 	    acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 245 | 				  &tz->polling_frequency); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | 	if (ACPI_FAILURE(status)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 247 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 249 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n", | 
 | 250 | 			  tz->polling_frequency)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 252 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | } | 
 | 254 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 255 | static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 |  | 
 | 258 | 	if (!tz) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 259 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 |  | 
 | 261 | 	tz->polling_frequency = seconds * 10;	/* Convert value to deci-seconds */ | 
 | 262 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 263 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
 | 264 | 			  "Polling frequency set to %lu seconds\n", | 
| Sanjoy Mahajan | 636cedf | 2007-02-16 01:24:43 -0500 | [diff] [blame] | 265 | 			  tz->polling_frequency/10)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 267 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } | 
 | 269 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 270 | static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 272 | 	acpi_status status = AE_OK; | 
 | 273 | 	union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | 
 | 274 | 	struct acpi_object_list arg_list = { 1, &arg0 }; | 
 | 275 | 	acpi_handle handle = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 |  | 
 | 278 | 	if (!tz) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 279 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 |  | 
| Patrick Mochel | 38ba7c9 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 281 | 	status = acpi_get_handle(tz->device->handle, "_SCP", &handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | 	if (ACPI_FAILURE(status)) { | 
 | 283 | 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n")); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 284 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | 	} | 
 | 286 |  | 
 | 287 | 	arg0.integer.value = mode; | 
 | 288 |  | 
 | 289 | 	status = acpi_evaluate_object(handle, NULL, &arg_list, NULL); | 
 | 290 | 	if (ACPI_FAILURE(status)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 291 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 293 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | } | 
 | 295 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 296 | static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 298 | 	acpi_status status = AE_OK; | 
 | 299 | 	int i = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 |  | 
 | 302 | 	if (!tz) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 303 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 |  | 
 | 305 | 	/* Critical Shutdown (required) */ | 
 | 306 |  | 
| Patrick Mochel | 38ba7c9 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 307 | 	status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 308 | 				       &tz->trips.critical.temperature); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | 	if (ACPI_FAILURE(status)) { | 
 | 310 | 		tz->trips.critical.flags.valid = 0; | 
| Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 311 | 		ACPI_EXCEPTION((AE_INFO, status, "No critical threshold")); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 312 | 		return -ENODEV; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 313 | 	} else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | 		tz->trips.critical.flags.valid = 1; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 315 | 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
 | 316 | 				  "Found critical threshold [%lu]\n", | 
 | 317 | 				  tz->trips.critical.temperature)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | 	} | 
 | 319 |  | 
 | 320 | 	/* Critical Sleep (optional) */ | 
 | 321 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 322 | 	status = | 
| Patrick Mochel | 38ba7c9 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 323 | 	    acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 324 | 				  &tz->trips.hot.temperature); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | 	if (ACPI_FAILURE(status)) { | 
 | 326 | 		tz->trips.hot.flags.valid = 0; | 
 | 327 | 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No hot threshold\n")); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 328 | 	} else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | 		tz->trips.hot.flags.valid = 1; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 330 | 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found hot threshold [%lu]\n", | 
 | 331 | 				  tz->trips.hot.temperature)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | 	} | 
 | 333 |  | 
 | 334 | 	/* Passive: Processors (optional) */ | 
 | 335 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 336 | 	status = | 
| Patrick Mochel | 38ba7c9 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 337 | 	    acpi_evaluate_integer(tz->device->handle, "_PSV", NULL, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 338 | 				  &tz->trips.passive.temperature); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | 	if (ACPI_FAILURE(status)) { | 
 | 340 | 		tz->trips.passive.flags.valid = 0; | 
 | 341 | 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No passive threshold\n")); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 342 | 	} else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | 		tz->trips.passive.flags.valid = 1; | 
 | 344 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 345 | 		status = | 
| Patrick Mochel | 38ba7c9 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 346 | 		    acpi_evaluate_integer(tz->device->handle, "_TC1", NULL, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 347 | 					  &tz->trips.passive.tc1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | 		if (ACPI_FAILURE(status)) | 
 | 349 | 			tz->trips.passive.flags.valid = 0; | 
 | 350 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 351 | 		status = | 
| Patrick Mochel | 38ba7c9 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 352 | 		    acpi_evaluate_integer(tz->device->handle, "_TC2", NULL, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 353 | 					  &tz->trips.passive.tc2); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | 		if (ACPI_FAILURE(status)) | 
 | 355 | 			tz->trips.passive.flags.valid = 0; | 
 | 356 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 357 | 		status = | 
| Patrick Mochel | 38ba7c9 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 358 | 		    acpi_evaluate_integer(tz->device->handle, "_TSP", NULL, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 359 | 					  &tz->trips.passive.tsp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | 		if (ACPI_FAILURE(status)) | 
 | 361 | 			tz->trips.passive.flags.valid = 0; | 
 | 362 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 363 | 		status = | 
| Patrick Mochel | 38ba7c9 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 364 | 		    acpi_evaluate_reference(tz->device->handle, "_PSL", NULL, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 365 | 					    &tz->trips.passive.devices); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | 		if (ACPI_FAILURE(status)) | 
 | 367 | 			tz->trips.passive.flags.valid = 0; | 
 | 368 |  | 
 | 369 | 		if (!tz->trips.passive.flags.valid) | 
| Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 370 | 			printk(KERN_WARNING PREFIX "Invalid passive threshold\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | 		else | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 372 | 			ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
 | 373 | 					  "Found passive threshold [%lu]\n", | 
 | 374 | 					  tz->trips.passive.temperature)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | 	} | 
 | 376 |  | 
 | 377 | 	/* Active: Fans, etc. (optional) */ | 
 | 378 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 379 | 	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 381 | 		char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 383 | 		status = | 
| Patrick Mochel | 38ba7c9 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 384 | 		    acpi_evaluate_integer(tz->device->handle, name, NULL, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 385 | 					  &tz->trips.active[i].temperature); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | 		if (ACPI_FAILURE(status)) | 
 | 387 | 			break; | 
 | 388 |  | 
 | 389 | 		name[2] = 'L'; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 390 | 		status = | 
| Patrick Mochel | 38ba7c9 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 391 | 		    acpi_evaluate_reference(tz->device->handle, name, NULL, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 392 | 					    &tz->trips.active[i].devices); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | 		if (ACPI_SUCCESS(status)) { | 
 | 394 | 			tz->trips.active[i].flags.valid = 1; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 395 | 			ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
 | 396 | 					  "Found active threshold [%d]:[%lu]\n", | 
 | 397 | 					  i, tz->trips.active[i].temperature)); | 
 | 398 | 		} else | 
| Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 399 | 			ACPI_EXCEPTION((AE_INFO, status, | 
 | 400 | 					"Invalid active threshold [%d]", i)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | 	} | 
 | 402 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 403 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | } | 
 | 405 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 406 | static int acpi_thermal_get_devices(struct acpi_thermal *tz) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 408 | 	acpi_status status = AE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 |  | 
 | 411 | 	if (!tz) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 412 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 414 | 	status = | 
| Patrick Mochel | 38ba7c9 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 415 | 	    acpi_evaluate_reference(tz->device->handle, "_TZD", NULL, &tz->devices); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | 	if (ACPI_FAILURE(status)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 417 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 419 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | } | 
 | 421 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 422 | static int acpi_thermal_call_usermode(char *path) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 424 | 	char *argv[2] = { NULL, NULL }; | 
 | 425 | 	char *envp[3] = { NULL, NULL, NULL }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 |  | 
 | 428 | 	if (!path) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 429 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 |  | 
 | 431 | 	argv[0] = path; | 
 | 432 |  | 
 | 433 | 	/* minimal command environment */ | 
 | 434 | 	envp[0] = "HOME=/"; | 
 | 435 | 	envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin"; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 436 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | 	call_usermodehelper(argv[0], argv, envp, 0); | 
 | 438 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 439 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | } | 
 | 441 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 442 | static int acpi_thermal_critical(struct acpi_thermal *tz) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | 	if (!tz || !tz->trips.critical.flags.valid) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 445 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 |  | 
 | 447 | 	if (tz->temperature >= tz->trips.critical.temperature) { | 
| Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 448 | 		printk(KERN_WARNING PREFIX "Critical trip point\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | 		tz->trips.critical.flags.enabled = 1; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 450 | 	} else if (tz->trips.critical.flags.enabled) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | 		tz->trips.critical.flags.enabled = 0; | 
 | 452 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 453 | 	printk(KERN_EMERG | 
 | 454 | 	       "Critical temperature reached (%ld C), shutting down.\n", | 
 | 455 | 	       KELVIN_TO_CELSIUS(tz->temperature)); | 
| Patrick Mochel | 8348e1b | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 456 | 	acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 457 | 				tz->trips.critical.flags.enabled); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 |  | 
 | 459 | 	acpi_thermal_call_usermode(ACPI_THERMAL_PATH_POWEROFF); | 
 | 460 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 461 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | } | 
 | 463 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 464 | static int acpi_thermal_hot(struct acpi_thermal *tz) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | 	if (!tz || !tz->trips.hot.flags.valid) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 467 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 |  | 
 | 469 | 	if (tz->temperature >= tz->trips.hot.temperature) { | 
| Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 470 | 		printk(KERN_WARNING PREFIX "Hot trip point\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | 		tz->trips.hot.flags.enabled = 1; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 472 | 	} else if (tz->trips.hot.flags.enabled) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | 		tz->trips.hot.flags.enabled = 0; | 
 | 474 |  | 
| Patrick Mochel | 8348e1b | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 475 | 	acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_HOT, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 476 | 				tz->trips.hot.flags.enabled); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 |  | 
 | 478 | 	/* TBD: Call user-mode "sleep(S4)" function */ | 
 | 479 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 480 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | } | 
 | 482 |  | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 483 | static void acpi_thermal_passive(struct acpi_thermal *tz) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | { | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 485 | 	int result = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | 	struct acpi_thermal_passive *passive = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 487 | 	int trend = 0; | 
 | 488 | 	int i = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 |  | 
 | 491 | 	if (!tz || !tz->trips.passive.flags.valid) | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 492 | 		return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 |  | 
 | 494 | 	passive = &(tz->trips.passive); | 
 | 495 |  | 
 | 496 | 	/* | 
 | 497 | 	 * Above Trip? | 
 | 498 | 	 * ----------- | 
 | 499 | 	 * Calculate the thermal trend (using the passive cooling equation) | 
 | 500 | 	 * and modify the performance limit for all passive cooling devices | 
 | 501 | 	 * accordingly.  Note that we assume symmetry. | 
 | 502 | 	 */ | 
 | 503 | 	if (tz->temperature >= passive->temperature) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 504 | 		trend = | 
 | 505 | 		    (passive->tc1 * (tz->temperature - tz->last_temperature)) + | 
 | 506 | 		    (passive->tc2 * (tz->temperature - passive->temperature)); | 
 | 507 | 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
 | 508 | 				  "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n", | 
 | 509 | 				  trend, passive->tc1, tz->temperature, | 
 | 510 | 				  tz->last_temperature, passive->tc2, | 
 | 511 | 				  tz->temperature, passive->temperature)); | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 512 | 		passive->flags.enabled = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | 		/* Heating up? */ | 
 | 514 | 		if (trend > 0) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 515 | 			for (i = 0; i < passive->devices.count; i++) | 
 | 516 | 				acpi_processor_set_thermal_limit(passive-> | 
 | 517 | 								 devices. | 
 | 518 | 								 handles[i], | 
 | 519 | 								 ACPI_PROCESSOR_LIMIT_INCREMENT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | 		/* Cooling off? */ | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 521 | 		else if (trend < 0) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 522 | 			for (i = 0; i < passive->devices.count; i++) | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 523 | 				/* | 
 | 524 | 				 * assume that we are on highest | 
 | 525 | 				 * freq/lowest thrott and can leave | 
 | 526 | 				 * passive mode, even in error case | 
 | 527 | 				 */ | 
 | 528 | 				if (!acpi_processor_set_thermal_limit | 
 | 529 | 				    (passive->devices.handles[i], | 
 | 530 | 				     ACPI_PROCESSOR_LIMIT_DECREMENT)) | 
 | 531 | 					result = 0; | 
 | 532 | 			/* | 
 | 533 | 			 * Leave cooling mode, even if the temp might | 
 | 534 | 			 * higher than trip point This is because some | 
 | 535 | 			 * machines might have long thermal polling | 
 | 536 | 			 * frequencies (tsp) defined. We will fall back | 
 | 537 | 			 * into passive mode in next cycle (probably quicker) | 
 | 538 | 			 */ | 
 | 539 | 			if (result) { | 
 | 540 | 				passive->flags.enabled = 0; | 
 | 541 | 				ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
 | 542 | 						  "Disabling passive cooling, still above threshold," | 
 | 543 | 						  " but we are cooling down\n")); | 
 | 544 | 			} | 
 | 545 | 		} | 
 | 546 | 		return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | 	} | 
 | 548 |  | 
 | 549 | 	/* | 
 | 550 | 	 * Below Trip? | 
 | 551 | 	 * ----------- | 
 | 552 | 	 * Implement passive cooling hysteresis to slowly increase performance | 
 | 553 | 	 * and avoid thrashing around the passive trip point.  Note that we | 
 | 554 | 	 * assume symmetry. | 
 | 555 | 	 */ | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 556 | 	if (!passive->flags.enabled) | 
 | 557 | 		return; | 
 | 558 | 	for (i = 0; i < passive->devices.count; i++) | 
 | 559 | 		if (!acpi_processor_set_thermal_limit | 
 | 560 | 		    (passive->devices.handles[i], | 
 | 561 | 		     ACPI_PROCESSOR_LIMIT_DECREMENT)) | 
 | 562 | 			result = 0; | 
 | 563 | 	if (result) { | 
 | 564 | 		passive->flags.enabled = 0; | 
 | 565 | 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
 | 566 | 				  "Disabling passive cooling (zone is cool)\n")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } | 
 | 569 |  | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 570 | static void acpi_thermal_active(struct acpi_thermal *tz) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 572 | 	int result = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | 	struct acpi_thermal_active *active = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 574 | 	int i = 0; | 
 | 575 | 	int j = 0; | 
 | 576 | 	unsigned long maxtemp = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 |  | 
 | 579 | 	if (!tz) | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 580 | 		return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 582 | 	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | 		active = &(tz->trips.active[i]); | 
 | 584 | 		if (!active || !active->flags.valid) | 
 | 585 | 			break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | 		if (tz->temperature >= active->temperature) { | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 587 | 			/* | 
 | 588 | 			 * Above Threshold? | 
 | 589 | 			 * ---------------- | 
 | 590 | 			 * If not already enabled, turn ON all cooling devices | 
 | 591 | 			 * associated with this active threshold. | 
 | 592 | 			 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | 			if (active->temperature > maxtemp) | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 594 | 				tz->state.active_index = i; | 
 | 595 | 			maxtemp = active->temperature; | 
 | 596 | 			if (active->flags.enabled) | 
 | 597 | 				continue; | 
 | 598 | 			for (j = 0; j < active->devices.count; j++) { | 
 | 599 | 				result = | 
 | 600 | 				    acpi_bus_set_power(active->devices. | 
 | 601 | 						       handles[j], | 
 | 602 | 						       ACPI_STATE_D0); | 
 | 603 | 				if (result) { | 
| Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 604 | 					printk(KERN_WARNING PREFIX | 
 | 605 | 						      "Unable to turn cooling device [%p] 'on'\n", | 
| Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 606 | 						      active->devices. | 
| Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 607 | 						      handles[j]); | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 608 | 					continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | 				} | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 610 | 				active->flags.enabled = 1; | 
 | 611 | 				ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
 | 612 | 						  "Cooling device [%p] now 'on'\n", | 
 | 613 | 						  active->devices.handles[j])); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | 			} | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 615 | 			continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | 		} | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 617 | 		if (!active->flags.enabled) | 
 | 618 | 			continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | 		/* | 
 | 620 | 		 * Below Threshold? | 
 | 621 | 		 * ---------------- | 
 | 622 | 		 * Turn OFF all cooling devices associated with this | 
 | 623 | 		 * threshold. | 
 | 624 | 		 */ | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 625 | 		for (j = 0; j < active->devices.count; j++) { | 
 | 626 | 			result = acpi_bus_set_power(active->devices.handles[j], | 
 | 627 | 						    ACPI_STATE_D3); | 
 | 628 | 			if (result) { | 
| Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 629 | 				printk(KERN_WARNING PREFIX | 
 | 630 | 					      "Unable to turn cooling device [%p] 'off'\n", | 
 | 631 | 					      active->devices.handles[j]); | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 632 | 				continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | 			} | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 634 | 			active->flags.enabled = 0; | 
 | 635 | 			ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
 | 636 | 					  "Cooling device [%p] now 'off'\n", | 
 | 637 | 					  active->devices.handles[j])); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | 		} | 
 | 639 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | } | 
 | 641 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 642 | static void acpi_thermal_check(void *context); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 644 | static void acpi_thermal_run(unsigned long data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | { | 
 | 646 | 	struct acpi_thermal *tz = (struct acpi_thermal *)data; | 
 | 647 | 	if (!tz->zombie) | 
| Alexey Starikovskiy | b8d3519 | 2006-05-05 03:23:00 -0400 | [diff] [blame] | 648 | 		acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | } | 
 | 650 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 651 | static void acpi_thermal_check(void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 653 | 	int result = 0; | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 654 | 	struct acpi_thermal *tz = data; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 655 | 	unsigned long sleep_time = 0; | 
 | 656 | 	int i = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | 	struct acpi_thermal_state state; | 
 | 658 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 |  | 
 | 660 | 	if (!tz) { | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 661 | 		printk(KERN_ERR PREFIX "Invalid (NULL) context\n"); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 662 | 		return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | 	} | 
 | 664 |  | 
 | 665 | 	state = tz->state; | 
 | 666 |  | 
 | 667 | 	result = acpi_thermal_get_temperature(tz); | 
 | 668 | 	if (result) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 669 | 		return; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 670 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | 	memset(&tz->state, 0, sizeof(tz->state)); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 672 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | 	/* | 
 | 674 | 	 * Check Trip Points | 
 | 675 | 	 * ----------------- | 
 | 676 | 	 * Compare the current temperature to the trip point values to see | 
 | 677 | 	 * if we've entered one of the thermal policy states.  Note that | 
 | 678 | 	 * this function determines when a state is entered, but the  | 
 | 679 | 	 * individual policy decides when it is exited (e.g. hysteresis). | 
 | 680 | 	 */ | 
 | 681 | 	if (tz->trips.critical.flags.valid) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 682 | 		state.critical |= | 
 | 683 | 		    (tz->temperature >= tz->trips.critical.temperature); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | 	if (tz->trips.hot.flags.valid) | 
 | 685 | 		state.hot |= (tz->temperature >= tz->trips.hot.temperature); | 
 | 686 | 	if (tz->trips.passive.flags.valid) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 687 | 		state.passive |= | 
 | 688 | 		    (tz->temperature >= tz->trips.passive.temperature); | 
 | 689 | 	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | 		if (tz->trips.active[i].flags.valid) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 691 | 			state.active |= | 
 | 692 | 			    (tz->temperature >= | 
 | 693 | 			     tz->trips.active[i].temperature); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 |  | 
 | 695 | 	/* | 
 | 696 | 	 * Invoke Policy | 
 | 697 | 	 * ------------- | 
 | 698 | 	 * Separated from the above check to allow individual policy to  | 
 | 699 | 	 * determine when to exit a given state. | 
 | 700 | 	 */ | 
 | 701 | 	if (state.critical) | 
 | 702 | 		acpi_thermal_critical(tz); | 
 | 703 | 	if (state.hot) | 
 | 704 | 		acpi_thermal_hot(tz); | 
 | 705 | 	if (state.passive) | 
 | 706 | 		acpi_thermal_passive(tz); | 
 | 707 | 	if (state.active) | 
 | 708 | 		acpi_thermal_active(tz); | 
 | 709 |  | 
 | 710 | 	/* | 
 | 711 | 	 * Calculate State | 
 | 712 | 	 * --------------- | 
 | 713 | 	 * Again, separated from the above two to allow independent policy | 
 | 714 | 	 * decisions. | 
 | 715 | 	 */ | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 716 | 	tz->state.critical = tz->trips.critical.flags.enabled; | 
 | 717 | 	tz->state.hot = tz->trips.hot.flags.enabled; | 
 | 718 | 	tz->state.passive = tz->trips.passive.flags.enabled; | 
 | 719 | 	tz->state.active = 0; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 720 | 	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 721 | 		tz->state.active |= tz->trips.active[i].flags.enabled; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 |  | 
 | 723 | 	/* | 
 | 724 | 	 * Calculate Sleep Time | 
 | 725 | 	 * -------------------- | 
 | 726 | 	 * If we're in the passive state, use _TSP's value.  Otherwise | 
 | 727 | 	 * use the default polling frequency (e.g. _TZP).  If no polling | 
 | 728 | 	 * frequency is specified then we'll wait forever (at least until | 
 | 729 | 	 * a thermal event occurs).  Note that _TSP and _TZD values are | 
 | 730 | 	 * given in 1/10th seconds (we must covert to milliseconds). | 
 | 731 | 	 */ | 
 | 732 | 	if (tz->state.passive) | 
 | 733 | 		sleep_time = tz->trips.passive.tsp * 100; | 
 | 734 | 	else if (tz->polling_frequency > 0) | 
 | 735 | 		sleep_time = tz->polling_frequency * 100; | 
 | 736 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 737 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n", | 
 | 738 | 			  tz->name, tz->temperature, sleep_time)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 |  | 
 | 740 | 	/* | 
 | 741 | 	 * Schedule Next Poll | 
 | 742 | 	 * ------------------ | 
 | 743 | 	 */ | 
 | 744 | 	if (!sleep_time) { | 
 | 745 | 		if (timer_pending(&(tz->timer))) | 
 | 746 | 			del_timer(&(tz->timer)); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 747 | 	} else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | 		if (timer_pending(&(tz->timer))) | 
| Andrew Morton | 94e22e1 | 2007-04-23 14:41:13 -0700 | [diff] [blame] | 749 | 			mod_timer(&(tz->timer), | 
 | 750 | 					jiffies + (HZ * sleep_time) / 1000); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | 		else { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 752 | 			tz->timer.data = (unsigned long)tz; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | 			tz->timer.function = acpi_thermal_run; | 
 | 754 | 			tz->timer.expires = jiffies + (HZ * sleep_time) / 1000; | 
 | 755 | 			add_timer(&(tz->timer)); | 
 | 756 | 		} | 
 | 757 | 	} | 
 | 758 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 759 | 	return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | } | 
 | 761 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | /* -------------------------------------------------------------------------- | 
 | 763 |                               FS Interface (/proc) | 
 | 764 |    -------------------------------------------------------------------------- */ | 
 | 765 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 766 | static struct proc_dir_entry *acpi_thermal_dir; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 |  | 
 | 768 | static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset) | 
 | 769 | { | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 770 | 	struct acpi_thermal *tz = seq->private; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 |  | 
 | 773 | 	if (!tz) | 
 | 774 | 		goto end; | 
 | 775 |  | 
 | 776 | 	seq_puts(seq, "state:                   "); | 
 | 777 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 778 | 	if (!tz->state.critical && !tz->state.hot && !tz->state.passive | 
 | 779 | 	    && !tz->state.active) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | 		seq_puts(seq, "ok\n"); | 
 | 781 | 	else { | 
 | 782 | 		if (tz->state.critical) | 
 | 783 | 			seq_puts(seq, "critical "); | 
 | 784 | 		if (tz->state.hot) | 
 | 785 | 			seq_puts(seq, "hot "); | 
 | 786 | 		if (tz->state.passive) | 
 | 787 | 			seq_puts(seq, "passive "); | 
 | 788 | 		if (tz->state.active) | 
 | 789 | 			seq_printf(seq, "active[%d]", tz->state.active_index); | 
 | 790 | 		seq_puts(seq, "\n"); | 
 | 791 | 	} | 
 | 792 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 793 |       end: | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 794 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | } | 
 | 796 |  | 
 | 797 | static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file) | 
 | 798 | { | 
 | 799 | 	return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data); | 
 | 800 | } | 
 | 801 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset) | 
 | 803 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 804 | 	int result = 0; | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 805 | 	struct acpi_thermal *tz = seq->private; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 |  | 
 | 808 | 	if (!tz) | 
 | 809 | 		goto end; | 
 | 810 |  | 
 | 811 | 	result = acpi_thermal_get_temperature(tz); | 
 | 812 | 	if (result) | 
 | 813 | 		goto end; | 
 | 814 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 815 | 	seq_printf(seq, "temperature:             %ld C\n", | 
 | 816 | 		   KELVIN_TO_CELSIUS(tz->temperature)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 818 |       end: | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 819 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | } | 
 | 821 |  | 
 | 822 | static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file) | 
 | 823 | { | 
 | 824 | 	return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data); | 
 | 825 | } | 
 | 826 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset) | 
 | 828 | { | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 829 | 	struct acpi_thermal *tz = seq->private; | 
| Thomas Renninger | 68ccfaa | 2006-11-19 23:01:40 +0100 | [diff] [blame] | 830 | 	struct acpi_device *device; | 
| Thomas Renninger | e7c746e | 2007-06-18 00:40:51 -0400 | [diff] [blame] | 831 | 	acpi_status status; | 
 | 832 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 833 | 	int i = 0; | 
 | 834 | 	int j = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 |  | 
 | 837 | 	if (!tz) | 
 | 838 | 		goto end; | 
 | 839 |  | 
 | 840 | 	if (tz->trips.critical.flags.valid) | 
 | 841 | 		seq_printf(seq, "critical (S5):           %ld C\n", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 842 | 			   KELVIN_TO_CELSIUS(tz->trips.critical.temperature)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 |  | 
 | 844 | 	if (tz->trips.hot.flags.valid) | 
 | 845 | 		seq_printf(seq, "hot (S4):                %ld C\n", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 846 | 			   KELVIN_TO_CELSIUS(tz->trips.hot.temperature)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 |  | 
 | 848 | 	if (tz->trips.passive.flags.valid) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 849 | 		seq_printf(seq, | 
 | 850 | 			   "passive:                 %ld C: tc1=%lu tc2=%lu tsp=%lu devices=", | 
 | 851 | 			   KELVIN_TO_CELSIUS(tz->trips.passive.temperature), | 
 | 852 | 			   tz->trips.passive.tc1, tz->trips.passive.tc2, | 
 | 853 | 			   tz->trips.passive.tsp); | 
 | 854 | 		for (j = 0; j < tz->trips.passive.devices.count; j++) { | 
| Thomas Renninger | e7c746e | 2007-06-18 00:40:51 -0400 | [diff] [blame] | 855 | 			status = acpi_bus_get_device(tz->trips.passive.devices. | 
 | 856 | 						     handles[j], &device); | 
 | 857 | 			seq_printf(seq, "%4.4s ", status ? "" : | 
 | 858 | 				   acpi_device_bid(device)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | 		} | 
 | 860 | 		seq_puts(seq, "\n"); | 
 | 861 | 	} | 
 | 862 |  | 
 | 863 | 	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { | 
 | 864 | 		if (!(tz->trips.active[i].flags.valid)) | 
 | 865 | 			break; | 
 | 866 | 		seq_printf(seq, "active[%d]:               %ld C: devices=", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 867 | 			   i, | 
 | 868 | 			   KELVIN_TO_CELSIUS(tz->trips.active[i].temperature)); | 
| Thomas Renninger | 68ccfaa | 2006-11-19 23:01:40 +0100 | [diff] [blame] | 869 | 		for (j = 0; j < tz->trips.active[i].devices.count; j++){ | 
| Thomas Renninger | e7c746e | 2007-06-18 00:40:51 -0400 | [diff] [blame] | 870 | 			status = acpi_bus_get_device(tz->trips.active[i]. | 
 | 871 | 						     devices.handles[j], | 
 | 872 | 						     &device); | 
 | 873 | 			seq_printf(seq, "%4.4s ", status ? "" : | 
 | 874 | 				   acpi_device_bid(device)); | 
| Thomas Renninger | 68ccfaa | 2006-11-19 23:01:40 +0100 | [diff] [blame] | 875 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | 		seq_puts(seq, "\n"); | 
 | 877 | 	} | 
 | 878 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 879 |       end: | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 880 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | } | 
 | 882 |  | 
 | 883 | static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file) | 
 | 884 | { | 
 | 885 | 	return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data); | 
 | 886 | } | 
 | 887 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset) | 
 | 889 | { | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 890 | 	struct acpi_thermal *tz = seq->private; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 |  | 
 | 893 | 	if (!tz) | 
 | 894 | 		goto end; | 
 | 895 |  | 
| Len Brown | eaca2d3 | 2007-04-30 23:27:43 -0400 | [diff] [blame] | 896 | 	if (!tz->flags.cooling_mode) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | 		seq_puts(seq, "<setting not supported>\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | 	else | 
| Len Brown | eaca2d3 | 2007-04-30 23:27:43 -0400 | [diff] [blame] | 899 | 		seq_puts(seq, "0 - Active; 1 - Passive\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 901 |       end: | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 902 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | } | 
 | 904 |  | 
 | 905 | static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file) | 
 | 906 | { | 
 | 907 | 	return single_open(file, acpi_thermal_cooling_seq_show, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 908 | 			   PDE(inode)->data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | } | 
 | 910 |  | 
 | 911 | static ssize_t | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 912 | acpi_thermal_write_cooling_mode(struct file *file, | 
 | 913 | 				const char __user * buffer, | 
 | 914 | 				size_t count, loff_t * ppos) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | { | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 916 | 	struct seq_file *m = file->private_data; | 
 | 917 | 	struct acpi_thermal *tz = m->private; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 918 | 	int result = 0; | 
 | 919 | 	char mode_string[12] = { '\0' }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 |  | 
 | 922 | 	if (!tz || (count > sizeof(mode_string) - 1)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 923 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 |  | 
 | 925 | 	if (!tz->flags.cooling_mode) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 926 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 |  | 
 | 928 | 	if (copy_from_user(mode_string, buffer, count)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 929 | 		return -EFAULT; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 930 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | 	mode_string[count] = '\0'; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 932 |  | 
 | 933 | 	result = acpi_thermal_set_cooling_mode(tz, | 
 | 934 | 					       simple_strtoul(mode_string, NULL, | 
 | 935 | 							      0)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | 	if (result) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 937 | 		return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 |  | 
 | 939 | 	acpi_thermal_check(tz); | 
 | 940 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 941 | 	return count; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | } | 
 | 943 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset) | 
 | 945 | { | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 946 | 	struct acpi_thermal *tz = seq->private; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 |  | 
 | 949 | 	if (!tz) | 
 | 950 | 		goto end; | 
 | 951 |  | 
 | 952 | 	if (!tz->polling_frequency) { | 
 | 953 | 		seq_puts(seq, "<polling disabled>\n"); | 
 | 954 | 		goto end; | 
 | 955 | 	} | 
 | 956 |  | 
 | 957 | 	seq_printf(seq, "polling frequency:       %lu seconds\n", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 958 | 		   (tz->polling_frequency / 10)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 960 |       end: | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 961 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | } | 
 | 963 |  | 
 | 964 | static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file) | 
 | 965 | { | 
 | 966 | 	return single_open(file, acpi_thermal_polling_seq_show, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 967 | 			   PDE(inode)->data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | } | 
 | 969 |  | 
 | 970 | static ssize_t | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 971 | acpi_thermal_write_polling(struct file *file, | 
 | 972 | 			   const char __user * buffer, | 
 | 973 | 			   size_t count, loff_t * ppos) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | { | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 975 | 	struct seq_file *m = file->private_data; | 
 | 976 | 	struct acpi_thermal *tz = m->private; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 977 | 	int result = 0; | 
 | 978 | 	char polling_string[12] = { '\0' }; | 
 | 979 | 	int seconds = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 |  | 
 | 982 | 	if (!tz || (count > sizeof(polling_string) - 1)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 983 | 		return -EINVAL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 984 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | 	if (copy_from_user(polling_string, buffer, count)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 986 | 		return -EFAULT; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 987 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | 	polling_string[count] = '\0'; | 
 | 989 |  | 
 | 990 | 	seconds = simple_strtoul(polling_string, NULL, 0); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 991 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | 	result = acpi_thermal_set_polling(tz, seconds); | 
 | 993 | 	if (result) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 994 | 		return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 |  | 
 | 996 | 	acpi_thermal_check(tz); | 
 | 997 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 998 | 	return count; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | } | 
 | 1000 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1001 | static int acpi_thermal_add_fs(struct acpi_device *device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1003 | 	struct proc_dir_entry *entry = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 |  | 
 | 1006 | 	if (!acpi_device_dir(device)) { | 
 | 1007 | 		acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1008 | 						     acpi_thermal_dir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | 		if (!acpi_device_dir(device)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1010 | 			return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | 		acpi_device_dir(device)->owner = THIS_MODULE; | 
 | 1012 | 	} | 
 | 1013 |  | 
 | 1014 | 	/* 'state' [R] */ | 
 | 1015 | 	entry = create_proc_entry(ACPI_THERMAL_FILE_STATE, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1016 | 				  S_IRUGO, acpi_device_dir(device)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | 	if (!entry) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1018 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | 	else { | 
 | 1020 | 		entry->proc_fops = &acpi_thermal_state_fops; | 
 | 1021 | 		entry->data = acpi_driver_data(device); | 
 | 1022 | 		entry->owner = THIS_MODULE; | 
 | 1023 | 	} | 
 | 1024 |  | 
 | 1025 | 	/* 'temperature' [R] */ | 
 | 1026 | 	entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1027 | 				  S_IRUGO, acpi_device_dir(device)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | 	if (!entry) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1029 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | 	else { | 
 | 1031 | 		entry->proc_fops = &acpi_thermal_temp_fops; | 
 | 1032 | 		entry->data = acpi_driver_data(device); | 
 | 1033 | 		entry->owner = THIS_MODULE; | 
 | 1034 | 	} | 
 | 1035 |  | 
 | 1036 | 	/* 'trip_points' [R/W] */ | 
 | 1037 | 	entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1038 | 				  S_IFREG | S_IRUGO | S_IWUSR, | 
 | 1039 | 				  acpi_device_dir(device)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | 	if (!entry) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1041 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | 	else { | 
 | 1043 | 		entry->proc_fops = &acpi_thermal_trip_fops; | 
 | 1044 | 		entry->data = acpi_driver_data(device); | 
 | 1045 | 		entry->owner = THIS_MODULE; | 
 | 1046 | 	} | 
 | 1047 |  | 
 | 1048 | 	/* 'cooling_mode' [R/W] */ | 
 | 1049 | 	entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1050 | 				  S_IFREG | S_IRUGO | S_IWUSR, | 
 | 1051 | 				  acpi_device_dir(device)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | 	if (!entry) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1053 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | 	else { | 
 | 1055 | 		entry->proc_fops = &acpi_thermal_cooling_fops; | 
 | 1056 | 		entry->data = acpi_driver_data(device); | 
 | 1057 | 		entry->owner = THIS_MODULE; | 
 | 1058 | 	} | 
 | 1059 |  | 
 | 1060 | 	/* 'polling_frequency' [R/W] */ | 
 | 1061 | 	entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1062 | 				  S_IFREG | S_IRUGO | S_IWUSR, | 
 | 1063 | 				  acpi_device_dir(device)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | 	if (!entry) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1065 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | 	else { | 
 | 1067 | 		entry->proc_fops = &acpi_thermal_polling_fops; | 
 | 1068 | 		entry->data = acpi_driver_data(device); | 
 | 1069 | 		entry->owner = THIS_MODULE; | 
 | 1070 | 	} | 
 | 1071 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1072 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | } | 
 | 1074 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1075 | static int acpi_thermal_remove_fs(struct acpi_device *device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 |  | 
 | 1078 | 	if (acpi_device_dir(device)) { | 
 | 1079 | 		remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ, | 
 | 1080 | 				  acpi_device_dir(device)); | 
 | 1081 | 		remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE, | 
 | 1082 | 				  acpi_device_dir(device)); | 
 | 1083 | 		remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS, | 
 | 1084 | 				  acpi_device_dir(device)); | 
 | 1085 | 		remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE, | 
 | 1086 | 				  acpi_device_dir(device)); | 
 | 1087 | 		remove_proc_entry(ACPI_THERMAL_FILE_STATE, | 
 | 1088 | 				  acpi_device_dir(device)); | 
 | 1089 | 		remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir); | 
 | 1090 | 		acpi_device_dir(device) = NULL; | 
 | 1091 | 	} | 
 | 1092 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1093 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | } | 
 | 1095 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | /* -------------------------------------------------------------------------- | 
 | 1097 |                                  Driver Interface | 
 | 1098 |    -------------------------------------------------------------------------- */ | 
 | 1099 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1100 | static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | { | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1102 | 	struct acpi_thermal *tz = data; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1103 | 	struct acpi_device *device = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 |  | 
 | 1106 | 	if (!tz) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1107 | 		return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 |  | 
| Patrick Mochel | 8348e1b | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 1109 | 	device = tz->device; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 |  | 
 | 1111 | 	switch (event) { | 
 | 1112 | 	case ACPI_THERMAL_NOTIFY_TEMPERATURE: | 
 | 1113 | 		acpi_thermal_check(tz); | 
 | 1114 | 		break; | 
 | 1115 | 	case ACPI_THERMAL_NOTIFY_THRESHOLDS: | 
 | 1116 | 		acpi_thermal_get_trip_points(tz); | 
 | 1117 | 		acpi_thermal_check(tz); | 
 | 1118 | 		acpi_bus_generate_event(device, event, 0); | 
 | 1119 | 		break; | 
 | 1120 | 	case ACPI_THERMAL_NOTIFY_DEVICES: | 
 | 1121 | 		if (tz->flags.devices) | 
 | 1122 | 			acpi_thermal_get_devices(tz); | 
 | 1123 | 		acpi_bus_generate_event(device, event, 0); | 
 | 1124 | 		break; | 
 | 1125 | 	default: | 
 | 1126 | 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1127 | 				  "Unsupported event [0x%x]\n", event)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | 		break; | 
 | 1129 | 	} | 
 | 1130 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1131 | 	return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | } | 
 | 1133 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1134 | static int acpi_thermal_get_info(struct acpi_thermal *tz) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1136 | 	int result = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 |  | 
 | 1139 | 	if (!tz) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1140 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 |  | 
 | 1142 | 	/* Get temperature [_TMP] (required) */ | 
 | 1143 | 	result = acpi_thermal_get_temperature(tz); | 
 | 1144 | 	if (result) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1145 | 		return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 |  | 
 | 1147 | 	/* Get trip points [_CRT, _PSV, etc.] (required) */ | 
 | 1148 | 	result = acpi_thermal_get_trip_points(tz); | 
 | 1149 | 	if (result) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1150 | 		return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 |  | 
 | 1152 | 	/* Set the cooling mode [_SCP] to active cooling (default) */ | 
 | 1153 | 	result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1154 | 	if (!result) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | 		tz->flags.cooling_mode = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 |  | 
 | 1157 | 	/* Get default polling frequency [_TZP] (optional) */ | 
 | 1158 | 	if (tzp) | 
 | 1159 | 		tz->polling_frequency = tzp; | 
 | 1160 | 	else | 
 | 1161 | 		acpi_thermal_get_polling_frequency(tz); | 
 | 1162 |  | 
 | 1163 | 	/* Get devices in this thermal zone [_TZD] (optional) */ | 
 | 1164 | 	result = acpi_thermal_get_devices(tz); | 
 | 1165 | 	if (!result) | 
 | 1166 | 		tz->flags.devices = 1; | 
 | 1167 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1168 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | } | 
 | 1170 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1171 | static int acpi_thermal_add(struct acpi_device *device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1173 | 	int result = 0; | 
 | 1174 | 	acpi_status status = AE_OK; | 
 | 1175 | 	struct acpi_thermal *tz = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 |  | 
 | 1178 | 	if (!device) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1179 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 |  | 
| Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 1181 | 	tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | 	if (!tz) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1183 | 		return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 |  | 
| Patrick Mochel | 8348e1b | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 1185 | 	tz->device = device; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | 	strcpy(tz->name, device->pnp.bus_id); | 
 | 1187 | 	strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME); | 
 | 1188 | 	strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS); | 
 | 1189 | 	acpi_driver_data(device) = tz; | 
 | 1190 |  | 
 | 1191 | 	result = acpi_thermal_get_info(tz); | 
 | 1192 | 	if (result) | 
 | 1193 | 		goto end; | 
 | 1194 |  | 
 | 1195 | 	result = acpi_thermal_add_fs(device); | 
 | 1196 | 	if (result) | 
| Vasily Averin | 09047e7 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 1197 | 		goto end; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 |  | 
 | 1199 | 	init_timer(&tz->timer); | 
 | 1200 |  | 
 | 1201 | 	acpi_thermal_check(tz); | 
 | 1202 |  | 
| Patrick Mochel | 38ba7c9 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 1203 | 	status = acpi_install_notify_handler(device->handle, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1204 | 					     ACPI_DEVICE_NOTIFY, | 
 | 1205 | 					     acpi_thermal_notify, tz); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | 	if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | 		result = -ENODEV; | 
 | 1208 | 		goto end; | 
 | 1209 | 	} | 
 | 1210 |  | 
 | 1211 | 	printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1212 | 	       acpi_device_name(device), acpi_device_bid(device), | 
 | 1213 | 	       KELVIN_TO_CELSIUS(tz->temperature)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1215 |       end: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | 	if (result) { | 
 | 1217 | 		acpi_thermal_remove_fs(device); | 
 | 1218 | 		kfree(tz); | 
 | 1219 | 	} | 
 | 1220 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1221 | 	return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | } | 
 | 1223 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1224 | static int acpi_thermal_remove(struct acpi_device *device, int type) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1226 | 	acpi_status status = AE_OK; | 
 | 1227 | 	struct acpi_thermal *tz = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 |  | 
 | 1230 | 	if (!device || !acpi_driver_data(device)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1231 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 |  | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1233 | 	tz = acpi_driver_data(device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 |  | 
 | 1235 | 	/* avoid timer adding new defer task */ | 
 | 1236 | 	tz->zombie = 1; | 
 | 1237 | 	/* wait for running timer (on other CPUs) finish */ | 
 | 1238 | 	del_timer_sync(&(tz->timer)); | 
 | 1239 | 	/* synchronize deferred task */ | 
 | 1240 | 	acpi_os_wait_events_complete(NULL); | 
 | 1241 | 	/* deferred task may reinsert timer */ | 
 | 1242 | 	del_timer_sync(&(tz->timer)); | 
 | 1243 |  | 
| Patrick Mochel | 38ba7c9 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 1244 | 	status = acpi_remove_notify_handler(device->handle, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1245 | 					    ACPI_DEVICE_NOTIFY, | 
 | 1246 | 					    acpi_thermal_notify); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 |  | 
 | 1248 | 	/* Terminate policy */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1249 | 	if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | 		tz->trips.passive.flags.enabled = 0; | 
 | 1251 | 		acpi_thermal_passive(tz); | 
 | 1252 | 	} | 
 | 1253 | 	if (tz->trips.active[0].flags.valid | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1254 | 	    && tz->trips.active[0].flags.enabled) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | 		tz->trips.active[0].flags.enabled = 0; | 
 | 1256 | 		acpi_thermal_active(tz); | 
 | 1257 | 	} | 
 | 1258 |  | 
 | 1259 | 	acpi_thermal_remove_fs(device); | 
 | 1260 |  | 
 | 1261 | 	kfree(tz); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1262 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | } | 
 | 1264 |  | 
| Patrick Mochel | 5d9464a | 2006-12-07 20:56:27 +0800 | [diff] [blame] | 1265 | static int acpi_thermal_resume(struct acpi_device *device) | 
| Konstantin Karasyov | 74ce146 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1266 | { | 
 | 1267 | 	struct acpi_thermal *tz = NULL; | 
| Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1268 | 	int i, j, power_state, result; | 
 | 1269 |  | 
| Konstantin Karasyov | 74ce146 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1270 |  | 
 | 1271 | 	if (!device || !acpi_driver_data(device)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1272 | 		return -EINVAL; | 
| Konstantin Karasyov | 74ce146 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1273 |  | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1274 | 	tz = acpi_driver_data(device); | 
| Konstantin Karasyov | 74ce146 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1275 |  | 
| Konstantin Karasyov | bed936f | 2006-07-10 04:44:26 -0700 | [diff] [blame] | 1276 | 	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { | 
| Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1277 | 		if (!(&tz->trips.active[i])) | 
 | 1278 | 			break; | 
 | 1279 | 		if (!tz->trips.active[i].flags.valid) | 
 | 1280 | 			break; | 
 | 1281 | 		tz->trips.active[i].flags.enabled = 1; | 
 | 1282 | 		for (j = 0; j < tz->trips.active[i].devices.count; j++) { | 
 | 1283 | 			result = acpi_bus_get_power(tz->trips.active[i].devices. | 
 | 1284 | 			    handles[j], &power_state); | 
 | 1285 | 			if (result || (power_state != ACPI_STATE_D0)) { | 
 | 1286 | 				tz->trips.active[i].flags.enabled = 0; | 
 | 1287 | 				break; | 
 | 1288 | 			} | 
| Konstantin Karasyov | bed936f | 2006-07-10 04:44:26 -0700 | [diff] [blame] | 1289 | 		} | 
| Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1290 | 		tz->state.active |= tz->trips.active[i].flags.enabled; | 
| Konstantin Karasyov | bed936f | 2006-07-10 04:44:26 -0700 | [diff] [blame] | 1291 | 	} | 
 | 1292 |  | 
| Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1293 | 	acpi_thermal_check(tz); | 
| Konstantin Karasyov | 74ce146 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1294 |  | 
 | 1295 | 	return AE_OK; | 
 | 1296 | } | 
 | 1297 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1298 | static int __init acpi_thermal_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1300 | 	int result = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 |  | 
 | 1303 | 	acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir); | 
 | 1304 | 	if (!acpi_thermal_dir) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1305 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | 	acpi_thermal_dir->owner = THIS_MODULE; | 
 | 1307 |  | 
 | 1308 | 	result = acpi_bus_register_driver(&acpi_thermal_driver); | 
 | 1309 | 	if (result < 0) { | 
 | 1310 | 		remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1311 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | 	} | 
 | 1313 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1314 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | } | 
 | 1316 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1317 | static void __exit acpi_thermal_exit(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 |  | 
 | 1320 | 	acpi_bus_unregister_driver(&acpi_thermal_driver); | 
 | 1321 |  | 
 | 1322 | 	remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir); | 
 | 1323 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1324 | 	return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | } | 
 | 1326 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | module_init(acpi_thermal_init); | 
 | 1328 | module_exit(acpi_thermal_exit); |