asus-laptop.c 36 KB

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