thermal.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  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. acpi_status status;
  698. int i = 0;
  699. int j = 0;
  700. if (!tz)
  701. goto end;
  702. if (tz->trips.critical.flags.valid)
  703. seq_printf(seq, "critical (S5): %ld C\n",
  704. KELVIN_TO_CELSIUS(tz->trips.critical.temperature));
  705. if (tz->trips.hot.flags.valid)
  706. seq_printf(seq, "hot (S4): %ld C\n",
  707. KELVIN_TO_CELSIUS(tz->trips.hot.temperature));
  708. if (tz->trips.passive.flags.valid) {
  709. seq_printf(seq,
  710. "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
  711. KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
  712. tz->trips.passive.tc1, tz->trips.passive.tc2,
  713. tz->trips.passive.tsp);
  714. for (j = 0; j < tz->trips.passive.devices.count; j++) {
  715. status = acpi_bus_get_device(tz->trips.passive.devices.
  716. handles[j], &device);
  717. seq_printf(seq, "%4.4s ", status ? "" :
  718. acpi_device_bid(device));
  719. }
  720. seq_puts(seq, "\n");
  721. }
  722. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  723. if (!(tz->trips.active[i].flags.valid))
  724. break;
  725. seq_printf(seq, "active[%d]: %ld C: devices=",
  726. i,
  727. KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
  728. for (j = 0; j < tz->trips.active[i].devices.count; j++){
  729. status = acpi_bus_get_device(tz->trips.active[i].
  730. devices.handles[j],
  731. &device);
  732. seq_printf(seq, "%4.4s ", status ? "" :
  733. acpi_device_bid(device));
  734. }
  735. seq_puts(seq, "\n");
  736. }
  737. end:
  738. return 0;
  739. }
  740. static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
  741. {
  742. return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
  743. }
  744. static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
  745. {
  746. struct acpi_thermal *tz = seq->private;
  747. if (!tz)
  748. goto end;
  749. if (!tz->flags.cooling_mode)
  750. seq_puts(seq, "<setting not supported>\n");
  751. else
  752. seq_puts(seq, "0 - Active; 1 - Passive\n");
  753. end:
  754. return 0;
  755. }
  756. static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
  757. {
  758. return single_open(file, acpi_thermal_cooling_seq_show,
  759. PDE(inode)->data);
  760. }
  761. static ssize_t
  762. acpi_thermal_write_cooling_mode(struct file *file,
  763. const char __user * buffer,
  764. size_t count, loff_t * ppos)
  765. {
  766. struct seq_file *m = file->private_data;
  767. struct acpi_thermal *tz = m->private;
  768. int result = 0;
  769. char mode_string[12] = { '\0' };
  770. if (!tz || (count > sizeof(mode_string) - 1))
  771. return -EINVAL;
  772. if (!tz->flags.cooling_mode)
  773. return -ENODEV;
  774. if (copy_from_user(mode_string, buffer, count))
  775. return -EFAULT;
  776. mode_string[count] = '\0';
  777. result = acpi_thermal_set_cooling_mode(tz,
  778. simple_strtoul(mode_string, NULL,
  779. 0));
  780. if (result)
  781. return result;
  782. acpi_thermal_check(tz);
  783. return count;
  784. }
  785. static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
  786. {
  787. struct acpi_thermal *tz = seq->private;
  788. if (!tz)
  789. goto end;
  790. if (!tz->polling_frequency) {
  791. seq_puts(seq, "<polling disabled>\n");
  792. goto end;
  793. }
  794. seq_printf(seq, "polling frequency: %lu seconds\n",
  795. (tz->polling_frequency / 10));
  796. end:
  797. return 0;
  798. }
  799. static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
  800. {
  801. return single_open(file, acpi_thermal_polling_seq_show,
  802. PDE(inode)->data);
  803. }
  804. static ssize_t
  805. acpi_thermal_write_polling(struct file *file,
  806. const char __user * buffer,
  807. size_t count, loff_t * ppos)
  808. {
  809. struct seq_file *m = file->private_data;
  810. struct acpi_thermal *tz = m->private;
  811. int result = 0;
  812. char polling_string[12] = { '\0' };
  813. int seconds = 0;
  814. if (!tz || (count > sizeof(polling_string) - 1))
  815. return -EINVAL;
  816. if (copy_from_user(polling_string, buffer, count))
  817. return -EFAULT;
  818. polling_string[count] = '\0';
  819. seconds = simple_strtoul(polling_string, NULL, 0);
  820. result = acpi_thermal_set_polling(tz, seconds);
  821. if (result)
  822. return result;
  823. acpi_thermal_check(tz);
  824. return count;
  825. }
  826. static int acpi_thermal_add_fs(struct acpi_device *device)
  827. {
  828. struct proc_dir_entry *entry = NULL;
  829. if (!acpi_device_dir(device)) {
  830. acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
  831. acpi_thermal_dir);
  832. if (!acpi_device_dir(device))
  833. return -ENODEV;
  834. acpi_device_dir(device)->owner = THIS_MODULE;
  835. }
  836. /* 'state' [R] */
  837. entry = create_proc_entry(ACPI_THERMAL_FILE_STATE,
  838. S_IRUGO, acpi_device_dir(device));
  839. if (!entry)
  840. return -ENODEV;
  841. else {
  842. entry->proc_fops = &acpi_thermal_state_fops;
  843. entry->data = acpi_driver_data(device);
  844. entry->owner = THIS_MODULE;
  845. }
  846. /* 'temperature' [R] */
  847. entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
  848. S_IRUGO, acpi_device_dir(device));
  849. if (!entry)
  850. return -ENODEV;
  851. else {
  852. entry->proc_fops = &acpi_thermal_temp_fops;
  853. entry->data = acpi_driver_data(device);
  854. entry->owner = THIS_MODULE;
  855. }
  856. /* 'trip_points' [R/W] */
  857. entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
  858. S_IFREG | S_IRUGO | S_IWUSR,
  859. acpi_device_dir(device));
  860. if (!entry)
  861. return -ENODEV;
  862. else {
  863. entry->proc_fops = &acpi_thermal_trip_fops;
  864. entry->data = acpi_driver_data(device);
  865. entry->owner = THIS_MODULE;
  866. }
  867. /* 'cooling_mode' [R/W] */
  868. entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
  869. S_IFREG | S_IRUGO | S_IWUSR,
  870. acpi_device_dir(device));
  871. if (!entry)
  872. return -ENODEV;
  873. else {
  874. entry->proc_fops = &acpi_thermal_cooling_fops;
  875. entry->data = acpi_driver_data(device);
  876. entry->owner = THIS_MODULE;
  877. }
  878. /* 'polling_frequency' [R/W] */
  879. entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
  880. S_IFREG | S_IRUGO | S_IWUSR,
  881. acpi_device_dir(device));
  882. if (!entry)
  883. return -ENODEV;
  884. else {
  885. entry->proc_fops = &acpi_thermal_polling_fops;
  886. entry->data = acpi_driver_data(device);
  887. entry->owner = THIS_MODULE;
  888. }
  889. return 0;
  890. }
  891. static int acpi_thermal_remove_fs(struct acpi_device *device)
  892. {
  893. if (acpi_device_dir(device)) {
  894. remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
  895. acpi_device_dir(device));
  896. remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
  897. acpi_device_dir(device));
  898. remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
  899. acpi_device_dir(device));
  900. remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
  901. acpi_device_dir(device));
  902. remove_proc_entry(ACPI_THERMAL_FILE_STATE,
  903. acpi_device_dir(device));
  904. remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
  905. acpi_device_dir(device) = NULL;
  906. }
  907. return 0;
  908. }
  909. /* --------------------------------------------------------------------------
  910. Driver Interface
  911. -------------------------------------------------------------------------- */
  912. static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
  913. {
  914. struct acpi_thermal *tz = data;
  915. struct acpi_device *device = NULL;
  916. if (!tz)
  917. return;
  918. device = tz->device;
  919. switch (event) {
  920. case ACPI_THERMAL_NOTIFY_TEMPERATURE:
  921. acpi_thermal_check(tz);
  922. break;
  923. case ACPI_THERMAL_NOTIFY_THRESHOLDS:
  924. acpi_thermal_get_trip_points(tz);
  925. acpi_thermal_check(tz);
  926. acpi_bus_generate_event(device, event, 0);
  927. break;
  928. case ACPI_THERMAL_NOTIFY_DEVICES:
  929. if (tz->flags.devices)
  930. acpi_thermal_get_devices(tz);
  931. acpi_bus_generate_event(device, event, 0);
  932. break;
  933. default:
  934. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  935. "Unsupported event [0x%x]\n", event));
  936. break;
  937. }
  938. return;
  939. }
  940. static int acpi_thermal_get_info(struct acpi_thermal *tz)
  941. {
  942. int result = 0;
  943. if (!tz)
  944. return -EINVAL;
  945. /* Get temperature [_TMP] (required) */
  946. result = acpi_thermal_get_temperature(tz);
  947. if (result)
  948. return result;
  949. /* Get trip points [_CRT, _PSV, etc.] (required) */
  950. result = acpi_thermal_get_trip_points(tz);
  951. if (result)
  952. return result;
  953. /* Set the cooling mode [_SCP] to active cooling (default) */
  954. result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
  955. if (!result)
  956. tz->flags.cooling_mode = 1;
  957. /* Get default polling frequency [_TZP] (optional) */
  958. if (tzp)
  959. tz->polling_frequency = tzp;
  960. else
  961. acpi_thermal_get_polling_frequency(tz);
  962. /* Get devices in this thermal zone [_TZD] (optional) */
  963. result = acpi_thermal_get_devices(tz);
  964. if (!result)
  965. tz->flags.devices = 1;
  966. return 0;
  967. }
  968. static int acpi_thermal_add(struct acpi_device *device)
  969. {
  970. int result = 0;
  971. acpi_status status = AE_OK;
  972. struct acpi_thermal *tz = NULL;
  973. if (!device)
  974. return -EINVAL;
  975. tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
  976. if (!tz)
  977. return -ENOMEM;
  978. tz->device = device;
  979. strcpy(tz->name, device->pnp.bus_id);
  980. strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
  981. strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
  982. acpi_driver_data(device) = tz;
  983. result = acpi_thermal_get_info(tz);
  984. if (result)
  985. goto end;
  986. result = acpi_thermal_add_fs(device);
  987. if (result)
  988. goto end;
  989. init_timer(&tz->timer);
  990. acpi_thermal_check(tz);
  991. status = acpi_install_notify_handler(device->handle,
  992. ACPI_DEVICE_NOTIFY,
  993. acpi_thermal_notify, tz);
  994. if (ACPI_FAILURE(status)) {
  995. result = -ENODEV;
  996. goto end;
  997. }
  998. printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
  999. acpi_device_name(device), acpi_device_bid(device),
  1000. KELVIN_TO_CELSIUS(tz->temperature));
  1001. end:
  1002. if (result) {
  1003. acpi_thermal_remove_fs(device);
  1004. kfree(tz);
  1005. }
  1006. return result;
  1007. }
  1008. static int acpi_thermal_remove(struct acpi_device *device, int type)
  1009. {
  1010. acpi_status status = AE_OK;
  1011. struct acpi_thermal *tz = NULL;
  1012. if (!device || !acpi_driver_data(device))
  1013. return -EINVAL;
  1014. tz = acpi_driver_data(device);
  1015. /* avoid timer adding new defer task */
  1016. tz->zombie = 1;
  1017. /* wait for running timer (on other CPUs) finish */
  1018. del_timer_sync(&(tz->timer));
  1019. /* synchronize deferred task */
  1020. acpi_os_wait_events_complete(NULL);
  1021. /* deferred task may reinsert timer */
  1022. del_timer_sync(&(tz->timer));
  1023. status = acpi_remove_notify_handler(device->handle,
  1024. ACPI_DEVICE_NOTIFY,
  1025. acpi_thermal_notify);
  1026. /* Terminate policy */
  1027. if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
  1028. tz->trips.passive.flags.enabled = 0;
  1029. acpi_thermal_passive(tz);
  1030. }
  1031. if (tz->trips.active[0].flags.valid
  1032. && tz->trips.active[0].flags.enabled) {
  1033. tz->trips.active[0].flags.enabled = 0;
  1034. acpi_thermal_active(tz);
  1035. }
  1036. acpi_thermal_remove_fs(device);
  1037. kfree(tz);
  1038. return 0;
  1039. }
  1040. static int acpi_thermal_resume(struct acpi_device *device)
  1041. {
  1042. struct acpi_thermal *tz = NULL;
  1043. int i, j, power_state, result;
  1044. if (!device || !acpi_driver_data(device))
  1045. return -EINVAL;
  1046. tz = acpi_driver_data(device);
  1047. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  1048. if (!(&tz->trips.active[i]))
  1049. break;
  1050. if (!tz->trips.active[i].flags.valid)
  1051. break;
  1052. tz->trips.active[i].flags.enabled = 1;
  1053. for (j = 0; j < tz->trips.active[i].devices.count; j++) {
  1054. result = acpi_bus_get_power(tz->trips.active[i].devices.
  1055. handles[j], &power_state);
  1056. if (result || (power_state != ACPI_STATE_D0)) {
  1057. tz->trips.active[i].flags.enabled = 0;
  1058. break;
  1059. }
  1060. }
  1061. tz->state.active |= tz->trips.active[i].flags.enabled;
  1062. }
  1063. acpi_thermal_check(tz);
  1064. return AE_OK;
  1065. }
  1066. static int __init acpi_thermal_init(void)
  1067. {
  1068. int result = 0;
  1069. acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
  1070. if (!acpi_thermal_dir)
  1071. return -ENODEV;
  1072. acpi_thermal_dir->owner = THIS_MODULE;
  1073. result = acpi_bus_register_driver(&acpi_thermal_driver);
  1074. if (result < 0) {
  1075. remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
  1076. return -ENODEV;
  1077. }
  1078. return 0;
  1079. }
  1080. static void __exit acpi_thermal_exit(void)
  1081. {
  1082. acpi_bus_unregister_driver(&acpi_thermal_driver);
  1083. remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
  1084. return;
  1085. }
  1086. module_init(acpi_thermal_init);
  1087. module_exit(acpi_thermal_exit);