thermal.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441
  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. acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
  405. tz->device->dev.bus_id,
  406. ACPI_THERMAL_NOTIFY_CRITICAL,
  407. tz->trips.critical.flags.enabled);
  408. orderly_poweroff(true);
  409. return 0;
  410. }
  411. static int acpi_thermal_hot(struct acpi_thermal *tz)
  412. {
  413. if (!tz || !tz->trips.hot.flags.valid || nocrt)
  414. return -EINVAL;
  415. if (tz->temperature >= tz->trips.hot.temperature) {
  416. printk(KERN_WARNING PREFIX "Hot trip point\n");
  417. tz->trips.hot.flags.enabled = 1;
  418. } else if (tz->trips.hot.flags.enabled)
  419. tz->trips.hot.flags.enabled = 0;
  420. acpi_bus_generate_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
  421. tz->trips.hot.flags.enabled);
  422. acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
  423. tz->device->dev.bus_id,
  424. ACPI_THERMAL_NOTIFY_HOT,
  425. tz->trips.hot.flags.enabled);
  426. /* TBD: Call user-mode "sleep(S4)" function */
  427. return 0;
  428. }
  429. static void acpi_thermal_passive(struct acpi_thermal *tz)
  430. {
  431. int result = 1;
  432. struct acpi_thermal_passive *passive = NULL;
  433. int trend = 0;
  434. int i = 0;
  435. if (!tz || !tz->trips.passive.flags.valid)
  436. return;
  437. passive = &(tz->trips.passive);
  438. /*
  439. * Above Trip?
  440. * -----------
  441. * Calculate the thermal trend (using the passive cooling equation)
  442. * and modify the performance limit for all passive cooling devices
  443. * accordingly. Note that we assume symmetry.
  444. */
  445. if (tz->temperature >= passive->temperature) {
  446. trend =
  447. (passive->tc1 * (tz->temperature - tz->last_temperature)) +
  448. (passive->tc2 * (tz->temperature - passive->temperature));
  449. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  450. "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
  451. trend, passive->tc1, tz->temperature,
  452. tz->last_temperature, passive->tc2,
  453. tz->temperature, passive->temperature));
  454. passive->flags.enabled = 1;
  455. /* Heating up? */
  456. if (trend > 0)
  457. for (i = 0; i < passive->devices.count; i++)
  458. acpi_processor_set_thermal_limit(passive->
  459. devices.
  460. handles[i],
  461. ACPI_PROCESSOR_LIMIT_INCREMENT);
  462. /* Cooling off? */
  463. else if (trend < 0) {
  464. for (i = 0; i < passive->devices.count; i++)
  465. /*
  466. * assume that we are on highest
  467. * freq/lowest thrott and can leave
  468. * passive mode, even in error case
  469. */
  470. if (!acpi_processor_set_thermal_limit
  471. (passive->devices.handles[i],
  472. ACPI_PROCESSOR_LIMIT_DECREMENT))
  473. result = 0;
  474. /*
  475. * Leave cooling mode, even if the temp might
  476. * higher than trip point This is because some
  477. * machines might have long thermal polling
  478. * frequencies (tsp) defined. We will fall back
  479. * into passive mode in next cycle (probably quicker)
  480. */
  481. if (result) {
  482. passive->flags.enabled = 0;
  483. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  484. "Disabling passive cooling, still above threshold,"
  485. " but we are cooling down\n"));
  486. }
  487. }
  488. return;
  489. }
  490. /*
  491. * Below Trip?
  492. * -----------
  493. * Implement passive cooling hysteresis to slowly increase performance
  494. * and avoid thrashing around the passive trip point. Note that we
  495. * assume symmetry.
  496. */
  497. if (!passive->flags.enabled)
  498. return;
  499. for (i = 0; i < passive->devices.count; i++)
  500. if (!acpi_processor_set_thermal_limit
  501. (passive->devices.handles[i],
  502. ACPI_PROCESSOR_LIMIT_DECREMENT))
  503. result = 0;
  504. if (result) {
  505. passive->flags.enabled = 0;
  506. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  507. "Disabling passive cooling (zone is cool)\n"));
  508. }
  509. }
  510. static void acpi_thermal_active(struct acpi_thermal *tz)
  511. {
  512. int result = 0;
  513. struct acpi_thermal_active *active = NULL;
  514. int i = 0;
  515. int j = 0;
  516. unsigned long maxtemp = 0;
  517. if (!tz)
  518. return;
  519. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  520. active = &(tz->trips.active[i]);
  521. if (!active || !active->flags.valid)
  522. break;
  523. if (tz->temperature >= active->temperature) {
  524. /*
  525. * Above Threshold?
  526. * ----------------
  527. * If not already enabled, turn ON all cooling devices
  528. * associated with this active threshold.
  529. */
  530. if (active->temperature > maxtemp)
  531. tz->state.active_index = i;
  532. maxtemp = active->temperature;
  533. if (active->flags.enabled)
  534. continue;
  535. for (j = 0; j < active->devices.count; j++) {
  536. result =
  537. acpi_bus_set_power(active->devices.
  538. handles[j],
  539. ACPI_STATE_D0);
  540. if (result) {
  541. printk(KERN_WARNING PREFIX
  542. "Unable to turn cooling device [%p] 'on'\n",
  543. active->devices.
  544. handles[j]);
  545. continue;
  546. }
  547. active->flags.enabled = 1;
  548. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  549. "Cooling device [%p] now 'on'\n",
  550. active->devices.handles[j]));
  551. }
  552. continue;
  553. }
  554. if (!active->flags.enabled)
  555. continue;
  556. /*
  557. * Below Threshold?
  558. * ----------------
  559. * Turn OFF all cooling devices associated with this
  560. * threshold.
  561. */
  562. for (j = 0; j < active->devices.count; j++) {
  563. result = acpi_bus_set_power(active->devices.handles[j],
  564. ACPI_STATE_D3);
  565. if (result) {
  566. printk(KERN_WARNING PREFIX
  567. "Unable to turn cooling device [%p] 'off'\n",
  568. active->devices.handles[j]);
  569. continue;
  570. }
  571. active->flags.enabled = 0;
  572. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  573. "Cooling device [%p] now 'off'\n",
  574. active->devices.handles[j]));
  575. }
  576. }
  577. }
  578. static void acpi_thermal_check(void *context);
  579. static void acpi_thermal_run(unsigned long data)
  580. {
  581. struct acpi_thermal *tz = (struct acpi_thermal *)data;
  582. if (!tz->zombie)
  583. acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data);
  584. }
  585. static void acpi_thermal_check(void *data)
  586. {
  587. int result = 0;
  588. struct acpi_thermal *tz = data;
  589. unsigned long sleep_time = 0;
  590. int i = 0;
  591. struct acpi_thermal_state state;
  592. if (!tz) {
  593. printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
  594. return;
  595. }
  596. state = tz->state;
  597. result = acpi_thermal_get_temperature(tz);
  598. if (result)
  599. return;
  600. memset(&tz->state, 0, sizeof(tz->state));
  601. /*
  602. * Check Trip Points
  603. * -----------------
  604. * Compare the current temperature to the trip point values to see
  605. * if we've entered one of the thermal policy states. Note that
  606. * this function determines when a state is entered, but the
  607. * individual policy decides when it is exited (e.g. hysteresis).
  608. */
  609. if (tz->trips.critical.flags.valid)
  610. state.critical |=
  611. (tz->temperature >= tz->trips.critical.temperature);
  612. if (tz->trips.hot.flags.valid)
  613. state.hot |= (tz->temperature >= tz->trips.hot.temperature);
  614. if (tz->trips.passive.flags.valid)
  615. state.passive |=
  616. (tz->temperature >= tz->trips.passive.temperature);
  617. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
  618. if (tz->trips.active[i].flags.valid)
  619. state.active |=
  620. (tz->temperature >=
  621. tz->trips.active[i].temperature);
  622. /*
  623. * Invoke Policy
  624. * -------------
  625. * Separated from the above check to allow individual policy to
  626. * determine when to exit a given state.
  627. */
  628. if (state.critical)
  629. acpi_thermal_critical(tz);
  630. if (state.hot)
  631. acpi_thermal_hot(tz);
  632. if (state.passive)
  633. acpi_thermal_passive(tz);
  634. if (state.active)
  635. acpi_thermal_active(tz);
  636. /*
  637. * Calculate State
  638. * ---------------
  639. * Again, separated from the above two to allow independent policy
  640. * decisions.
  641. */
  642. tz->state.critical = tz->trips.critical.flags.enabled;
  643. tz->state.hot = tz->trips.hot.flags.enabled;
  644. tz->state.passive = tz->trips.passive.flags.enabled;
  645. tz->state.active = 0;
  646. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
  647. tz->state.active |= tz->trips.active[i].flags.enabled;
  648. /*
  649. * Calculate Sleep Time
  650. * --------------------
  651. * If we're in the passive state, use _TSP's value. Otherwise
  652. * use the default polling frequency (e.g. _TZP). If no polling
  653. * frequency is specified then we'll wait forever (at least until
  654. * a thermal event occurs). Note that _TSP and _TZD values are
  655. * given in 1/10th seconds (we must covert to milliseconds).
  656. */
  657. if (tz->state.passive)
  658. sleep_time = tz->trips.passive.tsp * 100;
  659. else if (tz->polling_frequency > 0)
  660. sleep_time = tz->polling_frequency * 100;
  661. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n",
  662. tz->name, tz->temperature, sleep_time));
  663. /*
  664. * Schedule Next Poll
  665. * ------------------
  666. */
  667. if (!sleep_time) {
  668. if (timer_pending(&(tz->timer)))
  669. del_timer(&(tz->timer));
  670. } else {
  671. if (timer_pending(&(tz->timer)))
  672. mod_timer(&(tz->timer),
  673. jiffies + (HZ * sleep_time) / 1000);
  674. else {
  675. tz->timer.data = (unsigned long)tz;
  676. tz->timer.function = acpi_thermal_run;
  677. tz->timer.expires = jiffies + (HZ * sleep_time) / 1000;
  678. add_timer(&(tz->timer));
  679. }
  680. }
  681. return;
  682. }
  683. /* --------------------------------------------------------------------------
  684. FS Interface (/proc)
  685. -------------------------------------------------------------------------- */
  686. static struct proc_dir_entry *acpi_thermal_dir;
  687. static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
  688. {
  689. struct acpi_thermal *tz = seq->private;
  690. if (!tz)
  691. goto end;
  692. seq_puts(seq, "state: ");
  693. if (!tz->state.critical && !tz->state.hot && !tz->state.passive
  694. && !tz->state.active)
  695. seq_puts(seq, "ok\n");
  696. else {
  697. if (tz->state.critical)
  698. seq_puts(seq, "critical ");
  699. if (tz->state.hot)
  700. seq_puts(seq, "hot ");
  701. if (tz->state.passive)
  702. seq_puts(seq, "passive ");
  703. if (tz->state.active)
  704. seq_printf(seq, "active[%d]", tz->state.active_index);
  705. seq_puts(seq, "\n");
  706. }
  707. end:
  708. return 0;
  709. }
  710. static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
  711. {
  712. return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
  713. }
  714. static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
  715. {
  716. int result = 0;
  717. struct acpi_thermal *tz = seq->private;
  718. if (!tz)
  719. goto end;
  720. result = acpi_thermal_get_temperature(tz);
  721. if (result)
  722. goto end;
  723. seq_printf(seq, "temperature: %ld C\n",
  724. KELVIN_TO_CELSIUS(tz->temperature));
  725. end:
  726. return 0;
  727. }
  728. static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
  729. {
  730. return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
  731. }
  732. static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
  733. {
  734. struct acpi_thermal *tz = seq->private;
  735. struct acpi_device *device;
  736. acpi_status status;
  737. int i = 0;
  738. int j = 0;
  739. if (!tz)
  740. goto end;
  741. if (tz->trips.critical.flags.valid)
  742. seq_printf(seq, "critical (S5): %ld C%s",
  743. KELVIN_TO_CELSIUS(tz->trips.critical.temperature),
  744. nocrt ? " <disabled>\n" : "\n");
  745. if (tz->trips.hot.flags.valid)
  746. seq_printf(seq, "hot (S4): %ld C%s",
  747. KELVIN_TO_CELSIUS(tz->trips.hot.temperature),
  748. nocrt ? " <disabled>\n" : "\n");
  749. if (tz->trips.passive.flags.valid) {
  750. seq_printf(seq,
  751. "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
  752. KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
  753. tz->trips.passive.tc1, tz->trips.passive.tc2,
  754. tz->trips.passive.tsp);
  755. for (j = 0; j < tz->trips.passive.devices.count; j++) {
  756. status = acpi_bus_get_device(tz->trips.passive.devices.
  757. handles[j], &device);
  758. seq_printf(seq, "%4.4s ", status ? "" :
  759. acpi_device_bid(device));
  760. }
  761. seq_puts(seq, "\n");
  762. }
  763. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  764. if (!(tz->trips.active[i].flags.valid))
  765. break;
  766. seq_printf(seq, "active[%d]: %ld C: devices=",
  767. i,
  768. KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
  769. for (j = 0; j < tz->trips.active[i].devices.count; j++){
  770. status = acpi_bus_get_device(tz->trips.active[i].
  771. devices.handles[j],
  772. &device);
  773. seq_printf(seq, "%4.4s ", status ? "" :
  774. acpi_device_bid(device));
  775. }
  776. seq_puts(seq, "\n");
  777. }
  778. end:
  779. return 0;
  780. }
  781. static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
  782. {
  783. return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
  784. }
  785. static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
  786. {
  787. struct acpi_thermal *tz = seq->private;
  788. if (!tz)
  789. goto end;
  790. if (!tz->flags.cooling_mode)
  791. seq_puts(seq, "<setting not supported>\n");
  792. else
  793. seq_puts(seq, "0 - Active; 1 - Passive\n");
  794. end:
  795. return 0;
  796. }
  797. static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
  798. {
  799. return single_open(file, acpi_thermal_cooling_seq_show,
  800. PDE(inode)->data);
  801. }
  802. static ssize_t
  803. acpi_thermal_write_cooling_mode(struct file *file,
  804. const char __user * buffer,
  805. size_t count, loff_t * ppos)
  806. {
  807. struct seq_file *m = file->private_data;
  808. struct acpi_thermal *tz = m->private;
  809. int result = 0;
  810. char mode_string[12] = { '\0' };
  811. if (!tz || (count > sizeof(mode_string) - 1))
  812. return -EINVAL;
  813. if (!tz->flags.cooling_mode)
  814. return -ENODEV;
  815. if (copy_from_user(mode_string, buffer, count))
  816. return -EFAULT;
  817. mode_string[count] = '\0';
  818. result = acpi_thermal_set_cooling_mode(tz,
  819. simple_strtoul(mode_string, NULL,
  820. 0));
  821. if (result)
  822. return result;
  823. acpi_thermal_check(tz);
  824. return count;
  825. }
  826. static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
  827. {
  828. struct acpi_thermal *tz = seq->private;
  829. if (!tz)
  830. goto end;
  831. if (!tz->polling_frequency) {
  832. seq_puts(seq, "<polling disabled>\n");
  833. goto end;
  834. }
  835. seq_printf(seq, "polling frequency: %lu seconds\n",
  836. (tz->polling_frequency / 10));
  837. end:
  838. return 0;
  839. }
  840. static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
  841. {
  842. return single_open(file, acpi_thermal_polling_seq_show,
  843. PDE(inode)->data);
  844. }
  845. static ssize_t
  846. acpi_thermal_write_polling(struct file *file,
  847. const char __user * buffer,
  848. size_t count, loff_t * ppos)
  849. {
  850. struct seq_file *m = file->private_data;
  851. struct acpi_thermal *tz = m->private;
  852. int result = 0;
  853. char polling_string[12] = { '\0' };
  854. int seconds = 0;
  855. if (!tz || (count > sizeof(polling_string) - 1))
  856. return -EINVAL;
  857. if (copy_from_user(polling_string, buffer, count))
  858. return -EFAULT;
  859. polling_string[count] = '\0';
  860. seconds = simple_strtoul(polling_string, NULL, 0);
  861. result = acpi_thermal_set_polling(tz, seconds);
  862. if (result)
  863. return result;
  864. acpi_thermal_check(tz);
  865. return count;
  866. }
  867. static int acpi_thermal_add_fs(struct acpi_device *device)
  868. {
  869. struct proc_dir_entry *entry = NULL;
  870. if (!acpi_device_dir(device)) {
  871. acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
  872. acpi_thermal_dir);
  873. if (!acpi_device_dir(device))
  874. return -ENODEV;
  875. acpi_device_dir(device)->owner = THIS_MODULE;
  876. }
  877. /* 'state' [R] */
  878. entry = create_proc_entry(ACPI_THERMAL_FILE_STATE,
  879. S_IRUGO, acpi_device_dir(device));
  880. if (!entry)
  881. return -ENODEV;
  882. else {
  883. entry->proc_fops = &acpi_thermal_state_fops;
  884. entry->data = acpi_driver_data(device);
  885. entry->owner = THIS_MODULE;
  886. }
  887. /* 'temperature' [R] */
  888. entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
  889. S_IRUGO, acpi_device_dir(device));
  890. if (!entry)
  891. return -ENODEV;
  892. else {
  893. entry->proc_fops = &acpi_thermal_temp_fops;
  894. entry->data = acpi_driver_data(device);
  895. entry->owner = THIS_MODULE;
  896. }
  897. /* 'trip_points' [R/W] */
  898. entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
  899. S_IFREG | S_IRUGO | S_IWUSR,
  900. acpi_device_dir(device));
  901. if (!entry)
  902. return -ENODEV;
  903. else {
  904. entry->proc_fops = &acpi_thermal_trip_fops;
  905. entry->data = acpi_driver_data(device);
  906. entry->owner = THIS_MODULE;
  907. }
  908. /* 'cooling_mode' [R/W] */
  909. entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
  910. S_IFREG | S_IRUGO | S_IWUSR,
  911. acpi_device_dir(device));
  912. if (!entry)
  913. return -ENODEV;
  914. else {
  915. entry->proc_fops = &acpi_thermal_cooling_fops;
  916. entry->data = acpi_driver_data(device);
  917. entry->owner = THIS_MODULE;
  918. }
  919. /* 'polling_frequency' [R/W] */
  920. entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
  921. S_IFREG | S_IRUGO | S_IWUSR,
  922. acpi_device_dir(device));
  923. if (!entry)
  924. return -ENODEV;
  925. else {
  926. entry->proc_fops = &acpi_thermal_polling_fops;
  927. entry->data = acpi_driver_data(device);
  928. entry->owner = THIS_MODULE;
  929. }
  930. return 0;
  931. }
  932. static int acpi_thermal_remove_fs(struct acpi_device *device)
  933. {
  934. if (acpi_device_dir(device)) {
  935. remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
  936. acpi_device_dir(device));
  937. remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
  938. acpi_device_dir(device));
  939. remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
  940. acpi_device_dir(device));
  941. remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
  942. acpi_device_dir(device));
  943. remove_proc_entry(ACPI_THERMAL_FILE_STATE,
  944. acpi_device_dir(device));
  945. remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
  946. acpi_device_dir(device) = NULL;
  947. }
  948. return 0;
  949. }
  950. /* --------------------------------------------------------------------------
  951. Driver Interface
  952. -------------------------------------------------------------------------- */
  953. static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
  954. {
  955. struct acpi_thermal *tz = data;
  956. struct acpi_device *device = NULL;
  957. if (!tz)
  958. return;
  959. device = tz->device;
  960. switch (event) {
  961. case ACPI_THERMAL_NOTIFY_TEMPERATURE:
  962. acpi_thermal_check(tz);
  963. break;
  964. case ACPI_THERMAL_NOTIFY_THRESHOLDS:
  965. acpi_thermal_get_trip_points(tz);
  966. acpi_thermal_check(tz);
  967. acpi_bus_generate_event(device, event, 0);
  968. acpi_bus_generate_netlink_event(device->pnp.device_class,
  969. device->dev.bus_id, event, 0);
  970. break;
  971. case ACPI_THERMAL_NOTIFY_DEVICES:
  972. if (tz->flags.devices)
  973. acpi_thermal_get_devices(tz);
  974. acpi_bus_generate_event(device, event, 0);
  975. acpi_bus_generate_netlink_event(device->pnp.device_class,
  976. device->dev.bus_id, event, 0);
  977. break;
  978. default:
  979. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  980. "Unsupported event [0x%x]\n", event));
  981. break;
  982. }
  983. return;
  984. }
  985. static int acpi_thermal_get_info(struct acpi_thermal *tz)
  986. {
  987. int result = 0;
  988. if (!tz)
  989. return -EINVAL;
  990. /* Get temperature [_TMP] (required) */
  991. result = acpi_thermal_get_temperature(tz);
  992. if (result)
  993. return result;
  994. /* Get trip points [_CRT, _PSV, etc.] (required) */
  995. result = acpi_thermal_get_trip_points(tz);
  996. if (result)
  997. return result;
  998. /* Set the cooling mode [_SCP] to active cooling (default) */
  999. result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
  1000. if (!result)
  1001. tz->flags.cooling_mode = 1;
  1002. /* Get default polling frequency [_TZP] (optional) */
  1003. if (tzp)
  1004. tz->polling_frequency = tzp;
  1005. else
  1006. acpi_thermal_get_polling_frequency(tz);
  1007. /* Get devices in this thermal zone [_TZD] (optional) */
  1008. result = acpi_thermal_get_devices(tz);
  1009. if (!result)
  1010. tz->flags.devices = 1;
  1011. return 0;
  1012. }
  1013. static int acpi_thermal_add(struct acpi_device *device)
  1014. {
  1015. int result = 0;
  1016. acpi_status status = AE_OK;
  1017. struct acpi_thermal *tz = NULL;
  1018. if (!device)
  1019. return -EINVAL;
  1020. tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
  1021. if (!tz)
  1022. return -ENOMEM;
  1023. tz->device = device;
  1024. strcpy(tz->name, device->pnp.bus_id);
  1025. strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
  1026. strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
  1027. acpi_driver_data(device) = tz;
  1028. result = acpi_thermal_get_info(tz);
  1029. if (result)
  1030. goto end;
  1031. result = acpi_thermal_add_fs(device);
  1032. if (result)
  1033. goto end;
  1034. init_timer(&tz->timer);
  1035. acpi_thermal_check(tz);
  1036. status = acpi_install_notify_handler(device->handle,
  1037. ACPI_DEVICE_NOTIFY,
  1038. acpi_thermal_notify, tz);
  1039. if (ACPI_FAILURE(status)) {
  1040. result = -ENODEV;
  1041. goto end;
  1042. }
  1043. printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
  1044. acpi_device_name(device), acpi_device_bid(device),
  1045. KELVIN_TO_CELSIUS(tz->temperature));
  1046. end:
  1047. if (result) {
  1048. acpi_thermal_remove_fs(device);
  1049. kfree(tz);
  1050. }
  1051. return result;
  1052. }
  1053. static int acpi_thermal_remove(struct acpi_device *device, int type)
  1054. {
  1055. acpi_status status = AE_OK;
  1056. struct acpi_thermal *tz = NULL;
  1057. if (!device || !acpi_driver_data(device))
  1058. return -EINVAL;
  1059. tz = acpi_driver_data(device);
  1060. /* avoid timer adding new defer task */
  1061. tz->zombie = 1;
  1062. /* wait for running timer (on other CPUs) finish */
  1063. del_timer_sync(&(tz->timer));
  1064. /* synchronize deferred task */
  1065. acpi_os_wait_events_complete(NULL);
  1066. /* deferred task may reinsert timer */
  1067. del_timer_sync(&(tz->timer));
  1068. status = acpi_remove_notify_handler(device->handle,
  1069. ACPI_DEVICE_NOTIFY,
  1070. acpi_thermal_notify);
  1071. /* Terminate policy */
  1072. if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
  1073. tz->trips.passive.flags.enabled = 0;
  1074. acpi_thermal_passive(tz);
  1075. }
  1076. if (tz->trips.active[0].flags.valid
  1077. && tz->trips.active[0].flags.enabled) {
  1078. tz->trips.active[0].flags.enabled = 0;
  1079. acpi_thermal_active(tz);
  1080. }
  1081. acpi_thermal_remove_fs(device);
  1082. kfree(tz);
  1083. return 0;
  1084. }
  1085. static int acpi_thermal_resume(struct acpi_device *device)
  1086. {
  1087. struct acpi_thermal *tz = NULL;
  1088. int i, j, power_state, result;
  1089. if (!device || !acpi_driver_data(device))
  1090. return -EINVAL;
  1091. tz = acpi_driver_data(device);
  1092. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  1093. if (!(&tz->trips.active[i]))
  1094. break;
  1095. if (!tz->trips.active[i].flags.valid)
  1096. break;
  1097. tz->trips.active[i].flags.enabled = 1;
  1098. for (j = 0; j < tz->trips.active[i].devices.count; j++) {
  1099. result = acpi_bus_get_power(tz->trips.active[i].devices.
  1100. handles[j], &power_state);
  1101. if (result || (power_state != ACPI_STATE_D0)) {
  1102. tz->trips.active[i].flags.enabled = 0;
  1103. break;
  1104. }
  1105. }
  1106. tz->state.active |= tz->trips.active[i].flags.enabled;
  1107. }
  1108. acpi_thermal_check(tz);
  1109. return AE_OK;
  1110. }
  1111. #ifdef CONFIG_DMI
  1112. static int thermal_act(struct dmi_system_id *d) {
  1113. if (act == 0) {
  1114. printk(KERN_NOTICE "ACPI: %s detected: "
  1115. "disabling all active thermal trip points\n", d->ident);
  1116. act = -1;
  1117. }
  1118. return 0;
  1119. }
  1120. static int thermal_tzp(struct dmi_system_id *d) {
  1121. if (tzp == 0) {
  1122. printk(KERN_NOTICE "ACPI: %s detected: "
  1123. "enabling thermal zone polling\n", d->ident);
  1124. tzp = 300; /* 300 dS = 30 Seconds */
  1125. }
  1126. return 0;
  1127. }
  1128. static int thermal_psv(struct dmi_system_id *d) {
  1129. if (psv == 0) {
  1130. printk(KERN_NOTICE "ACPI: %s detected: "
  1131. "disabling all passive thermal trip points\n", d->ident);
  1132. psv = -1;
  1133. }
  1134. return 0;
  1135. }
  1136. static struct dmi_system_id thermal_dmi_table[] __initdata = {
  1137. /*
  1138. * Award BIOS on this AOpen makes thermal control almost worthless.
  1139. * http://bugzilla.kernel.org/show_bug.cgi?id=8842
  1140. */
  1141. {
  1142. .callback = thermal_act,
  1143. .ident = "AOpen i915GMm-HFS",
  1144. .matches = {
  1145. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  1146. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  1147. },
  1148. },
  1149. {
  1150. .callback = thermal_psv,
  1151. .ident = "AOpen i915GMm-HFS",
  1152. .matches = {
  1153. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  1154. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  1155. },
  1156. },
  1157. {
  1158. .callback = thermal_tzp,
  1159. .ident = "AOpen i915GMm-HFS",
  1160. .matches = {
  1161. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  1162. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  1163. },
  1164. },
  1165. {}
  1166. };
  1167. #endif /* CONFIG_DMI */
  1168. static int __init acpi_thermal_init(void)
  1169. {
  1170. int result = 0;
  1171. dmi_check_system(thermal_dmi_table);
  1172. if (off) {
  1173. printk(KERN_NOTICE "ACPI: thermal control disabled\n");
  1174. return -ENODEV;
  1175. }
  1176. acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
  1177. if (!acpi_thermal_dir)
  1178. return -ENODEV;
  1179. acpi_thermal_dir->owner = THIS_MODULE;
  1180. result = acpi_bus_register_driver(&acpi_thermal_driver);
  1181. if (result < 0) {
  1182. remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
  1183. return -ENODEV;
  1184. }
  1185. return 0;
  1186. }
  1187. static void __exit acpi_thermal_exit(void)
  1188. {
  1189. acpi_bus_unregister_driver(&acpi_thermal_driver);
  1190. remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
  1191. return;
  1192. }
  1193. module_init(acpi_thermal_init);
  1194. module_exit(acpi_thermal_exit);