thermal.c 48 KB

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