asus_acpi.c 40 KB

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