backlight: Remove unneeded owner field
[pandora-kernel.git] / drivers / acpi / ibm_acpi.c
index 392abbb..accf4f7 100644 (file)
@@ -3,6 +3,7 @@
  *
  *
  *  Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
+ *  Copyright (C) 2006 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
  *
  *  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
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#define IBM_VERSION "0.12a"
+#define IBM_VERSION "0.13"
 
 /*
  *  Changelog:
+ *
+ *  2006-11-22 0.13    new maintainer
+ *                     changelog now lives in git commit history, and will
+ *                     not be updated further in-file.
  *  
  *  2005-08-17  0.12   fix compilation on 2.6.13-rc kernels
  *  2005-03-17 0.11    support for 600e, 770x
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/string.h>
+
 #include <linux/proc_fs.h>
 #include <linux/backlight.h>
 #include <asm/uaccess.h>
+
 #include <linux/dmi.h>
 #include <linux/jiffies.h>
 #include <linux/workqueue.h>
 #define IBM_FILE "ibm_acpi"
 #define IBM_URL "http://ibm-acpi.sf.net/"
 
-MODULE_AUTHOR("Borislav Deianov");
+MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
 MODULE_DESCRIPTION(IBM_DESC);
 MODULE_VERSION(IBM_VERSION);
 MODULE_LICENSE("GPL");
@@ -121,28 +128,6 @@ static acpi_handle root_handle = NULL;
        static char        *object##_path;                      \
        static char        *object##_paths[] = { paths }
 
-/*
- * The following models are supported to various degrees:
- *
- * 570, 600e, 600x, 770e, 770x
- * A20m, A21e, A21m, A21p, A22p, A30, A30p, A31, A31p
- * G40, G41
- * R30, R31, R32, R40, R40e, R50, R50e, R50p, R51
- * T20, T21, T22, T23, T30, T40, T40p, T41, T41p, T42, T42p, T43
- * X20, X21, X22, X23, X24, X30, X31, X40
- *
- * The following models have no supported features:
- *
- * 240, 240x, i1400
- *
- * Still missing DSDTs for the following models:
- *
- * A20p, A22e, A22m
- * R52
- * S31
- * T43p
- */
-
 IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0",     /* 240, 240x */
           "\\_SB.PCI.ISA.EC",  /* 570 */
           "\\_SB.PCI0.ISA0.EC0",       /* 600e/x, 770e, 770x */
@@ -395,7 +380,7 @@ struct ibm_struct {
 
 static struct proc_dir_entry *proc_dir = NULL;
 
-static struct backlight_device *ibm_backlight_device;
+static struct backlight_device *ibm_backlight_device = NULL;
 
 #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
 #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
@@ -506,11 +491,15 @@ static char *next_cmd(char **cmds)
        return start;
 }
 
-static int driver_init(void)
+static int ibm_acpi_driver_init(void)
 {
        printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
        printk(IBM_INFO "%s\n", IBM_URL);
 
+       if (ibm_thinkpad_ec_found)
+               printk(IBM_INFO "ThinkPad EC firmware %s\n",
+                      ibm_thinkpad_ec_found);
+
        return 0;
 }
 
@@ -783,12 +772,15 @@ static int wan_write(char *buf)
        return 0;
 }
 
-static int video_supported;
-static int video_orig_autosw;
+enum video_access_mode {
+       IBMACPI_VIDEO_NONE = 0,
+       IBMACPI_VIDEO_570,      /* 570 */
+       IBMACPI_VIDEO_770,      /* 600e/x, 770e, 770x */
+       IBMACPI_VIDEO_NEW,      /* all others */
+};
 
-#define VIDEO_570 1
-#define VIDEO_770 2
-#define VIDEO_NEW 3
+static enum video_access_mode video_supported;
+static int video_orig_autosw;
 
 static int video_init(void)
 {
@@ -800,16 +792,16 @@ static int video_init(void)
 
        if (!vid_handle)
                /* video switching not supported on R30, R31 */
-               video_supported = 0;
+               video_supported = IBMACPI_VIDEO_NONE;
        else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
                /* 570 */
-               video_supported = VIDEO_570;
+               video_supported = IBMACPI_VIDEO_570;
        else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
                /* 600e/x, 770e, 770x */
-               video_supported = VIDEO_770;
+               video_supported = IBMACPI_VIDEO_770;
        else
                /* all others */
-               video_supported = VIDEO_NEW;
+               video_supported = IBMACPI_VIDEO_NEW;
 
        return 0;
 }
@@ -819,15 +811,15 @@ static int video_status(void)
        int status = 0;
        int i;
 
-       if (video_supported == VIDEO_570) {
+       if (video_supported == IBMACPI_VIDEO_570) {
                if (acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", 0x87))
                        status = i & 3;
-       } else if (video_supported == VIDEO_770) {
+       } else if (video_supported == IBMACPI_VIDEO_770) {
                if (acpi_evalf(NULL, &i, "\\VCDL", "d"))
                        status |= 0x01 * i;
                if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
                        status |= 0x02 * i;
-       } else if (video_supported == VIDEO_NEW) {
+       } else if (video_supported == IBMACPI_VIDEO_NEW) {
                acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1);
                if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
                        status |= 0x02 * i;
@@ -846,9 +838,10 @@ static int video_autosw(void)
 {
        int autosw = 0;
 
-       if (video_supported == VIDEO_570)
+       if (video_supported == IBMACPI_VIDEO_570)
                acpi_evalf(vid_handle, &autosw, "SWIT", "d");
-       else if (video_supported == VIDEO_770 || video_supported == VIDEO_NEW)
+       else if (video_supported == IBMACPI_VIDEO_770 ||
+                video_supported == IBMACPI_VIDEO_NEW)
                acpi_evalf(vid_handle, &autosw, "^VDEE", "d");
 
        return autosw & 1;
@@ -868,12 +861,12 @@ static int video_read(char *p)
        len += sprintf(p + len, "status:\t\tsupported\n");
        len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
        len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
-       if (video_supported == VIDEO_NEW)
+       if (video_supported == IBMACPI_VIDEO_NEW)
                len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
        len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
        len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
        len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
-       if (video_supported == VIDEO_NEW)
+       if (video_supported == IBMACPI_VIDEO_NEW)
                len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
        len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
        len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
@@ -888,7 +881,7 @@ static int video_switch(void)
 
        if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
                return -EIO;
-       ret = video_supported == VIDEO_570 ?
+       ret = video_supported == IBMACPI_VIDEO_570 ?
            acpi_evalf(ec_handle, NULL, "_Q16", "v") :
            acpi_evalf(vid_handle, NULL, "VSWT", "v");
        acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw);
@@ -898,9 +891,9 @@ static int video_switch(void)
 
 static int video_expand(void)
 {
-       if (video_supported == VIDEO_570)
+       if (video_supported == IBMACPI_VIDEO_570)
                return acpi_evalf(ec_handle, NULL, "_Q17", "v");
-       else if (video_supported == VIDEO_770)
+       else if (video_supported == IBMACPI_VIDEO_770)
                return acpi_evalf(vid_handle, NULL, "VEXP", "v");
        else
                return acpi_evalf(NULL, NULL, "\\VEXP", "v");
@@ -910,10 +903,10 @@ static int video_switch2(int status)
 {
        int ret;
 
-       if (video_supported == VIDEO_570) {
+       if (video_supported == IBMACPI_VIDEO_570) {
                ret = acpi_evalf(NULL, NULL,
                                 "\\_SB.PHS2", "vdd", 0x8b, status | 0x80);
-       } else if (video_supported == VIDEO_770) {
+       } else if (video_supported == IBMACPI_VIDEO_770) {
                int autosw = video_autosw();
                if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
                        return -EIO;
@@ -949,10 +942,10 @@ static int video_write(char *buf)
                        enable |= 0x02;
                } else if (strlencmp(cmd, "crt_disable") == 0) {
                        disable |= 0x02;
-               } else if (video_supported == VIDEO_NEW &&
+               } else if (video_supported == IBMACPI_VIDEO_NEW &&
                           strlencmp(cmd, "dvi_enable") == 0) {
                        enable |= 0x08;
-               } else if (video_supported == VIDEO_NEW &&
+               } else if (video_supported == IBMACPI_VIDEO_NEW &&
                           strlencmp(cmd, "dvi_disable") == 0) {
                        disable |= 0x08;
                } else if (strlencmp(cmd, "auto_enable") == 0) {
@@ -1248,26 +1241,28 @@ static int cmos_write(char *buf)
        return 0;
 }
 
-static int led_supported;
-
-#define LED_570 1
-#define LED_OLD 2
-#define LED_NEW 3
+enum led_access_mode {
+       IBMACPI_LED_NONE = 0,
+       IBMACPI_LED_570,        /* 570 */
+       IBMACPI_LED_OLD,        /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
+       IBMACPI_LED_NEW,        /* all others */
+};
+static enum led_access_mode led_supported;
 
 static int led_init(void)
 {
        if (!led_handle)
                /* led not supported on R30, R31 */
-               led_supported = 0;
+               led_supported = IBMACPI_LED_NONE;
        else if (strlencmp(led_path, "SLED") == 0)
                /* 570 */
-               led_supported = LED_570;
+               led_supported = IBMACPI_LED_570;
        else if (strlencmp(led_path, "SYSL") == 0)
                /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
-               led_supported = LED_OLD;
+               led_supported = IBMACPI_LED_OLD;
        else
                /* all others */
-               led_supported = LED_NEW;
+               led_supported = IBMACPI_LED_NEW;
 
        return 0;
 }
@@ -1284,7 +1279,7 @@ static int led_read(char *p)
        }
        len += sprintf(p + len, "status:\t\tsupported\n");
 
-       if (led_supported == LED_570) {
+       if (led_supported == IBMACPI_LED_570) {
                /* 570 */
                int i, status;
                for (i = 0; i < 8; i++) {
@@ -1333,13 +1328,13 @@ static int led_write(char *buf)
                } else
                        return -EINVAL;
 
-               if (led_supported == LED_570) {
+               if (led_supported == IBMACPI_LED_570) {
                        /* 570 */
                        led = 1 << led;
                        if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
                                        led, led_sled_arg1[ind]))
                                return -EIO;
-               } else if (led_supported == LED_OLD) {
+               } else if (led_supported == IBMACPI_LED_OLD) {
                        /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
                        led = 1 << led;
                        ret = ec_write(EC_HLMS, led);
@@ -1634,6 +1629,7 @@ static int brightness_get(struct backlight_device *bd)
                return -EIO;
 
        level &= 0x7;
+
        return level;
 }
 
@@ -1708,6 +1704,32 @@ static int brightness_update_status(struct backlight_device *bd)
        return brightness_set(bd->props->brightness);
 }
 
+static struct backlight_properties ibm_backlight_data = {
+        .get_brightness = brightness_get,
+        .update_status  = brightness_update_status,
+        .max_brightness = 7,
+};
+
+static int brightness_init(void)
+{
+       ibm_backlight_device = backlight_device_register("ibm", NULL, NULL,
+                                                        &ibm_backlight_data);
+       if (IS_ERR(ibm_backlight_device)) {
+               printk(IBM_ERR "Could not register backlight device\n");
+               return PTR_ERR(ibm_backlight_device);
+       }
+
+       return 0;
+}
+
+static void brightness_exit(void)
+{
+       if (ibm_backlight_device) {
+               backlight_device_unregister(ibm_backlight_device);
+               ibm_backlight_device = NULL;
+       }
+}
+
 static int volume_offset = 0x30;
 
 static int volume_read(char *p)
@@ -1801,9 +1823,9 @@ static enum fan_control_commands fan_control_commands;
 static int fan_control_status_known;
 static u8 fan_control_initial_status;
 
-static void fan_watchdog_fire(void *ignored);
+static void fan_watchdog_fire(struct work_struct *ignored);
 static int fan_watchdog_maxinterval;
-static DECLARE_WORK(fan_watchdog_task, fan_watchdog_fire, NULL);
+static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire);
 
 static int fan_init(void)
 {
@@ -2260,7 +2282,7 @@ static int fan_write(char *buf)
        return rc;
 }
 
-static void fan_watchdog_fire(void *ignored)
+static void fan_watchdog_fire(struct work_struct *ignored)
 {
        printk(IBM_NOTICE "fan watchdog: enabling fan\n");
        if (fan_set_enable()) {
@@ -2273,7 +2295,7 @@ static void fan_watchdog_fire(void *ignored)
 static struct ibm_struct ibms[] = {
        {
         .name = "driver",
-        .init = driver_init,
+        .init = ibm_acpi_driver_init,
         .read = driver_read,
         },
        {
@@ -2370,6 +2392,8 @@ static struct ibm_struct ibms[] = {
         .name = "brightness",
         .read = brightness_read,
         .write = brightness_write,
+        .init = brightness_init,
+        .exit = brightness_exit,
         },
        {
         .name = "volume",
@@ -2389,7 +2413,7 @@ static struct ibm_struct ibms[] = {
 static int dispatch_read(char *page, char **start, off_t off, int count,
                         int *eof, void *data)
 {
-       struct ibm_struct *ibm = (struct ibm_struct *)data;
+       struct ibm_struct *ibm = data;
        int len;
 
        if (!ibm || !ibm->read)
@@ -2414,7 +2438,7 @@ static int dispatch_read(char *page, char **start, off_t off, int count,
 static int dispatch_write(struct file *file, const char __user * userbuf,
                          unsigned long count, void *data)
 {
-       struct ibm_struct *ibm = (struct ibm_struct *)data;
+       struct ibm_struct *ibm = data;
        char *kernbuf;
        int ret;
 
@@ -2443,7 +2467,7 @@ static int dispatch_write(struct file *file, const char __user * userbuf,
 
 static void dispatch_notify(acpi_handle handle, u32 event, void *data)
 {
-       struct ibm_struct *ibm = (struct ibm_struct *)data;
+       struct ibm_struct *ibm = data;
 
        if (!ibm || !ibm->notify)
                return;
@@ -2475,7 +2499,7 @@ static int __init setup_notify(struct ibm_struct *ibm)
                       ibm->name, status);
                return -ENODEV;
        }
-
+       ibm->notify_installed = 1;
        return 0;
 }
 
@@ -2488,13 +2512,12 @@ static int __init register_driver(struct ibm_struct *ibm)
 {
        int ret;
 
-       ibm->driver = kmalloc(sizeof(struct acpi_driver), GFP_KERNEL);
+       ibm->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
        if (!ibm->driver) {
                printk(IBM_ERR "kmalloc(ibm->driver) failed\n");
                return -1;
        }
 
-       memset(ibm->driver, 0, sizeof(struct acpi_driver));
        sprintf(ibm->driver->name, "%s_%s", IBM_NAME, ibm->name);
        ibm->driver->ids = ibm->hid;
        ibm->driver->ops.add = &ibm_device_add;
@@ -2552,7 +2575,6 @@ static int __init ibm_init(struct ibm_struct *ibm)
                ret = setup_notify(ibm);
                if (ret < 0)
                        return ret;
-               ibm->notify_installed = 1;
        }
 
        return 0;
@@ -2598,7 +2620,7 @@ static void __init ibm_handle_init(char *name,
        ibm_handle_init(#object, &object##_handle, *object##_parent,    \
                object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
 
-static int set_ibm_param(const char *val, struct kernel_param *kp)
+static int __init set_ibm_param(const char *val, struct kernel_param *kp)
 {
        unsigned int i;
 
@@ -2633,24 +2655,15 @@ IBM_PARAM(brightness);
 IBM_PARAM(volume);
 IBM_PARAM(fan);
 
-static struct backlight_properties ibm_backlight_data = {
-       .owner = THIS_MODULE,
-       .get_brightness = brightness_get,
-       .update_status = brightness_update_status,
-       .max_brightness = 7,
-};
-
 static void acpi_ibm_exit(void)
 {
        int i;
 
-       if (ibm_backlight_device)
-               backlight_device_unregister(ibm_backlight_device);
-
        for (i = ARRAY_SIZE(ibms) - 1; i >= 0; i--)
                ibm_exit(&ibms[i]);
 
-       remove_proc_entry(IBM_DIR, acpi_root_dir);
+       if (proc_dir)
+               remove_proc_entry(IBM_DIR, acpi_root_dir);
 
        if (ibm_thinkpad_ec_found)
                kfree(ibm_thinkpad_ec_found);
@@ -2687,11 +2700,6 @@ static int __init acpi_ibm_init(void)
        if (acpi_disabled)
                return -ENODEV;
 
-       if (!acpi_specific_hotkey_enabled) {
-               printk(IBM_ERR "using generic hotkey driver\n");
-               return -ENODEV;
-       }
-
        /* ec is required because many other handles are relative to it */
        IBM_HANDLE_INIT(ec);
        if (!ec_handle) {
@@ -2701,9 +2709,6 @@ static int __init acpi_ibm_init(void)
 
        /* Models with newer firmware report the EC in DMI */
        ibm_thinkpad_ec_found = check_dmi_for_ec();
-       if (ibm_thinkpad_ec_found)
-               printk(IBM_INFO "ThinkPad EC firmware %s\n",
-                      ibm_thinkpad_ec_found);
 
        /* these handles are not required */
        IBM_HANDLE_INIT(vid);
@@ -2733,6 +2738,7 @@ static int __init acpi_ibm_init(void)
        proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir);
        if (!proc_dir) {
                printk(IBM_ERR "unable to create proc dir %s", IBM_DIR);
+               acpi_ibm_exit();
                return -ENODEV;
        }
        proc_dir->owner = THIS_MODULE;
@@ -2747,14 +2753,6 @@ static int __init acpi_ibm_init(void)
                }
        }
 
-       ibm_backlight_device = backlight_device_register("ibm", NULL,
-                                                        &ibm_backlight_data);
-       if (IS_ERR(ibm_backlight_device)) {
-               printk(IBM_ERR "Could not register ibm backlight device\n");
-               ibm_backlight_device = NULL;
-               acpi_ibm_exit();
-       }
-
        return 0;
 }