thermal.c 48 KB

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