tree-wide: fix comment/printk typos
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / platform / x86 / asus-laptop.c
blob767cb61c1a80f06b3475c5c017da1cb60c973a5c
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 helpfull
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 <acpi/acpi_drivers.h>
49 #include <acpi/acpi_bus.h>
50 #include <asm/uaccess.h>
51 #include <linux/input.h>
53 #define ASUS_LAPTOP_VERSION "0.42"
55 #define ASUS_HOTK_NAME "Asus Laptop Support"
56 #define ASUS_HOTK_CLASS "hotkey"
57 #define ASUS_HOTK_DEVICE_NAME "Hotkey"
58 #define ASUS_HOTK_FILE KBUILD_MODNAME
59 #define ASUS_HOTK_PREFIX "\\_SB.ATKD."
63 * Some events we use, same for all Asus
65 #define ATKD_BR_UP 0x10
66 #define ATKD_BR_DOWN 0x20
67 #define ATKD_LCD_ON 0x33
68 #define ATKD_LCD_OFF 0x34
71 * Known bits returned by \_SB.ATKD.HWRS
73 #define WL_HWRS 0x80
74 #define BT_HWRS 0x100
77 * Flags for hotk status
78 * WL_ON and BT_ON are also used for wireless_status()
80 #define WL_ON 0x01 /* internal Wifi */
81 #define BT_ON 0x02 /* internal Bluetooth */
82 #define MLED_ON 0x04 /* mail LED */
83 #define TLED_ON 0x08 /* touchpad LED */
84 #define RLED_ON 0x10 /* Record LED */
85 #define PLED_ON 0x20 /* Phone LED */
86 #define GLED_ON 0x40 /* Gaming LED */
87 #define LCD_ON 0x80 /* LCD backlight */
88 #define GPS_ON 0x100 /* GPS */
89 #define KEY_ON 0x200 /* Keyboard backlight */
91 #define ASUS_LOG ASUS_HOTK_FILE ": "
92 #define ASUS_ERR KERN_ERR ASUS_LOG
93 #define ASUS_WARNING KERN_WARNING ASUS_LOG
94 #define ASUS_NOTICE KERN_NOTICE ASUS_LOG
95 #define ASUS_INFO KERN_INFO ASUS_LOG
96 #define ASUS_DEBUG KERN_DEBUG ASUS_LOG
98 MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
99 MODULE_DESCRIPTION(ASUS_HOTK_NAME);
100 MODULE_LICENSE("GPL");
103 * WAPF defines the behavior of the Fn+Fx wlan key
104 * The significance of values is yet to be found, but
105 * most of the time:
106 * 0x0 will do nothing
107 * 0x1 will allow to control the device with Fn+Fx key.
108 * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key
109 * 0x5 like 0x1 or 0x4
110 * So, if something doesn't work as you want, just try other values =)
112 static uint wapf = 1;
113 module_param(wapf, uint, 0644);
114 MODULE_PARM_DESC(wapf, "WAPF value");
116 #define ASUS_HANDLE(object, paths...) \
117 static acpi_handle object##_handle = NULL; \
118 static char *object##_paths[] = { paths }
120 /* LED */
121 ASUS_HANDLE(mled_set, ASUS_HOTK_PREFIX "MLED");
122 ASUS_HANDLE(tled_set, ASUS_HOTK_PREFIX "TLED");
123 ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED"); /* W1JC */
124 ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED"); /* A7J */
125 ASUS_HANDLE(gled_set, ASUS_HOTK_PREFIX "GLED"); /* G1, G2 (probably) */
127 /* LEDD */
128 ASUS_HANDLE(ledd_set, ASUS_HOTK_PREFIX "SLCM");
131 * Bluetooth and WLAN
132 * WLED and BLED are not handled like other XLED, because in some dsdt
133 * they also control the WLAN/Bluetooth device.
135 ASUS_HANDLE(wl_switch, ASUS_HOTK_PREFIX "WLED");
136 ASUS_HANDLE(bt_switch, ASUS_HOTK_PREFIX "BLED");
137 ASUS_HANDLE(wireless_status, ASUS_HOTK_PREFIX "RSTS"); /* All new models */
139 /* Brightness */
140 ASUS_HANDLE(brightness_set, ASUS_HOTK_PREFIX "SPLV");
141 ASUS_HANDLE(brightness_get, ASUS_HOTK_PREFIX "GPLV");
143 /* Backlight */
144 ASUS_HANDLE(lcd_switch, "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */
145 "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */
146 "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */
147 "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */
148 "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */
149 "\\_SB.PCI0.LPCB.EC0._Q0E", /* P30/P35 */
150 "\\_SB.PCI0.PX40.Q10", /* S1x */
151 "\\Q10"); /* A2x, L2D, L3D, M2E */
153 /* Display */
154 ASUS_HANDLE(display_set, ASUS_HOTK_PREFIX "SDSP");
155 ASUS_HANDLE(display_get,
156 /* A6B, A6K A6R A7D F3JM L4R M6R A3G M6A M6V VX-1 V6J V6V W3Z */
157 "\\_SB.PCI0.P0P1.VGA.GETD",
158 /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V S5A M5A z33A W1Jc W2V G1 */
159 "\\_SB.PCI0.P0P2.VGA.GETD",
160 /* A6V A6Q */
161 "\\_SB.PCI0.P0P3.VGA.GETD",
162 /* A6T, A6M */
163 "\\_SB.PCI0.P0PA.VGA.GETD",
164 /* L3C */
165 "\\_SB.PCI0.PCI1.VGAC.NMAP",
166 /* Z96F */
167 "\\_SB.PCI0.VGA.GETD",
168 /* A2D */
169 "\\ACTD",
170 /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */
171 "\\ADVG",
172 /* P30 */
173 "\\DNXT",
174 /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */
175 "\\INFB",
176 /* A3F A6F A3N A3L M6N W3N W6A */
177 "\\SSTE");
179 ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC"); /* Z71A Z71V */
180 ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL"); /* Z71A Z71V */
182 /* GPS */
183 /* R2H use different handle for GPS on/off */
184 ASUS_HANDLE(gps_on, ASUS_HOTK_PREFIX "SDON"); /* R2H */
185 ASUS_HANDLE(gps_off, ASUS_HOTK_PREFIX "SDOF"); /* R2H */
186 ASUS_HANDLE(gps_status, ASUS_HOTK_PREFIX "GPST");
188 /* Keyboard light */
189 ASUS_HANDLE(kled_set, ASUS_HOTK_PREFIX "SLKB");
190 ASUS_HANDLE(kled_get, ASUS_HOTK_PREFIX "GLKB");
193 * This is the main structure, we can use it to store anything interesting
194 * about the hotk device
196 struct asus_hotk {
197 char *name; /* laptop name */
198 struct acpi_device *device; /* the device we are in */
199 acpi_handle handle; /* the handle of the hotk device */
200 char status; /* status of the hotk, for LEDs, ... */
201 u32 ledd_status; /* status of the LED display */
202 u8 light_level; /* light sensor level */
203 u8 light_switch; /* light sensor switch value */
204 u16 event_count[128]; /* count for each event TODO make this better */
205 struct input_dev *inputdev;
206 u16 *keycode_map;
210 * This header is made available to allow proper configuration given model,
211 * revision number , ... this info cannot go in struct asus_hotk because it is
212 * available before the hotk
214 static struct acpi_table_header *asus_info;
216 /* The actual device the driver binds to */
217 static struct asus_hotk *hotk;
220 * The hotkey driver declaration
222 static const struct acpi_device_id asus_device_ids[] = {
223 {"ATK0100", 0},
224 {"ATK0101", 0},
225 {"", 0},
227 MODULE_DEVICE_TABLE(acpi, asus_device_ids);
229 static int asus_hotk_add(struct acpi_device *device);
230 static int asus_hotk_remove(struct acpi_device *device, int type);
231 static void asus_hotk_notify(struct acpi_device *device, u32 event);
233 static struct acpi_driver asus_hotk_driver = {
234 .name = ASUS_HOTK_NAME,
235 .class = ASUS_HOTK_CLASS,
236 .ids = asus_device_ids,
237 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
238 .ops = {
239 .add = asus_hotk_add,
240 .remove = asus_hotk_remove,
241 .notify = asus_hotk_notify,
245 /* The backlight device /sys/class/backlight */
246 static struct backlight_device *asus_backlight_device;
249 * The backlight class declaration
251 static int read_brightness(struct backlight_device *bd);
252 static int update_bl_status(struct backlight_device *bd);
253 static struct backlight_ops asusbl_ops = {
254 .get_brightness = read_brightness,
255 .update_status = update_bl_status,
259 * These functions actually update the LED's, and are called from a
260 * workqueue. By doing this as separate work rather than when the LED
261 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
262 * potentially bad time, such as a timer interrupt.
264 static struct workqueue_struct *led_workqueue;
266 #define ASUS_LED(object, ledname, max) \
267 static void object##_led_set(struct led_classdev *led_cdev, \
268 enum led_brightness value); \
269 static enum led_brightness object##_led_get( \
270 struct led_classdev *led_cdev); \
271 static void object##_led_update(struct work_struct *ignored); \
272 static int object##_led_wk; \
273 static DECLARE_WORK(object##_led_work, object##_led_update); \
274 static struct led_classdev object##_led = { \
275 .name = "asus::" ledname, \
276 .brightness_set = object##_led_set, \
277 .brightness_get = object##_led_get, \
278 .max_brightness = max \
281 ASUS_LED(mled, "mail", 1);
282 ASUS_LED(tled, "touchpad", 1);
283 ASUS_LED(rled, "record", 1);
284 ASUS_LED(pled, "phone", 1);
285 ASUS_LED(gled, "gaming", 1);
286 ASUS_LED(kled, "kbd_backlight", 3);
288 struct key_entry {
289 char type;
290 u8 code;
291 u16 keycode;
294 enum { KE_KEY, KE_END };
296 static struct key_entry asus_keymap[] = {
297 {KE_KEY, 0x02, KEY_SCREENLOCK},
298 {KE_KEY, 0x05, KEY_WLAN},
299 {KE_KEY, 0x08, BTN_TOUCH},
300 {KE_KEY, 0x17, KEY_ZOOM},
301 {KE_KEY, 0x1f, KEY_BATTERY},
302 {KE_KEY, 0x30, KEY_VOLUMEUP},
303 {KE_KEY, 0x31, KEY_VOLUMEDOWN},
304 {KE_KEY, 0x32, KEY_MUTE},
305 {KE_KEY, 0x33, KEY_SWITCHVIDEOMODE},
306 {KE_KEY, 0x34, KEY_SWITCHVIDEOMODE},
307 {KE_KEY, 0x40, KEY_PREVIOUSSONG},
308 {KE_KEY, 0x41, KEY_NEXTSONG},
309 {KE_KEY, 0x43, KEY_STOPCD},
310 {KE_KEY, 0x45, KEY_PLAYPAUSE},
311 {KE_KEY, 0x4c, KEY_MEDIA},
312 {KE_KEY, 0x50, KEY_EMAIL},
313 {KE_KEY, 0x51, KEY_WWW},
314 {KE_KEY, 0x55, KEY_CALC},
315 {KE_KEY, 0x5C, KEY_SCREENLOCK}, /* Screenlock */
316 {KE_KEY, 0x5D, KEY_WLAN},
317 {KE_KEY, 0x5E, KEY_WLAN},
318 {KE_KEY, 0x5F, KEY_WLAN},
319 {KE_KEY, 0x60, KEY_SWITCHVIDEOMODE},
320 {KE_KEY, 0x61, KEY_SWITCHVIDEOMODE},
321 {KE_KEY, 0x62, KEY_SWITCHVIDEOMODE},
322 {KE_KEY, 0x63, KEY_SWITCHVIDEOMODE},
323 {KE_KEY, 0x6B, BTN_TOUCH}, /* Lock Mouse */
324 {KE_KEY, 0x82, KEY_CAMERA},
325 {KE_KEY, 0x8A, KEY_PROG1},
326 {KE_KEY, 0x95, KEY_MEDIA},
327 {KE_KEY, 0x99, KEY_PHONE},
328 {KE_KEY, 0xc4, KEY_KBDILLUMUP},
329 {KE_KEY, 0xc5, KEY_KBDILLUMDOWN},
330 {KE_END, 0},
334 * This function evaluates an ACPI method, given an int as parameter, the
335 * method is searched within the scope of the handle, can be NULL. The output
336 * of the method is written is output, which can also be NULL
338 * returns 0 if write is successful, -1 else.
340 static int write_acpi_int(acpi_handle handle, const char *method, int val,
341 struct acpi_buffer *output)
343 struct acpi_object_list params; /* list of input parameters (an int) */
344 union acpi_object in_obj; /* the only param we use */
345 acpi_status status;
347 if (!handle)
348 return 0;
350 params.count = 1;
351 params.pointer = &in_obj;
352 in_obj.type = ACPI_TYPE_INTEGER;
353 in_obj.integer.value = val;
355 status = acpi_evaluate_object(handle, (char *)method, &params, output);
356 if (status == AE_OK)
357 return 0;
358 else
359 return -1;
362 static int read_wireless_status(int mask)
364 unsigned long long status;
365 acpi_status rv = AE_OK;
367 if (!wireless_status_handle)
368 return (hotk->status & mask) ? 1 : 0;
370 rv = acpi_evaluate_integer(wireless_status_handle, NULL, NULL, &status);
371 if (ACPI_FAILURE(rv))
372 pr_warning("Error reading Wireless status\n");
373 else
374 return (status & mask) ? 1 : 0;
376 return (hotk->status & mask) ? 1 : 0;
379 static int read_gps_status(void)
381 unsigned long long status;
382 acpi_status rv = AE_OK;
384 rv = acpi_evaluate_integer(gps_status_handle, NULL, NULL, &status);
385 if (ACPI_FAILURE(rv))
386 pr_warning("Error reading GPS status\n");
387 else
388 return status ? 1 : 0;
390 return (hotk->status & GPS_ON) ? 1 : 0;
393 /* Generic LED functions */
394 static int read_status(int mask)
396 /* There is a special method for both wireless devices */
397 if (mask == BT_ON || mask == WL_ON)
398 return read_wireless_status(mask);
399 else if (mask == GPS_ON)
400 return read_gps_status();
402 return (hotk->status & mask) ? 1 : 0;
405 static void write_status(acpi_handle handle, int out, int mask)
407 hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask);
409 switch (mask) {
410 case MLED_ON:
411 out = !(out & 0x1);
412 break;
413 case GLED_ON:
414 out = (out & 0x1) + 1;
415 break;
416 case GPS_ON:
417 handle = (out) ? gps_on_handle : gps_off_handle;
418 out = 0x02;
419 break;
420 default:
421 out &= 0x1;
422 break;
425 if (write_acpi_int(handle, NULL, out, NULL))
426 pr_warning(" write failed %x\n", mask);
429 /* /sys/class/led handlers */
430 #define ASUS_LED_HANDLER(object, mask) \
431 static void object##_led_set(struct led_classdev *led_cdev, \
432 enum led_brightness value) \
434 object##_led_wk = (value > 0) ? 1 : 0; \
435 queue_work(led_workqueue, &object##_led_work); \
437 static void object##_led_update(struct work_struct *ignored) \
439 int value = object##_led_wk; \
440 write_status(object##_set_handle, value, (mask)); \
442 static enum led_brightness object##_led_get( \
443 struct led_classdev *led_cdev) \
445 return led_cdev->brightness; \
448 ASUS_LED_HANDLER(mled, MLED_ON);
449 ASUS_LED_HANDLER(pled, PLED_ON);
450 ASUS_LED_HANDLER(rled, RLED_ON);
451 ASUS_LED_HANDLER(tled, TLED_ON);
452 ASUS_LED_HANDLER(gled, GLED_ON);
455 * Keyboard backlight
457 static int get_kled_lvl(void)
459 unsigned long long kblv;
460 struct acpi_object_list params;
461 union acpi_object in_obj;
462 acpi_status rv;
464 params.count = 1;
465 params.pointer = &in_obj;
466 in_obj.type = ACPI_TYPE_INTEGER;
467 in_obj.integer.value = 2;
469 rv = acpi_evaluate_integer(kled_get_handle, NULL, &params, &kblv);
470 if (ACPI_FAILURE(rv)) {
471 pr_warning("Error reading kled level\n");
472 return 0;
474 return kblv;
477 static int set_kled_lvl(int kblv)
479 if (kblv > 0)
480 kblv = (1 << 7) | (kblv & 0x7F);
481 else
482 kblv = 0;
484 if (write_acpi_int(kled_set_handle, NULL, kblv, NULL)) {
485 pr_warning("Keyboard LED display write failed\n");
486 return -EINVAL;
488 return 0;
491 static void kled_led_set(struct led_classdev *led_cdev,
492 enum led_brightness value)
494 kled_led_wk = value;
495 queue_work(led_workqueue, &kled_led_work);
498 static void kled_led_update(struct work_struct *ignored)
500 set_kled_lvl(kled_led_wk);
503 static enum led_brightness kled_led_get(struct led_classdev *led_cdev)
505 return get_kled_lvl();
508 static int get_lcd_state(void)
510 return read_status(LCD_ON);
513 static int set_lcd_state(int value)
515 int lcd = 0;
516 acpi_status status = 0;
518 lcd = value ? 1 : 0;
520 if (lcd == get_lcd_state())
521 return 0;
523 if (lcd_switch_handle) {
524 status = acpi_evaluate_object(lcd_switch_handle,
525 NULL, NULL, NULL);
527 if (ACPI_FAILURE(status))
528 pr_warning("Error switching LCD\n");
531 write_status(NULL, lcd, LCD_ON);
532 return 0;
535 static void lcd_blank(int blank)
537 struct backlight_device *bd = asus_backlight_device;
539 if (bd) {
540 bd->props.power = blank;
541 backlight_update_status(bd);
545 static int read_brightness(struct backlight_device *bd)
547 unsigned long long value;
548 acpi_status rv = AE_OK;
550 rv = acpi_evaluate_integer(brightness_get_handle, NULL, NULL, &value);
551 if (ACPI_FAILURE(rv))
552 pr_warning("Error reading brightness\n");
554 return value;
557 static int set_brightness(struct backlight_device *bd, int value)
559 int ret = 0;
561 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
562 /* 0 <= value <= 15 */
564 if (write_acpi_int(brightness_set_handle, NULL, value, NULL)) {
565 pr_warning("Error changing brightness\n");
566 ret = -EIO;
569 return ret;
572 static int update_bl_status(struct backlight_device *bd)
574 int rv;
575 int value = bd->props.brightness;
577 rv = set_brightness(bd, value);
578 if (rv)
579 return rv;
581 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0;
582 return set_lcd_state(value);
586 * Platform device handlers
590 * We write our info in page, we begin at offset off and cannot write more
591 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
592 * number of bytes written in page
594 static ssize_t show_infos(struct device *dev,
595 struct device_attribute *attr, char *page)
597 int len = 0;
598 unsigned long long temp;
599 char buf[16]; /* enough for all info */
600 acpi_status rv = AE_OK;
603 * We use the easy way, we don't care of off and count, so we don't set eof
604 * to 1
607 len += sprintf(page, ASUS_HOTK_NAME " " ASUS_LAPTOP_VERSION "\n");
608 len += sprintf(page + len, "Model reference : %s\n", hotk->name);
610 * The SFUN method probably allows the original driver to get the list
611 * of features supported by a given model. For now, 0x0100 or 0x0800
612 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
613 * The significance of others is yet to be found.
615 rv = acpi_evaluate_integer(hotk->handle, "SFUN", NULL, &temp);
616 if (!ACPI_FAILURE(rv))
617 len += sprintf(page + len, "SFUN value : %#x\n",
618 (uint) temp);
620 * The HWRS method return informations about the hardware.
621 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
622 * The significance of others is yet to be found.
623 * If we don't find the method, we assume the device are present.
625 rv = acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &temp);
626 if (!ACPI_FAILURE(rv))
627 len += sprintf(page + len, "HRWS value : %#x\n",
628 (uint) temp);
630 * Another value for userspace: the ASYM method returns 0x02 for
631 * battery low and 0x04 for battery critical, its readings tend to be
632 * more accurate than those provided by _BST.
633 * Note: since not all the laptops provide this method, errors are
634 * silently ignored.
636 rv = acpi_evaluate_integer(hotk->handle, "ASYM", NULL, &temp);
637 if (!ACPI_FAILURE(rv))
638 len += sprintf(page + len, "ASYM value : %#x\n",
639 (uint) temp);
640 if (asus_info) {
641 snprintf(buf, 16, "%d", asus_info->length);
642 len += sprintf(page + len, "DSDT length : %s\n", buf);
643 snprintf(buf, 16, "%d", asus_info->checksum);
644 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
645 snprintf(buf, 16, "%d", asus_info->revision);
646 len += sprintf(page + len, "DSDT revision : %s\n", buf);
647 snprintf(buf, 7, "%s", asus_info->oem_id);
648 len += sprintf(page + len, "OEM id : %s\n", buf);
649 snprintf(buf, 9, "%s", asus_info->oem_table_id);
650 len += sprintf(page + len, "OEM table id : %s\n", buf);
651 snprintf(buf, 16, "%x", asus_info->oem_revision);
652 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
653 snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
654 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
655 snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
656 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
659 return len;
662 static int parse_arg(const char *buf, unsigned long count, int *val)
664 if (!count)
665 return 0;
666 if (count > 31)
667 return -EINVAL;
668 if (sscanf(buf, "%i", val) != 1)
669 return -EINVAL;
670 return count;
673 static ssize_t store_status(const char *buf, size_t count,
674 acpi_handle handle, int mask)
676 int rv, value;
677 int out = 0;
679 rv = parse_arg(buf, count, &value);
680 if (rv > 0)
681 out = value ? 1 : 0;
683 write_status(handle, out, mask);
685 return rv;
689 * LEDD display
691 static ssize_t show_ledd(struct device *dev,
692 struct device_attribute *attr, char *buf)
694 return sprintf(buf, "0x%08x\n", hotk->ledd_status);
697 static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
698 const char *buf, size_t count)
700 int rv, value;
702 rv = parse_arg(buf, count, &value);
703 if (rv > 0) {
704 if (write_acpi_int(ledd_set_handle, NULL, value, NULL))
705 pr_warning("LED display write failed\n");
706 else
707 hotk->ledd_status = (u32) value;
709 return rv;
713 * WLAN
715 static ssize_t show_wlan(struct device *dev,
716 struct device_attribute *attr, char *buf)
718 return sprintf(buf, "%d\n", read_status(WL_ON));
721 static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
722 const char *buf, size_t count)
724 return store_status(buf, count, wl_switch_handle, WL_ON);
728 * Bluetooth
730 static ssize_t show_bluetooth(struct device *dev,
731 struct device_attribute *attr, char *buf)
733 return sprintf(buf, "%d\n", read_status(BT_ON));
736 static ssize_t store_bluetooth(struct device *dev,
737 struct device_attribute *attr, const char *buf,
738 size_t count)
740 return store_status(buf, count, bt_switch_handle, BT_ON);
744 * Display
746 static void set_display(int value)
748 /* no sanity check needed for now */
749 if (write_acpi_int(display_set_handle, NULL, value, NULL))
750 pr_warning("Error setting display\n");
751 return;
754 static int read_display(void)
756 unsigned long long value = 0;
757 acpi_status rv = AE_OK;
760 * In most of the case, we know how to set the display, but sometime
761 * we can't read it
763 if (display_get_handle) {
764 rv = acpi_evaluate_integer(display_get_handle, NULL,
765 NULL, &value);
766 if (ACPI_FAILURE(rv))
767 pr_warning("Error reading display status\n");
770 value &= 0x0F; /* needed for some models, shouldn't hurt others */
772 return value;
776 * Now, *this* one could be more user-friendly, but so far, no-one has
777 * complained. The significance of bits is the same as in store_disp()
779 static ssize_t show_disp(struct device *dev,
780 struct device_attribute *attr, char *buf)
782 return sprintf(buf, "%d\n", read_display());
786 * Experimental support for display switching. As of now: 1 should activate
787 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
788 * Any combination (bitwise) of these will suffice. I never actually tested 4
789 * displays hooked up simultaneously, so be warned. See the acpi4asus README
790 * for more info.
792 static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
793 const char *buf, size_t count)
795 int rv, value;
797 rv = parse_arg(buf, count, &value);
798 if (rv > 0)
799 set_display(value);
800 return rv;
804 * Light Sens
806 static void set_light_sens_switch(int value)
808 if (write_acpi_int(ls_switch_handle, NULL, value, NULL))
809 pr_warning("Error setting light sensor switch\n");
810 hotk->light_switch = value;
813 static ssize_t show_lssw(struct device *dev,
814 struct device_attribute *attr, char *buf)
816 return sprintf(buf, "%d\n", hotk->light_switch);
819 static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
820 const char *buf, size_t count)
822 int rv, value;
824 rv = parse_arg(buf, count, &value);
825 if (rv > 0)
826 set_light_sens_switch(value ? 1 : 0);
828 return rv;
831 static void set_light_sens_level(int value)
833 if (write_acpi_int(ls_level_handle, NULL, value, NULL))
834 pr_warning("Error setting light sensor level\n");
835 hotk->light_level = value;
838 static ssize_t show_lslvl(struct device *dev,
839 struct device_attribute *attr, char *buf)
841 return sprintf(buf, "%d\n", hotk->light_level);
844 static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
845 const char *buf, size_t count)
847 int rv, value;
849 rv = parse_arg(buf, count, &value);
850 if (rv > 0) {
851 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
852 /* 0 <= value <= 15 */
853 set_light_sens_level(value);
856 return rv;
860 * GPS
862 static ssize_t show_gps(struct device *dev,
863 struct device_attribute *attr, char *buf)
865 return sprintf(buf, "%d\n", read_status(GPS_ON));
868 static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
869 const char *buf, size_t count)
871 return store_status(buf, count, NULL, GPS_ON);
875 * Hotkey functions
877 static struct key_entry *asus_get_entry_by_scancode(int code)
879 struct key_entry *key;
881 for (key = asus_keymap; key->type != KE_END; key++)
882 if (code == key->code)
883 return key;
885 return NULL;
888 static struct key_entry *asus_get_entry_by_keycode(int code)
890 struct key_entry *key;
892 for (key = asus_keymap; key->type != KE_END; key++)
893 if (code == key->keycode && key->type == KE_KEY)
894 return key;
896 return NULL;
899 static int asus_getkeycode(struct input_dev *dev, int scancode, int *keycode)
901 struct key_entry *key = asus_get_entry_by_scancode(scancode);
903 if (key && key->type == KE_KEY) {
904 *keycode = key->keycode;
905 return 0;
908 return -EINVAL;
911 static int asus_setkeycode(struct input_dev *dev, int scancode, int keycode)
913 struct key_entry *key;
914 int old_keycode;
916 if (keycode < 0 || keycode > KEY_MAX)
917 return -EINVAL;
919 key = asus_get_entry_by_scancode(scancode);
920 if (key && key->type == KE_KEY) {
921 old_keycode = key->keycode;
922 key->keycode = keycode;
923 set_bit(keycode, dev->keybit);
924 if (!asus_get_entry_by_keycode(old_keycode))
925 clear_bit(old_keycode, dev->keybit);
926 return 0;
929 return -EINVAL;
932 static void asus_hotk_notify(struct acpi_device *device, u32 event)
934 static struct key_entry *key;
935 u16 count;
937 /* TODO Find a better way to handle events count. */
938 if (!hotk)
939 return;
942 * We need to tell the backlight device when the backlight power is
943 * switched
945 if (event == ATKD_LCD_ON) {
946 write_status(NULL, 1, LCD_ON);
947 lcd_blank(FB_BLANK_UNBLANK);
948 } else if (event == ATKD_LCD_OFF) {
949 write_status(NULL, 0, LCD_ON);
950 lcd_blank(FB_BLANK_POWERDOWN);
953 count = hotk->event_count[event % 128]++;
954 acpi_bus_generate_proc_event(hotk->device, event, count);
955 acpi_bus_generate_netlink_event(hotk->device->pnp.device_class,
956 dev_name(&hotk->device->dev), event,
957 count);
959 if (hotk->inputdev) {
960 key = asus_get_entry_by_scancode(event);
961 if (!key)
962 return ;
964 switch (key->type) {
965 case KE_KEY:
966 input_report_key(hotk->inputdev, key->keycode, 1);
967 input_sync(hotk->inputdev);
968 input_report_key(hotk->inputdev, key->keycode, 0);
969 input_sync(hotk->inputdev);
970 break;
975 #define ASUS_CREATE_DEVICE_ATTR(_name) \
976 struct device_attribute dev_attr_##_name = { \
977 .attr = { \
978 .name = __stringify(_name), \
979 .mode = 0 }, \
980 .show = NULL, \
981 .store = NULL, \
984 #define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \
985 do { \
986 dev_attr_##_name.attr.mode = _mode; \
987 dev_attr_##_name.show = _show; \
988 dev_attr_##_name.store = _store; \
989 } while(0)
991 static ASUS_CREATE_DEVICE_ATTR(infos);
992 static ASUS_CREATE_DEVICE_ATTR(wlan);
993 static ASUS_CREATE_DEVICE_ATTR(bluetooth);
994 static ASUS_CREATE_DEVICE_ATTR(display);
995 static ASUS_CREATE_DEVICE_ATTR(ledd);
996 static ASUS_CREATE_DEVICE_ATTR(ls_switch);
997 static ASUS_CREATE_DEVICE_ATTR(ls_level);
998 static ASUS_CREATE_DEVICE_ATTR(gps);
1000 static struct attribute *asuspf_attributes[] = {
1001 &dev_attr_infos.attr,
1002 &dev_attr_wlan.attr,
1003 &dev_attr_bluetooth.attr,
1004 &dev_attr_display.attr,
1005 &dev_attr_ledd.attr,
1006 &dev_attr_ls_switch.attr,
1007 &dev_attr_ls_level.attr,
1008 &dev_attr_gps.attr,
1009 NULL
1012 static struct attribute_group asuspf_attribute_group = {
1013 .attrs = asuspf_attributes
1016 static struct platform_driver asuspf_driver = {
1017 .driver = {
1018 .name = ASUS_HOTK_FILE,
1019 .owner = THIS_MODULE,
1023 static struct platform_device *asuspf_device;
1025 static void asus_hotk_add_fs(void)
1027 ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL);
1029 if (wl_switch_handle)
1030 ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan);
1032 if (bt_switch_handle)
1033 ASUS_SET_DEVICE_ATTR(bluetooth, 0644,
1034 show_bluetooth, store_bluetooth);
1036 if (display_set_handle && display_get_handle)
1037 ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp);
1038 else if (display_set_handle)
1039 ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp);
1041 if (ledd_set_handle)
1042 ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd);
1044 if (ls_switch_handle && ls_level_handle) {
1045 ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
1046 ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
1049 if (gps_status_handle && gps_on_handle && gps_off_handle)
1050 ASUS_SET_DEVICE_ATTR(gps, 0644, show_gps, store_gps);
1053 static int asus_handle_init(char *name, acpi_handle * handle,
1054 char **paths, int num_paths)
1056 int i;
1057 acpi_status status;
1059 for (i = 0; i < num_paths; i++) {
1060 status = acpi_get_handle(NULL, paths[i], handle);
1061 if (ACPI_SUCCESS(status))
1062 return 0;
1065 *handle = NULL;
1066 return -ENODEV;
1069 #define ASUS_HANDLE_INIT(object) \
1070 asus_handle_init(#object, &object##_handle, object##_paths, \
1071 ARRAY_SIZE(object##_paths))
1074 * This function is used to initialize the hotk with right values. In this
1075 * method, we can make all the detection we want, and modify the hotk struct
1077 static int asus_hotk_get_info(void)
1079 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1080 union acpi_object *model = NULL;
1081 unsigned long long bsts_result, hwrs_result;
1082 char *string = NULL;
1083 acpi_status status;
1086 * Get DSDT headers early enough to allow for differentiating between
1087 * models, but late enough to allow acpi_bus_register_driver() to fail
1088 * before doing anything ACPI-specific. Should we encounter a machine,
1089 * which needs special handling (i.e. its hotkey device has a different
1090 * HID), this bit will be moved. A global variable asus_info contains
1091 * the DSDT header.
1093 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
1094 if (ACPI_FAILURE(status))
1095 pr_warning("Couldn't get the DSDT table header\n");
1097 /* We have to write 0 on init this far for all ASUS models */
1098 if (write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
1099 pr_err("Hotkey initialization failed\n");
1100 return -ENODEV;
1103 /* This needs to be called for some laptops to init properly */
1104 status =
1105 acpi_evaluate_integer(hotk->handle, "BSTS", NULL, &bsts_result);
1106 if (ACPI_FAILURE(status))
1107 pr_warning("Error calling BSTS\n");
1108 else if (bsts_result)
1109 pr_notice("BSTS called, 0x%02x returned\n",
1110 (uint) bsts_result);
1112 /* This too ... */
1113 write_acpi_int(hotk->handle, "CWAP", wapf, NULL);
1116 * Try to match the object returned by INIT to the specific model.
1117 * Handle every possible object (or the lack of thereof) the DSDT
1118 * writers might throw at us. When in trouble, we pass NULL to
1119 * asus_model_match() and try something completely different.
1121 if (buffer.pointer) {
1122 model = buffer.pointer;
1123 switch (model->type) {
1124 case ACPI_TYPE_STRING:
1125 string = model->string.pointer;
1126 break;
1127 case ACPI_TYPE_BUFFER:
1128 string = model->buffer.pointer;
1129 break;
1130 default:
1131 string = "";
1132 break;
1135 hotk->name = kstrdup(string, GFP_KERNEL);
1136 if (!hotk->name)
1137 return -ENOMEM;
1139 if (*string)
1140 pr_notice(" %s model detected\n", string);
1142 ASUS_HANDLE_INIT(mled_set);
1143 ASUS_HANDLE_INIT(tled_set);
1144 ASUS_HANDLE_INIT(rled_set);
1145 ASUS_HANDLE_INIT(pled_set);
1146 ASUS_HANDLE_INIT(gled_set);
1148 ASUS_HANDLE_INIT(ledd_set);
1150 ASUS_HANDLE_INIT(kled_set);
1151 ASUS_HANDLE_INIT(kled_get);
1154 * The HWRS method return informations about the hardware.
1155 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
1156 * The significance of others is yet to be found.
1157 * If we don't find the method, we assume the device are present.
1159 status =
1160 acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &hwrs_result);
1161 if (ACPI_FAILURE(status))
1162 hwrs_result = WL_HWRS | BT_HWRS;
1164 if (hwrs_result & WL_HWRS)
1165 ASUS_HANDLE_INIT(wl_switch);
1166 if (hwrs_result & BT_HWRS)
1167 ASUS_HANDLE_INIT(bt_switch);
1169 ASUS_HANDLE_INIT(wireless_status);
1171 ASUS_HANDLE_INIT(brightness_set);
1172 ASUS_HANDLE_INIT(brightness_get);
1174 ASUS_HANDLE_INIT(lcd_switch);
1176 ASUS_HANDLE_INIT(display_set);
1177 ASUS_HANDLE_INIT(display_get);
1180 * There is a lot of models with "ALSL", but a few get
1181 * a real light sens, so we need to check it.
1183 if (!ASUS_HANDLE_INIT(ls_switch))
1184 ASUS_HANDLE_INIT(ls_level);
1186 ASUS_HANDLE_INIT(gps_on);
1187 ASUS_HANDLE_INIT(gps_off);
1188 ASUS_HANDLE_INIT(gps_status);
1190 kfree(model);
1192 return AE_OK;
1195 static int asus_input_init(void)
1197 const struct key_entry *key;
1198 int result;
1200 hotk->inputdev = input_allocate_device();
1201 if (!hotk->inputdev) {
1202 pr_info("Unable to allocate input device\n");
1203 return 0;
1205 hotk->inputdev->name = "Asus Laptop extra buttons";
1206 hotk->inputdev->phys = ASUS_HOTK_FILE "/input0";
1207 hotk->inputdev->id.bustype = BUS_HOST;
1208 hotk->inputdev->getkeycode = asus_getkeycode;
1209 hotk->inputdev->setkeycode = asus_setkeycode;
1211 for (key = asus_keymap; key->type != KE_END; key++) {
1212 switch (key->type) {
1213 case KE_KEY:
1214 set_bit(EV_KEY, hotk->inputdev->evbit);
1215 set_bit(key->keycode, hotk->inputdev->keybit);
1216 break;
1219 result = input_register_device(hotk->inputdev);
1220 if (result) {
1221 pr_info("Unable to register input device\n");
1222 input_free_device(hotk->inputdev);
1224 return result;
1227 static int asus_hotk_check(void)
1229 int result = 0;
1231 result = acpi_bus_get_status(hotk->device);
1232 if (result)
1233 return result;
1235 if (hotk->device->status.present) {
1236 result = asus_hotk_get_info();
1237 } else {
1238 pr_err("Hotkey device not present, aborting\n");
1239 return -EINVAL;
1242 return result;
1245 static int asus_hotk_found;
1247 static int asus_hotk_add(struct acpi_device *device)
1249 int result;
1251 if (!device)
1252 return -EINVAL;
1254 pr_notice("Asus Laptop Support version %s\n",
1255 ASUS_LAPTOP_VERSION);
1257 hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL);
1258 if (!hotk)
1259 return -ENOMEM;
1261 hotk->handle = device->handle;
1262 strcpy(acpi_device_name(device), ASUS_HOTK_DEVICE_NAME);
1263 strcpy(acpi_device_class(device), ASUS_HOTK_CLASS);
1264 device->driver_data = hotk;
1265 hotk->device = device;
1267 result = asus_hotk_check();
1268 if (result)
1269 goto end;
1271 asus_hotk_add_fs();
1273 asus_hotk_found = 1;
1275 /* WLED and BLED are on by default */
1276 write_status(bt_switch_handle, 1, BT_ON);
1277 write_status(wl_switch_handle, 1, WL_ON);
1279 /* If the h/w switch is off, we need to check the real status */
1280 write_status(NULL, read_status(BT_ON), BT_ON);
1281 write_status(NULL, read_status(WL_ON), WL_ON);
1283 /* LCD Backlight is on by default */
1284 write_status(NULL, 1, LCD_ON);
1286 /* Keyboard Backlight is on by default */
1287 if (kled_set_handle)
1288 set_kled_lvl(1);
1290 /* LED display is off by default */
1291 hotk->ledd_status = 0xFFF;
1293 /* Set initial values of light sensor and level */
1294 hotk->light_switch = 0; /* Default to light sensor disabled */
1295 hotk->light_level = 5; /* level 5 for sensor sensitivity */
1297 if (ls_switch_handle)
1298 set_light_sens_switch(hotk->light_switch);
1300 if (ls_level_handle)
1301 set_light_sens_level(hotk->light_level);
1303 /* GPS is on by default */
1304 write_status(NULL, 1, GPS_ON);
1306 end:
1307 if (result) {
1308 kfree(hotk->name);
1309 kfree(hotk);
1312 return result;
1315 static int asus_hotk_remove(struct acpi_device *device, int type)
1317 if (!device || !acpi_driver_data(device))
1318 return -EINVAL;
1320 kfree(hotk->name);
1321 kfree(hotk);
1323 return 0;
1326 static void asus_backlight_exit(void)
1328 if (asus_backlight_device)
1329 backlight_device_unregister(asus_backlight_device);
1332 #define ASUS_LED_UNREGISTER(object) \
1333 if (object##_led.dev) \
1334 led_classdev_unregister(&object##_led)
1336 static void asus_led_exit(void)
1338 destroy_workqueue(led_workqueue);
1339 ASUS_LED_UNREGISTER(mled);
1340 ASUS_LED_UNREGISTER(tled);
1341 ASUS_LED_UNREGISTER(pled);
1342 ASUS_LED_UNREGISTER(rled);
1343 ASUS_LED_UNREGISTER(gled);
1344 ASUS_LED_UNREGISTER(kled);
1347 static void asus_input_exit(void)
1349 if (hotk->inputdev)
1350 input_unregister_device(hotk->inputdev);
1353 static void __exit asus_laptop_exit(void)
1355 asus_backlight_exit();
1356 asus_led_exit();
1357 asus_input_exit();
1359 acpi_bus_unregister_driver(&asus_hotk_driver);
1360 sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group);
1361 platform_device_unregister(asuspf_device);
1362 platform_driver_unregister(&asuspf_driver);
1365 static int asus_backlight_init(struct device *dev)
1367 struct backlight_device *bd;
1369 if (brightness_set_handle && lcd_switch_handle) {
1370 bd = backlight_device_register(ASUS_HOTK_FILE, dev,
1371 NULL, &asusbl_ops);
1372 if (IS_ERR(bd)) {
1373 pr_err("Could not register asus backlight device\n");
1374 asus_backlight_device = NULL;
1375 return PTR_ERR(bd);
1378 asus_backlight_device = bd;
1380 bd->props.max_brightness = 15;
1381 bd->props.brightness = read_brightness(NULL);
1382 bd->props.power = FB_BLANK_UNBLANK;
1383 backlight_update_status(bd);
1385 return 0;
1388 static int asus_led_register(acpi_handle handle,
1389 struct led_classdev *ldev, struct device *dev)
1391 if (!handle)
1392 return 0;
1394 return led_classdev_register(dev, ldev);
1397 #define ASUS_LED_REGISTER(object, device) \
1398 asus_led_register(object##_set_handle, &object##_led, device)
1400 static int asus_led_init(struct device *dev)
1402 int rv;
1404 rv = ASUS_LED_REGISTER(mled, dev);
1405 if (rv)
1406 goto out;
1408 rv = ASUS_LED_REGISTER(tled, dev);
1409 if (rv)
1410 goto out1;
1412 rv = ASUS_LED_REGISTER(rled, dev);
1413 if (rv)
1414 goto out2;
1416 rv = ASUS_LED_REGISTER(pled, dev);
1417 if (rv)
1418 goto out3;
1420 rv = ASUS_LED_REGISTER(gled, dev);
1421 if (rv)
1422 goto out4;
1424 if (kled_set_handle && kled_get_handle)
1425 rv = ASUS_LED_REGISTER(kled, dev);
1426 if (rv)
1427 goto out5;
1429 led_workqueue = create_singlethread_workqueue("led_workqueue");
1430 if (!led_workqueue)
1431 goto out6;
1433 return 0;
1434 out6:
1435 rv = -ENOMEM;
1436 ASUS_LED_UNREGISTER(kled);
1437 out5:
1438 ASUS_LED_UNREGISTER(gled);
1439 out4:
1440 ASUS_LED_UNREGISTER(pled);
1441 out3:
1442 ASUS_LED_UNREGISTER(rled);
1443 out2:
1444 ASUS_LED_UNREGISTER(tled);
1445 out1:
1446 ASUS_LED_UNREGISTER(mled);
1447 out:
1448 return rv;
1451 static int __init asus_laptop_init(void)
1453 int result;
1455 if (acpi_disabled)
1456 return -ENODEV;
1458 result = acpi_bus_register_driver(&asus_hotk_driver);
1459 if (result < 0)
1460 return result;
1463 * This is a bit of a kludge. We only want this module loaded
1464 * for ASUS systems, but there's currently no way to probe the
1465 * ACPI namespace for ASUS HIDs. So we just return failure if
1466 * we didn't find one, which will cause the module to be
1467 * unloaded.
1469 if (!asus_hotk_found) {
1470 acpi_bus_unregister_driver(&asus_hotk_driver);
1471 return -ENODEV;
1474 result = asus_input_init();
1475 if (result)
1476 goto fail_input;
1478 /* Register platform stuff */
1479 result = platform_driver_register(&asuspf_driver);
1480 if (result)
1481 goto fail_platform_driver;
1483 asuspf_device = platform_device_alloc(ASUS_HOTK_FILE, -1);
1484 if (!asuspf_device) {
1485 result = -ENOMEM;
1486 goto fail_platform_device1;
1489 result = platform_device_add(asuspf_device);
1490 if (result)
1491 goto fail_platform_device2;
1493 result = sysfs_create_group(&asuspf_device->dev.kobj,
1494 &asuspf_attribute_group);
1495 if (result)
1496 goto fail_sysfs;
1498 result = asus_led_init(&asuspf_device->dev);
1499 if (result)
1500 goto fail_led;
1502 if (!acpi_video_backlight_support()) {
1503 result = asus_backlight_init(&asuspf_device->dev);
1504 if (result)
1505 goto fail_backlight;
1506 } else
1507 pr_info("Brightness ignored, must be controlled by "
1508 "ACPI video driver\n");
1510 return 0;
1512 fail_backlight:
1513 asus_led_exit();
1515 fail_led:
1516 sysfs_remove_group(&asuspf_device->dev.kobj,
1517 &asuspf_attribute_group);
1519 fail_sysfs:
1520 platform_device_del(asuspf_device);
1522 fail_platform_device2:
1523 platform_device_put(asuspf_device);
1525 fail_platform_device1:
1526 platform_driver_unregister(&asuspf_driver);
1528 fail_platform_driver:
1529 asus_input_exit();
1531 fail_input:
1533 return result;
1536 module_init(asus_laptop_init);
1537 module_exit(asus_laptop_exit);