asus-laptop.c 36 KB

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