Pull fluff into release branch
[sfrench/cifs-2.6.git] / drivers / acpi / asus_acpi.c
index e9ee4c52a5f6266a7edc5df20d80aad2647338ea..84de0887a0da067a2b5073d635dc43f8eec388de 100644 (file)
@@ -26,7 +26,7 @@
  *  Pontus Fuchs   - Helper functions, cleanup
  *  Johann Wiesner - Small compile fixes
  *  John Belmonte  - ACPI code for Toshiba laptop was a good starting point.
- *  Éric Burghard  - LED display support for W1N
+ *  ic Burghard  - LED display support for W1N
  *
  */
 
@@ -35,6 +35,7 @@
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/proc_fs.h>
+#include <linux/backlight.h>
 #include <acpi/acpi_drivers.h>
 #include <acpi/acpi_bus.h>
 #include <asm/uaccess.h>
@@ -138,7 +139,9 @@ struct asus_hotk {
                S2x,            //S200 (J1 reported), Victor MP-XP7210
                W1N,            //W1000N
                W5A,            //W5A
+               W3V,            //W3030V
                xxN,            //M2400N, M3700N, M5200N, M6800N, S1300N, S5200N
+               A4S,            //Z81sp
                //(Centrino)
                END_MODEL
        } model;                //Models currently supported
@@ -376,6 +379,17 @@ static struct model_data model_conf[END_MODEL] = {
         .display_get = "\\ADVG"},
 
        {
+        .name = "W3V",
+        .mt_mled = "MLED",
+        .mt_wled = "WLED",
+        .mt_lcd_switch = xxN_PREFIX "_Q10",
+        .lcd_status = "\\BKLT",
+        .brightness_set = "SPLV",
+        .brightness_get = "GPLV",
+        .display_set = "SDSP",
+        .display_get = "\\INFB"},
+
+       {
         .name = "xxN",
         .mt_mled = "MLED",
 /* WLED present, but not controlled by ACPI */
@@ -384,12 +398,23 @@ static struct model_data model_conf[END_MODEL] = {
         .brightness_set = "SPLV",
         .brightness_get = "GPLV",
         .display_set = "SDSP",
-        .display_get = "\\ADVG"}
+       .display_get = "\\ADVG"},
+
+       {
+               .name              = "A4S",
+               .brightness_set    = "SPLV",
+               .brightness_get    = "GPLV",
+               .mt_bt_switch      = "BLED",
+               .mt_wled           = "WLED"
+       }
+
 };
 
 /* procdir we use */
 static struct proc_dir_entry *asus_proc_dir;
 
+static struct backlight_device *asus_backlight_device;
+
 /*
  * This header is made available to allow proper configuration given model,
  * revision number , ... this info cannot go in struct asus_hotk because it is
@@ -406,7 +431,7 @@ static struct asus_hotk *hotk;
 static int asus_hotk_add(struct acpi_device *device);
 static int asus_hotk_remove(struct acpi_device *device, int type);
 static struct acpi_driver asus_hotk_driver = {
-       .name = ACPI_HOTK_NAME,
+       .name = "asus_acpi",
        .class = ACPI_HOTK_CLASS,
        .ids = ACPI_HOTK_HID,
        .ops = {
@@ -555,11 +580,11 @@ static int
 write_led(const char __user * buffer, unsigned long count,
          char *ledname, int ledmask, int invert)
 {
-       int value;
+       int rv, value;
        int led_out = 0;
 
-       count = parse_arg(buffer, count, &value);
-       if (count > 0)
+       rv = parse_arg(buffer, count, &value);
+       if (rv > 0)
                led_out = value ? 1 : 0;
 
        hotk->status =
@@ -572,7 +597,7 @@ write_led(const char __user * buffer, unsigned long count,
                printk(KERN_WARNING "Asus ACPI: LED (%s) write failed\n",
                       ledname);
 
-       return count;
+       return rv;
 }
 
 /*
@@ -607,20 +632,18 @@ static int
 proc_write_ledd(struct file *file, const char __user * buffer,
                unsigned long count, void *data)
 {
-       int value;
+       int rv, value;
 
-       count = parse_arg(buffer, count, &value);
-       if (count > 0) {
+       rv = parse_arg(buffer, count, &value);
+       if (rv > 0) {
                if (!write_acpi_int
                    (hotk->handle, hotk->methods->mt_ledd, value, NULL))
                        printk(KERN_WARNING
                               "Asus ACPI: LED display write failed\n");
                else
                        hotk->ledd_status = (u32) value;
-       } else if (count < 0)
-               printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
-
-       return count;
+       }
+       return rv;
 }
 
 /*
@@ -761,15 +784,15 @@ static int
 proc_write_lcd(struct file *file, const char __user * buffer,
               unsigned long count, void *data)
 {
-       int value;
+       int rv, value;
 
-       count = parse_arg(buffer, count, &value);
-       if (count > 0)
+       rv = parse_arg(buffer, count, &value);
+       if (rv > 0)
                set_lcd_state(value);
-       return count;
+       return rv;
 }
 
-static int read_brightness(void)
+static int read_brightness(struct backlight_device *bd)
 {
        int value;
 
@@ -791,9 +814,10 @@ static int read_brightness(void)
 /*
  * Change the brightness level
  */
-static void set_brightness(int value)
+static int set_brightness(int value)
 {
        acpi_status status = 0;
+       int ret = 0;
 
        /* SPLV laptop */
        if (hotk->methods->brightness_set) {
@@ -801,11 +825,12 @@ static void set_brightness(int value)
                                    value, NULL))
                        printk(KERN_WARNING
                               "Asus ACPI: Error changing brightness\n");
-               return;
+                       ret = -EIO;
+               goto out;
        }
 
        /* No SPLV method if we are here, act as appropriate */
-       value -= read_brightness();
+       value -= read_brightness(NULL);
        while (value != 0) {
                status = acpi_evaluate_object(NULL, (value > 0) ?
                                              hotk->methods->brightness_up :
@@ -815,33 +840,37 @@ static void set_brightness(int value)
                if (ACPI_FAILURE(status))
                        printk(KERN_WARNING
                               "Asus ACPI: Error changing brightness\n");
+                       ret = -EIO;
        }
-       return;
+out:
+       return ret;
+}
+
+static int set_brightness_status(struct backlight_device *bd)
+{
+       return set_brightness(bd->props->brightness);
 }
 
 static int
 proc_read_brn(char *page, char **start, off_t off, int count, int *eof,
              void *data)
 {
-       return sprintf(page, "%d\n", read_brightness());
+       return sprintf(page, "%d\n", read_brightness(NULL));
 }
 
 static int
 proc_write_brn(struct file *file, const char __user * buffer,
               unsigned long count, void *data)
 {
-       int value;
+       int rv, value;
 
-       count = parse_arg(buffer, count, &value);
-       if (count > 0) {
+       rv = parse_arg(buffer, count, &value);
+       if (rv > 0) {
                value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
                /* 0 <= value <= 15 */
                set_brightness(value);
-       } else if (count < 0) {
-               printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
        }
-
-       return count;
+       return rv;
 }
 
 static void set_display(int value)
@@ -880,15 +909,12 @@ static int
 proc_write_disp(struct file *file, const char __user * buffer,
                unsigned long count, void *data)
 {
-       int value;
+       int rv, value;
 
-       count = parse_arg(buffer, count, &value);
-       if (count > 0)
+       rv = parse_arg(buffer, count, &value);
+       if (rv > 0)
                set_display(value);
-       else if (count < 0)
-               printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
-
-       return count;
+       return rv;
 }
 
 typedef int (proc_readfunc) (char *page, char **start, off_t off, int count,
@@ -1097,8 +1123,12 @@ static int asus_model_match(char *model)
                return A4G;
        else if (strncmp(model, "W1N", 3) == 0)
                return W1N;
+       else if (strncmp(model, "W3V", 3) == 0)
+               return W3V;
        else if (strncmp(model, "W5A", 3) == 0)
                return W5A;
+       else if (strncmp(model, "A4S", 3) == 0)
+               return A4S;
        else
                return END_MODEL;
 }
@@ -1110,7 +1140,6 @@ static int asus_model_match(char *model)
 static int asus_hotk_get_info(void)
 {
        struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
-       struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
        union acpi_object *model = NULL;
        int bsts_result;
        char *string = NULL;
@@ -1124,11 +1153,9 @@ static int asus_hotk_get_info(void)
         * HID), this bit will be moved. A global variable asus_info contains
         * the DSDT header.
         */
-       status = acpi_get_table(ACPI_TABLE_ID_DSDT, 1, &dsdt);
+       status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
        if (ACPI_FAILURE(status))
                printk(KERN_WARNING "  Couldn't get the DSDT table header\n");
-       else
-               asus_info = (struct acpi_table_header *)dsdt.pointer;
 
        /* We have to write 0 on init this far for all ASUS models */
        if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
@@ -1150,7 +1177,7 @@ static int asus_hotk_get_info(void)
         * asus_model_match() and try something completely different.
         */
        if (buffer.pointer) {
-               model = (union acpi_object *)buffer.pointer;
+               model = buffer.pointer;
                switch (model->type) {
                case ACPI_TYPE_STRING:
                        string = model->string.pointer;
@@ -1200,9 +1227,10 @@ static int asus_hotk_get_info(void)
                hotk->methods->mt_wled = NULL;
        /* L5D's WLED is not controlled by ACPI */
        else if (strncmp(string, "M2N", 3) == 0 ||
+                strncmp(string, "W3V", 3) == 0 ||
                 strncmp(string, "S1N", 3) == 0)
                hotk->methods->mt_wled = "WLED";
-       /* M2N and S1N have a usable WLED */
+       /* M2N, S1N and W3V have a usable WLED */
        else if (asus_info) {
                if (strncmp(asus_info->oem_table_id, "L1", 2) == 0)
                        hotk->methods->mled_status = NULL;
@@ -1245,11 +1273,9 @@ static int asus_hotk_add(struct acpi_device *device)
        printk(KERN_NOTICE "Asus Laptop ACPI Extras version %s\n",
               ASUS_ACPI_VERSION);
 
-       hotk =
-           (struct asus_hotk *)kmalloc(sizeof(struct asus_hotk), GFP_KERNEL);
+       hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL);
        if (!hotk)
                return -ENOMEM;
-       memset(hotk, 0, sizeof(struct asus_hotk));
 
        hotk->handle = device->handle;
        strcpy(acpi_device_name(device), ACPI_HOTK_DEVICE_NAME);
@@ -1326,6 +1352,24 @@ static int asus_hotk_remove(struct acpi_device *device, int type)
        return 0;
 }
 
+static struct backlight_properties asus_backlight_data = {
+        .owner          = THIS_MODULE,
+        .get_brightness = read_brightness,
+        .update_status  = set_brightness_status,
+        .max_brightness = 15,
+};
+
+static void __exit asus_acpi_exit(void)
+{
+       if (asus_backlight_device)
+               backlight_device_unregister(asus_backlight_device);
+
+       acpi_bus_unregister_driver(&asus_hotk_driver);
+       remove_proc_entry(PROC_ASUS, acpi_root_dir);
+
+       return;
+}
+
 static int __init asus_acpi_init(void)
 {
        int result;
@@ -1363,17 +1407,15 @@ static int __init asus_acpi_init(void)
                return result;
        }
 
-       return 0;
-}
-
-static void __exit asus_acpi_exit(void)
-{
-       acpi_bus_unregister_driver(&asus_hotk_driver);
-       remove_proc_entry(PROC_ASUS, acpi_root_dir);
-
-       kfree(asus_info);
+       asus_backlight_device = backlight_device_register("asus",NULL,NULL,
+                                                         &asus_backlight_data);
+        if (IS_ERR(asus_backlight_device)) {
+               printk(KERN_ERR "Could not register asus backlight device\n");
+               asus_backlight_device = NULL;
+               asus_acpi_exit();
+       }
 
-       return;
+       return 0;
 }
 
 module_init(asus_acpi_init);