asus_acpi.c 38 KB

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