Pull platform-drivers into test branch
[powerpc.git] / drivers / acpi / ibm_acpi.c
index 3c091c4..130cc8c 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>
 
 #include <acpi/acpi_drivers.h>
 #include <acpi/acnamesp.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");
@@ -119,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 */
@@ -170,8 +157,10 @@ 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 */ 
           "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
     );                         /* A21e, R30, R31 */
 
@@ -186,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 */
@@ -348,7 +338,8 @@ enum fan_control_access_mode {
 enum fan_control_commands {
        IBMACPI_FAN_CMD_SPEED   = 0x0001,       /* speed command */
        IBMACPI_FAN_CMD_LEVEL   = 0x0002,       /* level command  */
-       IBMACPI_FAN_CMD_ENABLE  = 0x0004,       /* enable/disable cmd */
+       IBMACPI_FAN_CMD_ENABLE  = 0x0004,       /* enable/disable cmd,
+                                                * and also watchdog cmd */
 };
 
 enum {                                 /* Fan control constants */
@@ -362,7 +353,7 @@ enum {                                      /* Fan control constants */
                                                 * control */
 };
 
-static charibm_thinkpad_ec_found = NULL;
+static char *ibm_thinkpad_ec_found = NULL;
 
 struct ibm_struct {
        char *name;
@@ -391,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")
@@ -779,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)
 {
@@ -796,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;
 }
@@ -815,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;
@@ -842,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;
@@ -864,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");
@@ -884,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);
@@ -894,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");
@@ -906,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;
@@ -945,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) {
@@ -1047,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;
@@ -1056,7 +1052,7 @@ static int _sta(acpi_handle handle)
 
        return status;
 }
-
+#endif
 #ifdef CONFIG_ACPI_IBM_DOCK
 #define dock_docked() (_sta(dock_handle) & 1)
 
@@ -1122,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;
@@ -1197,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)
 {
@@ -1244,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;
 }
@@ -1280,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++) {
@@ -1329,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);
@@ -1630,6 +1630,7 @@ static int brightness_get(struct backlight_device *bd)
                return -EIO;
 
        level &= 0x7;
+
        return level;
 }
 
@@ -1704,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, 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)
@@ -1794,13 +1822,20 @@ static enum fan_status_access_mode fan_status_access_mode;
 static enum fan_control_access_mode fan_control_access_mode;
 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(struct work_struct *ignored);
+static int fan_watchdog_maxinterval;
+static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire);
+
 static int fan_init(void)
 {
-       u8 status;
-
        fan_status_access_mode = IBMACPI_FAN_NONE;
        fan_control_access_mode = IBMACPI_FAN_WR_NONE;
        fan_control_commands = 0;
+       fan_control_status_known = 1;
+       fan_watchdog_maxinterval = 0;
 
        if (gfan_handle) {
                /* 570, 600e/x, 770e, 770x */
@@ -1808,8 +1843,33 @@ static int fan_init(void)
        } else {
                /* all other ThinkPads: note that even old-style
                 * ThinkPad ECs supports the fan control register */
-               if (likely(acpi_ec_read(fan_status_offset, &status))) {
+               if (likely(acpi_ec_read(fan_status_offset,
+                                       &fan_control_initial_status))) {
                        fan_status_access_mode = IBMACPI_FAN_RD_TPEC;
+
+                       /* In some ThinkPads, neither the EC nor the ACPI
+                        * DSDT initialize the fan status, and it ends up
+                        * being set to 0x07 when it *could* be either
+                        * 0x07 or 0x80.
+                        *
+                        * Enable for TP-1Y (T43), TP-78 (R51e),
+                        * TP-76 (R52), TP-70 (T43, R52), which are known
+                        * to be buggy. */
+                       if (fan_control_initial_status == 0x07 &&
+                           ibm_thinkpad_ec_found &&
+                           ((ibm_thinkpad_ec_found[0] == '1' &&
+                             ibm_thinkpad_ec_found[1] == 'Y') ||
+                            (ibm_thinkpad_ec_found[0] == '7' &&
+                             (ibm_thinkpad_ec_found[1] == '6' ||
+                              ibm_thinkpad_ec_found[1] == '8' ||
+                              ibm_thinkpad_ec_found[1] == '0'))
+                           )) {
+                               printk(IBM_NOTICE
+                                      "fan_init: initial fan status is "
+                                      "unknown, assuming it is in auto "
+                                      "mode\n");
+                               fan_control_status_known = 0;
+                       }
                } else {
                        printk(IBM_ERR
                               "ThinkPad ACPI EC access misbehaving, "
@@ -1907,6 +1967,31 @@ static int fan_get_speed(unsigned int *speed)
        return 0;
 }
 
+static void fan_exit(void)
+{
+       cancel_delayed_work(&fan_watchdog_task);
+       flush_scheduled_work();
+}
+
+static void fan_watchdog_reset(void)
+{
+       static int fan_watchdog_active = 0;
+
+       if (fan_watchdog_active)
+               cancel_delayed_work(&fan_watchdog_task);
+
+       if (fan_watchdog_maxinterval > 0) {
+               fan_watchdog_active = 1;
+               if (!schedule_delayed_work(&fan_watchdog_task,
+                               msecs_to_jiffies(fan_watchdog_maxinterval
+                                                * 1000))) {
+                       printk(IBM_ERR "failed to schedule the fan watchdog, "
+                              "watchdog will not trigger\n");
+               }
+       } else
+               fan_watchdog_active = 0;
+}
+
 static int fan_read(char *p)
 {
        int len = 0;
@@ -1930,9 +2015,21 @@ static int fan_read(char *p)
                if ((rc = fan_get_status(&status)) < 0)
                        return rc;
 
+               if (unlikely(!fan_control_status_known)) {
+                       if (status != fan_control_initial_status)
+                               fan_control_status_known = 1;
+                       else
+                               /* Return most likely status. In fact, it
+                                * might be the only possible status */
+                               status = IBMACPI_FAN_EC_AUTO;
+               }
+
                len += sprintf(p + len, "status:\t\t%s\n",
                               (status != 0) ? "enabled" : "disabled");
 
+               /* No ThinkPad boots on disengaged mode, we can safely
+                * assume the tachometer is online if fan control status
+                * was unknown */
                if ((rc = fan_get_speed(&speed)) < 0)
                        return rc;
 
@@ -1968,7 +2065,9 @@ static int fan_read(char *p)
        }
 
        if (fan_control_commands & IBMACPI_FAN_CMD_ENABLE)
-               len += sprintf(p + len, "commands:\tenable, disable\n");
+               len += sprintf(p + len, "commands:\tenable, disable\n"
+                              "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
+                              "1-120 (seconds))\n");
 
        if (fan_control_commands & IBMACPI_FAN_CMD_SPEED)
                len += sprintf(p + len, "commands:\tspeed <speed>"
@@ -1997,6 +2096,8 @@ static int fan_set_level(int level)
 
                if (!acpi_ec_write(fan_status_offset, level))
                        return -EIO;
+               else
+                       fan_control_status_known = 1;
                break;
 
        default:
@@ -2022,6 +2123,8 @@ static int fan_set_enable(void)
 
                if (!acpi_ec_write(fan_status_offset, s))
                        return -EIO;
+               else
+                       fan_control_status_known = 1;
                break;
 
        case IBMACPI_FAN_WR_ACPI_SFAN:
@@ -2051,6 +2154,8 @@ static int fan_set_disable(void)
        case IBMACPI_FAN_WR_TPEC:
                if (!acpi_ec_write(fan_status_offset, 0x00))
                        return -EIO;
+               else
+                       fan_control_status_known = 1;
                break;
 
        case IBMACPI_FAN_WR_ACPI_SFAN:
@@ -2141,6 +2246,21 @@ static int fan_write_cmd_speed(const char *cmd, int *rc)
        return 1;
 }
 
+static int fan_write_cmd_watchdog(const char *cmd, int *rc)
+{
+       int interval;
+
+       if (sscanf(cmd, "watchdog %d", &interval) != 1)
+               return 0;
+
+       if (interval < 0 || interval > 120)
+               *rc = -EINVAL;
+       else
+               fan_watchdog_maxinterval = interval;
+
+       return 1;
+}
+
 static int fan_write(char *buf)
 {
        char *cmd;
@@ -2151,16 +2271,29 @@ static int fan_write(char *buf)
                      fan_write_cmd_level(cmd, &rc)) &&
                    !((fan_control_commands & IBMACPI_FAN_CMD_ENABLE) &&
                      (fan_write_cmd_enable(cmd, &rc) ||
-                      fan_write_cmd_disable(cmd, &rc))) &&
+                      fan_write_cmd_disable(cmd, &rc) ||
+                      fan_write_cmd_watchdog(cmd, &rc))) &&
                    !((fan_control_commands & IBMACPI_FAN_CMD_SPEED) &&
                      fan_write_cmd_speed(cmd, &rc))
                    )
                        rc = -EINVAL;
+               else if (!rc)
+                       fan_watchdog_reset();
        }
 
        return rc;
 }
 
+static void fan_watchdog_fire(struct work_struct *ignored)
+{
+       printk(IBM_NOTICE "fan watchdog: enabling fan\n");
+       if (fan_set_enable()) {
+               printk(IBM_ERR "fan watchdog: error while enabling fan\n");
+               /* reschedule for later */
+               fan_watchdog_reset();
+       }
+}
+
 static struct ibm_struct ibms[] = {
        {
         .name = "driver",
@@ -2221,6 +2354,7 @@ static struct ibm_struct ibms[] = {
         .type = ACPI_SYSTEM_NOTIFY,
         },
 #endif
+#ifdef CONFIG_ACPI_IBM_BAY
        {
         .name = "bay",
         .init = bay_init,
@@ -2230,6 +2364,7 @@ static struct ibm_struct ibms[] = {
         .handle = &bay_handle,
         .type = ACPI_SYSTEM_NOTIFY,
         },
+#endif
        {
         .name = "cmos",
         .read = cmos_read,
@@ -2261,6 +2396,8 @@ static struct ibm_struct ibms[] = {
         .name = "brightness",
         .read = brightness_read,
         .write = brightness_write,
+        .init = brightness_init,
+        .exit = brightness_exit,
         },
        {
         .name = "volume",
@@ -2272,6 +2409,7 @@ static struct ibm_struct ibms[] = {
         .read = fan_read,
         .write = fan_write,
         .init = fan_init,
+        .exit = fan_exit,
         .experimental = 1,
         },
 };
@@ -2279,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)
@@ -2304,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;
 
@@ -2333,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;
@@ -2365,7 +2503,7 @@ static int __init setup_notify(struct ibm_struct *ibm)
                       ibm->name, status);
                return -ENODEV;
        }
-
+       ibm->notify_installed = 1;
        return 0;
 }
 
@@ -2442,7 +2580,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;
@@ -2514,7 +2651,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);
@@ -2523,20 +2662,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]);
 
@@ -2607,12 +2736,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);
@@ -2637,14 +2768,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;
 }