thermal.c 36 KB

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