asus-laptop.c 36 KB

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