asus_acpi.c 39 KB

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