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