svcsock.c: include sunrpc.h to quiet sparse noise
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / platform / x86 / asus-laptop.c
blobd65df92e2acc63fb9eea85d82434c359ed8654fd
1 /*
2 * asus-laptop.c - Asus Laptop Support
5 * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
6 * Copyright (C) 2006-2007 Corentin Chary
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.
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.
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
23 * The development page for this driver is located at
24 * http://sourceforge.net/projects/acpi4asus/
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 helpful
33 * Sam Lin - GPS support
36 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
38 #include <linux/kernel.h>
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/types.h>
42 #include <linux/err.h>
43 #include <linux/proc_fs.h>
44 #include <linux/backlight.h>
45 #include <linux/fb.h>
46 #include <linux/leds.h>
47 #include <linux/platform_device.h>
48 #include <linux/uaccess.h>
49 #include <linux/input.h>
50 #include <linux/input/sparse-keymap.h>
51 #include <linux/rfkill.h>
52 #include <linux/slab.h>
53 #include <linux/dmi.h>
54 #include <acpi/acpi_drivers.h>
55 #include <acpi/acpi_bus.h>
57 #define ASUS_LAPTOP_VERSION "0.42"
59 #define ASUS_LAPTOP_NAME "Asus Laptop Support"
60 #define ASUS_LAPTOP_CLASS "hotkey"
61 #define ASUS_LAPTOP_DEVICE_NAME "Hotkey"
62 #define ASUS_LAPTOP_FILE KBUILD_MODNAME
63 #define ASUS_LAPTOP_PREFIX "\\_SB.ATKD."
65 MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
66 MODULE_DESCRIPTION(ASUS_LAPTOP_NAME);
67 MODULE_LICENSE("GPL");
70 * WAPF defines the behavior of the Fn+Fx wlan key
71 * The significance of values is yet to be found, but
72 * most of the time:
73 * 0x0 will do nothing
74 * 0x1 will allow to control the device with Fn+Fx key.
75 * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key
76 * 0x5 like 0x1 or 0x4
77 * So, if something doesn't work as you want, just try other values =)
79 static uint wapf = 1;
80 module_param(wapf, uint, 0444);
81 MODULE_PARM_DESC(wapf, "WAPF value");
83 static int wlan_status = 1;
84 static int bluetooth_status = 1;
85 static int wimax_status = -1;
86 static int wwan_status = -1;
88 module_param(wlan_status, int, 0444);
89 MODULE_PARM_DESC(wlan_status, "Set the wireless status on boot "
90 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
91 "default is 1");
93 module_param(bluetooth_status, int, 0444);
94 MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot "
95 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
96 "default is 1");
98 module_param(wimax_status, int, 0444);
99 MODULE_PARM_DESC(wimax_status, "Set the wireless status on boot "
100 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
101 "default is 1");
103 module_param(wwan_status, int, 0444);
104 MODULE_PARM_DESC(wwan_status, "Set the wireless status on boot "
105 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
106 "default is 1");
109 * Some events we use, same for all Asus
111 #define ATKD_BR_UP 0x10 /* (event & ~ATKD_BR_UP) = brightness level */
112 #define ATKD_BR_DOWN 0x20 /* (event & ~ATKD_BR_DOWN) = britghness level */
113 #define ATKD_BR_MIN ATKD_BR_UP
114 #define ATKD_BR_MAX (ATKD_BR_DOWN | 0xF) /* 0x2f */
115 #define ATKD_LCD_ON 0x33
116 #define ATKD_LCD_OFF 0x34
119 * Known bits returned by \_SB.ATKD.HWRS
121 #define WL_HWRS 0x80
122 #define BT_HWRS 0x100
125 * Flags for hotk status
126 * WL_ON and BT_ON are also used for wireless_status()
128 #define WL_RSTS 0x01 /* internal Wifi */
129 #define BT_RSTS 0x02 /* internal Bluetooth */
130 #define WM_RSTS 0x08 /* internal wimax */
131 #define WW_RSTS 0x20 /* internal wwan */
133 /* LED */
134 #define METHOD_MLED "MLED"
135 #define METHOD_TLED "TLED"
136 #define METHOD_RLED "RLED" /* W1JC */
137 #define METHOD_PLED "PLED" /* A7J */
138 #define METHOD_GLED "GLED" /* G1, G2 (probably) */
140 /* LEDD */
141 #define METHOD_LEDD "SLCM"
144 * Bluetooth and WLAN
145 * WLED and BLED are not handled like other XLED, because in some dsdt
146 * they also control the WLAN/Bluetooth device.
148 #define METHOD_WLAN "WLED"
149 #define METHOD_BLUETOOTH "BLED"
151 /* WWAN and WIMAX */
152 #define METHOD_WWAN "GSMC"
153 #define METHOD_WIMAX "WMXC"
155 #define METHOD_WL_STATUS "RSTS"
157 /* Brightness */
158 #define METHOD_BRIGHTNESS_SET "SPLV"
159 #define METHOD_BRIGHTNESS_GET "GPLV"
161 /* Display */
162 #define METHOD_SWITCH_DISPLAY "SDSP"
164 #define METHOD_ALS_CONTROL "ALSC" /* Z71A Z71V */
165 #define METHOD_ALS_LEVEL "ALSL" /* Z71A Z71V */
167 /* GPS */
168 /* R2H use different handle for GPS on/off */
169 #define METHOD_GPS_ON "SDON"
170 #define METHOD_GPS_OFF "SDOF"
171 #define METHOD_GPS_STATUS "GPST"
173 /* Keyboard light */
174 #define METHOD_KBD_LIGHT_SET "SLKB"
175 #define METHOD_KBD_LIGHT_GET "GLKB"
178 * Define a specific led structure to keep the main structure clean
180 struct asus_led {
181 int wk;
182 struct work_struct work;
183 struct led_classdev led;
184 struct asus_laptop *asus;
185 const char *method;
189 * This is the main structure, we can use it to store anything interesting
190 * about the hotk device
192 struct asus_laptop {
193 char *name; /* laptop name */
195 struct acpi_table_header *dsdt_info;
196 struct platform_device *platform_device;
197 struct acpi_device *device; /* the device we are in */
198 struct backlight_device *backlight_device;
200 struct input_dev *inputdev;
201 struct key_entry *keymap;
203 struct asus_led mled;
204 struct asus_led tled;
205 struct asus_led rled;
206 struct asus_led pled;
207 struct asus_led gled;
208 struct asus_led kled;
209 struct workqueue_struct *led_workqueue;
211 int wireless_status;
212 bool have_rsts;
214 struct rfkill *gps_rfkill;
216 acpi_handle handle; /* the handle of the hotk device */
217 u32 ledd_status; /* status of the LED display */
218 u8 light_level; /* light sensor level */
219 u8 light_switch; /* light sensor switch value */
220 u16 event_count[128]; /* count for each event TODO make this better */
223 static const struct key_entry asus_keymap[] = {
224 /* Lenovo SL Specific keycodes */
225 {KE_KEY, 0x02, { KEY_SCREENLOCK } },
226 {KE_KEY, 0x05, { KEY_WLAN } },
227 {KE_KEY, 0x08, { KEY_F13 } },
228 {KE_KEY, 0x17, { KEY_ZOOM } },
229 {KE_KEY, 0x1f, { KEY_BATTERY } },
230 /* End of Lenovo SL Specific keycodes */
231 {KE_KEY, 0x30, { KEY_VOLUMEUP } },
232 {KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
233 {KE_KEY, 0x32, { KEY_MUTE } },
234 {KE_KEY, 0x33, { KEY_SWITCHVIDEOMODE } },
235 {KE_KEY, 0x34, { KEY_SWITCHVIDEOMODE } },
236 {KE_KEY, 0x40, { KEY_PREVIOUSSONG } },
237 {KE_KEY, 0x41, { KEY_NEXTSONG } },
238 {KE_KEY, 0x43, { KEY_STOPCD } },
239 {KE_KEY, 0x45, { KEY_PLAYPAUSE } },
240 {KE_KEY, 0x4c, { KEY_MEDIA } },
241 {KE_KEY, 0x50, { KEY_EMAIL } },
242 {KE_KEY, 0x51, { KEY_WWW } },
243 {KE_KEY, 0x55, { KEY_CALC } },
244 {KE_KEY, 0x5C, { KEY_SCREENLOCK } }, /* Screenlock */
245 {KE_KEY, 0x5D, { KEY_WLAN } },
246 {KE_KEY, 0x5E, { KEY_WLAN } },
247 {KE_KEY, 0x5F, { KEY_WLAN } },
248 {KE_KEY, 0x60, { KEY_SWITCHVIDEOMODE } },
249 {KE_KEY, 0x61, { KEY_SWITCHVIDEOMODE } },
250 {KE_KEY, 0x62, { KEY_SWITCHVIDEOMODE } },
251 {KE_KEY, 0x63, { KEY_SWITCHVIDEOMODE } },
252 {KE_KEY, 0x6B, { KEY_F13 } }, /* Lock Touchpad */
253 {KE_KEY, 0x7E, { KEY_BLUETOOTH } },
254 {KE_KEY, 0x7D, { KEY_BLUETOOTH } },
255 {KE_KEY, 0x82, { KEY_CAMERA } },
256 {KE_KEY, 0x88, { KEY_WLAN } },
257 {KE_KEY, 0x8A, { KEY_PROG1 } },
258 {KE_KEY, 0x95, { KEY_MEDIA } },
259 {KE_KEY, 0x99, { KEY_PHONE } },
260 {KE_KEY, 0xc4, { KEY_KBDILLUMUP } },
261 {KE_KEY, 0xc5, { KEY_KBDILLUMDOWN } },
262 {KE_KEY, 0xb5, { KEY_CALC } },
263 {KE_END, 0},
268 * This function evaluates an ACPI method, given an int as parameter, the
269 * method is searched within the scope of the handle, can be NULL. The output
270 * of the method is written is output, which can also be NULL
272 * returns 0 if write is successful, -1 else.
274 static int write_acpi_int_ret(acpi_handle handle, const char *method, int val,
275 struct acpi_buffer *output)
277 struct acpi_object_list params; /* list of input parameters (an int) */
278 union acpi_object in_obj; /* the only param we use */
279 acpi_status status;
281 if (!handle)
282 return -1;
284 params.count = 1;
285 params.pointer = &in_obj;
286 in_obj.type = ACPI_TYPE_INTEGER;
287 in_obj.integer.value = val;
289 status = acpi_evaluate_object(handle, (char *)method, &params, output);
290 if (status == AE_OK)
291 return 0;
292 else
293 return -1;
296 static int write_acpi_int(acpi_handle handle, const char *method, int val)
298 return write_acpi_int_ret(handle, method, val, NULL);
301 static int acpi_check_handle(acpi_handle handle, const char *method,
302 acpi_handle *ret)
304 acpi_status status;
306 if (method == NULL)
307 return -ENODEV;
309 if (ret)
310 status = acpi_get_handle(handle, (char *)method,
311 ret);
312 else {
313 acpi_handle dummy;
315 status = acpi_get_handle(handle, (char *)method,
316 &dummy);
319 if (status != AE_OK) {
320 if (ret)
321 pr_warn("Error finding %s\n", method);
322 return -ENODEV;
324 return 0;
327 /* Generic LED function */
328 static int asus_led_set(struct asus_laptop *asus, const char *method,
329 int value)
331 if (!strcmp(method, METHOD_MLED))
332 value = !value;
333 else if (!strcmp(method, METHOD_GLED))
334 value = !value + 1;
335 else
336 value = !!value;
338 return write_acpi_int(asus->handle, method, value);
342 * LEDs
344 /* /sys/class/led handlers */
345 static void asus_led_cdev_set(struct led_classdev *led_cdev,
346 enum led_brightness value)
348 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
349 struct asus_laptop *asus = led->asus;
351 led->wk = !!value;
352 queue_work(asus->led_workqueue, &led->work);
355 static void asus_led_cdev_update(struct work_struct *work)
357 struct asus_led *led = container_of(work, struct asus_led, work);
358 struct asus_laptop *asus = led->asus;
360 asus_led_set(asus, led->method, led->wk);
363 static enum led_brightness asus_led_cdev_get(struct led_classdev *led_cdev)
365 return led_cdev->brightness;
369 * Keyboard backlight (also a LED)
371 static int asus_kled_lvl(struct asus_laptop *asus)
373 unsigned long long kblv;
374 struct acpi_object_list params;
375 union acpi_object in_obj;
376 acpi_status rv;
378 params.count = 1;
379 params.pointer = &in_obj;
380 in_obj.type = ACPI_TYPE_INTEGER;
381 in_obj.integer.value = 2;
383 rv = acpi_evaluate_integer(asus->handle, METHOD_KBD_LIGHT_GET,
384 &params, &kblv);
385 if (ACPI_FAILURE(rv)) {
386 pr_warn("Error reading kled level\n");
387 return -ENODEV;
389 return kblv;
392 static int asus_kled_set(struct asus_laptop *asus, int kblv)
394 if (kblv > 0)
395 kblv = (1 << 7) | (kblv & 0x7F);
396 else
397 kblv = 0;
399 if (write_acpi_int(asus->handle, METHOD_KBD_LIGHT_SET, kblv)) {
400 pr_warn("Keyboard LED display write failed\n");
401 return -EINVAL;
403 return 0;
406 static void asus_kled_cdev_set(struct led_classdev *led_cdev,
407 enum led_brightness value)
409 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
410 struct asus_laptop *asus = led->asus;
412 led->wk = value;
413 queue_work(asus->led_workqueue, &led->work);
416 static void asus_kled_cdev_update(struct work_struct *work)
418 struct asus_led *led = container_of(work, struct asus_led, work);
419 struct asus_laptop *asus = led->asus;
421 asus_kled_set(asus, led->wk);
424 static enum led_brightness asus_kled_cdev_get(struct led_classdev *led_cdev)
426 struct asus_led *led = container_of(led_cdev, struct asus_led, led);
427 struct asus_laptop *asus = led->asus;
429 return asus_kled_lvl(asus);
432 static void asus_led_exit(struct asus_laptop *asus)
434 if (asus->mled.led.dev)
435 led_classdev_unregister(&asus->mled.led);
436 if (asus->tled.led.dev)
437 led_classdev_unregister(&asus->tled.led);
438 if (asus->pled.led.dev)
439 led_classdev_unregister(&asus->pled.led);
440 if (asus->rled.led.dev)
441 led_classdev_unregister(&asus->rled.led);
442 if (asus->gled.led.dev)
443 led_classdev_unregister(&asus->gled.led);
444 if (asus->kled.led.dev)
445 led_classdev_unregister(&asus->kled.led);
446 if (asus->led_workqueue) {
447 destroy_workqueue(asus->led_workqueue);
448 asus->led_workqueue = NULL;
452 /* Ugly macro, need to fix that later */
453 static int asus_led_register(struct asus_laptop *asus,
454 struct asus_led *led,
455 const char *name, const char *method)
457 struct led_classdev *led_cdev = &led->led;
459 if (!method || acpi_check_handle(asus->handle, method, NULL))
460 return 0; /* Led not present */
462 led->asus = asus;
463 led->method = method;
465 INIT_WORK(&led->work, asus_led_cdev_update);
466 led_cdev->name = name;
467 led_cdev->brightness_set = asus_led_cdev_set;
468 led_cdev->brightness_get = asus_led_cdev_get;
469 led_cdev->max_brightness = 1;
470 return led_classdev_register(&asus->platform_device->dev, led_cdev);
473 static int asus_led_init(struct asus_laptop *asus)
475 int r;
478 * Functions that actually update the LED's are called from a
479 * workqueue. By doing this as separate work rather than when the LED
480 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
481 * potentially bad time, such as a timer interrupt.
483 asus->led_workqueue = create_singlethread_workqueue("led_workqueue");
484 if (!asus->led_workqueue)
485 return -ENOMEM;
487 r = asus_led_register(asus, &asus->mled, "asus::mail", METHOD_MLED);
488 if (r)
489 goto error;
490 r = asus_led_register(asus, &asus->tled, "asus::touchpad", METHOD_TLED);
491 if (r)
492 goto error;
493 r = asus_led_register(asus, &asus->rled, "asus::record", METHOD_RLED);
494 if (r)
495 goto error;
496 r = asus_led_register(asus, &asus->pled, "asus::phone", METHOD_PLED);
497 if (r)
498 goto error;
499 r = asus_led_register(asus, &asus->gled, "asus::gaming", METHOD_GLED);
500 if (r)
501 goto error;
502 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL) &&
503 !acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_GET, NULL)) {
504 struct asus_led *led = &asus->kled;
505 struct led_classdev *cdev = &led->led;
507 led->asus = asus;
509 INIT_WORK(&led->work, asus_kled_cdev_update);
510 cdev->name = "asus::kbd_backlight";
511 cdev->brightness_set = asus_kled_cdev_set;
512 cdev->brightness_get = asus_kled_cdev_get;
513 cdev->max_brightness = 3;
514 r = led_classdev_register(&asus->platform_device->dev, cdev);
516 error:
517 if (r)
518 asus_led_exit(asus);
519 return r;
523 * Backlight device
525 static int asus_read_brightness(struct backlight_device *bd)
527 struct asus_laptop *asus = bl_get_data(bd);
528 unsigned long long value;
529 acpi_status rv = AE_OK;
531 rv = acpi_evaluate_integer(asus->handle, METHOD_BRIGHTNESS_GET,
532 NULL, &value);
533 if (ACPI_FAILURE(rv))
534 pr_warn("Error reading brightness\n");
536 return value;
539 static int asus_set_brightness(struct backlight_device *bd, int value)
541 struct asus_laptop *asus = bl_get_data(bd);
543 if (write_acpi_int(asus->handle, METHOD_BRIGHTNESS_SET, value)) {
544 pr_warn("Error changing brightness\n");
545 return -EIO;
547 return 0;
550 static int update_bl_status(struct backlight_device *bd)
552 int value = bd->props.brightness;
554 return asus_set_brightness(bd, value);
557 static const struct backlight_ops asusbl_ops = {
558 .get_brightness = asus_read_brightness,
559 .update_status = update_bl_status,
562 static int asus_backlight_notify(struct asus_laptop *asus)
564 struct backlight_device *bd = asus->backlight_device;
565 int old = bd->props.brightness;
567 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
569 return old;
572 static int asus_backlight_init(struct asus_laptop *asus)
574 struct backlight_device *bd;
575 struct backlight_properties props;
577 if (acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_GET, NULL) ||
578 acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_SET, NULL))
579 return 0;
581 memset(&props, 0, sizeof(struct backlight_properties));
582 props.max_brightness = 15;
583 props.type = BACKLIGHT_PLATFORM;
585 bd = backlight_device_register(ASUS_LAPTOP_FILE,
586 &asus->platform_device->dev, asus,
587 &asusbl_ops, &props);
588 if (IS_ERR(bd)) {
589 pr_err("Could not register asus backlight device\n");
590 asus->backlight_device = NULL;
591 return PTR_ERR(bd);
594 asus->backlight_device = bd;
595 bd->props.brightness = asus_read_brightness(bd);
596 bd->props.power = FB_BLANK_UNBLANK;
597 backlight_update_status(bd);
598 return 0;
601 static void asus_backlight_exit(struct asus_laptop *asus)
603 if (asus->backlight_device)
604 backlight_device_unregister(asus->backlight_device);
605 asus->backlight_device = NULL;
609 * Platform device handlers
613 * We write our info in page, we begin at offset off and cannot write more
614 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
615 * number of bytes written in page
617 static ssize_t show_infos(struct device *dev,
618 struct device_attribute *attr, char *page)
620 struct asus_laptop *asus = dev_get_drvdata(dev);
621 int len = 0;
622 unsigned long long temp;
623 char buf[16]; /* enough for all info */
624 acpi_status rv = AE_OK;
627 * We use the easy way, we don't care of off and count,
628 * so we don't set eof to 1
631 len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n");
632 len += sprintf(page + len, "Model reference : %s\n", asus->name);
634 * The SFUN method probably allows the original driver to get the list
635 * of features supported by a given model. For now, 0x0100 or 0x0800
636 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
637 * The significance of others is yet to be found.
639 rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp);
640 if (!ACPI_FAILURE(rv))
641 len += sprintf(page + len, "SFUN value : %#x\n",
642 (uint) temp);
644 * The HWRS method return informations about the hardware.
645 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
646 * The significance of others is yet to be found.
647 * If we don't find the method, we assume the device are present.
649 rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp);
650 if (!ACPI_FAILURE(rv))
651 len += sprintf(page + len, "HRWS value : %#x\n",
652 (uint) temp);
654 * Another value for userspace: the ASYM method returns 0x02 for
655 * battery low and 0x04 for battery critical, its readings tend to be
656 * more accurate than those provided by _BST.
657 * Note: since not all the laptops provide this method, errors are
658 * silently ignored.
660 rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp);
661 if (!ACPI_FAILURE(rv))
662 len += sprintf(page + len, "ASYM value : %#x\n",
663 (uint) temp);
664 if (asus->dsdt_info) {
665 snprintf(buf, 16, "%d", asus->dsdt_info->length);
666 len += sprintf(page + len, "DSDT length : %s\n", buf);
667 snprintf(buf, 16, "%d", asus->dsdt_info->checksum);
668 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
669 snprintf(buf, 16, "%d", asus->dsdt_info->revision);
670 len += sprintf(page + len, "DSDT revision : %s\n", buf);
671 snprintf(buf, 7, "%s", asus->dsdt_info->oem_id);
672 len += sprintf(page + len, "OEM id : %s\n", buf);
673 snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id);
674 len += sprintf(page + len, "OEM table id : %s\n", buf);
675 snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision);
676 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
677 snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id);
678 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
679 snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision);
680 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
683 return len;
686 static int parse_arg(const char *buf, unsigned long count, int *val)
688 if (!count)
689 return 0;
690 if (count > 31)
691 return -EINVAL;
692 if (sscanf(buf, "%i", val) != 1)
693 return -EINVAL;
694 return count;
697 static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
698 const char *buf, size_t count,
699 const char *method)
701 int rv, value;
702 int out = 0;
704 rv = parse_arg(buf, count, &value);
705 if (rv > 0)
706 out = value ? 1 : 0;
708 if (write_acpi_int(asus->handle, method, value))
709 return -ENODEV;
710 return rv;
714 * LEDD display
716 static ssize_t show_ledd(struct device *dev,
717 struct device_attribute *attr, char *buf)
719 struct asus_laptop *asus = dev_get_drvdata(dev);
721 return sprintf(buf, "0x%08x\n", asus->ledd_status);
724 static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
725 const char *buf, size_t count)
727 struct asus_laptop *asus = dev_get_drvdata(dev);
728 int rv, value;
730 rv = parse_arg(buf, count, &value);
731 if (rv > 0) {
732 if (write_acpi_int(asus->handle, METHOD_LEDD, value)) {
733 pr_warn("LED display write failed\n");
734 return -ENODEV;
736 asus->ledd_status = (u32) value;
738 return rv;
742 * Wireless
744 static int asus_wireless_status(struct asus_laptop *asus, int mask)
746 unsigned long long status;
747 acpi_status rv = AE_OK;
749 if (!asus->have_rsts)
750 return (asus->wireless_status & mask) ? 1 : 0;
752 rv = acpi_evaluate_integer(asus->handle, METHOD_WL_STATUS,
753 NULL, &status);
754 if (ACPI_FAILURE(rv)) {
755 pr_warn("Error reading Wireless status\n");
756 return -EINVAL;
758 return !!(status & mask);
762 * WLAN
764 static int asus_wlan_set(struct asus_laptop *asus, int status)
766 if (write_acpi_int(asus->handle, METHOD_WLAN, !!status)) {
767 pr_warn("Error setting wlan status to %d\n", status);
768 return -EIO;
770 return 0;
773 static ssize_t show_wlan(struct device *dev,
774 struct device_attribute *attr, char *buf)
776 struct asus_laptop *asus = dev_get_drvdata(dev);
778 return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS));
781 static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
782 const char *buf, size_t count)
784 struct asus_laptop *asus = dev_get_drvdata(dev);
786 return sysfs_acpi_set(asus, buf, count, METHOD_WLAN);
790 * Bluetooth
792 static int asus_bluetooth_set(struct asus_laptop *asus, int status)
794 if (write_acpi_int(asus->handle, METHOD_BLUETOOTH, !!status)) {
795 pr_warn("Error setting bluetooth status to %d\n", status);
796 return -EIO;
798 return 0;
801 static ssize_t show_bluetooth(struct device *dev,
802 struct device_attribute *attr, char *buf)
804 struct asus_laptop *asus = dev_get_drvdata(dev);
806 return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS));
809 static ssize_t store_bluetooth(struct device *dev,
810 struct device_attribute *attr, const char *buf,
811 size_t count)
813 struct asus_laptop *asus = dev_get_drvdata(dev);
815 return sysfs_acpi_set(asus, buf, count, METHOD_BLUETOOTH);
819 * Wimax
821 static int asus_wimax_set(struct asus_laptop *asus, int status)
823 if (write_acpi_int(asus->handle, METHOD_WIMAX, !!status)) {
824 pr_warn("Error setting wimax status to %d\n", status);
825 return -EIO;
827 return 0;
830 static ssize_t show_wimax(struct device *dev,
831 struct device_attribute *attr, char *buf)
833 struct asus_laptop *asus = dev_get_drvdata(dev);
835 return sprintf(buf, "%d\n", asus_wireless_status(asus, WM_RSTS));
838 static ssize_t store_wimax(struct device *dev,
839 struct device_attribute *attr, const char *buf,
840 size_t count)
842 struct asus_laptop *asus = dev_get_drvdata(dev);
844 return sysfs_acpi_set(asus, buf, count, METHOD_WIMAX);
848 * Wwan
850 static int asus_wwan_set(struct asus_laptop *asus, int status)
852 if (write_acpi_int(asus->handle, METHOD_WWAN, !!status)) {
853 pr_warn("Error setting wwan status to %d\n", status);
854 return -EIO;
856 return 0;
859 static ssize_t show_wwan(struct device *dev,
860 struct device_attribute *attr, char *buf)
862 struct asus_laptop *asus = dev_get_drvdata(dev);
864 return sprintf(buf, "%d\n", asus_wireless_status(asus, WW_RSTS));
867 static ssize_t store_wwan(struct device *dev,
868 struct device_attribute *attr, const char *buf,
869 size_t count)
871 struct asus_laptop *asus = dev_get_drvdata(dev);
873 return sysfs_acpi_set(asus, buf, count, METHOD_WWAN);
877 * Display
879 static void asus_set_display(struct asus_laptop *asus, int value)
881 /* no sanity check needed for now */
882 if (write_acpi_int(asus->handle, METHOD_SWITCH_DISPLAY, value))
883 pr_warn("Error setting display\n");
884 return;
888 * Experimental support for display switching. As of now: 1 should activate
889 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
890 * Any combination (bitwise) of these will suffice. I never actually tested 4
891 * displays hooked up simultaneously, so be warned. See the acpi4asus README
892 * for more info.
894 static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
895 const char *buf, size_t count)
897 struct asus_laptop *asus = dev_get_drvdata(dev);
898 int rv, value;
900 rv = parse_arg(buf, count, &value);
901 if (rv > 0)
902 asus_set_display(asus, value);
903 return rv;
907 * Light Sens
909 static void asus_als_switch(struct asus_laptop *asus, int value)
911 if (write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value))
912 pr_warn("Error setting light sensor switch\n");
913 asus->light_switch = value;
916 static ssize_t show_lssw(struct device *dev,
917 struct device_attribute *attr, char *buf)
919 struct asus_laptop *asus = dev_get_drvdata(dev);
921 return sprintf(buf, "%d\n", asus->light_switch);
924 static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
925 const char *buf, size_t count)
927 struct asus_laptop *asus = dev_get_drvdata(dev);
928 int rv, value;
930 rv = parse_arg(buf, count, &value);
931 if (rv > 0)
932 asus_als_switch(asus, value ? 1 : 0);
934 return rv;
937 static void asus_als_level(struct asus_laptop *asus, int value)
939 if (write_acpi_int(asus->handle, METHOD_ALS_LEVEL, value))
940 pr_warn("Error setting light sensor level\n");
941 asus->light_level = value;
944 static ssize_t show_lslvl(struct device *dev,
945 struct device_attribute *attr, char *buf)
947 struct asus_laptop *asus = dev_get_drvdata(dev);
949 return sprintf(buf, "%d\n", asus->light_level);
952 static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
953 const char *buf, size_t count)
955 struct asus_laptop *asus = dev_get_drvdata(dev);
956 int rv, value;
958 rv = parse_arg(buf, count, &value);
959 if (rv > 0) {
960 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
961 /* 0 <= value <= 15 */
962 asus_als_level(asus, value);
965 return rv;
969 * GPS
971 static int asus_gps_status(struct asus_laptop *asus)
973 unsigned long long status;
974 acpi_status rv = AE_OK;
976 rv = acpi_evaluate_integer(asus->handle, METHOD_GPS_STATUS,
977 NULL, &status);
978 if (ACPI_FAILURE(rv)) {
979 pr_warn("Error reading GPS status\n");
980 return -ENODEV;
982 return !!status;
985 static int asus_gps_switch(struct asus_laptop *asus, int status)
987 const char *meth = status ? METHOD_GPS_ON : METHOD_GPS_OFF;
989 if (write_acpi_int(asus->handle, meth, 0x02))
990 return -ENODEV;
991 return 0;
994 static ssize_t show_gps(struct device *dev,
995 struct device_attribute *attr, char *buf)
997 struct asus_laptop *asus = dev_get_drvdata(dev);
999 return sprintf(buf, "%d\n", asus_gps_status(asus));
1002 static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
1003 const char *buf, size_t count)
1005 struct asus_laptop *asus = dev_get_drvdata(dev);
1006 int rv, value;
1007 int ret;
1009 rv = parse_arg(buf, count, &value);
1010 if (rv <= 0)
1011 return -EINVAL;
1012 ret = asus_gps_switch(asus, !!value);
1013 if (ret)
1014 return ret;
1015 rfkill_set_sw_state(asus->gps_rfkill, !value);
1016 return rv;
1020 * rfkill
1022 static int asus_gps_rfkill_set(void *data, bool blocked)
1024 struct asus_laptop *asus = data;
1026 return asus_gps_switch(asus, !blocked);
1029 static const struct rfkill_ops asus_gps_rfkill_ops = {
1030 .set_block = asus_gps_rfkill_set,
1033 static void asus_rfkill_exit(struct asus_laptop *asus)
1035 if (asus->gps_rfkill) {
1036 rfkill_unregister(asus->gps_rfkill);
1037 rfkill_destroy(asus->gps_rfkill);
1038 asus->gps_rfkill = NULL;
1042 static int asus_rfkill_init(struct asus_laptop *asus)
1044 int result;
1046 if (acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) ||
1047 acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) ||
1048 acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL))
1049 return 0;
1051 asus->gps_rfkill = rfkill_alloc("asus-gps", &asus->platform_device->dev,
1052 RFKILL_TYPE_GPS,
1053 &asus_gps_rfkill_ops, asus);
1054 if (!asus->gps_rfkill)
1055 return -EINVAL;
1057 result = rfkill_register(asus->gps_rfkill);
1058 if (result) {
1059 rfkill_destroy(asus->gps_rfkill);
1060 asus->gps_rfkill = NULL;
1063 return result;
1067 * Input device (i.e. hotkeys)
1069 static void asus_input_notify(struct asus_laptop *asus, int event)
1071 if (asus->inputdev)
1072 sparse_keymap_report_event(asus->inputdev, event, 1, true);
1075 static int asus_input_init(struct asus_laptop *asus)
1077 struct input_dev *input;
1078 int error;
1080 input = input_allocate_device();
1081 if (!input) {
1082 pr_info("Unable to allocate input device\n");
1083 return -ENOMEM;
1085 input->name = "Asus Laptop extra buttons";
1086 input->phys = ASUS_LAPTOP_FILE "/input0";
1087 input->id.bustype = BUS_HOST;
1088 input->dev.parent = &asus->platform_device->dev;
1090 error = sparse_keymap_setup(input, asus_keymap, NULL);
1091 if (error) {
1092 pr_err("Unable to setup input device keymap\n");
1093 goto err_free_dev;
1095 error = input_register_device(input);
1096 if (error) {
1097 pr_info("Unable to register input device\n");
1098 goto err_free_keymap;
1101 asus->inputdev = input;
1102 return 0;
1104 err_free_keymap:
1105 sparse_keymap_free(input);
1106 err_free_dev:
1107 input_free_device(input);
1108 return error;
1111 static void asus_input_exit(struct asus_laptop *asus)
1113 if (asus->inputdev) {
1114 sparse_keymap_free(asus->inputdev);
1115 input_unregister_device(asus->inputdev);
1117 asus->inputdev = NULL;
1121 * ACPI driver
1123 static void asus_acpi_notify(struct acpi_device *device, u32 event)
1125 struct asus_laptop *asus = acpi_driver_data(device);
1126 u16 count;
1128 /* TODO Find a better way to handle events count. */
1129 count = asus->event_count[event % 128]++;
1130 acpi_bus_generate_proc_event(asus->device, event, count);
1131 acpi_bus_generate_netlink_event(asus->device->pnp.device_class,
1132 dev_name(&asus->device->dev), event,
1133 count);
1135 /* Brightness events are special */
1136 if (event >= ATKD_BR_MIN && event <= ATKD_BR_MAX) {
1138 /* Ignore them completely if the acpi video driver is used */
1139 if (asus->backlight_device != NULL) {
1140 /* Update the backlight device. */
1141 asus_backlight_notify(asus);
1143 return ;
1145 asus_input_notify(asus, event);
1148 static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL);
1149 static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan);
1150 static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR,
1151 show_bluetooth, store_bluetooth);
1152 static DEVICE_ATTR(wimax, S_IRUGO | S_IWUSR, show_wimax, store_wimax);
1153 static DEVICE_ATTR(wwan, S_IRUGO | S_IWUSR, show_wwan, store_wwan);
1154 static DEVICE_ATTR(display, S_IWUSR, NULL, store_disp);
1155 static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
1156 static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
1157 static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw);
1158 static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps);
1160 static struct attribute *asus_attributes[] = {
1161 &dev_attr_infos.attr,
1162 &dev_attr_wlan.attr,
1163 &dev_attr_bluetooth.attr,
1164 &dev_attr_wimax.attr,
1165 &dev_attr_wwan.attr,
1166 &dev_attr_display.attr,
1167 &dev_attr_ledd.attr,
1168 &dev_attr_ls_level.attr,
1169 &dev_attr_ls_switch.attr,
1170 &dev_attr_gps.attr,
1171 NULL
1174 static mode_t asus_sysfs_is_visible(struct kobject *kobj,
1175 struct attribute *attr,
1176 int idx)
1178 struct device *dev = container_of(kobj, struct device, kobj);
1179 struct platform_device *pdev = to_platform_device(dev);
1180 struct asus_laptop *asus = platform_get_drvdata(pdev);
1181 acpi_handle handle = asus->handle;
1182 bool supported;
1184 if (attr == &dev_attr_wlan.attr) {
1185 supported = !acpi_check_handle(handle, METHOD_WLAN, NULL);
1187 } else if (attr == &dev_attr_bluetooth.attr) {
1188 supported = !acpi_check_handle(handle, METHOD_BLUETOOTH, NULL);
1190 } else if (attr == &dev_attr_display.attr) {
1191 supported = !acpi_check_handle(handle, METHOD_SWITCH_DISPLAY, NULL);
1193 } else if (attr == &dev_attr_wimax.attr) {
1194 supported =
1195 !acpi_check_handle(asus->handle, METHOD_WIMAX, NULL);
1197 } else if (attr == &dev_attr_wwan.attr) {
1198 supported = !acpi_check_handle(asus->handle, METHOD_WWAN, NULL);
1200 } else if (attr == &dev_attr_ledd.attr) {
1201 supported = !acpi_check_handle(handle, METHOD_LEDD, NULL);
1203 } else if (attr == &dev_attr_ls_switch.attr ||
1204 attr == &dev_attr_ls_level.attr) {
1205 supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) &&
1206 !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
1208 } else if (attr == &dev_attr_gps.attr) {
1209 supported = !acpi_check_handle(handle, METHOD_GPS_ON, NULL) &&
1210 !acpi_check_handle(handle, METHOD_GPS_OFF, NULL) &&
1211 !acpi_check_handle(handle, METHOD_GPS_STATUS, NULL);
1212 } else {
1213 supported = true;
1216 return supported ? attr->mode : 0;
1220 static const struct attribute_group asus_attr_group = {
1221 .is_visible = asus_sysfs_is_visible,
1222 .attrs = asus_attributes,
1225 static int asus_platform_init(struct asus_laptop *asus)
1227 int result;
1229 asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1);
1230 if (!asus->platform_device)
1231 return -ENOMEM;
1232 platform_set_drvdata(asus->platform_device, asus);
1234 result = platform_device_add(asus->platform_device);
1235 if (result)
1236 goto fail_platform_device;
1238 result = sysfs_create_group(&asus->platform_device->dev.kobj,
1239 &asus_attr_group);
1240 if (result)
1241 goto fail_sysfs;
1243 return 0;
1245 fail_sysfs:
1246 platform_device_del(asus->platform_device);
1247 fail_platform_device:
1248 platform_device_put(asus->platform_device);
1249 return result;
1252 static void asus_platform_exit(struct asus_laptop *asus)
1254 sysfs_remove_group(&asus->platform_device->dev.kobj, &asus_attr_group);
1255 platform_device_unregister(asus->platform_device);
1258 static struct platform_driver platform_driver = {
1259 .driver = {
1260 .name = ASUS_LAPTOP_FILE,
1261 .owner = THIS_MODULE,
1266 * This function is used to initialize the context with right values. In this
1267 * method, we can make all the detection we want, and modify the asus_laptop
1268 * struct
1270 static int asus_laptop_get_info(struct asus_laptop *asus)
1272 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1273 union acpi_object *model = NULL;
1274 unsigned long long bsts_result, hwrs_result;
1275 char *string = NULL;
1276 acpi_status status;
1279 * Get DSDT headers early enough to allow for differentiating between
1280 * models, but late enough to allow acpi_bus_register_driver() to fail
1281 * before doing anything ACPI-specific. Should we encounter a machine,
1282 * which needs special handling (i.e. its hotkey device has a different
1283 * HID), this bit will be moved.
1285 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info);
1286 if (ACPI_FAILURE(status))
1287 pr_warn("Couldn't get the DSDT table header\n");
1289 /* We have to write 0 on init this far for all ASUS models */
1290 if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) {
1291 pr_err("Hotkey initialization failed\n");
1292 return -ENODEV;
1295 /* This needs to be called for some laptops to init properly */
1296 status =
1297 acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result);
1298 if (ACPI_FAILURE(status))
1299 pr_warn("Error calling BSTS\n");
1300 else if (bsts_result)
1301 pr_notice("BSTS called, 0x%02x returned\n",
1302 (uint) bsts_result);
1304 /* This too ... */
1305 if (write_acpi_int(asus->handle, "CWAP", wapf))
1306 pr_err("Error calling CWAP(%d)\n", wapf);
1308 * Try to match the object returned by INIT to the specific model.
1309 * Handle every possible object (or the lack of thereof) the DSDT
1310 * writers might throw at us. When in trouble, we pass NULL to
1311 * asus_model_match() and try something completely different.
1313 if (buffer.pointer) {
1314 model = buffer.pointer;
1315 switch (model->type) {
1316 case ACPI_TYPE_STRING:
1317 string = model->string.pointer;
1318 break;
1319 case ACPI_TYPE_BUFFER:
1320 string = model->buffer.pointer;
1321 break;
1322 default:
1323 string = "";
1324 break;
1327 asus->name = kstrdup(string, GFP_KERNEL);
1328 if (!asus->name) {
1329 kfree(buffer.pointer);
1330 return -ENOMEM;
1333 if (*string)
1334 pr_notice(" %s model detected\n", string);
1337 * The HWRS method return informations about the hardware.
1338 * 0x80 bit is for WLAN, 0x100 for Bluetooth,
1339 * 0x40 for WWAN, 0x10 for WIMAX.
1340 * The significance of others is yet to be found.
1342 status =
1343 acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result);
1344 if (!ACPI_FAILURE(status))
1345 pr_notice(" HRWS returned %x", (int)hwrs_result);
1347 if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL))
1348 asus->have_rsts = true;
1350 kfree(model);
1352 return AE_OK;
1355 static int __devinit asus_acpi_init(struct asus_laptop *asus)
1357 int result = 0;
1359 result = acpi_bus_get_status(asus->device);
1360 if (result)
1361 return result;
1362 if (!asus->device->status.present) {
1363 pr_err("Hotkey device not present, aborting\n");
1364 return -ENODEV;
1367 result = asus_laptop_get_info(asus);
1368 if (result)
1369 return result;
1371 /* WLED and BLED are on by default */
1372 if (bluetooth_status >= 0)
1373 asus_bluetooth_set(asus, !!bluetooth_status);
1375 if (wlan_status >= 0)
1376 asus_wlan_set(asus, !!wlan_status);
1378 if (wimax_status >= 0)
1379 asus_wimax_set(asus, !!wimax_status);
1381 if (wwan_status >= 0)
1382 asus_wwan_set(asus, !!wwan_status);
1384 /* Keyboard Backlight is on by default */
1385 if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL))
1386 asus_kled_set(asus, 1);
1388 /* LED display is off by default */
1389 asus->ledd_status = 0xFFF;
1391 /* Set initial values of light sensor and level */
1392 asus->light_switch = 0; /* Default to light sensor disabled */
1393 asus->light_level = 5; /* level 5 for sensor sensitivity */
1395 if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
1396 !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
1397 asus_als_switch(asus, asus->light_switch);
1398 asus_als_level(asus, asus->light_level);
1401 return result;
1404 static void __devinit asus_dmi_check(void)
1406 const char *model;
1408 model = dmi_get_system_info(DMI_PRODUCT_NAME);
1409 if (!model)
1410 return;
1412 /* On L1400B WLED control the sound card, don't mess with it ... */
1413 if (strncmp(model, "L1400B", 6) == 0) {
1414 wlan_status = -1;
1418 static bool asus_device_present;
1420 static int __devinit asus_acpi_add(struct acpi_device *device)
1422 struct asus_laptop *asus;
1423 int result;
1425 pr_notice("Asus Laptop Support version %s\n",
1426 ASUS_LAPTOP_VERSION);
1427 asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL);
1428 if (!asus)
1429 return -ENOMEM;
1430 asus->handle = device->handle;
1431 strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME);
1432 strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS);
1433 device->driver_data = asus;
1434 asus->device = device;
1436 asus_dmi_check();
1438 result = asus_acpi_init(asus);
1439 if (result)
1440 goto fail_platform;
1443 * Register the platform device first. It is used as a parent for the
1444 * sub-devices below.
1446 result = asus_platform_init(asus);
1447 if (result)
1448 goto fail_platform;
1450 if (!acpi_video_backlight_support()) {
1451 result = asus_backlight_init(asus);
1452 if (result)
1453 goto fail_backlight;
1454 } else
1455 pr_info("Backlight controlled by ACPI video driver\n");
1457 result = asus_input_init(asus);
1458 if (result)
1459 goto fail_input;
1461 result = asus_led_init(asus);
1462 if (result)
1463 goto fail_led;
1465 result = asus_rfkill_init(asus);
1466 if (result)
1467 goto fail_rfkill;
1469 asus_device_present = true;
1470 return 0;
1472 fail_rfkill:
1473 asus_led_exit(asus);
1474 fail_led:
1475 asus_input_exit(asus);
1476 fail_input:
1477 asus_backlight_exit(asus);
1478 fail_backlight:
1479 asus_platform_exit(asus);
1480 fail_platform:
1481 kfree(asus->name);
1482 kfree(asus);
1484 return result;
1487 static int asus_acpi_remove(struct acpi_device *device, int type)
1489 struct asus_laptop *asus = acpi_driver_data(device);
1491 asus_backlight_exit(asus);
1492 asus_rfkill_exit(asus);
1493 asus_led_exit(asus);
1494 asus_input_exit(asus);
1495 asus_platform_exit(asus);
1497 kfree(asus->name);
1498 kfree(asus);
1499 return 0;
1502 static const struct acpi_device_id asus_device_ids[] = {
1503 {"ATK0100", 0},
1504 {"ATK0101", 0},
1505 {"", 0},
1507 MODULE_DEVICE_TABLE(acpi, asus_device_ids);
1509 static struct acpi_driver asus_acpi_driver = {
1510 .name = ASUS_LAPTOP_NAME,
1511 .class = ASUS_LAPTOP_CLASS,
1512 .owner = THIS_MODULE,
1513 .ids = asus_device_ids,
1514 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1515 .ops = {
1516 .add = asus_acpi_add,
1517 .remove = asus_acpi_remove,
1518 .notify = asus_acpi_notify,
1522 static int __init asus_laptop_init(void)
1524 int result;
1526 result = platform_driver_register(&platform_driver);
1527 if (result < 0)
1528 return result;
1530 result = acpi_bus_register_driver(&asus_acpi_driver);
1531 if (result < 0)
1532 goto fail_acpi_driver;
1533 if (!asus_device_present) {
1534 result = -ENODEV;
1535 goto fail_no_device;
1537 return 0;
1539 fail_no_device:
1540 acpi_bus_unregister_driver(&asus_acpi_driver);
1541 fail_acpi_driver:
1542 platform_driver_unregister(&platform_driver);
1543 return result;
1546 static void __exit asus_laptop_exit(void)
1548 acpi_bus_unregister_driver(&asus_acpi_driver);
1549 platform_driver_unregister(&platform_driver);
1552 module_init(asus_laptop_init);
1553 module_exit(asus_laptop_exit);