dm exception store: update dm io interface
[powerpc.git] / drivers / misc / asus-laptop.c
index dcab778..65c32a9 100644 (file)
@@ -3,7 +3,7 @@
  *
  *
  *  Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
- *  Copyright (C) 2006 Corentin Chary
+ *  Copyright (C) 2006-2007 Corentin Chary
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -48,7 +48,7 @@
 #include <acpi/acpi_bus.h>
 #include <asm/uaccess.h>
 
-#define ASUS_LAPTOP_VERSION "0.40"
+#define ASUS_LAPTOP_VERSION "0.41"
 
 #define ASUS_HOTK_NAME          "Asus Laptop Support"
 #define ASUS_HOTK_CLASS         "hotkey"
@@ -81,7 +81,8 @@
 #define TLED_ON     0x08       //touchpad LED
 #define RLED_ON     0x10       //Record LED
 #define PLED_ON     0x20       //Phone LED
-#define LCD_ON      0x40       //LCD backlight
+#define GLED_ON     0x40       //Gaming LED
+#define LCD_ON      0x80       //LCD backlight
 
 #define ASUS_LOG    ASUS_HOTK_FILE ": "
 #define ASUS_ERR    KERN_ERR    ASUS_LOG
@@ -94,6 +95,19 @@ 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
+ * The significance of values is yet to be found, but
+ * most of the time:
+ * 0x0 will do nothing
+ * 0x1 will allow to control the device with Fn+Fx key.
+ * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key
+ * 0x5 like 0x1 or 0x4
+ * So, if something doesn't work as you want, just try other values =)
+ */
+static uint wapf = 1;
+module_param(wapf, uint, 0644);
+MODULE_PARM_DESC(wapf, "WAPF value");
+
 #define ASUS_HANDLE(object, paths...)                                  \
        static acpi_handle  object##_handle = NULL;                     \
        static char *object##_paths[] = { paths }
@@ -103,6 +117,7 @@ ASUS_HANDLE(mled_set, ASUS_HOTK_PREFIX "MLED");
 ASUS_HANDLE(tled_set, ASUS_HOTK_PREFIX "TLED");
 ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED");        /* W1JC */
 ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED");        /* A7J */
+ASUS_HANDLE(gled_set, ASUS_HOTK_PREFIX "GLED");        /* G1, G2 (probably) */
 
 /* LEDD */
 ASUS_HANDLE(ledd_set, ASUS_HOTK_PREFIX "SLCM");
@@ -221,6 +236,7 @@ ASUS_LED(mled, "mail");
 ASUS_LED(tled, "touchpad");
 ASUS_LED(rled, "record");
 ASUS_LED(pled, "phone");
+ASUS_LED(gled, "gaming");
 
 /*
  * This function evaluates an ACPI method, given an int as parameter, the
@@ -272,19 +288,28 @@ static int read_status(int mask)
        return (hotk->status & mask) ? 1 : 0;
 }
 
-static void write_status(acpi_handle handle, int out, int mask, int invert)
+static void write_status(acpi_handle handle, int out, int mask)
 {
        hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask);
 
-       if (invert)             /* invert target value */
+       switch (mask) {
+       case MLED_ON:
                out = !out & 0x1;
+               break;
+       case GLED_ON:
+               out = (out & 0x1) + 1;
+               break;
+       default:
+               out &= 0x1;
+               break;
+       }
 
        if (handle && !write_acpi_int(handle, NULL, out, NULL))
-               printk(ASUS_WARNING " write failed\n");
+               printk(ASUS_WARNING " write failed %x\n", mask);
 }
 
 /* /sys/class/led handlers */
-#define ASUS_LED_HANDLER(object, mask, invert)                         \
+#define ASUS_LED_HANDLER(object, mask)                                 \
        static void object##_led_set(struct led_classdev *led_cdev,     \
                                     enum led_brightness value)         \
        {                                                               \
@@ -294,13 +319,14 @@ static void write_status(acpi_handle handle, int out, int mask, int invert)
        static void object##_led_update(struct work_struct *ignored)    \
        {                                                               \
                int value = object##_led_wk;                            \
-               write_status(object##_set_handle, value, (mask), (invert)); \
+               write_status(object##_set_handle, value, (mask));       \
        }
 
-ASUS_LED_HANDLER(mled, MLED_ON, 1);
-ASUS_LED_HANDLER(pled, PLED_ON, 0);
-ASUS_LED_HANDLER(rled, RLED_ON, 0);
-ASUS_LED_HANDLER(tled, TLED_ON, 0);
+ASUS_LED_HANDLER(mled, MLED_ON);
+ASUS_LED_HANDLER(pled, PLED_ON);
+ASUS_LED_HANDLER(rled, RLED_ON);
+ASUS_LED_HANDLER(tled, TLED_ON);
+ASUS_LED_HANDLER(gled, GLED_ON);
 
 static int get_lcd_state(void)
 {
@@ -325,7 +351,7 @@ static int set_lcd_state(int value)
                        printk(ASUS_WARNING "Error switching LCD\n");
        }
 
-       write_status(NULL, lcd, LCD_ON, 0);
+       write_status(NULL, lcd, LCD_ON);
        return 0;
 }
 
@@ -458,7 +484,7 @@ static int parse_arg(const char *buf, unsigned long count, int *val)
 }
 
 static ssize_t store_status(const char *buf, size_t count,
-                           acpi_handle handle, int mask, int invert)
+                           acpi_handle handle, int mask)
 {
        int rv, value;
        int out = 0;
@@ -467,7 +493,7 @@ static ssize_t store_status(const char *buf, size_t count,
        if (rv > 0)
                out = value ? 1 : 0;
 
-       write_status(handle, out, mask, invert);
+       write_status(handle, out, mask);
 
        return rv;
 }
@@ -508,7 +534,7 @@ static ssize_t show_wlan(struct device *dev,
 static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
                          const char *buf, size_t count)
 {
-       return store_status(buf, count, wl_switch_handle, WL_ON, 0);
+       return store_status(buf, count, wl_switch_handle, WL_ON);
 }
 
 /*
@@ -524,7 +550,7 @@ static ssize_t store_bluetooth(struct device *dev,
                               struct device_attribute *attr, const char *buf,
                               size_t count)
 {
-       return store_status(buf, count, bt_switch_handle, BT_ON, 0);
+       return store_status(buf, count, bt_switch_handle, BT_ON);
 }
 
 /*
@@ -652,10 +678,10 @@ static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
         * switched
         */
        if (event == ATKD_LCD_ON) {
-               write_status(NULL, 1, LCD_ON, 0);
+               write_status(NULL, 1, LCD_ON);
                lcd_blank(FB_BLANK_UNBLANK);
        } else if (event == ATKD_LCD_OFF) {
-               write_status(NULL, 0, LCD_ON, 0);
+               write_status(NULL, 0, LCD_ON);
                lcd_blank(FB_BLANK_POWERDOWN);
        }
 
@@ -798,6 +824,9 @@ static int asus_hotk_get_info(void)
                printk(ASUS_NOTICE "BSTS called, 0x%02x returned\n",
                       (uint) bsts_result);
 
+       /* This too ... */
+       write_acpi_int(hotk->handle, "CWAP", wapf, NULL);
+
        /*
         * Try to match the object returned by INIT to the specific model.
         * Handle every possible object (or the lack of thereof) the DSDT
@@ -829,6 +858,7 @@ static int asus_hotk_get_info(void)
        ASUS_HANDLE_INIT(tled_set);
        ASUS_HANDLE_INIT(rled_set);
        ASUS_HANDLE_INIT(pled_set);
+       ASUS_HANDLE_INIT(gled_set);
 
        ASUS_HANDLE_INIT(ledd_set);
 
@@ -928,11 +958,15 @@ static int asus_hotk_add(struct acpi_device *device)
        asus_hotk_found = 1;
 
        /* WLED and BLED are on by default */
-       write_status(bt_switch_handle, 1, BT_ON, 0);
-       write_status(wl_switch_handle, 1, WL_ON, 0);
+       write_status(bt_switch_handle, 1, BT_ON);
+       write_status(wl_switch_handle, 1, WL_ON);
+
+       /* If the h/w switch is off, we need to check the real status */
+       write_status(NULL, read_status(BT_ON), BT_ON);
+       write_status(NULL, read_status(WL_ON), WL_ON);
 
        /* LCD Backlight is on by default */
-       write_status(NULL, 1, LCD_ON, 0);
+       write_status(NULL, 1, LCD_ON);
 
        /* LED display is off by default */
        hotk->ledd_status = 0xFFF;
@@ -991,6 +1025,7 @@ static void asus_led_exit(void)
        ASUS_LED_UNREGISTER(tled);
        ASUS_LED_UNREGISTER(pled);
        ASUS_LED_UNREGISTER(rled);
+       ASUS_LED_UNREGISTER(gled);
 
        destroy_workqueue(led_workqueue);
 }
@@ -1062,6 +1097,10 @@ static int asus_led_init(struct device *dev)
        if (rv)
                return rv;
 
+       rv = ASUS_LED_REGISTER(gled, dev);
+       if (rv)
+               return rv;
+
        led_workqueue = create_singlethread_workqueue("led_workqueue");
        if (!led_workqueue)
                return -ENOMEM;