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