asus_acpi.c 39 KB

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