thermal.c 48 KB

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