thermal.c 40 KB

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