thermal.c 33 KB

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