asus-laptop.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  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 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. *
  34. */
  35. #include <linux/autoconf.h>
  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/leds.h>
  43. #include <linux/platform_device.h>
  44. #include <acpi/acpi_drivers.h>
  45. #include <acpi/acpi_bus.h>
  46. #include <asm/uaccess.h>
  47. #define ASUS_LAPTOP_VERSION "0.40"
  48. #define ASUS_HOTK_NAME "Asus Laptop Support"
  49. #define ASUS_HOTK_CLASS "hotkey"
  50. #define ASUS_HOTK_DEVICE_NAME "Hotkey"
  51. #define ASUS_HOTK_HID "ATK0100"
  52. #define ASUS_HOTK_FILE "asus-laptop"
  53. #define ASUS_HOTK_PREFIX "\\_SB.ATKD."
  54. /*
  55. * Known bits returned by \_SB.ATKD.HWRS
  56. */
  57. #define WL_HWRS 0x80
  58. #define BT_HWRS 0x100
  59. /*
  60. * Flags for hotk status
  61. * WL_ON and BT_ON are also used for wireless_status()
  62. */
  63. #define WL_ON 0x01 //internal Wifi
  64. #define BT_ON 0x02 //internal Bluetooth
  65. #define MLED_ON 0x04 //mail LED
  66. #define TLED_ON 0x08 //touchpad LED
  67. #define RLED_ON 0x10 //Record LED
  68. #define PLED_ON 0x20 //Phone LED
  69. #define ASUS_LOG ASUS_HOTK_FILE ": "
  70. #define ASUS_ERR KERN_ERR ASUS_LOG
  71. #define ASUS_WARNING KERN_WARNING ASUS_LOG
  72. #define ASUS_NOTICE KERN_NOTICE ASUS_LOG
  73. #define ASUS_INFO KERN_INFO ASUS_LOG
  74. #define ASUS_DEBUG KERN_DEBUG ASUS_LOG
  75. MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
  76. MODULE_DESCRIPTION(ASUS_HOTK_NAME);
  77. MODULE_LICENSE("GPL");
  78. #define ASUS_HANDLE(object, paths...) \
  79. static acpi_handle object##_handle = NULL; \
  80. static char *object##_paths[] = { paths }
  81. /* LED */
  82. ASUS_HANDLE(mled_set, ASUS_HOTK_PREFIX "MLED");
  83. ASUS_HANDLE(tled_set, ASUS_HOTK_PREFIX "TLED");
  84. ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED"); /* W1JC */
  85. ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED"); /* A7J */
  86. /* Bluetooth and WLAN
  87. * WLED and BLED are not handled like other XLED, because in some dsdt
  88. * they also control the WLAN/Bluetooth device.
  89. */
  90. ASUS_HANDLE(wl_switch, ASUS_HOTK_PREFIX "WLED");
  91. ASUS_HANDLE(bt_switch, ASUS_HOTK_PREFIX "BLED");
  92. ASUS_HANDLE(wireless_status, ASUS_HOTK_PREFIX "RSTS"); /* All new models */
  93. /*
  94. * This is the main structure, we can use it to store anything interesting
  95. * about the hotk device
  96. */
  97. struct asus_hotk {
  98. char *name; //laptop name
  99. struct acpi_device *device; //the device we are in
  100. acpi_handle handle; //the handle of the hotk device
  101. char status; //status of the hotk, for LEDs, ...
  102. u16 event_count[128]; //count for each event TODO make this better
  103. };
  104. /*
  105. * This header is made available to allow proper configuration given model,
  106. * revision number , ... this info cannot go in struct asus_hotk because it is
  107. * available before the hotk
  108. */
  109. static struct acpi_table_header *asus_info;
  110. /* The actual device the driver binds to */
  111. static struct asus_hotk *hotk;
  112. /*
  113. * The hotkey driver declaration
  114. */
  115. static int asus_hotk_add(struct acpi_device *device);
  116. static int asus_hotk_remove(struct acpi_device *device, int type);
  117. static struct acpi_driver asus_hotk_driver = {
  118. .name = ASUS_HOTK_NAME,
  119. .class = ASUS_HOTK_CLASS,
  120. .ids = ASUS_HOTK_HID,
  121. .ops = {
  122. .add = asus_hotk_add,
  123. .remove = asus_hotk_remove,
  124. },
  125. };
  126. /* These functions actually update the LED's, and are called from a
  127. * workqueue. By doing this as separate work rather than when the LED
  128. * subsystem asks, we avoid messing with the Asus ACPI stuff during a
  129. * potentially bad time, such as a timer interrupt. */
  130. static struct workqueue_struct *led_workqueue;
  131. #define ASUS_LED(object, ledname) \
  132. static void object##_led_set(struct led_classdev *led_cdev, \
  133. enum led_brightness value); \
  134. static void object##_led_update(struct work_struct *ignored); \
  135. static int object##_led_wk; \
  136. DECLARE_WORK(object##_led_work, object##_led_update); \
  137. static struct led_classdev object##_led = { \
  138. .name = "asus:" ledname, \
  139. .brightness_set = object##_led_set, \
  140. }
  141. ASUS_LED(mled, "mail");
  142. ASUS_LED(tled, "touchpad");
  143. ASUS_LED(rled, "record");
  144. ASUS_LED(pled, "phone");
  145. /*
  146. * This function evaluates an ACPI method, given an int as parameter, the
  147. * method is searched within the scope of the handle, can be NULL. The output
  148. * of the method is written is output, which can also be NULL
  149. *
  150. * returns 1 if write is successful, 0 else.
  151. */
  152. static int write_acpi_int(acpi_handle handle, const char *method, int val,
  153. struct acpi_buffer *output)
  154. {
  155. struct acpi_object_list params; //list of input parameters (an int here)
  156. union acpi_object in_obj; //the only param we use
  157. acpi_status status;
  158. params.count = 1;
  159. params.pointer = &in_obj;
  160. in_obj.type = ACPI_TYPE_INTEGER;
  161. in_obj.integer.value = val;
  162. status = acpi_evaluate_object(handle, (char *)method, &params, output);
  163. return (status == AE_OK);
  164. }
  165. static int read_acpi_int(acpi_handle handle, const char *method, int *val,
  166. struct acpi_object_list *params)
  167. {
  168. struct acpi_buffer output;
  169. union acpi_object out_obj;
  170. acpi_status status;
  171. output.length = sizeof(out_obj);
  172. output.pointer = &out_obj;
  173. status = acpi_evaluate_object(handle, (char *)method, params, &output);
  174. *val = out_obj.integer.value;
  175. return (status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER);
  176. }
  177. static int read_wireless_status(int mask) {
  178. int status;
  179. if (!wireless_status_handle)
  180. return (hotk->status & mask) ? 1 : 0;
  181. if (read_acpi_int(wireless_status_handle, NULL, &status, NULL)) {
  182. return (status & mask) ? 1 : 0;
  183. } else
  184. printk(ASUS_WARNING "Error reading Wireless status\n");
  185. return (hotk->status & mask) ? 1 : 0;
  186. }
  187. /* Generic LED functions */
  188. static int read_status(int mask)
  189. {
  190. /* There is a special method for both wireless devices */
  191. if (mask == BT_ON || mask == WL_ON)
  192. return read_wireless_status(mask);
  193. return (hotk->status & mask) ? 1 : 0;
  194. }
  195. static void write_status(acpi_handle handle, int out, int mask,
  196. int invert)
  197. {
  198. hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask);
  199. if (invert) /* invert target value */
  200. out = !out & 0x1;
  201. if (handle && !write_acpi_int(handle, NULL, out, NULL))
  202. printk(ASUS_WARNING " write failed\n");
  203. }
  204. /* /sys/class/led handlers */
  205. #define ASUS_LED_HANDLER(object, mask, invert) \
  206. static void object##_led_set(struct led_classdev *led_cdev, \
  207. enum led_brightness value) \
  208. { \
  209. object##_led_wk = value; \
  210. queue_work(led_workqueue, &object##_led_work); \
  211. } \
  212. static void object##_led_update(struct work_struct *ignored) \
  213. { \
  214. int value = object##_led_wk; \
  215. write_status(object##_set_handle, value, (mask), (invert)); \
  216. }
  217. ASUS_LED_HANDLER(mled, MLED_ON, 1);
  218. ASUS_LED_HANDLER(pled, PLED_ON, 0);
  219. ASUS_LED_HANDLER(rled, RLED_ON, 0);
  220. ASUS_LED_HANDLER(tled, TLED_ON, 0);
  221. /*
  222. * Platform device handlers
  223. */
  224. /*
  225. * We write our info in page, we begin at offset off and cannot write more
  226. * than count bytes. We set eof to 1 if we handle those 2 values. We return the
  227. * number of bytes written in page
  228. */
  229. static ssize_t show_infos(struct device *dev,
  230. struct device_attribute *attr, char *page)
  231. {
  232. int len = 0;
  233. int temp;
  234. char buf[16]; //enough for all info
  235. /*
  236. * We use the easy way, we don't care of off and count, so we don't set eof
  237. * to 1
  238. */
  239. len += sprintf(page, ASUS_HOTK_NAME " " ASUS_LAPTOP_VERSION "\n");
  240. len += sprintf(page + len, "Model reference : %s\n", hotk->name);
  241. /*
  242. * The SFUN method probably allows the original driver to get the list
  243. * of features supported by a given model. For now, 0x0100 or 0x0800
  244. * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
  245. * The significance of others is yet to be found.
  246. */
  247. if (read_acpi_int(hotk->handle, "SFUN", &temp, NULL))
  248. len +=
  249. sprintf(page + len, "SFUN value : 0x%04x\n", temp);
  250. /*
  251. * Another value for userspace: the ASYM method returns 0x02 for
  252. * battery low and 0x04 for battery critical, its readings tend to be
  253. * more accurate than those provided by _BST.
  254. * Note: since not all the laptops provide this method, errors are
  255. * silently ignored.
  256. */
  257. if (read_acpi_int(hotk->handle, "ASYM", &temp, NULL))
  258. len +=
  259. sprintf(page + len, "ASYM value : 0x%04x\n", temp);
  260. if (asus_info) {
  261. snprintf(buf, 16, "%d", asus_info->length);
  262. len += sprintf(page + len, "DSDT length : %s\n", buf);
  263. snprintf(buf, 16, "%d", asus_info->checksum);
  264. len += sprintf(page + len, "DSDT checksum : %s\n", buf);
  265. snprintf(buf, 16, "%d", asus_info->revision);
  266. len += sprintf(page + len, "DSDT revision : %s\n", buf);
  267. snprintf(buf, 7, "%s", asus_info->oem_id);
  268. len += sprintf(page + len, "OEM id : %s\n", buf);
  269. snprintf(buf, 9, "%s", asus_info->oem_table_id);
  270. len += sprintf(page + len, "OEM table id : %s\n", buf);
  271. snprintf(buf, 16, "%x", asus_info->oem_revision);
  272. len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
  273. snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
  274. len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
  275. snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
  276. len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
  277. }
  278. return len;
  279. }
  280. static int parse_arg(const char *buf, unsigned long count, int *val)
  281. {
  282. if (!count)
  283. return 0;
  284. if (count > 31)
  285. return -EINVAL;
  286. if (sscanf(buf, "%i", val) != 1)
  287. return -EINVAL;
  288. return count;
  289. }
  290. static ssize_t store_status(const char *buf, size_t count,
  291. acpi_handle handle, int mask, int invert)
  292. {
  293. int rv, value;
  294. int out = 0;
  295. rv = parse_arg(buf, count, &value);
  296. if (rv > 0)
  297. out = value ? 1 : 0;
  298. write_status(handle, out, mask, invert);
  299. return rv;
  300. }
  301. /*
  302. * WLAN
  303. */
  304. static ssize_t show_wlan(struct device *dev,
  305. struct device_attribute *attr, char *buf)
  306. {
  307. return sprintf(buf, "%d\n", read_status(WL_ON));
  308. }
  309. static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
  310. const char *buf, size_t count)
  311. {
  312. return store_status(buf, count, wl_switch_handle, WL_ON, 0);
  313. }
  314. /*
  315. * Bluetooth
  316. */
  317. static ssize_t show_bluetooth(struct device *dev,
  318. struct device_attribute *attr, char *buf)
  319. {
  320. return sprintf(buf, "%d\n", read_status(BT_ON));
  321. }
  322. static ssize_t store_bluetooth(struct device *dev, struct device_attribute *attr,
  323. const char *buf, size_t count)
  324. {
  325. return store_status(buf, count, bt_switch_handle, BT_ON, 0);
  326. }
  327. static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
  328. {
  329. /* TODO Find a better way to handle events count. */
  330. if (!hotk)
  331. return;
  332. acpi_bus_generate_event(hotk->device, event,
  333. hotk->event_count[event % 128]++);
  334. return;
  335. }
  336. #define ASUS_CREATE_DEVICE_ATTR(_name) \
  337. struct device_attribute dev_attr_##_name = { \
  338. .attr = { \
  339. .name = __stringify(_name), \
  340. .mode = 0, \
  341. .owner = THIS_MODULE }, \
  342. .show = NULL, \
  343. .store = NULL, \
  344. }
  345. #define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \
  346. do { \
  347. dev_attr_##_name.attr.mode = _mode; \
  348. dev_attr_##_name.show = _show; \
  349. dev_attr_##_name.store = _store; \
  350. } while(0)
  351. static ASUS_CREATE_DEVICE_ATTR(infos);
  352. static ASUS_CREATE_DEVICE_ATTR(wlan);
  353. static ASUS_CREATE_DEVICE_ATTR(bluetooth);
  354. static struct attribute *asuspf_attributes[] = {
  355. &dev_attr_infos.attr,
  356. &dev_attr_wlan.attr,
  357. &dev_attr_bluetooth.attr,
  358. NULL
  359. };
  360. static struct attribute_group asuspf_attribute_group = {
  361. .attrs = asuspf_attributes
  362. };
  363. static struct platform_driver asuspf_driver = {
  364. .driver = {
  365. .name = ASUS_HOTK_FILE,
  366. .owner = THIS_MODULE,
  367. }
  368. };
  369. static struct platform_device *asuspf_device;
  370. static void asus_hotk_add_fs(void)
  371. {
  372. ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL);
  373. if (wl_switch_handle)
  374. ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan);
  375. if (bt_switch_handle)
  376. ASUS_SET_DEVICE_ATTR(bluetooth, 0644,
  377. show_bluetooth, store_bluetooth);
  378. }
  379. static int asus_handle_init(char *name, acpi_handle *handle,
  380. char **paths, int num_paths)
  381. {
  382. int i;
  383. acpi_status status;
  384. for (i = 0; i < num_paths; i++) {
  385. status = acpi_get_handle(NULL, paths[i], handle);
  386. if (ACPI_SUCCESS(status))
  387. return 0;
  388. }
  389. *handle = NULL;
  390. return -ENODEV;
  391. }
  392. #define ASUS_HANDLE_INIT(object) \
  393. asus_handle_init(#object, &object##_handle, object##_paths, \
  394. ARRAY_SIZE(object##_paths))
  395. /*
  396. * This function is used to initialize the hotk with right values. In this
  397. * method, we can make all the detection we want, and modify the hotk struct
  398. */
  399. static int asus_hotk_get_info(void)
  400. {
  401. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  402. struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
  403. union acpi_object *model = NULL;
  404. int bsts_result, hwrs_result;
  405. char *string = NULL;
  406. acpi_status status;
  407. /*
  408. * Get DSDT headers early enough to allow for differentiating between
  409. * models, but late enough to allow acpi_bus_register_driver() to fail
  410. * before doing anything ACPI-specific. Should we encounter a machine,
  411. * which needs special handling (i.e. its hotkey device has a different
  412. * HID), this bit will be moved. A global variable asus_info contains
  413. * the DSDT header.
  414. */
  415. status = acpi_get_table(ACPI_TABLE_ID_DSDT, 1, &dsdt);
  416. if (ACPI_FAILURE(status))
  417. printk(ASUS_WARNING "Couldn't get the DSDT table header\n");
  418. else
  419. asus_info = dsdt.pointer;
  420. /* We have to write 0 on init this far for all ASUS models */
  421. if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
  422. printk(ASUS_ERR "Hotkey initialization failed\n");
  423. return -ENODEV;
  424. }
  425. /* This needs to be called for some laptops to init properly */
  426. if (!read_acpi_int(hotk->handle, "BSTS", &bsts_result, NULL))
  427. printk(ASUS_WARNING "Error calling BSTS\n");
  428. else if (bsts_result)
  429. printk(ASUS_NOTICE "BSTS called, 0x%02x returned\n",
  430. bsts_result);
  431. /*
  432. * Try to match the object returned by INIT to the specific model.
  433. * Handle every possible object (or the lack of thereof) the DSDT
  434. * writers might throw at us. When in trouble, we pass NULL to
  435. * asus_model_match() and try something completely different.
  436. */
  437. if (buffer.pointer) {
  438. model = buffer.pointer;
  439. switch (model->type) {
  440. case ACPI_TYPE_STRING:
  441. string = model->string.pointer;
  442. break;
  443. case ACPI_TYPE_BUFFER:
  444. string = model->buffer.pointer;
  445. break;
  446. default:
  447. string = "";
  448. break;
  449. }
  450. }
  451. hotk->name = kstrdup(string, GFP_KERNEL);
  452. if (!hotk->name)
  453. return -ENOMEM;
  454. if(*string)
  455. printk(ASUS_NOTICE " %s model detected\n", string);
  456. ASUS_HANDLE_INIT(mled_set);
  457. ASUS_HANDLE_INIT(tled_set);
  458. ASUS_HANDLE_INIT(rled_set);
  459. ASUS_HANDLE_INIT(pled_set);
  460. /*
  461. * The HWRS method return informations about the hardware.
  462. * 0x80 bit is for WLAN, 0x100 for Bluetooth.
  463. * The significance of others is yet to be found.
  464. * If we don't find the method, we assume the device are present.
  465. */
  466. if (!read_acpi_int(hotk->handle, "HRWS", &hwrs_result, NULL))
  467. hwrs_result = WL_HWRS | BT_HWRS;
  468. if(hwrs_result & WL_HWRS)
  469. ASUS_HANDLE_INIT(wl_switch);
  470. if(hwrs_result & BT_HWRS)
  471. ASUS_HANDLE_INIT(bt_switch);
  472. ASUS_HANDLE_INIT(wireless_status);
  473. kfree(model);
  474. return AE_OK;
  475. }
  476. static int asus_hotk_check(void)
  477. {
  478. int result = 0;
  479. result = acpi_bus_get_status(hotk->device);
  480. if (result)
  481. return result;
  482. if (hotk->device->status.present) {
  483. result = asus_hotk_get_info();
  484. } else {
  485. printk(ASUS_ERR "Hotkey device not present, aborting\n");
  486. return -EINVAL;
  487. }
  488. return result;
  489. }
  490. static int asus_hotk_found;
  491. static int asus_hotk_add(struct acpi_device *device)
  492. {
  493. acpi_status status = AE_OK;
  494. int result;
  495. if (!device)
  496. return -EINVAL;
  497. printk(ASUS_NOTICE "Asus Laptop Support version %s\n",
  498. ASUS_LAPTOP_VERSION);
  499. hotk = kmalloc(sizeof(struct asus_hotk), GFP_KERNEL);
  500. if (!hotk)
  501. return -ENOMEM;
  502. memset(hotk, 0, sizeof(struct asus_hotk));
  503. hotk->handle = device->handle;
  504. strcpy(acpi_device_name(device), ASUS_HOTK_DEVICE_NAME);
  505. strcpy(acpi_device_class(device), ASUS_HOTK_CLASS);
  506. acpi_driver_data(device) = hotk;
  507. hotk->device = device;
  508. result = asus_hotk_check();
  509. if (result)
  510. goto end;
  511. asus_hotk_add_fs();
  512. /*
  513. * We install the handler, it will receive the hotk in parameter, so, we
  514. * could add other data to the hotk struct
  515. */
  516. status = acpi_install_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
  517. asus_hotk_notify, hotk);
  518. if (ACPI_FAILURE(status))
  519. printk(ASUS_ERR "Error installing notify handler\n");
  520. asus_hotk_found = 1;
  521. /* WLED and BLED are on by default */
  522. write_status(bt_switch_handle, 1, BT_ON, 0);
  523. write_status(wl_switch_handle, 1, WL_ON, 0);
  524. end:
  525. if (result) {
  526. kfree(hotk->name);
  527. kfree(hotk);
  528. }
  529. return result;
  530. }
  531. static int asus_hotk_remove(struct acpi_device *device, int type)
  532. {
  533. acpi_status status = 0;
  534. if (!device || !acpi_driver_data(device))
  535. return -EINVAL;
  536. status = acpi_remove_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
  537. asus_hotk_notify);
  538. if (ACPI_FAILURE(status))
  539. printk(ASUS_ERR "Error removing notify handler\n");
  540. kfree(hotk->name);
  541. kfree(hotk);
  542. return 0;
  543. }
  544. #define ASUS_LED_UNREGISTER(object) \
  545. if(object##_led.class_dev \
  546. && !IS_ERR(object##_led.class_dev)) \
  547. led_classdev_unregister(&object##_led)
  548. static void asus_led_exit(void)
  549. {
  550. ASUS_LED_UNREGISTER(mled);
  551. ASUS_LED_UNREGISTER(tled);
  552. ASUS_LED_UNREGISTER(pled);
  553. ASUS_LED_UNREGISTER(rled);
  554. destroy_workqueue(led_workqueue);
  555. }
  556. static void __exit asus_laptop_exit(void)
  557. {
  558. asus_led_exit();
  559. acpi_bus_unregister_driver(&asus_hotk_driver);
  560. sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group);
  561. platform_device_unregister(asuspf_device);
  562. platform_driver_unregister(&asuspf_driver);
  563. kfree(asus_info);
  564. }
  565. static int asus_led_register(acpi_handle handle,
  566. struct led_classdev * ldev,
  567. struct device * dev)
  568. {
  569. if(!handle)
  570. return 0;
  571. return led_classdev_register(dev, ldev);
  572. }
  573. #define ASUS_LED_REGISTER(object, device) \
  574. asus_led_register(object##_set_handle, &object##_led, device)
  575. static int asus_led_init(struct device * dev)
  576. {
  577. int rv;
  578. rv = ASUS_LED_REGISTER(mled, dev);
  579. if(rv)
  580. return rv;
  581. rv = ASUS_LED_REGISTER(tled, dev);
  582. if(rv)
  583. return rv;
  584. rv = ASUS_LED_REGISTER(rled, dev);
  585. if(rv)
  586. return rv;
  587. rv = ASUS_LED_REGISTER(pled, dev);
  588. if(rv)
  589. return rv;
  590. led_workqueue = create_singlethread_workqueue("led_workqueue");
  591. if(!led_workqueue)
  592. return -ENOMEM;
  593. return 0;
  594. }
  595. static int __init asus_laptop_init(void)
  596. {
  597. struct device *dev;
  598. int result;
  599. if (acpi_disabled)
  600. return -ENODEV;
  601. if (!acpi_specific_hotkey_enabled) {
  602. printk(ASUS_ERR "Using generic hotkey driver\n");
  603. return -ENODEV;
  604. }
  605. result = acpi_bus_register_driver(&asus_hotk_driver);
  606. if (result < 0)
  607. return result;
  608. /*
  609. * This is a bit of a kludge. We only want this module loaded
  610. * for ASUS systems, but there's currently no way to probe the
  611. * ACPI namespace for ASUS HIDs. So we just return failure if
  612. * we didn't find one, which will cause the module to be
  613. * unloaded.
  614. */
  615. if (!asus_hotk_found) {
  616. acpi_bus_unregister_driver(&asus_hotk_driver);
  617. return -ENODEV;
  618. }
  619. dev = acpi_get_physical_device(hotk->device->handle);
  620. result = asus_led_init(dev);
  621. if(result)
  622. goto fail_led;
  623. /* Register platform stuff */
  624. result = platform_driver_register(&asuspf_driver);
  625. if (result)
  626. goto fail_platform_driver;
  627. asuspf_device = platform_device_alloc(ASUS_HOTK_FILE, -1);
  628. if (!asuspf_device) {
  629. result = -ENOMEM;
  630. goto fail_platform_device1;
  631. }
  632. result = platform_device_add(asuspf_device);
  633. if (result)
  634. goto fail_platform_device2;
  635. result = sysfs_create_group(&asuspf_device->dev.kobj,
  636. &asuspf_attribute_group);
  637. if (result)
  638. goto fail_sysfs;
  639. return 0;
  640. fail_sysfs:
  641. platform_device_del(asuspf_device);
  642. fail_platform_device2:
  643. platform_device_put(asuspf_device);
  644. fail_platform_device1:
  645. platform_driver_unregister(&asuspf_driver);
  646. fail_platform_driver:
  647. asus_led_exit();
  648. fail_led:
  649. return result;
  650. }
  651. module_init(asus_laptop_init);
  652. module_exit(asus_laptop_exit);