thermal.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482
  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 <acpi/acpi_bus.h>
  46. #include <acpi/acpi_drivers.h>
  47. #define ACPI_THERMAL_COMPONENT 0x04000000
  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 KELVIN_TO_CELSIUS(t) (long)(((long)t-2732>=0) ? ((long)t-2732+5)/10 : ((long)t-2732-5)/10)
  64. #define CELSIUS_TO_KELVIN(t) ((t+273)*10)
  65. #define _COMPONENT ACPI_THERMAL_COMPONENT
  66. ACPI_MODULE_NAME("thermal");
  67. MODULE_AUTHOR("Paul Diefenbaugh");
  68. MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
  69. MODULE_LICENSE("GPL");
  70. static int act;
  71. module_param(act, int, 0644);
  72. MODULE_PARM_DESC(act, "Disable or override all lowest active trip points.");
  73. static int crt;
  74. module_param(crt, int, 0644);
  75. MODULE_PARM_DESC(crt, "Disable or lower all critical trip points.");
  76. static int tzp;
  77. module_param(tzp, int, 0444);
  78. MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.");
  79. static int nocrt;
  80. module_param(nocrt, int, 0);
  81. MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points.");
  82. static int off;
  83. module_param(off, int, 0);
  84. MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.");
  85. static int psv;
  86. module_param(psv, int, 0644);
  87. MODULE_PARM_DESC(psv, "Disable or override all passive trip points.");
  88. static int acpi_thermal_add(struct acpi_device *device);
  89. static int acpi_thermal_remove(struct acpi_device *device, int type);
  90. static int acpi_thermal_resume(struct acpi_device *device);
  91. static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
  92. static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
  93. static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
  94. static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
  95. static ssize_t acpi_thermal_write_cooling_mode(struct file *,
  96. const char __user *, size_t,
  97. loff_t *);
  98. static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
  99. static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
  100. size_t, loff_t *);
  101. static const struct acpi_device_id thermal_device_ids[] = {
  102. {ACPI_THERMAL_HID, 0},
  103. {"", 0},
  104. };
  105. MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
  106. static struct acpi_driver acpi_thermal_driver = {
  107. .name = "thermal",
  108. .class = ACPI_THERMAL_CLASS,
  109. .ids = thermal_device_ids,
  110. .ops = {
  111. .add = acpi_thermal_add,
  112. .remove = acpi_thermal_remove,
  113. .resume = acpi_thermal_resume,
  114. },
  115. };
  116. struct acpi_thermal_state {
  117. u8 critical:1;
  118. u8 hot:1;
  119. u8 passive:1;
  120. u8 active:1;
  121. u8 reserved:4;
  122. int active_index;
  123. };
  124. struct acpi_thermal_state_flags {
  125. u8 valid:1;
  126. u8 enabled:1;
  127. u8 reserved:6;
  128. };
  129. struct acpi_thermal_critical {
  130. struct acpi_thermal_state_flags flags;
  131. unsigned long temperature;
  132. };
  133. struct acpi_thermal_hot {
  134. struct acpi_thermal_state_flags flags;
  135. unsigned long temperature;
  136. };
  137. struct acpi_thermal_passive {
  138. struct acpi_thermal_state_flags flags;
  139. unsigned long temperature;
  140. unsigned long tc1;
  141. unsigned long tc2;
  142. unsigned long tsp;
  143. struct acpi_handle_list devices;
  144. };
  145. struct acpi_thermal_active {
  146. struct acpi_thermal_state_flags flags;
  147. unsigned long temperature;
  148. struct acpi_handle_list devices;
  149. };
  150. struct acpi_thermal_trips {
  151. struct acpi_thermal_critical critical;
  152. struct acpi_thermal_hot hot;
  153. struct acpi_thermal_passive passive;
  154. struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
  155. };
  156. struct acpi_thermal_flags {
  157. u8 cooling_mode:1; /* _SCP */
  158. u8 devices:1; /* _TZD */
  159. u8 reserved:6;
  160. };
  161. struct acpi_thermal {
  162. struct acpi_device * device;
  163. acpi_bus_id name;
  164. unsigned long temperature;
  165. unsigned long last_temperature;
  166. unsigned long polling_frequency;
  167. volatile u8 zombie;
  168. struct acpi_thermal_flags flags;
  169. struct acpi_thermal_state state;
  170. struct acpi_thermal_trips trips;
  171. struct acpi_handle_list devices;
  172. struct timer_list timer;
  173. struct mutex lock;
  174. };
  175. static const struct file_operations acpi_thermal_state_fops = {
  176. .open = acpi_thermal_state_open_fs,
  177. .read = seq_read,
  178. .llseek = seq_lseek,
  179. .release = single_release,
  180. };
  181. static const struct file_operations acpi_thermal_temp_fops = {
  182. .open = acpi_thermal_temp_open_fs,
  183. .read = seq_read,
  184. .llseek = seq_lseek,
  185. .release = single_release,
  186. };
  187. static const struct file_operations acpi_thermal_trip_fops = {
  188. .open = acpi_thermal_trip_open_fs,
  189. .read = seq_read,
  190. .llseek = seq_lseek,
  191. .release = single_release,
  192. };
  193. static const struct file_operations acpi_thermal_cooling_fops = {
  194. .open = acpi_thermal_cooling_open_fs,
  195. .read = seq_read,
  196. .write = acpi_thermal_write_cooling_mode,
  197. .llseek = seq_lseek,
  198. .release = single_release,
  199. };
  200. static const struct file_operations acpi_thermal_polling_fops = {
  201. .open = acpi_thermal_polling_open_fs,
  202. .read = seq_read,
  203. .write = acpi_thermal_write_polling,
  204. .llseek = seq_lseek,
  205. .release = single_release,
  206. };
  207. /* --------------------------------------------------------------------------
  208. Thermal Zone Management
  209. -------------------------------------------------------------------------- */
  210. static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
  211. {
  212. acpi_status status = AE_OK;
  213. if (!tz)
  214. return -EINVAL;
  215. tz->last_temperature = tz->temperature;
  216. status =
  217. acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tz->temperature);
  218. if (ACPI_FAILURE(status))
  219. return -ENODEV;
  220. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
  221. tz->temperature));
  222. return 0;
  223. }
  224. static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
  225. {
  226. acpi_status status = AE_OK;
  227. if (!tz)
  228. return -EINVAL;
  229. status =
  230. acpi_evaluate_integer(tz->device->handle, "_TZP", NULL,
  231. &tz->polling_frequency);
  232. if (ACPI_FAILURE(status))
  233. return -ENODEV;
  234. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
  235. tz->polling_frequency));
  236. return 0;
  237. }
  238. static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
  239. {
  240. if (!tz)
  241. return -EINVAL;
  242. tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
  243. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  244. "Polling frequency set to %lu seconds\n",
  245. tz->polling_frequency/10));
  246. return 0;
  247. }
  248. static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
  249. {
  250. acpi_status status = AE_OK;
  251. union acpi_object arg0 = { ACPI_TYPE_INTEGER };
  252. struct acpi_object_list arg_list = { 1, &arg0 };
  253. acpi_handle handle = NULL;
  254. if (!tz)
  255. return -EINVAL;
  256. status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
  257. if (ACPI_FAILURE(status)) {
  258. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
  259. return -ENODEV;
  260. }
  261. arg0.integer.value = mode;
  262. status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
  263. if (ACPI_FAILURE(status))
  264. return -ENODEV;
  265. return 0;
  266. }
  267. static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
  268. {
  269. acpi_status status = AE_OK;
  270. int i = 0;
  271. if (!tz)
  272. return -EINVAL;
  273. /* Critical Shutdown (required) */
  274. status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL,
  275. &tz->trips.critical.temperature);
  276. if (ACPI_FAILURE(status)) {
  277. tz->trips.critical.flags.valid = 0;
  278. ACPI_EXCEPTION((AE_INFO, status, "No critical threshold"));
  279. return -ENODEV;
  280. } else {
  281. tz->trips.critical.flags.valid = 1;
  282. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  283. "Found critical threshold [%lu]\n",
  284. tz->trips.critical.temperature));
  285. }
  286. if (tz->trips.critical.flags.valid == 1) {
  287. if (crt == -1) {
  288. tz->trips.critical.flags.valid = 0;
  289. } else if (crt > 0) {
  290. unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
  291. /*
  292. * Allow override to lower critical threshold
  293. */
  294. if (crt_k < tz->trips.critical.temperature)
  295. tz->trips.critical.temperature = crt_k;
  296. }
  297. }
  298. /* Critical Sleep (optional) */
  299. status =
  300. acpi_evaluate_integer(tz->device->handle, "_HOT", NULL,
  301. &tz->trips.hot.temperature);
  302. if (ACPI_FAILURE(status)) {
  303. tz->trips.hot.flags.valid = 0;
  304. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No hot threshold\n"));
  305. } else {
  306. tz->trips.hot.flags.valid = 1;
  307. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found hot threshold [%lu]\n",
  308. tz->trips.hot.temperature));
  309. }
  310. /* Passive: Processors (optional) */
  311. if (psv == -1) {
  312. status = AE_SUPPORT;
  313. } else if (psv > 0) {
  314. tz->trips.passive.temperature = CELSIUS_TO_KELVIN(psv);
  315. status = AE_OK;
  316. } else {
  317. status = acpi_evaluate_integer(tz->device->handle,
  318. "_PSV", NULL, &tz->trips.passive.temperature);
  319. }
  320. if (ACPI_FAILURE(status)) {
  321. tz->trips.passive.flags.valid = 0;
  322. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No passive threshold\n"));
  323. } else {
  324. tz->trips.passive.flags.valid = 1;
  325. status =
  326. acpi_evaluate_integer(tz->device->handle, "_TC1", NULL,
  327. &tz->trips.passive.tc1);
  328. if (ACPI_FAILURE(status))
  329. tz->trips.passive.flags.valid = 0;
  330. status =
  331. acpi_evaluate_integer(tz->device->handle, "_TC2", NULL,
  332. &tz->trips.passive.tc2);
  333. if (ACPI_FAILURE(status))
  334. tz->trips.passive.flags.valid = 0;
  335. status =
  336. acpi_evaluate_integer(tz->device->handle, "_TSP", NULL,
  337. &tz->trips.passive.tsp);
  338. if (ACPI_FAILURE(status))
  339. tz->trips.passive.flags.valid = 0;
  340. status =
  341. acpi_evaluate_reference(tz->device->handle, "_PSL", NULL,
  342. &tz->trips.passive.devices);
  343. if (ACPI_FAILURE(status))
  344. tz->trips.passive.flags.valid = 0;
  345. if (!tz->trips.passive.flags.valid)
  346. printk(KERN_WARNING PREFIX "Invalid passive threshold\n");
  347. else
  348. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  349. "Found passive threshold [%lu]\n",
  350. tz->trips.passive.temperature));
  351. }
  352. /* Active: Fans, etc. (optional) */
  353. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  354. char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
  355. if (act == -1)
  356. break; /* disable all active trip points */
  357. status = acpi_evaluate_integer(tz->device->handle,
  358. name, NULL, &tz->trips.active[i].temperature);
  359. if (ACPI_FAILURE(status)) {
  360. if (i == 0) /* no active trip points */
  361. break;
  362. if (act <= 0) /* no override requested */
  363. break;
  364. if (i == 1) { /* 1 trip point */
  365. tz->trips.active[0].temperature =
  366. CELSIUS_TO_KELVIN(act);
  367. } else { /* multiple trips */
  368. /*
  369. * Don't allow override higher than
  370. * the next higher trip point
  371. */
  372. tz->trips.active[i - 1].temperature =
  373. (tz->trips.active[i - 2].temperature <
  374. CELSIUS_TO_KELVIN(act) ?
  375. tz->trips.active[i - 2].temperature :
  376. CELSIUS_TO_KELVIN(act));
  377. }
  378. break;
  379. }
  380. name[2] = 'L';
  381. status =
  382. acpi_evaluate_reference(tz->device->handle, name, NULL,
  383. &tz->trips.active[i].devices);
  384. if (ACPI_SUCCESS(status)) {
  385. tz->trips.active[i].flags.valid = 1;
  386. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  387. "Found active threshold [%d]:[%lu]\n",
  388. i, tz->trips.active[i].temperature));
  389. } else
  390. ACPI_EXCEPTION((AE_INFO, status,
  391. "Invalid active threshold [%d]", i));
  392. }
  393. return 0;
  394. }
  395. static int acpi_thermal_get_devices(struct acpi_thermal *tz)
  396. {
  397. acpi_status status = AE_OK;
  398. if (!tz)
  399. return -EINVAL;
  400. status =
  401. acpi_evaluate_reference(tz->device->handle, "_TZD", NULL, &tz->devices);
  402. if (ACPI_FAILURE(status))
  403. return -ENODEV;
  404. return 0;
  405. }
  406. static int acpi_thermal_critical(struct acpi_thermal *tz)
  407. {
  408. if (!tz || !tz->trips.critical.flags.valid || nocrt)
  409. return -EINVAL;
  410. if (tz->temperature >= tz->trips.critical.temperature) {
  411. printk(KERN_WARNING PREFIX "Critical trip point\n");
  412. tz->trips.critical.flags.enabled = 1;
  413. } else if (tz->trips.critical.flags.enabled)
  414. tz->trips.critical.flags.enabled = 0;
  415. printk(KERN_EMERG
  416. "Critical temperature reached (%ld C), shutting down.\n",
  417. KELVIN_TO_CELSIUS(tz->temperature));
  418. acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL,
  419. tz->trips.critical.flags.enabled);
  420. acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
  421. tz->device->dev.bus_id,
  422. ACPI_THERMAL_NOTIFY_CRITICAL,
  423. tz->trips.critical.flags.enabled);
  424. orderly_poweroff(true);
  425. return 0;
  426. }
  427. static int acpi_thermal_hot(struct acpi_thermal *tz)
  428. {
  429. if (!tz || !tz->trips.hot.flags.valid || nocrt)
  430. return -EINVAL;
  431. if (tz->temperature >= tz->trips.hot.temperature) {
  432. printk(KERN_WARNING PREFIX "Hot trip point\n");
  433. tz->trips.hot.flags.enabled = 1;
  434. } else if (tz->trips.hot.flags.enabled)
  435. tz->trips.hot.flags.enabled = 0;
  436. acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
  437. tz->trips.hot.flags.enabled);
  438. acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
  439. tz->device->dev.bus_id,
  440. ACPI_THERMAL_NOTIFY_HOT,
  441. tz->trips.hot.flags.enabled);
  442. /* TBD: Call user-mode "sleep(S4)" function */
  443. return 0;
  444. }
  445. static void acpi_thermal_passive(struct acpi_thermal *tz)
  446. {
  447. int result = 1;
  448. struct acpi_thermal_passive *passive = NULL;
  449. int trend = 0;
  450. int i = 0;
  451. if (!tz || !tz->trips.passive.flags.valid)
  452. return;
  453. passive = &(tz->trips.passive);
  454. /*
  455. * Above Trip?
  456. * -----------
  457. * Calculate the thermal trend (using the passive cooling equation)
  458. * and modify the performance limit for all passive cooling devices
  459. * accordingly. Note that we assume symmetry.
  460. */
  461. if (tz->temperature >= passive->temperature) {
  462. trend =
  463. (passive->tc1 * (tz->temperature - tz->last_temperature)) +
  464. (passive->tc2 * (tz->temperature - passive->temperature));
  465. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  466. "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
  467. trend, passive->tc1, tz->temperature,
  468. tz->last_temperature, passive->tc2,
  469. tz->temperature, passive->temperature));
  470. passive->flags.enabled = 1;
  471. /* Heating up? */
  472. if (trend > 0)
  473. for (i = 0; i < passive->devices.count; i++)
  474. acpi_processor_set_thermal_limit(passive->
  475. devices.
  476. handles[i],
  477. ACPI_PROCESSOR_LIMIT_INCREMENT);
  478. /* Cooling off? */
  479. else if (trend < 0) {
  480. for (i = 0; i < passive->devices.count; i++)
  481. /*
  482. * assume that we are on highest
  483. * freq/lowest thrott and can leave
  484. * passive mode, even in error case
  485. */
  486. if (!acpi_processor_set_thermal_limit
  487. (passive->devices.handles[i],
  488. ACPI_PROCESSOR_LIMIT_DECREMENT))
  489. result = 0;
  490. /*
  491. * Leave cooling mode, even if the temp might
  492. * higher than trip point This is because some
  493. * machines might have long thermal polling
  494. * frequencies (tsp) defined. We will fall back
  495. * into passive mode in next cycle (probably quicker)
  496. */
  497. if (result) {
  498. passive->flags.enabled = 0;
  499. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  500. "Disabling passive cooling, still above threshold,"
  501. " but we are cooling down\n"));
  502. }
  503. }
  504. return;
  505. }
  506. /*
  507. * Below Trip?
  508. * -----------
  509. * Implement passive cooling hysteresis to slowly increase performance
  510. * and avoid thrashing around the passive trip point. Note that we
  511. * assume symmetry.
  512. */
  513. if (!passive->flags.enabled)
  514. return;
  515. for (i = 0; i < passive->devices.count; i++)
  516. if (!acpi_processor_set_thermal_limit
  517. (passive->devices.handles[i],
  518. ACPI_PROCESSOR_LIMIT_DECREMENT))
  519. result = 0;
  520. if (result) {
  521. passive->flags.enabled = 0;
  522. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  523. "Disabling passive cooling (zone is cool)\n"));
  524. }
  525. }
  526. static void acpi_thermal_active(struct acpi_thermal *tz)
  527. {
  528. int result = 0;
  529. struct acpi_thermal_active *active = NULL;
  530. int i = 0;
  531. int j = 0;
  532. unsigned long maxtemp = 0;
  533. if (!tz)
  534. return;
  535. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  536. active = &(tz->trips.active[i]);
  537. if (!active || !active->flags.valid)
  538. break;
  539. if (tz->temperature >= active->temperature) {
  540. /*
  541. * Above Threshold?
  542. * ----------------
  543. * If not already enabled, turn ON all cooling devices
  544. * associated with this active threshold.
  545. */
  546. if (active->temperature > maxtemp)
  547. tz->state.active_index = i;
  548. maxtemp = active->temperature;
  549. if (active->flags.enabled)
  550. continue;
  551. for (j = 0; j < active->devices.count; j++) {
  552. result =
  553. acpi_bus_set_power(active->devices.
  554. handles[j],
  555. ACPI_STATE_D0);
  556. if (result) {
  557. printk(KERN_WARNING PREFIX
  558. "Unable to turn cooling device [%p] 'on'\n",
  559. active->devices.
  560. handles[j]);
  561. continue;
  562. }
  563. active->flags.enabled = 1;
  564. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  565. "Cooling device [%p] now 'on'\n",
  566. active->devices.handles[j]));
  567. }
  568. continue;
  569. }
  570. if (!active->flags.enabled)
  571. continue;
  572. /*
  573. * Below Threshold?
  574. * ----------------
  575. * Turn OFF all cooling devices associated with this
  576. * threshold.
  577. */
  578. for (j = 0; j < active->devices.count; j++) {
  579. result = acpi_bus_set_power(active->devices.handles[j],
  580. ACPI_STATE_D3);
  581. if (result) {
  582. printk(KERN_WARNING PREFIX
  583. "Unable to turn cooling device [%p] 'off'\n",
  584. active->devices.handles[j]);
  585. continue;
  586. }
  587. active->flags.enabled = 0;
  588. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  589. "Cooling device [%p] now 'off'\n",
  590. active->devices.handles[j]));
  591. }
  592. }
  593. }
  594. static void acpi_thermal_check(void *context);
  595. static void acpi_thermal_run(unsigned long data)
  596. {
  597. struct acpi_thermal *tz = (struct acpi_thermal *)data;
  598. if (!tz->zombie)
  599. acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data);
  600. }
  601. static void acpi_thermal_check(void *data)
  602. {
  603. int result = 0;
  604. struct acpi_thermal *tz = data;
  605. unsigned long sleep_time = 0;
  606. unsigned long timeout_jiffies = 0;
  607. int i = 0;
  608. struct acpi_thermal_state state;
  609. if (!tz) {
  610. printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
  611. return;
  612. }
  613. /* Check if someone else is already running */
  614. if (!mutex_trylock(&tz->lock))
  615. return;
  616. state = tz->state;
  617. result = acpi_thermal_get_temperature(tz);
  618. if (result)
  619. goto unlock;
  620. memset(&tz->state, 0, sizeof(tz->state));
  621. /*
  622. * Check Trip Points
  623. * -----------------
  624. * Compare the current temperature to the trip point values to see
  625. * if we've entered one of the thermal policy states. Note that
  626. * this function determines when a state is entered, but the
  627. * individual policy decides when it is exited (e.g. hysteresis).
  628. */
  629. if (tz->trips.critical.flags.valid)
  630. state.critical |=
  631. (tz->temperature >= tz->trips.critical.temperature);
  632. if (tz->trips.hot.flags.valid)
  633. state.hot |= (tz->temperature >= tz->trips.hot.temperature);
  634. if (tz->trips.passive.flags.valid)
  635. state.passive |=
  636. (tz->temperature >= tz->trips.passive.temperature);
  637. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
  638. if (tz->trips.active[i].flags.valid)
  639. state.active |=
  640. (tz->temperature >=
  641. tz->trips.active[i].temperature);
  642. /*
  643. * Invoke Policy
  644. * -------------
  645. * Separated from the above check to allow individual policy to
  646. * determine when to exit a given state.
  647. */
  648. if (state.critical)
  649. acpi_thermal_critical(tz);
  650. if (state.hot)
  651. acpi_thermal_hot(tz);
  652. if (state.passive)
  653. acpi_thermal_passive(tz);
  654. if (state.active)
  655. acpi_thermal_active(tz);
  656. /*
  657. * Calculate State
  658. * ---------------
  659. * Again, separated from the above two to allow independent policy
  660. * decisions.
  661. */
  662. tz->state.critical = tz->trips.critical.flags.enabled;
  663. tz->state.hot = tz->trips.hot.flags.enabled;
  664. tz->state.passive = tz->trips.passive.flags.enabled;
  665. tz->state.active = 0;
  666. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
  667. tz->state.active |= tz->trips.active[i].flags.enabled;
  668. /*
  669. * Calculate Sleep Time
  670. * --------------------
  671. * If we're in the passive state, use _TSP's value. Otherwise
  672. * use the default polling frequency (e.g. _TZP). If no polling
  673. * frequency is specified then we'll wait forever (at least until
  674. * a thermal event occurs). Note that _TSP and _TZD values are
  675. * given in 1/10th seconds (we must covert to milliseconds).
  676. */
  677. if (tz->state.passive) {
  678. sleep_time = tz->trips.passive.tsp * 100;
  679. timeout_jiffies = jiffies + (HZ * sleep_time) / 1000;
  680. } else if (tz->polling_frequency > 0) {
  681. sleep_time = tz->polling_frequency * 100;
  682. timeout_jiffies = round_jiffies(jiffies + (HZ * sleep_time) / 1000);
  683. }
  684. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n",
  685. tz->name, tz->temperature, sleep_time));
  686. /*
  687. * Schedule Next Poll
  688. * ------------------
  689. */
  690. if (!sleep_time) {
  691. if (timer_pending(&(tz->timer)))
  692. del_timer(&(tz->timer));
  693. } else {
  694. if (timer_pending(&(tz->timer)))
  695. mod_timer(&(tz->timer), timeout_jiffies);
  696. else {
  697. tz->timer.data = (unsigned long)tz;
  698. tz->timer.function = acpi_thermal_run;
  699. tz->timer.expires = timeout_jiffies;
  700. add_timer(&(tz->timer));
  701. }
  702. }
  703. unlock:
  704. mutex_unlock(&tz->lock);
  705. }
  706. /* --------------------------------------------------------------------------
  707. FS Interface (/proc)
  708. -------------------------------------------------------------------------- */
  709. static struct proc_dir_entry *acpi_thermal_dir;
  710. static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
  711. {
  712. struct acpi_thermal *tz = seq->private;
  713. if (!tz)
  714. goto end;
  715. seq_puts(seq, "state: ");
  716. if (!tz->state.critical && !tz->state.hot && !tz->state.passive
  717. && !tz->state.active)
  718. seq_puts(seq, "ok\n");
  719. else {
  720. if (tz->state.critical)
  721. seq_puts(seq, "critical ");
  722. if (tz->state.hot)
  723. seq_puts(seq, "hot ");
  724. if (tz->state.passive)
  725. seq_puts(seq, "passive ");
  726. if (tz->state.active)
  727. seq_printf(seq, "active[%d]", tz->state.active_index);
  728. seq_puts(seq, "\n");
  729. }
  730. end:
  731. return 0;
  732. }
  733. static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
  734. {
  735. return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
  736. }
  737. static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
  738. {
  739. int result = 0;
  740. struct acpi_thermal *tz = seq->private;
  741. if (!tz)
  742. goto end;
  743. result = acpi_thermal_get_temperature(tz);
  744. if (result)
  745. goto end;
  746. seq_printf(seq, "temperature: %ld C\n",
  747. KELVIN_TO_CELSIUS(tz->temperature));
  748. end:
  749. return 0;
  750. }
  751. static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
  752. {
  753. return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
  754. }
  755. static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
  756. {
  757. struct acpi_thermal *tz = seq->private;
  758. struct acpi_device *device;
  759. acpi_status status;
  760. int i = 0;
  761. int j = 0;
  762. if (!tz)
  763. goto end;
  764. if (tz->trips.critical.flags.valid)
  765. seq_printf(seq, "critical (S5): %ld C%s",
  766. KELVIN_TO_CELSIUS(tz->trips.critical.temperature),
  767. nocrt ? " <disabled>\n" : "\n");
  768. if (tz->trips.hot.flags.valid)
  769. seq_printf(seq, "hot (S4): %ld C%s",
  770. KELVIN_TO_CELSIUS(tz->trips.hot.temperature),
  771. nocrt ? " <disabled>\n" : "\n");
  772. if (tz->trips.passive.flags.valid) {
  773. seq_printf(seq,
  774. "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
  775. KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
  776. tz->trips.passive.tc1, tz->trips.passive.tc2,
  777. tz->trips.passive.tsp);
  778. for (j = 0; j < tz->trips.passive.devices.count; j++) {
  779. status = acpi_bus_get_device(tz->trips.passive.devices.
  780. handles[j], &device);
  781. seq_printf(seq, "%4.4s ", status ? "" :
  782. acpi_device_bid(device));
  783. }
  784. seq_puts(seq, "\n");
  785. }
  786. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  787. if (!(tz->trips.active[i].flags.valid))
  788. break;
  789. seq_printf(seq, "active[%d]: %ld C: devices=",
  790. i,
  791. KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
  792. for (j = 0; j < tz->trips.active[i].devices.count; j++){
  793. status = acpi_bus_get_device(tz->trips.active[i].
  794. devices.handles[j],
  795. &device);
  796. seq_printf(seq, "%4.4s ", status ? "" :
  797. acpi_device_bid(device));
  798. }
  799. seq_puts(seq, "\n");
  800. }
  801. end:
  802. return 0;
  803. }
  804. static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
  805. {
  806. return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
  807. }
  808. static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
  809. {
  810. struct acpi_thermal *tz = seq->private;
  811. if (!tz)
  812. goto end;
  813. if (!tz->flags.cooling_mode)
  814. seq_puts(seq, "<setting not supported>\n");
  815. else
  816. seq_puts(seq, "0 - Active; 1 - Passive\n");
  817. end:
  818. return 0;
  819. }
  820. static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
  821. {
  822. return single_open(file, acpi_thermal_cooling_seq_show,
  823. PDE(inode)->data);
  824. }
  825. static ssize_t
  826. acpi_thermal_write_cooling_mode(struct file *file,
  827. const char __user * buffer,
  828. size_t count, loff_t * ppos)
  829. {
  830. struct seq_file *m = file->private_data;
  831. struct acpi_thermal *tz = m->private;
  832. int result = 0;
  833. char mode_string[12] = { '\0' };
  834. if (!tz || (count > sizeof(mode_string) - 1))
  835. return -EINVAL;
  836. if (!tz->flags.cooling_mode)
  837. return -ENODEV;
  838. if (copy_from_user(mode_string, buffer, count))
  839. return -EFAULT;
  840. mode_string[count] = '\0';
  841. result = acpi_thermal_set_cooling_mode(tz,
  842. simple_strtoul(mode_string, NULL,
  843. 0));
  844. if (result)
  845. return result;
  846. acpi_thermal_check(tz);
  847. return count;
  848. }
  849. static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
  850. {
  851. struct acpi_thermal *tz = seq->private;
  852. if (!tz)
  853. goto end;
  854. if (!tz->polling_frequency) {
  855. seq_puts(seq, "<polling disabled>\n");
  856. goto end;
  857. }
  858. seq_printf(seq, "polling frequency: %lu seconds\n",
  859. (tz->polling_frequency / 10));
  860. end:
  861. return 0;
  862. }
  863. static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
  864. {
  865. return single_open(file, acpi_thermal_polling_seq_show,
  866. PDE(inode)->data);
  867. }
  868. static ssize_t
  869. acpi_thermal_write_polling(struct file *file,
  870. const char __user * buffer,
  871. size_t count, loff_t * ppos)
  872. {
  873. struct seq_file *m = file->private_data;
  874. struct acpi_thermal *tz = m->private;
  875. int result = 0;
  876. char polling_string[12] = { '\0' };
  877. int seconds = 0;
  878. if (!tz || (count > sizeof(polling_string) - 1))
  879. return -EINVAL;
  880. if (copy_from_user(polling_string, buffer, count))
  881. return -EFAULT;
  882. polling_string[count] = '\0';
  883. seconds = simple_strtoul(polling_string, NULL, 0);
  884. result = acpi_thermal_set_polling(tz, seconds);
  885. if (result)
  886. return result;
  887. acpi_thermal_check(tz);
  888. return count;
  889. }
  890. static int acpi_thermal_add_fs(struct acpi_device *device)
  891. {
  892. struct proc_dir_entry *entry = NULL;
  893. if (!acpi_device_dir(device)) {
  894. acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
  895. acpi_thermal_dir);
  896. if (!acpi_device_dir(device))
  897. return -ENODEV;
  898. acpi_device_dir(device)->owner = THIS_MODULE;
  899. }
  900. /* 'state' [R] */
  901. entry = create_proc_entry(ACPI_THERMAL_FILE_STATE,
  902. S_IRUGO, acpi_device_dir(device));
  903. if (!entry)
  904. return -ENODEV;
  905. else {
  906. entry->proc_fops = &acpi_thermal_state_fops;
  907. entry->data = acpi_driver_data(device);
  908. entry->owner = THIS_MODULE;
  909. }
  910. /* 'temperature' [R] */
  911. entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
  912. S_IRUGO, acpi_device_dir(device));
  913. if (!entry)
  914. return -ENODEV;
  915. else {
  916. entry->proc_fops = &acpi_thermal_temp_fops;
  917. entry->data = acpi_driver_data(device);
  918. entry->owner = THIS_MODULE;
  919. }
  920. /* 'trip_points' [R] */
  921. entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
  922. S_IRUGO,
  923. acpi_device_dir(device));
  924. if (!entry)
  925. return -ENODEV;
  926. else {
  927. entry->proc_fops = &acpi_thermal_trip_fops;
  928. entry->data = acpi_driver_data(device);
  929. entry->owner = THIS_MODULE;
  930. }
  931. /* 'cooling_mode' [R/W] */
  932. entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
  933. S_IFREG | S_IRUGO | S_IWUSR,
  934. acpi_device_dir(device));
  935. if (!entry)
  936. return -ENODEV;
  937. else {
  938. entry->proc_fops = &acpi_thermal_cooling_fops;
  939. entry->data = acpi_driver_data(device);
  940. entry->owner = THIS_MODULE;
  941. }
  942. /* 'polling_frequency' [R/W] */
  943. entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
  944. S_IFREG | S_IRUGO | S_IWUSR,
  945. acpi_device_dir(device));
  946. if (!entry)
  947. return -ENODEV;
  948. else {
  949. entry->proc_fops = &acpi_thermal_polling_fops;
  950. entry->data = acpi_driver_data(device);
  951. entry->owner = THIS_MODULE;
  952. }
  953. return 0;
  954. }
  955. static int acpi_thermal_remove_fs(struct acpi_device *device)
  956. {
  957. if (acpi_device_dir(device)) {
  958. remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
  959. acpi_device_dir(device));
  960. remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
  961. acpi_device_dir(device));
  962. remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
  963. acpi_device_dir(device));
  964. remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
  965. acpi_device_dir(device));
  966. remove_proc_entry(ACPI_THERMAL_FILE_STATE,
  967. acpi_device_dir(device));
  968. remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
  969. acpi_device_dir(device) = NULL;
  970. }
  971. return 0;
  972. }
  973. /* --------------------------------------------------------------------------
  974. Driver Interface
  975. -------------------------------------------------------------------------- */
  976. static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
  977. {
  978. struct acpi_thermal *tz = data;
  979. struct acpi_device *device = NULL;
  980. if (!tz)
  981. return;
  982. device = tz->device;
  983. switch (event) {
  984. case ACPI_THERMAL_NOTIFY_TEMPERATURE:
  985. acpi_thermal_check(tz);
  986. break;
  987. case ACPI_THERMAL_NOTIFY_THRESHOLDS:
  988. acpi_thermal_get_trip_points(tz);
  989. acpi_thermal_check(tz);
  990. acpi_bus_generate_proc_event(device, event, 0);
  991. acpi_bus_generate_netlink_event(device->pnp.device_class,
  992. device->dev.bus_id, event, 0);
  993. break;
  994. case ACPI_THERMAL_NOTIFY_DEVICES:
  995. if (tz->flags.devices)
  996. acpi_thermal_get_devices(tz);
  997. acpi_bus_generate_proc_event(device, event, 0);
  998. acpi_bus_generate_netlink_event(device->pnp.device_class,
  999. device->dev.bus_id, event, 0);
  1000. break;
  1001. default:
  1002. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  1003. "Unsupported event [0x%x]\n", event));
  1004. break;
  1005. }
  1006. return;
  1007. }
  1008. static int acpi_thermal_get_info(struct acpi_thermal *tz)
  1009. {
  1010. int result = 0;
  1011. if (!tz)
  1012. return -EINVAL;
  1013. /* Get temperature [_TMP] (required) */
  1014. result = acpi_thermal_get_temperature(tz);
  1015. if (result)
  1016. return result;
  1017. /* Get trip points [_CRT, _PSV, etc.] (required) */
  1018. result = acpi_thermal_get_trip_points(tz);
  1019. if (result)
  1020. return result;
  1021. /* Set the cooling mode [_SCP] to active cooling (default) */
  1022. result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
  1023. if (!result)
  1024. tz->flags.cooling_mode = 1;
  1025. /* Get default polling frequency [_TZP] (optional) */
  1026. if (tzp)
  1027. tz->polling_frequency = tzp;
  1028. else
  1029. acpi_thermal_get_polling_frequency(tz);
  1030. /* Get devices in this thermal zone [_TZD] (optional) */
  1031. result = acpi_thermal_get_devices(tz);
  1032. if (!result)
  1033. tz->flags.devices = 1;
  1034. return 0;
  1035. }
  1036. static int acpi_thermal_add(struct acpi_device *device)
  1037. {
  1038. int result = 0;
  1039. acpi_status status = AE_OK;
  1040. struct acpi_thermal *tz = NULL;
  1041. if (!device)
  1042. return -EINVAL;
  1043. tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
  1044. if (!tz)
  1045. return -ENOMEM;
  1046. tz->device = device;
  1047. strcpy(tz->name, device->pnp.bus_id);
  1048. strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
  1049. strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
  1050. acpi_driver_data(device) = tz;
  1051. mutex_init(&tz->lock);
  1052. result = acpi_thermal_get_info(tz);
  1053. if (result)
  1054. goto end;
  1055. result = acpi_thermal_add_fs(device);
  1056. if (result)
  1057. goto end;
  1058. init_timer(&tz->timer);
  1059. acpi_thermal_check(tz);
  1060. status = acpi_install_notify_handler(device->handle,
  1061. ACPI_DEVICE_NOTIFY,
  1062. acpi_thermal_notify, tz);
  1063. if (ACPI_FAILURE(status)) {
  1064. result = -ENODEV;
  1065. goto end;
  1066. }
  1067. printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
  1068. acpi_device_name(device), acpi_device_bid(device),
  1069. KELVIN_TO_CELSIUS(tz->temperature));
  1070. end:
  1071. if (result) {
  1072. acpi_thermal_remove_fs(device);
  1073. kfree(tz);
  1074. }
  1075. return result;
  1076. }
  1077. static int acpi_thermal_remove(struct acpi_device *device, int type)
  1078. {
  1079. acpi_status status = AE_OK;
  1080. struct acpi_thermal *tz = NULL;
  1081. if (!device || !acpi_driver_data(device))
  1082. return -EINVAL;
  1083. tz = acpi_driver_data(device);
  1084. /* avoid timer adding new defer task */
  1085. tz->zombie = 1;
  1086. /* wait for running timer (on other CPUs) finish */
  1087. del_timer_sync(&(tz->timer));
  1088. /* synchronize deferred task */
  1089. acpi_os_wait_events_complete(NULL);
  1090. /* deferred task may reinsert timer */
  1091. del_timer_sync(&(tz->timer));
  1092. status = acpi_remove_notify_handler(device->handle,
  1093. ACPI_DEVICE_NOTIFY,
  1094. acpi_thermal_notify);
  1095. /* Terminate policy */
  1096. if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
  1097. tz->trips.passive.flags.enabled = 0;
  1098. acpi_thermal_passive(tz);
  1099. }
  1100. if (tz->trips.active[0].flags.valid
  1101. && tz->trips.active[0].flags.enabled) {
  1102. tz->trips.active[0].flags.enabled = 0;
  1103. acpi_thermal_active(tz);
  1104. }
  1105. acpi_thermal_remove_fs(device);
  1106. mutex_destroy(&tz->lock);
  1107. kfree(tz);
  1108. return 0;
  1109. }
  1110. static int acpi_thermal_resume(struct acpi_device *device)
  1111. {
  1112. struct acpi_thermal *tz = NULL;
  1113. int i, j, power_state, result;
  1114. if (!device || !acpi_driver_data(device))
  1115. return -EINVAL;
  1116. tz = acpi_driver_data(device);
  1117. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  1118. if (!(&tz->trips.active[i]))
  1119. break;
  1120. if (!tz->trips.active[i].flags.valid)
  1121. break;
  1122. tz->trips.active[i].flags.enabled = 1;
  1123. for (j = 0; j < tz->trips.active[i].devices.count; j++) {
  1124. result = acpi_bus_get_power(tz->trips.active[i].devices.
  1125. handles[j], &power_state);
  1126. if (result || (power_state != ACPI_STATE_D0)) {
  1127. tz->trips.active[i].flags.enabled = 0;
  1128. break;
  1129. }
  1130. }
  1131. tz->state.active |= tz->trips.active[i].flags.enabled;
  1132. }
  1133. acpi_thermal_check(tz);
  1134. return AE_OK;
  1135. }
  1136. #ifdef CONFIG_DMI
  1137. static int thermal_act(const struct dmi_system_id *d) {
  1138. if (act == 0) {
  1139. printk(KERN_NOTICE "ACPI: %s detected: "
  1140. "disabling all active thermal trip points\n", d->ident);
  1141. act = -1;
  1142. }
  1143. return 0;
  1144. }
  1145. static int thermal_nocrt(const struct dmi_system_id *d) {
  1146. printk(KERN_NOTICE "ACPI: %s detected: "
  1147. "disabling all critical thermal trip point actions.\n", d->ident);
  1148. nocrt = 1;
  1149. return 0;
  1150. }
  1151. static int thermal_tzp(const struct dmi_system_id *d) {
  1152. if (tzp == 0) {
  1153. printk(KERN_NOTICE "ACPI: %s detected: "
  1154. "enabling thermal zone polling\n", d->ident);
  1155. tzp = 300; /* 300 dS = 30 Seconds */
  1156. }
  1157. return 0;
  1158. }
  1159. static int thermal_psv(const struct dmi_system_id *d) {
  1160. if (psv == 0) {
  1161. printk(KERN_NOTICE "ACPI: %s detected: "
  1162. "disabling all passive thermal trip points\n", d->ident);
  1163. psv = -1;
  1164. }
  1165. return 0;
  1166. }
  1167. static struct dmi_system_id thermal_dmi_table[] __initdata = {
  1168. /*
  1169. * Award BIOS on this AOpen makes thermal control almost worthless.
  1170. * http://bugzilla.kernel.org/show_bug.cgi?id=8842
  1171. */
  1172. {
  1173. .callback = thermal_act,
  1174. .ident = "AOpen i915GMm-HFS",
  1175. .matches = {
  1176. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  1177. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  1178. },
  1179. },
  1180. {
  1181. .callback = thermal_psv,
  1182. .ident = "AOpen i915GMm-HFS",
  1183. .matches = {
  1184. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  1185. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  1186. },
  1187. },
  1188. {
  1189. .callback = thermal_tzp,
  1190. .ident = "AOpen i915GMm-HFS",
  1191. .matches = {
  1192. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  1193. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  1194. },
  1195. },
  1196. {
  1197. .callback = thermal_nocrt,
  1198. .ident = "Gigabyte GA-7ZX",
  1199. .matches = {
  1200. DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
  1201. DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
  1202. },
  1203. },
  1204. {}
  1205. };
  1206. #endif /* CONFIG_DMI */
  1207. static int __init acpi_thermal_init(void)
  1208. {
  1209. int result = 0;
  1210. dmi_check_system(thermal_dmi_table);
  1211. if (off) {
  1212. printk(KERN_NOTICE "ACPI: thermal control disabled\n");
  1213. return -ENODEV;
  1214. }
  1215. acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
  1216. if (!acpi_thermal_dir)
  1217. return -ENODEV;
  1218. acpi_thermal_dir->owner = THIS_MODULE;
  1219. result = acpi_bus_register_driver(&acpi_thermal_driver);
  1220. if (result < 0) {
  1221. remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
  1222. return -ENODEV;
  1223. }
  1224. return 0;
  1225. }
  1226. static void __exit acpi_thermal_exit(void)
  1227. {
  1228. acpi_bus_unregister_driver(&acpi_thermal_driver);
  1229. remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
  1230. return;
  1231. }
  1232. module_init(acpi_thermal_init);
  1233. module_exit(acpi_thermal_exit);