asus_acpi.c 37 KB

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