asus_acpi.c 39 KB

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