asus-laptop.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525
  1. /*
  2. * asus-laptop.c - Asus Laptop Support
  3. *
  4. *
  5. * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
  6. * Copyright (C) 2006-2007 Corentin Chary
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. *
  23. * The development page for this driver is located at
  24. * http://sourceforge.net/projects/acpi4asus/
  25. *
  26. * Credits:
  27. * Pontus Fuchs - Helper functions, cleanup
  28. * Johann Wiesner - Small compile fixes
  29. * John Belmonte - ACPI code for Toshiba laptop was a good starting point.
  30. * Eric Burghard - LED display support for W1N
  31. * Josh Green - Light Sens support
  32. * Thomas Tuttle - His first patch for led support was very helpfull
  33. * Sam Lin - GPS support
  34. */
  35. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  36. #include <linux/kernel.h>
  37. #include <linux/module.h>
  38. #include <linux/init.h>
  39. #include <linux/types.h>
  40. #include <linux/err.h>
  41. #include <linux/proc_fs.h>
  42. #include <linux/backlight.h>
  43. #include <linux/fb.h>
  44. #include <linux/leds.h>
  45. #include <linux/platform_device.h>
  46. #include <acpi/acpi_drivers.h>
  47. #include <acpi/acpi_bus.h>
  48. #include <asm/uaccess.h>
  49. #include <linux/input.h>
  50. #define ASUS_LAPTOP_VERSION "0.42"
  51. #define ASUS_HOTK_NAME "Asus Laptop Support"
  52. #define ASUS_HOTK_CLASS "hotkey"
  53. #define ASUS_HOTK_DEVICE_NAME "Hotkey"
  54. #define ASUS_HOTK_FILE KBUILD_MODNAME
  55. #define ASUS_HOTK_PREFIX "\\_SB.ATKD."
  56. /*
  57. * Some events we use, same for all Asus
  58. */
  59. #define ATKD_BR_UP 0x10
  60. #define ATKD_BR_DOWN 0x20
  61. #define ATKD_LCD_ON 0x33
  62. #define ATKD_LCD_OFF 0x34
  63. /*
  64. * Known bits returned by \_SB.ATKD.HWRS
  65. */
  66. #define WL_HWRS 0x80
  67. #define BT_HWRS 0x100
  68. /*
  69. * Flags for hotk status
  70. * WL_ON and BT_ON are also used for wireless_status()
  71. */
  72. #define WL_ON 0x01 /* internal Wifi */
  73. #define BT_ON 0x02 /* internal Bluetooth */
  74. #define MLED_ON 0x04 /* mail LED */
  75. #define TLED_ON 0x08 /* touchpad LED */
  76. #define RLED_ON 0x10 /* Record LED */
  77. #define PLED_ON 0x20 /* Phone LED */
  78. #define GLED_ON 0x40 /* Gaming LED */
  79. #define LCD_ON 0x80 /* LCD backlight */
  80. #define GPS_ON 0x100 /* GPS */
  81. #define KEY_ON 0x200 /* Keyboard backlight */
  82. MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
  83. MODULE_DESCRIPTION(ASUS_HOTK_NAME);
  84. MODULE_LICENSE("GPL");
  85. /*
  86. * WAPF defines the behavior of the Fn+Fx wlan key
  87. * The significance of values is yet to be found, but
  88. * most of the time:
  89. * 0x0 will do nothing
  90. * 0x1 will allow to control the device with Fn+Fx key.
  91. * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key
  92. * 0x5 like 0x1 or 0x4
  93. * So, if something doesn't work as you want, just try other values =)
  94. */
  95. static uint wapf = 1;
  96. module_param(wapf, uint, 0644);
  97. MODULE_PARM_DESC(wapf, "WAPF value");
  98. static uint wireless_status = 1;
  99. static uint bluetooth_status = 1;
  100. module_param(wireless_status, uint, 0644);
  101. MODULE_PARM_DESC(wireless_status, "Set the wireless status on boot "
  102. "(0 = disabled, 1 = enabled, -1 = don't do anything). "
  103. "default is 1");
  104. module_param(bluetooth_status, uint, 0644);
  105. MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot "
  106. "(0 = disabled, 1 = enabled, -1 = don't do anything). "
  107. "default is 1");
  108. #define ASUS_HANDLE(object, paths...) \
  109. static acpi_handle object##_handle = NULL; \
  110. static char *object##_paths[] = { paths }
  111. /* LED */
  112. ASUS_HANDLE(mled_set, ASUS_HOTK_PREFIX "MLED");
  113. ASUS_HANDLE(tled_set, ASUS_HOTK_PREFIX "TLED");
  114. ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED"); /* W1JC */
  115. ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED"); /* A7J */
  116. ASUS_HANDLE(gled_set, ASUS_HOTK_PREFIX "GLED"); /* G1, G2 (probably) */
  117. /* LEDD */
  118. ASUS_HANDLE(ledd_set, ASUS_HOTK_PREFIX "SLCM");
  119. /*
  120. * Bluetooth and WLAN
  121. * WLED and BLED are not handled like other XLED, because in some dsdt
  122. * they also control the WLAN/Bluetooth device.
  123. */
  124. ASUS_HANDLE(wl_switch, ASUS_HOTK_PREFIX "WLED");
  125. ASUS_HANDLE(bt_switch, ASUS_HOTK_PREFIX "BLED");
  126. ASUS_HANDLE(wireless_status, ASUS_HOTK_PREFIX "RSTS"); /* All new models */
  127. /* Brightness */
  128. ASUS_HANDLE(brightness_set, ASUS_HOTK_PREFIX "SPLV");
  129. ASUS_HANDLE(brightness_get, ASUS_HOTK_PREFIX "GPLV");
  130. /* Backlight */
  131. ASUS_HANDLE(lcd_switch, "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */
  132. "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */
  133. "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */
  134. "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */
  135. "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */
  136. "\\_SB.PCI0.LPCB.EC0._Q0E", /* P30/P35 */
  137. "\\_SB.PCI0.PX40.Q10", /* S1x */
  138. "\\Q10"); /* A2x, L2D, L3D, M2E */
  139. /* Display */
  140. ASUS_HANDLE(display_set, ASUS_HOTK_PREFIX "SDSP");
  141. ASUS_HANDLE(display_get,
  142. /* A6B, A6K A6R A7D F3JM L4R M6R A3G M6A M6V VX-1 V6J V6V W3Z */
  143. "\\_SB.PCI0.P0P1.VGA.GETD",
  144. /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V S5A M5A z33A W1Jc W2V G1 */
  145. "\\_SB.PCI0.P0P2.VGA.GETD",
  146. /* A6V A6Q */
  147. "\\_SB.PCI0.P0P3.VGA.GETD",
  148. /* A6T, A6M */
  149. "\\_SB.PCI0.P0PA.VGA.GETD",
  150. /* L3C */
  151. "\\_SB.PCI0.PCI1.VGAC.NMAP",
  152. /* Z96F */
  153. "\\_SB.PCI0.VGA.GETD",
  154. /* A2D */
  155. "\\ACTD",
  156. /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */
  157. "\\ADVG",
  158. /* P30 */
  159. "\\DNXT",
  160. /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */
  161. "\\INFB",
  162. /* A3F A6F A3N A3L M6N W3N W6A */
  163. "\\SSTE");
  164. ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC"); /* Z71A Z71V */
  165. ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL"); /* Z71A Z71V */
  166. /* GPS */
  167. /* R2H use different handle for GPS on/off */
  168. ASUS_HANDLE(gps_on, ASUS_HOTK_PREFIX "SDON"); /* R2H */
  169. ASUS_HANDLE(gps_off, ASUS_HOTK_PREFIX "SDOF"); /* R2H */
  170. ASUS_HANDLE(gps_status, ASUS_HOTK_PREFIX "GPST");
  171. /* Keyboard light */
  172. ASUS_HANDLE(kled_set, ASUS_HOTK_PREFIX "SLKB");
  173. ASUS_HANDLE(kled_get, ASUS_HOTK_PREFIX "GLKB");
  174. /*
  175. * This is the main structure, we can use it to store anything interesting
  176. * about the hotk device
  177. */
  178. struct asus_hotk {
  179. char *name; /* laptop name */
  180. struct platform_device *platform_device;
  181. struct acpi_device *device; /* the device we are in */
  182. acpi_handle handle; /* the handle of the hotk device */
  183. char status; /* status of the hotk, for LEDs, ... */
  184. u32 ledd_status; /* status of the LED display */
  185. u8 light_level; /* light sensor level */
  186. u8 light_switch; /* light sensor switch value */
  187. u16 event_count[128]; /* count for each event TODO make this better */
  188. struct input_dev *inputdev;
  189. u16 *keycode_map;
  190. };
  191. /*
  192. * This header is made available to allow proper configuration given model,
  193. * revision number , ... this info cannot go in struct asus_hotk because it is
  194. * available before the hotk
  195. */
  196. static struct acpi_table_header *asus_info;
  197. /* The actual device the driver binds to */
  198. static struct asus_hotk *hotk;
  199. /* The backlight device /sys/class/backlight */
  200. static struct backlight_device *asus_backlight_device;
  201. /*
  202. * The backlight class declaration
  203. */
  204. static int read_brightness(struct backlight_device *bd);
  205. static int update_bl_status(struct backlight_device *bd);
  206. static struct backlight_ops asusbl_ops = {
  207. .get_brightness = read_brightness,
  208. .update_status = update_bl_status,
  209. };
  210. /*
  211. * These functions actually update the LED's, and are called from a
  212. * workqueue. By doing this as separate work rather than when the LED
  213. * subsystem asks, we avoid messing with the Asus ACPI stuff during a
  214. * potentially bad time, such as a timer interrupt.
  215. */
  216. static struct workqueue_struct *led_workqueue;
  217. #define ASUS_LED(object, ledname, max) \
  218. static void object##_led_set(struct led_classdev *led_cdev, \
  219. enum led_brightness value); \
  220. static enum led_brightness object##_led_get( \
  221. struct led_classdev *led_cdev); \
  222. static void object##_led_update(struct work_struct *ignored); \
  223. static int object##_led_wk; \
  224. static DECLARE_WORK(object##_led_work, object##_led_update); \
  225. static struct led_classdev object##_led = { \
  226. .name = "asus::" ledname, \
  227. .brightness_set = object##_led_set, \
  228. .brightness_get = object##_led_get, \
  229. .max_brightness = max \
  230. }
  231. ASUS_LED(mled, "mail", 1);
  232. ASUS_LED(tled, "touchpad", 1);
  233. ASUS_LED(rled, "record", 1);
  234. ASUS_LED(pled, "phone", 1);
  235. ASUS_LED(gled, "gaming", 1);
  236. ASUS_LED(kled, "kbd_backlight", 3);
  237. struct key_entry {
  238. char type;
  239. u8 code;
  240. u16 keycode;
  241. };
  242. enum { KE_KEY, KE_END };
  243. static struct key_entry asus_keymap[] = {
  244. {KE_KEY, 0x02, KEY_SCREENLOCK},
  245. {KE_KEY, 0x05, KEY_WLAN},
  246. {KE_KEY, 0x08, KEY_F13},
  247. {KE_KEY, 0x17, KEY_ZOOM},
  248. {KE_KEY, 0x1f, KEY_BATTERY},
  249. {KE_KEY, 0x30, KEY_VOLUMEUP},
  250. {KE_KEY, 0x31, KEY_VOLUMEDOWN},
  251. {KE_KEY, 0x32, KEY_MUTE},
  252. {KE_KEY, 0x33, KEY_SWITCHVIDEOMODE},
  253. {KE_KEY, 0x34, KEY_SWITCHVIDEOMODE},
  254. {KE_KEY, 0x40, KEY_PREVIOUSSONG},
  255. {KE_KEY, 0x41, KEY_NEXTSONG},
  256. {KE_KEY, 0x43, KEY_STOPCD},
  257. {KE_KEY, 0x45, KEY_PLAYPAUSE},
  258. {KE_KEY, 0x4c, KEY_MEDIA},
  259. {KE_KEY, 0x50, KEY_EMAIL},
  260. {KE_KEY, 0x51, KEY_WWW},
  261. {KE_KEY, 0x55, KEY_CALC},
  262. {KE_KEY, 0x5C, KEY_SCREENLOCK}, /* Screenlock */
  263. {KE_KEY, 0x5D, KEY_WLAN},
  264. {KE_KEY, 0x5E, KEY_WLAN},
  265. {KE_KEY, 0x5F, KEY_WLAN},
  266. {KE_KEY, 0x60, KEY_SWITCHVIDEOMODE},
  267. {KE_KEY, 0x61, KEY_SWITCHVIDEOMODE},
  268. {KE_KEY, 0x62, KEY_SWITCHVIDEOMODE},
  269. {KE_KEY, 0x63, KEY_SWITCHVIDEOMODE},
  270. {KE_KEY, 0x6B, KEY_F13}, /* Lock Touchpad */
  271. {KE_KEY, 0x82, KEY_CAMERA},
  272. {KE_KEY, 0x88, KEY_WLAN },
  273. {KE_KEY, 0x8A, KEY_PROG1},
  274. {KE_KEY, 0x95, KEY_MEDIA},
  275. {KE_KEY, 0x99, KEY_PHONE},
  276. {KE_KEY, 0xc4, KEY_KBDILLUMUP},
  277. {KE_KEY, 0xc5, KEY_KBDILLUMDOWN},
  278. {KE_END, 0},
  279. };
  280. /*
  281. * This function evaluates an ACPI method, given an int as parameter, the
  282. * method is searched within the scope of the handle, can be NULL. The output
  283. * of the method is written is output, which can also be NULL
  284. *
  285. * returns 0 if write is successful, -1 else.
  286. */
  287. static int write_acpi_int_ret(acpi_handle handle, const char *method, int val,
  288. struct acpi_buffer *output)
  289. {
  290. struct acpi_object_list params; /* list of input parameters (an int) */
  291. union acpi_object in_obj; /* the only param we use */
  292. acpi_status status;
  293. if (!handle)
  294. return 0;
  295. params.count = 1;
  296. params.pointer = &in_obj;
  297. in_obj.type = ACPI_TYPE_INTEGER;
  298. in_obj.integer.value = val;
  299. status = acpi_evaluate_object(handle, (char *)method, &params, output);
  300. if (status == AE_OK)
  301. return 0;
  302. else
  303. return -1;
  304. }
  305. static int write_acpi_int(acpi_handle handle, const char *method, int val)
  306. {
  307. return write_acpi_int_ret(handle, method, val, NULL);
  308. }
  309. static int read_wireless_status(int mask)
  310. {
  311. unsigned long long status;
  312. acpi_status rv = AE_OK;
  313. if (!wireless_status_handle)
  314. return (hotk->status & mask) ? 1 : 0;
  315. rv = acpi_evaluate_integer(wireless_status_handle, NULL, NULL, &status);
  316. if (ACPI_FAILURE(rv))
  317. pr_warning("Error reading Wireless status\n");
  318. else
  319. return (status & mask) ? 1 : 0;
  320. return (hotk->status & mask) ? 1 : 0;
  321. }
  322. static int read_gps_status(void)
  323. {
  324. unsigned long long status;
  325. acpi_status rv = AE_OK;
  326. rv = acpi_evaluate_integer(gps_status_handle, NULL, NULL, &status);
  327. if (ACPI_FAILURE(rv))
  328. pr_warning("Error reading GPS status\n");
  329. else
  330. return status ? 1 : 0;
  331. return (hotk->status & GPS_ON) ? 1 : 0;
  332. }
  333. /* Generic LED functions */
  334. static int read_status(int mask)
  335. {
  336. /* There is a special method for both wireless devices */
  337. if (mask == BT_ON || mask == WL_ON)
  338. return read_wireless_status(mask);
  339. else if (mask == GPS_ON)
  340. return read_gps_status();
  341. return (hotk->status & mask) ? 1 : 0;
  342. }
  343. static void write_status(acpi_handle handle, int out, int mask)
  344. {
  345. hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask);
  346. switch (mask) {
  347. case MLED_ON:
  348. out = !(out & 0x1);
  349. break;
  350. case GLED_ON:
  351. out = (out & 0x1) + 1;
  352. break;
  353. case GPS_ON:
  354. handle = (out) ? gps_on_handle : gps_off_handle;
  355. out = 0x02;
  356. break;
  357. default:
  358. out &= 0x1;
  359. break;
  360. }
  361. if (write_acpi_int(handle, NULL, out))
  362. pr_warning(" write failed %x\n", mask);
  363. }
  364. /* /sys/class/led handlers */
  365. #define ASUS_LED_HANDLER(object, mask) \
  366. static void object##_led_set(struct led_classdev *led_cdev, \
  367. enum led_brightness value) \
  368. { \
  369. object##_led_wk = (value > 0) ? 1 : 0; \
  370. queue_work(led_workqueue, &object##_led_work); \
  371. } \
  372. static void object##_led_update(struct work_struct *ignored) \
  373. { \
  374. int value = object##_led_wk; \
  375. write_status(object##_set_handle, value, (mask)); \
  376. } \
  377. static enum led_brightness object##_led_get( \
  378. struct led_classdev *led_cdev) \
  379. { \
  380. return led_cdev->brightness; \
  381. }
  382. ASUS_LED_HANDLER(mled, MLED_ON);
  383. ASUS_LED_HANDLER(pled, PLED_ON);
  384. ASUS_LED_HANDLER(rled, RLED_ON);
  385. ASUS_LED_HANDLER(tled, TLED_ON);
  386. ASUS_LED_HANDLER(gled, GLED_ON);
  387. /*
  388. * Keyboard backlight
  389. */
  390. static int get_kled_lvl(void)
  391. {
  392. unsigned long long kblv;
  393. struct acpi_object_list params;
  394. union acpi_object in_obj;
  395. acpi_status rv;
  396. params.count = 1;
  397. params.pointer = &in_obj;
  398. in_obj.type = ACPI_TYPE_INTEGER;
  399. in_obj.integer.value = 2;
  400. rv = acpi_evaluate_integer(kled_get_handle, NULL, &params, &kblv);
  401. if (ACPI_FAILURE(rv)) {
  402. pr_warning("Error reading kled level\n");
  403. return 0;
  404. }
  405. return kblv;
  406. }
  407. static int set_kled_lvl(int kblv)
  408. {
  409. if (kblv > 0)
  410. kblv = (1 << 7) | (kblv & 0x7F);
  411. else
  412. kblv = 0;
  413. if (write_acpi_int(kled_set_handle, NULL, kblv)) {
  414. pr_warning("Keyboard LED display write failed\n");
  415. return -EINVAL;
  416. }
  417. return 0;
  418. }
  419. static void kled_led_set(struct led_classdev *led_cdev,
  420. enum led_brightness value)
  421. {
  422. kled_led_wk = value;
  423. queue_work(led_workqueue, &kled_led_work);
  424. }
  425. static void kled_led_update(struct work_struct *ignored)
  426. {
  427. set_kled_lvl(kled_led_wk);
  428. }
  429. static enum led_brightness kled_led_get(struct led_classdev *led_cdev)
  430. {
  431. return get_kled_lvl();
  432. }
  433. static int get_lcd_state(void)
  434. {
  435. return read_status(LCD_ON);
  436. }
  437. static int set_lcd_state(int value)
  438. {
  439. int lcd = 0;
  440. acpi_status status = 0;
  441. lcd = value ? 1 : 0;
  442. if (lcd == get_lcd_state())
  443. return 0;
  444. if (lcd_switch_handle) {
  445. status = acpi_evaluate_object(lcd_switch_handle,
  446. NULL, NULL, NULL);
  447. if (ACPI_FAILURE(status))
  448. pr_warning("Error switching LCD\n");
  449. }
  450. write_status(NULL, lcd, LCD_ON);
  451. return 0;
  452. }
  453. static void lcd_blank(int blank)
  454. {
  455. struct backlight_device *bd = asus_backlight_device;
  456. if (bd) {
  457. bd->props.power = blank;
  458. backlight_update_status(bd);
  459. }
  460. }
  461. static int read_brightness(struct backlight_device *bd)
  462. {
  463. unsigned long long value;
  464. acpi_status rv = AE_OK;
  465. rv = acpi_evaluate_integer(brightness_get_handle, NULL, NULL, &value);
  466. if (ACPI_FAILURE(rv))
  467. pr_warning("Error reading brightness\n");
  468. return value;
  469. }
  470. static int set_brightness(struct backlight_device *bd, int value)
  471. {
  472. if (write_acpi_int(brightness_set_handle, NULL, value)) {
  473. pr_warning("Error changing brightness\n");
  474. return -EIO;
  475. }
  476. return 0;
  477. }
  478. static int update_bl_status(struct backlight_device *bd)
  479. {
  480. int rv;
  481. int value = bd->props.brightness;
  482. rv = set_brightness(bd, value);
  483. if (rv)
  484. return rv;
  485. value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0;
  486. return set_lcd_state(value);
  487. }
  488. /*
  489. * Platform device handlers
  490. */
  491. /*
  492. * We write our info in page, we begin at offset off and cannot write more
  493. * than count bytes. We set eof to 1 if we handle those 2 values. We return the
  494. * number of bytes written in page
  495. */
  496. static ssize_t show_infos(struct device *dev,
  497. struct device_attribute *attr, char *page)
  498. {
  499. int len = 0;
  500. unsigned long long temp;
  501. char buf[16]; /* enough for all info */
  502. acpi_status rv = AE_OK;
  503. /*
  504. * We use the easy way, we don't care of off and count, so we don't set eof
  505. * to 1
  506. */
  507. len += sprintf(page, ASUS_HOTK_NAME " " ASUS_LAPTOP_VERSION "\n");
  508. len += sprintf(page + len, "Model reference : %s\n", hotk->name);
  509. /*
  510. * The SFUN method probably allows the original driver to get the list
  511. * of features supported by a given model. For now, 0x0100 or 0x0800
  512. * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
  513. * The significance of others is yet to be found.
  514. */
  515. rv = acpi_evaluate_integer(hotk->handle, "SFUN", NULL, &temp);
  516. if (!ACPI_FAILURE(rv))
  517. len += sprintf(page + len, "SFUN value : %#x\n",
  518. (uint) temp);
  519. /*
  520. * The HWRS method return informations about the hardware.
  521. * 0x80 bit is for WLAN, 0x100 for Bluetooth.
  522. * The significance of others is yet to be found.
  523. * If we don't find the method, we assume the device are present.
  524. */
  525. rv = acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &temp);
  526. if (!ACPI_FAILURE(rv))
  527. len += sprintf(page + len, "HRWS value : %#x\n",
  528. (uint) temp);
  529. /*
  530. * Another value for userspace: the ASYM method returns 0x02 for
  531. * battery low and 0x04 for battery critical, its readings tend to be
  532. * more accurate than those provided by _BST.
  533. * Note: since not all the laptops provide this method, errors are
  534. * silently ignored.
  535. */
  536. rv = acpi_evaluate_integer(hotk->handle, "ASYM", NULL, &temp);
  537. if (!ACPI_FAILURE(rv))
  538. len += sprintf(page + len, "ASYM value : %#x\n",
  539. (uint) temp);
  540. if (asus_info) {
  541. snprintf(buf, 16, "%d", asus_info->length);
  542. len += sprintf(page + len, "DSDT length : %s\n", buf);
  543. snprintf(buf, 16, "%d", asus_info->checksum);
  544. len += sprintf(page + len, "DSDT checksum : %s\n", buf);
  545. snprintf(buf, 16, "%d", asus_info->revision);
  546. len += sprintf(page + len, "DSDT revision : %s\n", buf);
  547. snprintf(buf, 7, "%s", asus_info->oem_id);
  548. len += sprintf(page + len, "OEM id : %s\n", buf);
  549. snprintf(buf, 9, "%s", asus_info->oem_table_id);
  550. len += sprintf(page + len, "OEM table id : %s\n", buf);
  551. snprintf(buf, 16, "%x", asus_info->oem_revision);
  552. len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
  553. snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
  554. len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
  555. snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
  556. len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
  557. }
  558. return len;
  559. }
  560. static int parse_arg(const char *buf, unsigned long count, int *val)
  561. {
  562. if (!count)
  563. return 0;
  564. if (count > 31)
  565. return -EINVAL;
  566. if (sscanf(buf, "%i", val) != 1)
  567. return -EINVAL;
  568. return count;
  569. }
  570. static ssize_t store_status(const char *buf, size_t count,
  571. acpi_handle handle, int mask)
  572. {
  573. int rv, value;
  574. int out = 0;
  575. rv = parse_arg(buf, count, &value);
  576. if (rv > 0)
  577. out = value ? 1 : 0;
  578. write_status(handle, out, mask);
  579. return rv;
  580. }
  581. /*
  582. * LEDD display
  583. */
  584. static ssize_t show_ledd(struct device *dev,
  585. struct device_attribute *attr, char *buf)
  586. {
  587. return sprintf(buf, "0x%08x\n", hotk->ledd_status);
  588. }
  589. static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
  590. const char *buf, size_t count)
  591. {
  592. int rv, value;
  593. rv = parse_arg(buf, count, &value);
  594. if (rv > 0) {
  595. if (write_acpi_int(ledd_set_handle, NULL, value))
  596. pr_warning("LED display write failed\n");
  597. else
  598. hotk->ledd_status = (u32) value;
  599. }
  600. return rv;
  601. }
  602. /*
  603. * WLAN
  604. */
  605. static ssize_t show_wlan(struct device *dev,
  606. struct device_attribute *attr, char *buf)
  607. {
  608. return sprintf(buf, "%d\n", read_status(WL_ON));
  609. }
  610. static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
  611. const char *buf, size_t count)
  612. {
  613. return store_status(buf, count, wl_switch_handle, WL_ON);
  614. }
  615. /*
  616. * Bluetooth
  617. */
  618. static ssize_t show_bluetooth(struct device *dev,
  619. struct device_attribute *attr, char *buf)
  620. {
  621. return sprintf(buf, "%d\n", read_status(BT_ON));
  622. }
  623. static ssize_t store_bluetooth(struct device *dev,
  624. struct device_attribute *attr, const char *buf,
  625. size_t count)
  626. {
  627. return store_status(buf, count, bt_switch_handle, BT_ON);
  628. }
  629. /*
  630. * Display
  631. */
  632. static void set_display(int value)
  633. {
  634. /* no sanity check needed for now */
  635. if (write_acpi_int(display_set_handle, NULL, value))
  636. pr_warning("Error setting display\n");
  637. return;
  638. }
  639. static int read_display(void)
  640. {
  641. unsigned long long value = 0;
  642. acpi_status rv = AE_OK;
  643. /*
  644. * In most of the case, we know how to set the display, but sometime
  645. * we can't read it
  646. */
  647. if (display_get_handle) {
  648. rv = acpi_evaluate_integer(display_get_handle, NULL,
  649. NULL, &value);
  650. if (ACPI_FAILURE(rv))
  651. pr_warning("Error reading display status\n");
  652. }
  653. value &= 0x0F; /* needed for some models, shouldn't hurt others */
  654. return value;
  655. }
  656. /*
  657. * Now, *this* one could be more user-friendly, but so far, no-one has
  658. * complained. The significance of bits is the same as in store_disp()
  659. */
  660. static ssize_t show_disp(struct device *dev,
  661. struct device_attribute *attr, char *buf)
  662. {
  663. return sprintf(buf, "%d\n", read_display());
  664. }
  665. /*
  666. * Experimental support for display switching. As of now: 1 should activate
  667. * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
  668. * Any combination (bitwise) of these will suffice. I never actually tested 4
  669. * displays hooked up simultaneously, so be warned. See the acpi4asus README
  670. * for more info.
  671. */
  672. static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
  673. const char *buf, size_t count)
  674. {
  675. int rv, value;
  676. rv = parse_arg(buf, count, &value);
  677. if (rv > 0)
  678. set_display(value);
  679. return rv;
  680. }
  681. /*
  682. * Light Sens
  683. */
  684. static void set_light_sens_switch(int value)
  685. {
  686. if (write_acpi_int(ls_switch_handle, NULL, value))
  687. pr_warning("Error setting light sensor switch\n");
  688. hotk->light_switch = value;
  689. }
  690. static ssize_t show_lssw(struct device *dev,
  691. struct device_attribute *attr, char *buf)
  692. {
  693. return sprintf(buf, "%d\n", hotk->light_switch);
  694. }
  695. static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
  696. const char *buf, size_t count)
  697. {
  698. int rv, value;
  699. rv = parse_arg(buf, count, &value);
  700. if (rv > 0)
  701. set_light_sens_switch(value ? 1 : 0);
  702. return rv;
  703. }
  704. static void set_light_sens_level(int value)
  705. {
  706. if (write_acpi_int(ls_level_handle, NULL, value))
  707. pr_warning("Error setting light sensor level\n");
  708. hotk->light_level = value;
  709. }
  710. static ssize_t show_lslvl(struct device *dev,
  711. struct device_attribute *attr, char *buf)
  712. {
  713. return sprintf(buf, "%d\n", hotk->light_level);
  714. }
  715. static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
  716. const char *buf, size_t count)
  717. {
  718. int rv, value;
  719. rv = parse_arg(buf, count, &value);
  720. if (rv > 0) {
  721. value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
  722. /* 0 <= value <= 15 */
  723. set_light_sens_level(value);
  724. }
  725. return rv;
  726. }
  727. /*
  728. * GPS
  729. */
  730. static ssize_t show_gps(struct device *dev,
  731. struct device_attribute *attr, char *buf)
  732. {
  733. return sprintf(buf, "%d\n", read_status(GPS_ON));
  734. }
  735. static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
  736. const char *buf, size_t count)
  737. {
  738. return store_status(buf, count, NULL, GPS_ON);
  739. }
  740. /*
  741. * Hotkey functions
  742. */
  743. static struct key_entry *asus_get_entry_by_scancode(int code)
  744. {
  745. struct key_entry *key;
  746. for (key = asus_keymap; key->type != KE_END; key++)
  747. if (code == key->code)
  748. return key;
  749. return NULL;
  750. }
  751. static struct key_entry *asus_get_entry_by_keycode(int code)
  752. {
  753. struct key_entry *key;
  754. for (key = asus_keymap; key->type != KE_END; key++)
  755. if (code == key->keycode && key->type == KE_KEY)
  756. return key;
  757. return NULL;
  758. }
  759. static int asus_getkeycode(struct input_dev *dev, int scancode, int *keycode)
  760. {
  761. struct key_entry *key = asus_get_entry_by_scancode(scancode);
  762. if (key && key->type == KE_KEY) {
  763. *keycode = key->keycode;
  764. return 0;
  765. }
  766. return -EINVAL;
  767. }
  768. static int asus_setkeycode(struct input_dev *dev, int scancode, int keycode)
  769. {
  770. struct key_entry *key;
  771. int old_keycode;
  772. if (keycode < 0 || keycode > KEY_MAX)
  773. return -EINVAL;
  774. key = asus_get_entry_by_scancode(scancode);
  775. if (key && key->type == KE_KEY) {
  776. old_keycode = key->keycode;
  777. key->keycode = keycode;
  778. set_bit(keycode, dev->keybit);
  779. if (!asus_get_entry_by_keycode(old_keycode))
  780. clear_bit(old_keycode, dev->keybit);
  781. return 0;
  782. }
  783. return -EINVAL;
  784. }
  785. static void asus_acpi_notify(struct acpi_device *device, u32 event)
  786. {
  787. static struct key_entry *key;
  788. u16 count;
  789. /*
  790. * We need to tell the backlight device when the backlight power is
  791. * switched
  792. */
  793. if (event == ATKD_LCD_ON) {
  794. write_status(NULL, 1, LCD_ON);
  795. lcd_blank(FB_BLANK_UNBLANK);
  796. } else if (event == ATKD_LCD_OFF) {
  797. write_status(NULL, 0, LCD_ON);
  798. lcd_blank(FB_BLANK_POWERDOWN);
  799. }
  800. /* TODO Find a better way to handle events count. */
  801. count = hotk->event_count[event % 128]++;
  802. acpi_bus_generate_proc_event(hotk->device, event, count);
  803. acpi_bus_generate_netlink_event(hotk->device->pnp.device_class,
  804. dev_name(&hotk->device->dev), event,
  805. count);
  806. if (hotk->inputdev) {
  807. key = asus_get_entry_by_scancode(event);
  808. if (!key)
  809. return ;
  810. switch (key->type) {
  811. case KE_KEY:
  812. input_report_key(hotk->inputdev, key->keycode, 1);
  813. input_sync(hotk->inputdev);
  814. input_report_key(hotk->inputdev, key->keycode, 0);
  815. input_sync(hotk->inputdev);
  816. break;
  817. }
  818. }
  819. }
  820. #define ASUS_CREATE_DEVICE_ATTR(_name) \
  821. struct device_attribute dev_attr_##_name = { \
  822. .attr = { \
  823. .name = __stringify(_name), \
  824. .mode = 0 }, \
  825. .show = NULL, \
  826. .store = NULL, \
  827. }
  828. #define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \
  829. do { \
  830. dev_attr_##_name.attr.mode = _mode; \
  831. dev_attr_##_name.show = _show; \
  832. dev_attr_##_name.store = _store; \
  833. } while(0)
  834. static ASUS_CREATE_DEVICE_ATTR(infos);
  835. static ASUS_CREATE_DEVICE_ATTR(wlan);
  836. static ASUS_CREATE_DEVICE_ATTR(bluetooth);
  837. static ASUS_CREATE_DEVICE_ATTR(display);
  838. static ASUS_CREATE_DEVICE_ATTR(ledd);
  839. static ASUS_CREATE_DEVICE_ATTR(ls_switch);
  840. static ASUS_CREATE_DEVICE_ATTR(ls_level);
  841. static ASUS_CREATE_DEVICE_ATTR(gps);
  842. static struct attribute *asuspf_attributes[] = {
  843. &dev_attr_infos.attr,
  844. &dev_attr_wlan.attr,
  845. &dev_attr_bluetooth.attr,
  846. &dev_attr_display.attr,
  847. &dev_attr_ledd.attr,
  848. &dev_attr_ls_switch.attr,
  849. &dev_attr_ls_level.attr,
  850. &dev_attr_gps.attr,
  851. NULL
  852. };
  853. static struct attribute_group platform_attribute_group = {
  854. .attrs = asuspf_attributes
  855. };
  856. static int asus_platform_init(void)
  857. {
  858. int result;
  859. hotk->platform_device = platform_device_alloc(ASUS_HOTK_FILE, -1);
  860. if (!hotk->platform_device)
  861. return -ENOMEM;
  862. result = platform_device_add(hotk->platform_device);
  863. if (result)
  864. goto fail_platform_device;
  865. result = sysfs_create_group(&hotk->platform_device->dev.kobj,
  866. &platform_attribute_group);
  867. if (result)
  868. goto fail_sysfs;
  869. return 0;
  870. fail_sysfs:
  871. platform_device_del(hotk->platform_device);
  872. fail_platform_device:
  873. platform_device_put(hotk->platform_device);
  874. return result;
  875. }
  876. static void asus_platform_exit(void)
  877. {
  878. sysfs_remove_group(&hotk->platform_device->dev.kobj,
  879. &platform_attribute_group);
  880. platform_device_unregister(hotk->platform_device);
  881. }
  882. static struct platform_driver platform_driver = {
  883. .driver = {
  884. .name = ASUS_HOTK_FILE,
  885. .owner = THIS_MODULE,
  886. }
  887. };
  888. static void asus_hotk_add_fs(void)
  889. {
  890. ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL);
  891. if (wl_switch_handle)
  892. ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan);
  893. if (bt_switch_handle)
  894. ASUS_SET_DEVICE_ATTR(bluetooth, 0644,
  895. show_bluetooth, store_bluetooth);
  896. if (display_set_handle && display_get_handle)
  897. ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp);
  898. else if (display_set_handle)
  899. ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp);
  900. if (ledd_set_handle)
  901. ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd);
  902. if (ls_switch_handle && ls_level_handle) {
  903. ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
  904. ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
  905. }
  906. if (gps_status_handle && gps_on_handle && gps_off_handle)
  907. ASUS_SET_DEVICE_ATTR(gps, 0644, show_gps, store_gps);
  908. }
  909. static int asus_handle_init(char *name, acpi_handle * handle,
  910. char **paths, int num_paths)
  911. {
  912. int i;
  913. acpi_status status;
  914. for (i = 0; i < num_paths; i++) {
  915. status = acpi_get_handle(NULL, paths[i], handle);
  916. if (ACPI_SUCCESS(status))
  917. return 0;
  918. }
  919. *handle = NULL;
  920. return -ENODEV;
  921. }
  922. #define ASUS_HANDLE_INIT(object) \
  923. asus_handle_init(#object, &object##_handle, object##_paths, \
  924. ARRAY_SIZE(object##_paths))
  925. /*
  926. * This function is used to initialize the hotk with right values. In this
  927. * method, we can make all the detection we want, and modify the hotk struct
  928. */
  929. static int asus_hotk_get_info(void)
  930. {
  931. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  932. union acpi_object *model = NULL;
  933. unsigned long long bsts_result, hwrs_result;
  934. char *string = NULL;
  935. acpi_status status;
  936. /*
  937. * Get DSDT headers early enough to allow for differentiating between
  938. * models, but late enough to allow acpi_bus_register_driver() to fail
  939. * before doing anything ACPI-specific. Should we encounter a machine,
  940. * which needs special handling (i.e. its hotkey device has a different
  941. * HID), this bit will be moved. A global variable asus_info contains
  942. * the DSDT header.
  943. */
  944. status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
  945. if (ACPI_FAILURE(status))
  946. pr_warning("Couldn't get the DSDT table header\n");
  947. /* We have to write 0 on init this far for all ASUS models */
  948. if (write_acpi_int_ret(hotk->handle, "INIT", 0, &buffer)) {
  949. pr_err("Hotkey initialization failed\n");
  950. return -ENODEV;
  951. }
  952. /* This needs to be called for some laptops to init properly */
  953. status =
  954. acpi_evaluate_integer(hotk->handle, "BSTS", NULL, &bsts_result);
  955. if (ACPI_FAILURE(status))
  956. pr_warning("Error calling BSTS\n");
  957. else if (bsts_result)
  958. pr_notice("BSTS called, 0x%02x returned\n",
  959. (uint) bsts_result);
  960. /* This too ... */
  961. write_acpi_int(hotk->handle, "CWAP", wapf);
  962. /*
  963. * Try to match the object returned by INIT to the specific model.
  964. * Handle every possible object (or the lack of thereof) the DSDT
  965. * writers might throw at us. When in trouble, we pass NULL to
  966. * asus_model_match() and try something completely different.
  967. */
  968. if (buffer.pointer) {
  969. model = buffer.pointer;
  970. switch (model->type) {
  971. case ACPI_TYPE_STRING:
  972. string = model->string.pointer;
  973. break;
  974. case ACPI_TYPE_BUFFER:
  975. string = model->buffer.pointer;
  976. break;
  977. default:
  978. string = "";
  979. break;
  980. }
  981. }
  982. hotk->name = kstrdup(string, GFP_KERNEL);
  983. if (!hotk->name)
  984. return -ENOMEM;
  985. if (*string)
  986. pr_notice(" %s model detected\n", string);
  987. ASUS_HANDLE_INIT(mled_set);
  988. ASUS_HANDLE_INIT(tled_set);
  989. ASUS_HANDLE_INIT(rled_set);
  990. ASUS_HANDLE_INIT(pled_set);
  991. ASUS_HANDLE_INIT(gled_set);
  992. ASUS_HANDLE_INIT(ledd_set);
  993. ASUS_HANDLE_INIT(kled_set);
  994. ASUS_HANDLE_INIT(kled_get);
  995. /*
  996. * The HWRS method return informations about the hardware.
  997. * 0x80 bit is for WLAN, 0x100 for Bluetooth.
  998. * The significance of others is yet to be found.
  999. * If we don't find the method, we assume the device are present.
  1000. */
  1001. status =
  1002. acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &hwrs_result);
  1003. if (ACPI_FAILURE(status))
  1004. hwrs_result = WL_HWRS | BT_HWRS;
  1005. if (hwrs_result & WL_HWRS)
  1006. ASUS_HANDLE_INIT(wl_switch);
  1007. if (hwrs_result & BT_HWRS)
  1008. ASUS_HANDLE_INIT(bt_switch);
  1009. ASUS_HANDLE_INIT(wireless_status);
  1010. ASUS_HANDLE_INIT(brightness_set);
  1011. ASUS_HANDLE_INIT(brightness_get);
  1012. ASUS_HANDLE_INIT(lcd_switch);
  1013. ASUS_HANDLE_INIT(display_set);
  1014. ASUS_HANDLE_INIT(display_get);
  1015. /*
  1016. * There is a lot of models with "ALSL", but a few get
  1017. * a real light sens, so we need to check it.
  1018. */
  1019. if (!ASUS_HANDLE_INIT(ls_switch))
  1020. ASUS_HANDLE_INIT(ls_level);
  1021. ASUS_HANDLE_INIT(gps_on);
  1022. ASUS_HANDLE_INIT(gps_off);
  1023. ASUS_HANDLE_INIT(gps_status);
  1024. kfree(model);
  1025. return AE_OK;
  1026. }
  1027. static int asus_input_init(struct device *dev)
  1028. {
  1029. const struct key_entry *key;
  1030. int result;
  1031. hotk->inputdev = input_allocate_device();
  1032. if (!hotk->inputdev) {
  1033. pr_info("Unable to allocate input device\n");
  1034. return 0;
  1035. }
  1036. hotk->inputdev->name = "Asus Laptop extra buttons";
  1037. hotk->inputdev->dev.parent = dev;
  1038. hotk->inputdev->phys = ASUS_HOTK_FILE "/input0";
  1039. hotk->inputdev->id.bustype = BUS_HOST;
  1040. hotk->inputdev->getkeycode = asus_getkeycode;
  1041. hotk->inputdev->setkeycode = asus_setkeycode;
  1042. for (key = asus_keymap; key->type != KE_END; key++) {
  1043. switch (key->type) {
  1044. case KE_KEY:
  1045. set_bit(EV_KEY, hotk->inputdev->evbit);
  1046. set_bit(key->keycode, hotk->inputdev->keybit);
  1047. break;
  1048. }
  1049. }
  1050. result = input_register_device(hotk->inputdev);
  1051. if (result) {
  1052. pr_info("Unable to register input device\n");
  1053. input_free_device(hotk->inputdev);
  1054. }
  1055. return result;
  1056. }
  1057. static void asus_backlight_exit(void)
  1058. {
  1059. if (asus_backlight_device)
  1060. backlight_device_unregister(asus_backlight_device);
  1061. }
  1062. #define ASUS_LED_UNREGISTER(object) \
  1063. if (object##_led.dev) \
  1064. led_classdev_unregister(&object##_led)
  1065. static void asus_led_exit(void)
  1066. {
  1067. destroy_workqueue(led_workqueue);
  1068. ASUS_LED_UNREGISTER(mled);
  1069. ASUS_LED_UNREGISTER(tled);
  1070. ASUS_LED_UNREGISTER(pled);
  1071. ASUS_LED_UNREGISTER(rled);
  1072. ASUS_LED_UNREGISTER(gled);
  1073. ASUS_LED_UNREGISTER(kled);
  1074. }
  1075. static void asus_input_exit(void)
  1076. {
  1077. if (hotk->inputdev)
  1078. input_unregister_device(hotk->inputdev);
  1079. }
  1080. static int asus_backlight_init(struct device *dev)
  1081. {
  1082. struct backlight_device *bd;
  1083. if (brightness_set_handle && lcd_switch_handle) {
  1084. bd = backlight_device_register(ASUS_HOTK_FILE, dev,
  1085. NULL, &asusbl_ops);
  1086. if (IS_ERR(bd)) {
  1087. pr_err("Could not register asus backlight device\n");
  1088. asus_backlight_device = NULL;
  1089. return PTR_ERR(bd);
  1090. }
  1091. asus_backlight_device = bd;
  1092. bd->props.max_brightness = 15;
  1093. bd->props.brightness = read_brightness(NULL);
  1094. bd->props.power = FB_BLANK_UNBLANK;
  1095. backlight_update_status(bd);
  1096. }
  1097. return 0;
  1098. }
  1099. static int asus_led_register(acpi_handle handle,
  1100. struct led_classdev *ldev, struct device *dev)
  1101. {
  1102. if (!handle)
  1103. return 0;
  1104. return led_classdev_register(dev, ldev);
  1105. }
  1106. #define ASUS_LED_REGISTER(object, device) \
  1107. asus_led_register(object##_set_handle, &object##_led, device)
  1108. static int asus_led_init(struct device *dev)
  1109. {
  1110. int rv;
  1111. rv = ASUS_LED_REGISTER(mled, dev);
  1112. if (rv)
  1113. goto out;
  1114. rv = ASUS_LED_REGISTER(tled, dev);
  1115. if (rv)
  1116. goto out1;
  1117. rv = ASUS_LED_REGISTER(rled, dev);
  1118. if (rv)
  1119. goto out2;
  1120. rv = ASUS_LED_REGISTER(pled, dev);
  1121. if (rv)
  1122. goto out3;
  1123. rv = ASUS_LED_REGISTER(gled, dev);
  1124. if (rv)
  1125. goto out4;
  1126. if (kled_set_handle && kled_get_handle)
  1127. rv = ASUS_LED_REGISTER(kled, dev);
  1128. if (rv)
  1129. goto out5;
  1130. led_workqueue = create_singlethread_workqueue("led_workqueue");
  1131. if (!led_workqueue)
  1132. goto out6;
  1133. return 0;
  1134. out6:
  1135. rv = -ENOMEM;
  1136. ASUS_LED_UNREGISTER(kled);
  1137. out5:
  1138. ASUS_LED_UNREGISTER(gled);
  1139. out4:
  1140. ASUS_LED_UNREGISTER(pled);
  1141. out3:
  1142. ASUS_LED_UNREGISTER(rled);
  1143. out2:
  1144. ASUS_LED_UNREGISTER(tled);
  1145. out1:
  1146. ASUS_LED_UNREGISTER(mled);
  1147. out:
  1148. return rv;
  1149. }
  1150. static bool asus_device_present;
  1151. static int __devinit asus_acpi_init(struct acpi_device *device)
  1152. {
  1153. int result = 0;
  1154. result = acpi_bus_get_status(hotk->device);
  1155. if (result)
  1156. return result;
  1157. if (!hotk->device->status.present) {
  1158. pr_err("Hotkey device not present, aborting\n");
  1159. return -ENODEV;
  1160. }
  1161. result = asus_hotk_get_info();
  1162. if (result)
  1163. return result;
  1164. asus_hotk_add_fs();
  1165. /* WLED and BLED are on by default */
  1166. write_status(bt_switch_handle, 1, BT_ON);
  1167. write_status(wl_switch_handle, 1, WL_ON);
  1168. /* If the h/w switch is off, we need to check the real status */
  1169. write_status(NULL, read_status(BT_ON), BT_ON);
  1170. write_status(NULL, read_status(WL_ON), WL_ON);
  1171. /* LCD Backlight is on by default */
  1172. write_status(NULL, 1, LCD_ON);
  1173. /* Keyboard Backlight is on by default */
  1174. if (kled_set_handle)
  1175. set_kled_lvl(1);
  1176. /* LED display is off by default */
  1177. hotk->ledd_status = 0xFFF;
  1178. /* Set initial values of light sensor and level */
  1179. hotk->light_switch = 0; /* Default to light sensor disabled */
  1180. hotk->light_level = 5; /* level 5 for sensor sensitivity */
  1181. if (ls_switch_handle)
  1182. set_light_sens_switch(hotk->light_switch);
  1183. if (ls_level_handle)
  1184. set_light_sens_level(hotk->light_level);
  1185. /* GPS is on by default */
  1186. write_status(NULL, 1, GPS_ON);
  1187. return result;
  1188. }
  1189. static int __devinit asus_acpi_add(struct acpi_device *device)
  1190. {
  1191. int result;
  1192. pr_notice("Asus Laptop Support version %s\n",
  1193. ASUS_LAPTOP_VERSION);
  1194. hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL);
  1195. if (!hotk)
  1196. return -ENOMEM;
  1197. hotk->handle = device->handle;
  1198. strcpy(acpi_device_name(device), ASUS_HOTK_DEVICE_NAME);
  1199. strcpy(acpi_device_class(device), ASUS_HOTK_CLASS);
  1200. device->driver_data = hotk;
  1201. hotk->device = device;
  1202. result = asus_acpi_init(device);
  1203. if (result)
  1204. goto fail_platform;
  1205. /*
  1206. * Register the platform device first. It is used as a parent for the
  1207. * sub-devices below.
  1208. */
  1209. result = asus_platform_init();
  1210. if (result)
  1211. goto fail_platform;
  1212. if (!acpi_video_backlight_support()) {
  1213. result = asus_backlight_init(&hotk->platform_device->dev);
  1214. if (result)
  1215. goto fail_backlight;
  1216. } else
  1217. pr_info("Backlight controlled by ACPI video driver\n");
  1218. result = asus_input_init(&hotk->platform_device->dev);
  1219. if (result)
  1220. goto fail_input;
  1221. result = asus_led_init(&hotk->platform_device->dev);
  1222. if (result)
  1223. goto fail_led;
  1224. asus_device_present = true;
  1225. return 0;
  1226. fail_led:
  1227. asus_input_exit();
  1228. fail_input:
  1229. asus_backlight_exit();
  1230. fail_backlight:
  1231. asus_platform_exit();
  1232. fail_platform:
  1233. kfree(hotk->name);
  1234. kfree(hotk);
  1235. return result;
  1236. }
  1237. static int asus_acpi_remove(struct acpi_device *device, int type)
  1238. {
  1239. asus_backlight_exit();
  1240. asus_led_exit();
  1241. asus_input_exit();
  1242. asus_platform_exit();
  1243. kfree(hotk->name);
  1244. kfree(hotk);
  1245. return 0;
  1246. }
  1247. static const struct acpi_device_id asus_device_ids[] = {
  1248. {"ATK0100", 0},
  1249. {"ATK0101", 0},
  1250. {"", 0},
  1251. };
  1252. MODULE_DEVICE_TABLE(acpi, asus_device_ids);
  1253. static struct acpi_driver asus_acpi_driver = {
  1254. .name = ASUS_HOTK_NAME,
  1255. .class = ASUS_HOTK_CLASS,
  1256. .owner = THIS_MODULE,
  1257. .ids = asus_device_ids,
  1258. .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
  1259. .ops = {
  1260. .add = asus_acpi_add,
  1261. .remove = asus_acpi_remove,
  1262. .notify = asus_acpi_notify,
  1263. },
  1264. };
  1265. static int __init asus_laptop_init(void)
  1266. {
  1267. int result;
  1268. result = platform_driver_register(&platform_driver);
  1269. if (result < 0)
  1270. return result;
  1271. result = acpi_bus_register_driver(&asus_acpi_driver);
  1272. if (result < 0)
  1273. goto fail_acpi_driver;
  1274. if (!asus_device_present) {
  1275. result = -ENODEV;
  1276. goto fail_no_device;
  1277. }
  1278. return 0;
  1279. fail_no_device:
  1280. acpi_bus_unregister_driver(&asus_acpi_driver);
  1281. fail_acpi_driver:
  1282. platform_driver_unregister(&platform_driver);
  1283. return result;
  1284. }
  1285. static void __exit asus_laptop_exit(void)
  1286. {
  1287. acpi_bus_unregister_driver(&asus_acpi_driver);
  1288. platform_driver_unregister(&platform_driver);
  1289. }
  1290. module_init(asus_laptop_init);
  1291. module_exit(asus_laptop_exit);