asus_acpi.c 37 KB

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