Merge branch 'perf-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[pandora-kernel.git] / drivers / platform / x86 / asus-laptop.c
index eaffe73..b39d2bb 100644 (file)
@@ -33,6 +33,8 @@
  *  Sam Lin        - GPS support
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #define ASUS_HOTK_NAME          "Asus Laptop Support"
 #define ASUS_HOTK_CLASS         "hotkey"
 #define ASUS_HOTK_DEVICE_NAME   "Hotkey"
-#define ASUS_HOTK_FILE          "asus-laptop"
+#define ASUS_HOTK_FILE          KBUILD_MODNAME
 #define ASUS_HOTK_PREFIX        "\\_SB.ATKD."
 
+
 /*
  * Some events we use, same for all Asus
  */
  * Flags for hotk status
  * WL_ON and BT_ON are also used for wireless_status()
  */
-#define WL_ON       0x01       //internal Wifi
-#define BT_ON       0x02       //internal Bluetooth
-#define MLED_ON     0x04       //mail LED
-#define TLED_ON     0x08       //touchpad LED
-#define RLED_ON     0x10       //Record LED
-#define PLED_ON     0x20       //Phone LED
-#define GLED_ON     0x40       //Gaming LED
-#define LCD_ON      0x80       //LCD backlight
-#define GPS_ON      0x100      //GPS
+#define WL_ON       0x01       /* internal Wifi */
+#define BT_ON       0x02       /* internal Bluetooth */
+#define MLED_ON     0x04       /* mail LED */
+#define TLED_ON     0x08       /* touchpad LED */
+#define RLED_ON     0x10       /* Record LED */
+#define PLED_ON     0x20       /* Phone LED */
+#define GLED_ON     0x40       /* Gaming LED */
+#define LCD_ON      0x80       /* LCD backlight */
+#define GPS_ON      0x100      /* GPS */
+#define KEY_ON      0x200      /* Keyboard backlight */
 
 #define ASUS_LOG    ASUS_HOTK_FILE ": "
 #define ASUS_ERR    KERN_ERR    ASUS_LOG
@@ -95,7 +99,8 @@ MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
 MODULE_DESCRIPTION(ASUS_HOTK_NAME);
 MODULE_LICENSE("GPL");
 
-/* WAPF defines the behavior of the Fn+Fx wlan key
+/*
+ * WAPF defines the behavior of the Fn+Fx wlan key
  * The significance of values is yet to be found, but
  * most of the time:
  * 0x0 will do nothing
@@ -122,7 +127,8 @@ ASUS_HANDLE(gled_set, ASUS_HOTK_PREFIX "GLED");     /* G1, G2 (probably) */
 /* LEDD */
 ASUS_HANDLE(ledd_set, ASUS_HOTK_PREFIX "SLCM");
 
-/* Bluetooth and WLAN
+/*
+ * Bluetooth and WLAN
  * WLED and BLED are not handled like other XLED, because in some dsdt
  * they also control the WLAN/Bluetooth device.
  */
@@ -146,22 +152,32 @@ ASUS_HANDLE(lcd_switch, "\\_SB.PCI0.SBRG.EC0._Q10",       /* All new models */
 
 /* Display */
 ASUS_HANDLE(display_set, ASUS_HOTK_PREFIX "SDSP");
-ASUS_HANDLE(display_get, "\\_SB.PCI0.P0P1.VGA.GETD",   /*  A6B, A6K A6R A7D F3JM L4R M6R A3G
-                                                          M6A M6V VX-1 V6J V6V W3Z */
-           "\\_SB.PCI0.P0P2.VGA.GETD", /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V
-                                          S5A M5A z33A W1Jc W2V G1 */
-           "\\_SB.PCI0.P0P3.VGA.GETD", /* A6V A6Q */
-           "\\_SB.PCI0.P0PA.VGA.GETD", /* A6T, A6M */
-           "\\_SB.PCI0.PCI1.VGAC.NMAP",        /* L3C */
-           "\\_SB.PCI0.VGA.GETD",      /* Z96F */
-           "\\ACTD",           /* A2D */
-           "\\ADVG",           /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */
-           "\\DNXT",           /* P30 */
-           "\\INFB",           /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */
-           "\\SSTE");          /* A3F A6F A3N A3L M6N W3N W6A */
-
-ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC");       /* Z71A Z71V */
-ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL");        /* Z71A Z71V */
+ASUS_HANDLE(display_get,
+           /* A6B, A6K A6R A7D F3JM L4R M6R A3G M6A M6V VX-1 V6J V6V W3Z */
+           "\\_SB.PCI0.P0P1.VGA.GETD",
+           /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V S5A M5A z33A W1Jc W2V G1 */
+           "\\_SB.PCI0.P0P2.VGA.GETD",
+           /* A6V A6Q */
+           "\\_SB.PCI0.P0P3.VGA.GETD",
+           /* A6T, A6M */
+           "\\_SB.PCI0.P0PA.VGA.GETD",
+           /* L3C */
+           "\\_SB.PCI0.PCI1.VGAC.NMAP",
+           /* Z96F */
+           "\\_SB.PCI0.VGA.GETD",
+           /* A2D */
+           "\\ACTD",
+           /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */
+           "\\ADVG",
+           /* P30 */
+           "\\DNXT",
+           /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */
+           "\\INFB",
+           /* A3F A6F A3N A3L M6N W3N W6A */
+           "\\SSTE");
+
+ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC"); /* Z71A Z71V */
+ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL");         /* Z71A Z71V */
 
 /* GPS */
 /* R2H use different handle for GPS on/off */
@@ -169,19 +185,23 @@ ASUS_HANDLE(gps_on, ASUS_HOTK_PREFIX "SDON");     /* R2H */
 ASUS_HANDLE(gps_off, ASUS_HOTK_PREFIX "SDOF"); /* R2H */
 ASUS_HANDLE(gps_status, ASUS_HOTK_PREFIX "GPST");
 
+/* Keyboard light */
+ASUS_HANDLE(kled_set, ASUS_HOTK_PREFIX "SLKB");
+ASUS_HANDLE(kled_get, ASUS_HOTK_PREFIX "GLKB");
+
 /*
  * This is the main structure, we can use it to store anything interesting
  * about the hotk device
  */
 struct asus_hotk {
-       char *name;             //laptop name
-       struct acpi_device *device;     //the device we are in
-       acpi_handle handle;     //the handle of the hotk device
-       char status;            //status of the hotk, for LEDs, ...
-       u32 ledd_status;        //status of the LED display
-       u8 light_level;         //light sensor level
-       u8 light_switch;        //light sensor switch value
-       u16 event_count[128];   //count for each event TODO make this better
+       char *name;             /* laptop name */
+       struct acpi_device *device;     /* the device we are in */
+       acpi_handle handle;     /* the handle of the hotk device */
+       char status;            /* status of the hotk, for LEDs, ... */
+       u32 ledd_status;        /* status of the LED display */
+       u8 light_level;         /* light sensor level */
+       u8 light_switch;        /* light sensor switch value */
+       u16 event_count[128];   /* count for each event TODO make this better */
        struct input_dev *inputdev;
        u16 *keycode_map;
 };
@@ -234,28 +254,35 @@ static struct backlight_ops asusbl_ops = {
        .update_status = update_bl_status,
 };
 
-/* These functions actually update the LED's, and are called from a
+/*
+ * These functions actually update the LED's, and are called from a
  * workqueue. By doing this as separate work rather than when the LED
  * subsystem asks, we avoid messing with the Asus ACPI stuff during a
- * potentially bad time, such as a timer interrupt. */
+ * potentially bad time, such as a timer interrupt.
+ */
 static struct workqueue_struct *led_workqueue;
 
-#define ASUS_LED(object, ledname)                                      \
+#define ASUS_LED(object, ledname, max)                                 \
        static void object##_led_set(struct led_classdev *led_cdev,     \
                                     enum led_brightness value);        \
+       static enum led_brightness object##_led_get(                    \
+               struct led_classdev *led_cdev);                         \
        static void object##_led_update(struct work_struct *ignored);   \
        static int object##_led_wk;                                     \
        static DECLARE_WORK(object##_led_work, object##_led_update);    \
        static struct led_classdev object##_led = {                     \
                .name           = "asus::" ledname,                     \
                .brightness_set = object##_led_set,                     \
+               .brightness_get = object##_led_get,                     \
+               .max_brightness = max                                   \
        }
 
-ASUS_LED(mled, "mail");
-ASUS_LED(tled, "touchpad");
-ASUS_LED(rled, "record");
-ASUS_LED(pled, "phone");
-ASUS_LED(gled, "gaming");
+ASUS_LED(mled, "mail", 1);
+ASUS_LED(tled, "touchpad", 1);
+ASUS_LED(rled, "record", 1);
+ASUS_LED(pled, "phone", 1);
+ASUS_LED(gled, "gaming", 1);
+ASUS_LED(kled, "kbd_backlight", 3);
 
 struct key_entry {
        char type;
@@ -275,16 +302,23 @@ static struct key_entry asus_keymap[] = {
        {KE_KEY, 0x41, KEY_NEXTSONG},
        {KE_KEY, 0x43, KEY_STOPCD},
        {KE_KEY, 0x45, KEY_PLAYPAUSE},
+       {KE_KEY, 0x4c, KEY_MEDIA},
        {KE_KEY, 0x50, KEY_EMAIL},
        {KE_KEY, 0x51, KEY_WWW},
+       {KE_KEY, 0x55, KEY_CALC},
        {KE_KEY, 0x5C, KEY_SCREENLOCK},  /* Screenlock */
        {KE_KEY, 0x5D, KEY_WLAN},
+       {KE_KEY, 0x5E, KEY_WLAN},
+       {KE_KEY, 0x5F, KEY_WLAN},
+       {KE_KEY, 0x60, KEY_SWITCHVIDEOMODE},
        {KE_KEY, 0x61, KEY_SWITCHVIDEOMODE},
        {KE_KEY, 0x6B, BTN_TOUCH}, /* Lock Mouse */
        {KE_KEY, 0x82, KEY_CAMERA},
        {KE_KEY, 0x8A, KEY_PROG1},
        {KE_KEY, 0x95, KEY_MEDIA},
        {KE_KEY, 0x99, KEY_PHONE},
+       {KE_KEY, 0xc4, KEY_KBDILLUMUP},
+       {KE_KEY, 0xc5, KEY_KBDILLUMDOWN},
        {KE_END, 0},
 };
 
@@ -298,8 +332,8 @@ static struct key_entry asus_keymap[] = {
 static int write_acpi_int(acpi_handle handle, const char *method, int val,
                          struct acpi_buffer *output)
 {
-       struct acpi_object_list params; //list of input parameters (an int here)
-       union acpi_object in_obj;       //the only param we use
+       struct acpi_object_list params; /* list of input parameters (an int) */
+       union acpi_object in_obj;       /* the only param we use */
        acpi_status status;
 
        if (!handle)
@@ -327,7 +361,7 @@ static int read_wireless_status(int mask)
 
        rv = acpi_evaluate_integer(wireless_status_handle, NULL, NULL, &status);
        if (ACPI_FAILURE(rv))
-               printk(ASUS_WARNING "Error reading Wireless status\n");
+               pr_warning("Error reading Wireless status\n");
        else
                return (status & mask) ? 1 : 0;
 
@@ -341,7 +375,7 @@ static int read_gps_status(void)
 
        rv = acpi_evaluate_integer(gps_status_handle, NULL, NULL, &status);
        if (ACPI_FAILURE(rv))
-               printk(ASUS_WARNING "Error reading GPS status\n");
+               pr_warning("Error reading GPS status\n");
        else
                return status ? 1 : 0;
 
@@ -381,7 +415,7 @@ static void write_status(acpi_handle handle, int out, int mask)
        }
 
        if (write_acpi_int(handle, NULL, out, NULL))
-               printk(ASUS_WARNING " write failed %x\n", mask);
+               pr_warning(" write failed %x\n", mask);
 }
 
 /* /sys/class/led handlers */
@@ -396,6 +430,11 @@ static void write_status(acpi_handle handle, int out, int mask)
        {                                                               \
                int value = object##_led_wk;                            \
                write_status(object##_set_handle, value, (mask));       \
+       }                                                               \
+       static enum led_brightness object##_led_get(                    \
+               struct led_classdev *led_cdev)                          \
+       {                                                               \
+               return led_cdev->brightness;                            \
        }
 
 ASUS_LED_HANDLER(mled, MLED_ON);
@@ -404,6 +443,60 @@ ASUS_LED_HANDLER(rled, RLED_ON);
 ASUS_LED_HANDLER(tled, TLED_ON);
 ASUS_LED_HANDLER(gled, GLED_ON);
 
+/*
+ * Keyboard backlight
+ */
+static int get_kled_lvl(void)
+{
+       unsigned long long kblv;
+       struct acpi_object_list params;
+       union acpi_object in_obj;
+       acpi_status rv;
+
+       params.count = 1;
+       params.pointer = &in_obj;
+       in_obj.type = ACPI_TYPE_INTEGER;
+       in_obj.integer.value = 2;
+
+       rv = acpi_evaluate_integer(kled_get_handle, NULL, &params, &kblv);
+       if (ACPI_FAILURE(rv)) {
+               pr_warning("Error reading kled level\n");
+               return 0;
+       }
+       return kblv;
+}
+
+static int set_kled_lvl(int kblv)
+{
+       if (kblv > 0)
+               kblv = (1 << 7) | (kblv & 0x7F);
+       else
+               kblv = 0;
+
+       if (write_acpi_int(kled_set_handle, NULL, kblv, NULL)) {
+               pr_warning("Keyboard LED display write failed\n");
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static void kled_led_set(struct led_classdev *led_cdev,
+                        enum led_brightness value)
+{
+       kled_led_wk = value;
+       queue_work(led_workqueue, &kled_led_work);
+}
+
+static void kled_led_update(struct work_struct *ignored)
+{
+       set_kled_lvl(kled_led_wk);
+}
+
+static enum led_brightness kled_led_get(struct led_classdev *led_cdev)
+{
+       return get_kled_lvl();
+}
+
 static int get_lcd_state(void)
 {
        return read_status(LCD_ON);
@@ -424,7 +517,7 @@ static int set_lcd_state(int value)
                                              NULL, NULL, NULL);
 
                if (ACPI_FAILURE(status))
-                       printk(ASUS_WARNING "Error switching LCD\n");
+                       pr_warning("Error switching LCD\n");
        }
 
        write_status(NULL, lcd, LCD_ON);
@@ -448,7 +541,7 @@ static int read_brightness(struct backlight_device *bd)
 
        rv = acpi_evaluate_integer(brightness_get_handle, NULL, NULL, &value);
        if (ACPI_FAILURE(rv))
-               printk(ASUS_WARNING "Error reading brightness\n");
+               pr_warning("Error reading brightness\n");
 
        return value;
 }
@@ -461,7 +554,7 @@ static int set_brightness(struct backlight_device *bd, int value)
        /* 0 <= value <= 15 */
 
        if (write_acpi_int(brightness_set_handle, NULL, value, NULL)) {
-               printk(ASUS_WARNING "Error changing brightness\n");
+               pr_warning("Error changing brightness\n");
                ret = -EIO;
        }
 
@@ -495,7 +588,7 @@ static ssize_t show_infos(struct device *dev,
 {
        int len = 0;
        unsigned long long temp;
-       char buf[16];           //enough for all info
+       char buf[16];           /* enough for all info */
        acpi_status rv = AE_OK;
 
        /*
@@ -513,7 +606,17 @@ static ssize_t show_infos(struct device *dev,
         */
        rv = acpi_evaluate_integer(hotk->handle, "SFUN", NULL, &temp);
        if (!ACPI_FAILURE(rv))
-               len += sprintf(page + len, "SFUN value         : 0x%04x\n",
+               len += sprintf(page + len, "SFUN value         : %#x\n",
+                              (uint) temp);
+       /*
+        * The HWRS method return informations about the hardware.
+        * 0x80 bit is for WLAN, 0x100 for Bluetooth.
+        * The significance of others is yet to be found.
+        * If we don't find the method, we assume the device are present.
+        */
+       rv = acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &temp);
+       if (!ACPI_FAILURE(rv))
+               len += sprintf(page + len, "HRWS value         : %#x\n",
                               (uint) temp);
        /*
         * Another value for userspace: the ASYM method returns 0x02 for
@@ -524,7 +627,7 @@ static ssize_t show_infos(struct device *dev,
         */
        rv = acpi_evaluate_integer(hotk->handle, "ASYM", NULL, &temp);
        if (!ACPI_FAILURE(rv))
-               len += sprintf(page + len, "ASYM value         : 0x%04x\n",
+               len += sprintf(page + len, "ASYM value         : %#x\n",
                               (uint) temp);
        if (asus_info) {
                snprintf(buf, 16, "%d", asus_info->length);
@@ -591,7 +694,7 @@ static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
        rv = parse_arg(buf, count, &value);
        if (rv > 0) {
                if (write_acpi_int(ledd_set_handle, NULL, value, NULL))
-                       printk(ASUS_WARNING "LED display write failed\n");
+                       pr_warning("LED display write failed\n");
                else
                        hotk->ledd_status = (u32) value;
        }
@@ -636,7 +739,7 @@ static void set_display(int value)
 {
        /* no sanity check needed for now */
        if (write_acpi_int(display_set_handle, NULL, value, NULL))
-               printk(ASUS_WARNING "Error setting display\n");
+               pr_warning("Error setting display\n");
        return;
 }
 
@@ -645,13 +748,15 @@ static int read_display(void)
        unsigned long long value = 0;
        acpi_status rv = AE_OK;
 
-       /* In most of the case, we know how to set the display, but sometime
-          we can't read it */
+       /*
+        * In most of the case, we know how to set the display, but sometime
+        * we can't read it
+        */
        if (display_get_handle) {
                rv = acpi_evaluate_integer(display_get_handle, NULL,
                                           NULL, &value);
                if (ACPI_FAILURE(rv))
-                       printk(ASUS_WARNING "Error reading display status\n");
+                       pr_warning("Error reading display status\n");
        }
 
        value &= 0x0F;          /* needed for some models, shouldn't hurt others */
@@ -693,7 +798,7 @@ static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
 static void set_light_sens_switch(int value)
 {
        if (write_acpi_int(ls_switch_handle, NULL, value, NULL))
-               printk(ASUS_WARNING "Error setting light sensor switch\n");
+               pr_warning("Error setting light sensor switch\n");
        hotk->light_switch = value;
 }
 
@@ -718,7 +823,7 @@ static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
 static void set_light_sens_level(int value)
 {
        if (write_acpi_int(ls_level_handle, NULL, value, NULL))
-               printk(ASUS_WARNING "Error setting light sensor level\n");
+               pr_warning("Error setting light sensor level\n");
        hotk->light_level = value;
 }
 
@@ -979,11 +1084,11 @@ static int asus_hotk_get_info(void)
         */
        status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
        if (ACPI_FAILURE(status))
-               printk(ASUS_WARNING "Couldn't get the DSDT table header\n");
+               pr_warning("Couldn't get the DSDT table header\n");
 
        /* We have to write 0 on init this far for all ASUS models */
        if (write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
-               printk(ASUS_ERR "Hotkey initialization failed\n");
+               pr_err("Hotkey initialization failed\n");
                return -ENODEV;
        }
 
@@ -991,9 +1096,9 @@ static int asus_hotk_get_info(void)
        status =
            acpi_evaluate_integer(hotk->handle, "BSTS", NULL, &bsts_result);
        if (ACPI_FAILURE(status))
-               printk(ASUS_WARNING "Error calling BSTS\n");
+               pr_warning("Error calling BSTS\n");
        else if (bsts_result)
-               printk(ASUS_NOTICE "BSTS called, 0x%02x returned\n",
+               pr_notice("BSTS called, 0x%02x returned\n",
                       (uint) bsts_result);
 
        /* This too ... */
@@ -1024,7 +1129,7 @@ static int asus_hotk_get_info(void)
                return -ENOMEM;
 
        if (*string)
-               printk(ASUS_NOTICE "  %s model detected\n", string);
+               pr_notice("  %s model detected\n", string);
 
        ASUS_HANDLE_INIT(mled_set);
        ASUS_HANDLE_INIT(tled_set);
@@ -1034,6 +1139,9 @@ static int asus_hotk_get_info(void)
 
        ASUS_HANDLE_INIT(ledd_set);
 
+       ASUS_HANDLE_INIT(kled_set);
+       ASUS_HANDLE_INIT(kled_get);
+
        /*
         * The HWRS method return informations about the hardware.
         * 0x80 bit is for WLAN, 0x100 for Bluetooth.
@@ -1060,8 +1168,10 @@ static int asus_hotk_get_info(void)
        ASUS_HANDLE_INIT(display_set);
        ASUS_HANDLE_INIT(display_get);
 
-       /* There is a lot of models with "ALSL", but a few get
-          a real light sens, so we need to check it. */
+       /*
+        * There is a lot of models with "ALSL", but a few get
+        * a real light sens, so we need to check it.
+        */
        if (!ASUS_HANDLE_INIT(ls_switch))
                ASUS_HANDLE_INIT(ls_level);
 
@@ -1081,7 +1191,7 @@ static int asus_input_init(void)
 
        hotk->inputdev = input_allocate_device();
        if (!hotk->inputdev) {
-               printk(ASUS_INFO "Unable to allocate input device\n");
+               pr_info("Unable to allocate input device\n");
                return 0;
        }
        hotk->inputdev->name = "Asus Laptop extra buttons";
@@ -1100,7 +1210,7 @@ static int asus_input_init(void)
        }
        result = input_register_device(hotk->inputdev);
        if (result) {
-               printk(ASUS_INFO "Unable to register input device\n");
+               pr_info("Unable to register input device\n");
                input_free_device(hotk->inputdev);
        }
        return result;
@@ -1117,7 +1227,7 @@ static int asus_hotk_check(void)
        if (hotk->device->status.present) {
                result = asus_hotk_get_info();
        } else {
-               printk(ASUS_ERR "Hotkey device not present, aborting\n");
+               pr_err("Hotkey device not present, aborting\n");
                return -EINVAL;
        }
 
@@ -1133,7 +1243,7 @@ static int asus_hotk_add(struct acpi_device *device)
        if (!device)
                return -EINVAL;
 
-       printk(ASUS_NOTICE "Asus Laptop Support version %s\n",
+       pr_notice("Asus Laptop Support version %s\n",
               ASUS_LAPTOP_VERSION);
 
        hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL);
@@ -1165,6 +1275,10 @@ static int asus_hotk_add(struct acpi_device *device)
        /* LCD Backlight is on by default */
        write_status(NULL, 1, LCD_ON);
 
+       /* Keyboard Backlight is on by default */
+       if (kled_set_handle)
+               set_kled_lvl(1);
+
        /* LED display is off by default */
        hotk->ledd_status = 0xFFF;
 
@@ -1219,6 +1333,7 @@ static void asus_led_exit(void)
        ASUS_LED_UNREGISTER(pled);
        ASUS_LED_UNREGISTER(rled);
        ASUS_LED_UNREGISTER(gled);
+       ASUS_LED_UNREGISTER(kled);
 }
 
 static void asus_input_exit(void)
@@ -1247,8 +1362,7 @@ static int asus_backlight_init(struct device *dev)
                bd = backlight_device_register(ASUS_HOTK_FILE, dev,
                                               NULL, &asusbl_ops);
                if (IS_ERR(bd)) {
-                       printk(ASUS_ERR
-                              "Could not register asus backlight device\n");
+                       pr_err("Could not register asus backlight device\n");
                        asus_backlight_device = NULL;
                        return PTR_ERR(bd);
                }
@@ -1299,13 +1413,20 @@ static int asus_led_init(struct device *dev)
        if (rv)
                goto out4;
 
+       if (kled_set_handle && kled_get_handle)
+               rv = ASUS_LED_REGISTER(kled, dev);
+       if (rv)
+               goto out5;
+
        led_workqueue = create_singlethread_workqueue("led_workqueue");
        if (!led_workqueue)
-               goto out5;
+               goto out6;
 
        return 0;
-out5:
+out6:
        rv = -ENOMEM;
+       ASUS_LED_UNREGISTER(kled);
+out5:
        ASUS_LED_UNREGISTER(gled);
 out4:
        ASUS_LED_UNREGISTER(pled);
@@ -1321,7 +1442,6 @@ out:
 
 static int __init asus_laptop_init(void)
 {
-       struct device *dev;
        int result;
 
        if (acpi_disabled)
@@ -1343,24 +1463,10 @@ static int __init asus_laptop_init(void)
                return -ENODEV;
        }
 
-       dev = acpi_get_physical_device(hotk->device->handle);
-
-       if (!acpi_video_backlight_support()) {
-               result = asus_backlight_init(dev);
-               if (result)
-                       goto fail_backlight;
-       } else
-               printk(ASUS_INFO "Brightness ignored, must be controlled by "
-                      "ACPI video driver\n");
-
        result = asus_input_init();
        if (result)
                goto fail_input;
 
-       result = asus_led_init(dev);
-       if (result)
-               goto fail_led;
-
        /* Register platform stuff */
        result = platform_driver_register(&asuspf_driver);
        if (result)
@@ -1381,8 +1487,27 @@ static int __init asus_laptop_init(void)
        if (result)
                goto fail_sysfs;
 
+       result = asus_led_init(&asuspf_device->dev);
+       if (result)
+               goto fail_led;
+
+       if (!acpi_video_backlight_support()) {
+               result = asus_backlight_init(&asuspf_device->dev);
+               if (result)
+                       goto fail_backlight;
+       } else
+               pr_info("Brightness ignored, must be controlled by "
+                      "ACPI video driver\n");
+
        return 0;
 
+fail_backlight:
+       asus_led_exit();
+
+fail_led:
+       sysfs_remove_group(&asuspf_device->dev.kobj,
+                         &asuspf_attribute_group);
+
 fail_sysfs:
        platform_device_del(asuspf_device);
 
@@ -1393,15 +1518,9 @@ fail_platform_device1:
        platform_driver_unregister(&asuspf_driver);
 
 fail_platform_driver:
-       asus_led_exit();
-
-fail_led:
        asus_input_exit();
 
 fail_input:
-       asus_backlight_exit();
-
-fail_backlight:
 
        return result;
 }