thermal.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920
  1. /*
  2. * acpi_thermal.c - ACPI Thermal Zone Driver ($Revision: 41 $)
  3. *
  4. * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  5. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  6. *
  7. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or (at
  12. * your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  22. *
  23. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. *
  25. * This driver fully implements the ACPI thermal policy as described in the
  26. * ACPI 2.0 Specification.
  27. *
  28. * TBD: 1. Implement passive cooling hysteresis.
  29. * 2. Enhance passive cooling (CPU) states/limit interface to support
  30. * concepts of 'multiple limiters', upper/lower limits, etc.
  31. *
  32. */
  33. #include <linux/kernel.h>
  34. #include <linux/module.h>
  35. #include <linux/dmi.h>
  36. #include <linux/init.h>
  37. #include <linux/types.h>
  38. #include <linux/proc_fs.h>
  39. #include <linux/timer.h>
  40. #include <linux/jiffies.h>
  41. #include <linux/kmod.h>
  42. #include <linux/seq_file.h>
  43. #include <linux/reboot.h>
  44. #include <asm/uaccess.h>
  45. #include <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 timer_list timer;
  171. struct thermal_zone_device *thermal_zone;
  172. int tz_enabled;
  173. struct mutex lock;
  174. };
  175. static const struct file_operations acpi_thermal_state_fops = {
  176. .owner = THIS_MODULE,
  177. .open = acpi_thermal_state_open_fs,
  178. .read = seq_read,
  179. .llseek = seq_lseek,
  180. .release = single_release,
  181. };
  182. static const struct file_operations acpi_thermal_temp_fops = {
  183. .owner = THIS_MODULE,
  184. .open = acpi_thermal_temp_open_fs,
  185. .read = seq_read,
  186. .llseek = seq_lseek,
  187. .release = single_release,
  188. };
  189. static const struct file_operations acpi_thermal_trip_fops = {
  190. .owner = THIS_MODULE,
  191. .open = acpi_thermal_trip_open_fs,
  192. .read = seq_read,
  193. .llseek = seq_lseek,
  194. .release = single_release,
  195. };
  196. static const struct file_operations acpi_thermal_cooling_fops = {
  197. .owner = THIS_MODULE,
  198. .open = acpi_thermal_cooling_open_fs,
  199. .read = seq_read,
  200. .write = acpi_thermal_write_cooling_mode,
  201. .llseek = seq_lseek,
  202. .release = single_release,
  203. };
  204. static const struct file_operations acpi_thermal_polling_fops = {
  205. .owner = THIS_MODULE,
  206. .open = acpi_thermal_polling_open_fs,
  207. .read = seq_read,
  208. .write = acpi_thermal_write_polling,
  209. .llseek = seq_lseek,
  210. .release = single_release,
  211. };
  212. /* --------------------------------------------------------------------------
  213. Thermal Zone Management
  214. -------------------------------------------------------------------------- */
  215. static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
  216. {
  217. acpi_status status = AE_OK;
  218. unsigned long long tmp;
  219. if (!tz)
  220. return -EINVAL;
  221. tz->last_temperature = tz->temperature;
  222. status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp);
  223. if (ACPI_FAILURE(status))
  224. return -ENODEV;
  225. tz->temperature = tmp;
  226. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n",
  227. tz->temperature));
  228. return 0;
  229. }
  230. static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
  231. {
  232. acpi_status status = AE_OK;
  233. unsigned long long tmp;
  234. if (!tz)
  235. return -EINVAL;
  236. status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp);
  237. if (ACPI_FAILURE(status))
  238. return -ENODEV;
  239. tz->polling_frequency = tmp;
  240. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n",
  241. tz->polling_frequency));
  242. return 0;
  243. }
  244. static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
  245. {
  246. if (!tz)
  247. return -EINVAL;
  248. tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
  249. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  250. "Polling frequency set to %lu seconds\n",
  251. tz->polling_frequency/10));
  252. return 0;
  253. }
  254. static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
  255. {
  256. acpi_status status = AE_OK;
  257. union acpi_object arg0 = { ACPI_TYPE_INTEGER };
  258. struct acpi_object_list arg_list = { 1, &arg0 };
  259. acpi_handle handle = NULL;
  260. if (!tz)
  261. return -EINVAL;
  262. status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
  263. if (ACPI_FAILURE(status)) {
  264. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
  265. return -ENODEV;
  266. }
  267. arg0.integer.value = mode;
  268. status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
  269. if (ACPI_FAILURE(status))
  270. return -ENODEV;
  271. return 0;
  272. }
  273. #define ACPI_TRIPS_CRITICAL 0x01
  274. #define ACPI_TRIPS_HOT 0x02
  275. #define ACPI_TRIPS_PASSIVE 0x04
  276. #define ACPI_TRIPS_ACTIVE 0x08
  277. #define ACPI_TRIPS_DEVICES 0x10
  278. #define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE)
  279. #define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES
  280. #define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \
  281. ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \
  282. ACPI_TRIPS_DEVICES)
  283. /*
  284. * This exception is thrown out in two cases:
  285. * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
  286. * when re-evaluating the AML code.
  287. * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change.
  288. * We need to re-bind the cooling devices of a thermal zone when this occurs.
  289. */
  290. #define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \
  291. do { \
  292. if (flags != ACPI_TRIPS_INIT) \
  293. ACPI_EXCEPTION((AE_INFO, AE_ERROR, \
  294. "ACPI thermal trip point %s changed\n" \
  295. "Please send acpidump to linux-acpi@vger.kernel.org\n", str)); \
  296. } while (0)
  297. static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
  298. {
  299. acpi_status status = AE_OK;
  300. unsigned long long tmp;
  301. struct acpi_handle_list devices;
  302. int valid = 0;
  303. int i;
  304. /* Critical Shutdown (required) */
  305. if (flag & ACPI_TRIPS_CRITICAL) {
  306. status = acpi_evaluate_integer(tz->device->handle,
  307. "_CRT", NULL, &tmp);
  308. tz->trips.critical.temperature = tmp;
  309. /*
  310. * Treat freezing temperatures as invalid as well; some
  311. * BIOSes return really low values and cause reboots at startup.
  312. * Below zero (Celcius) values clearly aren't right for sure..
  313. * ... so lets discard those as invalid.
  314. */
  315. if (ACPI_FAILURE(status) ||
  316. tz->trips.critical.temperature <= 2732) {
  317. tz->trips.critical.flags.valid = 0;
  318. ACPI_EXCEPTION((AE_INFO, status,
  319. "No or invalid critical threshold"));
  320. return -ENODEV;
  321. } else {
  322. tz->trips.critical.flags.valid = 1;
  323. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  324. "Found critical threshold [%lu]\n",
  325. tz->trips.critical.temperature));
  326. }
  327. if (tz->trips.critical.flags.valid == 1) {
  328. if (crt == -1) {
  329. tz->trips.critical.flags.valid = 0;
  330. } else if (crt > 0) {
  331. unsigned long crt_k = CELSIUS_TO_KELVIN(crt);
  332. /*
  333. * Allow override critical threshold
  334. */
  335. if (crt_k > tz->trips.critical.temperature)
  336. printk(KERN_WARNING PREFIX
  337. "Critical threshold %d C\n", crt);
  338. tz->trips.critical.temperature = crt_k;
  339. }
  340. }
  341. }
  342. /* Critical Sleep (optional) */
  343. if (flag & ACPI_TRIPS_HOT) {
  344. status = acpi_evaluate_integer(tz->device->handle,
  345. "_HOT", NULL, &tmp);
  346. if (ACPI_FAILURE(status)) {
  347. tz->trips.hot.flags.valid = 0;
  348. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  349. "No hot threshold\n"));
  350. } else {
  351. tz->trips.hot.temperature = tmp;
  352. tz->trips.hot.flags.valid = 1;
  353. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  354. "Found hot threshold [%lu]\n",
  355. tz->trips.critical.temperature));
  356. }
  357. }
  358. /* Passive (optional) */
  359. if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) ||
  360. (flag == ACPI_TRIPS_INIT)) {
  361. valid = tz->trips.passive.flags.valid;
  362. if (psv == -1) {
  363. status = AE_SUPPORT;
  364. } else if (psv > 0) {
  365. tmp = CELSIUS_TO_KELVIN(psv);
  366. status = AE_OK;
  367. } else {
  368. status = acpi_evaluate_integer(tz->device->handle,
  369. "_PSV", NULL, &tmp);
  370. }
  371. if (ACPI_FAILURE(status))
  372. tz->trips.passive.flags.valid = 0;
  373. else {
  374. tz->trips.passive.temperature = tmp;
  375. tz->trips.passive.flags.valid = 1;
  376. if (flag == ACPI_TRIPS_INIT) {
  377. status = acpi_evaluate_integer(
  378. tz->device->handle, "_TC1",
  379. NULL, &tmp);
  380. if (ACPI_FAILURE(status))
  381. tz->trips.passive.flags.valid = 0;
  382. else
  383. tz->trips.passive.tc1 = tmp;
  384. status = acpi_evaluate_integer(
  385. tz->device->handle, "_TC2",
  386. NULL, &tmp);
  387. if (ACPI_FAILURE(status))
  388. tz->trips.passive.flags.valid = 0;
  389. else
  390. tz->trips.passive.tc2 = tmp;
  391. status = acpi_evaluate_integer(
  392. tz->device->handle, "_TSP",
  393. NULL, &tmp);
  394. if (ACPI_FAILURE(status))
  395. tz->trips.passive.flags.valid = 0;
  396. else
  397. tz->trips.passive.tsp = tmp;
  398. }
  399. }
  400. }
  401. if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) {
  402. memset(&devices, 0, sizeof(struct acpi_handle_list));
  403. status = acpi_evaluate_reference(tz->device->handle, "_PSL",
  404. NULL, &devices);
  405. if (ACPI_FAILURE(status)) {
  406. printk(KERN_WARNING PREFIX
  407. "Invalid passive threshold\n");
  408. tz->trips.passive.flags.valid = 0;
  409. }
  410. else
  411. tz->trips.passive.flags.valid = 1;
  412. if (memcmp(&tz->trips.passive.devices, &devices,
  413. sizeof(struct acpi_handle_list))) {
  414. memcpy(&tz->trips.passive.devices, &devices,
  415. sizeof(struct acpi_handle_list));
  416. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
  417. }
  418. }
  419. if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) {
  420. if (valid != tz->trips.passive.flags.valid)
  421. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
  422. }
  423. /* Active (optional) */
  424. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  425. char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
  426. valid = tz->trips.active[i].flags.valid;
  427. if (act == -1)
  428. break; /* disable all active trip points */
  429. if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) &&
  430. tz->trips.active[i].flags.valid)) {
  431. status = acpi_evaluate_integer(tz->device->handle,
  432. name, NULL, &tmp);
  433. if (ACPI_FAILURE(status)) {
  434. tz->trips.active[i].flags.valid = 0;
  435. if (i == 0)
  436. break;
  437. if (act <= 0)
  438. break;
  439. if (i == 1)
  440. tz->trips.active[0].temperature =
  441. CELSIUS_TO_KELVIN(act);
  442. else
  443. /*
  444. * Don't allow override higher than
  445. * the next higher trip point
  446. */
  447. tz->trips.active[i - 1].temperature =
  448. (tz->trips.active[i - 2].temperature <
  449. CELSIUS_TO_KELVIN(act) ?
  450. tz->trips.active[i - 2].temperature :
  451. CELSIUS_TO_KELVIN(act));
  452. break;
  453. } else {
  454. tz->trips.active[i].temperature = tmp;
  455. tz->trips.active[i].flags.valid = 1;
  456. }
  457. }
  458. name[2] = 'L';
  459. if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) {
  460. memset(&devices, 0, sizeof(struct acpi_handle_list));
  461. status = acpi_evaluate_reference(tz->device->handle,
  462. name, NULL, &devices);
  463. if (ACPI_FAILURE(status)) {
  464. printk(KERN_WARNING PREFIX
  465. "Invalid active%d threshold\n", i);
  466. tz->trips.active[i].flags.valid = 0;
  467. }
  468. else
  469. tz->trips.active[i].flags.valid = 1;
  470. if (memcmp(&tz->trips.active[i].devices, &devices,
  471. sizeof(struct acpi_handle_list))) {
  472. memcpy(&tz->trips.active[i].devices, &devices,
  473. sizeof(struct acpi_handle_list));
  474. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
  475. }
  476. }
  477. if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES))
  478. if (valid != tz->trips.active[i].flags.valid)
  479. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state");
  480. if (!tz->trips.active[i].flags.valid)
  481. break;
  482. }
  483. if (flag & ACPI_TRIPS_DEVICES) {
  484. memset(&devices, 0, sizeof(struct acpi_handle_list));
  485. status = acpi_evaluate_reference(tz->device->handle, "_TZD",
  486. NULL, &devices);
  487. if (memcmp(&tz->devices, &devices,
  488. sizeof(struct acpi_handle_list))) {
  489. memcpy(&tz->devices, &devices,
  490. sizeof(struct acpi_handle_list));
  491. ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device");
  492. }
  493. }
  494. return 0;
  495. }
  496. static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
  497. {
  498. return acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
  499. }
  500. static int acpi_thermal_critical(struct acpi_thermal *tz)
  501. {
  502. if (!tz || !tz->trips.critical.flags.valid)
  503. return -EINVAL;
  504. if (tz->temperature >= tz->trips.critical.temperature) {
  505. printk(KERN_WARNING PREFIX "Critical trip point\n");
  506. tz->trips.critical.flags.enabled = 1;
  507. } else if (tz->trips.critical.flags.enabled)
  508. tz->trips.critical.flags.enabled = 0;
  509. acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL,
  510. tz->trips.critical.flags.enabled);
  511. acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
  512. dev_name(&tz->device->dev),
  513. ACPI_THERMAL_NOTIFY_CRITICAL,
  514. tz->trips.critical.flags.enabled);
  515. /* take no action if nocrt is set */
  516. if(!nocrt) {
  517. printk(KERN_EMERG
  518. "Critical temperature reached (%ld C), shutting down.\n",
  519. KELVIN_TO_CELSIUS(tz->temperature));
  520. orderly_poweroff(true);
  521. }
  522. return 0;
  523. }
  524. static int acpi_thermal_hot(struct acpi_thermal *tz)
  525. {
  526. if (!tz || !tz->trips.hot.flags.valid)
  527. return -EINVAL;
  528. if (tz->temperature >= tz->trips.hot.temperature) {
  529. printk(KERN_WARNING PREFIX "Hot trip point\n");
  530. tz->trips.hot.flags.enabled = 1;
  531. } else if (tz->trips.hot.flags.enabled)
  532. tz->trips.hot.flags.enabled = 0;
  533. acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
  534. tz->trips.hot.flags.enabled);
  535. acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
  536. dev_name(&tz->device->dev),
  537. ACPI_THERMAL_NOTIFY_HOT,
  538. tz->trips.hot.flags.enabled);
  539. /* TBD: Call user-mode "sleep(S4)" function if nocrt is cleared */
  540. return 0;
  541. }
  542. static void acpi_thermal_passive(struct acpi_thermal *tz)
  543. {
  544. int result = 1;
  545. struct acpi_thermal_passive *passive = NULL;
  546. int trend = 0;
  547. int i = 0;
  548. if (!tz || !tz->trips.passive.flags.valid)
  549. return;
  550. passive = &(tz->trips.passive);
  551. /*
  552. * Above Trip?
  553. * -----------
  554. * Calculate the thermal trend (using the passive cooling equation)
  555. * and modify the performance limit for all passive cooling devices
  556. * accordingly. Note that we assume symmetry.
  557. */
  558. if (tz->temperature >= passive->temperature) {
  559. trend =
  560. (passive->tc1 * (tz->temperature - tz->last_temperature)) +
  561. (passive->tc2 * (tz->temperature - passive->temperature));
  562. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  563. "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
  564. trend, passive->tc1, tz->temperature,
  565. tz->last_temperature, passive->tc2,
  566. tz->temperature, passive->temperature));
  567. passive->flags.enabled = 1;
  568. /* Heating up? */
  569. if (trend > 0)
  570. for (i = 0; i < passive->devices.count; i++)
  571. acpi_processor_set_thermal_limit(passive->
  572. devices.
  573. handles[i],
  574. ACPI_PROCESSOR_LIMIT_INCREMENT);
  575. /* Cooling off? */
  576. else if (trend < 0) {
  577. for (i = 0; i < passive->devices.count; i++)
  578. /*
  579. * assume that we are on highest
  580. * freq/lowest thrott and can leave
  581. * passive mode, even in error case
  582. */
  583. if (!acpi_processor_set_thermal_limit
  584. (passive->devices.handles[i],
  585. ACPI_PROCESSOR_LIMIT_DECREMENT))
  586. result = 0;
  587. /*
  588. * Leave cooling mode, even if the temp might
  589. * higher than trip point This is because some
  590. * machines might have long thermal polling
  591. * frequencies (tsp) defined. We will fall back
  592. * into passive mode in next cycle (probably quicker)
  593. */
  594. if (result) {
  595. passive->flags.enabled = 0;
  596. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  597. "Disabling passive cooling, still above threshold,"
  598. " but we are cooling down\n"));
  599. }
  600. }
  601. return;
  602. }
  603. /*
  604. * Below Trip?
  605. * -----------
  606. * Implement passive cooling hysteresis to slowly increase performance
  607. * and avoid thrashing around the passive trip point. Note that we
  608. * assume symmetry.
  609. */
  610. if (!passive->flags.enabled)
  611. return;
  612. for (i = 0; i < passive->devices.count; i++)
  613. if (!acpi_processor_set_thermal_limit
  614. (passive->devices.handles[i],
  615. ACPI_PROCESSOR_LIMIT_DECREMENT))
  616. result = 0;
  617. if (result) {
  618. passive->flags.enabled = 0;
  619. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  620. "Disabling passive cooling (zone is cool)\n"));
  621. }
  622. }
  623. static void acpi_thermal_active(struct acpi_thermal *tz)
  624. {
  625. int result = 0;
  626. struct acpi_thermal_active *active = NULL;
  627. int i = 0;
  628. int j = 0;
  629. unsigned long maxtemp = 0;
  630. if (!tz)
  631. return;
  632. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  633. active = &(tz->trips.active[i]);
  634. if (!active || !active->flags.valid)
  635. break;
  636. if (tz->temperature >= active->temperature) {
  637. /*
  638. * Above Threshold?
  639. * ----------------
  640. * If not already enabled, turn ON all cooling devices
  641. * associated with this active threshold.
  642. */
  643. if (active->temperature > maxtemp)
  644. tz->state.active_index = i;
  645. maxtemp = active->temperature;
  646. if (active->flags.enabled)
  647. continue;
  648. for (j = 0; j < active->devices.count; j++) {
  649. result =
  650. acpi_bus_set_power(active->devices.
  651. handles[j],
  652. ACPI_STATE_D0);
  653. if (result) {
  654. printk(KERN_WARNING PREFIX
  655. "Unable to turn cooling device [%p] 'on'\n",
  656. active->devices.
  657. handles[j]);
  658. continue;
  659. }
  660. active->flags.enabled = 1;
  661. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  662. "Cooling device [%p] now 'on'\n",
  663. active->devices.handles[j]));
  664. }
  665. continue;
  666. }
  667. if (!active->flags.enabled)
  668. continue;
  669. /*
  670. * Below Threshold?
  671. * ----------------
  672. * Turn OFF all cooling devices associated with this
  673. * threshold.
  674. */
  675. for (j = 0; j < active->devices.count; j++) {
  676. result = acpi_bus_set_power(active->devices.handles[j],
  677. ACPI_STATE_D3);
  678. if (result) {
  679. printk(KERN_WARNING PREFIX
  680. "Unable to turn cooling device [%p] 'off'\n",
  681. active->devices.handles[j]);
  682. continue;
  683. }
  684. active->flags.enabled = 0;
  685. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  686. "Cooling device [%p] now 'off'\n",
  687. active->devices.handles[j]));
  688. }
  689. }
  690. }
  691. static void acpi_thermal_check(void *context);
  692. static void acpi_thermal_run(unsigned long data)
  693. {
  694. struct acpi_thermal *tz = (struct acpi_thermal *)data;
  695. if (!tz->zombie)
  696. acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data);
  697. }
  698. static void acpi_thermal_active_off(void *data)
  699. {
  700. int result = 0;
  701. struct acpi_thermal *tz = data;
  702. int i = 0;
  703. int j = 0;
  704. struct acpi_thermal_active *active = NULL;
  705. if (!tz) {
  706. printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
  707. return;
  708. }
  709. result = acpi_thermal_get_temperature(tz);
  710. if (result)
  711. return;
  712. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  713. active = &(tz->trips.active[i]);
  714. if (!active || !active->flags.valid)
  715. break;
  716. if (tz->temperature >= active->temperature) {
  717. /*
  718. * If the thermal temperature is greater than the
  719. * active threshod, unnecessary to turn off the
  720. * the active cooling device.
  721. */
  722. continue;
  723. }
  724. /*
  725. * Below Threshold?
  726. * ----------------
  727. * Turn OFF all cooling devices associated with this
  728. * threshold.
  729. */
  730. for (j = 0; j < active->devices.count; j++)
  731. result = acpi_bus_set_power(active->devices.handles[j],
  732. ACPI_STATE_D3);
  733. }
  734. }
  735. static void acpi_thermal_check(void *data)
  736. {
  737. int result = 0;
  738. struct acpi_thermal *tz = data;
  739. unsigned long sleep_time = 0;
  740. unsigned long timeout_jiffies = 0;
  741. int i = 0;
  742. struct acpi_thermal_state state;
  743. if (!tz) {
  744. printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
  745. return;
  746. }
  747. /* Check if someone else is already running */
  748. if (!mutex_trylock(&tz->lock))
  749. return;
  750. state = tz->state;
  751. result = acpi_thermal_get_temperature(tz);
  752. if (result)
  753. goto unlock;
  754. if (!tz->tz_enabled)
  755. goto unlock;
  756. memset(&tz->state, 0, sizeof(tz->state));
  757. /*
  758. * Check Trip Points
  759. * -----------------
  760. * Compare the current temperature to the trip point values to see
  761. * if we've entered one of the thermal policy states. Note that
  762. * this function determines when a state is entered, but the
  763. * individual policy decides when it is exited (e.g. hysteresis).
  764. */
  765. if (tz->trips.critical.flags.valid)
  766. state.critical |=
  767. (tz->temperature >= tz->trips.critical.temperature);
  768. if (tz->trips.hot.flags.valid)
  769. state.hot |= (tz->temperature >= tz->trips.hot.temperature);
  770. if (tz->trips.passive.flags.valid)
  771. state.passive |=
  772. (tz->temperature >= tz->trips.passive.temperature);
  773. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
  774. if (tz->trips.active[i].flags.valid)
  775. state.active |=
  776. (tz->temperature >=
  777. tz->trips.active[i].temperature);
  778. /*
  779. * Invoke Policy
  780. * -------------
  781. * Separated from the above check to allow individual policy to
  782. * determine when to exit a given state.
  783. */
  784. if (state.critical)
  785. acpi_thermal_critical(tz);
  786. if (state.hot)
  787. acpi_thermal_hot(tz);
  788. if (state.passive)
  789. acpi_thermal_passive(tz);
  790. if (state.active)
  791. acpi_thermal_active(tz);
  792. /*
  793. * Calculate State
  794. * ---------------
  795. * Again, separated from the above two to allow independent policy
  796. * decisions.
  797. */
  798. tz->state.critical = tz->trips.critical.flags.enabled;
  799. tz->state.hot = tz->trips.hot.flags.enabled;
  800. tz->state.passive = tz->trips.passive.flags.enabled;
  801. tz->state.active = 0;
  802. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
  803. tz->state.active |= tz->trips.active[i].flags.enabled;
  804. /*
  805. * Calculate Sleep Time
  806. * --------------------
  807. * If we're in the passive state, use _TSP's value. Otherwise
  808. * use the default polling frequency (e.g. _TZP). If no polling
  809. * frequency is specified then we'll wait forever (at least until
  810. * a thermal event occurs). Note that _TSP and _TZD values are
  811. * given in 1/10th seconds (we must covert to milliseconds).
  812. */
  813. if (tz->state.passive) {
  814. sleep_time = tz->trips.passive.tsp * 100;
  815. timeout_jiffies = jiffies + (HZ * sleep_time) / 1000;
  816. } else if (tz->polling_frequency > 0) {
  817. sleep_time = tz->polling_frequency * 100;
  818. timeout_jiffies = round_jiffies(jiffies + (HZ * sleep_time) / 1000);
  819. }
  820. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n",
  821. tz->name, tz->temperature, sleep_time));
  822. /*
  823. * Schedule Next Poll
  824. * ------------------
  825. */
  826. if (!sleep_time) {
  827. if (timer_pending(&(tz->timer)))
  828. del_timer(&(tz->timer));
  829. } else {
  830. if (timer_pending(&(tz->timer)))
  831. mod_timer(&(tz->timer), timeout_jiffies);
  832. else {
  833. tz->timer.data = (unsigned long)tz;
  834. tz->timer.function = acpi_thermal_run;
  835. tz->timer.expires = timeout_jiffies;
  836. add_timer(&(tz->timer));
  837. }
  838. }
  839. unlock:
  840. mutex_unlock(&tz->lock);
  841. }
  842. /* sys I/F for generic thermal sysfs support */
  843. #define KELVIN_TO_MILLICELSIUS(t) (t * 100 - 273200)
  844. static int thermal_get_temp(struct thermal_zone_device *thermal,
  845. unsigned long *temp)
  846. {
  847. struct acpi_thermal *tz = thermal->devdata;
  848. int result;
  849. if (!tz)
  850. return -EINVAL;
  851. result = acpi_thermal_get_temperature(tz);
  852. if (result)
  853. return result;
  854. *temp = KELVIN_TO_MILLICELSIUS(tz->temperature);
  855. return 0;
  856. }
  857. static const char enabled[] = "kernel";
  858. static const char disabled[] = "user";
  859. static int thermal_get_mode(struct thermal_zone_device *thermal,
  860. enum thermal_device_mode *mode)
  861. {
  862. struct acpi_thermal *tz = thermal->devdata;
  863. if (!tz)
  864. return -EINVAL;
  865. *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
  866. THERMAL_DEVICE_DISABLED;
  867. return 0;
  868. }
  869. static int thermal_set_mode(struct thermal_zone_device *thermal,
  870. enum thermal_device_mode mode)
  871. {
  872. struct acpi_thermal *tz = thermal->devdata;
  873. int enable;
  874. if (!tz)
  875. return -EINVAL;
  876. /*
  877. * enable/disable thermal management from ACPI thermal driver
  878. */
  879. if (mode == THERMAL_DEVICE_ENABLED)
  880. enable = 1;
  881. else if (mode == THERMAL_DEVICE_DISABLED)
  882. enable = 0;
  883. else
  884. return -EINVAL;
  885. if (enable != tz->tz_enabled) {
  886. tz->tz_enabled = enable;
  887. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  888. "%s ACPI thermal control\n",
  889. tz->tz_enabled ? enabled : disabled));
  890. acpi_thermal_check(tz);
  891. }
  892. return 0;
  893. }
  894. static int thermal_get_trip_type(struct thermal_zone_device *thermal,
  895. int trip, enum thermal_trip_type *type)
  896. {
  897. struct acpi_thermal *tz = thermal->devdata;
  898. int i;
  899. if (!tz || trip < 0)
  900. return -EINVAL;
  901. if (tz->trips.critical.flags.valid) {
  902. if (!trip) {
  903. *type = THERMAL_TRIP_CRITICAL;
  904. return 0;
  905. }
  906. trip--;
  907. }
  908. if (tz->trips.hot.flags.valid) {
  909. if (!trip) {
  910. *type = THERMAL_TRIP_HOT;
  911. return 0;
  912. }
  913. trip--;
  914. }
  915. if (tz->trips.passive.flags.valid) {
  916. if (!trip) {
  917. *type = THERMAL_TRIP_PASSIVE;
  918. return 0;
  919. }
  920. trip--;
  921. }
  922. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
  923. tz->trips.active[i].flags.valid; i++) {
  924. if (!trip) {
  925. *type = THERMAL_TRIP_ACTIVE;
  926. return 0;
  927. }
  928. trip--;
  929. }
  930. return -EINVAL;
  931. }
  932. static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
  933. int trip, unsigned long *temp)
  934. {
  935. struct acpi_thermal *tz = thermal->devdata;
  936. int i;
  937. if (!tz || trip < 0)
  938. return -EINVAL;
  939. if (tz->trips.critical.flags.valid) {
  940. if (!trip) {
  941. *temp = KELVIN_TO_MILLICELSIUS(
  942. tz->trips.critical.temperature);
  943. return 0;
  944. }
  945. trip--;
  946. }
  947. if (tz->trips.hot.flags.valid) {
  948. if (!trip) {
  949. *temp = KELVIN_TO_MILLICELSIUS(
  950. tz->trips.hot.temperature);
  951. return 0;
  952. }
  953. trip--;
  954. }
  955. if (tz->trips.passive.flags.valid) {
  956. if (!trip) {
  957. *temp = KELVIN_TO_MILLICELSIUS(
  958. tz->trips.passive.temperature);
  959. return 0;
  960. }
  961. trip--;
  962. }
  963. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
  964. tz->trips.active[i].flags.valid; i++) {
  965. if (!trip) {
  966. *temp = KELVIN_TO_MILLICELSIUS(
  967. tz->trips.active[i].temperature);
  968. return 0;
  969. }
  970. trip--;
  971. }
  972. return -EINVAL;
  973. }
  974. static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
  975. unsigned long *temperature) {
  976. struct acpi_thermal *tz = thermal->devdata;
  977. if (tz->trips.critical.flags.valid) {
  978. *temperature = KELVIN_TO_MILLICELSIUS(
  979. tz->trips.critical.temperature);
  980. return 0;
  981. } else
  982. return -EINVAL;
  983. }
  984. typedef int (*cb)(struct thermal_zone_device *, int,
  985. struct thermal_cooling_device *);
  986. static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
  987. struct thermal_cooling_device *cdev,
  988. cb action)
  989. {
  990. struct acpi_device *device = cdev->devdata;
  991. struct acpi_thermal *tz = thermal->devdata;
  992. struct acpi_device *dev;
  993. acpi_status status;
  994. acpi_handle handle;
  995. int i;
  996. int j;
  997. int trip = -1;
  998. int result = 0;
  999. if (tz->trips.critical.flags.valid)
  1000. trip++;
  1001. if (tz->trips.hot.flags.valid)
  1002. trip++;
  1003. if (tz->trips.passive.flags.valid) {
  1004. trip++;
  1005. for (i = 0; i < tz->trips.passive.devices.count;
  1006. i++) {
  1007. handle = tz->trips.passive.devices.handles[i];
  1008. status = acpi_bus_get_device(handle, &dev);
  1009. if (ACPI_SUCCESS(status) && (dev == device)) {
  1010. result = action(thermal, trip, cdev);
  1011. if (result)
  1012. goto failed;
  1013. }
  1014. }
  1015. }
  1016. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  1017. if (!tz->trips.active[i].flags.valid)
  1018. break;
  1019. trip++;
  1020. for (j = 0;
  1021. j < tz->trips.active[i].devices.count;
  1022. j++) {
  1023. handle = tz->trips.active[i].devices.handles[j];
  1024. status = acpi_bus_get_device(handle, &dev);
  1025. if (ACPI_SUCCESS(status) && (dev == device)) {
  1026. result = action(thermal, trip, cdev);
  1027. if (result)
  1028. goto failed;
  1029. }
  1030. }
  1031. }
  1032. for (i = 0; i < tz->devices.count; i++) {
  1033. handle = tz->devices.handles[i];
  1034. status = acpi_bus_get_device(handle, &dev);
  1035. if (ACPI_SUCCESS(status) && (dev == device)) {
  1036. result = action(thermal, -1, cdev);
  1037. if (result)
  1038. goto failed;
  1039. }
  1040. }
  1041. failed:
  1042. return result;
  1043. }
  1044. static int
  1045. acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal,
  1046. struct thermal_cooling_device *cdev)
  1047. {
  1048. return acpi_thermal_cooling_device_cb(thermal, cdev,
  1049. thermal_zone_bind_cooling_device);
  1050. }
  1051. static int
  1052. acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
  1053. struct thermal_cooling_device *cdev)
  1054. {
  1055. return acpi_thermal_cooling_device_cb(thermal, cdev,
  1056. thermal_zone_unbind_cooling_device);
  1057. }
  1058. static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
  1059. .bind = acpi_thermal_bind_cooling_device,
  1060. .unbind = acpi_thermal_unbind_cooling_device,
  1061. .get_temp = thermal_get_temp,
  1062. .get_mode = thermal_get_mode,
  1063. .set_mode = thermal_set_mode,
  1064. .get_trip_type = thermal_get_trip_type,
  1065. .get_trip_temp = thermal_get_trip_temp,
  1066. .get_crit_temp = thermal_get_crit_temp,
  1067. };
  1068. static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
  1069. {
  1070. int trips = 0;
  1071. int result;
  1072. acpi_status status;
  1073. int i;
  1074. if (tz->trips.critical.flags.valid)
  1075. trips++;
  1076. if (tz->trips.hot.flags.valid)
  1077. trips++;
  1078. if (tz->trips.passive.flags.valid)
  1079. trips++;
  1080. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
  1081. tz->trips.active[i].flags.valid; i++, trips++);
  1082. tz->thermal_zone = thermal_zone_device_register("acpitz",
  1083. trips, tz, &acpi_thermal_zone_ops);
  1084. if (IS_ERR(tz->thermal_zone))
  1085. return -ENODEV;
  1086. result = sysfs_create_link(&tz->device->dev.kobj,
  1087. &tz->thermal_zone->device.kobj, "thermal_zone");
  1088. if (result)
  1089. return result;
  1090. result = sysfs_create_link(&tz->thermal_zone->device.kobj,
  1091. &tz->device->dev.kobj, "device");
  1092. if (result)
  1093. return result;
  1094. status = acpi_attach_data(tz->device->handle,
  1095. acpi_bus_private_data_handler,
  1096. tz->thermal_zone);
  1097. if (ACPI_FAILURE(status)) {
  1098. printk(KERN_ERR PREFIX
  1099. "Error attaching device data\n");
  1100. return -ENODEV;
  1101. }
  1102. tz->tz_enabled = 1;
  1103. dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
  1104. tz->thermal_zone->id);
  1105. return 0;
  1106. }
  1107. static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
  1108. {
  1109. sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
  1110. sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
  1111. thermal_zone_device_unregister(tz->thermal_zone);
  1112. tz->thermal_zone = NULL;
  1113. acpi_detach_data(tz->device->handle, acpi_bus_private_data_handler);
  1114. }
  1115. /* --------------------------------------------------------------------------
  1116. FS Interface (/proc)
  1117. -------------------------------------------------------------------------- */
  1118. static struct proc_dir_entry *acpi_thermal_dir;
  1119. static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
  1120. {
  1121. struct acpi_thermal *tz = seq->private;
  1122. if (!tz)
  1123. goto end;
  1124. seq_puts(seq, "state: ");
  1125. if (!tz->state.critical && !tz->state.hot && !tz->state.passive
  1126. && !tz->state.active)
  1127. seq_puts(seq, "ok\n");
  1128. else {
  1129. if (tz->state.critical)
  1130. seq_puts(seq, "critical ");
  1131. if (tz->state.hot)
  1132. seq_puts(seq, "hot ");
  1133. if (tz->state.passive)
  1134. seq_puts(seq, "passive ");
  1135. if (tz->state.active)
  1136. seq_printf(seq, "active[%d]", tz->state.active_index);
  1137. seq_puts(seq, "\n");
  1138. }
  1139. end:
  1140. return 0;
  1141. }
  1142. static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
  1143. {
  1144. return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
  1145. }
  1146. static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
  1147. {
  1148. int result = 0;
  1149. struct acpi_thermal *tz = seq->private;
  1150. if (!tz)
  1151. goto end;
  1152. result = acpi_thermal_get_temperature(tz);
  1153. if (result)
  1154. goto end;
  1155. seq_printf(seq, "temperature: %ld C\n",
  1156. KELVIN_TO_CELSIUS(tz->temperature));
  1157. end:
  1158. return 0;
  1159. }
  1160. static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
  1161. {
  1162. return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
  1163. }
  1164. static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
  1165. {
  1166. struct acpi_thermal *tz = seq->private;
  1167. struct acpi_device *device;
  1168. acpi_status status;
  1169. int i = 0;
  1170. int j = 0;
  1171. if (!tz)
  1172. goto end;
  1173. if (tz->trips.critical.flags.valid)
  1174. seq_printf(seq, "critical (S5): %ld C%s",
  1175. KELVIN_TO_CELSIUS(tz->trips.critical.temperature),
  1176. nocrt ? " <disabled>\n" : "\n");
  1177. if (tz->trips.hot.flags.valid)
  1178. seq_printf(seq, "hot (S4): %ld C%s",
  1179. KELVIN_TO_CELSIUS(tz->trips.hot.temperature),
  1180. nocrt ? " <disabled>\n" : "\n");
  1181. if (tz->trips.passive.flags.valid) {
  1182. seq_printf(seq,
  1183. "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
  1184. KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
  1185. tz->trips.passive.tc1, tz->trips.passive.tc2,
  1186. tz->trips.passive.tsp);
  1187. for (j = 0; j < tz->trips.passive.devices.count; j++) {
  1188. status = acpi_bus_get_device(tz->trips.passive.devices.
  1189. handles[j], &device);
  1190. seq_printf(seq, "%4.4s ", status ? "" :
  1191. acpi_device_bid(device));
  1192. }
  1193. seq_puts(seq, "\n");
  1194. }
  1195. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  1196. if (!(tz->trips.active[i].flags.valid))
  1197. break;
  1198. seq_printf(seq, "active[%d]: %ld C: devices=",
  1199. i,
  1200. KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
  1201. for (j = 0; j < tz->trips.active[i].devices.count; j++){
  1202. status = acpi_bus_get_device(tz->trips.active[i].
  1203. devices.handles[j],
  1204. &device);
  1205. seq_printf(seq, "%4.4s ", status ? "" :
  1206. acpi_device_bid(device));
  1207. }
  1208. seq_puts(seq, "\n");
  1209. }
  1210. end:
  1211. return 0;
  1212. }
  1213. static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
  1214. {
  1215. return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
  1216. }
  1217. static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
  1218. {
  1219. struct acpi_thermal *tz = seq->private;
  1220. if (!tz)
  1221. goto end;
  1222. if (!tz->flags.cooling_mode)
  1223. seq_puts(seq, "<setting not supported>\n");
  1224. else
  1225. seq_puts(seq, "0 - Active; 1 - Passive\n");
  1226. end:
  1227. return 0;
  1228. }
  1229. static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
  1230. {
  1231. return single_open(file, acpi_thermal_cooling_seq_show,
  1232. PDE(inode)->data);
  1233. }
  1234. static ssize_t
  1235. acpi_thermal_write_cooling_mode(struct file *file,
  1236. const char __user * buffer,
  1237. size_t count, loff_t * ppos)
  1238. {
  1239. struct seq_file *m = file->private_data;
  1240. struct acpi_thermal *tz = m->private;
  1241. int result = 0;
  1242. char mode_string[12] = { '\0' };
  1243. if (!tz || (count > sizeof(mode_string) - 1))
  1244. return -EINVAL;
  1245. if (!tz->flags.cooling_mode)
  1246. return -ENODEV;
  1247. if (copy_from_user(mode_string, buffer, count))
  1248. return -EFAULT;
  1249. mode_string[count] = '\0';
  1250. result = acpi_thermal_set_cooling_mode(tz,
  1251. simple_strtoul(mode_string, NULL,
  1252. 0));
  1253. if (result)
  1254. return result;
  1255. acpi_thermal_check(tz);
  1256. return count;
  1257. }
  1258. static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
  1259. {
  1260. struct acpi_thermal *tz = seq->private;
  1261. if (!tz)
  1262. goto end;
  1263. if (!tz->polling_frequency) {
  1264. seq_puts(seq, "<polling disabled>\n");
  1265. goto end;
  1266. }
  1267. seq_printf(seq, "polling frequency: %lu seconds\n",
  1268. (tz->polling_frequency / 10));
  1269. end:
  1270. return 0;
  1271. }
  1272. static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
  1273. {
  1274. return single_open(file, acpi_thermal_polling_seq_show,
  1275. PDE(inode)->data);
  1276. }
  1277. static ssize_t
  1278. acpi_thermal_write_polling(struct file *file,
  1279. const char __user * buffer,
  1280. size_t count, loff_t * ppos)
  1281. {
  1282. struct seq_file *m = file->private_data;
  1283. struct acpi_thermal *tz = m->private;
  1284. int result = 0;
  1285. char polling_string[12] = { '\0' };
  1286. int seconds = 0;
  1287. if (!tz || (count > sizeof(polling_string) - 1))
  1288. return -EINVAL;
  1289. if (copy_from_user(polling_string, buffer, count))
  1290. return -EFAULT;
  1291. polling_string[count] = '\0';
  1292. seconds = simple_strtoul(polling_string, NULL, 0);
  1293. result = acpi_thermal_set_polling(tz, seconds);
  1294. if (result)
  1295. return result;
  1296. acpi_thermal_check(tz);
  1297. return count;
  1298. }
  1299. static int acpi_thermal_add_fs(struct acpi_device *device)
  1300. {
  1301. struct proc_dir_entry *entry = NULL;
  1302. if (!acpi_device_dir(device)) {
  1303. acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
  1304. acpi_thermal_dir);
  1305. if (!acpi_device_dir(device))
  1306. return -ENODEV;
  1307. acpi_device_dir(device)->owner = THIS_MODULE;
  1308. }
  1309. /* 'state' [R] */
  1310. entry = proc_create_data(ACPI_THERMAL_FILE_STATE,
  1311. S_IRUGO, acpi_device_dir(device),
  1312. &acpi_thermal_state_fops,
  1313. acpi_driver_data(device));
  1314. if (!entry)
  1315. return -ENODEV;
  1316. /* 'temperature' [R] */
  1317. entry = proc_create_data(ACPI_THERMAL_FILE_TEMPERATURE,
  1318. S_IRUGO, acpi_device_dir(device),
  1319. &acpi_thermal_temp_fops,
  1320. acpi_driver_data(device));
  1321. if (!entry)
  1322. return -ENODEV;
  1323. /* 'trip_points' [R] */
  1324. entry = proc_create_data(ACPI_THERMAL_FILE_TRIP_POINTS,
  1325. S_IRUGO,
  1326. acpi_device_dir(device),
  1327. &acpi_thermal_trip_fops,
  1328. acpi_driver_data(device));
  1329. if (!entry)
  1330. return -ENODEV;
  1331. /* 'cooling_mode' [R/W] */
  1332. entry = proc_create_data(ACPI_THERMAL_FILE_COOLING_MODE,
  1333. S_IFREG | S_IRUGO | S_IWUSR,
  1334. acpi_device_dir(device),
  1335. &acpi_thermal_cooling_fops,
  1336. acpi_driver_data(device));
  1337. if (!entry)
  1338. return -ENODEV;
  1339. /* 'polling_frequency' [R/W] */
  1340. entry = proc_create_data(ACPI_THERMAL_FILE_POLLING_FREQ,
  1341. S_IFREG | S_IRUGO | S_IWUSR,
  1342. acpi_device_dir(device),
  1343. &acpi_thermal_polling_fops,
  1344. acpi_driver_data(device));
  1345. if (!entry)
  1346. return -ENODEV;
  1347. return 0;
  1348. }
  1349. static int acpi_thermal_remove_fs(struct acpi_device *device)
  1350. {
  1351. if (acpi_device_dir(device)) {
  1352. remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
  1353. acpi_device_dir(device));
  1354. remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
  1355. acpi_device_dir(device));
  1356. remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
  1357. acpi_device_dir(device));
  1358. remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
  1359. acpi_device_dir(device));
  1360. remove_proc_entry(ACPI_THERMAL_FILE_STATE,
  1361. acpi_device_dir(device));
  1362. remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
  1363. acpi_device_dir(device) = NULL;
  1364. }
  1365. return 0;
  1366. }
  1367. /* --------------------------------------------------------------------------
  1368. Driver Interface
  1369. -------------------------------------------------------------------------- */
  1370. static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
  1371. {
  1372. struct acpi_thermal *tz = data;
  1373. struct acpi_device *device = NULL;
  1374. if (!tz)
  1375. return;
  1376. device = tz->device;
  1377. switch (event) {
  1378. case ACPI_THERMAL_NOTIFY_TEMPERATURE:
  1379. acpi_thermal_check(tz);
  1380. break;
  1381. case ACPI_THERMAL_NOTIFY_THRESHOLDS:
  1382. acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS);
  1383. acpi_thermal_check(tz);
  1384. acpi_bus_generate_proc_event(device, event, 0);
  1385. acpi_bus_generate_netlink_event(device->pnp.device_class,
  1386. dev_name(&device->dev), event, 0);
  1387. break;
  1388. case ACPI_THERMAL_NOTIFY_DEVICES:
  1389. acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES);
  1390. acpi_thermal_check(tz);
  1391. acpi_bus_generate_proc_event(device, event, 0);
  1392. acpi_bus_generate_netlink_event(device->pnp.device_class,
  1393. dev_name(&device->dev), event, 0);
  1394. break;
  1395. default:
  1396. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  1397. "Unsupported event [0x%x]\n", event));
  1398. break;
  1399. }
  1400. return;
  1401. }
  1402. static int acpi_thermal_get_info(struct acpi_thermal *tz)
  1403. {
  1404. int result = 0;
  1405. if (!tz)
  1406. return -EINVAL;
  1407. /* Get temperature [_TMP] (required) */
  1408. result = acpi_thermal_get_temperature(tz);
  1409. if (result)
  1410. return result;
  1411. /* Get trip points [_CRT, _PSV, etc.] (required) */
  1412. result = acpi_thermal_get_trip_points(tz);
  1413. if (result)
  1414. return result;
  1415. /* Set the cooling mode [_SCP] to active cooling (default) */
  1416. result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
  1417. if (!result)
  1418. tz->flags.cooling_mode = 1;
  1419. /* Get default polling frequency [_TZP] (optional) */
  1420. if (tzp)
  1421. tz->polling_frequency = tzp;
  1422. else
  1423. acpi_thermal_get_polling_frequency(tz);
  1424. return 0;
  1425. }
  1426. static int acpi_thermal_add(struct acpi_device *device)
  1427. {
  1428. int result = 0;
  1429. acpi_status status = AE_OK;
  1430. struct acpi_thermal *tz = NULL;
  1431. if (!device)
  1432. return -EINVAL;
  1433. tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
  1434. if (!tz)
  1435. return -ENOMEM;
  1436. tz->device = device;
  1437. strcpy(tz->name, device->pnp.bus_id);
  1438. strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
  1439. strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
  1440. device->driver_data = tz;
  1441. mutex_init(&tz->lock);
  1442. result = acpi_thermal_get_info(tz);
  1443. if (result)
  1444. goto free_memory;
  1445. result = acpi_thermal_register_thermal_zone(tz);
  1446. if (result)
  1447. goto free_memory;
  1448. result = acpi_thermal_add_fs(device);
  1449. if (result)
  1450. goto unregister_thermal_zone;
  1451. init_timer(&tz->timer);
  1452. acpi_thermal_active_off(tz);
  1453. acpi_thermal_check(tz);
  1454. status = acpi_install_notify_handler(device->handle,
  1455. ACPI_DEVICE_NOTIFY,
  1456. acpi_thermal_notify, tz);
  1457. if (ACPI_FAILURE(status)) {
  1458. result = -ENODEV;
  1459. goto remove_fs;
  1460. }
  1461. printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
  1462. acpi_device_name(device), acpi_device_bid(device),
  1463. KELVIN_TO_CELSIUS(tz->temperature));
  1464. goto end;
  1465. remove_fs:
  1466. acpi_thermal_remove_fs(device);
  1467. unregister_thermal_zone:
  1468. thermal_zone_device_unregister(tz->thermal_zone);
  1469. free_memory:
  1470. kfree(tz);
  1471. end:
  1472. return result;
  1473. }
  1474. static int acpi_thermal_remove(struct acpi_device *device, int type)
  1475. {
  1476. acpi_status status = AE_OK;
  1477. struct acpi_thermal *tz = NULL;
  1478. if (!device || !acpi_driver_data(device))
  1479. return -EINVAL;
  1480. tz = acpi_driver_data(device);
  1481. /* avoid timer adding new defer task */
  1482. tz->zombie = 1;
  1483. /* wait for running timer (on other CPUs) finish */
  1484. del_timer_sync(&(tz->timer));
  1485. /* synchronize deferred task */
  1486. acpi_os_wait_events_complete(NULL);
  1487. /* deferred task may reinsert timer */
  1488. del_timer_sync(&(tz->timer));
  1489. status = acpi_remove_notify_handler(device->handle,
  1490. ACPI_DEVICE_NOTIFY,
  1491. acpi_thermal_notify);
  1492. /* Terminate policy */
  1493. if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
  1494. tz->trips.passive.flags.enabled = 0;
  1495. acpi_thermal_passive(tz);
  1496. }
  1497. if (tz->trips.active[0].flags.valid
  1498. && tz->trips.active[0].flags.enabled) {
  1499. tz->trips.active[0].flags.enabled = 0;
  1500. acpi_thermal_active(tz);
  1501. }
  1502. acpi_thermal_remove_fs(device);
  1503. acpi_thermal_unregister_thermal_zone(tz);
  1504. mutex_destroy(&tz->lock);
  1505. kfree(tz);
  1506. return 0;
  1507. }
  1508. static int acpi_thermal_resume(struct acpi_device *device)
  1509. {
  1510. struct acpi_thermal *tz = NULL;
  1511. int i, j, power_state, result;
  1512. if (!device || !acpi_driver_data(device))
  1513. return -EINVAL;
  1514. tz = acpi_driver_data(device);
  1515. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  1516. if (!(&tz->trips.active[i]))
  1517. break;
  1518. if (!tz->trips.active[i].flags.valid)
  1519. break;
  1520. tz->trips.active[i].flags.enabled = 1;
  1521. for (j = 0; j < tz->trips.active[i].devices.count; j++) {
  1522. result = acpi_bus_get_power(tz->trips.active[i].devices.
  1523. handles[j], &power_state);
  1524. if (result || (power_state != ACPI_STATE_D0)) {
  1525. tz->trips.active[i].flags.enabled = 0;
  1526. break;
  1527. }
  1528. }
  1529. tz->state.active |= tz->trips.active[i].flags.enabled;
  1530. }
  1531. acpi_thermal_check(tz);
  1532. return AE_OK;
  1533. }
  1534. static int thermal_act(const struct dmi_system_id *d) {
  1535. if (act == 0) {
  1536. printk(KERN_NOTICE "ACPI: %s detected: "
  1537. "disabling all active thermal trip points\n", d->ident);
  1538. act = -1;
  1539. }
  1540. return 0;
  1541. }
  1542. static int thermal_nocrt(const struct dmi_system_id *d) {
  1543. printk(KERN_NOTICE "ACPI: %s detected: "
  1544. "disabling all critical thermal trip point actions.\n", d->ident);
  1545. nocrt = 1;
  1546. return 0;
  1547. }
  1548. static int thermal_tzp(const struct dmi_system_id *d) {
  1549. if (tzp == 0) {
  1550. printk(KERN_NOTICE "ACPI: %s detected: "
  1551. "enabling thermal zone polling\n", d->ident);
  1552. tzp = 300; /* 300 dS = 30 Seconds */
  1553. }
  1554. return 0;
  1555. }
  1556. static int thermal_psv(const struct dmi_system_id *d) {
  1557. if (psv == 0) {
  1558. printk(KERN_NOTICE "ACPI: %s detected: "
  1559. "disabling all passive thermal trip points\n", d->ident);
  1560. psv = -1;
  1561. }
  1562. return 0;
  1563. }
  1564. static struct dmi_system_id thermal_dmi_table[] __initdata = {
  1565. /*
  1566. * Award BIOS on this AOpen makes thermal control almost worthless.
  1567. * http://bugzilla.kernel.org/show_bug.cgi?id=8842
  1568. */
  1569. {
  1570. .callback = thermal_act,
  1571. .ident = "AOpen i915GMm-HFS",
  1572. .matches = {
  1573. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  1574. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  1575. },
  1576. },
  1577. {
  1578. .callback = thermal_psv,
  1579. .ident = "AOpen i915GMm-HFS",
  1580. .matches = {
  1581. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  1582. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  1583. },
  1584. },
  1585. {
  1586. .callback = thermal_tzp,
  1587. .ident = "AOpen i915GMm-HFS",
  1588. .matches = {
  1589. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  1590. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  1591. },
  1592. },
  1593. {
  1594. .callback = thermal_nocrt,
  1595. .ident = "Gigabyte GA-7ZX",
  1596. .matches = {
  1597. DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
  1598. DMI_MATCH(DMI_BOARD_NAME, "7ZX"),
  1599. },
  1600. },
  1601. {}
  1602. };
  1603. static int __init acpi_thermal_init(void)
  1604. {
  1605. int result = 0;
  1606. dmi_check_system(thermal_dmi_table);
  1607. if (off) {
  1608. printk(KERN_NOTICE "ACPI: thermal control disabled\n");
  1609. return -ENODEV;
  1610. }
  1611. acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
  1612. if (!acpi_thermal_dir)
  1613. return -ENODEV;
  1614. acpi_thermal_dir->owner = THIS_MODULE;
  1615. result = acpi_bus_register_driver(&acpi_thermal_driver);
  1616. if (result < 0) {
  1617. remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
  1618. return -ENODEV;
  1619. }
  1620. return 0;
  1621. }
  1622. static void __exit acpi_thermal_exit(void)
  1623. {
  1624. acpi_bus_unregister_driver(&acpi_thermal_driver);
  1625. remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
  1626. return;
  1627. }
  1628. module_init(acpi_thermal_init);
  1629. module_exit(acpi_thermal_exit);