asus_acpi.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410
  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. #define ACPI_HOTK_HID "ATK0100"
  56. /*
  57. * Some events we use, same for all Asus
  58. */
  59. #define BR_UP 0x10
  60. #define BR_DOWN 0x20
  61. /*
  62. * Flags for hotk status
  63. */
  64. #define MLED_ON 0x01 //mail LED
  65. #define WLED_ON 0x02 //wireless LED
  66. #define TLED_ON 0x04 //touchpad LED
  67. #define BT_ON 0x08 //internal Bluetooth
  68. MODULE_AUTHOR("Julien Lerouge, Karol Kozimor");
  69. MODULE_DESCRIPTION(ACPI_HOTK_NAME);
  70. MODULE_LICENSE("GPL");
  71. static uid_t asus_uid;
  72. static gid_t asus_gid;
  73. module_param(asus_uid, uint, 0);
  74. MODULE_PARM_DESC(asus_uid, "UID for entries in /proc/acpi/asus.\n");
  75. module_param(asus_gid, uint, 0);
  76. MODULE_PARM_DESC(asus_gid, "GID for entries in /proc/acpi/asus.\n");
  77. /* For each model, all features implemented,
  78. * those marked with R are relative to HOTK, A for absolute */
  79. struct model_data {
  80. char *name; //name of the laptop________________A
  81. char *mt_mled; //method to handle mled_____________R
  82. char *mled_status; //node to handle mled reading_______A
  83. char *mt_wled; //method to handle wled_____________R
  84. char *wled_status; //node to handle wled reading_______A
  85. char *mt_tled; //method to handle tled_____________R
  86. char *tled_status; //node to handle tled reading_______A
  87. char *mt_ledd; //method to handle LED display______R
  88. char *mt_bt_switch; //method to switch Bluetooth on/off_R
  89. char *bt_status; //no model currently supports this__?
  90. char *mt_lcd_switch; //method to turn LCD on/off_________A
  91. char *lcd_status; //node to read LCD panel state______A
  92. char *brightness_up; //method to set brightness up_______A
  93. char *brightness_down; //guess what ?______________________A
  94. char *brightness_set; //method to set absolute brightness_R
  95. char *brightness_get; //method to get absolute brightness_R
  96. char *brightness_status; //node to get brightness____________A
  97. char *display_set; //method to set video output________R
  98. char *display_get; //method to get video output________R
  99. };
  100. /*
  101. * This is the main structure, we can use it to store anything interesting
  102. * about the hotk device
  103. */
  104. struct asus_hotk {
  105. struct acpi_device *device; //the device we are in
  106. acpi_handle handle; //the handle of the hotk device
  107. char status; //status of the hotk, for LEDs, ...
  108. u32 ledd_status; //status of the LED display
  109. struct model_data *methods; //methods available on the laptop
  110. u8 brightness; //brightness level
  111. enum {
  112. A1x = 0, //A1340D, A1300F
  113. A2x, //A2500H
  114. A4G, //A4700G
  115. D1x, //D1
  116. L2D, //L2000D
  117. L3C, //L3800C
  118. L3D, //L3400D
  119. L3H, //L3H, L2000E, L5D
  120. L4R, //L4500R
  121. L5x, //L5800C
  122. L8L, //L8400L
  123. M1A, //M1300A
  124. M2E, //M2400E, L4400L
  125. M6N, //M6800N, W3400N
  126. M6R, //M6700R, A3000G
  127. P30, //Samsung P30
  128. S1x, //S1300A, but also L1400B and M2400A (L84F)
  129. S2x, //S200 (J1 reported), Victor MP-XP7210
  130. W1N, //W1000N
  131. W5A, //W5A
  132. W3V, //W3030V
  133. xxN, //M2400N, M3700N, M5200N, M6800N, S1300N, S5200N
  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. /* procdir we use */
  369. static struct proc_dir_entry *asus_proc_dir;
  370. static struct backlight_device *asus_backlight_device;
  371. /*
  372. * This header is made available to allow proper configuration given model,
  373. * revision number , ... this info cannot go in struct asus_hotk because it is
  374. * available before the hotk
  375. */
  376. static struct acpi_table_header *asus_info;
  377. /* The actual device the driver binds to */
  378. static struct asus_hotk *hotk;
  379. /*
  380. * The hotkey driver declaration
  381. */
  382. static int asus_hotk_add(struct acpi_device *device);
  383. static int asus_hotk_remove(struct acpi_device *device, int type);
  384. static struct acpi_driver asus_hotk_driver = {
  385. .name = ACPI_HOTK_NAME,
  386. .class = ACPI_HOTK_CLASS,
  387. .ids = ACPI_HOTK_HID,
  388. .ops = {
  389. .add = asus_hotk_add,
  390. .remove = asus_hotk_remove,
  391. },
  392. };
  393. /*
  394. * This function evaluates an ACPI method, given an int as parameter, the
  395. * method is searched within the scope of the handle, can be NULL. The output
  396. * of the method is written is output, which can also be NULL
  397. *
  398. * returns 1 if write is successful, 0 else.
  399. */
  400. static int write_acpi_int(acpi_handle handle, const char *method, int val,
  401. struct acpi_buffer *output)
  402. {
  403. struct acpi_object_list params; //list of input parameters (an int here)
  404. union acpi_object in_obj; //the only param we use
  405. acpi_status status;
  406. params.count = 1;
  407. params.pointer = &in_obj;
  408. in_obj.type = ACPI_TYPE_INTEGER;
  409. in_obj.integer.value = val;
  410. status = acpi_evaluate_object(handle, (char *)method, &params, output);
  411. return (status == AE_OK);
  412. }
  413. static int read_acpi_int(acpi_handle handle, const char *method, int *val)
  414. {
  415. struct acpi_buffer output;
  416. union acpi_object out_obj;
  417. acpi_status status;
  418. output.length = sizeof(out_obj);
  419. output.pointer = &out_obj;
  420. status = acpi_evaluate_object(handle, (char *)method, NULL, &output);
  421. *val = out_obj.integer.value;
  422. return (status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER);
  423. }
  424. /*
  425. * We write our info in page, we begin at offset off and cannot write more
  426. * than count bytes. We set eof to 1 if we handle those 2 values. We return the
  427. * number of bytes written in page
  428. */
  429. static int
  430. proc_read_info(char *page, char **start, off_t off, int count, int *eof,
  431. void *data)
  432. {
  433. int len = 0;
  434. int temp;
  435. char buf[16]; //enough for all info
  436. /*
  437. * We use the easy way, we don't care of off and count, so we don't set eof
  438. * to 1
  439. */
  440. len += sprintf(page, ACPI_HOTK_NAME " " ASUS_ACPI_VERSION "\n");
  441. len += sprintf(page + len, "Model reference : %s\n",
  442. hotk->methods->name);
  443. /*
  444. * The SFUN method probably allows the original driver to get the list
  445. * of features supported by a given model. For now, 0x0100 or 0x0800
  446. * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
  447. * The significance of others is yet to be found.
  448. */
  449. if (read_acpi_int(hotk->handle, "SFUN", &temp))
  450. len +=
  451. sprintf(page + len, "SFUN value : 0x%04x\n", temp);
  452. /*
  453. * Another value for userspace: the ASYM method returns 0x02 for
  454. * battery low and 0x04 for battery critical, its readings tend to be
  455. * more accurate than those provided by _BST.
  456. * Note: since not all the laptops provide this method, errors are
  457. * silently ignored.
  458. */
  459. if (read_acpi_int(hotk->handle, "ASYM", &temp))
  460. len +=
  461. sprintf(page + len, "ASYM value : 0x%04x\n", temp);
  462. if (asus_info) {
  463. snprintf(buf, 16, "%d", asus_info->length);
  464. len += sprintf(page + len, "DSDT length : %s\n", buf);
  465. snprintf(buf, 16, "%d", asus_info->checksum);
  466. len += sprintf(page + len, "DSDT checksum : %s\n", buf);
  467. snprintf(buf, 16, "%d", asus_info->revision);
  468. len += sprintf(page + len, "DSDT revision : %s\n", buf);
  469. snprintf(buf, 7, "%s", asus_info->oem_id);
  470. len += sprintf(page + len, "OEM id : %s\n", buf);
  471. snprintf(buf, 9, "%s", asus_info->oem_table_id);
  472. len += sprintf(page + len, "OEM table id : %s\n", buf);
  473. snprintf(buf, 16, "%x", asus_info->oem_revision);
  474. len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
  475. snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
  476. len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
  477. snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
  478. len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
  479. }
  480. return len;
  481. }
  482. /*
  483. * /proc handlers
  484. * We write our info in page, we begin at offset off and cannot write more
  485. * than count bytes. We set eof to 1 if we handle those 2 values. We return the
  486. * number of bytes written in page
  487. */
  488. /* Generic LED functions */
  489. static int read_led(const char *ledname, int ledmask)
  490. {
  491. if (ledname) {
  492. int led_status;
  493. if (read_acpi_int(NULL, ledname, &led_status))
  494. return led_status;
  495. else
  496. printk(KERN_WARNING "Asus ACPI: Error reading LED "
  497. "status\n");
  498. }
  499. return (hotk->status & ledmask) ? 1 : 0;
  500. }
  501. static int parse_arg(const char __user * buf, unsigned long count, int *val)
  502. {
  503. char s[32];
  504. if (!count)
  505. return 0;
  506. if (count > 31)
  507. return -EINVAL;
  508. if (copy_from_user(s, buf, count))
  509. return -EFAULT;
  510. s[count] = 0;
  511. if (sscanf(s, "%i", val) != 1)
  512. return -EINVAL;
  513. return count;
  514. }
  515. /* FIXME: kill extraneous args so it can be called independently */
  516. static int
  517. write_led(const char __user * buffer, unsigned long count,
  518. char *ledname, int ledmask, int invert)
  519. {
  520. int rv, value;
  521. int led_out = 0;
  522. rv = parse_arg(buffer, count, &value);
  523. if (rv > 0)
  524. led_out = value ? 1 : 0;
  525. hotk->status =
  526. (led_out) ? (hotk->status | ledmask) : (hotk->status & ~ledmask);
  527. if (invert) /* invert target value */
  528. led_out = !led_out & 0x1;
  529. if (!write_acpi_int(hotk->handle, ledname, led_out, NULL))
  530. printk(KERN_WARNING "Asus ACPI: LED (%s) write failed\n",
  531. ledname);
  532. return rv;
  533. }
  534. /*
  535. * Proc handlers for MLED
  536. */
  537. static int
  538. proc_read_mled(char *page, char **start, off_t off, int count, int *eof,
  539. void *data)
  540. {
  541. return sprintf(page, "%d\n",
  542. read_led(hotk->methods->mled_status, MLED_ON));
  543. }
  544. static int
  545. proc_write_mled(struct file *file, const char __user * buffer,
  546. unsigned long count, void *data)
  547. {
  548. return write_led(buffer, count, hotk->methods->mt_mled, MLED_ON, 1);
  549. }
  550. /*
  551. * Proc handlers for LED display
  552. */
  553. static int
  554. proc_read_ledd(char *page, char **start, off_t off, int count, int *eof,
  555. void *data)
  556. {
  557. return sprintf(page, "0x%08x\n", hotk->ledd_status);
  558. }
  559. static int
  560. proc_write_ledd(struct file *file, const char __user * buffer,
  561. unsigned long count, void *data)
  562. {
  563. int rv, value;
  564. rv = parse_arg(buffer, count, &value);
  565. if (rv > 0) {
  566. if (!write_acpi_int
  567. (hotk->handle, hotk->methods->mt_ledd, value, NULL))
  568. printk(KERN_WARNING
  569. "Asus ACPI: LED display write failed\n");
  570. else
  571. hotk->ledd_status = (u32) value;
  572. }
  573. return rv;
  574. }
  575. /*
  576. * Proc handlers for WLED
  577. */
  578. static int
  579. proc_read_wled(char *page, char **start, off_t off, int count, int *eof,
  580. void *data)
  581. {
  582. return sprintf(page, "%d\n",
  583. read_led(hotk->methods->wled_status, WLED_ON));
  584. }
  585. static int
  586. proc_write_wled(struct file *file, const char __user * buffer,
  587. unsigned long count, void *data)
  588. {
  589. return write_led(buffer, count, hotk->methods->mt_wled, WLED_ON, 0);
  590. }
  591. /*
  592. * Proc handlers for Bluetooth
  593. */
  594. static int
  595. proc_read_bluetooth(char *page, char **start, off_t off, int count, int *eof,
  596. void *data)
  597. {
  598. return sprintf(page, "%d\n", read_led(hotk->methods->bt_status, BT_ON));
  599. }
  600. static int
  601. proc_write_bluetooth(struct file *file, const char __user * buffer,
  602. unsigned long count, void *data)
  603. {
  604. /* Note: mt_bt_switch controls both internal Bluetooth adapter's
  605. presence and its LED */
  606. return write_led(buffer, count, hotk->methods->mt_bt_switch, BT_ON, 0);
  607. }
  608. /*
  609. * Proc handlers for TLED
  610. */
  611. static int
  612. proc_read_tled(char *page, char **start, off_t off, int count, int *eof,
  613. void *data)
  614. {
  615. return sprintf(page, "%d\n",
  616. read_led(hotk->methods->tled_status, TLED_ON));
  617. }
  618. static int
  619. proc_write_tled(struct file *file, const char __user * buffer,
  620. unsigned long count, void *data)
  621. {
  622. return write_led(buffer, count, hotk->methods->mt_tled, TLED_ON, 0);
  623. }
  624. static int get_lcd_state(void)
  625. {
  626. int lcd = 0;
  627. if (hotk->model != L3H) {
  628. /* We don't have to check anything if we are here */
  629. if (!read_acpi_int(NULL, hotk->methods->lcd_status, &lcd))
  630. printk(KERN_WARNING
  631. "Asus ACPI: Error reading LCD status\n");
  632. if (hotk->model == L2D)
  633. lcd = ~lcd;
  634. } else { /* L3H and the like have to be handled differently */
  635. acpi_status status = 0;
  636. struct acpi_object_list input;
  637. union acpi_object mt_params[2];
  638. struct acpi_buffer output;
  639. union acpi_object out_obj;
  640. input.count = 2;
  641. input.pointer = mt_params;
  642. /* Note: the following values are partly guessed up, but
  643. otherwise they seem to work */
  644. mt_params[0].type = ACPI_TYPE_INTEGER;
  645. mt_params[0].integer.value = 0x02;
  646. mt_params[1].type = ACPI_TYPE_INTEGER;
  647. mt_params[1].integer.value = 0x02;
  648. output.length = sizeof(out_obj);
  649. output.pointer = &out_obj;
  650. status =
  651. acpi_evaluate_object(NULL, hotk->methods->lcd_status,
  652. &input, &output);
  653. if (status != AE_OK)
  654. return -1;
  655. if (out_obj.type == ACPI_TYPE_INTEGER)
  656. /* That's what the AML code does */
  657. lcd = out_obj.integer.value >> 8;
  658. }
  659. return (lcd & 1);
  660. }
  661. static int set_lcd_state(int value)
  662. {
  663. int lcd = 0;
  664. acpi_status status = 0;
  665. lcd = value ? 1 : 0;
  666. if (lcd != get_lcd_state()) {
  667. /* switch */
  668. if (hotk->model != L3H) {
  669. status =
  670. acpi_evaluate_object(NULL,
  671. hotk->methods->mt_lcd_switch,
  672. NULL, NULL);
  673. } else { /* L3H and the like have to be handled differently */
  674. if (!write_acpi_int
  675. (hotk->handle, hotk->methods->mt_lcd_switch, 0x07,
  676. NULL))
  677. status = AE_ERROR;
  678. /* L3H's AML executes EHK (0x07) upon Fn+F7 keypress,
  679. the exact behaviour is simulated here */
  680. }
  681. if (ACPI_FAILURE(status))
  682. printk(KERN_WARNING "Asus ACPI: Error switching LCD\n");
  683. }
  684. return 0;
  685. }
  686. static int
  687. proc_read_lcd(char *page, char **start, off_t off, int count, int *eof,
  688. void *data)
  689. {
  690. return sprintf(page, "%d\n", get_lcd_state());
  691. }
  692. static int
  693. proc_write_lcd(struct file *file, const char __user * buffer,
  694. unsigned long count, void *data)
  695. {
  696. int rv, value;
  697. rv = parse_arg(buffer, count, &value);
  698. if (rv > 0)
  699. set_lcd_state(value);
  700. return rv;
  701. }
  702. static int read_brightness(struct backlight_device *bd)
  703. {
  704. int value;
  705. if (hotk->methods->brightness_get) { /* SPLV/GPLV laptop */
  706. if (!read_acpi_int(hotk->handle, hotk->methods->brightness_get,
  707. &value))
  708. printk(KERN_WARNING
  709. "Asus ACPI: Error reading brightness\n");
  710. } else if (hotk->methods->brightness_status) { /* For D1 for example */
  711. if (!read_acpi_int(NULL, hotk->methods->brightness_status,
  712. &value))
  713. printk(KERN_WARNING
  714. "Asus ACPI: Error reading brightness\n");
  715. } else /* No GPLV method */
  716. value = hotk->brightness;
  717. return value;
  718. }
  719. /*
  720. * Change the brightness level
  721. */
  722. static int set_brightness(int value)
  723. {
  724. acpi_status status = 0;
  725. int ret = 0;
  726. /* SPLV laptop */
  727. if (hotk->methods->brightness_set) {
  728. if (!write_acpi_int(hotk->handle, hotk->methods->brightness_set,
  729. value, NULL))
  730. printk(KERN_WARNING
  731. "Asus ACPI: Error changing brightness\n");
  732. ret = -EIO;
  733. goto out;
  734. }
  735. /* No SPLV method if we are here, act as appropriate */
  736. value -= read_brightness(NULL);
  737. while (value != 0) {
  738. status = acpi_evaluate_object(NULL, (value > 0) ?
  739. hotk->methods->brightness_up :
  740. hotk->methods->brightness_down,
  741. NULL, NULL);
  742. (value > 0) ? value-- : value++;
  743. if (ACPI_FAILURE(status))
  744. printk(KERN_WARNING
  745. "Asus ACPI: Error changing brightness\n");
  746. ret = -EIO;
  747. }
  748. out:
  749. return ret;
  750. }
  751. static int set_brightness_status(struct backlight_device *bd)
  752. {
  753. return set_brightness(bd->props->brightness);
  754. }
  755. static int
  756. proc_read_brn(char *page, char **start, off_t off, int count, int *eof,
  757. void *data)
  758. {
  759. return sprintf(page, "%d\n", read_brightness(NULL));
  760. }
  761. static int
  762. proc_write_brn(struct file *file, const char __user * buffer,
  763. unsigned long count, void *data)
  764. {
  765. int rv, value;
  766. rv = parse_arg(buffer, count, &value);
  767. if (rv > 0) {
  768. value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
  769. /* 0 <= value <= 15 */
  770. set_brightness(value);
  771. }
  772. return rv;
  773. }
  774. static void set_display(int value)
  775. {
  776. /* no sanity check needed for now */
  777. if (!write_acpi_int(hotk->handle, hotk->methods->display_set,
  778. value, NULL))
  779. printk(KERN_WARNING "Asus ACPI: Error setting display\n");
  780. return;
  781. }
  782. /*
  783. * Now, *this* one could be more user-friendly, but so far, no-one has
  784. * complained. The significance of bits is the same as in proc_write_disp()
  785. */
  786. static int
  787. proc_read_disp(char *page, char **start, off_t off, int count, int *eof,
  788. void *data)
  789. {
  790. int value = 0;
  791. if (!read_acpi_int(hotk->handle, hotk->methods->display_get, &value))
  792. printk(KERN_WARNING
  793. "Asus ACPI: Error reading display status\n");
  794. value &= 0x07; /* needed for some models, shouldn't hurt others */
  795. return sprintf(page, "%d\n", value);
  796. }
  797. /*
  798. * Experimental support for display switching. As of now: 1 should activate
  799. * the LCD output, 2 should do for CRT, and 4 for TV-Out. Any combination
  800. * (bitwise) of these will suffice. I never actually tested 3 displays hooked up
  801. * simultaneously, so be warned. See the acpi4asus README for more info.
  802. */
  803. static int
  804. proc_write_disp(struct file *file, const char __user * buffer,
  805. unsigned long count, void *data)
  806. {
  807. int rv, value;
  808. rv = parse_arg(buffer, count, &value);
  809. if (rv > 0)
  810. set_display(value);
  811. return rv;
  812. }
  813. typedef int (proc_readfunc) (char *page, char **start, off_t off, int count,
  814. int *eof, void *data);
  815. typedef int (proc_writefunc) (struct file * file, const char __user * buffer,
  816. unsigned long count, void *data);
  817. static int
  818. asus_proc_add(char *name, proc_writefunc * writefunc,
  819. proc_readfunc * readfunc, mode_t mode,
  820. struct acpi_device *device)
  821. {
  822. struct proc_dir_entry *proc =
  823. create_proc_entry(name, mode, acpi_device_dir(device));
  824. if (!proc) {
  825. printk(KERN_WARNING " Unable to create %s fs entry\n", name);
  826. return -1;
  827. }
  828. proc->write_proc = writefunc;
  829. proc->read_proc = readfunc;
  830. proc->data = acpi_driver_data(device);
  831. proc->owner = THIS_MODULE;
  832. proc->uid = asus_uid;
  833. proc->gid = asus_gid;
  834. return 0;
  835. }
  836. static int asus_hotk_add_fs(struct acpi_device *device)
  837. {
  838. struct proc_dir_entry *proc;
  839. mode_t mode;
  840. /*
  841. * If parameter uid or gid is not changed, keep the default setting for
  842. * our proc entries (-rw-rw-rw-) else, it means we care about security,
  843. * and then set to -rw-rw----
  844. */
  845. if ((asus_uid == 0) && (asus_gid == 0)) {
  846. mode = S_IFREG | S_IRUGO | S_IWUGO;
  847. } else {
  848. mode = S_IFREG | S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP;
  849. printk(KERN_WARNING " asus_uid and asus_gid parameters are "
  850. "deprecated, use chown and chmod instead!\n");
  851. }
  852. acpi_device_dir(device) = asus_proc_dir;
  853. if (!acpi_device_dir(device))
  854. return -ENODEV;
  855. proc = create_proc_entry(PROC_INFO, mode, acpi_device_dir(device));
  856. if (proc) {
  857. proc->read_proc = proc_read_info;
  858. proc->data = acpi_driver_data(device);
  859. proc->owner = THIS_MODULE;
  860. proc->uid = asus_uid;
  861. proc->gid = asus_gid;
  862. } else {
  863. printk(KERN_WARNING " Unable to create " PROC_INFO
  864. " fs entry\n");
  865. }
  866. if (hotk->methods->mt_wled) {
  867. asus_proc_add(PROC_WLED, &proc_write_wled, &proc_read_wled,
  868. mode, device);
  869. }
  870. if (hotk->methods->mt_ledd) {
  871. asus_proc_add(PROC_LEDD, &proc_write_ledd, &proc_read_ledd,
  872. mode, device);
  873. }
  874. if (hotk->methods->mt_mled) {
  875. asus_proc_add(PROC_MLED, &proc_write_mled, &proc_read_mled,
  876. mode, device);
  877. }
  878. if (hotk->methods->mt_tled) {
  879. asus_proc_add(PROC_TLED, &proc_write_tled, &proc_read_tled,
  880. mode, device);
  881. }
  882. if (hotk->methods->mt_bt_switch) {
  883. asus_proc_add(PROC_BT, &proc_write_bluetooth,
  884. &proc_read_bluetooth, mode, device);
  885. }
  886. /*
  887. * We need both read node and write method as LCD switch is also accessible
  888. * from keyboard
  889. */
  890. if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status) {
  891. asus_proc_add(PROC_LCD, &proc_write_lcd, &proc_read_lcd, mode,
  892. device);
  893. }
  894. if ((hotk->methods->brightness_up && hotk->methods->brightness_down) ||
  895. (hotk->methods->brightness_get && hotk->methods->brightness_set)) {
  896. asus_proc_add(PROC_BRN, &proc_write_brn, &proc_read_brn, mode,
  897. device);
  898. }
  899. if (hotk->methods->display_set) {
  900. asus_proc_add(PROC_DISP, &proc_write_disp, &proc_read_disp,
  901. mode, device);
  902. }
  903. return 0;
  904. }
  905. static int asus_hotk_remove_fs(struct acpi_device *device)
  906. {
  907. if (acpi_device_dir(device)) {
  908. remove_proc_entry(PROC_INFO, acpi_device_dir(device));
  909. if (hotk->methods->mt_wled)
  910. remove_proc_entry(PROC_WLED, acpi_device_dir(device));
  911. if (hotk->methods->mt_mled)
  912. remove_proc_entry(PROC_MLED, acpi_device_dir(device));
  913. if (hotk->methods->mt_tled)
  914. remove_proc_entry(PROC_TLED, acpi_device_dir(device));
  915. if (hotk->methods->mt_ledd)
  916. remove_proc_entry(PROC_LEDD, acpi_device_dir(device));
  917. if (hotk->methods->mt_bt_switch)
  918. remove_proc_entry(PROC_BT, acpi_device_dir(device));
  919. if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status)
  920. remove_proc_entry(PROC_LCD, acpi_device_dir(device));
  921. if ((hotk->methods->brightness_up
  922. && hotk->methods->brightness_down)
  923. || (hotk->methods->brightness_get
  924. && hotk->methods->brightness_set))
  925. remove_proc_entry(PROC_BRN, acpi_device_dir(device));
  926. if (hotk->methods->display_set)
  927. remove_proc_entry(PROC_DISP, acpi_device_dir(device));
  928. }
  929. return 0;
  930. }
  931. static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
  932. {
  933. /* TODO Find a better way to handle events count. */
  934. if (!hotk)
  935. return;
  936. if ((event & ~((u32) BR_UP)) < 16) {
  937. hotk->brightness = (event & ~((u32) BR_UP));
  938. } else if ((event & ~((u32) BR_DOWN)) < 16) {
  939. hotk->brightness = (event & ~((u32) BR_DOWN));
  940. }
  941. acpi_bus_generate_event(hotk->device, event,
  942. hotk->event_count[event % 128]++);
  943. return;
  944. }
  945. /*
  946. * Match the model string to the list of supported models. Return END_MODEL if
  947. * no match or model is NULL.
  948. */
  949. static int asus_model_match(char *model)
  950. {
  951. if (model == NULL)
  952. return END_MODEL;
  953. if (strncmp(model, "L3D", 3) == 0)
  954. return L3D;
  955. else if (strncmp(model, "L2E", 3) == 0 ||
  956. strncmp(model, "L3H", 3) == 0 || strncmp(model, "L5D", 3) == 0)
  957. return L3H;
  958. else if (strncmp(model, "L3", 2) == 0 || strncmp(model, "L2B", 3) == 0)
  959. return L3C;
  960. else if (strncmp(model, "L8L", 3) == 0)
  961. return L8L;
  962. else if (strncmp(model, "L4R", 3) == 0)
  963. return L4R;
  964. else if (strncmp(model, "M6N", 3) == 0 || strncmp(model, "W3N", 3) == 0)
  965. return M6N;
  966. else if (strncmp(model, "M6R", 3) == 0 || strncmp(model, "A3G", 3) == 0)
  967. return M6R;
  968. else if (strncmp(model, "M2N", 3) == 0 ||
  969. strncmp(model, "M3N", 3) == 0 ||
  970. strncmp(model, "M5N", 3) == 0 ||
  971. strncmp(model, "M6N", 3) == 0 ||
  972. strncmp(model, "S1N", 3) == 0 ||
  973. strncmp(model, "S5N", 3) == 0 || strncmp(model, "W1N", 3) == 0)
  974. return xxN;
  975. else if (strncmp(model, "M1", 2) == 0)
  976. return M1A;
  977. else if (strncmp(model, "M2", 2) == 0 || strncmp(model, "L4E", 3) == 0)
  978. return M2E;
  979. else if (strncmp(model, "L2", 2) == 0)
  980. return L2D;
  981. else if (strncmp(model, "L8", 2) == 0)
  982. return S1x;
  983. else if (strncmp(model, "D1", 2) == 0)
  984. return D1x;
  985. else if (strncmp(model, "A1", 2) == 0)
  986. return A1x;
  987. else if (strncmp(model, "A2", 2) == 0)
  988. return A2x;
  989. else if (strncmp(model, "J1", 2) == 0)
  990. return S2x;
  991. else if (strncmp(model, "L5", 2) == 0)
  992. return L5x;
  993. else if (strncmp(model, "A4G", 3) == 0)
  994. return A4G;
  995. else if (strncmp(model, "W1N", 3) == 0)
  996. return W1N;
  997. else if (strncmp(model, "W3V", 3) == 0)
  998. return W3V;
  999. else if (strncmp(model, "W5A", 3) == 0)
  1000. return W5A;
  1001. else
  1002. return END_MODEL;
  1003. }
  1004. /*
  1005. * This function is used to initialize the hotk with right values. In this
  1006. * method, we can make all the detection we want, and modify the hotk struct
  1007. */
  1008. static int asus_hotk_get_info(void)
  1009. {
  1010. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  1011. union acpi_object *model = NULL;
  1012. int bsts_result;
  1013. char *string = NULL;
  1014. acpi_status status;
  1015. /*
  1016. * Get DSDT headers early enough to allow for differentiating between
  1017. * models, but late enough to allow acpi_bus_register_driver() to fail
  1018. * before doing anything ACPI-specific. Should we encounter a machine,
  1019. * which needs special handling (i.e. its hotkey device has a different
  1020. * HID), this bit will be moved. A global variable asus_info contains
  1021. * the DSDT header.
  1022. */
  1023. status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
  1024. if (ACPI_FAILURE(status))
  1025. printk(KERN_WARNING " Couldn't get the DSDT table header\n");
  1026. /* We have to write 0 on init this far for all ASUS models */
  1027. if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
  1028. printk(KERN_ERR " Hotkey initialization failed\n");
  1029. return -ENODEV;
  1030. }
  1031. /* This needs to be called for some laptops to init properly */
  1032. if (!read_acpi_int(hotk->handle, "BSTS", &bsts_result))
  1033. printk(KERN_WARNING " Error calling BSTS\n");
  1034. else if (bsts_result)
  1035. printk(KERN_NOTICE " BSTS called, 0x%02x returned\n",
  1036. bsts_result);
  1037. /*
  1038. * Try to match the object returned by INIT to the specific model.
  1039. * Handle every possible object (or the lack of thereof) the DSDT
  1040. * writers might throw at us. When in trouble, we pass NULL to
  1041. * asus_model_match() and try something completely different.
  1042. */
  1043. if (buffer.pointer) {
  1044. model = buffer.pointer;
  1045. switch (model->type) {
  1046. case ACPI_TYPE_STRING:
  1047. string = model->string.pointer;
  1048. break;
  1049. case ACPI_TYPE_BUFFER:
  1050. string = model->buffer.pointer;
  1051. break;
  1052. default:
  1053. kfree(model);
  1054. break;
  1055. }
  1056. }
  1057. hotk->model = asus_model_match(string);
  1058. if (hotk->model == END_MODEL) { /* match failed */
  1059. if (asus_info &&
  1060. strncmp(asus_info->oem_table_id, "ODEM", 4) == 0) {
  1061. hotk->model = P30;
  1062. printk(KERN_NOTICE
  1063. " Samsung P30 detected, supported\n");
  1064. } else {
  1065. hotk->model = M2E;
  1066. printk(KERN_NOTICE " unsupported model %s, trying "
  1067. "default values\n", string);
  1068. printk(KERN_NOTICE
  1069. " send /proc/acpi/dsdt to the developers\n");
  1070. }
  1071. hotk->methods = &model_conf[hotk->model];
  1072. return AE_OK;
  1073. }
  1074. hotk->methods = &model_conf[hotk->model];
  1075. printk(KERN_NOTICE " %s model detected, supported\n", string);
  1076. /* Sort of per-model blacklist */
  1077. if (strncmp(string, "L2B", 3) == 0)
  1078. hotk->methods->lcd_status = NULL;
  1079. /* L2B is similar enough to L3C to use its settings, with this only
  1080. exception */
  1081. else if (strncmp(string, "A3G", 3) == 0)
  1082. hotk->methods->lcd_status = "\\BLFG";
  1083. /* A3G is like M6R */
  1084. else if (strncmp(string, "S5N", 3) == 0 ||
  1085. strncmp(string, "M5N", 3) == 0 ||
  1086. strncmp(string, "W3N", 3) == 0)
  1087. hotk->methods->mt_mled = NULL;
  1088. /* S5N, M5N and W3N have no MLED */
  1089. else if (strncmp(string, "L5D", 3) == 0)
  1090. hotk->methods->mt_wled = NULL;
  1091. /* L5D's WLED is not controlled by ACPI */
  1092. else if (strncmp(string, "M2N", 3) == 0 ||
  1093. strncmp(string, "W3V", 3) == 0 ||
  1094. strncmp(string, "S1N", 3) == 0)
  1095. hotk->methods->mt_wled = "WLED";
  1096. /* M2N, S1N and W3V have a usable WLED */
  1097. else if (asus_info) {
  1098. if (strncmp(asus_info->oem_table_id, "L1", 2) == 0)
  1099. hotk->methods->mled_status = NULL;
  1100. /* S1300A reports L84F, but L1400B too, account for that */
  1101. }
  1102. kfree(model);
  1103. return AE_OK;
  1104. }
  1105. static int asus_hotk_check(void)
  1106. {
  1107. int result = 0;
  1108. result = acpi_bus_get_status(hotk->device);
  1109. if (result)
  1110. return result;
  1111. if (hotk->device->status.present) {
  1112. result = asus_hotk_get_info();
  1113. } else {
  1114. printk(KERN_ERR " Hotkey device not present, aborting\n");
  1115. return -EINVAL;
  1116. }
  1117. return result;
  1118. }
  1119. static int asus_hotk_found;
  1120. static int asus_hotk_add(struct acpi_device *device)
  1121. {
  1122. acpi_status status = AE_OK;
  1123. int result;
  1124. if (!device)
  1125. return -EINVAL;
  1126. printk(KERN_NOTICE "Asus Laptop ACPI Extras version %s\n",
  1127. ASUS_ACPI_VERSION);
  1128. hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL);
  1129. if (!hotk)
  1130. return -ENOMEM;
  1131. hotk->handle = device->handle;
  1132. strcpy(acpi_device_name(device), ACPI_HOTK_DEVICE_NAME);
  1133. strcpy(acpi_device_class(device), ACPI_HOTK_CLASS);
  1134. acpi_driver_data(device) = hotk;
  1135. hotk->device = device;
  1136. result = asus_hotk_check();
  1137. if (result)
  1138. goto end;
  1139. result = asus_hotk_add_fs(device);
  1140. if (result)
  1141. goto end;
  1142. /*
  1143. * We install the handler, it will receive the hotk in parameter, so, we
  1144. * could add other data to the hotk struct
  1145. */
  1146. status = acpi_install_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
  1147. asus_hotk_notify, hotk);
  1148. if (ACPI_FAILURE(status))
  1149. printk(KERN_ERR " Error installing notify handler\n");
  1150. /* For laptops without GPLV: init the hotk->brightness value */
  1151. if ((!hotk->methods->brightness_get)
  1152. && (!hotk->methods->brightness_status)
  1153. && (hotk->methods->brightness_up && hotk->methods->brightness_down)) {
  1154. status =
  1155. acpi_evaluate_object(NULL, hotk->methods->brightness_down,
  1156. NULL, NULL);
  1157. if (ACPI_FAILURE(status))
  1158. printk(KERN_WARNING " Error changing brightness\n");
  1159. else {
  1160. status =
  1161. acpi_evaluate_object(NULL,
  1162. hotk->methods->brightness_up,
  1163. NULL, NULL);
  1164. if (ACPI_FAILURE(status))
  1165. printk(KERN_WARNING " Strange, error changing"
  1166. " brightness\n");
  1167. }
  1168. }
  1169. asus_hotk_found = 1;
  1170. /* LED display is off by default */
  1171. hotk->ledd_status = 0xFFF;
  1172. end:
  1173. if (result) {
  1174. kfree(hotk);
  1175. }
  1176. return result;
  1177. }
  1178. static int asus_hotk_remove(struct acpi_device *device, int type)
  1179. {
  1180. acpi_status status = 0;
  1181. if (!device || !acpi_driver_data(device))
  1182. return -EINVAL;
  1183. status = acpi_remove_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
  1184. asus_hotk_notify);
  1185. if (ACPI_FAILURE(status))
  1186. printk(KERN_ERR "Asus ACPI: Error removing notify handler\n");
  1187. asus_hotk_remove_fs(device);
  1188. kfree(hotk);
  1189. return 0;
  1190. }
  1191. static struct backlight_properties asus_backlight_data = {
  1192. .owner = THIS_MODULE,
  1193. .get_brightness = read_brightness,
  1194. .update_status = set_brightness_status,
  1195. .max_brightness = 15,
  1196. };
  1197. static void __exit asus_acpi_exit(void)
  1198. {
  1199. if (asus_backlight_device)
  1200. backlight_device_unregister(asus_backlight_device);
  1201. acpi_bus_unregister_driver(&asus_hotk_driver);
  1202. remove_proc_entry(PROC_ASUS, acpi_root_dir);
  1203. return;
  1204. }
  1205. static int __init asus_acpi_init(void)
  1206. {
  1207. int result;
  1208. if (acpi_disabled)
  1209. return -ENODEV;
  1210. if (!acpi_specific_hotkey_enabled) {
  1211. printk(KERN_ERR "Using generic hotkey driver\n");
  1212. return -ENODEV;
  1213. }
  1214. asus_proc_dir = proc_mkdir(PROC_ASUS, acpi_root_dir);
  1215. if (!asus_proc_dir) {
  1216. printk(KERN_ERR "Asus ACPI: Unable to create /proc entry\n");
  1217. return -ENODEV;
  1218. }
  1219. asus_proc_dir->owner = THIS_MODULE;
  1220. result = acpi_bus_register_driver(&asus_hotk_driver);
  1221. if (result < 0) {
  1222. remove_proc_entry(PROC_ASUS, acpi_root_dir);
  1223. return result;
  1224. }
  1225. /*
  1226. * This is a bit of a kludge. We only want this module loaded
  1227. * for ASUS systems, but there's currently no way to probe the
  1228. * ACPI namespace for ASUS HIDs. So we just return failure if
  1229. * we didn't find one, which will cause the module to be
  1230. * unloaded.
  1231. */
  1232. if (!asus_hotk_found) {
  1233. acpi_bus_unregister_driver(&asus_hotk_driver);
  1234. remove_proc_entry(PROC_ASUS, acpi_root_dir);
  1235. return result;
  1236. }
  1237. asus_backlight_device = backlight_device_register("asus",NULL,NULL,
  1238. &asus_backlight_data);
  1239. if (IS_ERR(asus_backlight_device)) {
  1240. printk(KERN_ERR "Could not register asus backlight device\n");
  1241. asus_backlight_device = NULL;
  1242. asus_acpi_exit();
  1243. }
  1244. return 0;
  1245. }
  1246. module_init(asus_acpi_init);
  1247. module_exit(asus_acpi_exit);