thermal.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557
  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 <linux/device.h>
  44. #include <asm/uaccess.h>
  45. #include <linux/thermal.h>
  46. #include <acpi/acpi_bus.h>
  47. #include <acpi/acpi_drivers.h>
  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 _COMPONENT ACPI_THERMAL_COMPONENT
  64. ACPI_MODULE_NAME("thermal");
  65. MODULE_AUTHOR("Paul Diefenbaugh");
  66. MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
  67. MODULE_LICENSE("GPL");
  68. static int act;
  69. module_param(act, int, 0644);
  70. MODULE_PARM_DESC(act, "Disable or override all lowest active trip points.");
  71. static int crt;
  72. module_param(crt, int, 0644);
  73. MODULE_PARM_DESC(crt, "Disable or lower all critical trip points.");
  74. static int tzp;
  75. module_param(tzp, int, 0444);
  76. MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.");
  77. static int nocrt;
  78. module_param(nocrt, int, 0);
  79. MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points.");
  80. static int off;
  81. module_param(off, int, 0);
  82. MODULE_PARM_DESC(off, "Set to disable ACPI thermal support.");
  83. static int psv;
  84. module_param(psv, int, 0644);
  85. MODULE_PARM_DESC(psv, "Disable or override all passive trip points.");
  86. static int acpi_thermal_add(struct acpi_device *device);
  87. static int acpi_thermal_remove(struct acpi_device *device, int type);
  88. static int acpi_thermal_resume(struct acpi_device *device);
  89. static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
  90. static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
  91. static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
  92. static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
  93. static ssize_t acpi_thermal_write_cooling_mode(struct file *,
  94. const char __user *, size_t,
  95. loff_t *);
  96. static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
  97. static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
  98. size_t, loff_t *);
  99. static const struct acpi_device_id thermal_device_ids[] = {
  100. {ACPI_THERMAL_HID, 0},
  101. {"", 0},
  102. };
  103. MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
  104. static struct acpi_driver acpi_thermal_driver = {
  105. .name = "thermal",
  106. .class = ACPI_THERMAL_CLASS,
  107. .ids = thermal_device_ids,
  108. .ops = {
  109. .add = acpi_thermal_add,
  110. .remove = acpi_thermal_remove,
  111. .resume = acpi_thermal_resume,
  112. },
  113. };
  114. struct acpi_thermal_state {
  115. u8 critical:1;
  116. u8 hot:1;
  117. u8 passive:1;
  118. u8 active:1;
  119. u8 reserved:4;
  120. int active_index;
  121. };
  122. struct acpi_thermal_state_flags {
  123. u8 valid:1;
  124. u8 enabled:1;
  125. u8 reserved:6;
  126. };
  127. struct acpi_thermal_critical {
  128. struct acpi_thermal_state_flags flags;
  129. unsigned long temperature;
  130. };
  131. struct acpi_thermal_hot {
  132. struct acpi_thermal_state_flags flags;
  133. unsigned long temperature;
  134. };
  135. struct acpi_thermal_passive {
  136. struct acpi_thermal_state_flags flags;
  137. unsigned long temperature;
  138. unsigned long tc1;
  139. unsigned long tc2;
  140. unsigned long tsp;
  141. struct acpi_handle_list devices;
  142. };
  143. struct acpi_thermal_active {
  144. struct acpi_thermal_state_flags flags;
  145. unsigned long temperature;
  146. struct acpi_handle_list devices;
  147. };
  148. struct acpi_thermal_trips {
  149. struct acpi_thermal_critical critical;
  150. struct acpi_thermal_hot hot;
  151. struct acpi_thermal_passive passive;
  152. struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
  153. };
  154. struct acpi_thermal_flags {
  155. u8 cooling_mode:1; /* _SCP */
  156. u8 devices:1; /* _TZD */
  157. u8 reserved:6;
  158. };
  159. struct acpi_thermal {
  160. struct acpi_device * device;
  161. acpi_bus_id name;
  162. unsigned long temperature;
  163. unsigned long last_temperature;
  164. unsigned long polling_frequency;
  165. volatile u8 zombie;
  166. struct acpi_thermal_flags flags;
  167. struct acpi_thermal_state state;
  168. struct acpi_thermal_trips trips;
  169. struct acpi_handle_list devices;
  170. struct thermal_zone_device *thermal_zone;
  171. int tz_enabled;
  172. struct mutex lock;
  173. };
  174. static const struct file_operations acpi_thermal_state_fops = {
  175. .owner = THIS_MODULE,
  176. .open = acpi_thermal_state_open_fs,
  177. .read = seq_read,
  178. .llseek = seq_lseek,
  179. .release = single_release,
  180. };
  181. static const struct file_operations acpi_thermal_temp_fops = {
  182. .owner = THIS_MODULE,
  183. .open = acpi_thermal_temp_open_fs,
  184. .read = seq_read,
  185. .llseek = seq_lseek,
  186. .release = single_release,
  187. };
  188. static const struct file_operations acpi_thermal_trip_fops = {
  189. .owner = THIS_MODULE,
  190. .open = acpi_thermal_trip_open_fs,
  191. .read = seq_read,
  192. .llseek = seq_lseek,
  193. .release = single_release,
  194. };
  195. static const struct file_operations acpi_thermal_cooling_fops = {
  196. .owner = THIS_MODULE,
  197. .open = acpi_thermal_cooling_open_fs,
  198. .read = seq_read,
  199. .write = acpi_thermal_write_cooling_mode,
  200. .llseek = seq_lseek,
  201. .release = single_release,
  202. };
  203. static const struct file_operations acpi_thermal_polling_fops = {
  204. .owner = THIS_MODULE,
  205. .open = acpi_thermal_polling_open_fs,
  206. .read = seq_read,
  207. .write = acpi_thermal_write_polling,
  208. .llseek = seq_lseek,
  209. .release = single_release,
  210. };
  211. /* --------------------------------------------------------------------------
  212. Thermal Zone Management
  213. -------------------------------------------------------------------------- */
  214. static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
  215. {
  216. acpi_status status = AE_OK;
  217. unsigned long long tmp;
  218. if (!tz)
  219. return -EINVAL;
  220. tz->last_temperature = tz->temperature;
  221. status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp);
  222. if (ACPI_FAILURE(status))
  223. return -ENODEV;
  224. tz->temperature = tmp;
  225. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
  226. tz->temperature));
  227. return 0;
  228. }
  229. static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
  230. {
  231. acpi_status status = AE_OK;
  232. unsigned long long tmp;
  233. if (!tz)
  234. return -EINVAL;
  235. status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp);
  236. if (ACPI_FAILURE(status))
  237. return -ENODEV;
  238. tz->polling_frequency = tmp;
  239. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
  240. tz->polling_frequency));
  241. return 0;
  242. }
  243. static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
  244. {
  245. if (!tz)
  246. return -EINVAL;
  247. tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
  248. tz->thermal_zone->polling_delay = seconds * 1000;
  249. if (tz->tz_enabled)
  250. thermal_zone_device_update(tz->thermal_zone);
  251. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  252. "Polling frequency set to %lu seconds\n",
  253. tz->polling_frequency/10));
  254. return 0;
  255. }
  256. static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
  257. {
  258. acpi_status status = AE_OK;
  259. union acpi_object arg0 = { ACPI_TYPE_INTEGER };
  260. struct acpi_object_list arg_list = { 1, &arg0 };
  261. acpi_handle handle = NULL;
  262. if (!tz)
  263. return -EINVAL;
  264. status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
  265. if (ACPI_FAILURE(status)) {
  266. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
  267. return -ENODEV;
  268. }
  269. arg0.integer.value = mode;
  270. status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
  271. if (ACPI_FAILURE(status))
  272. return -ENODEV;
  273. return 0;
  274. }
  275. #define ACPI_TRIPS_CRITICAL 0x01
  276. #define ACPI_TRIPS_HOT 0x02
  277. #define ACPI_TRIPS_PASSIVE 0x04
  278. #define ACPI_TRIPS_ACTIVE 0x08
  279. #define ACPI_TRIPS_DEVICES 0x10
  280. #define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE)
  281. #define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES
  282. #define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \
  283. ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \
  284. ACPI_TRIPS_DEVICES)
  285. /*
  286. * This exception is thrown out in two cases:
  287. * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
  288. * when re-evaluating the AML code.
  289. * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change.
  290. * We need to re-bind the cooling devices of a thermal zone when this occurs.
  291. */
  292. #define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \
  293. do { \
  294. if (flags != ACPI_TRIPS_INIT) \
  295. ACPI_EXCEPTION((AE_INFO, AE_ERROR, \
  296. "ACPI thermal trip point %s changed\n" \
  297. "Please send acpidump to linux-acpi@vger.kernel.org\n", str)); \
  298. } while (0)
  299. static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
  300. {
  301. acpi_status status = AE_OK;
  302. unsigned long long tmp;
  303. struct acpi_handle_list devices;
  304. int valid = 0;
  305. int i;
  306. /* Critical Shutdown (required) */
  307. if (flag & ACPI_TRIPS_CRITICAL) {
  308. status = acpi_evaluate_integer(tz->device->handle,
  309. "_CRT", NULL, &tmp);
  310. tz->trips.critical.temperature = tmp;
  311. /*
  312. * Treat freezing temperatures as invalid as well; some
  313. * BIOSes return really low values and cause reboots at startup.
  314. * Below zero (Celsius) values clearly aren't right for sure..
  315. * ... so lets discard those as invalid.
  316. */
  317. if (ACPI_FAILURE(status) ||
  318. tz->trips.critical.temperature <= 2732) {
  319. tz->trips.critical.flags.valid = 0;
  320. ACPI_EXCEPTION((AE_INFO, status,
  321. "No or invalid critical threshold"));
  322. return -ENODEV;
  323. } else {
  324. tz->trips.critical.flags.valid = 1;
  325. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  326. "Found critical threshold [%lu]\n",
  327. tz->trips.critical.temperature));
  328. }
  329. if (tz->trips.critical.flags.valid == 1) {
  330. if (crt == -1) {
  331. tz->trips.critical.flags.valid = 0;
  332. } else if (crt > 0) {
  333. unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
  334. /*
  335. * Allow override critical threshold
  336. */
  337. if (crt_k > tz->trips.critical.temperature)
  338. printk(KERN_WARNING PREFIX
  339. "Critical threshold %d C\n", crt);
  340. tz->trips.critical.temperature = crt_k;
  341. }
  342. }
  343. }
  344. /* Critical Sleep (optional) */
  345. if (flag & ACPI_TRIPS_HOT) {
  346. status = acpi_evaluate_integer(tz->device->handle,
  347. "_HOT", NULL, &tmp);
  348. if (ACPI_FAILURE(status)) {
  349. tz->trips.hot.flags.valid = 0;
  350. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  351. "No hot threshold\n"));
  352. } else {
  353. tz->trips.hot.temperature = tmp;
  354. tz->trips.hot.flags.valid = 1;
  355. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  356. "Found hot threshold [%lu]\n",
  357. tz->trips.critical.temperature));
  358. }
  359. }
  360. /* Passive (optional) */
  361. if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) ||
  362. (flag == ACPI_TRIPS_INIT)) {
  363. valid = tz->trips.passive.flags.valid;
  364. if (psv == -1) {
  365. status = AE_SUPPORT;
  366. } else if (psv > 0) {
  367. tmp = CELSIUS_TO_KELVIN(psv);
  368. status = AE_OK;
  369. } else {
  370. status = acpi_evaluate_integer(tz->device->handle,
  371. "_PSV", NULL, &tmp);
  372. }
  373. if (ACPI_FAILURE(status))
  374. tz->trips.passive.flags.valid = 0;
  375. else {
  376. tz->trips.passive.temperature = tmp;
  377. tz->trips.passive.flags.valid = 1;
  378. if (flag == ACPI_TRIPS_INIT) {
  379. status = acpi_evaluate_integer(
  380. tz->device->handle, "_TC1",
  381. NULL, &tmp);
  382. if (ACPI_FAILURE(status))
  383. tz->trips.passive.flags.valid = 0;
  384. else
  385. tz->trips.passive.tc1 = tmp;
  386. status = acpi_evaluate_integer(
  387. tz->device->handle, "_TC2",
  388. NULL, &tmp);
  389. if (ACPI_FAILURE(status))
  390. tz->trips.passive.flags.valid = 0;
  391. else
  392. tz->trips.passive.tc2 = tmp;
  393. status = acpi_evaluate_integer(
  394. tz->device->handle, "_TSP",
  395. NULL, &tmp);
  396. if (ACPI_FAILURE(status))
  397. tz->trips.passive.flags.valid = 0;
  398. else
  399. tz->trips.passive.tsp = tmp;
  400. }
  401. }
  402. }
  403. if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) {
  404. memset(&devices, 0, sizeof(struct acpi_handle_list));
  405. status = acpi_evaluate_reference(tz->device->handle, "_PSL",
  406. NULL, &devices);
  407. if (ACPI_FAILURE(status)) {
  408. printk(KERN_WARNING PREFIX
  409. "Invalid passive threshold\n");
  410. tz->trips.passive.flags.valid = 0;
  411. }
  412. else
  413. tz->trips.passive.flags.valid = 1;
  414. if (memcmp(&tz->trips.passive.devices, &devices,
  415. sizeof(struct acpi_handle_list))) {
  416. memcpy(&tz->trips.passive.devices, &devices,
  417. sizeof(struct acpi_handle_list));
  418. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
  419. }
  420. }
  421. if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) {
  422. if (valid != tz->trips.passive.flags.valid)
  423. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
  424. }
  425. /* Active (optional) */
  426. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  427. char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
  428. valid = tz->trips.active[i].flags.valid;
  429. if (act == -1)
  430. break; /* disable all active trip points */
  431. if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) &&
  432. tz->trips.active[i].flags.valid)) {
  433. status = acpi_evaluate_integer(tz->device->handle,
  434. name, NULL, &tmp);
  435. if (ACPI_FAILURE(status)) {
  436. tz->trips.active[i].flags.valid = 0;
  437. if (i == 0)
  438. break;
  439. if (act <= 0)
  440. break;
  441. if (i == 1)
  442. tz->trips.active[0].temperature =
  443. CELSIUS_TO_KELVIN(act);
  444. else
  445. /*
  446. * Don't allow override higher than
  447. * the next higher trip point
  448. */
  449. tz->trips.active[i - 1].temperature =
  450. (tz->trips.active[i - 2].temperature <
  451. CELSIUS_TO_KELVIN(act) ?
  452. tz->trips.active[i - 2].temperature :
  453. CELSIUS_TO_KELVIN(act));
  454. break;
  455. } else {
  456. tz->trips.active[i].temperature = tmp;
  457. tz->trips.active[i].flags.valid = 1;
  458. }
  459. }
  460. name[2] = 'L';
  461. if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) {
  462. memset(&devices, 0, sizeof(struct acpi_handle_list));
  463. status = acpi_evaluate_reference(tz->device->handle,
  464. name, NULL, &devices);
  465. if (ACPI_FAILURE(status)) {
  466. printk(KERN_WARNING PREFIX
  467. "Invalid active%d threshold\n", i);
  468. tz->trips.active[i].flags.valid = 0;
  469. }
  470. else
  471. tz->trips.active[i].flags.valid = 1;
  472. if (memcmp(&tz->trips.active[i].devices, &devices,
  473. sizeof(struct acpi_handle_list))) {
  474. memcpy(&tz->trips.active[i].devices, &devices,
  475. sizeof(struct acpi_handle_list));
  476. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
  477. }
  478. }
  479. if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES))
  480. if (valid != tz->trips.active[i].flags.valid)
  481. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
  482. if (!tz->trips.active[i].flags.valid)
  483. break;
  484. }
  485. if (flag & ACPI_TRIPS_DEVICES) {
  486. memset(&devices, 0, sizeof(struct acpi_handle_list));
  487. status = acpi_evaluate_reference(tz->device->handle, "_TZD",
  488. NULL, &devices);
  489. if (memcmp(&tz->devices, &devices,
  490. sizeof(struct acpi_handle_list))) {
  491. memcpy(&tz->devices, &devices,
  492. sizeof(struct acpi_handle_list));
  493. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
  494. }
  495. }
  496. return 0;
  497. }
  498. static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
  499. {
  500. return acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
  501. }
  502. static void acpi_thermal_check(void *data)
  503. {
  504. struct acpi_thermal *tz = data;
  505. thermal_zone_device_update(tz->thermal_zone);
  506. }
  507. /* sys I/F for generic thermal sysfs support */
  508. #define KELVIN_TO_MILLICELSIUS(t) (t * 100 - 273200)
  509. static int thermal_get_temp(struct thermal_zone_device *thermal,
  510. unsigned long *temp)
  511. {
  512. struct acpi_thermal *tz = thermal->devdata;
  513. int result;
  514. if (!tz)
  515. return -EINVAL;
  516. result = acpi_thermal_get_temperature(tz);
  517. if (result)
  518. return result;
  519. *temp = KELVIN_TO_MILLICELSIUS(tz->temperature);
  520. return 0;
  521. }
  522. static const char enabled[] = "kernel";
  523. static const char disabled[] = "user";
  524. static int thermal_get_mode(struct thermal_zone_device *thermal,
  525. enum thermal_device_mode *mode)
  526. {
  527. struct acpi_thermal *tz = thermal->devdata;
  528. if (!tz)
  529. return -EINVAL;
  530. *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
  531. THERMAL_DEVICE_DISABLED;
  532. return 0;
  533. }
  534. static int thermal_set_mode(struct thermal_zone_device *thermal,
  535. enum thermal_device_mode mode)
  536. {
  537. struct acpi_thermal *tz = thermal->devdata;
  538. int enable;
  539. if (!tz)
  540. return -EINVAL;
  541. /*
  542. * enable/disable thermal management from ACPI thermal driver
  543. */
  544. if (mode == THERMAL_DEVICE_ENABLED)
  545. enable = 1;
  546. else if (mode == THERMAL_DEVICE_DISABLED)
  547. enable = 0;
  548. else
  549. return -EINVAL;
  550. if (enable != tz->tz_enabled) {
  551. tz->tz_enabled = enable;
  552. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  553. "%s ACPI thermal control\n",
  554. tz->tz_enabled ? enabled : disabled));
  555. acpi_thermal_check(tz);
  556. }
  557. return 0;
  558. }
  559. static int thermal_get_trip_type(struct thermal_zone_device *thermal,
  560. int trip, enum thermal_trip_type *type)
  561. {
  562. struct acpi_thermal *tz = thermal->devdata;
  563. int i;
  564. if (!tz || trip < 0)
  565. return -EINVAL;
  566. if (tz->trips.critical.flags.valid) {
  567. if (!trip) {
  568. *type = THERMAL_TRIP_CRITICAL;
  569. return 0;
  570. }
  571. trip--;
  572. }
  573. if (tz->trips.hot.flags.valid) {
  574. if (!trip) {
  575. *type = THERMAL_TRIP_HOT;
  576. return 0;
  577. }
  578. trip--;
  579. }
  580. if (tz->trips.passive.flags.valid) {
  581. if (!trip) {
  582. *type = THERMAL_TRIP_PASSIVE;
  583. return 0;
  584. }
  585. trip--;
  586. }
  587. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
  588. tz->trips.active[i].flags.valid; i++) {
  589. if (!trip) {
  590. *type = THERMAL_TRIP_ACTIVE;
  591. return 0;
  592. }
  593. trip--;
  594. }
  595. return -EINVAL;
  596. }
  597. static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
  598. int trip, unsigned long *temp)
  599. {
  600. struct acpi_thermal *tz = thermal->devdata;
  601. int i;
  602. if (!tz || trip < 0)
  603. return -EINVAL;
  604. if (tz->trips.critical.flags.valid) {
  605. if (!trip) {
  606. *temp = KELVIN_TO_MILLICELSIUS(
  607. tz->trips.critical.temperature);
  608. return 0;
  609. }
  610. trip--;
  611. }
  612. if (tz->trips.hot.flags.valid) {
  613. if (!trip) {
  614. *temp = KELVIN_TO_MILLICELSIUS(
  615. tz->trips.hot.temperature);
  616. return 0;
  617. }
  618. trip--;
  619. }
  620. if (tz->trips.passive.flags.valid) {
  621. if (!trip) {
  622. *temp = KELVIN_TO_MILLICELSIUS(
  623. tz->trips.passive.temperature);
  624. return 0;
  625. }
  626. trip--;
  627. }
  628. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
  629. tz->trips.active[i].flags.valid; i++) {
  630. if (!trip) {
  631. *temp = KELVIN_TO_MILLICELSIUS(
  632. tz->trips.active[i].temperature);
  633. return 0;
  634. }
  635. trip--;
  636. }
  637. return -EINVAL;
  638. }
  639. static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
  640. unsigned long *temperature) {
  641. struct acpi_thermal *tz = thermal->devdata;
  642. if (tz->trips.critical.flags.valid) {
  643. *temperature = KELVIN_TO_MILLICELSIUS(
  644. tz->trips.critical.temperature);
  645. return 0;
  646. } else
  647. return -EINVAL;
  648. }
  649. static int thermal_notify(struct thermal_zone_device *thermal, int trip,
  650. enum thermal_trip_type trip_type)
  651. {
  652. u8 type = 0;
  653. struct acpi_thermal *tz = thermal->devdata;
  654. if (trip_type == THERMAL_TRIP_CRITICAL)
  655. type = ACPI_THERMAL_NOTIFY_CRITICAL;
  656. else if (trip_type == THERMAL_TRIP_HOT)
  657. type = ACPI_THERMAL_NOTIFY_HOT;
  658. else
  659. return 0;
  660. acpi_bus_generate_proc_event(tz->device, type, 1);
  661. acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
  662. dev_name(&tz->device->dev), type, 1);
  663. if (trip_type == THERMAL_TRIP_CRITICAL && nocrt)
  664. return 1;
  665. return 0;
  666. }
  667. typedef int (*cb)(struct thermal_zone_device *, int,
  668. struct thermal_cooling_device *);
  669. static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
  670. struct thermal_cooling_device *cdev,
  671. cb action)
  672. {
  673. struct acpi_device *device = cdev->devdata;
  674. struct acpi_thermal *tz = thermal->devdata;
  675. struct acpi_device *dev;
  676. acpi_status status;
  677. acpi_handle handle;
  678. int i;
  679. int j;
  680. int trip = -1;
  681. int result = 0;
  682. if (tz->trips.critical.flags.valid)
  683. trip++;
  684. if (tz->trips.hot.flags.valid)
  685. trip++;
  686. if (tz->trips.passive.flags.valid) {
  687. trip++;
  688. for (i = 0; i < tz->trips.passive.devices.count;
  689. i++) {
  690. handle = tz->trips.passive.devices.handles[i];
  691. status = acpi_bus_get_device(handle, &dev);
  692. if (ACPI_SUCCESS(status) && (dev == device)) {
  693. result = action(thermal, trip, cdev);
  694. if (result)
  695. goto failed;
  696. }
  697. }
  698. }
  699. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  700. if (!tz->trips.active[i].flags.valid)
  701. break;
  702. trip++;
  703. for (j = 0;
  704. j < tz->trips.active[i].devices.count;
  705. j++) {
  706. handle = tz->trips.active[i].devices.handles[j];
  707. status = acpi_bus_get_device(handle, &dev);
  708. if (ACPI_SUCCESS(status) && (dev == device)) {
  709. result = action(thermal, trip, cdev);
  710. if (result)
  711. goto failed;
  712. }
  713. }
  714. }
  715. for (i = 0; i < tz->devices.count; i++) {
  716. handle = tz->devices.handles[i];
  717. status = acpi_bus_get_device(handle, &dev);
  718. if (ACPI_SUCCESS(status) && (dev == device)) {
  719. result = action(thermal, -1, cdev);
  720. if (result)
  721. goto failed;
  722. }
  723. }
  724. failed:
  725. return result;
  726. }
  727. static int
  728. acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
  729. struct thermal_cooling_device *cdev)
  730. {
  731. return acpi_thermal_cooling_device_cb(thermal, cdev,
  732. thermal_zone_bind_cooling_device);
  733. }
  734. static int
  735. acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
  736. struct thermal_cooling_device *cdev)
  737. {
  738. return acpi_thermal_cooling_device_cb(thermal, cdev,
  739. thermal_zone_unbind_cooling_device);
  740. }
  741. static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
  742. .bind = acpi_thermal_bind_cooling_device,
  743. .unbind = acpi_thermal_unbind_cooling_device,
  744. .get_temp = thermal_get_temp,
  745. .get_mode = thermal_get_mode,
  746. .set_mode = thermal_set_mode,
  747. .get_trip_type = thermal_get_trip_type,
  748. .get_trip_temp = thermal_get_trip_temp,
  749. .get_crit_temp = thermal_get_crit_temp,
  750. .notify = thermal_notify,
  751. };
  752. static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
  753. {
  754. int trips = 0;
  755. int result;
  756. acpi_status status;
  757. int i;
  758. if (tz->trips.critical.flags.valid)
  759. trips++;
  760. if (tz->trips.hot.flags.valid)
  761. trips++;
  762. if (tz->trips.passive.flags.valid)
  763. trips++;
  764. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
  765. tz->trips.active[i].flags.valid; i++, trips++);
  766. if (tz->trips.passive.flags.valid)
  767. tz->thermal_zone =
  768. thermal_zone_device_register("acpitz", trips, tz,
  769. &acpi_thermal_zone_ops,
  770. tz->trips.passive.tc1,
  771. tz->trips.passive.tc2,
  772. tz->trips.passive.tsp*100,
  773. tz->polling_frequency*100);
  774. else
  775. tz->thermal_zone =
  776. thermal_zone_device_register("acpitz", trips, tz,
  777. &acpi_thermal_zone_ops,
  778. 0, 0, 0,
  779. tz->polling_frequency);
  780. if (IS_ERR(tz->thermal_zone))
  781. return -ENODEV;
  782. result = sysfs_create_link(&tz->device->dev.kobj,
  783. &tz->thermal_zone->device.kobj, "thermal_zone");
  784. if (result)
  785. return result;
  786. result = sysfs_create_link(&tz->thermal_zone->device.kobj,
  787. &tz->device->dev.kobj, "device");
  788. if (result)
  789. return result;
  790. status = acpi_attach_data(tz->device->handle,
  791. acpi_bus_private_data_handler,
  792. tz->thermal_zone);
  793. if (ACPI_FAILURE(status)) {
  794. printk(KERN_ERR PREFIX
  795. "Error attaching device data\n");
  796. return -ENODEV;
  797. }
  798. tz->tz_enabled = 1;
  799. dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
  800. tz->thermal_zone->id);
  801. return 0;
  802. }
  803. static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
  804. {
  805. sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
  806. sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
  807. thermal_zone_device_unregister(tz->thermal_zone);
  808. tz->thermal_zone = NULL;
  809. acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler);
  810. }
  811. /* --------------------------------------------------------------------------
  812. FS Interface (/proc)
  813. -------------------------------------------------------------------------- */
  814. static struct proc_dir_entry *acpi_thermal_dir;
  815. static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
  816. {
  817. struct acpi_thermal *tz = seq->private;
  818. if (!tz)
  819. goto end;
  820. seq_puts(seq, "state: ");
  821. if (!tz->state.critical && !tz->state.hot && !tz->state.passive
  822. && !tz->state.active)
  823. seq_puts(seq, "ok\n");
  824. else {
  825. if (tz->state.critical)
  826. seq_puts(seq, "critical ");
  827. if (tz->state.hot)
  828. seq_puts(seq, "hot ");
  829. if (tz->state.passive)
  830. seq_puts(seq, "passive ");
  831. if (tz->state.active)
  832. seq_printf(seq, "active[%d]", tz->state.active_index);
  833. seq_puts(seq, "\n");
  834. }
  835. end:
  836. return 0;
  837. }
  838. static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
  839. {
  840. return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
  841. }
  842. static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
  843. {
  844. int result = 0;
  845. struct acpi_thermal *tz = seq->private;
  846. if (!tz)
  847. goto end;
  848. result = acpi_thermal_get_temperature(tz);
  849. if (result)
  850. goto end;
  851. seq_printf(seq, "temperature: %ld C\n",
  852. KELVIN_TO_CELSIUS(tz->temperature));
  853. end:
  854. return 0;
  855. }
  856. static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
  857. {
  858. return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
  859. }
  860. static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
  861. {
  862. struct acpi_thermal *tz = seq->private;
  863. struct acpi_device *device;
  864. acpi_status status;
  865. int i = 0;
  866. int j = 0;
  867. if (!tz)
  868. goto end;
  869. if (tz->trips.critical.flags.valid)
  870. seq_printf(seq, "critical (S5): %ld C%s",
  871. KELVIN_TO_CELSIUS(tz->trips.critical.temperature),
  872. nocrt ? " <disabled>\n" : "\n");
  873. if (tz->trips.hot.flags.valid)
  874. seq_printf(seq, "hot (S4): %ld C%s",
  875. KELVIN_TO_CELSIUS(tz->trips.hot.temperature),
  876. nocrt ? " <disabled>\n" : "\n");
  877. if (tz->trips.passive.flags.valid) {
  878. seq_printf(seq,
  879. "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
  880. KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
  881. tz->trips.passive.tc1, tz->trips.passive.tc2,
  882. tz->trips.passive.tsp);
  883. for (j = 0; j < tz->trips.passive.devices.count; j++) {
  884. status = acpi_bus_get_device(tz->trips.passive.devices.
  885. handles[j], &device);
  886. seq_printf(seq, "%4.4s ", status ? "" :
  887. acpi_device_bid(device));
  888. }
  889. seq_puts(seq, "\n");
  890. }
  891. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  892. if (!(tz->trips.active[i].flags.valid))
  893. break;
  894. seq_printf(seq, "active[%d]: %ld C: devices=",
  895. i,
  896. KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
  897. for (j = 0; j < tz->trips.active[i].devices.count; j++){
  898. status = acpi_bus_get_device(tz->trips.active[i].
  899. devices.handles[j],
  900. &device);
  901. seq_printf(seq, "%4.4s ", status ? "" :
  902. acpi_device_bid(device));
  903. }
  904. seq_puts(seq, "\n");
  905. }
  906. end:
  907. return 0;
  908. }
  909. static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
  910. {
  911. return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
  912. }
  913. static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
  914. {
  915. struct acpi_thermal *tz = seq->private;
  916. if (!tz)
  917. goto end;
  918. if (!tz->flags.cooling_mode)
  919. seq_puts(seq, "<setting not supported>\n");
  920. else
  921. seq_puts(seq, "0 - Active; 1 - Passive\n");
  922. end:
  923. return 0;
  924. }
  925. static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
  926. {
  927. return single_open(file, acpi_thermal_cooling_seq_show,
  928. PDE(inode)->data);
  929. }
  930. static ssize_t
  931. acpi_thermal_write_cooling_mode(struct file *file,
  932. const char __user * buffer,
  933. size_t count, loff_t * ppos)
  934. {
  935. struct seq_file *m = file->private_data;
  936. struct acpi_thermal *tz = m->private;
  937. int result = 0;
  938. char mode_string[12] = { '\0' };
  939. if (!tz || (count > sizeof(mode_string) - 1))
  940. return -EINVAL;
  941. if (!tz->flags.cooling_mode)
  942. return -ENODEV;
  943. if (copy_from_user(mode_string, buffer, count))
  944. return -EFAULT;
  945. mode_string[count] = '\0';
  946. result = acpi_thermal_set_cooling_mode(tz,
  947. simple_strtoul(mode_string, NULL,
  948. 0));
  949. if (result)
  950. return result;
  951. acpi_thermal_check(tz);
  952. return count;
  953. }
  954. static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
  955. {
  956. struct acpi_thermal *tz = seq->private;
  957. if (!tz)
  958. goto end;
  959. if (!tz->thermal_zone->polling_delay) {
  960. seq_puts(seq, "<polling disabled>\n");
  961. goto end;
  962. }
  963. seq_printf(seq, "polling frequency: %d seconds\n",
  964. (tz->thermal_zone->polling_delay / 1000));
  965. end:
  966. return 0;
  967. }
  968. static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
  969. {
  970. return single_open(file, acpi_thermal_polling_seq_show,
  971. PDE(inode)->data);
  972. }
  973. static ssize_t
  974. acpi_thermal_write_polling(struct file *file,
  975. const char __user * buffer,
  976. size_t count, loff_t * ppos)
  977. {
  978. struct seq_file *m = file->private_data;
  979. struct acpi_thermal *tz = m->private;
  980. int result = 0;
  981. char polling_string[12] = { '\0' };
  982. int seconds = 0;
  983. if (!tz || (count > sizeof(polling_string) - 1))
  984. return -EINVAL;
  985. if (copy_from_user(polling_string, buffer, count))
  986. return -EFAULT;
  987. polling_string[count] = '\0';
  988. seconds = simple_strtoul(polling_string, NULL, 0);
  989. result = acpi_thermal_set_polling(tz, seconds);
  990. if (result)
  991. return result;
  992. acpi_thermal_check(tz);
  993. return count;
  994. }
  995. static int acpi_thermal_add_fs(struct acpi_device *device)
  996. {
  997. struct proc_dir_entry *entry = NULL;
  998. if (!acpi_device_dir(device)) {
  999. acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
  1000. acpi_thermal_dir);
  1001. if (!acpi_device_dir(device))
  1002. return -ENODEV;
  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. result = acpi_bus_register_driver(&acpi_thermal_driver);
  1289. if (result < 0) {
  1290. remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
  1291. return -ENODEV;
  1292. }
  1293. return 0;
  1294. }
  1295. static void __exit acpi_thermal_exit(void)
  1296. {
  1297. acpi_bus_unregister_driver(&acpi_thermal_driver);
  1298. remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
  1299. return;
  1300. }
  1301. module_init(acpi_thermal_init);
  1302. module_exit(acpi_thermal_exit);