asus_acpi.c 39 KB

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