thermal.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882
  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/dmi.h>
  36. #include <linux/init.h>
  37. #include <linux/types.h>
  38. #include <linux/proc_fs.h>
  39. #include <linux/timer.h>
  40. #include <linux/jiffies.h>
  41. #include <linux/kmod.h>
  42. #include <linux/seq_file.h>
  43. #include <linux/reboot.h>
  44. #include <asm/uaccess.h>
  45. #include <linux/thermal.h>
  46. #include <acpi/acpi_bus.h>
  47. #include <acpi/acpi_drivers.h>
  48. #define ACPI_THERMAL_COMPONENT 0x04000000
  49. #define ACPI_THERMAL_CLASS "thermal_zone"
  50. #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
  51. #define ACPI_THERMAL_FILE_STATE "state"
  52. #define ACPI_THERMAL_FILE_TEMPERATURE "temperature"
  53. #define ACPI_THERMAL_FILE_TRIP_POINTS "trip_points"
  54. #define ACPI_THERMAL_FILE_COOLING_MODE "cooling_mode"
  55. #define ACPI_THERMAL_FILE_POLLING_FREQ "polling_frequency"
  56. #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80
  57. #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81
  58. #define ACPI_THERMAL_NOTIFY_DEVICES 0x82
  59. #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0
  60. #define ACPI_THERMAL_NOTIFY_HOT 0xF1
  61. #define ACPI_THERMAL_MODE_ACTIVE 0x00
  62. #define ACPI_THERMAL_MAX_ACTIVE 10
  63. #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
  64. #define _COMPONENT ACPI_THERMAL_COMPONENT
  65. ACPI_MODULE_NAME("thermal");
  66. MODULE_AUTHOR("Paul Diefenbaugh");
  67. MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
  68. MODULE_LICENSE("GPL");
  69. static int act;
  70. module_param(act, int, 0644);
  71. MODULE_PARM_DESC(act, "Disable or override all lowest active trip points.");
  72. static int crt;
  73. module_param(crt, int, 0644);
  74. MODULE_PARM_DESC(crt, "Disable or lower all critical trip points.");
  75. static int tzp;
  76. module_param(tzp, int, 0444);
  77. MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.");
  78. static int nocrt;
  79. module_param(nocrt, int, 0);
  80. MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points.");
  81. static int off;
  82. module_param(off, int, 0);
  83. MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.");
  84. static int psv;
  85. module_param(psv, int, 0644);
  86. MODULE_PARM_DESC(psv, "Disable or override all passive trip points.");
  87. static int acpi_thermal_add(struct acpi_device *device);
  88. static int acpi_thermal_remove(struct acpi_device *device, int type);
  89. static int acpi_thermal_resume(struct acpi_device *device);
  90. static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
  91. static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
  92. static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
  93. static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
  94. static ssize_t acpi_thermal_write_cooling_mode(struct file *,
  95. const char __user *, size_t,
  96. loff_t *);
  97. static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
  98. static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
  99. size_t, loff_t *);
  100. static const struct acpi_device_id thermal_device_ids[] = {
  101. {ACPI_THERMAL_HID, 0},
  102. {"", 0},
  103. };
  104. MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
  105. static struct acpi_driver acpi_thermal_driver = {
  106. .name = "thermal",
  107. .class = ACPI_THERMAL_CLASS,
  108. .ids = thermal_device_ids,
  109. .ops = {
  110. .add = acpi_thermal_add,
  111. .remove = acpi_thermal_remove,
  112. .resume = acpi_thermal_resume,
  113. },
  114. };
  115. struct acpi_thermal_state {
  116. u8 critical:1;
  117. u8 hot:1;
  118. u8 passive:1;
  119. u8 active:1;
  120. u8 reserved:4;
  121. int active_index;
  122. };
  123. struct acpi_thermal_state_flags {
  124. u8 valid:1;
  125. u8 enabled:1;
  126. u8 reserved:6;
  127. };
  128. struct acpi_thermal_critical {
  129. struct acpi_thermal_state_flags flags;
  130. unsigned long temperature;
  131. };
  132. struct acpi_thermal_hot {
  133. struct acpi_thermal_state_flags flags;
  134. unsigned long temperature;
  135. };
  136. struct acpi_thermal_passive {
  137. struct acpi_thermal_state_flags flags;
  138. unsigned long temperature;
  139. unsigned long tc1;
  140. unsigned long tc2;
  141. unsigned long tsp;
  142. struct acpi_handle_list devices;
  143. };
  144. struct acpi_thermal_active {
  145. struct acpi_thermal_state_flags flags;
  146. unsigned long temperature;
  147. struct acpi_handle_list devices;
  148. };
  149. struct acpi_thermal_trips {
  150. struct acpi_thermal_critical critical;
  151. struct acpi_thermal_hot hot;
  152. struct acpi_thermal_passive passive;
  153. struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
  154. };
  155. struct acpi_thermal_flags {
  156. u8 cooling_mode:1; /* _SCP */
  157. u8 devices:1; /* _TZD */
  158. u8 reserved:6;
  159. };
  160. struct acpi_thermal {
  161. struct acpi_device * device;
  162. acpi_bus_id name;
  163. unsigned long temperature;
  164. unsigned long last_temperature;
  165. unsigned long polling_frequency;
  166. volatile u8 zombie;
  167. struct acpi_thermal_flags flags;
  168. struct acpi_thermal_state state;
  169. struct acpi_thermal_trips trips;
  170. struct acpi_handle_list devices;
  171. struct timer_list timer;
  172. struct thermal_zone_device *thermal_zone;
  173. int tz_enabled;
  174. struct mutex lock;
  175. };
  176. static const struct file_operations acpi_thermal_state_fops = {
  177. .owner = THIS_MODULE,
  178. .open = acpi_thermal_state_open_fs,
  179. .read = seq_read,
  180. .llseek = seq_lseek,
  181. .release = single_release,
  182. };
  183. static const struct file_operations acpi_thermal_temp_fops = {
  184. .owner = THIS_MODULE,
  185. .open = acpi_thermal_temp_open_fs,
  186. .read = seq_read,
  187. .llseek = seq_lseek,
  188. .release = single_release,
  189. };
  190. static const struct file_operations acpi_thermal_trip_fops = {
  191. .owner = THIS_MODULE,
  192. .open = acpi_thermal_trip_open_fs,
  193. .read = seq_read,
  194. .llseek = seq_lseek,
  195. .release = single_release,
  196. };
  197. static const struct file_operations acpi_thermal_cooling_fops = {
  198. .owner = THIS_MODULE,
  199. .open = acpi_thermal_cooling_open_fs,
  200. .read = seq_read,
  201. .write = acpi_thermal_write_cooling_mode,
  202. .llseek = seq_lseek,
  203. .release = single_release,
  204. };
  205. static const struct file_operations acpi_thermal_polling_fops = {
  206. .owner = THIS_MODULE,
  207. .open = acpi_thermal_polling_open_fs,
  208. .read = seq_read,
  209. .write = acpi_thermal_write_polling,
  210. .llseek = seq_lseek,
  211. .release = single_release,
  212. };
  213. /* --------------------------------------------------------------------------
  214. Thermal Zone Management
  215. -------------------------------------------------------------------------- */
  216. static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
  217. {
  218. acpi_status status = AE_OK;
  219. if (!tz)
  220. return -EINVAL;
  221. tz->last_temperature = tz->temperature;
  222. status =
  223. acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tz->temperature);
  224. if (ACPI_FAILURE(status))
  225. return -ENODEV;
  226. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
  227. tz->temperature));
  228. return 0;
  229. }
  230. static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
  231. {
  232. acpi_status status = AE_OK;
  233. if (!tz)
  234. return -EINVAL;
  235. status =
  236. acpi_evaluate_integer(tz->device->handle, "_TZP", NULL,
  237. &tz->polling_frequency);
  238. if (ACPI_FAILURE(status))
  239. return -ENODEV;
  240. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
  241. tz->polling_frequency));
  242. return 0;
  243. }
  244. static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
  245. {
  246. if (!tz)
  247. return -EINVAL;
  248. tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
  249. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  250. "Polling frequency set to %lu seconds\n",
  251. tz->polling_frequency/10));
  252. return 0;
  253. }
  254. static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
  255. {
  256. acpi_status status = AE_OK;
  257. union acpi_object arg0 = { ACPI_TYPE_INTEGER };
  258. struct acpi_object_list arg_list = { 1, &arg0 };
  259. acpi_handle handle = NULL;
  260. if (!tz)
  261. return -EINVAL;
  262. status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
  263. if (ACPI_FAILURE(status)) {
  264. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
  265. return -ENODEV;
  266. }
  267. arg0.integer.value = mode;
  268. status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
  269. if (ACPI_FAILURE(status))
  270. return -ENODEV;
  271. return 0;
  272. }
  273. #define ACPI_TRIPS_CRITICAL 0x01
  274. #define ACPI_TRIPS_HOT 0x02
  275. #define ACPI_TRIPS_PASSIVE 0x04
  276. #define ACPI_TRIPS_ACTIVE 0x08
  277. #define ACPI_TRIPS_DEVICES 0x10
  278. #define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE)
  279. #define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES
  280. #define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \
  281. ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \
  282. ACPI_TRIPS_DEVICES)
  283. /*
  284. * This exception is thrown out in two cases:
  285. * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
  286. * when re-evaluating the AML code.
  287. * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change.
  288. * We need to re-bind the cooling devices of a thermal zone when this occurs.
  289. */
  290. #define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \
  291. do { \
  292. if (flags != ACPI_TRIPS_INIT) \
  293. ACPI_EXCEPTION((AE_INFO, AE_ERROR, \
  294. "ACPI thermal trip point %s changed\n" \
  295. "Please send acpidump to linux-acpi@vger.kernel.org\n", str)); \
  296. } while (0)
  297. static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
  298. {
  299. acpi_status status = AE_OK;
  300. struct acpi_handle_list devices;
  301. int valid = 0;
  302. int i;
  303. /* Critical Shutdown (required) */
  304. if (flag & ACPI_TRIPS_CRITICAL) {
  305. status = acpi_evaluate_integer(tz->device->handle,
  306. "_CRT", NULL, &tz->trips.critical.temperature);
  307. /*
  308. * Treat freezing temperatures as invalid as well; some
  309. * BIOSes return really low values and cause reboots at startup.
  310. * Below zero (Celcius) values clearly aren't right for sure..
  311. * ... so lets discard those as invalid.
  312. */
  313. if (ACPI_FAILURE(status) ||
  314. tz->trips.critical.temperature <= 2732) {
  315. tz->trips.critical.flags.valid = 0;
  316. ACPI_EXCEPTION((AE_INFO, status,
  317. "No or invalid critical threshold"));
  318. return -ENODEV;
  319. } else {
  320. tz->trips.critical.flags.valid = 1;
  321. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  322. "Found critical threshold [%lu]\n",
  323. tz->trips.critical.temperature));
  324. }
  325. if (tz->trips.critical.flags.valid == 1) {
  326. if (crt == -1) {
  327. tz->trips.critical.flags.valid = 0;
  328. } else if (crt > 0) {
  329. unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
  330. /*
  331. * Allow override critical threshold
  332. */
  333. if (crt_k > tz->trips.critical.temperature)
  334. printk(KERN_WARNING PREFIX
  335. "Critical threshold %d C\n", crt);
  336. tz->trips.critical.temperature = crt_k;
  337. }
  338. }
  339. }
  340. /* Critical Sleep (optional) */
  341. if (flag & ACPI_TRIPS_HOT) {
  342. status = acpi_evaluate_integer(tz->device->handle,
  343. "_HOT", NULL, &tz->trips.hot.temperature);
  344. if (ACPI_FAILURE(status)) {
  345. tz->trips.hot.flags.valid = 0;
  346. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  347. "No hot threshold\n"));
  348. } else {
  349. tz->trips.hot.flags.valid = 1;
  350. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  351. "Found hot threshold [%lu]\n",
  352. tz->trips.critical.temperature));
  353. }
  354. }
  355. /* Passive (optional) */
  356. if (flag & ACPI_TRIPS_PASSIVE) {
  357. valid = tz->trips.passive.flags.valid;
  358. if (psv == -1) {
  359. status = AE_SUPPORT;
  360. } else if (psv > 0) {
  361. tz->trips.passive.temperature = CELSIUS_TO_KELVIN(psv);
  362. status = AE_OK;
  363. } else {
  364. status = acpi_evaluate_integer(tz->device->handle,
  365. "_PSV", NULL, &tz->trips.passive.temperature);
  366. }
  367. if (ACPI_FAILURE(status))
  368. tz->trips.passive.flags.valid = 0;
  369. else {
  370. tz->trips.passive.flags.valid = 1;
  371. if (flag == ACPI_TRIPS_INIT) {
  372. status = acpi_evaluate_integer(
  373. tz->device->handle, "_TC1",
  374. NULL, &tz->trips.passive.tc1);
  375. if (ACPI_FAILURE(status))
  376. tz->trips.passive.flags.valid = 0;
  377. status = acpi_evaluate_integer(
  378. tz->device->handle, "_TC2",
  379. NULL, &tz->trips.passive.tc2);
  380. if (ACPI_FAILURE(status))
  381. tz->trips.passive.flags.valid = 0;
  382. status = acpi_evaluate_integer(
  383. tz->device->handle, "_TSP",
  384. NULL, &tz->trips.passive.tsp);
  385. if (ACPI_FAILURE(status))
  386. tz->trips.passive.flags.valid = 0;
  387. }
  388. }
  389. }
  390. if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) {
  391. memset(&devices, 0, sizeof(struct acpi_handle_list));
  392. status = acpi_evaluate_reference(tz->device->handle, "_PSL",
  393. NULL, &devices);
  394. if (ACPI_FAILURE(status))
  395. tz->trips.passive.flags.valid = 0;
  396. else
  397. tz->trips.passive.flags.valid = 1;
  398. if (memcmp(&tz->trips.passive.devices, &devices,
  399. sizeof(struct acpi_handle_list))) {
  400. memcpy(&tz->trips.passive.devices, &devices,
  401. sizeof(struct acpi_handle_list));
  402. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
  403. }
  404. }
  405. if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) {
  406. if (valid != tz->trips.passive.flags.valid)
  407. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
  408. }
  409. /* Active (optional) */
  410. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  411. char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
  412. valid = tz->trips.active[i].flags.valid;
  413. if (act == -1)
  414. break; /* disable all active trip points */
  415. if (flag & ACPI_TRIPS_ACTIVE) {
  416. status = acpi_evaluate_integer(tz->device->handle,
  417. name, NULL, &tz->trips.active[i].temperature);
  418. if (ACPI_FAILURE(status)) {
  419. tz->trips.active[i].flags.valid = 0;
  420. if (i == 0)
  421. break;
  422. if (act <= 0)
  423. break;
  424. if (i == 1)
  425. tz->trips.active[0].temperature =
  426. CELSIUS_TO_KELVIN(act);
  427. else
  428. /*
  429. * Don't allow override higher than
  430. * the next higher trip point
  431. */
  432. tz->trips.active[i - 1].temperature =
  433. (tz->trips.active[i - 2].temperature <
  434. CELSIUS_TO_KELVIN(act) ?
  435. tz->trips.active[i - 2].temperature :
  436. CELSIUS_TO_KELVIN(act));
  437. break;
  438. } else
  439. tz->trips.active[i].flags.valid = 1;
  440. }
  441. name[2] = 'L';
  442. if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) {
  443. memset(&devices, 0, sizeof(struct acpi_handle_list));
  444. status = acpi_evaluate_reference(tz->device->handle,
  445. name, NULL, &devices);
  446. if (ACPI_FAILURE(status))
  447. tz->trips.active[i].flags.valid = 0;
  448. else
  449. tz->trips.active[i].flags.valid = 1;
  450. if (memcmp(&tz->trips.active[i].devices, &devices,
  451. sizeof(struct acpi_handle_list))) {
  452. memcpy(&tz->trips.active[i].devices, &devices,
  453. sizeof(struct acpi_handle_list));
  454. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
  455. }
  456. }
  457. if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES))
  458. if (valid != tz->trips.active[i].flags.valid)
  459. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
  460. if (!tz->trips.active[i].flags.valid)
  461. break;
  462. }
  463. if (flag & ACPI_TRIPS_DEVICES) {
  464. memset(&devices, 0, sizeof(struct acpi_handle_list));
  465. status = acpi_evaluate_reference(tz->device->handle, "_TZD",
  466. NULL, &devices);
  467. if (memcmp(&tz->devices, &devices,
  468. sizeof(struct acpi_handle_list))) {
  469. memcpy(&tz->devices, &devices,
  470. sizeof(struct acpi_handle_list));
  471. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
  472. }
  473. }
  474. return 0;
  475. }
  476. static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
  477. {
  478. return acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
  479. }
  480. static int acpi_thermal_critical(struct acpi_thermal *tz)
  481. {
  482. if (!tz || !tz->trips.critical.flags.valid)
  483. return -EINVAL;
  484. if (tz->temperature >= tz->trips.critical.temperature) {
  485. printk(KERN_WARNING PREFIX "Critical trip point\n");
  486. tz->trips.critical.flags.enabled = 1;
  487. } else if (tz->trips.critical.flags.enabled)
  488. tz->trips.critical.flags.enabled = 0;
  489. acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL,
  490. tz->trips.critical.flags.enabled);
  491. acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
  492. tz->device->dev.bus_id,
  493. ACPI_THERMAL_NOTIFY_CRITICAL,
  494. tz->trips.critical.flags.enabled);
  495. /* take no action if nocrt is set */
  496. if(!nocrt) {
  497. printk(KERN_EMERG
  498. "Critical temperature reached (%ld C), shutting down.\n",
  499. KELVIN_TO_CELSIUS(tz->temperature));
  500. orderly_poweroff(true);
  501. }
  502. return 0;
  503. }
  504. static int acpi_thermal_hot(struct acpi_thermal *tz)
  505. {
  506. if (!tz || !tz->trips.hot.flags.valid)
  507. return -EINVAL;
  508. if (tz->temperature >= tz->trips.hot.temperature) {
  509. printk(KERN_WARNING PREFIX "Hot trip point\n");
  510. tz->trips.hot.flags.enabled = 1;
  511. } else if (tz->trips.hot.flags.enabled)
  512. tz->trips.hot.flags.enabled = 0;
  513. acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
  514. tz->trips.hot.flags.enabled);
  515. acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
  516. tz->device->dev.bus_id,
  517. ACPI_THERMAL_NOTIFY_HOT,
  518. tz->trips.hot.flags.enabled);
  519. /* TBD: Call user-mode "sleep(S4)" function if nocrt is cleared */
  520. return 0;
  521. }
  522. static void acpi_thermal_passive(struct acpi_thermal *tz)
  523. {
  524. int result = 1;
  525. struct acpi_thermal_passive *passive = NULL;
  526. int trend = 0;
  527. int i = 0;
  528. if (!tz || !tz->trips.passive.flags.valid)
  529. return;
  530. passive = &(tz->trips.passive);
  531. /*
  532. * Above Trip?
  533. * -----------
  534. * Calculate the thermal trend (using the passive cooling equation)
  535. * and modify the performance limit for all passive cooling devices
  536. * accordingly. Note that we assume symmetry.
  537. */
  538. if (tz->temperature >= passive->temperature) {
  539. trend =
  540. (passive->tc1 * (tz->temperature - tz->last_temperature)) +
  541. (passive->tc2 * (tz->temperature - passive->temperature));
  542. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  543. "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
  544. trend, passive->tc1, tz->temperature,
  545. tz->last_temperature, passive->tc2,
  546. tz->temperature, passive->temperature));
  547. passive->flags.enabled = 1;
  548. /* Heating up? */
  549. if (trend > 0)
  550. for (i = 0; i < passive->devices.count; i++)
  551. acpi_processor_set_thermal_limit(passive->
  552. devices.
  553. handles[i],
  554. ACPI_PROCESSOR_LIMIT_INCREMENT);
  555. /* Cooling off? */
  556. else if (trend < 0) {
  557. for (i = 0; i < passive->devices.count; i++)
  558. /*
  559. * assume that we are on highest
  560. * freq/lowest thrott and can leave
  561. * passive mode, even in error case
  562. */
  563. if (!acpi_processor_set_thermal_limit
  564. (passive->devices.handles[i],
  565. ACPI_PROCESSOR_LIMIT_DECREMENT))
  566. result = 0;
  567. /*
  568. * Leave cooling mode, even if the temp might
  569. * higher than trip point This is because some
  570. * machines might have long thermal polling
  571. * frequencies (tsp) defined. We will fall back
  572. * into passive mode in next cycle (probably quicker)
  573. */
  574. if (result) {
  575. passive->flags.enabled = 0;
  576. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  577. "Disabling passive cooling, still above threshold,"
  578. " but we are cooling down\n"));
  579. }
  580. }
  581. return;
  582. }
  583. /*
  584. * Below Trip?
  585. * -----------
  586. * Implement passive cooling hysteresis to slowly increase performance
  587. * and avoid thrashing around the passive trip point. Note that we
  588. * assume symmetry.
  589. */
  590. if (!passive->flags.enabled)
  591. return;
  592. for (i = 0; i < passive->devices.count; i++)
  593. if (!acpi_processor_set_thermal_limit
  594. (passive->devices.handles[i],
  595. ACPI_PROCESSOR_LIMIT_DECREMENT))
  596. result = 0;
  597. if (result) {
  598. passive->flags.enabled = 0;
  599. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  600. "Disabling passive cooling (zone is cool)\n"));
  601. }
  602. }
  603. static void acpi_thermal_active(struct acpi_thermal *tz)
  604. {
  605. int result = 0;
  606. struct acpi_thermal_active *active = NULL;
  607. int i = 0;
  608. int j = 0;
  609. unsigned long maxtemp = 0;
  610. if (!tz)
  611. return;
  612. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  613. active = &(tz->trips.active[i]);
  614. if (!active || !active->flags.valid)
  615. break;
  616. if (tz->temperature >= active->temperature) {
  617. /*
  618. * Above Threshold?
  619. * ----------------
  620. * If not already enabled, turn ON all cooling devices
  621. * associated with this active threshold.
  622. */
  623. if (active->temperature > maxtemp)
  624. tz->state.active_index = i;
  625. maxtemp = active->temperature;
  626. if (active->flags.enabled)
  627. continue;
  628. for (j = 0; j < active->devices.count; j++) {
  629. result =
  630. acpi_bus_set_power(active->devices.
  631. handles[j],
  632. ACPI_STATE_D0);
  633. if (result) {
  634. printk(KERN_WARNING PREFIX
  635. "Unable to turn cooling device [%p] 'on'\n",
  636. active->devices.
  637. handles[j]);
  638. continue;
  639. }
  640. active->flags.enabled = 1;
  641. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  642. "Cooling device [%p] now 'on'\n",
  643. active->devices.handles[j]));
  644. }
  645. continue;
  646. }
  647. if (!active->flags.enabled)
  648. continue;
  649. /*
  650. * Below Threshold?
  651. * ----------------
  652. * Turn OFF all cooling devices associated with this
  653. * threshold.
  654. */
  655. for (j = 0; j < active->devices.count; j++) {
  656. result = acpi_bus_set_power(active->devices.handles[j],
  657. ACPI_STATE_D3);
  658. if (result) {
  659. printk(KERN_WARNING PREFIX
  660. "Unable to turn cooling device [%p] 'off'\n",
  661. active->devices.handles[j]);
  662. continue;
  663. }
  664. active->flags.enabled = 0;
  665. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  666. "Cooling device [%p] now 'off'\n",
  667. active->devices.handles[j]));
  668. }
  669. }
  670. }
  671. static void acpi_thermal_check(void *context);
  672. static void acpi_thermal_run(unsigned long data)
  673. {
  674. struct acpi_thermal *tz = (struct acpi_thermal *)data;
  675. if (!tz->zombie)
  676. acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data);
  677. }
  678. static void acpi_thermal_active_off(void *data)
  679. {
  680. int result = 0;
  681. struct acpi_thermal *tz = data;
  682. int i = 0;
  683. int j = 0;
  684. struct acpi_thermal_active *active = NULL;
  685. if (!tz) {
  686. printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
  687. return;
  688. }
  689. result = acpi_thermal_get_temperature(tz);
  690. if (result)
  691. return;
  692. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  693. active = &(tz->trips.active[i]);
  694. if (!active || !active->flags.valid)
  695. break;
  696. if (tz->temperature >= active->temperature) {
  697. /*
  698. * If the thermal temperature is greater than the
  699. * active threshod, unnecessary to turn off the
  700. * the active cooling device.
  701. */
  702. continue;
  703. }
  704. /*
  705. * Below Threshold?
  706. * ----------------
  707. * Turn OFF all cooling devices associated with this
  708. * threshold.
  709. */
  710. for (j = 0; j < active->devices.count; j++)
  711. result = acpi_bus_set_power(active->devices.handles[j],
  712. ACPI_STATE_D3);
  713. }
  714. }
  715. static void acpi_thermal_check(void *data)
  716. {
  717. int result = 0;
  718. struct acpi_thermal *tz = data;
  719. unsigned long sleep_time = 0;
  720. unsigned long timeout_jiffies = 0;
  721. int i = 0;
  722. struct acpi_thermal_state state;
  723. if (!tz) {
  724. printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
  725. return;
  726. }
  727. /* Check if someone else is already running */
  728. if (!mutex_trylock(&tz->lock))
  729. return;
  730. state = tz->state;
  731. result = acpi_thermal_get_temperature(tz);
  732. if (result)
  733. goto unlock;
  734. if (!tz->tz_enabled)
  735. goto unlock;
  736. memset(&tz->state, 0, sizeof(tz->state));
  737. /*
  738. * Check Trip Points
  739. * -----------------
  740. * Compare the current temperature to the trip point values to see
  741. * if we've entered one of the thermal policy states. Note that
  742. * this function determines when a state is entered, but the
  743. * individual policy decides when it is exited (e.g. hysteresis).
  744. */
  745. if (tz->trips.critical.flags.valid)
  746. state.critical |=
  747. (tz->temperature >= tz->trips.critical.temperature);
  748. if (tz->trips.hot.flags.valid)
  749. state.hot |= (tz->temperature >= tz->trips.hot.temperature);
  750. if (tz->trips.passive.flags.valid)
  751. state.passive |=
  752. (tz->temperature >= tz->trips.passive.temperature);
  753. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
  754. if (tz->trips.active[i].flags.valid)
  755. state.active |=
  756. (tz->temperature >=
  757. tz->trips.active[i].temperature);
  758. /*
  759. * Invoke Policy
  760. * -------------
  761. * Separated from the above check to allow individual policy to
  762. * determine when to exit a given state.
  763. */
  764. if (state.critical)
  765. acpi_thermal_critical(tz);
  766. if (state.hot)
  767. acpi_thermal_hot(tz);
  768. if (state.passive)
  769. acpi_thermal_passive(tz);
  770. if (state.active)
  771. acpi_thermal_active(tz);
  772. /*
  773. * Calculate State
  774. * ---------------
  775. * Again, separated from the above two to allow independent policy
  776. * decisions.
  777. */
  778. tz->state.critical = tz->trips.critical.flags.enabled;
  779. tz->state.hot = tz->trips.hot.flags.enabled;
  780. tz->state.passive = tz->trips.passive.flags.enabled;
  781. tz->state.active = 0;
  782. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
  783. tz->state.active |= tz->trips.active[i].flags.enabled;
  784. /*
  785. * Calculate Sleep Time
  786. * --------------------
  787. * If we're in the passive state, use _TSP's value. Otherwise
  788. * use the default polling frequency (e.g. _TZP). If no polling
  789. * frequency is specified then we'll wait forever (at least until
  790. * a thermal event occurs). Note that _TSP and _TZD values are
  791. * given in 1/10th seconds (we must covert to milliseconds).
  792. */
  793. if (tz->state.passive) {
  794. sleep_time = tz->trips.passive.tsp * 100;
  795. timeout_jiffies = jiffies + (HZ * sleep_time) / 1000;
  796. } else if (tz->polling_frequency > 0) {
  797. sleep_time = tz->polling_frequency * 100;
  798. timeout_jiffies = round_jiffies(jiffies + (HZ * sleep_time) / 1000);
  799. }
  800. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n",
  801. tz->name, tz->temperature, sleep_time));
  802. /*
  803. * Schedule Next Poll
  804. * ------------------
  805. */
  806. if (!sleep_time) {
  807. if (timer_pending(&(tz->timer)))
  808. del_timer(&(tz->timer));
  809. } else {
  810. if (timer_pending(&(tz->timer)))
  811. mod_timer(&(tz->timer), timeout_jiffies);
  812. else {
  813. tz->timer.data = (unsigned long)tz;
  814. tz->timer.function = acpi_thermal_run;
  815. tz->timer.expires = timeout_jiffies;
  816. add_timer(&(tz->timer));
  817. }
  818. }
  819. unlock:
  820. mutex_unlock(&tz->lock);
  821. }
  822. /* sys I/F for generic thermal sysfs support */
  823. #define KELVIN_TO_MILLICELSIUS(t) (t * 100 - 273200)
  824. static int thermal_get_temp(struct thermal_zone_device *thermal, char *buf)
  825. {
  826. struct acpi_thermal *tz = thermal->devdata;
  827. int result;
  828. if (!tz)
  829. return -EINVAL;
  830. result = acpi_thermal_get_temperature(tz);
  831. if (result)
  832. return result;
  833. return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS(tz->temperature));
  834. }
  835. static const char enabled[] = "kernel";
  836. static const char disabled[] = "user";
  837. static int thermal_get_mode(struct thermal_zone_device *thermal,
  838. char *buf)
  839. {
  840. struct acpi_thermal *tz = thermal->devdata;
  841. if (!tz)
  842. return -EINVAL;
  843. return sprintf(buf, "%s\n", tz->tz_enabled ?
  844. enabled : disabled);
  845. }
  846. static int thermal_set_mode(struct thermal_zone_device *thermal,
  847. const char *buf)
  848. {
  849. struct acpi_thermal *tz = thermal->devdata;
  850. int enable;
  851. if (!tz)
  852. return -EINVAL;
  853. /*
  854. * enable/disable thermal management from ACPI thermal driver
  855. */
  856. if (!strncmp(buf, enabled, sizeof enabled - 1))
  857. enable = 1;
  858. else if (!strncmp(buf, disabled, sizeof disabled - 1))
  859. enable = 0;
  860. else
  861. return -EINVAL;
  862. if (enable != tz->tz_enabled) {
  863. tz->tz_enabled = enable;
  864. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  865. "%s ACPI thermal control\n",
  866. tz->tz_enabled ? enabled : disabled));
  867. acpi_thermal_check(tz);
  868. }
  869. return 0;
  870. }
  871. static int thermal_get_trip_type(struct thermal_zone_device *thermal,
  872. int trip, char *buf)
  873. {
  874. struct acpi_thermal *tz = thermal->devdata;
  875. int i;
  876. if (!tz || trip < 0)
  877. return -EINVAL;
  878. if (tz->trips.critical.flags.valid) {
  879. if (!trip)
  880. return sprintf(buf, "critical\n");
  881. trip--;
  882. }
  883. if (tz->trips.hot.flags.valid) {
  884. if (!trip)
  885. return sprintf(buf, "hot\n");
  886. trip--;
  887. }
  888. if (tz->trips.passive.flags.valid) {
  889. if (!trip)
  890. return sprintf(buf, "passive\n");
  891. trip--;
  892. }
  893. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
  894. tz->trips.active[i].flags.valid; i++) {
  895. if (!trip)
  896. return sprintf(buf, "active%d\n", i);
  897. trip--;
  898. }
  899. return -EINVAL;
  900. }
  901. static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
  902. int trip, char *buf)
  903. {
  904. struct acpi_thermal *tz = thermal->devdata;
  905. int i;
  906. if (!tz || trip < 0)
  907. return -EINVAL;
  908. if (tz->trips.critical.flags.valid) {
  909. if (!trip)
  910. return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS(
  911. tz->trips.critical.temperature));
  912. trip--;
  913. }
  914. if (tz->trips.hot.flags.valid) {
  915. if (!trip)
  916. return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS(
  917. tz->trips.hot.temperature));
  918. trip--;
  919. }
  920. if (tz->trips.passive.flags.valid) {
  921. if (!trip)
  922. return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS(
  923. tz->trips.passive.temperature));
  924. trip--;
  925. }
  926. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
  927. tz->trips.active[i].flags.valid; i++) {
  928. if (!trip)
  929. return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS(
  930. tz->trips.active[i].temperature));
  931. trip--;
  932. }
  933. return -EINVAL;
  934. }
  935. static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
  936. unsigned long *temperature) {
  937. struct acpi_thermal *tz = thermal->devdata;
  938. if (tz->trips.critical.flags.valid) {
  939. *temperature = KELVIN_TO_MILLICELSIUS(
  940. tz->trips.critical.temperature);
  941. return 0;
  942. } else
  943. return -EINVAL;
  944. }
  945. typedef int (*cb)(struct thermal_zone_device *, int,
  946. struct thermal_cooling_device *);
  947. static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
  948. struct thermal_cooling_device *cdev,
  949. cb action)
  950. {
  951. struct acpi_device *device = cdev->devdata;
  952. struct acpi_thermal *tz = thermal->devdata;
  953. struct acpi_device *dev;
  954. acpi_status status;
  955. acpi_handle handle;
  956. int i;
  957. int j;
  958. int trip = -1;
  959. int result = 0;
  960. if (tz->trips.critical.flags.valid)
  961. trip++;
  962. if (tz->trips.hot.flags.valid)
  963. trip++;
  964. if (tz->trips.passive.flags.valid) {
  965. trip++;
  966. for (i = 0; i < tz->trips.passive.devices.count;
  967. i++) {
  968. handle = tz->trips.passive.devices.handles[i];
  969. status = acpi_bus_get_device(handle, &dev);
  970. if (ACPI_SUCCESS(status) && (dev == device)) {
  971. result = action(thermal, trip, cdev);
  972. if (result)
  973. goto failed;
  974. }
  975. }
  976. }
  977. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  978. if (!tz->trips.active[i].flags.valid)
  979. break;
  980. trip++;
  981. for (j = 0;
  982. j < tz->trips.active[i].devices.count;
  983. j++) {
  984. handle = tz->trips.active[i].devices.handles[j];
  985. status = acpi_bus_get_device(handle, &dev);
  986. if (ACPI_SUCCESS(status) && (dev == device)) {
  987. result = action(thermal, trip, cdev);
  988. if (result)
  989. goto failed;
  990. }
  991. }
  992. }
  993. for (i = 0; i < tz->devices.count; i++) {
  994. handle = tz->devices.handles[i];
  995. status = acpi_bus_get_device(handle, &dev);
  996. if (ACPI_SUCCESS(status) && (dev == device)) {
  997. result = action(thermal, -1, cdev);
  998. if (result)
  999. goto failed;
  1000. }
  1001. }
  1002. failed:
  1003. return result;
  1004. }
  1005. static int
  1006. acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
  1007. struct thermal_cooling_device *cdev)
  1008. {
  1009. return acpi_thermal_cooling_device_cb(thermal, cdev,
  1010. thermal_zone_bind_cooling_device);
  1011. }
  1012. static int
  1013. acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
  1014. struct thermal_cooling_device *cdev)
  1015. {
  1016. return acpi_thermal_cooling_device_cb(thermal, cdev,
  1017. thermal_zone_unbind_cooling_device);
  1018. }
  1019. static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
  1020. .bind = acpi_thermal_bind_cooling_device,
  1021. .unbind = acpi_thermal_unbind_cooling_device,
  1022. .get_temp = thermal_get_temp,
  1023. .get_mode = thermal_get_mode,
  1024. .set_mode = thermal_set_mode,
  1025. .get_trip_type = thermal_get_trip_type,
  1026. .get_trip_temp = thermal_get_trip_temp,
  1027. .get_crit_temp = thermal_get_crit_temp,
  1028. };
  1029. static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
  1030. {
  1031. int trips = 0;
  1032. int result;
  1033. acpi_status status;
  1034. int i;
  1035. if (tz->trips.critical.flags.valid)
  1036. trips++;
  1037. if (tz->trips.hot.flags.valid)
  1038. trips++;
  1039. if (tz->trips.passive.flags.valid)
  1040. trips++;
  1041. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
  1042. tz->trips.active[i].flags.valid; i++, trips++);
  1043. tz->thermal_zone = thermal_zone_device_register("acpitz",
  1044. trips, tz, &acpi_thermal_zone_ops);
  1045. if (IS_ERR(tz->thermal_zone))
  1046. return -ENODEV;
  1047. result = sysfs_create_link(&tz->device->dev.kobj,
  1048. &tz->thermal_zone->device.kobj, "thermal_zone");
  1049. if (result)
  1050. return result;
  1051. result = sysfs_create_link(&tz->thermal_zone->device.kobj,
  1052. &tz->device->dev.kobj, "device");
  1053. if (result)
  1054. return result;
  1055. status = acpi_attach_data(tz->device->handle,
  1056. acpi_bus_private_data_handler,
  1057. tz->thermal_zone);
  1058. if (ACPI_FAILURE(status)) {
  1059. printk(KERN_ERR PREFIX
  1060. "Error attaching device data\n");
  1061. return -ENODEV;
  1062. }
  1063. tz->tz_enabled = 1;
  1064. dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
  1065. tz->thermal_zone->id);
  1066. return 0;
  1067. }
  1068. static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
  1069. {
  1070. sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
  1071. sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
  1072. thermal_zone_device_unregister(tz->thermal_zone);
  1073. tz->thermal_zone = NULL;
  1074. acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler);
  1075. }
  1076. /* --------------------------------------------------------------------------
  1077. FS Interface (/proc)
  1078. -------------------------------------------------------------------------- */
  1079. static struct proc_dir_entry *acpi_thermal_dir;
  1080. static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
  1081. {
  1082. struct acpi_thermal *tz = seq->private;
  1083. if (!tz)
  1084. goto end;
  1085. seq_puts(seq, "state: ");
  1086. if (!tz->state.critical && !tz->state.hot && !tz->state.passive
  1087. && !tz->state.active)
  1088. seq_puts(seq, "ok\n");
  1089. else {
  1090. if (tz->state.critical)
  1091. seq_puts(seq, "critical ");
  1092. if (tz->state.hot)
  1093. seq_puts(seq, "hot ");
  1094. if (tz->state.passive)
  1095. seq_puts(seq, "passive ");
  1096. if (tz->state.active)
  1097. seq_printf(seq, "active[%d]", tz->state.active_index);
  1098. seq_puts(seq, "\n");
  1099. }
  1100. end:
  1101. return 0;
  1102. }
  1103. static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
  1104. {
  1105. return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
  1106. }
  1107. static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
  1108. {
  1109. int result = 0;
  1110. struct acpi_thermal *tz = seq->private;
  1111. if (!tz)
  1112. goto end;
  1113. result = acpi_thermal_get_temperature(tz);
  1114. if (result)
  1115. goto end;
  1116. seq_printf(seq, "temperature: %ld C\n",
  1117. KELVIN_TO_CELSIUS(tz->temperature));
  1118. end:
  1119. return 0;
  1120. }
  1121. static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
  1122. {
  1123. return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
  1124. }
  1125. static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
  1126. {
  1127. struct acpi_thermal *tz = seq->private;
  1128. struct acpi_device *device;
  1129. acpi_status status;
  1130. int i = 0;
  1131. int j = 0;
  1132. if (!tz)
  1133. goto end;
  1134. if (tz->trips.critical.flags.valid)
  1135. seq_printf(seq, "critical (S5): %ld C%s",
  1136. KELVIN_TO_CELSIUS(tz->trips.critical.temperature),
  1137. nocrt ? " <disabled>\n" : "\n");
  1138. if (tz->trips.hot.flags.valid)
  1139. seq_printf(seq, "hot (S4): %ld C%s",
  1140. KELVIN_TO_CELSIUS(tz->trips.hot.temperature),
  1141. nocrt ? " <disabled>\n" : "\n");
  1142. if (tz->trips.passive.flags.valid) {
  1143. seq_printf(seq,
  1144. "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
  1145. KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
  1146. tz->trips.passive.tc1, tz->trips.passive.tc2,
  1147. tz->trips.passive.tsp);
  1148. for (j = 0; j < tz->trips.passive.devices.count; j++) {
  1149. status = acpi_bus_get_device(tz->trips.passive.devices.
  1150. handles[j], &device);
  1151. seq_printf(seq, "%4.4s ", status ? "" :
  1152. acpi_device_bid(device));
  1153. }
  1154. seq_puts(seq, "\n");
  1155. }
  1156. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  1157. if (!(tz->trips.active[i].flags.valid))
  1158. break;
  1159. seq_printf(seq, "active[%d]: %ld C: devices=",
  1160. i,
  1161. KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
  1162. for (j = 0; j < tz->trips.active[i].devices.count; j++){
  1163. status = acpi_bus_get_device(tz->trips.active[i].
  1164. devices.handles[j],
  1165. &device);
  1166. seq_printf(seq, "%4.4s ", status ? "" :
  1167. acpi_device_bid(device));
  1168. }
  1169. seq_puts(seq, "\n");
  1170. }
  1171. end:
  1172. return 0;
  1173. }
  1174. static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
  1175. {
  1176. return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
  1177. }
  1178. static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
  1179. {
  1180. struct acpi_thermal *tz = seq->private;
  1181. if (!tz)
  1182. goto end;
  1183. if (!tz->flags.cooling_mode)
  1184. seq_puts(seq, "<setting not supported>\n");
  1185. else
  1186. seq_puts(seq, "0 - Active; 1 - Passive\n");
  1187. end:
  1188. return 0;
  1189. }
  1190. static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
  1191. {
  1192. return single_open(file, acpi_thermal_cooling_seq_show,
  1193. PDE(inode)->data);
  1194. }
  1195. static ssize_t
  1196. acpi_thermal_write_cooling_mode(struct file *file,
  1197. const char __user * buffer,
  1198. size_t count, loff_t * ppos)
  1199. {
  1200. struct seq_file *m = file->private_data;
  1201. struct acpi_thermal *tz = m->private;
  1202. int result = 0;
  1203. char mode_string[12] = { '\0' };
  1204. if (!tz || (count > sizeof(mode_string) - 1))
  1205. return -EINVAL;
  1206. if (!tz->flags.cooling_mode)
  1207. return -ENODEV;
  1208. if (copy_from_user(mode_string, buffer, count))
  1209. return -EFAULT;
  1210. mode_string[count] = '\0';
  1211. result = acpi_thermal_set_cooling_mode(tz,
  1212. simple_strtoul(mode_string, NULL,
  1213. 0));
  1214. if (result)
  1215. return result;
  1216. acpi_thermal_check(tz);
  1217. return count;
  1218. }
  1219. static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
  1220. {
  1221. struct acpi_thermal *tz = seq->private;
  1222. if (!tz)
  1223. goto end;
  1224. if (!tz->polling_frequency) {
  1225. seq_puts(seq, "<polling disabled>\n");
  1226. goto end;
  1227. }
  1228. seq_printf(seq, "polling frequency: %lu seconds\n",
  1229. (tz->polling_frequency / 10));
  1230. end:
  1231. return 0;
  1232. }
  1233. static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
  1234. {
  1235. return single_open(file, acpi_thermal_polling_seq_show,
  1236. PDE(inode)->data);
  1237. }
  1238. static ssize_t
  1239. acpi_thermal_write_polling(struct file *file,
  1240. const char __user * buffer,
  1241. size_t count, loff_t * ppos)
  1242. {
  1243. struct seq_file *m = file->private_data;
  1244. struct acpi_thermal *tz = m->private;
  1245. int result = 0;
  1246. char polling_string[12] = { '\0' };
  1247. int seconds = 0;
  1248. if (!tz || (count > sizeof(polling_string) - 1))
  1249. return -EINVAL;
  1250. if (copy_from_user(polling_string, buffer, count))
  1251. return -EFAULT;
  1252. polling_string[count] = '\0';
  1253. seconds = simple_strtoul(polling_string, NULL, 0);
  1254. result = acpi_thermal_set_polling(tz, seconds);
  1255. if (result)
  1256. return result;
  1257. acpi_thermal_check(tz);
  1258. return count;
  1259. }
  1260. static int acpi_thermal_add_fs(struct acpi_device *device)
  1261. {
  1262. struct proc_dir_entry *entry = NULL;
  1263. if (!acpi_device_dir(device)) {
  1264. acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
  1265. acpi_thermal_dir);
  1266. if (!acpi_device_dir(device))
  1267. return -ENODEV;
  1268. acpi_device_dir(device)->owner = THIS_MODULE;
  1269. }
  1270. /* 'state' [R] */
  1271. entry = proc_create_data(ACPI_THERMAL_FILE_STATE,
  1272. S_IRUGO, acpi_device_dir(device),
  1273. &acpi_thermal_state_fops,
  1274. acpi_driver_data(device));
  1275. if (!entry)
  1276. return -ENODEV;
  1277. /* 'temperature' [R] */
  1278. entry = proc_create_data(ACPI_THERMAL_FILE_TEMPERATURE,
  1279. S_IRUGO, acpi_device_dir(device),
  1280. &acpi_thermal_temp_fops,
  1281. acpi_driver_data(device));
  1282. if (!entry)
  1283. return -ENODEV;
  1284. /* 'trip_points' [R] */
  1285. entry = proc_create_data(ACPI_THERMAL_FILE_TRIP_POINTS,
  1286. S_IRUGO,
  1287. acpi_device_dir(device),
  1288. &acpi_thermal_trip_fops,
  1289. acpi_driver_data(device));
  1290. if (!entry)
  1291. return -ENODEV;
  1292. /* 'cooling_mode' [R/W] */
  1293. entry = proc_create_data(ACPI_THERMAL_FILE_COOLING_MODE,
  1294. S_IFREG | S_IRUGO | S_IWUSR,
  1295. acpi_device_dir(device),
  1296. &acpi_thermal_cooling_fops,
  1297. acpi_driver_data(device));
  1298. if (!entry)
  1299. return -ENODEV;
  1300. /* 'polling_frequency' [R/W] */
  1301. entry = proc_create_data(ACPI_THERMAL_FILE_POLLING_FREQ,
  1302. S_IFREG | S_IRUGO | S_IWUSR,
  1303. acpi_device_dir(device),
  1304. &acpi_thermal_polling_fops,
  1305. acpi_driver_data(device));
  1306. if (!entry)
  1307. return -ENODEV;
  1308. return 0;
  1309. }
  1310. static int acpi_thermal_remove_fs(struct acpi_device *device)
  1311. {
  1312. if (acpi_device_dir(device)) {
  1313. remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
  1314. acpi_device_dir(device));
  1315. remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
  1316. acpi_device_dir(device));
  1317. remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
  1318. acpi_device_dir(device));
  1319. remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
  1320. acpi_device_dir(device));
  1321. remove_proc_entry(ACPI_THERMAL_FILE_STATE,
  1322. acpi_device_dir(device));
  1323. remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
  1324. acpi_device_dir(device) = NULL;
  1325. }
  1326. return 0;
  1327. }
  1328. /* --------------------------------------------------------------------------
  1329. Driver Interface
  1330. -------------------------------------------------------------------------- */
  1331. static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
  1332. {
  1333. struct acpi_thermal *tz = data;
  1334. struct acpi_device *device = NULL;
  1335. if (!tz)
  1336. return;
  1337. device = tz->device;
  1338. switch (event) {
  1339. case ACPI_THERMAL_NOTIFY_TEMPERATURE:
  1340. acpi_thermal_check(tz);
  1341. break;
  1342. case ACPI_THERMAL_NOTIFY_THRESHOLDS:
  1343. acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS);
  1344. acpi_thermal_check(tz);
  1345. acpi_bus_generate_proc_event(device, event, 0);
  1346. acpi_bus_generate_netlink_event(device->pnp.device_class,
  1347. device->dev.bus_id, event, 0);
  1348. break;
  1349. case ACPI_THERMAL_NOTIFY_DEVICES:
  1350. acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES);
  1351. acpi_thermal_check(tz);
  1352. acpi_bus_generate_proc_event(device, event, 0);
  1353. acpi_bus_generate_netlink_event(device->pnp.device_class,
  1354. device->dev.bus_id, event, 0);
  1355. break;
  1356. default:
  1357. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  1358. "Unsupported event [0x%x]\n", event));
  1359. break;
  1360. }
  1361. return;
  1362. }
  1363. static int acpi_thermal_get_info(struct acpi_thermal *tz)
  1364. {
  1365. int result = 0;
  1366. if (!tz)
  1367. return -EINVAL;
  1368. /* Get temperature [_TMP] (required) */
  1369. result = acpi_thermal_get_temperature(tz);
  1370. if (result)
  1371. return result;
  1372. /* Get trip points [_CRT, _PSV, etc.] (required) */
  1373. result = acpi_thermal_get_trip_points(tz);
  1374. if (result)
  1375. return result;
  1376. /* Set the cooling mode [_SCP] to active cooling (default) */
  1377. result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
  1378. if (!result)
  1379. tz->flags.cooling_mode = 1;
  1380. /* Get default polling frequency [_TZP] (optional) */
  1381. if (tzp)
  1382. tz->polling_frequency = tzp;
  1383. else
  1384. acpi_thermal_get_polling_frequency(tz);
  1385. return 0;
  1386. }
  1387. static int acpi_thermal_add(struct acpi_device *device)
  1388. {
  1389. int result = 0;
  1390. acpi_status status = AE_OK;
  1391. struct acpi_thermal *tz = NULL;
  1392. if (!device)
  1393. return -EINVAL;
  1394. tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
  1395. if (!tz)
  1396. return -ENOMEM;
  1397. tz->device = device;
  1398. strcpy(tz->name, device->pnp.bus_id);
  1399. strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
  1400. strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
  1401. device->driver_data = tz;
  1402. mutex_init(&tz->lock);
  1403. result = acpi_thermal_get_info(tz);
  1404. if (result)
  1405. goto free_memory;
  1406. result = acpi_thermal_register_thermal_zone(tz);
  1407. if (result)
  1408. goto free_memory;
  1409. result = acpi_thermal_add_fs(device);
  1410. if (result)
  1411. goto unregister_thermal_zone;
  1412. init_timer(&tz->timer);
  1413. acpi_thermal_active_off(tz);
  1414. acpi_thermal_check(tz);
  1415. status = acpi_install_notify_handler(device->handle,
  1416. ACPI_DEVICE_NOTIFY,
  1417. acpi_thermal_notify, tz);
  1418. if (ACPI_FAILURE(status)) {
  1419. result = -ENODEV;
  1420. goto remove_fs;
  1421. }
  1422. printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
  1423. acpi_device_name(device), acpi_device_bid(device),
  1424. KELVIN_TO_CELSIUS(tz->temperature));
  1425. goto end;
  1426. remove_fs:
  1427. acpi_thermal_remove_fs(device);
  1428. unregister_thermal_zone:
  1429. thermal_zone_device_unregister(tz->thermal_zone);
  1430. free_memory:
  1431. kfree(tz);
  1432. end:
  1433. return result;
  1434. }
  1435. static int acpi_thermal_remove(struct acpi_device *device, int type)
  1436. {
  1437. acpi_status status = AE_OK;
  1438. struct acpi_thermal *tz = NULL;
  1439. if (!device || !acpi_driver_data(device))
  1440. return -EINVAL;
  1441. tz = acpi_driver_data(device);
  1442. /* avoid timer adding new defer task */
  1443. tz->zombie = 1;
  1444. /* wait for running timer (on other CPUs) finish */
  1445. del_timer_sync(&(tz->timer));
  1446. /* synchronize deferred task */
  1447. acpi_os_wait_events_complete(NULL);
  1448. /* deferred task may reinsert timer */
  1449. del_timer_sync(&(tz->timer));
  1450. status = acpi_remove_notify_handler(device->handle,
  1451. ACPI_DEVICE_NOTIFY,
  1452. acpi_thermal_notify);
  1453. /* Terminate policy */
  1454. if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
  1455. tz->trips.passive.flags.enabled = 0;
  1456. acpi_thermal_passive(tz);
  1457. }
  1458. if (tz->trips.active[0].flags.valid
  1459. && tz->trips.active[0].flags.enabled) {
  1460. tz->trips.active[0].flags.enabled = 0;
  1461. acpi_thermal_active(tz);
  1462. }
  1463. acpi_thermal_remove_fs(device);
  1464. acpi_thermal_unregister_thermal_zone(tz);
  1465. mutex_destroy(&tz->lock);
  1466. kfree(tz);
  1467. return 0;
  1468. }
  1469. static int acpi_thermal_resume(struct acpi_device *device)
  1470. {
  1471. struct acpi_thermal *tz = NULL;
  1472. int i, j, power_state, result;
  1473. if (!device || !acpi_driver_data(device))
  1474. return -EINVAL;
  1475. tz = acpi_driver_data(device);
  1476. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  1477. if (!(&tz->trips.active[i]))
  1478. break;
  1479. if (!tz->trips.active[i].flags.valid)
  1480. break;
  1481. tz->trips.active[i].flags.enabled = 1;
  1482. for (j = 0; j < tz->trips.active[i].devices.count; j++) {
  1483. result = acpi_bus_get_power(tz->trips.active[i].devices.
  1484. handles[j], &power_state);
  1485. if (result || (power_state != ACPI_STATE_D0)) {
  1486. tz->trips.active[i].flags.enabled = 0;
  1487. break;
  1488. }
  1489. }
  1490. tz->state.active |= tz->trips.active[i].flags.enabled;
  1491. }
  1492. acpi_thermal_check(tz);
  1493. return AE_OK;
  1494. }
  1495. static int thermal_act(const struct dmi_system_id *d) {
  1496. if (act == 0) {
  1497. printk(KERN_NOTICE "ACPI: %s detected: "
  1498. "disabling all active thermal trip points\n", d->ident);
  1499. act = -1;
  1500. }
  1501. return 0;
  1502. }
  1503. static int thermal_nocrt(const struct dmi_system_id *d) {
  1504. printk(KERN_NOTICE "ACPI: %s detected: "
  1505. "disabling all critical thermal trip point actions.\n", d->ident);
  1506. nocrt = 1;
  1507. return 0;
  1508. }
  1509. static int thermal_tzp(const struct dmi_system_id *d) {
  1510. if (tzp == 0) {
  1511. printk(KERN_NOTICE "ACPI: %s detected: "
  1512. "enabling thermal zone polling\n", d->ident);
  1513. tzp = 300; /* 300 dS = 30 Seconds */
  1514. }
  1515. return 0;
  1516. }
  1517. static int thermal_psv(const struct dmi_system_id *d) {
  1518. if (psv == 0) {
  1519. printk(KERN_NOTICE "ACPI: %s detected: "
  1520. "disabling all passive thermal trip points\n", d->ident);
  1521. psv = -1;
  1522. }
  1523. return 0;
  1524. }
  1525. static struct dmi_system_id thermal_dmi_table[] __initdata = {
  1526. /*
  1527. * Award BIOS on this AOpen makes thermal control almost worthless.
  1528. * http://bugzilla.kernel.org/show_bug.cgi?id=8842
  1529. */
  1530. {
  1531. .callback = thermal_act,
  1532. .ident = "AOpen i915GMm-HFS",
  1533. .matches = {
  1534. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  1535. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  1536. },
  1537. },
  1538. {
  1539. .callback = thermal_psv,
  1540. .ident = "AOpen i915GMm-HFS",
  1541. .matches = {
  1542. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  1543. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  1544. },
  1545. },
  1546. {
  1547. .callback = thermal_tzp,
  1548. .ident = "AOpen i915GMm-HFS",
  1549. .matches = {
  1550. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  1551. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  1552. },
  1553. },
  1554. {
  1555. .callback = thermal_nocrt,
  1556. .ident = "Gigabyte GA-7ZX",
  1557. .matches = {
  1558. DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
  1559. DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
  1560. },
  1561. },
  1562. {}
  1563. };
  1564. static int __init acpi_thermal_init(void)
  1565. {
  1566. int result = 0;
  1567. dmi_check_system(thermal_dmi_table);
  1568. if (off) {
  1569. printk(KERN_NOTICE "ACPI: thermal control disabled\n");
  1570. return -ENODEV;
  1571. }
  1572. acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
  1573. if (!acpi_thermal_dir)
  1574. return -ENODEV;
  1575. acpi_thermal_dir->owner = THIS_MODULE;
  1576. result = acpi_bus_register_driver(&acpi_thermal_driver);
  1577. if (result < 0) {
  1578. remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
  1579. return -ENODEV;
  1580. }
  1581. return 0;
  1582. }
  1583. static void __exit acpi_thermal_exit(void)
  1584. {
  1585. acpi_bus_unregister_driver(&acpi_thermal_driver);
  1586. remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
  1587. return;
  1588. }
  1589. module_init(acpi_thermal_init);
  1590. module_exit(acpi_thermal_exit);