thermal.c 48 KB

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