thermal.c 33 KB

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