asus_acpi.c 40 KB

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