thermal.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558
  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/jiffies.h>
  40. #include <linux/kmod.h>
  41. #include <linux/seq_file.h>
  42. #include <linux/reboot.h>
  43. #include <asm/uaccess.h>
  44. #include <linux/thermal.h>
  45. #include <acpi/acpi_bus.h>
  46. #include <acpi/acpi_drivers.h>
  47. #define ACPI_THERMAL_CLASS "thermal_zone"
  48. #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
  49. #define ACPI_THERMAL_FILE_STATE "state"
  50. #define ACPI_THERMAL_FILE_TEMPERATURE "temperature"
  51. #define ACPI_THERMAL_FILE_TRIP_POINTS "trip_points"
  52. #define ACPI_THERMAL_FILE_COOLING_MODE "cooling_mode"
  53. #define ACPI_THERMAL_FILE_POLLING_FREQ "polling_frequency"
  54. #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80
  55. #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81
  56. #define ACPI_THERMAL_NOTIFY_DEVICES 0x82
  57. #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0
  58. #define ACPI_THERMAL_NOTIFY_HOT 0xF1
  59. #define ACPI_THERMAL_MODE_ACTIVE 0x00
  60. #define ACPI_THERMAL_MAX_ACTIVE 10
  61. #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
  62. #define _COMPONENT ACPI_THERMAL_COMPONENT
  63. ACPI_MODULE_NAME("thermal");
  64. MODULE_AUTHOR("Paul Diefenbaugh");
  65. MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
  66. MODULE_LICENSE("GPL");
  67. static int act;
  68. module_param(act, int, 0644);
  69. MODULE_PARM_DESC(act, "Disable or override all lowest active trip points.");
  70. static int crt;
  71. module_param(crt, int, 0644);
  72. MODULE_PARM_DESC(crt, "Disable or lower all critical trip points.");
  73. static int tzp;
  74. module_param(tzp, int, 0444);
  75. MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.");
  76. static int nocrt;
  77. module_param(nocrt, int, 0);
  78. MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points.");
  79. static int off;
  80. module_param(off, int, 0);
  81. MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.");
  82. static int psv;
  83. module_param(psv, int, 0644);
  84. MODULE_PARM_DESC(psv, "Disable or override all passive trip points.");
  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 thermal_zone_device *thermal_zone;
  170. int tz_enabled;
  171. struct mutex lock;
  172. };
  173. static const struct file_operations acpi_thermal_state_fops = {
  174. .owner = THIS_MODULE,
  175. .open = acpi_thermal_state_open_fs,
  176. .read = seq_read,
  177. .llseek = seq_lseek,
  178. .release = single_release,
  179. };
  180. static const struct file_operations acpi_thermal_temp_fops = {
  181. .owner = THIS_MODULE,
  182. .open = acpi_thermal_temp_open_fs,
  183. .read = seq_read,
  184. .llseek = seq_lseek,
  185. .release = single_release,
  186. };
  187. static const struct file_operations acpi_thermal_trip_fops = {
  188. .owner = THIS_MODULE,
  189. .open = acpi_thermal_trip_open_fs,
  190. .read = seq_read,
  191. .llseek = seq_lseek,
  192. .release = single_release,
  193. };
  194. static const struct file_operations acpi_thermal_cooling_fops = {
  195. .owner = THIS_MODULE,
  196. .open = acpi_thermal_cooling_open_fs,
  197. .read = seq_read,
  198. .write = acpi_thermal_write_cooling_mode,
  199. .llseek = seq_lseek,
  200. .release = single_release,
  201. };
  202. static const struct file_operations acpi_thermal_polling_fops = {
  203. .owner = THIS_MODULE,
  204. .open = acpi_thermal_polling_open_fs,
  205. .read = seq_read,
  206. .write = acpi_thermal_write_polling,
  207. .llseek = seq_lseek,
  208. .release = single_release,
  209. };
  210. /* --------------------------------------------------------------------------
  211. Thermal Zone Management
  212. -------------------------------------------------------------------------- */
  213. static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
  214. {
  215. acpi_status status = AE_OK;
  216. unsigned long long tmp;
  217. if (!tz)
  218. return -EINVAL;
  219. tz->last_temperature = tz->temperature;
  220. status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp);
  221. if (ACPI_FAILURE(status))
  222. return -ENODEV;
  223. tz->temperature = tmp;
  224. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
  225. tz->temperature));
  226. return 0;
  227. }
  228. static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
  229. {
  230. acpi_status status = AE_OK;
  231. unsigned long long tmp;
  232. if (!tz)
  233. return -EINVAL;
  234. status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp);
  235. if (ACPI_FAILURE(status))
  236. return -ENODEV;
  237. tz->polling_frequency = tmp;
  238. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
  239. tz->polling_frequency));
  240. return 0;
  241. }
  242. static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
  243. {
  244. if (!tz)
  245. return -EINVAL;
  246. tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
  247. tz->thermal_zone->polling_delay = seconds * 1000;
  248. if (tz->tz_enabled)
  249. thermal_zone_device_update(tz->thermal_zone);
  250. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  251. "Polling frequency set to %lu seconds\n",
  252. tz->polling_frequency/10));
  253. return 0;
  254. }
  255. static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
  256. {
  257. acpi_status status = AE_OK;
  258. union acpi_object arg0 = { ACPI_TYPE_INTEGER };
  259. struct acpi_object_list arg_list = { 1, &arg0 };
  260. acpi_handle handle = NULL;
  261. if (!tz)
  262. return -EINVAL;
  263. status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
  264. if (ACPI_FAILURE(status)) {
  265. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
  266. return -ENODEV;
  267. }
  268. arg0.integer.value = mode;
  269. status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
  270. if (ACPI_FAILURE(status))
  271. return -ENODEV;
  272. return 0;
  273. }
  274. #define ACPI_TRIPS_CRITICAL 0x01
  275. #define ACPI_TRIPS_HOT 0x02
  276. #define ACPI_TRIPS_PASSIVE 0x04
  277. #define ACPI_TRIPS_ACTIVE 0x08
  278. #define ACPI_TRIPS_DEVICES 0x10
  279. #define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE)
  280. #define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES
  281. #define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \
  282. ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \
  283. ACPI_TRIPS_DEVICES)
  284. /*
  285. * This exception is thrown out in two cases:
  286. * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
  287. * when re-evaluating the AML code.
  288. * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change.
  289. * We need to re-bind the cooling devices of a thermal zone when this occurs.
  290. */
  291. #define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \
  292. do { \
  293. if (flags != ACPI_TRIPS_INIT) \
  294. ACPI_EXCEPTION((AE_INFO, AE_ERROR, \
  295. "ACPI thermal trip point %s changed\n" \
  296. "Please send acpidump to linux-acpi@vger.kernel.org\n", str)); \
  297. } while (0)
  298. static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
  299. {
  300. acpi_status status = AE_OK;
  301. unsigned long long tmp;
  302. struct acpi_handle_list devices;
  303. int valid = 0;
  304. int i;
  305. /* Critical Shutdown (required) */
  306. if (flag & ACPI_TRIPS_CRITICAL) {
  307. status = acpi_evaluate_integer(tz->device->handle,
  308. "_CRT", NULL, &tmp);
  309. tz->trips.critical.temperature = tmp;
  310. /*
  311. * Treat freezing temperatures as invalid as well; some
  312. * BIOSes return really low values and cause reboots at startup.
  313. * Below zero (Celcius) values clearly aren't right for sure..
  314. * ... so lets discard those as invalid.
  315. */
  316. if (ACPI_FAILURE(status) ||
  317. tz->trips.critical.temperature <= 2732) {
  318. tz->trips.critical.flags.valid = 0;
  319. ACPI_EXCEPTION((AE_INFO, status,
  320. "No or invalid critical threshold"));
  321. return -ENODEV;
  322. } else {
  323. tz->trips.critical.flags.valid = 1;
  324. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  325. "Found critical threshold [%lu]\n",
  326. tz->trips.critical.temperature));
  327. }
  328. if (tz->trips.critical.flags.valid == 1) {
  329. if (crt == -1) {
  330. tz->trips.critical.flags.valid = 0;
  331. } else if (crt > 0) {
  332. unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
  333. /*
  334. * Allow override critical threshold
  335. */
  336. if (crt_k > tz->trips.critical.temperature)
  337. printk(KERN_WARNING PREFIX
  338. "Critical threshold %d C\n", crt);
  339. tz->trips.critical.temperature = crt_k;
  340. }
  341. }
  342. }
  343. /* Critical Sleep (optional) */
  344. if (flag & ACPI_TRIPS_HOT) {
  345. status = acpi_evaluate_integer(tz->device->handle,
  346. "_HOT", NULL, &tmp);
  347. if (ACPI_FAILURE(status)) {
  348. tz->trips.hot.flags.valid = 0;
  349. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  350. "No hot threshold\n"));
  351. } else {
  352. tz->trips.hot.temperature = tmp;
  353. tz->trips.hot.flags.valid = 1;
  354. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  355. "Found hot threshold [%lu]\n",
  356. tz->trips.critical.temperature));
  357. }
  358. }
  359. /* Passive (optional) */
  360. if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) ||
  361. (flag == ACPI_TRIPS_INIT)) {
  362. valid = tz->trips.passive.flags.valid;
  363. if (psv == -1) {
  364. status = AE_SUPPORT;
  365. } else if (psv > 0) {
  366. tmp = CELSIUS_TO_KELVIN(psv);
  367. status = AE_OK;
  368. } else {
  369. status = acpi_evaluate_integer(tz->device->handle,
  370. "_PSV", NULL, &tmp);
  371. }
  372. if (ACPI_FAILURE(status))
  373. tz->trips.passive.flags.valid = 0;
  374. else {
  375. tz->trips.passive.temperature = tmp;
  376. tz->trips.passive.flags.valid = 1;
  377. if (flag == ACPI_TRIPS_INIT) {
  378. status = acpi_evaluate_integer(
  379. tz->device->handle, "_TC1",
  380. NULL, &tmp);
  381. if (ACPI_FAILURE(status))
  382. tz->trips.passive.flags.valid = 0;
  383. else
  384. tz->trips.passive.tc1 = tmp;
  385. status = acpi_evaluate_integer(
  386. tz->device->handle, "_TC2",
  387. NULL, &tmp);
  388. if (ACPI_FAILURE(status))
  389. tz->trips.passive.flags.valid = 0;
  390. else
  391. tz->trips.passive.tc2 = tmp;
  392. status = acpi_evaluate_integer(
  393. tz->device->handle, "_TSP",
  394. NULL, &tmp);
  395. if (ACPI_FAILURE(status))
  396. tz->trips.passive.flags.valid = 0;
  397. else
  398. tz->trips.passive.tsp = tmp;
  399. }
  400. }
  401. }
  402. if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) {
  403. memset(&devices, 0, sizeof(struct acpi_handle_list));
  404. status = acpi_evaluate_reference(tz->device->handle, "_PSL",
  405. NULL, &devices);
  406. if (ACPI_FAILURE(status)) {
  407. printk(KERN_WARNING PREFIX
  408. "Invalid passive threshold\n");
  409. tz->trips.passive.flags.valid = 0;
  410. }
  411. else
  412. tz->trips.passive.flags.valid = 1;
  413. if (memcmp(&tz->trips.passive.devices, &devices,
  414. sizeof(struct acpi_handle_list))) {
  415. memcpy(&tz->trips.passive.devices, &devices,
  416. sizeof(struct acpi_handle_list));
  417. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
  418. }
  419. }
  420. if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) {
  421. if (valid != tz->trips.passive.flags.valid)
  422. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
  423. }
  424. /* Active (optional) */
  425. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  426. char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
  427. valid = tz->trips.active[i].flags.valid;
  428. if (act == -1)
  429. break; /* disable all active trip points */
  430. if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) &&
  431. tz->trips.active[i].flags.valid)) {
  432. status = acpi_evaluate_integer(tz->device->handle,
  433. name, NULL, &tmp);
  434. if (ACPI_FAILURE(status)) {
  435. tz->trips.active[i].flags.valid = 0;
  436. if (i == 0)
  437. break;
  438. if (act <= 0)
  439. break;
  440. if (i == 1)
  441. tz->trips.active[0].temperature =
  442. CELSIUS_TO_KELVIN(act);
  443. else
  444. /*
  445. * Don't allow override higher than
  446. * the next higher trip point
  447. */
  448. tz->trips.active[i - 1].temperature =
  449. (tz->trips.active[i - 2].temperature <
  450. CELSIUS_TO_KELVIN(act) ?
  451. tz->trips.active[i - 2].temperature :
  452. CELSIUS_TO_KELVIN(act));
  453. break;
  454. } else {
  455. tz->trips.active[i].temperature = tmp;
  456. tz->trips.active[i].flags.valid = 1;
  457. }
  458. }
  459. name[2] = 'L';
  460. if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) {
  461. memset(&devices, 0, sizeof(struct acpi_handle_list));
  462. status = acpi_evaluate_reference(tz->device->handle,
  463. name, NULL, &devices);
  464. if (ACPI_FAILURE(status)) {
  465. printk(KERN_WARNING PREFIX
  466. "Invalid active%d threshold\n", i);
  467. tz->trips.active[i].flags.valid = 0;
  468. }
  469. else
  470. tz->trips.active[i].flags.valid = 1;
  471. if (memcmp(&tz->trips.active[i].devices, &devices,
  472. sizeof(struct acpi_handle_list))) {
  473. memcpy(&tz->trips.active[i].devices, &devices,
  474. sizeof(struct acpi_handle_list));
  475. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
  476. }
  477. }
  478. if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES))
  479. if (valid != tz->trips.active[i].flags.valid)
  480. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
  481. if (!tz->trips.active[i].flags.valid)
  482. break;
  483. }
  484. if (flag & ACPI_TRIPS_DEVICES) {
  485. memset(&devices, 0, sizeof(struct acpi_handle_list));
  486. status = acpi_evaluate_reference(tz->device->handle, "_TZD",
  487. NULL, &devices);
  488. if (memcmp(&tz->devices, &devices,
  489. sizeof(struct acpi_handle_list))) {
  490. memcpy(&tz->devices, &devices,
  491. sizeof(struct acpi_handle_list));
  492. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
  493. }
  494. }
  495. return 0;
  496. }
  497. static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
  498. {
  499. return acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
  500. }
  501. static void acpi_thermal_check(void *data)
  502. {
  503. struct acpi_thermal *tz = data;
  504. thermal_zone_device_update(tz->thermal_zone);
  505. }
  506. /* sys I/F for generic thermal sysfs support */
  507. #define KELVIN_TO_MILLICELSIUS(t) (t * 100 - 273200)
  508. static int thermal_get_temp(struct thermal_zone_device *thermal,
  509. unsigned long *temp)
  510. {
  511. struct acpi_thermal *tz = thermal->devdata;
  512. int result;
  513. if (!tz)
  514. return -EINVAL;
  515. result = acpi_thermal_get_temperature(tz);
  516. if (result)
  517. return result;
  518. *temp = KELVIN_TO_MILLICELSIUS(tz->temperature);
  519. return 0;
  520. }
  521. static const char enabled[] = "kernel";
  522. static const char disabled[] = "user";
  523. static int thermal_get_mode(struct thermal_zone_device *thermal,
  524. enum thermal_device_mode *mode)
  525. {
  526. struct acpi_thermal *tz = thermal->devdata;
  527. if (!tz)
  528. return -EINVAL;
  529. *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
  530. THERMAL_DEVICE_DISABLED;
  531. return 0;
  532. }
  533. static int thermal_set_mode(struct thermal_zone_device *thermal,
  534. enum thermal_device_mode mode)
  535. {
  536. struct acpi_thermal *tz = thermal->devdata;
  537. int enable;
  538. if (!tz)
  539. return -EINVAL;
  540. /*
  541. * enable/disable thermal management from ACPI thermal driver
  542. */
  543. if (mode == THERMAL_DEVICE_ENABLED)
  544. enable = 1;
  545. else if (mode == THERMAL_DEVICE_DISABLED)
  546. enable = 0;
  547. else
  548. return -EINVAL;
  549. if (enable != tz->tz_enabled) {
  550. tz->tz_enabled = enable;
  551. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  552. "%s ACPI thermal control\n",
  553. tz->tz_enabled ? enabled : disabled));
  554. acpi_thermal_check(tz);
  555. }
  556. return 0;
  557. }
  558. static int thermal_get_trip_type(struct thermal_zone_device *thermal,
  559. int trip, enum thermal_trip_type *type)
  560. {
  561. struct acpi_thermal *tz = thermal->devdata;
  562. int i;
  563. if (!tz || trip < 0)
  564. return -EINVAL;
  565. if (tz->trips.critical.flags.valid) {
  566. if (!trip) {
  567. *type = THERMAL_TRIP_CRITICAL;
  568. return 0;
  569. }
  570. trip--;
  571. }
  572. if (tz->trips.hot.flags.valid) {
  573. if (!trip) {
  574. *type = THERMAL_TRIP_HOT;
  575. return 0;
  576. }
  577. trip--;
  578. }
  579. if (tz->trips.passive.flags.valid) {
  580. if (!trip) {
  581. *type = THERMAL_TRIP_PASSIVE;
  582. return 0;
  583. }
  584. trip--;
  585. }
  586. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
  587. tz->trips.active[i].flags.valid; i++) {
  588. if (!trip) {
  589. *type = THERMAL_TRIP_ACTIVE;
  590. return 0;
  591. }
  592. trip--;
  593. }
  594. return -EINVAL;
  595. }
  596. static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
  597. int trip, unsigned long *temp)
  598. {
  599. struct acpi_thermal *tz = thermal->devdata;
  600. int i;
  601. if (!tz || trip < 0)
  602. return -EINVAL;
  603. if (tz->trips.critical.flags.valid) {
  604. if (!trip) {
  605. *temp = KELVIN_TO_MILLICELSIUS(
  606. tz->trips.critical.temperature);
  607. return 0;
  608. }
  609. trip--;
  610. }
  611. if (tz->trips.hot.flags.valid) {
  612. if (!trip) {
  613. *temp = KELVIN_TO_MILLICELSIUS(
  614. tz->trips.hot.temperature);
  615. return 0;
  616. }
  617. trip--;
  618. }
  619. if (tz->trips.passive.flags.valid) {
  620. if (!trip) {
  621. *temp = KELVIN_TO_MILLICELSIUS(
  622. tz->trips.passive.temperature);
  623. return 0;
  624. }
  625. trip--;
  626. }
  627. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
  628. tz->trips.active[i].flags.valid; i++) {
  629. if (!trip) {
  630. *temp = KELVIN_TO_MILLICELSIUS(
  631. tz->trips.active[i].temperature);
  632. return 0;
  633. }
  634. trip--;
  635. }
  636. return -EINVAL;
  637. }
  638. static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
  639. unsigned long *temperature) {
  640. struct acpi_thermal *tz = thermal->devdata;
  641. if (tz->trips.critical.flags.valid) {
  642. *temperature = KELVIN_TO_MILLICELSIUS(
  643. tz->trips.critical.temperature);
  644. return 0;
  645. } else
  646. return -EINVAL;
  647. }
  648. static int thermal_notify(struct thermal_zone_device *thermal, int trip,
  649. enum thermal_trip_type trip_type)
  650. {
  651. u8 type = 0;
  652. struct acpi_thermal *tz = thermal->devdata;
  653. if (trip_type == THERMAL_TRIP_CRITICAL)
  654. type = ACPI_THERMAL_NOTIFY_CRITICAL;
  655. else if (trip_type == THERMAL_TRIP_HOT)
  656. type = ACPI_THERMAL_NOTIFY_HOT;
  657. else
  658. return 0;
  659. acpi_bus_generate_proc_event(tz->device, type, 1);
  660. acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
  661. tz->device->dev.bus_id, type, 1);
  662. if (trip_type == THERMAL_TRIP_CRITICAL && nocrt)
  663. return 1;
  664. return 0;
  665. }
  666. typedef int (*cb)(struct thermal_zone_device *, int,
  667. struct thermal_cooling_device *);
  668. static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
  669. struct thermal_cooling_device *cdev,
  670. cb action)
  671. {
  672. struct acpi_device *device = cdev->devdata;
  673. struct acpi_thermal *tz = thermal->devdata;
  674. struct acpi_device *dev;
  675. acpi_status status;
  676. acpi_handle handle;
  677. int i;
  678. int j;
  679. int trip = -1;
  680. int result = 0;
  681. if (tz->trips.critical.flags.valid)
  682. trip++;
  683. if (tz->trips.hot.flags.valid)
  684. trip++;
  685. if (tz->trips.passive.flags.valid) {
  686. trip++;
  687. for (i = 0; i < tz->trips.passive.devices.count;
  688. i++) {
  689. handle = tz->trips.passive.devices.handles[i];
  690. status = acpi_bus_get_device(handle, &dev);
  691. if (ACPI_SUCCESS(status) && (dev == device)) {
  692. result = action(thermal, trip, cdev);
  693. if (result)
  694. goto failed;
  695. }
  696. }
  697. }
  698. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  699. if (!tz->trips.active[i].flags.valid)
  700. break;
  701. trip++;
  702. for (j = 0;
  703. j < tz->trips.active[i].devices.count;
  704. j++) {
  705. handle = tz->trips.active[i].devices.handles[j];
  706. status = acpi_bus_get_device(handle, &dev);
  707. if (ACPI_SUCCESS(status) && (dev == device)) {
  708. result = action(thermal, trip, cdev);
  709. if (result)
  710. goto failed;
  711. }
  712. }
  713. }
  714. for (i = 0; i < tz->devices.count; i++) {
  715. handle = tz->devices.handles[i];
  716. status = acpi_bus_get_device(handle, &dev);
  717. if (ACPI_SUCCESS(status) && (dev == device)) {
  718. result = action(thermal, -1, cdev);
  719. if (result)
  720. goto failed;
  721. }
  722. }
  723. failed:
  724. return result;
  725. }
  726. static int
  727. acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
  728. struct thermal_cooling_device *cdev)
  729. {
  730. return acpi_thermal_cooling_device_cb(thermal, cdev,
  731. thermal_zone_bind_cooling_device);
  732. }
  733. static int
  734. acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
  735. struct thermal_cooling_device *cdev)
  736. {
  737. return acpi_thermal_cooling_device_cb(thermal, cdev,
  738. thermal_zone_unbind_cooling_device);
  739. }
  740. static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
  741. .bind = acpi_thermal_bind_cooling_device,
  742. .unbind = acpi_thermal_unbind_cooling_device,
  743. .get_temp = thermal_get_temp,
  744. .get_mode = thermal_get_mode,
  745. .set_mode = thermal_set_mode,
  746. .get_trip_type = thermal_get_trip_type,
  747. .get_trip_temp = thermal_get_trip_temp,
  748. .get_crit_temp = thermal_get_crit_temp,
  749. .notify = thermal_notify,
  750. };
  751. static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
  752. {
  753. int trips = 0;
  754. int result;
  755. acpi_status status;
  756. int i;
  757. if (tz->trips.critical.flags.valid)
  758. trips++;
  759. if (tz->trips.hot.flags.valid)
  760. trips++;
  761. if (tz->trips.passive.flags.valid)
  762. trips++;
  763. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
  764. tz->trips.active[i].flags.valid; i++, trips++);
  765. if (tz->trips.passive.flags.valid)
  766. tz->thermal_zone =
  767. thermal_zone_device_register("acpitz", trips, tz,
  768. &acpi_thermal_zone_ops,
  769. tz->trips.passive.tc1,
  770. tz->trips.passive.tc2,
  771. tz->trips.passive.tsp*100,
  772. tz->polling_frequency*100);
  773. else
  774. tz->thermal_zone =
  775. thermal_zone_device_register("acpitz", trips, tz,
  776. &acpi_thermal_zone_ops,
  777. 0, 0, 0,
  778. tz->polling_frequency);
  779. if (IS_ERR(tz->thermal_zone))
  780. return -ENODEV;
  781. result = sysfs_create_link(&tz->device->dev.kobj,
  782. &tz->thermal_zone->device.kobj, "thermal_zone");
  783. if (result)
  784. return result;
  785. result = sysfs_create_link(&tz->thermal_zone->device.kobj,
  786. &tz->device->dev.kobj, "device");
  787. if (result)
  788. return result;
  789. status = acpi_attach_data(tz->device->handle,
  790. acpi_bus_private_data_handler,
  791. tz->thermal_zone);
  792. if (ACPI_FAILURE(status)) {
  793. printk(KERN_ERR PREFIX
  794. "Error attaching device data\n");
  795. return -ENODEV;
  796. }
  797. tz->tz_enabled = 1;
  798. dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
  799. tz->thermal_zone->id);
  800. return 0;
  801. }
  802. static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
  803. {
  804. sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
  805. sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
  806. thermal_zone_device_unregister(tz->thermal_zone);
  807. tz->thermal_zone = NULL;
  808. acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler);
  809. }
  810. /* --------------------------------------------------------------------------
  811. FS Interface (/proc)
  812. -------------------------------------------------------------------------- */
  813. static struct proc_dir_entry *acpi_thermal_dir;
  814. static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
  815. {
  816. struct acpi_thermal *tz = seq->private;
  817. if (!tz)
  818. goto end;
  819. seq_puts(seq, "state: ");
  820. if (!tz->state.critical && !tz->state.hot && !tz->state.passive
  821. && !tz->state.active)
  822. seq_puts(seq, "ok\n");
  823. else {
  824. if (tz->state.critical)
  825. seq_puts(seq, "critical ");
  826. if (tz->state.hot)
  827. seq_puts(seq, "hot ");
  828. if (tz->state.passive)
  829. seq_puts(seq, "passive ");
  830. if (tz->state.active)
  831. seq_printf(seq, "active[%d]", tz->state.active_index);
  832. seq_puts(seq, "\n");
  833. }
  834. end:
  835. return 0;
  836. }
  837. static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
  838. {
  839. return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
  840. }
  841. static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
  842. {
  843. int result = 0;
  844. struct acpi_thermal *tz = seq->private;
  845. if (!tz)
  846. goto end;
  847. result = acpi_thermal_get_temperature(tz);
  848. if (result)
  849. goto end;
  850. seq_printf(seq, "temperature: %ld C\n",
  851. KELVIN_TO_CELSIUS(tz->temperature));
  852. end:
  853. return 0;
  854. }
  855. static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
  856. {
  857. return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
  858. }
  859. static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
  860. {
  861. struct acpi_thermal *tz = seq->private;
  862. struct acpi_device *device;
  863. acpi_status status;
  864. int i = 0;
  865. int j = 0;
  866. if (!tz)
  867. goto end;
  868. if (tz->trips.critical.flags.valid)
  869. seq_printf(seq, "critical (S5): %ld C%s",
  870. KELVIN_TO_CELSIUS(tz->trips.critical.temperature),
  871. nocrt ? " <disabled>\n" : "\n");
  872. if (tz->trips.hot.flags.valid)
  873. seq_printf(seq, "hot (S4): %ld C%s",
  874. KELVIN_TO_CELSIUS(tz->trips.hot.temperature),
  875. nocrt ? " <disabled>\n" : "\n");
  876. if (tz->trips.passive.flags.valid) {
  877. seq_printf(seq,
  878. "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
  879. KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
  880. tz->trips.passive.tc1, tz->trips.passive.tc2,
  881. tz->trips.passive.tsp);
  882. for (j = 0; j < tz->trips.passive.devices.count; j++) {
  883. status = acpi_bus_get_device(tz->trips.passive.devices.
  884. handles[j], &device);
  885. seq_printf(seq, "%4.4s ", status ? "" :
  886. acpi_device_bid(device));
  887. }
  888. seq_puts(seq, "\n");
  889. }
  890. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  891. if (!(tz->trips.active[i].flags.valid))
  892. break;
  893. seq_printf(seq, "active[%d]: %ld C: devices=",
  894. i,
  895. KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
  896. for (j = 0; j < tz->trips.active[i].devices.count; j++){
  897. status = acpi_bus_get_device(tz->trips.active[i].
  898. devices.handles[j],
  899. &device);
  900. seq_printf(seq, "%4.4s ", status ? "" :
  901. acpi_device_bid(device));
  902. }
  903. seq_puts(seq, "\n");
  904. }
  905. end:
  906. return 0;
  907. }
  908. static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
  909. {
  910. return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
  911. }
  912. static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
  913. {
  914. struct acpi_thermal *tz = seq->private;
  915. if (!tz)
  916. goto end;
  917. if (!tz->flags.cooling_mode)
  918. seq_puts(seq, "<setting not supported>\n");
  919. else
  920. seq_puts(seq, "0 - Active; 1 - Passive\n");
  921. end:
  922. return 0;
  923. }
  924. static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
  925. {
  926. return single_open(file, acpi_thermal_cooling_seq_show,
  927. PDE(inode)->data);
  928. }
  929. static ssize_t
  930. acpi_thermal_write_cooling_mode(struct file *file,
  931. const char __user * buffer,
  932. size_t count, loff_t * ppos)
  933. {
  934. struct seq_file *m = file->private_data;
  935. struct acpi_thermal *tz = m->private;
  936. int result = 0;
  937. char mode_string[12] = { '\0' };
  938. if (!tz || (count > sizeof(mode_string) - 1))
  939. return -EINVAL;
  940. if (!tz->flags.cooling_mode)
  941. return -ENODEV;
  942. if (copy_from_user(mode_string, buffer, count))
  943. return -EFAULT;
  944. mode_string[count] = '\0';
  945. result = acpi_thermal_set_cooling_mode(tz,
  946. simple_strtoul(mode_string, NULL,
  947. 0));
  948. if (result)
  949. return result;
  950. acpi_thermal_check(tz);
  951. return count;
  952. }
  953. static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
  954. {
  955. struct acpi_thermal *tz = seq->private;
  956. if (!tz)
  957. goto end;
  958. if (!tz->thermal_zone->polling_delay) {
  959. seq_puts(seq, "<polling disabled>\n");
  960. goto end;
  961. }
  962. seq_printf(seq, "polling frequency: %d seconds\n",
  963. (tz->thermal_zone->polling_delay / 1000));
  964. end:
  965. return 0;
  966. }
  967. static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
  968. {
  969. return single_open(file, acpi_thermal_polling_seq_show,
  970. PDE(inode)->data);
  971. }
  972. static ssize_t
  973. acpi_thermal_write_polling(struct file *file,
  974. const char __user * buffer,
  975. size_t count, loff_t * ppos)
  976. {
  977. struct seq_file *m = file->private_data;
  978. struct acpi_thermal *tz = m->private;
  979. int result = 0;
  980. char polling_string[12] = { '\0' };
  981. int seconds = 0;
  982. if (!tz || (count > sizeof(polling_string) - 1))
  983. return -EINVAL;
  984. if (copy_from_user(polling_string, buffer, count))
  985. return -EFAULT;
  986. polling_string[count] = '\0';
  987. seconds = simple_strtoul(polling_string, NULL, 0);
  988. result = acpi_thermal_set_polling(tz, seconds);
  989. if (result)
  990. return result;
  991. acpi_thermal_check(tz);
  992. return count;
  993. }
  994. static int acpi_thermal_add_fs(struct acpi_device *device)
  995. {
  996. struct proc_dir_entry *entry = NULL;
  997. if (!acpi_device_dir(device)) {
  998. acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
  999. acpi_thermal_dir);
  1000. if (!acpi_device_dir(device))
  1001. return -ENODEV;
  1002. acpi_device_dir(device)->owner = THIS_MODULE;
  1003. }
  1004. /* 'state' [R] */
  1005. entry = proc_create_data(ACPI_THERMAL_FILE_STATE,
  1006. S_IRUGO, acpi_device_dir(device),
  1007. &acpi_thermal_state_fops,
  1008. acpi_driver_data(device));
  1009. if (!entry)
  1010. return -ENODEV;
  1011. /* 'temperature' [R] */
  1012. entry = proc_create_data(ACPI_THERMAL_FILE_TEMPERATURE,
  1013. S_IRUGO, acpi_device_dir(device),
  1014. &acpi_thermal_temp_fops,
  1015. acpi_driver_data(device));
  1016. if (!entry)
  1017. return -ENODEV;
  1018. /* 'trip_points' [R] */
  1019. entry = proc_create_data(ACPI_THERMAL_FILE_TRIP_POINTS,
  1020. S_IRUGO,
  1021. acpi_device_dir(device),
  1022. &acpi_thermal_trip_fops,
  1023. acpi_driver_data(device));
  1024. if (!entry)
  1025. return -ENODEV;
  1026. /* 'cooling_mode' [R/W] */
  1027. entry = proc_create_data(ACPI_THERMAL_FILE_COOLING_MODE,
  1028. S_IFREG | S_IRUGO | S_IWUSR,
  1029. acpi_device_dir(device),
  1030. &acpi_thermal_cooling_fops,
  1031. acpi_driver_data(device));
  1032. if (!entry)
  1033. return -ENODEV;
  1034. /* 'polling_frequency' [R/W] */
  1035. entry = proc_create_data(ACPI_THERMAL_FILE_POLLING_FREQ,
  1036. S_IFREG | S_IRUGO | S_IWUSR,
  1037. acpi_device_dir(device),
  1038. &acpi_thermal_polling_fops,
  1039. acpi_driver_data(device));
  1040. if (!entry)
  1041. return -ENODEV;
  1042. return 0;
  1043. }
  1044. static int acpi_thermal_remove_fs(struct acpi_device *device)
  1045. {
  1046. if (acpi_device_dir(device)) {
  1047. remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
  1048. acpi_device_dir(device));
  1049. remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
  1050. acpi_device_dir(device));
  1051. remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
  1052. acpi_device_dir(device));
  1053. remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
  1054. acpi_device_dir(device));
  1055. remove_proc_entry(ACPI_THERMAL_FILE_STATE,
  1056. acpi_device_dir(device));
  1057. remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
  1058. acpi_device_dir(device) = NULL;
  1059. }
  1060. return 0;
  1061. }
  1062. /* --------------------------------------------------------------------------
  1063. Driver Interface
  1064. -------------------------------------------------------------------------- */
  1065. static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
  1066. {
  1067. struct acpi_thermal *tz = data;
  1068. struct acpi_device *device = NULL;
  1069. if (!tz)
  1070. return;
  1071. device = tz->device;
  1072. switch (event) {
  1073. case ACPI_THERMAL_NOTIFY_TEMPERATURE:
  1074. acpi_thermal_check(tz);
  1075. break;
  1076. case ACPI_THERMAL_NOTIFY_THRESHOLDS:
  1077. acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS);
  1078. acpi_thermal_check(tz);
  1079. acpi_bus_generate_proc_event(device, event, 0);
  1080. acpi_bus_generate_netlink_event(device->pnp.device_class,
  1081. dev_name(&device->dev), event, 0);
  1082. break;
  1083. case ACPI_THERMAL_NOTIFY_DEVICES:
  1084. acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES);
  1085. acpi_thermal_check(tz);
  1086. acpi_bus_generate_proc_event(device, event, 0);
  1087. acpi_bus_generate_netlink_event(device->pnp.device_class,
  1088. dev_name(&device->dev), event, 0);
  1089. break;
  1090. default:
  1091. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  1092. "Unsupported event [0x%x]\n", event));
  1093. break;
  1094. }
  1095. return;
  1096. }
  1097. static int acpi_thermal_get_info(struct acpi_thermal *tz)
  1098. {
  1099. int result = 0;
  1100. if (!tz)
  1101. return -EINVAL;
  1102. /* Get temperature [_TMP] (required) */
  1103. result = acpi_thermal_get_temperature(tz);
  1104. if (result)
  1105. return result;
  1106. /* Get trip points [_CRT, _PSV, etc.] (required) */
  1107. result = acpi_thermal_get_trip_points(tz);
  1108. if (result)
  1109. return result;
  1110. /* Set the cooling mode [_SCP] to active cooling (default) */
  1111. result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
  1112. if (!result)
  1113. tz->flags.cooling_mode = 1;
  1114. /* Get default polling frequency [_TZP] (optional) */
  1115. if (tzp)
  1116. tz->polling_frequency = tzp;
  1117. else
  1118. acpi_thermal_get_polling_frequency(tz);
  1119. return 0;
  1120. }
  1121. static int acpi_thermal_add(struct acpi_device *device)
  1122. {
  1123. int result = 0;
  1124. acpi_status status = AE_OK;
  1125. struct acpi_thermal *tz = NULL;
  1126. if (!device)
  1127. return -EINVAL;
  1128. tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
  1129. if (!tz)
  1130. return -ENOMEM;
  1131. tz->device = device;
  1132. strcpy(tz->name, device->pnp.bus_id);
  1133. strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
  1134. strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
  1135. device->driver_data = tz;
  1136. mutex_init(&tz->lock);
  1137. result = acpi_thermal_get_info(tz);
  1138. if (result)
  1139. goto free_memory;
  1140. result = acpi_thermal_register_thermal_zone(tz);
  1141. if (result)
  1142. goto free_memory;
  1143. result = acpi_thermal_add_fs(device);
  1144. if (result)
  1145. goto unregister_thermal_zone;
  1146. status = acpi_install_notify_handler(device->handle,
  1147. ACPI_DEVICE_NOTIFY,
  1148. acpi_thermal_notify, tz);
  1149. if (ACPI_FAILURE(status)) {
  1150. result = -ENODEV;
  1151. goto remove_fs;
  1152. }
  1153. printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
  1154. acpi_device_name(device), acpi_device_bid(device),
  1155. KELVIN_TO_CELSIUS(tz->temperature));
  1156. goto end;
  1157. remove_fs:
  1158. acpi_thermal_remove_fs(device);
  1159. unregister_thermal_zone:
  1160. thermal_zone_device_unregister(tz->thermal_zone);
  1161. free_memory:
  1162. kfree(tz);
  1163. end:
  1164. return result;
  1165. }
  1166. static int acpi_thermal_remove(struct acpi_device *device, int type)
  1167. {
  1168. acpi_status status = AE_OK;
  1169. struct acpi_thermal *tz = NULL;
  1170. if (!device || !acpi_driver_data(device))
  1171. return -EINVAL;
  1172. tz = acpi_driver_data(device);
  1173. status = acpi_remove_notify_handler(device->handle,
  1174. ACPI_DEVICE_NOTIFY,
  1175. acpi_thermal_notify);
  1176. acpi_thermal_remove_fs(device);
  1177. acpi_thermal_unregister_thermal_zone(tz);
  1178. mutex_destroy(&tz->lock);
  1179. kfree(tz);
  1180. return 0;
  1181. }
  1182. static int acpi_thermal_resume(struct acpi_device *device)
  1183. {
  1184. struct acpi_thermal *tz = NULL;
  1185. int i, j, power_state, result;
  1186. if (!device || !acpi_driver_data(device))
  1187. return -EINVAL;
  1188. tz = acpi_driver_data(device);
  1189. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  1190. if (!(&tz->trips.active[i]))
  1191. break;
  1192. if (!tz->trips.active[i].flags.valid)
  1193. break;
  1194. tz->trips.active[i].flags.enabled = 1;
  1195. for (j = 0; j < tz->trips.active[i].devices.count; j++) {
  1196. result = acpi_bus_get_power(tz->trips.active[i].devices.
  1197. handles[j], &power_state);
  1198. if (result || (power_state != ACPI_STATE_D0)) {
  1199. tz->trips.active[i].flags.enabled = 0;
  1200. break;
  1201. }
  1202. }
  1203. tz->state.active |= tz->trips.active[i].flags.enabled;
  1204. }
  1205. acpi_thermal_check(tz);
  1206. return AE_OK;
  1207. }
  1208. static int thermal_act(const struct dmi_system_id *d) {
  1209. if (act == 0) {
  1210. printk(KERN_NOTICE "ACPI: %s detected: "
  1211. "disabling all active thermal trip points\n", d->ident);
  1212. act = -1;
  1213. }
  1214. return 0;
  1215. }
  1216. static int thermal_nocrt(const struct dmi_system_id *d) {
  1217. printk(KERN_NOTICE "ACPI: %s detected: "
  1218. "disabling all critical thermal trip point actions.\n", d->ident);
  1219. nocrt = 1;
  1220. return 0;
  1221. }
  1222. static int thermal_tzp(const struct dmi_system_id *d) {
  1223. if (tzp == 0) {
  1224. printk(KERN_NOTICE "ACPI: %s detected: "
  1225. "enabling thermal zone polling\n", d->ident);
  1226. tzp = 300; /* 300 dS = 30 Seconds */
  1227. }
  1228. return 0;
  1229. }
  1230. static int thermal_psv(const struct dmi_system_id *d) {
  1231. if (psv == 0) {
  1232. printk(KERN_NOTICE "ACPI: %s detected: "
  1233. "disabling all passive thermal trip points\n", d->ident);
  1234. psv = -1;
  1235. }
  1236. return 0;
  1237. }
  1238. static struct dmi_system_id thermal_dmi_table[] __initdata = {
  1239. /*
  1240. * Award BIOS on this AOpen makes thermal control almost worthless.
  1241. * http://bugzilla.kernel.org/show_bug.cgi?id=8842
  1242. */
  1243. {
  1244. .callback = thermal_act,
  1245. .ident = "AOpen i915GMm-HFS",
  1246. .matches = {
  1247. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  1248. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  1249. },
  1250. },
  1251. {
  1252. .callback = thermal_psv,
  1253. .ident = "AOpen i915GMm-HFS",
  1254. .matches = {
  1255. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  1256. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  1257. },
  1258. },
  1259. {
  1260. .callback = thermal_tzp,
  1261. .ident = "AOpen i915GMm-HFS",
  1262. .matches = {
  1263. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  1264. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  1265. },
  1266. },
  1267. {
  1268. .callback = thermal_nocrt,
  1269. .ident = "Gigabyte GA-7ZX",
  1270. .matches = {
  1271. DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
  1272. DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
  1273. },
  1274. },
  1275. {}
  1276. };
  1277. static int __init acpi_thermal_init(void)
  1278. {
  1279. int result = 0;
  1280. dmi_check_system(thermal_dmi_table);
  1281. if (off) {
  1282. printk(KERN_NOTICE "ACPI: thermal control disabled\n");
  1283. return -ENODEV;
  1284. }
  1285. acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
  1286. if (!acpi_thermal_dir)
  1287. return -ENODEV;
  1288. acpi_thermal_dir->owner = THIS_MODULE;
  1289. result = acpi_bus_register_driver(&acpi_thermal_driver);
  1290. if (result < 0) {
  1291. remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
  1292. return -ENODEV;
  1293. }
  1294. return 0;
  1295. }
  1296. static void __exit acpi_thermal_exit(void)
  1297. {
  1298. acpi_bus_unregister_driver(&acpi_thermal_driver);
  1299. remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
  1300. return;
  1301. }
  1302. module_init(acpi_thermal_init);
  1303. module_exit(acpi_thermal_exit);