thermal.c 37 KB

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