asus_acpi.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424
  1. /*
  2. * asus_acpi.c - Asus Laptop ACPI Extras
  3. *
  4. *
  5. * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. *
  22. * The development page for this driver is located at
  23. * http://sourceforge.net/projects/acpi4asus/
  24. *
  25. * Credits:
  26. * Pontus Fuchs - Helper functions, cleanup
  27. * Johann Wiesner - Small compile fixes
  28. * John Belmonte - ACPI code for Toshiba laptop was a good starting point.
  29. * �ic Burghard - LED display support for W1N
  30. *
  31. */
  32. #include <linux/kernel.h>
  33. #include <linux/module.h>
  34. #include <linux/init.h>
  35. #include <linux/types.h>
  36. #include <linux/proc_fs.h>
  37. #include <linux/backlight.h>
  38. #include <acpi/acpi_drivers.h>
  39. #include <acpi/acpi_bus.h>
  40. #include <asm/uaccess.h>
  41. #define ASUS_ACPI_VERSION "0.30"
  42. #define PROC_ASUS "asus" //the directory
  43. #define PROC_MLED "mled"
  44. #define PROC_WLED "wled"
  45. #define PROC_TLED "tled"
  46. #define PROC_BT "bluetooth"
  47. #define PROC_LEDD "ledd"
  48. #define PROC_INFO "info"
  49. #define PROC_LCD "lcd"
  50. #define PROC_BRN "brn"
  51. #define PROC_DISP "disp"
  52. #define ACPI_HOTK_NAME "Asus Laptop ACPI Extras Driver"
  53. #define ACPI_HOTK_CLASS "hotkey"
  54. #define ACPI_HOTK_DEVICE_NAME "Hotkey"
  55. /*
  56. * Some events we use, same for all Asus
  57. */
  58. #define BR_UP 0x10
  59. #define BR_DOWN 0x20
  60. /*
  61. * Flags for hotk status
  62. */
  63. #define MLED_ON 0x01 //mail LED
  64. #define WLED_ON 0x02 //wireless LED
  65. #define TLED_ON 0x04 //touchpad LED
  66. #define BT_ON 0x08 //internal Bluetooth
  67. MODULE_AUTHOR("Julien Lerouge, Karol Kozimor");
  68. MODULE_DESCRIPTION(ACPI_HOTK_NAME);
  69. MODULE_LICENSE("GPL");
  70. static uid_t asus_uid;
  71. static gid_t asus_gid;
  72. module_param(asus_uid, uint, 0);
  73. MODULE_PARM_DESC(asus_uid, "UID for entries in /proc/acpi/asus.\n");
  74. module_param(asus_gid, uint, 0);
  75. MODULE_PARM_DESC(asus_gid, "GID for entries in /proc/acpi/asus.\n");
  76. /* For each model, all features implemented,
  77. * those marked with R are relative to HOTK, A for absolute */
  78. struct model_data {
  79. char *name; //name of the laptop________________A
  80. char *mt_mled; //method to handle mled_____________R
  81. char *mled_status; //node to handle mled reading_______A
  82. char *mt_wled; //method to handle wled_____________R
  83. char *wled_status; //node to handle wled reading_______A
  84. char *mt_tled; //method to handle tled_____________R
  85. char *tled_status; //node to handle tled reading_______A
  86. char *mt_ledd; //method to handle LED display______R
  87. char *mt_bt_switch; //method to switch Bluetooth on/off_R
  88. char *bt_status; //no model currently supports this__?
  89. char *mt_lcd_switch; //method to turn LCD on/off_________A
  90. char *lcd_status; //node to read LCD panel state______A
  91. char *brightness_up; //method to set brightness up_______A
  92. char *brightness_down; //guess what ?______________________A
  93. char *brightness_set; //method to set absolute brightness_R
  94. char *brightness_get; //method to get absolute brightness_R
  95. char *brightness_status; //node to get brightness____________A
  96. char *display_set; //method to set video output________R
  97. char *display_get; //method to get video output________R
  98. };
  99. /*
  100. * This is the main structure, we can use it to store anything interesting
  101. * about the hotk device
  102. */
  103. struct asus_hotk {
  104. struct acpi_device *device; //the device we are in
  105. acpi_handle handle; //the handle of the hotk device
  106. char status; //status of the hotk, for LEDs, ...
  107. u32 ledd_status; //status of the LED display
  108. struct model_data *methods; //methods available on the laptop
  109. u8 brightness; //brightness level
  110. enum {
  111. A1x = 0, //A1340D, A1300F
  112. A2x, //A2500H
  113. A4G, //A4700G
  114. D1x, //D1
  115. L2D, //L2000D
  116. L3C, //L3800C
  117. L3D, //L3400D
  118. L3H, //L3H, L2000E, L5D
  119. L4R, //L4500R
  120. L5x, //L5800C
  121. L8L, //L8400L
  122. M1A, //M1300A
  123. M2E, //M2400E, L4400L
  124. M6N, //M6800N, W3400N
  125. M6R, //M6700R, A3000G
  126. P30, //Samsung P30
  127. S1x, //S1300A, but also L1400B and M2400A (L84F)
  128. S2x, //S200 (J1 reported), Victor MP-XP7210
  129. W1N, //W1000N
  130. W5A, //W5A
  131. W3V, //W3030V
  132. xxN, //M2400N, M3700N, M5200N, M6800N, S1300N, S5200N
  133. A4S, //Z81sp
  134. //(Centrino)
  135. END_MODEL
  136. } model; //Models currently supported
  137. u16 event_count[128]; //count for each event TODO make this better
  138. };
  139. /* Here we go */
  140. #define A1x_PREFIX "\\_SB.PCI0.ISA.EC0."
  141. #define L3C_PREFIX "\\_SB.PCI0.PX40.ECD0."
  142. #define M1A_PREFIX "\\_SB.PCI0.PX40.EC0."
  143. #define P30_PREFIX "\\_SB.PCI0.LPCB.EC0."
  144. #define S1x_PREFIX "\\_SB.PCI0.PX40."
  145. #define S2x_PREFIX A1x_PREFIX
  146. #define xxN_PREFIX "\\_SB.PCI0.SBRG.EC0."
  147. static struct model_data model_conf[END_MODEL] = {
  148. /*
  149. * TODO I have seen a SWBX and AIBX method on some models, like L1400B,
  150. * it seems to be a kind of switch, but what for ?
  151. */
  152. {
  153. .name = "A1x",
  154. .mt_mled = "MLED",
  155. .mled_status = "\\MAIL",
  156. .mt_lcd_switch = A1x_PREFIX "_Q10",
  157. .lcd_status = "\\BKLI",
  158. .brightness_up = A1x_PREFIX "_Q0E",
  159. .brightness_down = A1x_PREFIX "_Q0F"},
  160. {
  161. .name = "A2x",
  162. .mt_mled = "MLED",
  163. .mt_wled = "WLED",
  164. .wled_status = "\\SG66",
  165. .mt_lcd_switch = "\\Q10",
  166. .lcd_status = "\\BAOF",
  167. .brightness_set = "SPLV",
  168. .brightness_get = "GPLV",
  169. .display_set = "SDSP",
  170. .display_get = "\\INFB"},
  171. {
  172. .name = "A4G",
  173. .mt_mled = "MLED",
  174. /* WLED present, but not controlled by ACPI */
  175. .mt_lcd_switch = xxN_PREFIX "_Q10",
  176. .brightness_set = "SPLV",
  177. .brightness_get = "GPLV",
  178. .display_set = "SDSP",
  179. .display_get = "\\ADVG"},
  180. {
  181. .name = "D1x",
  182. .mt_mled = "MLED",
  183. .mt_lcd_switch = "\\Q0D",
  184. .lcd_status = "\\GP11",
  185. .brightness_up = "\\Q0C",
  186. .brightness_down = "\\Q0B",
  187. .brightness_status = "\\BLVL",
  188. .display_set = "SDSP",
  189. .display_get = "\\INFB"},
  190. {
  191. .name = "L2D",
  192. .mt_mled = "MLED",
  193. .mled_status = "\\SGP6",
  194. .mt_wled = "WLED",
  195. .wled_status = "\\RCP3",
  196. .mt_lcd_switch = "\\Q10",
  197. .lcd_status = "\\SGP0",
  198. .brightness_up = "\\Q0E",
  199. .brightness_down = "\\Q0F",
  200. .display_set = "SDSP",
  201. .display_get = "\\INFB"},
  202. {
  203. .name = "L3C",
  204. .mt_mled = "MLED",
  205. .mt_wled = "WLED",
  206. .mt_lcd_switch = L3C_PREFIX "_Q10",
  207. .lcd_status = "\\GL32",
  208. .brightness_set = "SPLV",
  209. .brightness_get = "GPLV",
  210. .display_set = "SDSP",
  211. .display_get = "\\_SB.PCI0.PCI1.VGAC.NMAP"},
  212. {
  213. .name = "L3D",
  214. .mt_mled = "MLED",
  215. .mled_status = "\\MALD",
  216. .mt_wled = "WLED",
  217. .mt_lcd_switch = "\\Q10",
  218. .lcd_status = "\\BKLG",
  219. .brightness_set = "SPLV",
  220. .brightness_get = "GPLV",
  221. .display_set = "SDSP",
  222. .display_get = "\\INFB"},
  223. {
  224. .name = "L3H",
  225. .mt_mled = "MLED",
  226. .mt_wled = "WLED",
  227. .mt_lcd_switch = "EHK",
  228. .lcd_status = "\\_SB.PCI0.PM.PBC",
  229. .brightness_set = "SPLV",
  230. .brightness_get = "GPLV",
  231. .display_set = "SDSP",
  232. .display_get = "\\INFB"},
  233. {
  234. .name = "L4R",
  235. .mt_mled = "MLED",
  236. .mt_wled = "WLED",
  237. .wled_status = "\\_SB.PCI0.SBRG.SG13",
  238. .mt_lcd_switch = xxN_PREFIX "_Q10",
  239. .lcd_status = "\\_SB.PCI0.SBSM.SEO4",
  240. .brightness_set = "SPLV",
  241. .brightness_get = "GPLV",
  242. .display_set = "SDSP",
  243. .display_get = "\\_SB.PCI0.P0P1.VGA.GETD"},
  244. {
  245. .name = "L5x",
  246. .mt_mled = "MLED",
  247. /* WLED present, but not controlled by ACPI */
  248. .mt_tled = "TLED",
  249. .mt_lcd_switch = "\\Q0D",
  250. .lcd_status = "\\BAOF",
  251. .brightness_set = "SPLV",
  252. .brightness_get = "GPLV",
  253. .display_set = "SDSP",
  254. .display_get = "\\INFB"},
  255. {
  256. .name = "L8L"
  257. /* No features, but at least support the hotkeys */
  258. },
  259. {
  260. .name = "M1A",
  261. .mt_mled = "MLED",
  262. .mt_lcd_switch = M1A_PREFIX "Q10",
  263. .lcd_status = "\\PNOF",
  264. .brightness_up = M1A_PREFIX "Q0E",
  265. .brightness_down = M1A_PREFIX "Q0F",
  266. .brightness_status = "\\BRIT",
  267. .display_set = "SDSP",
  268. .display_get = "\\INFB"},
  269. {
  270. .name = "M2E",
  271. .mt_mled = "MLED",
  272. .mt_wled = "WLED",
  273. .mt_lcd_switch = "\\Q10",
  274. .lcd_status = "\\GP06",
  275. .brightness_set = "SPLV",
  276. .brightness_get = "GPLV",
  277. .display_set = "SDSP",
  278. .display_get = "\\INFB"},
  279. {
  280. .name = "M6N",
  281. .mt_mled = "MLED",
  282. .mt_wled = "WLED",
  283. .wled_status = "\\_SB.PCI0.SBRG.SG13",
  284. .mt_lcd_switch = xxN_PREFIX "_Q10",
  285. .lcd_status = "\\_SB.BKLT",
  286. .brightness_set = "SPLV",
  287. .brightness_get = "GPLV",
  288. .display_set = "SDSP",
  289. .display_get = "\\SSTE"},
  290. {
  291. .name = "M6R",
  292. .mt_mled = "MLED",
  293. .mt_wled = "WLED",
  294. .mt_lcd_switch = xxN_PREFIX "_Q10",
  295. .lcd_status = "\\_SB.PCI0.SBSM.SEO4",
  296. .brightness_set = "SPLV",
  297. .brightness_get = "GPLV",
  298. .display_set = "SDSP",
  299. .display_get = "\\_SB.PCI0.P0P1.VGA.GETD"},
  300. {
  301. .name = "P30",
  302. .mt_wled = "WLED",
  303. .mt_lcd_switch = P30_PREFIX "_Q0E",
  304. .lcd_status = "\\BKLT",
  305. .brightness_up = P30_PREFIX "_Q68",
  306. .brightness_down = P30_PREFIX "_Q69",
  307. .brightness_get = "GPLV",
  308. .display_set = "SDSP",
  309. .display_get = "\\DNXT"},
  310. {
  311. .name = "S1x",
  312. .mt_mled = "MLED",
  313. .mled_status = "\\EMLE",
  314. .mt_wled = "WLED",
  315. .mt_lcd_switch = S1x_PREFIX "Q10",
  316. .lcd_status = "\\PNOF",
  317. .brightness_set = "SPLV",
  318. .brightness_get = "GPLV"},
  319. {
  320. .name = "S2x",
  321. .mt_mled = "MLED",
  322. .mled_status = "\\MAIL",
  323. .mt_lcd_switch = S2x_PREFIX "_Q10",
  324. .lcd_status = "\\BKLI",
  325. .brightness_up = S2x_PREFIX "_Q0B",
  326. .brightness_down = S2x_PREFIX "_Q0A"},
  327. {
  328. .name = "W1N",
  329. .mt_mled = "MLED",
  330. .mt_wled = "WLED",
  331. .mt_ledd = "SLCM",
  332. .mt_lcd_switch = xxN_PREFIX "_Q10",
  333. .lcd_status = "\\BKLT",
  334. .brightness_set = "SPLV",
  335. .brightness_get = "GPLV",
  336. .display_set = "SDSP",
  337. .display_get = "\\ADVG"},
  338. {
  339. .name = "W5A",
  340. .mt_bt_switch = "BLED",
  341. .mt_wled = "WLED",
  342. .mt_lcd_switch = xxN_PREFIX "_Q10",
  343. .brightness_set = "SPLV",
  344. .brightness_get = "GPLV",
  345. .display_set = "SDSP",
  346. .display_get = "\\ADVG"},
  347. {
  348. .name = "W3V",
  349. .mt_mled = "MLED",
  350. .mt_wled = "WLED",
  351. .mt_lcd_switch = xxN_PREFIX "_Q10",
  352. .lcd_status = "\\BKLT",
  353. .brightness_set = "SPLV",
  354. .brightness_get = "GPLV",
  355. .display_set = "SDSP",
  356. .display_get = "\\INFB"},
  357. {
  358. .name = "xxN",
  359. .mt_mled = "MLED",
  360. /* WLED present, but not controlled by ACPI */
  361. .mt_lcd_switch = xxN_PREFIX "_Q10",
  362. .lcd_status = "\\BKLT",
  363. .brightness_set = "SPLV",
  364. .brightness_get = "GPLV",
  365. .display_set = "SDSP",
  366. .display_get = "\\ADVG"},
  367. {
  368. .name = "A4S",
  369. .brightness_set = "SPLV",
  370. .brightness_get = "GPLV",
  371. .mt_bt_switch = "BLED",
  372. .mt_wled = "WLED"
  373. }
  374. };
  375. /* procdir we use */
  376. static struct proc_dir_entry *asus_proc_dir;
  377. static struct backlight_device *asus_backlight_device;
  378. /*
  379. * This header is made available to allow proper configuration given model,
  380. * revision number , ... this info cannot go in struct asus_hotk because it is
  381. * available before the hotk
  382. */
  383. static struct acpi_table_header *asus_info;
  384. /* The actual device the driver binds to */
  385. static struct asus_hotk *hotk;
  386. /*
  387. * The hotkey driver and autoloading declaration
  388. */
  389. static int asus_hotk_add(struct acpi_device *device);
  390. static int asus_hotk_remove(struct acpi_device *device, int type);
  391. static const struct acpi_device_id asus_device_ids[] = {
  392. {"ATK0100", 0},
  393. {"", 0},
  394. };
  395. MODULE_DEVICE_TABLE(acpi, asus_device_ids);
  396. static struct acpi_driver asus_hotk_driver = {
  397. .name = "asus_acpi",
  398. .class = ACPI_HOTK_CLASS,
  399. .ids = asus_device_ids,
  400. .ops = {
  401. .add = asus_hotk_add,
  402. .remove = asus_hotk_remove,
  403. },
  404. };
  405. /*
  406. * This function evaluates an ACPI method, given an int as parameter, the
  407. * method is searched within the scope of the handle, can be NULL. The output
  408. * of the method is written is output, which can also be NULL
  409. *
  410. * returns 1 if write is successful, 0 else.
  411. */
  412. static int write_acpi_int(acpi_handle handle, const char *method, int val,
  413. struct acpi_buffer *output)
  414. {
  415. struct acpi_object_list params; //list of input parameters (an int here)
  416. union acpi_object in_obj; //the only param we use
  417. acpi_status status;
  418. params.count = 1;
  419. params.pointer = &in_obj;
  420. in_obj.type = ACPI_TYPE_INTEGER;
  421. in_obj.integer.value = val;
  422. status = acpi_evaluate_object(handle, (char *)method, &params, output);
  423. return (status == AE_OK);
  424. }
  425. static int read_acpi_int(acpi_handle handle, const char *method, int *val)
  426. {
  427. struct acpi_buffer output;
  428. union acpi_object out_obj;
  429. acpi_status status;
  430. output.length = sizeof(out_obj);
  431. output.pointer = &out_obj;
  432. status = acpi_evaluate_object(handle, (char *)method, NULL, &output);
  433. *val = out_obj.integer.value;
  434. return (status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER);
  435. }
  436. /*
  437. * We write our info in page, we begin at offset off and cannot write more
  438. * than count bytes. We set eof to 1 if we handle those 2 values. We return the
  439. * number of bytes written in page
  440. */
  441. static int
  442. proc_read_info(char *page, char **start, off_t off, int count, int *eof,
  443. void *data)
  444. {
  445. int len = 0;
  446. int temp;
  447. char buf[16]; //enough for all info
  448. /*
  449. * We use the easy way, we don't care of off and count, so we don't set eof
  450. * to 1
  451. */
  452. len += sprintf(page, ACPI_HOTK_NAME " " ASUS_ACPI_VERSION "\n");
  453. len += sprintf(page + len, "Model reference : %s\n",
  454. hotk->methods->name);
  455. /*
  456. * The SFUN method probably allows the original driver to get the list
  457. * of features supported by a given model. For now, 0x0100 or 0x0800
  458. * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
  459. * The significance of others is yet to be found.
  460. */
  461. if (read_acpi_int(hotk->handle, "SFUN", &temp))
  462. len +=
  463. sprintf(page + len, "SFUN value : 0x%04x\n", temp);
  464. /*
  465. * Another value for userspace: the ASYM method returns 0x02 for
  466. * battery low and 0x04 for battery critical, its readings tend to be
  467. * more accurate than those provided by _BST.
  468. * Note: since not all the laptops provide this method, errors are
  469. * silently ignored.
  470. */
  471. if (read_acpi_int(hotk->handle, "ASYM", &temp))
  472. len +=
  473. sprintf(page + len, "ASYM value : 0x%04x\n", temp);
  474. if (asus_info) {
  475. snprintf(buf, 16, "%d", asus_info->length);
  476. len += sprintf(page + len, "DSDT length : %s\n", buf);
  477. snprintf(buf, 16, "%d", asus_info->checksum);
  478. len += sprintf(page + len, "DSDT checksum : %s\n", buf);
  479. snprintf(buf, 16, "%d", asus_info->revision);
  480. len += sprintf(page + len, "DSDT revision : %s\n", buf);
  481. snprintf(buf, 7, "%s", asus_info->oem_id);
  482. len += sprintf(page + len, "OEM id : %s\n", buf);
  483. snprintf(buf, 9, "%s", asus_info->oem_table_id);
  484. len += sprintf(page + len, "OEM table id : %s\n", buf);
  485. snprintf(buf, 16, "%x", asus_info->oem_revision);
  486. len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
  487. snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
  488. len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
  489. snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
  490. len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
  491. }
  492. return len;
  493. }
  494. /*
  495. * /proc handlers
  496. * We write our info in page, we begin at offset off and cannot write more
  497. * than count bytes. We set eof to 1 if we handle those 2 values. We return the
  498. * number of bytes written in page
  499. */
  500. /* Generic LED functions */
  501. static int read_led(const char *ledname, int ledmask)
  502. {
  503. if (ledname) {
  504. int led_status;
  505. if (read_acpi_int(NULL, ledname, &led_status))
  506. return led_status;
  507. else
  508. printk(KERN_WARNING "Asus ACPI: Error reading LED "
  509. "status\n");
  510. }
  511. return (hotk->status & ledmask) ? 1 : 0;
  512. }
  513. static int parse_arg(const char __user * buf, unsigned long count, int *val)
  514. {
  515. char s[32];
  516. if (!count)
  517. return 0;
  518. if (count > 31)
  519. return -EINVAL;
  520. if (copy_from_user(s, buf, count))
  521. return -EFAULT;
  522. s[count] = 0;
  523. if (sscanf(s, "%i", val) != 1)
  524. return -EINVAL;
  525. return count;
  526. }
  527. /* FIXME: kill extraneous args so it can be called independently */
  528. static int
  529. write_led(const char __user * buffer, unsigned long count,
  530. char *ledname, int ledmask, int invert)
  531. {
  532. int rv, value;
  533. int led_out = 0;
  534. rv = parse_arg(buffer, count, &value);
  535. if (rv > 0)
  536. led_out = value ? 1 : 0;
  537. hotk->status =
  538. (led_out) ? (hotk->status | ledmask) : (hotk->status & ~ledmask);
  539. if (invert) /* invert target value */
  540. led_out = !led_out & 0x1;
  541. if (!write_acpi_int(hotk->handle, ledname, led_out, NULL))
  542. printk(KERN_WARNING "Asus ACPI: LED (%s) write failed\n",
  543. ledname);
  544. return rv;
  545. }
  546. /*
  547. * Proc handlers for MLED
  548. */
  549. static int
  550. proc_read_mled(char *page, char **start, off_t off, int count, int *eof,
  551. void *data)
  552. {
  553. return sprintf(page, "%d\n",
  554. read_led(hotk->methods->mled_status, MLED_ON));
  555. }
  556. static int
  557. proc_write_mled(struct file *file, const char __user * buffer,
  558. unsigned long count, void *data)
  559. {
  560. return write_led(buffer, count, hotk->methods->mt_mled, MLED_ON, 1);
  561. }
  562. /*
  563. * Proc handlers for LED display
  564. */
  565. static int
  566. proc_read_ledd(char *page, char **start, off_t off, int count, int *eof,
  567. void *data)
  568. {
  569. return sprintf(page, "0x%08x\n", hotk->ledd_status);
  570. }
  571. static int
  572. proc_write_ledd(struct file *file, const char __user * buffer,
  573. unsigned long count, void *data)
  574. {
  575. int rv, value;
  576. rv = parse_arg(buffer, count, &value);
  577. if (rv > 0) {
  578. if (!write_acpi_int
  579. (hotk->handle, hotk->methods->mt_ledd, value, NULL))
  580. printk(KERN_WARNING
  581. "Asus ACPI: LED display write failed\n");
  582. else
  583. hotk->ledd_status = (u32) value;
  584. }
  585. return rv;
  586. }
  587. /*
  588. * Proc handlers for WLED
  589. */
  590. static int
  591. proc_read_wled(char *page, char **start, off_t off, int count, int *eof,
  592. void *data)
  593. {
  594. return sprintf(page, "%d\n",
  595. read_led(hotk->methods->wled_status, WLED_ON));
  596. }
  597. static int
  598. proc_write_wled(struct file *file, const char __user * buffer,
  599. unsigned long count, void *data)
  600. {
  601. return write_led(buffer, count, hotk->methods->mt_wled, WLED_ON, 0);
  602. }
  603. /*
  604. * Proc handlers for Bluetooth
  605. */
  606. static int
  607. proc_read_bluetooth(char *page, char **start, off_t off, int count, int *eof,
  608. void *data)
  609. {
  610. return sprintf(page, "%d\n", read_led(hotk->methods->bt_status, BT_ON));
  611. }
  612. static int
  613. proc_write_bluetooth(struct file *file, const char __user * buffer,
  614. unsigned long count, void *data)
  615. {
  616. /* Note: mt_bt_switch controls both internal Bluetooth adapter's
  617. presence and its LED */
  618. return write_led(buffer, count, hotk->methods->mt_bt_switch, BT_ON, 0);
  619. }
  620. /*
  621. * Proc handlers for TLED
  622. */
  623. static int
  624. proc_read_tled(char *page, char **start, off_t off, int count, int *eof,
  625. void *data)
  626. {
  627. return sprintf(page, "%d\n",
  628. read_led(hotk->methods->tled_status, TLED_ON));
  629. }
  630. static int
  631. proc_write_tled(struct file *file, const char __user * buffer,
  632. unsigned long count, void *data)
  633. {
  634. return write_led(buffer, count, hotk->methods->mt_tled, TLED_ON, 0);
  635. }
  636. static int get_lcd_state(void)
  637. {
  638. int lcd = 0;
  639. if (hotk->model != L3H) {
  640. /* We don't have to check anything if we are here */
  641. if (!read_acpi_int(NULL, hotk->methods->lcd_status, &lcd))
  642. printk(KERN_WARNING
  643. "Asus ACPI: Error reading LCD status\n");
  644. if (hotk->model == L2D)
  645. lcd = ~lcd;
  646. } else { /* L3H and the like have to be handled differently */
  647. acpi_status status = 0;
  648. struct acpi_object_list input;
  649. union acpi_object mt_params[2];
  650. struct acpi_buffer output;
  651. union acpi_object out_obj;
  652. input.count = 2;
  653. input.pointer = mt_params;
  654. /* Note: the following values are partly guessed up, but
  655. otherwise they seem to work */
  656. mt_params[0].type = ACPI_TYPE_INTEGER;
  657. mt_params[0].integer.value = 0x02;
  658. mt_params[1].type = ACPI_TYPE_INTEGER;
  659. mt_params[1].integer.value = 0x02;
  660. output.length = sizeof(out_obj);
  661. output.pointer = &out_obj;
  662. status =
  663. acpi_evaluate_object(NULL, hotk->methods->lcd_status,
  664. &input, &output);
  665. if (status != AE_OK)
  666. return -1;
  667. if (out_obj.type == ACPI_TYPE_INTEGER)
  668. /* That's what the AML code does */
  669. lcd = out_obj.integer.value >> 8;
  670. }
  671. return (lcd & 1);
  672. }
  673. static int set_lcd_state(int value)
  674. {
  675. int lcd = 0;
  676. acpi_status status = 0;
  677. lcd = value ? 1 : 0;
  678. if (lcd != get_lcd_state()) {
  679. /* switch */
  680. if (hotk->model != L3H) {
  681. status =
  682. acpi_evaluate_object(NULL,
  683. hotk->methods->mt_lcd_switch,
  684. NULL, NULL);
  685. } else { /* L3H and the like have to be handled differently */
  686. if (!write_acpi_int
  687. (hotk->handle, hotk->methods->mt_lcd_switch, 0x07,
  688. NULL))
  689. status = AE_ERROR;
  690. /* L3H's AML executes EHK (0x07) upon Fn+F7 keypress,
  691. the exact behaviour is simulated here */
  692. }
  693. if (ACPI_FAILURE(status))
  694. printk(KERN_WARNING "Asus ACPI: Error switching LCD\n");
  695. }
  696. return 0;
  697. }
  698. static int
  699. proc_read_lcd(char *page, char **start, off_t off, int count, int *eof,
  700. void *data)
  701. {
  702. return sprintf(page, "%d\n", get_lcd_state());
  703. }
  704. static int
  705. proc_write_lcd(struct file *file, const char __user * buffer,
  706. unsigned long count, void *data)
  707. {
  708. int rv, value;
  709. rv = parse_arg(buffer, count, &value);
  710. if (rv > 0)
  711. set_lcd_state(value);
  712. return rv;
  713. }
  714. static int read_brightness(struct backlight_device *bd)
  715. {
  716. int value;
  717. if (hotk->methods->brightness_get) { /* SPLV/GPLV laptop */
  718. if (!read_acpi_int(hotk->handle, hotk->methods->brightness_get,
  719. &value))
  720. printk(KERN_WARNING
  721. "Asus ACPI: Error reading brightness\n");
  722. } else if (hotk->methods->brightness_status) { /* For D1 for example */
  723. if (!read_acpi_int(NULL, hotk->methods->brightness_status,
  724. &value))
  725. printk(KERN_WARNING
  726. "Asus ACPI: Error reading brightness\n");
  727. } else /* No GPLV method */
  728. value = hotk->brightness;
  729. return value;
  730. }
  731. /*
  732. * Change the brightness level
  733. */
  734. static int set_brightness(int value)
  735. {
  736. acpi_status status = 0;
  737. int ret = 0;
  738. /* SPLV laptop */
  739. if (hotk->methods->brightness_set) {
  740. if (!write_acpi_int(hotk->handle, hotk->methods->brightness_set,
  741. value, NULL))
  742. printk(KERN_WARNING
  743. "Asus ACPI: Error changing brightness\n");
  744. ret = -EIO;
  745. goto out;
  746. }
  747. /* No SPLV method if we are here, act as appropriate */
  748. value -= read_brightness(NULL);
  749. while (value != 0) {
  750. status = acpi_evaluate_object(NULL, (value > 0) ?
  751. hotk->methods->brightness_up :
  752. hotk->methods->brightness_down,
  753. NULL, NULL);
  754. (value > 0) ? value-- : value++;
  755. if (ACPI_FAILURE(status))
  756. printk(KERN_WARNING
  757. "Asus ACPI: Error changing brightness\n");
  758. ret = -EIO;
  759. }
  760. out:
  761. return ret;
  762. }
  763. static int set_brightness_status(struct backlight_device *bd)
  764. {
  765. return set_brightness(bd->props.brightness);
  766. }
  767. static int
  768. proc_read_brn(char *page, char **start, off_t off, int count, int *eof,
  769. void *data)
  770. {
  771. return sprintf(page, "%d\n", read_brightness(NULL));
  772. }
  773. static int
  774. proc_write_brn(struct file *file, const char __user * buffer,
  775. unsigned long count, void *data)
  776. {
  777. int rv, value;
  778. rv = parse_arg(buffer, count, &value);
  779. if (rv > 0) {
  780. value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
  781. /* 0 <= value <= 15 */
  782. set_brightness(value);
  783. }
  784. return rv;
  785. }
  786. static void set_display(int value)
  787. {
  788. /* no sanity check needed for now */
  789. if (!write_acpi_int(hotk->handle, hotk->methods->display_set,
  790. value, NULL))
  791. printk(KERN_WARNING "Asus ACPI: Error setting display\n");
  792. return;
  793. }
  794. /*
  795. * Now, *this* one could be more user-friendly, but so far, no-one has
  796. * complained. The significance of bits is the same as in proc_write_disp()
  797. */
  798. static int
  799. proc_read_disp(char *page, char **start, off_t off, int count, int *eof,
  800. void *data)
  801. {
  802. int value = 0;
  803. if (!read_acpi_int(hotk->handle, hotk->methods->display_get, &value))
  804. printk(KERN_WARNING
  805. "Asus ACPI: Error reading display status\n");
  806. value &= 0x07; /* needed for some models, shouldn't hurt others */
  807. return sprintf(page, "%d\n", value);
  808. }
  809. /*
  810. * Experimental support for display switching. As of now: 1 should activate
  811. * the LCD output, 2 should do for CRT, and 4 for TV-Out. Any combination
  812. * (bitwise) of these will suffice. I never actually tested 3 displays hooked up
  813. * simultaneously, so be warned. See the acpi4asus README for more info.
  814. */
  815. static int
  816. proc_write_disp(struct file *file, const char __user * buffer,
  817. unsigned long count, void *data)
  818. {
  819. int rv, value;
  820. rv = parse_arg(buffer, count, &value);
  821. if (rv > 0)
  822. set_display(value);
  823. return rv;
  824. }
  825. typedef int (proc_readfunc) (char *page, char **start, off_t off, int count,
  826. int *eof, void *data);
  827. typedef int (proc_writefunc) (struct file * file, const char __user * buffer,
  828. unsigned long count, void *data);
  829. static int
  830. asus_proc_add(char *name, proc_writefunc * writefunc,
  831. proc_readfunc * readfunc, mode_t mode,
  832. struct acpi_device *device)
  833. {
  834. struct proc_dir_entry *proc =
  835. create_proc_entry(name, mode, acpi_device_dir(device));
  836. if (!proc) {
  837. printk(KERN_WARNING " Unable to create %s fs entry\n", name);
  838. return -1;
  839. }
  840. proc->write_proc = writefunc;
  841. proc->read_proc = readfunc;
  842. proc->data = acpi_driver_data(device);
  843. proc->owner = THIS_MODULE;
  844. proc->uid = asus_uid;
  845. proc->gid = asus_gid;
  846. return 0;
  847. }
  848. static int asus_hotk_add_fs(struct acpi_device *device)
  849. {
  850. struct proc_dir_entry *proc;
  851. mode_t mode;
  852. /*
  853. * If parameter uid or gid is not changed, keep the default setting for
  854. * our proc entries (-rw-rw-rw-) else, it means we care about security,
  855. * and then set to -rw-rw----
  856. */
  857. if ((asus_uid == 0) && (asus_gid == 0)) {
  858. mode = S_IFREG | S_IRUGO | S_IWUGO;
  859. } else {
  860. mode = S_IFREG | S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP;
  861. printk(KERN_WARNING " asus_uid and asus_gid parameters are "
  862. "deprecated, use chown and chmod instead!\n");
  863. }
  864. acpi_device_dir(device) = asus_proc_dir;
  865. if (!acpi_device_dir(device))
  866. return -ENODEV;
  867. proc = create_proc_entry(PROC_INFO, mode, acpi_device_dir(device));
  868. if (proc) {
  869. proc->read_proc = proc_read_info;
  870. proc->data = acpi_driver_data(device);
  871. proc->owner = THIS_MODULE;
  872. proc->uid = asus_uid;
  873. proc->gid = asus_gid;
  874. } else {
  875. printk(KERN_WARNING " Unable to create " PROC_INFO
  876. " fs entry\n");
  877. }
  878. if (hotk->methods->mt_wled) {
  879. asus_proc_add(PROC_WLED, &proc_write_wled, &proc_read_wled,
  880. mode, device);
  881. }
  882. if (hotk->methods->mt_ledd) {
  883. asus_proc_add(PROC_LEDD, &proc_write_ledd, &proc_read_ledd,
  884. mode, device);
  885. }
  886. if (hotk->methods->mt_mled) {
  887. asus_proc_add(PROC_MLED, &proc_write_mled, &proc_read_mled,
  888. mode, device);
  889. }
  890. if (hotk->methods->mt_tled) {
  891. asus_proc_add(PROC_TLED, &proc_write_tled, &proc_read_tled,
  892. mode, device);
  893. }
  894. if (hotk->methods->mt_bt_switch) {
  895. asus_proc_add(PROC_BT, &proc_write_bluetooth,
  896. &proc_read_bluetooth, mode, device);
  897. }
  898. /*
  899. * We need both read node and write method as LCD switch is also accessible
  900. * from keyboard
  901. */
  902. if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status) {
  903. asus_proc_add(PROC_LCD, &proc_write_lcd, &proc_read_lcd, mode,
  904. device);
  905. }
  906. if ((hotk->methods->brightness_up && hotk->methods->brightness_down) ||
  907. (hotk->methods->brightness_get && hotk->methods->brightness_set)) {
  908. asus_proc_add(PROC_BRN, &proc_write_brn, &proc_read_brn, mode,
  909. device);
  910. }
  911. if (hotk->methods->display_set) {
  912. asus_proc_add(PROC_DISP, &proc_write_disp, &proc_read_disp,
  913. mode, device);
  914. }
  915. return 0;
  916. }
  917. static int asus_hotk_remove_fs(struct acpi_device *device)
  918. {
  919. if (acpi_device_dir(device)) {
  920. remove_proc_entry(PROC_INFO, acpi_device_dir(device));
  921. if (hotk->methods->mt_wled)
  922. remove_proc_entry(PROC_WLED, acpi_device_dir(device));
  923. if (hotk->methods->mt_mled)
  924. remove_proc_entry(PROC_MLED, acpi_device_dir(device));
  925. if (hotk->methods->mt_tled)
  926. remove_proc_entry(PROC_TLED, acpi_device_dir(device));
  927. if (hotk->methods->mt_ledd)
  928. remove_proc_entry(PROC_LEDD, acpi_device_dir(device));
  929. if (hotk->methods->mt_bt_switch)
  930. remove_proc_entry(PROC_BT, acpi_device_dir(device));
  931. if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status)
  932. remove_proc_entry(PROC_LCD, acpi_device_dir(device));
  933. if ((hotk->methods->brightness_up
  934. && hotk->methods->brightness_down)
  935. || (hotk->methods->brightness_get
  936. && hotk->methods->brightness_set))
  937. remove_proc_entry(PROC_BRN, acpi_device_dir(device));
  938. if (hotk->methods->display_set)
  939. remove_proc_entry(PROC_DISP, acpi_device_dir(device));
  940. }
  941. return 0;
  942. }
  943. static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
  944. {
  945. /* TODO Find a better way to handle events count. */
  946. if (!hotk)
  947. return;
  948. if ((event & ~((u32) BR_UP)) < 16) {
  949. hotk->brightness = (event & ~((u32) BR_UP));
  950. } else if ((event & ~((u32) BR_DOWN)) < 16) {
  951. hotk->brightness = (event & ~((u32) BR_DOWN));
  952. }
  953. acpi_bus_generate_proc_event(hotk->device, event,
  954. hotk->event_count[event % 128]++);
  955. return;
  956. }
  957. /*
  958. * Match the model string to the list of supported models. Return END_MODEL if
  959. * no match or model is NULL.
  960. */
  961. static int asus_model_match(char *model)
  962. {
  963. if (model == NULL)
  964. return END_MODEL;
  965. if (strncmp(model, "L3D", 3) == 0)
  966. return L3D;
  967. else if (strncmp(model, "L2E", 3) == 0 ||
  968. strncmp(model, "L3H", 3) == 0 || strncmp(model, "L5D", 3) == 0)
  969. return L3H;
  970. else if (strncmp(model, "L3", 2) == 0 || strncmp(model, "L2B", 3) == 0)
  971. return L3C;
  972. else if (strncmp(model, "L8L", 3) == 0)
  973. return L8L;
  974. else if (strncmp(model, "L4R", 3) == 0)
  975. return L4R;
  976. else if (strncmp(model, "M6N", 3) == 0 || strncmp(model, "W3N", 3) == 0)
  977. return M6N;
  978. else if (strncmp(model, "M6R", 3) == 0 || strncmp(model, "A3G", 3) == 0)
  979. return M6R;
  980. else if (strncmp(model, "M2N", 3) == 0 ||
  981. strncmp(model, "M3N", 3) == 0 ||
  982. strncmp(model, "M5N", 3) == 0 ||
  983. strncmp(model, "M6N", 3) == 0 ||
  984. strncmp(model, "S1N", 3) == 0 ||
  985. strncmp(model, "S5N", 3) == 0 || strncmp(model, "W1N", 3) == 0)
  986. return xxN;
  987. else if (strncmp(model, "M1", 2) == 0)
  988. return M1A;
  989. else if (strncmp(model, "M2", 2) == 0 || strncmp(model, "L4E", 3) == 0)
  990. return M2E;
  991. else if (strncmp(model, "L2", 2) == 0)
  992. return L2D;
  993. else if (strncmp(model, "L8", 2) == 0)
  994. return S1x;
  995. else if (strncmp(model, "D1", 2) == 0)
  996. return D1x;
  997. else if (strncmp(model, "A1", 2) == 0)
  998. return A1x;
  999. else if (strncmp(model, "A2", 2) == 0)
  1000. return A2x;
  1001. else if (strncmp(model, "J1", 2) == 0)
  1002. return S2x;
  1003. else if (strncmp(model, "L5", 2) == 0)
  1004. return L5x;
  1005. else if (strncmp(model, "A4G", 3) == 0)
  1006. return A4G;
  1007. else if (strncmp(model, "W1N", 3) == 0)
  1008. return W1N;
  1009. else if (strncmp(model, "W3V", 3) == 0)
  1010. return W3V;
  1011. else if (strncmp(model, "W5A", 3) == 0)
  1012. return W5A;
  1013. else if (strncmp(model, "A4S", 3) == 0)
  1014. return A4S;
  1015. else
  1016. return END_MODEL;
  1017. }
  1018. /*
  1019. * This function is used to initialize the hotk with right values. In this
  1020. * method, we can make all the detection we want, and modify the hotk struct
  1021. */
  1022. static int asus_hotk_get_info(void)
  1023. {
  1024. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  1025. union acpi_object *model = NULL;
  1026. int bsts_result;
  1027. char *string = NULL;
  1028. acpi_status status;
  1029. /*
  1030. * Get DSDT headers early enough to allow for differentiating between
  1031. * models, but late enough to allow acpi_bus_register_driver() to fail
  1032. * before doing anything ACPI-specific. Should we encounter a machine,
  1033. * which needs special handling (i.e. its hotkey device has a different
  1034. * HID), this bit will be moved. A global variable asus_info contains
  1035. * the DSDT header.
  1036. */
  1037. status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
  1038. if (ACPI_FAILURE(status))
  1039. printk(KERN_WARNING " Couldn't get the DSDT table header\n");
  1040. /* We have to write 0 on init this far for all ASUS models */
  1041. if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
  1042. printk(KERN_ERR " Hotkey initialization failed\n");
  1043. return -ENODEV;
  1044. }
  1045. /* This needs to be called for some laptops to init properly */
  1046. if (!read_acpi_int(hotk->handle, "BSTS", &bsts_result))
  1047. printk(KERN_WARNING " Error calling BSTS\n");
  1048. else if (bsts_result)
  1049. printk(KERN_NOTICE " BSTS called, 0x%02x returned\n",
  1050. bsts_result);
  1051. /*
  1052. * Try to match the object returned by INIT to the specific model.
  1053. * Handle every possible object (or the lack of thereof) the DSDT
  1054. * writers might throw at us. When in trouble, we pass NULL to
  1055. * asus_model_match() and try something completely different.
  1056. */
  1057. if (buffer.pointer) {
  1058. model = buffer.pointer;
  1059. switch (model->type) {
  1060. case ACPI_TYPE_STRING:
  1061. string = model->string.pointer;
  1062. break;
  1063. case ACPI_TYPE_BUFFER:
  1064. string = model->buffer.pointer;
  1065. break;
  1066. default:
  1067. kfree(model);
  1068. model = NULL;
  1069. break;
  1070. }
  1071. }
  1072. hotk->model = asus_model_match(string);
  1073. if (hotk->model == END_MODEL) { /* match failed */
  1074. if (asus_info &&
  1075. strncmp(asus_info->oem_table_id, "ODEM", 4) == 0) {
  1076. hotk->model = P30;
  1077. printk(KERN_NOTICE
  1078. " Samsung P30 detected, supported\n");
  1079. } else {
  1080. hotk->model = M2E;
  1081. printk(KERN_NOTICE " unsupported model %s, trying "
  1082. "default values\n", string);
  1083. printk(KERN_NOTICE
  1084. " send /proc/acpi/dsdt to the developers\n");
  1085. }
  1086. hotk->methods = &model_conf[hotk->model];
  1087. return AE_OK;
  1088. }
  1089. hotk->methods = &model_conf[hotk->model];
  1090. printk(KERN_NOTICE " %s model detected, supported\n", string);
  1091. /* Sort of per-model blacklist */
  1092. if (strncmp(string, "L2B", 3) == 0)
  1093. hotk->methods->lcd_status = NULL;
  1094. /* L2B is similar enough to L3C to use its settings, with this only
  1095. exception */
  1096. else if (strncmp(string, "A3G", 3) == 0)
  1097. hotk->methods->lcd_status = "\\BLFG";
  1098. /* A3G is like M6R */
  1099. else if (strncmp(string, "S5N", 3) == 0 ||
  1100. strncmp(string, "M5N", 3) == 0 ||
  1101. strncmp(string, "W3N", 3) == 0)
  1102. hotk->methods->mt_mled = NULL;
  1103. /* S5N, M5N and W3N have no MLED */
  1104. else if (strncmp(string, "L5D", 3) == 0)
  1105. hotk->methods->mt_wled = NULL;
  1106. /* L5D's WLED is not controlled by ACPI */
  1107. else if (strncmp(string, "M2N", 3) == 0 ||
  1108. strncmp(string, "W3V", 3) == 0 ||
  1109. strncmp(string, "S1N", 3) == 0)
  1110. hotk->methods->mt_wled = "WLED";
  1111. /* M2N, S1N and W3V have a usable WLED */
  1112. else if (asus_info) {
  1113. if (strncmp(asus_info->oem_table_id, "L1", 2) == 0)
  1114. hotk->methods->mled_status = NULL;
  1115. /* S1300A reports L84F, but L1400B too, account for that */
  1116. }
  1117. kfree(model);
  1118. return AE_OK;
  1119. }
  1120. static int asus_hotk_check(void)
  1121. {
  1122. int result = 0;
  1123. result = acpi_bus_get_status(hotk->device);
  1124. if (result)
  1125. return result;
  1126. if (hotk->device->status.present) {
  1127. result = asus_hotk_get_info();
  1128. } else {
  1129. printk(KERN_ERR " Hotkey device not present, aborting\n");
  1130. return -EINVAL;
  1131. }
  1132. return result;
  1133. }
  1134. static int asus_hotk_found;
  1135. static int asus_hotk_add(struct acpi_device *device)
  1136. {
  1137. acpi_status status = AE_OK;
  1138. int result;
  1139. if (!device)
  1140. return -EINVAL;
  1141. printk(KERN_NOTICE "Asus Laptop ACPI Extras version %s\n",
  1142. ASUS_ACPI_VERSION);
  1143. hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL);
  1144. if (!hotk)
  1145. return -ENOMEM;
  1146. hotk->handle = device->handle;
  1147. strcpy(acpi_device_name(device), ACPI_HOTK_DEVICE_NAME);
  1148. strcpy(acpi_device_class(device), ACPI_HOTK_CLASS);
  1149. acpi_driver_data(device) = hotk;
  1150. hotk->device = device;
  1151. result = asus_hotk_check();
  1152. if (result)
  1153. goto end;
  1154. result = asus_hotk_add_fs(device);
  1155. if (result)
  1156. goto end;
  1157. /*
  1158. * We install the handler, it will receive the hotk in parameter, so, we
  1159. * could add other data to the hotk struct
  1160. */
  1161. status = acpi_install_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
  1162. asus_hotk_notify, hotk);
  1163. if (ACPI_FAILURE(status))
  1164. printk(KERN_ERR " Error installing notify handler\n");
  1165. /* For laptops without GPLV: init the hotk->brightness value */
  1166. if ((!hotk->methods->brightness_get)
  1167. && (!hotk->methods->brightness_status)
  1168. && (hotk->methods->brightness_up && hotk->methods->brightness_down)) {
  1169. status =
  1170. acpi_evaluate_object(NULL, hotk->methods->brightness_down,
  1171. NULL, NULL);
  1172. if (ACPI_FAILURE(status))
  1173. printk(KERN_WARNING " Error changing brightness\n");
  1174. else {
  1175. status =
  1176. acpi_evaluate_object(NULL,
  1177. hotk->methods->brightness_up,
  1178. NULL, NULL);
  1179. if (ACPI_FAILURE(status))
  1180. printk(KERN_WARNING " Strange, error changing"
  1181. " brightness\n");
  1182. }
  1183. }
  1184. asus_hotk_found = 1;
  1185. /* LED display is off by default */
  1186. hotk->ledd_status = 0xFFF;
  1187. end:
  1188. if (result) {
  1189. kfree(hotk);
  1190. }
  1191. return result;
  1192. }
  1193. static int asus_hotk_remove(struct acpi_device *device, int type)
  1194. {
  1195. acpi_status status = 0;
  1196. if (!device || !acpi_driver_data(device))
  1197. return -EINVAL;
  1198. status = acpi_remove_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
  1199. asus_hotk_notify);
  1200. if (ACPI_FAILURE(status))
  1201. printk(KERN_ERR "Asus ACPI: Error removing notify handler\n");
  1202. asus_hotk_remove_fs(device);
  1203. kfree(hotk);
  1204. return 0;
  1205. }
  1206. static struct backlight_ops asus_backlight_data = {
  1207. .get_brightness = read_brightness,
  1208. .update_status = set_brightness_status,
  1209. };
  1210. static void asus_acpi_exit(void)
  1211. {
  1212. if (asus_backlight_device)
  1213. backlight_device_unregister(asus_backlight_device);
  1214. acpi_bus_unregister_driver(&asus_hotk_driver);
  1215. remove_proc_entry(PROC_ASUS, acpi_root_dir);
  1216. return;
  1217. }
  1218. static int __init asus_acpi_init(void)
  1219. {
  1220. int result;
  1221. if (acpi_disabled)
  1222. return -ENODEV;
  1223. asus_proc_dir = proc_mkdir(PROC_ASUS, acpi_root_dir);
  1224. if (!asus_proc_dir) {
  1225. printk(KERN_ERR "Asus ACPI: Unable to create /proc entry\n");
  1226. return -ENODEV;
  1227. }
  1228. asus_proc_dir->owner = THIS_MODULE;
  1229. result = acpi_bus_register_driver(&asus_hotk_driver);
  1230. if (result < 0) {
  1231. remove_proc_entry(PROC_ASUS, acpi_root_dir);
  1232. return result;
  1233. }
  1234. /*
  1235. * This is a bit of a kludge. We only want this module loaded
  1236. * for ASUS systems, but there's currently no way to probe the
  1237. * ACPI namespace for ASUS HIDs. So we just return failure if
  1238. * we didn't find one, which will cause the module to be
  1239. * unloaded.
  1240. */
  1241. if (!asus_hotk_found) {
  1242. acpi_bus_unregister_driver(&asus_hotk_driver);
  1243. remove_proc_entry(PROC_ASUS, acpi_root_dir);
  1244. return -ENODEV;
  1245. }
  1246. asus_backlight_device = backlight_device_register("asus",NULL,NULL,
  1247. &asus_backlight_data);
  1248. if (IS_ERR(asus_backlight_device)) {
  1249. printk(KERN_ERR "Could not register asus backlight device\n");
  1250. asus_backlight_device = NULL;
  1251. asus_acpi_exit();
  1252. return -ENODEV;
  1253. }
  1254. asus_backlight_device->props.max_brightness = 15;
  1255. return 0;
  1256. }
  1257. module_init(asus_acpi_init);
  1258. module_exit(asus_acpi_exit);