thermal.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445
  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/init.h>
  36. #include <linux/types.h>
  37. #include <linux/proc_fs.h>
  38. #include <linux/sched.h>
  39. #include <linux/kmod.h>
  40. #include <linux/seq_file.h>
  41. #include <asm/uaccess.h>
  42. #include <acpi/acpi_bus.h>
  43. #include <acpi/acpi_drivers.h>
  44. #define ACPI_THERMAL_COMPONENT 0x04000000
  45. #define ACPI_THERMAL_CLASS "thermal_zone"
  46. #define ACPI_THERMAL_DRIVER_NAME "ACPI Thermal Zone Driver"
  47. #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
  48. #define ACPI_THERMAL_FILE_STATE "state"
  49. #define ACPI_THERMAL_FILE_TEMPERATURE "temperature"
  50. #define ACPI_THERMAL_FILE_TRIP_POINTS "trip_points"
  51. #define ACPI_THERMAL_FILE_COOLING_MODE "cooling_mode"
  52. #define ACPI_THERMAL_FILE_POLLING_FREQ "polling_frequency"
  53. #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80
  54. #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81
  55. #define ACPI_THERMAL_NOTIFY_DEVICES 0x82
  56. #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0
  57. #define ACPI_THERMAL_NOTIFY_HOT 0xF1
  58. #define ACPI_THERMAL_MODE_ACTIVE 0x00
  59. #define ACPI_THERMAL_MODE_PASSIVE 0x01
  60. #define ACPI_THERMAL_MODE_CRITICAL 0xff
  61. #define ACPI_THERMAL_PATH_POWEROFF "/sbin/poweroff"
  62. #define ACPI_THERMAL_MAX_ACTIVE 10
  63. #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
  64. #define KELVIN_TO_CELSIUS(t) (long)(((long)t-2732>=0) ? ((long)t-2732+5)/10 : ((long)t-2732-5)/10)
  65. #define CELSIUS_TO_KELVIN(t) ((t+273)*10)
  66. #define _COMPONENT ACPI_THERMAL_COMPONENT
  67. ACPI_MODULE_NAME ("acpi_thermal")
  68. MODULE_AUTHOR("Paul Diefenbaugh");
  69. MODULE_DESCRIPTION(ACPI_THERMAL_DRIVER_NAME);
  70. MODULE_LICENSE("GPL");
  71. static int tzp;
  72. module_param(tzp, int, 0);
  73. MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.\n");
  74. static int acpi_thermal_add (struct acpi_device *device);
  75. static int acpi_thermal_remove (struct acpi_device *device, int type);
  76. static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
  77. static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
  78. static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
  79. static ssize_t acpi_thermal_write_trip_points (struct file*,const char __user *,size_t,loff_t *);
  80. static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
  81. static ssize_t acpi_thermal_write_cooling_mode (struct file*,const char __user *,size_t,loff_t *);
  82. static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
  83. static ssize_t acpi_thermal_write_polling(struct file*,const char __user *,size_t,loff_t *);
  84. static struct acpi_driver acpi_thermal_driver = {
  85. .name = ACPI_THERMAL_DRIVER_NAME,
  86. .class = ACPI_THERMAL_CLASS,
  87. .ids = ACPI_THERMAL_HID,
  88. .ops = {
  89. .add = acpi_thermal_add,
  90. .remove = acpi_thermal_remove,
  91. },
  92. };
  93. struct acpi_thermal_state {
  94. u8 critical:1;
  95. u8 hot:1;
  96. u8 passive:1;
  97. u8 active:1;
  98. u8 reserved:4;
  99. int active_index;
  100. };
  101. struct acpi_thermal_state_flags {
  102. u8 valid:1;
  103. u8 enabled:1;
  104. u8 reserved:6;
  105. };
  106. struct acpi_thermal_critical {
  107. struct acpi_thermal_state_flags flags;
  108. unsigned long temperature;
  109. };
  110. struct acpi_thermal_hot {
  111. struct acpi_thermal_state_flags flags;
  112. unsigned long temperature;
  113. };
  114. struct acpi_thermal_passive {
  115. struct acpi_thermal_state_flags flags;
  116. unsigned long temperature;
  117. unsigned long tc1;
  118. unsigned long tc2;
  119. unsigned long tsp;
  120. struct acpi_handle_list devices;
  121. };
  122. struct acpi_thermal_active {
  123. struct acpi_thermal_state_flags flags;
  124. unsigned long temperature;
  125. struct acpi_handle_list devices;
  126. };
  127. struct acpi_thermal_trips {
  128. struct acpi_thermal_critical critical;
  129. struct acpi_thermal_hot hot;
  130. struct acpi_thermal_passive passive;
  131. struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
  132. };
  133. struct acpi_thermal_flags {
  134. u8 cooling_mode:1; /* _SCP */
  135. u8 devices:1; /* _TZD */
  136. u8 reserved:6;
  137. };
  138. struct acpi_thermal {
  139. acpi_handle handle;
  140. acpi_bus_id name;
  141. unsigned long temperature;
  142. unsigned long last_temperature;
  143. unsigned long polling_frequency;
  144. u8 cooling_mode;
  145. volatile u8 zombie;
  146. struct acpi_thermal_flags flags;
  147. struct acpi_thermal_state state;
  148. struct acpi_thermal_trips trips;
  149. struct acpi_handle_list devices;
  150. struct timer_list timer;
  151. };
  152. static struct file_operations acpi_thermal_state_fops = {
  153. .open = acpi_thermal_state_open_fs,
  154. .read = seq_read,
  155. .llseek = seq_lseek,
  156. .release = single_release,
  157. };
  158. static struct file_operations acpi_thermal_temp_fops = {
  159. .open = acpi_thermal_temp_open_fs,
  160. .read = seq_read,
  161. .llseek = seq_lseek,
  162. .release = single_release,
  163. };
  164. static struct file_operations acpi_thermal_trip_fops = {
  165. .open = acpi_thermal_trip_open_fs,
  166. .read = seq_read,
  167. .write = acpi_thermal_write_trip_points,
  168. .llseek = seq_lseek,
  169. .release = single_release,
  170. };
  171. static struct file_operations acpi_thermal_cooling_fops = {
  172. .open = acpi_thermal_cooling_open_fs,
  173. .read = seq_read,
  174. .write = acpi_thermal_write_cooling_mode,
  175. .llseek = seq_lseek,
  176. .release = single_release,
  177. };
  178. static struct file_operations acpi_thermal_polling_fops = {
  179. .open = acpi_thermal_polling_open_fs,
  180. .read = seq_read,
  181. .write = acpi_thermal_write_polling,
  182. .llseek = seq_lseek,
  183. .release = single_release,
  184. };
  185. /* --------------------------------------------------------------------------
  186. Thermal Zone Management
  187. -------------------------------------------------------------------------- */
  188. static int
  189. acpi_thermal_get_temperature (
  190. struct acpi_thermal *tz)
  191. {
  192. acpi_status status = AE_OK;
  193. ACPI_FUNCTION_TRACE("acpi_thermal_get_temperature");
  194. if (!tz)
  195. return_VALUE(-EINVAL);
  196. tz->last_temperature = tz->temperature;
  197. status = acpi_evaluate_integer(tz->handle, "_TMP", NULL, &tz->temperature);
  198. if (ACPI_FAILURE(status))
  199. return_VALUE(-ENODEV);
  200. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n", tz->temperature));
  201. return_VALUE(0);
  202. }
  203. static int
  204. acpi_thermal_get_polling_frequency (
  205. struct acpi_thermal *tz)
  206. {
  207. acpi_status status = AE_OK;
  208. ACPI_FUNCTION_TRACE("acpi_thermal_get_polling_frequency");
  209. if (!tz)
  210. return_VALUE(-EINVAL);
  211. status = acpi_evaluate_integer(tz->handle, "_TZP", NULL, &tz->polling_frequency);
  212. if (ACPI_FAILURE(status))
  213. return_VALUE(-ENODEV);
  214. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n", tz->polling_frequency));
  215. return_VALUE(0);
  216. }
  217. static int
  218. acpi_thermal_set_polling (
  219. struct acpi_thermal *tz,
  220. int seconds)
  221. {
  222. ACPI_FUNCTION_TRACE("acpi_thermal_set_polling");
  223. if (!tz)
  224. return_VALUE(-EINVAL);
  225. tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
  226. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency set to %lu seconds\n", tz->polling_frequency));
  227. return_VALUE(0);
  228. }
  229. static int
  230. acpi_thermal_set_cooling_mode (
  231. struct acpi_thermal *tz,
  232. int mode)
  233. {
  234. acpi_status status = AE_OK;
  235. union acpi_object arg0 = {ACPI_TYPE_INTEGER};
  236. struct acpi_object_list arg_list = {1, &arg0};
  237. acpi_handle handle = NULL;
  238. ACPI_FUNCTION_TRACE("acpi_thermal_set_cooling_mode");
  239. if (!tz)
  240. return_VALUE(-EINVAL);
  241. status = acpi_get_handle(tz->handle, "_SCP", &handle);
  242. if (ACPI_FAILURE(status)) {
  243. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
  244. return_VALUE(-ENODEV);
  245. }
  246. arg0.integer.value = mode;
  247. status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
  248. if (ACPI_FAILURE(status))
  249. return_VALUE(-ENODEV);
  250. tz->cooling_mode = mode;
  251. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Cooling mode [%s]\n",
  252. mode?"passive":"active"));
  253. return_VALUE(0);
  254. }
  255. static int
  256. acpi_thermal_get_trip_points (
  257. struct acpi_thermal *tz)
  258. {
  259. acpi_status status = AE_OK;
  260. int i = 0;
  261. ACPI_FUNCTION_TRACE("acpi_thermal_get_trip_points");
  262. if (!tz)
  263. return_VALUE(-EINVAL);
  264. /* Critical Shutdown (required) */
  265. status = acpi_evaluate_integer(tz->handle, "_CRT", NULL,
  266. &tz->trips.critical.temperature);
  267. if (ACPI_FAILURE(status)) {
  268. tz->trips.critical.flags.valid = 0;
  269. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "No critical threshold\n"));
  270. return_VALUE(-ENODEV);
  271. }
  272. else {
  273. tz->trips.critical.flags.valid = 1;
  274. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found critical threshold [%lu]\n", tz->trips.critical.temperature));
  275. }
  276. /* Critical Sleep (optional) */
  277. status = acpi_evaluate_integer(tz->handle, "_HOT", NULL, &tz->trips.hot.temperature);
  278. if (ACPI_FAILURE(status)) {
  279. tz->trips.hot.flags.valid = 0;
  280. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No hot threshold\n"));
  281. }
  282. else {
  283. tz->trips.hot.flags.valid = 1;
  284. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found hot threshold [%lu]\n", tz->trips.hot.temperature));
  285. }
  286. /* Passive: Processors (optional) */
  287. status = acpi_evaluate_integer(tz->handle, "_PSV", NULL, &tz->trips.passive.temperature);
  288. if (ACPI_FAILURE(status)) {
  289. tz->trips.passive.flags.valid = 0;
  290. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No passive threshold\n"));
  291. }
  292. else {
  293. tz->trips.passive.flags.valid = 1;
  294. status = acpi_evaluate_integer(tz->handle, "_TC1", NULL, &tz->trips.passive.tc1);
  295. if (ACPI_FAILURE(status))
  296. tz->trips.passive.flags.valid = 0;
  297. status = acpi_evaluate_integer(tz->handle, "_TC2", NULL, &tz->trips.passive.tc2);
  298. if (ACPI_FAILURE(status))
  299. tz->trips.passive.flags.valid = 0;
  300. status = acpi_evaluate_integer(tz->handle, "_TSP", NULL, &tz->trips.passive.tsp);
  301. if (ACPI_FAILURE(status))
  302. tz->trips.passive.flags.valid = 0;
  303. status = acpi_evaluate_reference(tz->handle, "_PSL", NULL, &tz->trips.passive.devices);
  304. if (ACPI_FAILURE(status))
  305. tz->trips.passive.flags.valid = 0;
  306. if (!tz->trips.passive.flags.valid)
  307. ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid passive threshold\n"));
  308. else
  309. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found passive threshold [%lu]\n", tz->trips.passive.temperature));
  310. }
  311. /* Active: Fans, etc. (optional) */
  312. for (i=0; i<ACPI_THERMAL_MAX_ACTIVE; i++) {
  313. char name[5] = {'_','A','C',('0'+i),'\0'};
  314. status = acpi_evaluate_integer(tz->handle, name, NULL, &tz->trips.active[i].temperature);
  315. if (ACPI_FAILURE(status))
  316. break;
  317. name[2] = 'L';
  318. status = acpi_evaluate_reference(tz->handle, name, NULL, &tz->trips.active[i].devices);
  319. if (ACPI_SUCCESS(status)) {
  320. tz->trips.active[i].flags.valid = 1;
  321. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found active threshold [%d]:[%lu]\n", i, tz->trips.active[i].temperature));
  322. }
  323. else
  324. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid active threshold [%d]\n", i));
  325. }
  326. return_VALUE(0);
  327. }
  328. static int
  329. acpi_thermal_get_devices (
  330. struct acpi_thermal *tz)
  331. {
  332. acpi_status status = AE_OK;
  333. ACPI_FUNCTION_TRACE("acpi_thermal_get_devices");
  334. if (!tz)
  335. return_VALUE(-EINVAL);
  336. status = acpi_evaluate_reference(tz->handle, "_TZD", NULL, &tz->devices);
  337. if (ACPI_FAILURE(status))
  338. return_VALUE(-ENODEV);
  339. return_VALUE(0);
  340. }
  341. static int
  342. acpi_thermal_call_usermode (
  343. char *path)
  344. {
  345. char *argv[2] = {NULL, NULL};
  346. char *envp[3] = {NULL, NULL, NULL};
  347. ACPI_FUNCTION_TRACE("acpi_thermal_call_usermode");
  348. if (!path)
  349. return_VALUE(-EINVAL);
  350. argv[0] = path;
  351. /* minimal command environment */
  352. envp[0] = "HOME=/";
  353. envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
  354. call_usermodehelper(argv[0], argv, envp, 0);
  355. return_VALUE(0);
  356. }
  357. static int
  358. acpi_thermal_critical (
  359. struct acpi_thermal *tz)
  360. {
  361. int result = 0;
  362. struct acpi_device *device = NULL;
  363. ACPI_FUNCTION_TRACE("acpi_thermal_critical");
  364. if (!tz || !tz->trips.critical.flags.valid)
  365. return_VALUE(-EINVAL);
  366. if (tz->temperature >= tz->trips.critical.temperature) {
  367. ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Critical trip point\n"));
  368. tz->trips.critical.flags.enabled = 1;
  369. }
  370. else if (tz->trips.critical.flags.enabled)
  371. tz->trips.critical.flags.enabled = 0;
  372. result = acpi_bus_get_device(tz->handle, &device);
  373. if (result)
  374. return_VALUE(result);
  375. printk(KERN_EMERG "Critical temperature reached (%ld C), shutting down.\n", KELVIN_TO_CELSIUS(tz->temperature));
  376. acpi_bus_generate_event(device, ACPI_THERMAL_NOTIFY_CRITICAL, tz->trips.critical.flags.enabled);
  377. acpi_thermal_call_usermode(ACPI_THERMAL_PATH_POWEROFF);
  378. return_VALUE(0);
  379. }
  380. static int
  381. acpi_thermal_hot (
  382. struct acpi_thermal *tz)
  383. {
  384. int result = 0;
  385. struct acpi_device *device = NULL;
  386. ACPI_FUNCTION_TRACE("acpi_thermal_hot");
  387. if (!tz || !tz->trips.hot.flags.valid)
  388. return_VALUE(-EINVAL);
  389. if (tz->temperature >= tz->trips.hot.temperature) {
  390. ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Hot trip point\n"));
  391. tz->trips.hot.flags.enabled = 1;
  392. }
  393. else if (tz->trips.hot.flags.enabled)
  394. tz->trips.hot.flags.enabled = 0;
  395. result = acpi_bus_get_device(tz->handle, &device);
  396. if (result)
  397. return_VALUE(result);
  398. acpi_bus_generate_event(device, ACPI_THERMAL_NOTIFY_HOT, tz->trips.hot.flags.enabled);
  399. /* TBD: Call user-mode "sleep(S4)" function */
  400. return_VALUE(0);
  401. }
  402. static int
  403. acpi_thermal_passive (
  404. struct acpi_thermal *tz)
  405. {
  406. int result = 0;
  407. struct acpi_thermal_passive *passive = NULL;
  408. int trend = 0;
  409. int i = 0;
  410. ACPI_FUNCTION_TRACE("acpi_thermal_passive");
  411. if (!tz || !tz->trips.passive.flags.valid)
  412. return_VALUE(-EINVAL);
  413. passive = &(tz->trips.passive);
  414. /*
  415. * Above Trip?
  416. * -----------
  417. * Calculate the thermal trend (using the passive cooling equation)
  418. * and modify the performance limit for all passive cooling devices
  419. * accordingly. Note that we assume symmetry.
  420. */
  421. if (tz->temperature >= passive->temperature) {
  422. trend = (passive->tc1 * (tz->temperature - tz->last_temperature)) + (passive->tc2 * (tz->temperature - passive->temperature));
  423. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  424. "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
  425. trend, passive->tc1, tz->temperature,
  426. tz->last_temperature, passive->tc2,
  427. tz->temperature, passive->temperature));
  428. tz->trips.passive.flags.enabled = 1;
  429. /* Heating up? */
  430. if (trend > 0)
  431. for (i=0; i<passive->devices.count; i++)
  432. acpi_processor_set_thermal_limit(
  433. passive->devices.handles[i],
  434. ACPI_PROCESSOR_LIMIT_INCREMENT);
  435. /* Cooling off? */
  436. else if (trend < 0)
  437. for (i=0; i<passive->devices.count; i++)
  438. acpi_processor_set_thermal_limit(
  439. passive->devices.handles[i],
  440. ACPI_PROCESSOR_LIMIT_DECREMENT);
  441. }
  442. /*
  443. * Below Trip?
  444. * -----------
  445. * Implement passive cooling hysteresis to slowly increase performance
  446. * and avoid thrashing around the passive trip point. Note that we
  447. * assume symmetry.
  448. */
  449. else if (tz->trips.passive.flags.enabled) {
  450. for (i=0; i<passive->devices.count; i++)
  451. result = acpi_processor_set_thermal_limit(
  452. passive->devices.handles[i],
  453. ACPI_PROCESSOR_LIMIT_DECREMENT);
  454. if (result == 1) {
  455. tz->trips.passive.flags.enabled = 0;
  456. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  457. "Disabling passive cooling (zone is cool)\n"));
  458. }
  459. }
  460. return_VALUE(0);
  461. }
  462. static int
  463. acpi_thermal_active (
  464. struct acpi_thermal *tz)
  465. {
  466. int result = 0;
  467. struct acpi_thermal_active *active = NULL;
  468. int i = 0;
  469. int j = 0;
  470. unsigned long maxtemp = 0;
  471. ACPI_FUNCTION_TRACE("acpi_thermal_active");
  472. if (!tz)
  473. return_VALUE(-EINVAL);
  474. for (i=0; i<ACPI_THERMAL_MAX_ACTIVE; i++) {
  475. active = &(tz->trips.active[i]);
  476. if (!active || !active->flags.valid)
  477. break;
  478. /*
  479. * Above Threshold?
  480. * ----------------
  481. * If not already enabled, turn ON all cooling devices
  482. * associated with this active threshold.
  483. */
  484. if (tz->temperature >= active->temperature) {
  485. if (active->temperature > maxtemp)
  486. tz->state.active_index = i, maxtemp = active->temperature;
  487. if (!active->flags.enabled) {
  488. for (j = 0; j < active->devices.count; j++) {
  489. result = acpi_bus_set_power(active->devices.handles[j], ACPI_STATE_D0);
  490. if (result) {
  491. ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Unable to turn cooling device [%p] 'on'\n", active->devices.handles[j]));
  492. continue;
  493. }
  494. active->flags.enabled = 1;
  495. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Cooling device [%p] now 'on'\n", active->devices.handles[j]));
  496. }
  497. }
  498. }
  499. /*
  500. * Below Threshold?
  501. * ----------------
  502. * Turn OFF all cooling devices associated with this
  503. * threshold.
  504. */
  505. else if (active->flags.enabled) {
  506. for (j = 0; j < active->devices.count; j++) {
  507. result = acpi_bus_set_power(active->devices.handles[j], ACPI_STATE_D3);
  508. if (result) {
  509. ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Unable to turn cooling device [%p] 'off'\n", active->devices.handles[j]));
  510. continue;
  511. }
  512. active->flags.enabled = 0;
  513. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Cooling device [%p] now 'off'\n", active->devices.handles[j]));
  514. }
  515. }
  516. }
  517. return_VALUE(0);
  518. }
  519. static void acpi_thermal_check (void *context);
  520. static void
  521. acpi_thermal_run (
  522. unsigned long data)
  523. {
  524. struct acpi_thermal *tz = (struct acpi_thermal *)data;
  525. if (!tz->zombie)
  526. acpi_os_queue_for_execution(OSD_PRIORITY_GPE,
  527. acpi_thermal_check, (void *) data);
  528. }
  529. static void
  530. acpi_thermal_check (
  531. void *data)
  532. {
  533. int result = 0;
  534. struct acpi_thermal *tz = (struct acpi_thermal *) data;
  535. unsigned long sleep_time = 0;
  536. int i = 0;
  537. struct acpi_thermal_state state;
  538. ACPI_FUNCTION_TRACE("acpi_thermal_check");
  539. if (!tz) {
  540. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid (NULL) context.\n"));
  541. return_VOID;
  542. }
  543. state = tz->state;
  544. result = acpi_thermal_get_temperature(tz);
  545. if (result)
  546. return_VOID;
  547. memset(&tz->state, 0, sizeof(tz->state));
  548. /*
  549. * Check Trip Points
  550. * -----------------
  551. * Compare the current temperature to the trip point values to see
  552. * if we've entered one of the thermal policy states. Note that
  553. * this function determines when a state is entered, but the
  554. * individual policy decides when it is exited (e.g. hysteresis).
  555. */
  556. if (tz->trips.critical.flags.valid)
  557. state.critical |= (tz->temperature >= tz->trips.critical.temperature);
  558. if (tz->trips.hot.flags.valid)
  559. state.hot |= (tz->temperature >= tz->trips.hot.temperature);
  560. if (tz->trips.passive.flags.valid)
  561. state.passive |= (tz->temperature >= tz->trips.passive.temperature);
  562. for (i=0; i<ACPI_THERMAL_MAX_ACTIVE; i++)
  563. if (tz->trips.active[i].flags.valid)
  564. state.active |= (tz->temperature >= tz->trips.active[i].temperature);
  565. /*
  566. * Invoke Policy
  567. * -------------
  568. * Separated from the above check to allow individual policy to
  569. * determine when to exit a given state.
  570. */
  571. if (state.critical)
  572. acpi_thermal_critical(tz);
  573. if (state.hot)
  574. acpi_thermal_hot(tz);
  575. if (state.passive)
  576. acpi_thermal_passive(tz);
  577. if (state.active)
  578. acpi_thermal_active(tz);
  579. /*
  580. * Calculate State
  581. * ---------------
  582. * Again, separated from the above two to allow independent policy
  583. * decisions.
  584. */
  585. if (tz->trips.critical.flags.enabled)
  586. tz->state.critical = 1;
  587. if (tz->trips.hot.flags.enabled)
  588. tz->state.hot = 1;
  589. if (tz->trips.passive.flags.enabled)
  590. tz->state.passive = 1;
  591. for (i=0; i<ACPI_THERMAL_MAX_ACTIVE; i++)
  592. if (tz->trips.active[i].flags.enabled)
  593. tz->state.active = 1;
  594. /*
  595. * Calculate Sleep Time
  596. * --------------------
  597. * If we're in the passive state, use _TSP's value. Otherwise
  598. * use the default polling frequency (e.g. _TZP). If no polling
  599. * frequency is specified then we'll wait forever (at least until
  600. * a thermal event occurs). Note that _TSP and _TZD values are
  601. * given in 1/10th seconds (we must covert to milliseconds).
  602. */
  603. if (tz->state.passive)
  604. sleep_time = tz->trips.passive.tsp * 100;
  605. else if (tz->polling_frequency > 0)
  606. sleep_time = tz->polling_frequency * 100;
  607. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n",
  608. tz->name, tz->temperature, sleep_time));
  609. /*
  610. * Schedule Next Poll
  611. * ------------------
  612. */
  613. if (!sleep_time) {
  614. if (timer_pending(&(tz->timer)))
  615. del_timer(&(tz->timer));
  616. }
  617. else {
  618. if (timer_pending(&(tz->timer)))
  619. mod_timer(&(tz->timer), (HZ * sleep_time) / 1000);
  620. else {
  621. tz->timer.data = (unsigned long) tz;
  622. tz->timer.function = acpi_thermal_run;
  623. tz->timer.expires = jiffies + (HZ * sleep_time) / 1000;
  624. add_timer(&(tz->timer));
  625. }
  626. }
  627. return_VOID;
  628. }
  629. /* --------------------------------------------------------------------------
  630. FS Interface (/proc)
  631. -------------------------------------------------------------------------- */
  632. static struct proc_dir_entry *acpi_thermal_dir;
  633. static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
  634. {
  635. struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
  636. ACPI_FUNCTION_TRACE("acpi_thermal_state_seq_show");
  637. if (!tz)
  638. goto end;
  639. seq_puts(seq, "state: ");
  640. if (!tz->state.critical && !tz->state.hot && !tz->state.passive && !tz->state.active)
  641. seq_puts(seq, "ok\n");
  642. else {
  643. if (tz->state.critical)
  644. seq_puts(seq, "critical ");
  645. if (tz->state.hot)
  646. seq_puts(seq, "hot ");
  647. if (tz->state.passive)
  648. seq_puts(seq, "passive ");
  649. if (tz->state.active)
  650. seq_printf(seq, "active[%d]", tz->state.active_index);
  651. seq_puts(seq, "\n");
  652. }
  653. end:
  654. return_VALUE(0);
  655. }
  656. static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
  657. {
  658. return single_open(file, acpi_thermal_state_seq_show, PDE(inode)->data);
  659. }
  660. static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
  661. {
  662. int result = 0;
  663. struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
  664. ACPI_FUNCTION_TRACE("acpi_thermal_temp_seq_show");
  665. if (!tz)
  666. goto end;
  667. result = acpi_thermal_get_temperature(tz);
  668. if (result)
  669. goto end;
  670. seq_printf(seq, "temperature: %ld C\n",
  671. KELVIN_TO_CELSIUS(tz->temperature));
  672. end:
  673. return_VALUE(0);
  674. }
  675. static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
  676. {
  677. return single_open(file, acpi_thermal_temp_seq_show, PDE(inode)->data);
  678. }
  679. static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
  680. {
  681. struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
  682. int i = 0;
  683. int j = 0;
  684. ACPI_FUNCTION_TRACE("acpi_thermal_trip_seq_show");
  685. if (!tz)
  686. goto end;
  687. if (tz->trips.critical.flags.valid)
  688. seq_printf(seq, "critical (S5): %ld C\n",
  689. KELVIN_TO_CELSIUS(tz->trips.critical.temperature));
  690. if (tz->trips.hot.flags.valid)
  691. seq_printf(seq, "hot (S4): %ld C\n",
  692. KELVIN_TO_CELSIUS(tz->trips.hot.temperature));
  693. if (tz->trips.passive.flags.valid) {
  694. seq_printf(seq, "passive: %ld C: tc1=%lu tc2=%lu tsp=%lu devices=",
  695. KELVIN_TO_CELSIUS(tz->trips.passive.temperature),
  696. tz->trips.passive.tc1,
  697. tz->trips.passive.tc2,
  698. tz->trips.passive.tsp);
  699. for (j=0; j<tz->trips.passive.devices.count; j++) {
  700. seq_printf(seq, "0x%p ", tz->trips.passive.devices.handles[j]);
  701. }
  702. seq_puts(seq, "\n");
  703. }
  704. for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
  705. if (!(tz->trips.active[i].flags.valid))
  706. break;
  707. seq_printf(seq, "active[%d]: %ld C: devices=",
  708. i, KELVIN_TO_CELSIUS(tz->trips.active[i].temperature));
  709. for (j = 0; j < tz->trips.active[i].devices.count; j++)
  710. seq_printf(seq, "0x%p ",
  711. tz->trips.active[i].devices.handles[j]);
  712. seq_puts(seq, "\n");
  713. }
  714. end:
  715. return_VALUE(0);
  716. }
  717. static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
  718. {
  719. return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
  720. }
  721. static ssize_t
  722. acpi_thermal_write_trip_points (
  723. struct file *file,
  724. const char __user *buffer,
  725. size_t count,
  726. loff_t *ppos)
  727. {
  728. struct seq_file *m = (struct seq_file *)file->private_data;
  729. struct acpi_thermal *tz = (struct acpi_thermal *)m->private;
  730. char *limit_string;
  731. int num, critical, hot, passive;
  732. int *active;
  733. int i = 0;
  734. ACPI_FUNCTION_TRACE("acpi_thermal_write_trip_points");
  735. limit_string = kmalloc(ACPI_THERMAL_MAX_LIMIT_STR_LEN, GFP_KERNEL);
  736. if(!limit_string)
  737. return_VALUE(-ENOMEM);
  738. memset(limit_string, 0, ACPI_THERMAL_MAX_LIMIT_STR_LEN);
  739. active = kmalloc(ACPI_THERMAL_MAX_ACTIVE *sizeof(int), GFP_KERNEL);
  740. if(!active)
  741. return_VALUE(-ENOMEM);
  742. if (!tz || (count > ACPI_THERMAL_MAX_LIMIT_STR_LEN - 1)) {
  743. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument\n"));
  744. count = -EINVAL;
  745. goto end;
  746. }
  747. if (copy_from_user(limit_string, buffer, count)) {
  748. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data\n"));
  749. count = -EFAULT;
  750. goto end;
  751. }
  752. limit_string[count] = '\0';
  753. num = sscanf(limit_string, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d",
  754. &critical, &hot, &passive,
  755. &active[0], &active[1], &active[2], &active[3], &active[4],
  756. &active[5], &active[6], &active[7], &active[8], &active[9]);
  757. if(!(num >=5 && num < (ACPI_THERMAL_MAX_ACTIVE + 3))) {
  758. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data format\n"));
  759. count = -EINVAL;
  760. goto end;
  761. }
  762. tz->trips.critical.temperature = CELSIUS_TO_KELVIN(critical);
  763. tz->trips.hot.temperature = CELSIUS_TO_KELVIN(hot);
  764. tz->trips.passive.temperature = CELSIUS_TO_KELVIN(passive);
  765. for (i = 0; i < num - 3; i++) {
  766. if (!(tz->trips.active[i].flags.valid))
  767. break;
  768. tz->trips.active[i].temperature = CELSIUS_TO_KELVIN(active[i]);
  769. }
  770. end:
  771. kfree(active);
  772. kfree(limit_string);
  773. return_VALUE(count);
  774. }
  775. static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
  776. {
  777. struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
  778. ACPI_FUNCTION_TRACE("acpi_thermal_cooling_seq_show");
  779. if (!tz)
  780. goto end;
  781. if (!tz->flags.cooling_mode) {
  782. seq_puts(seq, "<setting not supported>\n");
  783. }
  784. if ( tz->cooling_mode == ACPI_THERMAL_MODE_CRITICAL )
  785. seq_printf(seq, "cooling mode: critical\n");
  786. else
  787. seq_printf(seq, "cooling mode: %s\n",
  788. tz->cooling_mode?"passive":"active");
  789. end:
  790. return_VALUE(0);
  791. }
  792. static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file)
  793. {
  794. return single_open(file, acpi_thermal_cooling_seq_show,
  795. PDE(inode)->data);
  796. }
  797. static ssize_t
  798. acpi_thermal_write_cooling_mode (
  799. struct file *file,
  800. const char __user *buffer,
  801. size_t count,
  802. loff_t *ppos)
  803. {
  804. struct seq_file *m = (struct seq_file *)file->private_data;
  805. struct acpi_thermal *tz = (struct acpi_thermal *)m->private;
  806. int result = 0;
  807. char mode_string[12] = {'\0'};
  808. ACPI_FUNCTION_TRACE("acpi_thermal_write_cooling_mode");
  809. if (!tz || (count > sizeof(mode_string) - 1))
  810. return_VALUE(-EINVAL);
  811. if (!tz->flags.cooling_mode)
  812. return_VALUE(-ENODEV);
  813. if (copy_from_user(mode_string, buffer, count))
  814. return_VALUE(-EFAULT);
  815. mode_string[count] = '\0';
  816. result = acpi_thermal_set_cooling_mode(tz,
  817. simple_strtoul(mode_string, NULL, 0));
  818. if (result)
  819. return_VALUE(result);
  820. acpi_thermal_check(tz);
  821. return_VALUE(count);
  822. }
  823. static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
  824. {
  825. struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
  826. ACPI_FUNCTION_TRACE("acpi_thermal_polling_seq_show");
  827. if (!tz)
  828. goto end;
  829. if (!tz->polling_frequency) {
  830. seq_puts(seq, "<polling disabled>\n");
  831. goto end;
  832. }
  833. seq_printf(seq, "polling frequency: %lu seconds\n",
  834. (tz->polling_frequency / 10));
  835. end:
  836. return_VALUE(0);
  837. }
  838. static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
  839. {
  840. return single_open(file, acpi_thermal_polling_seq_show,
  841. PDE(inode)->data);
  842. }
  843. static ssize_t
  844. acpi_thermal_write_polling (
  845. struct file *file,
  846. const char __user *buffer,
  847. size_t count,
  848. loff_t *ppos)
  849. {
  850. struct seq_file *m = (struct seq_file *)file->private_data;
  851. struct acpi_thermal *tz = (struct acpi_thermal *)m->private;
  852. int result = 0;
  853. char polling_string[12] = {'\0'};
  854. int seconds = 0;
  855. ACPI_FUNCTION_TRACE("acpi_thermal_write_polling");
  856. if (!tz || (count > sizeof(polling_string) - 1))
  857. return_VALUE(-EINVAL);
  858. if (copy_from_user(polling_string, buffer, count))
  859. return_VALUE(-EFAULT);
  860. polling_string[count] = '\0';
  861. seconds = simple_strtoul(polling_string, NULL, 0);
  862. result = acpi_thermal_set_polling(tz, seconds);
  863. if (result)
  864. return_VALUE(result);
  865. acpi_thermal_check(tz);
  866. return_VALUE(count);
  867. }
  868. static int
  869. acpi_thermal_add_fs (
  870. struct acpi_device *device)
  871. {
  872. struct proc_dir_entry *entry = NULL;
  873. ACPI_FUNCTION_TRACE("acpi_thermal_add_fs");
  874. if (!acpi_device_dir(device)) {
  875. acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
  876. acpi_thermal_dir);
  877. if (!acpi_device_dir(device))
  878. return_VALUE(-ENODEV);
  879. acpi_device_dir(device)->owner = THIS_MODULE;
  880. }
  881. /* 'state' [R] */
  882. entry = create_proc_entry(ACPI_THERMAL_FILE_STATE,
  883. S_IRUGO, acpi_device_dir(device));
  884. if (!entry)
  885. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  886. "Unable to create '%s' fs entry\n",
  887. ACPI_THERMAL_FILE_STATE));
  888. else {
  889. entry->proc_fops = &acpi_thermal_state_fops;
  890. entry->data = acpi_driver_data(device);
  891. entry->owner = THIS_MODULE;
  892. }
  893. /* 'temperature' [R] */
  894. entry = create_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
  895. S_IRUGO, acpi_device_dir(device));
  896. if (!entry)
  897. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  898. "Unable to create '%s' fs entry\n",
  899. ACPI_THERMAL_FILE_TEMPERATURE));
  900. else {
  901. entry->proc_fops = &acpi_thermal_temp_fops;
  902. entry->data = acpi_driver_data(device);
  903. entry->owner = THIS_MODULE;
  904. }
  905. /* 'trip_points' [R/W] */
  906. entry = create_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
  907. S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
  908. if (!entry)
  909. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  910. "Unable to create '%s' fs entry\n",
  911. ACPI_THERMAL_FILE_TRIP_POINTS));
  912. else {
  913. entry->proc_fops = &acpi_thermal_trip_fops;
  914. entry->data = acpi_driver_data(device);
  915. entry->owner = THIS_MODULE;
  916. }
  917. /* 'cooling_mode' [R/W] */
  918. entry = create_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
  919. S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
  920. if (!entry)
  921. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  922. "Unable to create '%s' fs entry\n",
  923. ACPI_THERMAL_FILE_COOLING_MODE));
  924. else {
  925. entry->proc_fops = &acpi_thermal_cooling_fops;
  926. entry->data = acpi_driver_data(device);
  927. entry->owner = THIS_MODULE;
  928. }
  929. /* 'polling_frequency' [R/W] */
  930. entry = create_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
  931. S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
  932. if (!entry)
  933. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  934. "Unable to create '%s' fs entry\n",
  935. ACPI_THERMAL_FILE_POLLING_FREQ));
  936. else {
  937. entry->proc_fops = &acpi_thermal_polling_fops;
  938. entry->data = acpi_driver_data(device);
  939. entry->owner = THIS_MODULE;
  940. }
  941. return_VALUE(0);
  942. }
  943. static int
  944. acpi_thermal_remove_fs (
  945. struct acpi_device *device)
  946. {
  947. ACPI_FUNCTION_TRACE("acpi_thermal_remove_fs");
  948. if (acpi_device_dir(device)) {
  949. remove_proc_entry(ACPI_THERMAL_FILE_POLLING_FREQ,
  950. acpi_device_dir(device));
  951. remove_proc_entry(ACPI_THERMAL_FILE_COOLING_MODE,
  952. acpi_device_dir(device));
  953. remove_proc_entry(ACPI_THERMAL_FILE_TRIP_POINTS,
  954. acpi_device_dir(device));
  955. remove_proc_entry(ACPI_THERMAL_FILE_TEMPERATURE,
  956. acpi_device_dir(device));
  957. remove_proc_entry(ACPI_THERMAL_FILE_STATE,
  958. acpi_device_dir(device));
  959. remove_proc_entry(acpi_device_bid(device), acpi_thermal_dir);
  960. acpi_device_dir(device) = NULL;
  961. }
  962. return_VALUE(0);
  963. }
  964. /* --------------------------------------------------------------------------
  965. Driver Interface
  966. -------------------------------------------------------------------------- */
  967. static void
  968. acpi_thermal_notify (
  969. acpi_handle handle,
  970. u32 event,
  971. void *data)
  972. {
  973. struct acpi_thermal *tz = (struct acpi_thermal *) data;
  974. struct acpi_device *device = NULL;
  975. ACPI_FUNCTION_TRACE("acpi_thermal_notify");
  976. if (!tz)
  977. return_VOID;
  978. if (acpi_bus_get_device(tz->handle, &device))
  979. return_VOID;
  980. switch (event) {
  981. case ACPI_THERMAL_NOTIFY_TEMPERATURE:
  982. acpi_thermal_check(tz);
  983. break;
  984. case ACPI_THERMAL_NOTIFY_THRESHOLDS:
  985. acpi_thermal_get_trip_points(tz);
  986. acpi_thermal_check(tz);
  987. acpi_bus_generate_event(device, event, 0);
  988. break;
  989. case ACPI_THERMAL_NOTIFY_DEVICES:
  990. if (tz->flags.devices)
  991. acpi_thermal_get_devices(tz);
  992. acpi_bus_generate_event(device, event, 0);
  993. break;
  994. default:
  995. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  996. "Unsupported event [0x%x]\n", event));
  997. break;
  998. }
  999. return_VOID;
  1000. }
  1001. static int
  1002. acpi_thermal_get_info (
  1003. struct acpi_thermal *tz)
  1004. {
  1005. int result = 0;
  1006. ACPI_FUNCTION_TRACE("acpi_thermal_get_info");
  1007. if (!tz)
  1008. return_VALUE(-EINVAL);
  1009. /* Get temperature [_TMP] (required) */
  1010. result = acpi_thermal_get_temperature(tz);
  1011. if (result)
  1012. return_VALUE(result);
  1013. /* Get trip points [_CRT, _PSV, etc.] (required) */
  1014. result = acpi_thermal_get_trip_points(tz);
  1015. if (result)
  1016. return_VALUE(result);
  1017. /* Set the cooling mode [_SCP] to active cooling (default) */
  1018. result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
  1019. if (!result)
  1020. tz->flags.cooling_mode = 1;
  1021. else {
  1022. /* Oh,we have not _SCP method.
  1023. Generally show cooling_mode by _ACx, _PSV,spec 12.2*/
  1024. tz->flags.cooling_mode = 0;
  1025. if ( tz->trips.active[0].flags.valid && tz->trips.passive.flags.valid ) {
  1026. if ( tz->trips.passive.temperature > tz->trips.active[0].temperature )
  1027. tz->cooling_mode = ACPI_THERMAL_MODE_ACTIVE;
  1028. else
  1029. tz->cooling_mode = ACPI_THERMAL_MODE_PASSIVE;
  1030. } else if ( !tz->trips.active[0].flags.valid && tz->trips.passive.flags.valid ) {
  1031. tz->cooling_mode = ACPI_THERMAL_MODE_PASSIVE;
  1032. } else if ( tz->trips.active[0].flags.valid && !tz->trips.passive.flags.valid ) {
  1033. tz->cooling_mode = ACPI_THERMAL_MODE_ACTIVE;
  1034. } else {
  1035. /* _ACx and _PSV are optional, but _CRT is required */
  1036. tz->cooling_mode = ACPI_THERMAL_MODE_CRITICAL;
  1037. }
  1038. }
  1039. /* Get default polling frequency [_TZP] (optional) */
  1040. if (tzp)
  1041. tz->polling_frequency = tzp;
  1042. else
  1043. acpi_thermal_get_polling_frequency(tz);
  1044. /* Get devices in this thermal zone [_TZD] (optional) */
  1045. result = acpi_thermal_get_devices(tz);
  1046. if (!result)
  1047. tz->flags.devices = 1;
  1048. return_VALUE(0);
  1049. }
  1050. static int
  1051. acpi_thermal_add (
  1052. struct acpi_device *device)
  1053. {
  1054. int result = 0;
  1055. acpi_status status = AE_OK;
  1056. struct acpi_thermal *tz = NULL;
  1057. ACPI_FUNCTION_TRACE("acpi_thermal_add");
  1058. if (!device)
  1059. return_VALUE(-EINVAL);
  1060. tz = kmalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
  1061. if (!tz)
  1062. return_VALUE(-ENOMEM);
  1063. memset(tz, 0, sizeof(struct acpi_thermal));
  1064. tz->handle = device->handle;
  1065. strcpy(tz->name, device->pnp.bus_id);
  1066. strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
  1067. strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS);
  1068. acpi_driver_data(device) = tz;
  1069. result = acpi_thermal_get_info(tz);
  1070. if (result)
  1071. goto end;
  1072. result = acpi_thermal_add_fs(device);
  1073. if (result)
  1074. return_VALUE(result);
  1075. init_timer(&tz->timer);
  1076. acpi_thermal_check(tz);
  1077. status = acpi_install_notify_handler(tz->handle,
  1078. ACPI_DEVICE_NOTIFY, acpi_thermal_notify, tz);
  1079. if (ACPI_FAILURE(status)) {
  1080. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  1081. "Error installing notify handler\n"));
  1082. result = -ENODEV;
  1083. goto end;
  1084. }
  1085. printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n",
  1086. acpi_device_name(device), acpi_device_bid(device),
  1087. KELVIN_TO_CELSIUS(tz->temperature));
  1088. end:
  1089. if (result) {
  1090. acpi_thermal_remove_fs(device);
  1091. kfree(tz);
  1092. }
  1093. return_VALUE(result);
  1094. }
  1095. static int
  1096. acpi_thermal_remove (
  1097. struct acpi_device *device,
  1098. int type)
  1099. {
  1100. acpi_status status = AE_OK;
  1101. struct acpi_thermal *tz = NULL;
  1102. ACPI_FUNCTION_TRACE("acpi_thermal_remove");
  1103. if (!device || !acpi_driver_data(device))
  1104. return_VALUE(-EINVAL);
  1105. tz = (struct acpi_thermal *) acpi_driver_data(device);
  1106. /* avoid timer adding new defer task */
  1107. tz->zombie = 1;
  1108. /* wait for running timer (on other CPUs) finish */
  1109. del_timer_sync(&(tz->timer));
  1110. /* synchronize deferred task */
  1111. acpi_os_wait_events_complete(NULL);
  1112. /* deferred task may reinsert timer */
  1113. del_timer_sync(&(tz->timer));
  1114. status = acpi_remove_notify_handler(tz->handle,
  1115. ACPI_DEVICE_NOTIFY, acpi_thermal_notify);
  1116. if (ACPI_FAILURE(status))
  1117. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  1118. "Error removing notify handler\n"));
  1119. /* Terminate policy */
  1120. if (tz->trips.passive.flags.valid
  1121. && tz->trips.passive.flags.enabled) {
  1122. tz->trips.passive.flags.enabled = 0;
  1123. acpi_thermal_passive(tz);
  1124. }
  1125. if (tz->trips.active[0].flags.valid
  1126. && tz->trips.active[0].flags.enabled) {
  1127. tz->trips.active[0].flags.enabled = 0;
  1128. acpi_thermal_active(tz);
  1129. }
  1130. acpi_thermal_remove_fs(device);
  1131. kfree(tz);
  1132. return_VALUE(0);
  1133. }
  1134. static int __init
  1135. acpi_thermal_init (void)
  1136. {
  1137. int result = 0;
  1138. ACPI_FUNCTION_TRACE("acpi_thermal_init");
  1139. acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
  1140. if (!acpi_thermal_dir)
  1141. return_VALUE(-ENODEV);
  1142. acpi_thermal_dir->owner = THIS_MODULE;
  1143. result = acpi_bus_register_driver(&acpi_thermal_driver);
  1144. if (result < 0) {
  1145. remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
  1146. return_VALUE(-ENODEV);
  1147. }
  1148. return_VALUE(0);
  1149. }
  1150. static void __exit
  1151. acpi_thermal_exit (void)
  1152. {
  1153. ACPI_FUNCTION_TRACE("acpi_thermal_exit");
  1154. acpi_bus_unregister_driver(&acpi_thermal_driver);
  1155. remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
  1156. return_VOID;
  1157. }
  1158. module_init(acpi_thermal_init);
  1159. module_exit(acpi_thermal_exit);