Pull style into test branch
[pandora-kernel.git] / drivers / acpi / ibm_acpi.c
index 392abbb..1e7abef 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 */
@@ -172,6 +157,7 @@ IBM_HANDLE(dock, root, "\\_SB.GDCK",        /* X30, X31, X40 */
           "\\_SB.PCI.ISA.SLCE",        /* 570 */
     );                         /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
 #endif
+#ifdef CONFIG_ACPI_IBM_BAY
 IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST",       /* 570 */
           "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
           "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */ 
@@ -189,6 +175,7 @@ IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
 IBM_HANDLE(bay2_ej, bay2, "_EJ3",      /* 600e/x, 770e, A3x */
           "_EJ0",              /* 770x */
     );                         /* all others */
+#endif
 
 /* don't list other alternatives as we install a notify handler on the 570 */
 IBM_HANDLE(pci, root, "\\_SB.PCI");    /* 570 */
@@ -395,7 +382,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")
@@ -783,12 +770,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 +790,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 +809,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 +836,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 +859,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 +879,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 +889,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 +901,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 +940,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) {
@@ -1051,6 +1042,7 @@ static int light_write(char *buf)
        return 0;
 }
 
+#if defined(CONFIG_ACPI_IBM_DOCK) || defined(CONFIG_ACPI_IBM_BAY)
 static int _sta(acpi_handle handle)
 {
        int status;
@@ -1060,7 +1052,7 @@ static int _sta(acpi_handle handle)
 
        return status;
 }
-
+#endif
 #ifdef CONFIG_ACPI_IBM_DOCK
 #define dock_docked() (_sta(dock_handle) & 1)
 
@@ -1126,6 +1118,7 @@ static void dock_notify(struct ibm_struct *ibm, u32 event)
 }
 #endif
 
+#ifdef CONFIG_ACPI_IBM_BAY
 static int bay_status_supported;
 static int bay_status2_supported;
 static int bay_eject_supported;
@@ -1201,6 +1194,7 @@ static void bay_notify(struct ibm_struct *ibm, u32 event)
 {
        acpi_bus_generate_event(ibm->device, event, 0);
 }
+#endif
 
 static int cmos_read(char *p)
 {
@@ -1248,26 +1242,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 +1280,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 +1329,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 +1630,7 @@ static int brightness_get(struct backlight_device *bd)
                return -EIO;
 
        level &= 0x7;
+
        return level;
 }
 
@@ -1708,6 +1705,33 @@ static int brightness_update_status(struct backlight_device *bd)
        return brightness_set(bd->props->brightness);
 }
 
+static struct backlight_properties ibm_backlight_data = {
+        .owner          = THIS_MODULE,
+        .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,
+                                                        &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 +1825,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 +2284,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()) {
@@ -2330,6 +2354,7 @@ static struct ibm_struct ibms[] = {
         .type = ACPI_SYSTEM_NOTIFY,
         },
 #endif
+#ifdef CONFIG_ACPI_IBM_BAY
        {
         .name = "bay",
         .init = bay_init,
@@ -2339,6 +2364,7 @@ static struct ibm_struct ibms[] = {
         .handle = &bay_handle,
         .type = ACPI_SYSTEM_NOTIFY,
         },
+#endif
        {
         .name = "cmos",
         .read = cmos_read,
@@ -2370,6 +2396,8 @@ static struct ibm_struct ibms[] = {
         .name = "brightness",
         .read = brightness_read,
         .write = brightness_write,
+        .init = brightness_init,
+        .exit = brightness_exit,
         },
        {
         .name = "volume",
@@ -2389,7 +2417,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 +2442,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 +2471,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;
@@ -2624,7 +2652,9 @@ IBM_PARAM(light);
 #ifdef CONFIG_ACPI_IBM_DOCK
 IBM_PARAM(dock);
 #endif
+#ifdef CONFIG_ACPI_IBM_BAY
 IBM_PARAM(bay);
+#endif
 IBM_PARAM(cmos);
 IBM_PARAM(led);
 IBM_PARAM(beep);
@@ -2633,20 +2663,10 @@ 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]);
 
@@ -2717,12 +2737,14 @@ static int __init acpi_ibm_init(void)
        IBM_HANDLE_INIT(dock);
 #endif
        IBM_HANDLE_INIT(pci);
+#ifdef CONFIG_ACPI_IBM_BAY
        IBM_HANDLE_INIT(bay);
        if (bay_handle)
                IBM_HANDLE_INIT(bay_ej);
        IBM_HANDLE_INIT(bay2);
        if (bay2_handle)
                IBM_HANDLE_INIT(bay2_ej);
+#endif
        IBM_HANDLE_INIT(beep);
        IBM_HANDLE_INIT(ecrd);
        IBM_HANDLE_INIT(ecwr);
@@ -2747,14 +2769,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;
 }