asus-laptop.c 39 KB

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