thermal.c 34 KB

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