thermal.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898
  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. }
  1289. /* 'state' [R] */
  1290. entry = proc_create_data(ACPI_THERMAL_FILE_STATE,
  1291. S_IRUGO, acpi_device_dir(device),
  1292. &acpi_thermal_state_fops,
  1293. acpi_driver_data(device));
  1294. if (!entry)
  1295. return -ENODEV;
  1296. /* 'temperature' [R] */
  1297. entry = proc_create_data(ACPI_THERMAL_FILE_TEMPERATURE,
  1298. S_IRUGO, acpi_device_dir(device),
  1299. &acpi_thermal_temp_fops,
  1300. acpi_driver_data(device));
  1301. if (!entry)
  1302. return -ENODEV;
  1303. /* 'trip_points' [R] */
  1304. entry = proc_create_data(ACPI_THERMAL_FILE_TRIP_POINTS,
  1305. S_IRUGO,
  1306. acpi_device_dir(device),
  1307. &acpi_thermal_trip_fops,
  1308. acpi_driver_data(device));
  1309. if (!entry)
  1310. return -ENODEV;
  1311. /* 'cooling_mode' [R/W] */
  1312. entry = proc_create_data(ACPI_THERMAL_FILE_COOLING_MODE,
  1313. S_IFREG | S_IRUGO | S_IWUSR,
  1314. acpi_device_dir(device),
  1315. &acpi_thermal_cooling_fops,
  1316. acpi_driver_data(device));
  1317. if (!entry)
  1318. return -ENODEV;
  1319. /* 'polling_frequency' [R/W] */
  1320. entry = proc_create_data(ACPI_THERMAL_FILE_POLLING_FREQ,
  1321. S_IFREG | S_IRUGO | S_IWUSR,
  1322. acpi_device_dir(device),
  1323. &acpi_thermal_polling_fops,
  1324. acpi_driver_data(device));
  1325. if (!entry)
  1326. return -ENODEV;
  1327. return 0;
  1328. }
  1329. static int acpi_thermal_remove_fs(struct acpi_device *device)
  1330. {
  1331. if (acpi_device_dir(device)) {
  1332. remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
  1333. acpi_device_dir(device));
  1334. remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
  1335. acpi_device_dir(device));
  1336. remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
  1337. acpi_device_dir(device));
  1338. remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
  1339. acpi_device_dir(device));
  1340. remove_proc_entry(ACPI_THERMAL_FILE_STATE,
  1341. acpi_device_dir(device));
  1342. remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
  1343. acpi_device_dir(device) = NULL;
  1344. }
  1345. return 0;
  1346. }
  1347. /* --------------------------------------------------------------------------
  1348. Driver Interface
  1349. -------------------------------------------------------------------------- */
  1350. static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
  1351. {
  1352. struct acpi_thermal *tz = data;
  1353. struct acpi_device *device = NULL;
  1354. if (!tz)
  1355. return;
  1356. device = tz->device;
  1357. switch (event) {
  1358. case ACPI_THERMAL_NOTIFY_TEMPERATURE:
  1359. acpi_thermal_check(tz);
  1360. break;
  1361. case ACPI_THERMAL_NOTIFY_THRESHOLDS:
  1362. acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS);
  1363. acpi_thermal_check(tz);
  1364. acpi_bus_generate_proc_event(device, event, 0);
  1365. acpi_bus_generate_netlink_event(device->pnp.device_class,
  1366. dev_name(&device->dev), event, 0);
  1367. break;
  1368. case ACPI_THERMAL_NOTIFY_DEVICES:
  1369. acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES);
  1370. acpi_thermal_check(tz);
  1371. acpi_bus_generate_proc_event(device, event, 0);
  1372. acpi_bus_generate_netlink_event(device->pnp.device_class,
  1373. dev_name(&device->dev), event, 0);
  1374. break;
  1375. default:
  1376. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  1377. "Unsupported event [0x%x]\n", event));
  1378. break;
  1379. }
  1380. return;
  1381. }
  1382. static int acpi_thermal_get_info(struct acpi_thermal *tz)
  1383. {
  1384. int result = 0;
  1385. if (!tz)
  1386. return -EINVAL;
  1387. /* Get temperature [_TMP] (required) */
  1388. result = acpi_thermal_get_temperature(tz);
  1389. if (result)
  1390. return result;
  1391. /* Get trip points [_CRT, _PSV, etc.] (required) */
  1392. result = acpi_thermal_get_trip_points(tz);
  1393. if (result)
  1394. return result;
  1395. /* Set the cooling mode [_SCP] to active cooling (default) */
  1396. result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
  1397. if (!result)
  1398. tz->flags.cooling_mode = 1;
  1399. /* Get default polling frequency [_TZP] (optional) */
  1400. if (tzp)
  1401. tz->polling_frequency = tzp;
  1402. else
  1403. acpi_thermal_get_polling_frequency(tz);
  1404. return 0;
  1405. }
  1406. static int acpi_thermal_add(struct acpi_device *device)
  1407. {
  1408. int result = 0;
  1409. acpi_status status = AE_OK;
  1410. struct acpi_thermal *tz = NULL;
  1411. if (!device)
  1412. return -EINVAL;
  1413. tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
  1414. if (!tz)
  1415. return -ENOMEM;
  1416. tz->device = device;
  1417. strcpy(tz->name, device->pnp.bus_id);
  1418. strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
  1419. strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
  1420. device->driver_data = tz;
  1421. mutex_init(&tz->lock);
  1422. result = acpi_thermal_get_info(tz);
  1423. if (result)
  1424. goto free_memory;
  1425. result = acpi_thermal_register_thermal_zone(tz);
  1426. if (result)
  1427. goto free_memory;
  1428. result = acpi_thermal_add_fs(device);
  1429. if (result)
  1430. goto unregister_thermal_zone;
  1431. init_timer(&tz->timer);
  1432. acpi_thermal_active_off(tz);
  1433. acpi_thermal_check(tz);
  1434. status = acpi_install_notify_handler(device->handle,
  1435. ACPI_DEVICE_NOTIFY,
  1436. acpi_thermal_notify, tz);
  1437. if (ACPI_FAILURE(status)) {
  1438. result = -ENODEV;
  1439. goto remove_fs;
  1440. }
  1441. printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
  1442. acpi_device_name(device), acpi_device_bid(device),
  1443. KELVIN_TO_CELSIUS(tz->temperature));
  1444. goto end;
  1445. remove_fs:
  1446. acpi_thermal_remove_fs(device);
  1447. unregister_thermal_zone:
  1448. thermal_zone_device_unregister(tz->thermal_zone);
  1449. free_memory:
  1450. kfree(tz);
  1451. end:
  1452. return result;
  1453. }
  1454. static int acpi_thermal_remove(struct acpi_device *device, int type)
  1455. {
  1456. acpi_status status = AE_OK;
  1457. struct acpi_thermal *tz = NULL;
  1458. if (!device || !acpi_driver_data(device))
  1459. return -EINVAL;
  1460. tz = acpi_driver_data(device);
  1461. /* avoid timer adding new defer task */
  1462. tz->zombie = 1;
  1463. /* wait for running timer (on other CPUs) finish */
  1464. del_timer_sync(&(tz->timer));
  1465. /* synchronize deferred task */
  1466. acpi_os_wait_events_complete(NULL);
  1467. /* deferred task may reinsert timer */
  1468. del_timer_sync(&(tz->timer));
  1469. status = acpi_remove_notify_handler(device->handle,
  1470. ACPI_DEVICE_NOTIFY,
  1471. acpi_thermal_notify);
  1472. /* Terminate policy */
  1473. if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
  1474. tz->trips.passive.flags.enabled = 0;
  1475. acpi_thermal_passive(tz);
  1476. }
  1477. if (tz->trips.active[0].flags.valid
  1478. && tz->trips.active[0].flags.enabled) {
  1479. tz->trips.active[0].flags.enabled = 0;
  1480. acpi_thermal_active(tz);
  1481. }
  1482. acpi_thermal_remove_fs(device);
  1483. acpi_thermal_unregister_thermal_zone(tz);
  1484. mutex_destroy(&tz->lock);
  1485. kfree(tz);
  1486. return 0;
  1487. }
  1488. static int acpi_thermal_resume(struct acpi_device *device)
  1489. {
  1490. struct acpi_thermal *tz = NULL;
  1491. int i, j, power_state, result;
  1492. if (!device || !acpi_driver_data(device))
  1493. return -EINVAL;
  1494. tz = acpi_driver_data(device);
  1495. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  1496. if (!(&tz->trips.active[i]))
  1497. break;
  1498. if (!tz->trips.active[i].flags.valid)
  1499. break;
  1500. tz->trips.active[i].flags.enabled = 1;
  1501. for (j = 0; j < tz->trips.active[i].devices.count; j++) {
  1502. result = acpi_bus_get_power(tz->trips.active[i].devices.
  1503. handles[j], &power_state);
  1504. if (result || (power_state != ACPI_STATE_D0)) {
  1505. tz->trips.active[i].flags.enabled = 0;
  1506. break;
  1507. }
  1508. }
  1509. tz->state.active |= tz->trips.active[i].flags.enabled;
  1510. }
  1511. acpi_thermal_check(tz);
  1512. return AE_OK;
  1513. }
  1514. static int thermal_act(const struct dmi_system_id *d) {
  1515. if (act == 0) {
  1516. printk(KERN_NOTICE "ACPI: %s detected: "
  1517. "disabling all active thermal trip points\n", d->ident);
  1518. act = -1;
  1519. }
  1520. return 0;
  1521. }
  1522. static int thermal_nocrt(const struct dmi_system_id *d) {
  1523. printk(KERN_NOTICE "ACPI: %s detected: "
  1524. "disabling all critical thermal trip point actions.\n", d->ident);
  1525. nocrt = 1;
  1526. return 0;
  1527. }
  1528. static int thermal_tzp(const struct dmi_system_id *d) {
  1529. if (tzp == 0) {
  1530. printk(KERN_NOTICE "ACPI: %s detected: "
  1531. "enabling thermal zone polling\n", d->ident);
  1532. tzp = 300; /* 300 dS = 30 Seconds */
  1533. }
  1534. return 0;
  1535. }
  1536. static int thermal_psv(const struct dmi_system_id *d) {
  1537. if (psv == 0) {
  1538. printk(KERN_NOTICE "ACPI: %s detected: "
  1539. "disabling all passive thermal trip points\n", d->ident);
  1540. psv = -1;
  1541. }
  1542. return 0;
  1543. }
  1544. static struct dmi_system_id thermal_dmi_table[] __initdata = {
  1545. /*
  1546. * Award BIOS on this AOpen makes thermal control almost worthless.
  1547. * http://bugzilla.kernel.org/show_bug.cgi?id=8842
  1548. */
  1549. {
  1550. .callback = thermal_act,
  1551. .ident = "AOpen i915GMm-HFS",
  1552. .matches = {
  1553. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  1554. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  1555. },
  1556. },
  1557. {
  1558. .callback = thermal_psv,
  1559. .ident = "AOpen i915GMm-HFS",
  1560. .matches = {
  1561. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  1562. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  1563. },
  1564. },
  1565. {
  1566. .callback = thermal_tzp,
  1567. .ident = "AOpen i915GMm-HFS",
  1568. .matches = {
  1569. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  1570. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  1571. },
  1572. },
  1573. {
  1574. .callback = thermal_nocrt,
  1575. .ident = "Gigabyte GA-7ZX",
  1576. .matches = {
  1577. DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
  1578. DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
  1579. },
  1580. },
  1581. {}
  1582. };
  1583. static int __init acpi_thermal_init(void)
  1584. {
  1585. int result = 0;
  1586. dmi_check_system(thermal_dmi_table);
  1587. if (off) {
  1588. printk(KERN_NOTICE "ACPI: thermal control disabled\n");
  1589. return -ENODEV;
  1590. }
  1591. acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
  1592. if (!acpi_thermal_dir)
  1593. return -ENODEV;
  1594. result = acpi_bus_register_driver(&acpi_thermal_driver);
  1595. if (result < 0) {
  1596. remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
  1597. return -ENODEV;
  1598. }
  1599. return 0;
  1600. }
  1601. static void __exit acpi_thermal_exit(void)
  1602. {
  1603. acpi_bus_unregister_driver(&acpi_thermal_driver);
  1604. remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
  1605. return;
  1606. }
  1607. module_init(acpi_thermal_init);
  1608. module_exit(acpi_thermal_exit);