thermal.c 34 KB

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