Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/cmarinas...
[linux-2.6.git] / drivers / platform / x86 / thinkpad_acpi.c
index 770b853..562fcf0 100644 (file)
@@ -58,6 +58,7 @@
 #include <linux/kthread.h>
 #include <linux/freezer.h>
 #include <linux/delay.h>
+#include <linux/slab.h>
 
 #include <linux/nvram.h>
 #include <linux/proc_fs.h>
@@ -121,8 +122,15 @@ enum {
        TP_NVRAM_POS_LEVEL_VOLUME       = 0,
 };
 
+/* Misc NVRAM-related */
+enum {
+       TP_NVRAM_LEVEL_VOLUME_MAX = 14,
+};
+
 /* ACPI HIDs */
-#define TPACPI_ACPI_HKEY_HID           "IBM0068"
+#define TPACPI_ACPI_IBM_HKEY_HID       "IBM0068"
+#define TPACPI_ACPI_LENOVO_HKEY_HID    "LEN0068"
+#define TPACPI_ACPI_EC_HID             "PNP0C09"
 
 /* Input IDs */
 #define TPACPI_HKEY_INPUT_PRODUCT      0x5054 /* "TP" */
@@ -298,8 +306,8 @@ static struct {
        u32 hotkey_tablet:1;
        u32 light:1;
        u32 light_status:1;
-       u32 bright_16levels:1;
        u32 bright_acpimode:1;
+       u32 bright_unkfw:1;
        u32 wan:1;
        u32 uwb:1;
        u32 fan_ctrl_status_undef:1;
@@ -362,6 +370,9 @@ struct tpacpi_led_classdev {
        unsigned int led;
 };
 
+/* brightness level capabilities */
+static unsigned int bright_maxlvl;     /* 0 = unknown */
+
 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
 static int dbg_wlswemul;
 static int tpacpi_wlsw_emulstate;
@@ -479,6 +490,15 @@ static unsigned long __init tpacpi_check_quirks(
        return 0;
 }
 
+static inline bool __pure __init tpacpi_is_lenovo(void)
+{
+       return thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO;
+}
+
+static inline bool __pure __init tpacpi_is_ibm(void)
+{
+       return thinkpad_id.vendor == PCI_VENDOR_ID_IBM;
+}
 
 /****************************************************************************
  ****************************************************************************
@@ -493,21 +513,13 @@ static unsigned long __init tpacpi_check_quirks(
  */
 
 static acpi_handle root_handle;
+static acpi_handle ec_handle;
 
 #define TPACPI_HANDLE(object, parent, paths...)                        \
        static acpi_handle  object##_handle;                    \
-       static acpi_handle *object##_parent = &parent##_handle; \
-       static char        *object##_path;                      \
-       static char        *object##_paths[] = { paths }
-
-TPACPI_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0",  /* 240, 240x */
-          "\\_SB.PCI.ISA.EC",  /* 570 */
-          "\\_SB.PCI0.ISA0.EC0",       /* 600e/x, 770e, 770x */
-          "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
-          "\\_SB.PCI0.AD4S.EC0",       /* i1400, R30 */
-          "\\_SB.PCI0.ICH3.EC0",       /* R31 */
-          "\\_SB.PCI0.LPC.EC", /* all others */
-          );
+       static const acpi_handle *object##_parent __initdata =  \
+                                               &parent##_handle; \
+       static char *object##_paths[] __initdata = { paths }
 
 TPACPI_HANDLE(ecrd, ec, "ECRD");       /* 570 */
 TPACPI_HANDLE(ecwr, ec, "ECWR");       /* 570 */
@@ -527,6 +539,7 @@ TPACPI_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA",       /* 570 */
           "\\_SB.PCI0.AGP0.VID0",      /* 600e/x, 770x */
           "\\_SB.PCI0.VID0",   /* 770e */
           "\\_SB.PCI0.VID",    /* A21e, G4x, R50e, X30, X40 */
+          "\\_SB.PCI0.AGP.VGA",        /* X100e and a few others */
           "\\_SB.PCI0.AGP.VID",        /* all others */
           );                           /* R30, R31 */
 
@@ -577,6 +590,7 @@ static int acpi_evalf(acpi_handle handle,
                default:
                        printk(TPACPI_ERR "acpi_evalf() called "
                               "with invalid format character '%c'\n", c);
+                       va_end(ap);
                        return 0;
                }
        }
@@ -593,9 +607,10 @@ static int acpi_evalf(acpi_handle handle,
 
        switch (res_type) {
        case 'd':               /* int */
-               if (res)
+               success = (status == AE_OK &&
+                          out_obj.type == ACPI_TYPE_INTEGER);
+               if (success && res)
                        *(int *)res = out_obj.integer.value;
-               success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER;
                break;
        case 'v':               /* void */
                success = status == AE_OK;
@@ -608,8 +623,8 @@ static int acpi_evalf(acpi_handle handle,
        }
 
        if (!success && !quiet)
-               printk(TPACPI_ERR "acpi_evalf(%s, %s, ...) failed: %d\n",
-                      method, fmt0, status);
+               printk(TPACPI_ERR "acpi_evalf(%s, %s, ...) failed: %s\n",
+                      method, fmt0, acpi_format_exception(status));
 
        return success;
 }
@@ -660,11 +675,11 @@ static int issue_thinkpad_cmos_command(int cmos_cmd)
 
 #define TPACPI_ACPIHANDLE_INIT(object) \
        drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
-               object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
+               object##_paths, ARRAY_SIZE(object##_paths))
 
-static void drv_acpi_handle_init(char *name,
-                          acpi_handle *handle, acpi_handle parent,
-                          char **paths, int num_paths, char **path)
+static void __init drv_acpi_handle_init(const char *name,
+                          acpi_handle *handle, const acpi_handle parent,
+                          char **paths, const int num_paths)
 {
        int i;
        acpi_status status;
@@ -675,10 +690,9 @@ static void drv_acpi_handle_init(char *name,
        for (i = 0; i < num_paths; i++) {
                status = acpi_get_handle(parent, paths[i], handle);
                if (ACPI_SUCCESS(status)) {
-                       *path = paths[i];
                        dbg_printk(TPACPI_DBG_INIT,
                                   "Found ACPI handle %s for %s\n",
-                                  *path, name);
+                                  paths[i], name);
                        return;
                }
        }
@@ -688,6 +702,43 @@ static void drv_acpi_handle_init(char *name,
        *handle = NULL;
 }
 
+static acpi_status __init tpacpi_acpi_handle_locate_callback(acpi_handle handle,
+                       u32 level, void *context, void **return_value)
+{
+       *(acpi_handle *)return_value = handle;
+
+       return AE_CTRL_TERMINATE;
+}
+
+static void __init tpacpi_acpi_handle_locate(const char *name,
+               const char *hid,
+               acpi_handle *handle)
+{
+       acpi_status status;
+       acpi_handle device_found;
+
+       BUG_ON(!name || !hid || !handle);
+       vdbg_printk(TPACPI_DBG_INIT,
+                       "trying to locate ACPI handle for %s, using HID %s\n",
+                       name, hid);
+
+       memset(&device_found, 0, sizeof(device_found));
+       status = acpi_get_devices(hid, tpacpi_acpi_handle_locate_callback,
+                                 (void *)name, &device_found);
+
+       *handle = NULL;
+
+       if (ACPI_SUCCESS(status)) {
+               *handle = device_found;
+               dbg_printk(TPACPI_DBG_INIT,
+                          "Found ACPI handle for %s\n", name);
+       } else {
+               vdbg_printk(TPACPI_DBG_INIT,
+                           "Could not locate an ACPI handle for %s: %s\n",
+                           name, acpi_format_exception(status));
+       }
+}
+
 static void dispatch_acpi_notify(acpi_handle handle, u32 event, void *data)
 {
        struct ibm_struct *ibm = data;
@@ -735,8 +786,8 @@ static int __init setup_acpi_notify(struct ibm_struct *ibm)
                               "handling %s events\n", ibm->name);
                } else {
                        printk(TPACPI_ERR
-                              "acpi_install_notify_handler(%s) failed: %d\n",
-                              ibm->name, status);
+                              "acpi_install_notify_handler(%s) failed: %s\n",
+                              ibm->name, acpi_format_exception(status));
                }
                return -ENODEV;
        }
@@ -1034,80 +1085,6 @@ static void tpacpi_disable_brightness_delay(void)
                        "ACPI backlight control delay disabled\n");
 }
 
-static int __init tpacpi_query_bcl_levels(acpi_handle handle)
-{
-       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
-       union acpi_object *obj;
-       int rc;
-
-       if (ACPI_SUCCESS(acpi_evaluate_object(handle, NULL, NULL, &buffer))) {
-               obj = (union acpi_object *)buffer.pointer;
-               if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
-                       printk(TPACPI_ERR "Unknown _BCL data, "
-                              "please report this to %s\n", TPACPI_MAIL);
-                       rc = 0;
-               } else {
-                       rc = obj->package.count;
-               }
-       } else {
-               return 0;
-       }
-
-       kfree(buffer.pointer);
-       return rc;
-}
-
-static acpi_status __init tpacpi_acpi_walk_find_bcl(acpi_handle handle,
-                                       u32 lvl, void *context, void **rv)
-{
-       char name[ACPI_PATH_SEGMENT_LENGTH];
-       struct acpi_buffer buffer = { sizeof(name), &name };
-
-       if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) &&
-           !strncmp("_BCL", name, sizeof(name) - 1)) {
-               BUG_ON(!rv || !*rv);
-               **(int **)rv = tpacpi_query_bcl_levels(handle);
-               return AE_CTRL_TERMINATE;
-       } else {
-               return AE_OK;
-       }
-}
-
-/*
- * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
- */
-static int __init tpacpi_check_std_acpi_brightness_support(void)
-{
-       int status;
-       int bcl_levels = 0;
-       void *bcl_ptr = &bcl_levels;
-
-       if (!vid_handle) {
-               TPACPI_ACPIHANDLE_INIT(vid);
-       }
-       if (!vid_handle)
-               return 0;
-
-       /*
-        * Search for a _BCL method, and execute it.  This is safe on all
-        * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
-        * BIOS in ACPI backlight control mode.  We do NOT have to care
-        * about calling the _BCL method in an enabled video device, any
-        * will do for our purposes.
-        */
-
-       status = acpi_walk_namespace(ACPI_TYPE_METHOD, vid_handle, 3,
-                                    tpacpi_acpi_walk_find_bcl, NULL, NULL,
-                                    &bcl_ptr);
-
-       if (ACPI_SUCCESS(status) && bcl_levels > 2) {
-               tp_features.bright_acpimode = 1;
-               return (bcl_levels - 2);
-       }
-
-       return 0;
-}
-
 static void printk_deprecated_attribute(const char * const what,
                                        const char * const details)
 {
@@ -1871,34 +1848,9 @@ static bool __init tpacpi_is_fw_known(void)
  ****************************************************************************/
 
 /*************************************************************************
- * thinkpad-acpi init subdriver
+ * thinkpad-acpi metadata subdriver
  */
 
-static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm)
-{
-       printk(TPACPI_INFO "%s v%s\n", TPACPI_DESC, TPACPI_VERSION);
-       printk(TPACPI_INFO "%s\n", TPACPI_URL);
-
-       printk(TPACPI_INFO "ThinkPad BIOS %s, EC %s\n",
-               (thinkpad_id.bios_version_str) ?
-                       thinkpad_id.bios_version_str : "unknown",
-               (thinkpad_id.ec_version_str) ?
-                       thinkpad_id.ec_version_str : "unknown");
-
-       if (thinkpad_id.vendor && thinkpad_id.model_str)
-               printk(TPACPI_INFO "%s %s, model %s\n",
-                       (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ?
-                               "IBM" : ((thinkpad_id.vendor ==
-                                               PCI_VENDOR_ID_LENOVO) ?
-                                       "Lenovo" : "Unknown vendor"),
-                       thinkpad_id.model_str,
-                       (thinkpad_id.nummodel_str) ?
-                               thinkpad_id.nummodel_str : "unknown");
-
-       tpacpi_check_outdated_fw();
-       return 0;
-}
-
 static int thinkpad_acpi_driver_read(struct seq_file *m)
 {
        seq_printf(m, "driver:\t\t%s\n", TPACPI_DESC);
@@ -1961,6 +1913,17 @@ enum {   /* hot key scan codes (derived from ACPI DSDT) */
        TP_ACPI_HOTKEYSCAN_VOLUMEDOWN,
        TP_ACPI_HOTKEYSCAN_MUTE,
        TP_ACPI_HOTKEYSCAN_THINKPAD,
+       TP_ACPI_HOTKEYSCAN_UNK1,
+       TP_ACPI_HOTKEYSCAN_UNK2,
+       TP_ACPI_HOTKEYSCAN_UNK3,
+       TP_ACPI_HOTKEYSCAN_UNK4,
+       TP_ACPI_HOTKEYSCAN_UNK5,
+       TP_ACPI_HOTKEYSCAN_UNK6,
+       TP_ACPI_HOTKEYSCAN_UNK7,
+       TP_ACPI_HOTKEYSCAN_UNK8,
+
+       /* Hotkey keymap size */
+       TPACPI_HOTKEY_MAP_LEN
 };
 
 enum { /* Keys/events available through NVRAM polling */
@@ -2313,16 +2276,12 @@ static void tpacpi_input_send_key(const unsigned int scancode)
        if (keycode != KEY_RESERVED) {
                mutex_lock(&tpacpi_inputdev_send_mutex);
 
+               input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, scancode);
                input_report_key(tpacpi_inputdev, keycode, 1);
-               if (keycode == KEY_UNKNOWN)
-                       input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN,
-                                   scancode);
                input_sync(tpacpi_inputdev);
 
+               input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, scancode);
                input_report_key(tpacpi_inputdev, keycode, 0);
-               if (keycode == KEY_UNKNOWN)
-                       input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN,
-                                   scancode);
                input_sync(tpacpi_inputdev);
 
                mutex_unlock(&tpacpi_inputdev_send_mutex);
@@ -2404,6 +2363,36 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
                        tpacpi_hotkey_send_key(__scancode); \
        } while (0)
 
+       void issue_volchange(const unsigned int oldvol,
+                            const unsigned int newvol)
+       {
+               unsigned int i = oldvol;
+
+               while (i > newvol) {
+                       TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
+                       i--;
+               }
+               while (i < newvol) {
+                       TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
+                       i++;
+               }
+       }
+
+       void issue_brightnesschange(const unsigned int oldbrt,
+                                   const unsigned int newbrt)
+       {
+               unsigned int i = oldbrt;
+
+               while (i > newbrt) {
+                       TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
+                       i--;
+               }
+               while (i < newbrt) {
+                       TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
+                       i++;
+               }
+       }
+
        TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
        TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
        TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
@@ -2413,41 +2402,61 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
 
        TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle);
 
-       /* handle volume */
-       if (oldn->volume_toggle != newn->volume_toggle) {
-               if (oldn->mute != newn->mute) {
+       /*
+        * Handle volume
+        *
+        * This code is supposed to duplicate the IBM firmware behaviour:
+        * - Pressing MUTE issues mute hotkey message, even when already mute
+        * - Pressing Volume up/down issues volume up/down hotkey messages,
+        *   even when already at maximum or minimum volume
+        * - The act of unmuting issues volume up/down notification,
+        *   depending which key was used to unmute
+        *
+        * We are constrained to what the NVRAM can tell us, which is not much
+        * and certainly not enough if more than one volume hotkey was pressed
+        * since the last poll cycle.
+        *
+        * Just to make our life interesting, some newer Lenovo ThinkPads have
+        * bugs in the BIOS and may fail to update volume_toggle properly.
+        */
+       if (newn->mute) {
+               /* muted */
+               if (!oldn->mute ||
+                   oldn->volume_toggle != newn->volume_toggle ||
+                   oldn->volume_level != newn->volume_level) {
+                       /* recently muted, or repeated mute keypress, or
+                        * multiple presses ending in mute */
+                       issue_volchange(oldn->volume_level, newn->volume_level);
                        TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
                }
-               if (oldn->volume_level > newn->volume_level) {
-                       TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
-               } else if (oldn->volume_level < newn->volume_level) {
+       } else {
+               /* unmute */
+               if (oldn->mute) {
+                       /* recently unmuted, issue 'unmute' keypress */
                        TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
-               } else if (oldn->mute == newn->mute) {
-                       /* repeated key presses that didn't change state */
-                       if (newn->mute) {
-                               TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
-                       } else if (newn->volume_level != 0) {
-                               TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
-                       } else {
+               }
+               if (oldn->volume_level != newn->volume_level) {
+                       issue_volchange(oldn->volume_level, newn->volume_level);
+               } else if (oldn->volume_toggle != newn->volume_toggle) {
+                       /* repeated vol up/down keypress at end of scale ? */
+                       if (newn->volume_level == 0)
                                TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
-                       }
+                       else if (newn->volume_level >= TP_NVRAM_LEVEL_VOLUME_MAX)
+                               TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
                }
        }
 
        /* handle brightness */
-       if (oldn->brightness_toggle != newn->brightness_toggle) {
-               if (oldn->brightness_level < newn->brightness_level) {
-                       TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
-               } else if (oldn->brightness_level > newn->brightness_level) {
+       if (oldn->brightness_level != newn->brightness_level) {
+               issue_brightnesschange(oldn->brightness_level,
+                                      newn->brightness_level);
+       } else if (oldn->brightness_toggle != newn->brightness_toggle) {
+               /* repeated key presses that didn't change state */
+               if (newn->brightness_level == 0)
                        TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
-               } else {
-                       /* repeated key presses that didn't change state */
-                       if (newn->brightness_level != 0) {
-                               TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
-                       } else {
-                               TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
-                       }
-               }
+               else if (newn->brightness_level >= bright_maxlvl
+                               && !tp_features.bright_unkfw)
+                       TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
        }
 
 #undef TPACPI_COMPARE_KEY
@@ -2982,7 +2991,7 @@ static void tpacpi_send_radiosw_update(void)
         * rfkill input events, or we will race the rfkill core input
         * handler.
         *
-        * tpacpi_inputdev_send_mutex works as a syncronization point
+        * tpacpi_inputdev_send_mutex works as a synchronization point
         * for the above.
         *
         * We optimize to avoid numerous calls to hotkey_get_wlsw.
@@ -3082,6 +3091,9 @@ static const struct tpacpi_quirk tpacpi_hotkey_qtable[] __initconst = {
        TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK), /* X22, X23, X24 */
 };
 
+typedef u16 tpacpi_keymap_entry_t;
+typedef tpacpi_keymap_entry_t tpacpi_keymap_t[TPACPI_HOTKEY_MAP_LEN];
+
 static int __init hotkey_init(struct ibm_init_struct *iibm)
 {
        /* Requirements for changing the default keymaps:
@@ -3113,9 +3125,17 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
         * If the above is too much to ask, don't change the keymap.
         * Ask the thinkpad-acpi maintainer to do it, instead.
         */
-       static u16 ibm_keycode_map[] __initdata = {
+
+       enum keymap_index {
+               TPACPI_KEYMAP_IBM_GENERIC = 0,
+               TPACPI_KEYMAP_LENOVO_GENERIC,
+       };
+
+       static const tpacpi_keymap_t tpacpi_keymaps[] __initconst = {
+       /* Generic keymap for IBM ThinkPads */
+       [TPACPI_KEYMAP_IBM_GENERIC] = {
                /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
-               KEY_FN_F1,      KEY_FN_F2,      KEY_COFFEE,     KEY_SLEEP,
+               KEY_FN_F1,      KEY_BATTERY,    KEY_COFFEE,     KEY_SLEEP,
                KEY_WLAN,       KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8,
                KEY_FN_F9,      KEY_FN_F10,     KEY_FN_F11,     KEY_SUSPEND,
 
@@ -3146,11 +3166,13 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
                /* (assignments unknown, please report if found) */
                KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
                KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
-       };
-       static u16 lenovo_keycode_map[] __initdata = {
+               },
+
+       /* Generic keymap for Lenovo ThinkPads */
+       [TPACPI_KEYMAP_LENOVO_GENERIC] = {
                /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
                KEY_FN_F1,      KEY_COFFEE,     KEY_BATTERY,    KEY_SLEEP,
-               KEY_WLAN,       KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8,
+               KEY_WLAN,       KEY_CAMERA, KEY_SWITCHVIDEOMODE, KEY_FN_F8,
                KEY_FN_F9,      KEY_FN_F10,     KEY_FN_F11,     KEY_SUSPEND,
 
                /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
@@ -3189,11 +3211,25 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
                /* (assignments unknown, please report if found) */
                KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
                KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+               },
        };
 
-#define TPACPI_HOTKEY_MAP_LEN          ARRAY_SIZE(ibm_keycode_map)
-#define TPACPI_HOTKEY_MAP_SIZE         sizeof(ibm_keycode_map)
-#define TPACPI_HOTKEY_MAP_TYPESIZE     sizeof(ibm_keycode_map[0])
+       static const struct tpacpi_quirk tpacpi_keymap_qtable[] __initconst = {
+               /* Generic maps (fallback) */
+               {
+                 .vendor = PCI_VENDOR_ID_IBM,
+                 .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY,
+                 .quirks = TPACPI_KEYMAP_IBM_GENERIC,
+               },
+               {
+                 .vendor = PCI_VENDOR_ID_LENOVO,
+                 .bios = TPACPI_MATCH_ANY, .ec = TPACPI_MATCH_ANY,
+                 .quirks = TPACPI_KEYMAP_LENOVO_GENERIC,
+               },
+       };
+
+#define TPACPI_HOTKEY_MAP_SIZE         sizeof(tpacpi_keymap_t)
+#define TPACPI_HOTKEY_MAP_TYPESIZE     sizeof(tpacpi_keymap_entry_t)
 
        int res, i;
        int status;
@@ -3202,6 +3238,7 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
        bool tabletsw_state = false;
 
        unsigned long quirks;
+       unsigned long keymap_id;
 
        vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
                        "initializing hotkey subdriver\n");
@@ -3342,7 +3379,6 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
                goto err_exit;
 
        /* Set up key map */
-
        hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE,
                                        GFP_KERNEL);
        if (!hotkey_keycode_map) {
@@ -3352,17 +3388,14 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
                goto err_exit;
        }
 
-       if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) {
-               dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
-                          "using Lenovo default hot key map\n");
-               memcpy(hotkey_keycode_map, &lenovo_keycode_map,
-                       TPACPI_HOTKEY_MAP_SIZE);
-       } else {
-               dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
-                          "using IBM default hot key map\n");
-               memcpy(hotkey_keycode_map, &ibm_keycode_map,
-                       TPACPI_HOTKEY_MAP_SIZE);
-       }
+       keymap_id = tpacpi_check_quirks(tpacpi_keymap_qtable,
+                                       ARRAY_SIZE(tpacpi_keymap_qtable));
+       BUG_ON(keymap_id >= ARRAY_SIZE(tpacpi_keymaps));
+       dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
+                  "using keymap number %lu\n", keymap_id);
+
+       memcpy(hotkey_keycode_map, &tpacpi_keymaps[keymap_id],
+               TPACPI_HOTKEY_MAP_SIZE);
 
        input_set_capability(tpacpi_inputdev, EV_MSC, MSC_SCAN);
        tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE;
@@ -3390,11 +3423,8 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
        }
 
        /* Do not issue duplicate brightness change events to
-        * userspace */
-       if (!tp_features.bright_acpimode)
-               /* update bright_acpimode... */
-               tpacpi_check_std_acpi_brightness_support();
-
+        * userspace. tpacpi_detect_brightness_capabilities() must have
+        * been called before this point  */
        if (tp_features.bright_acpimode && acpi_video_backlight_support()) {
                printk(TPACPI_INFO
                       "This ThinkPad has standard ACPI backlight "
@@ -3472,7 +3502,8 @@ static bool hotkey_notify_hotkey(const u32 hkey,
        *send_acpi_ev = true;
        *ignore_acpi_ev = false;
 
-       if (scancode > 0 && scancode < 0x21) {
+       /* HKEY event 0x1001 is scancode 0x00 */
+       if (scancode > 0 && scancode <= TPACPI_HOTKEY_MAP_LEN) {
                scancode--;
                if (!(hotkey_source_mask & (1 << scancode))) {
                        tpacpi_input_send_key_masked(scancode);
@@ -3849,7 +3880,8 @@ errexit:
 }
 
 static const struct acpi_device_id ibm_htk_device_ids[] = {
-       {TPACPI_ACPI_HKEY_HID, 0},
+       {TPACPI_ACPI_IBM_HKEY_HID, 0},
+       {TPACPI_ACPI_LENOVO_HKEY_HID, 0},
        {"", 0},
 };
 
@@ -4421,7 +4453,8 @@ static int __init video_init(struct ibm_init_struct *iibm)
        vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n");
 
        TPACPI_ACPIHANDLE_INIT(vid);
-       TPACPI_ACPIHANDLE_INIT(vid2);
+       if (tpacpi_is_ibm())
+               TPACPI_ACPIHANDLE_INIT(vid2);
 
        if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
                /* G41, assume IVGA doesn't change */
@@ -4430,10 +4463,12 @@ static int __init video_init(struct ibm_init_struct *iibm)
        if (!vid_handle)
                /* video switching not supported on R30, R31 */
                video_supported = TPACPI_VIDEO_NONE;
-       else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
+       else if (tpacpi_is_ibm() &&
+                acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
                /* 570 */
                video_supported = TPACPI_VIDEO_570;
-       else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
+       else if (tpacpi_is_ibm() &&
+                acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
                /* 600e/x, 770e, 770x */
                video_supported = TPACPI_VIDEO_770;
        else
@@ -4810,8 +4845,10 @@ static int __init light_init(struct ibm_init_struct *iibm)
 
        vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n");
 
-       TPACPI_ACPIHANDLE_INIT(ledb);
-       TPACPI_ACPIHANDLE_INIT(lght);
+       if (tpacpi_is_ibm()) {
+               TPACPI_ACPIHANDLE_INIT(ledb);
+               TPACPI_ACPIHANDLE_INIT(lght);
+       }
        TPACPI_ACPIHANDLE_INIT(cmos);
        INIT_WORK(&tpacpi_led_thinklight.work, light_set_status_worker);
 
@@ -5006,11 +5043,7 @@ enum {   /* For TPACPI_LED_OLD */
 
 static enum led_access_mode led_supported;
 
-TPACPI_HANDLE(led, ec, "SLED", /* 570 */
-          "SYSL",              /* 600e/x, 770e, 770x, A21e, A2xm/p, */
-                               /* T20-22, X20-21 */
-          "LED",               /* all others */
-          );                   /* R30, R31 */
+static acpi_handle led_handle;
 
 #define TPACPI_LED_NUMLEDS 16
 static struct tpacpi_led_classdev *tpacpi_leds;
@@ -5270,6 +5303,32 @@ static const struct tpacpi_quirk led_useful_qtable[] __initconst = {
 #undef TPACPI_LEDQ_IBM
 #undef TPACPI_LEDQ_LNV
 
+static enum led_access_mode __init led_init_detect_mode(void)
+{
+       acpi_status status;
+
+       if (tpacpi_is_ibm()) {
+               /* 570 */
+               status = acpi_get_handle(ec_handle, "SLED", &led_handle);
+               if (ACPI_SUCCESS(status))
+                       return TPACPI_LED_570;
+
+               /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
+               status = acpi_get_handle(ec_handle, "SYSL", &led_handle);
+               if (ACPI_SUCCESS(status))
+                       return TPACPI_LED_OLD;
+       }
+
+       /* most others */
+       status = acpi_get_handle(ec_handle, "LED", &led_handle);
+       if (ACPI_SUCCESS(status))
+               return TPACPI_LED_NEW;
+
+       /* R30, R31, and unknown firmwares */
+       led_handle = NULL;
+       return TPACPI_LED_NONE;
+}
+
 static int __init led_init(struct ibm_init_struct *iibm)
 {
        unsigned int i;
@@ -5278,20 +5337,7 @@ static int __init led_init(struct ibm_init_struct *iibm)
 
        vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n");
 
-       TPACPI_ACPIHANDLE_INIT(led);
-
-       if (!led_handle)
-               /* led not supported on R30, R31 */
-               led_supported = TPACPI_LED_NONE;
-       else if (strlencmp(led_path, "SLED") == 0)
-               /* 570 */
-               led_supported = TPACPI_LED_570;
-       else if (strlencmp(led_path, "SYSL") == 0)
-               /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
-               led_supported = TPACPI_LED_OLD;
-       else
-               /* all others */
-               led_supported = TPACPI_LED_NEW;
+       led_supported = led_init_detect_mode();
 
        vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n",
                str_supported(led_supported), led_supported);
@@ -5740,11 +5786,12 @@ static int __init thermal_init(struct ibm_init_struct *iibm)
                            TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8;
                }
        } else if (acpi_tmp7) {
-               if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
+               if (tpacpi_is_ibm() &&
+                   acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
                        /* 600e/x, 770e, 770x */
                        thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT;
                } else {
-                       /* Standard ACPI TMPx access, max 8 sensors */
+                       /* IBM/LENOVO DSDT EC.TMPx access, max 8 sensors */
                        thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
                }
        } else {
@@ -5826,75 +5873,6 @@ static struct ibm_struct thermal_driver_data = {
 };
 
 /*************************************************************************
- * EC Dump subdriver
- */
-
-static u8 ecdump_regs[256];
-
-static int ecdump_read(struct seq_file *m)
-{
-       int i, j;
-       u8 v;
-
-       seq_printf(m, "EC      "
-                      " +00 +01 +02 +03 +04 +05 +06 +07"
-                      " +08 +09 +0a +0b +0c +0d +0e +0f\n");
-       for (i = 0; i < 256; i += 16) {
-               seq_printf(m, "EC 0x%02x:", i);
-               for (j = 0; j < 16; j++) {
-                       if (!acpi_ec_read(i + j, &v))
-                               break;
-                       if (v != ecdump_regs[i + j])
-                               seq_printf(m, " *%02x", v);
-                       else
-                               seq_printf(m, "  %02x", v);
-                       ecdump_regs[i + j] = v;
-               }
-               seq_putc(m, '\n');
-               if (j != 16)
-                       break;
-       }
-
-       /* These are way too dangerous to advertise openly... */
-#if 0
-       seq_printf(m, "commands:\t0x<offset> 0x<value>"
-                      " (<offset> is 00-ff, <value> is 00-ff)\n");
-       seq_printf(m, "commands:\t0x<offset> <value>  "
-                      " (<offset> is 00-ff, <value> is 0-255)\n");
-#endif
-       return 0;
-}
-
-static int ecdump_write(char *buf)
-{
-       char *cmd;
-       int i, v;
-
-       while ((cmd = next_cmd(&buf))) {
-               if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) {
-                       /* i and v set */
-               } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) {
-                       /* i and v set */
-               } else
-                       return -EINVAL;
-               if (i >= 0 && i < 256 && v >= 0 && v < 256) {
-                       if (!acpi_ec_write(i, v))
-                               return -EIO;
-               } else
-                       return -EINVAL;
-       }
-
-       return 0;
-}
-
-static struct ibm_struct ecdump_driver_data = {
-       .name = "ecdump",
-       .read = ecdump_read,
-       .write = ecdump_write,
-       .flags.experimental = 1,
-};
-
-/*************************************************************************
  * Backlight/brightness subdriver
  */
 
@@ -5953,7 +5931,7 @@ static unsigned int tpacpi_brightness_nvram_get(void)
        lnvram = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS)
                  & TP_NVRAM_MASK_LEVEL_BRIGHTNESS)
                  >> TP_NVRAM_POS_LEVEL_BRIGHTNESS;
-       lnvram &= (tp_features.bright_16levels) ? 0x0f : 0x07;
+       lnvram &= bright_maxlvl;
 
        return lnvram;
 }
@@ -6062,8 +6040,7 @@ static int brightness_set(unsigned int value)
 {
        int res;
 
-       if (value > ((tp_features.bright_16levels)? 15 : 7) ||
-           value < 0)
+       if (value > bright_maxlvl || value < 0)
                return -EINVAL;
 
        vdbg_printk(TPACPI_DBG_BRGHT,
@@ -6131,7 +6108,7 @@ static void tpacpi_brightness_notify_change(void)
                               BACKLIGHT_UPDATE_HOTKEY);
 }
 
-static struct backlight_ops ibm_backlight_data = {
+static const struct backlight_ops ibm_backlight_data = {
        .get_brightness = brightness_get,
        .update_status  = brightness_update_status,
 };
@@ -6139,6 +6116,52 @@ static struct backlight_ops ibm_backlight_data = {
 /* --------------------------------------------------------------------- */
 
 /*
+ * Call _BCL method of video device.  On some ThinkPads this will
+ * switch the firmware to the ACPI brightness control mode.
+ */
+
+static int __init tpacpi_query_bcl_levels(acpi_handle handle)
+{
+       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+       union acpi_object *obj;
+       int rc;
+
+       if (ACPI_SUCCESS(acpi_evaluate_object(handle, "_BCL", NULL, &buffer))) {
+               obj = (union acpi_object *)buffer.pointer;
+               if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
+                       printk(TPACPI_ERR "Unknown _BCL data, "
+                              "please report this to %s\n", TPACPI_MAIL);
+                       rc = 0;
+               } else {
+                       rc = obj->package.count;
+               }
+       } else {
+               return 0;
+       }
+
+       kfree(buffer.pointer);
+       return rc;
+}
+
+
+/*
+ * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
+ */
+static unsigned int __init tpacpi_check_std_acpi_brightness_support(void)
+{
+       acpi_handle video_device;
+       int bcl_levels = 0;
+
+       tpacpi_acpi_handle_locate("video", ACPI_VIDEO_HID, &video_device);
+       if (video_device)
+               bcl_levels = tpacpi_query_bcl_levels(video_device);
+
+       tp_features.bright_acpimode = (bcl_levels > 0);
+
+       return (bcl_levels > 2) ? (bcl_levels - 2) : 0;
+}
+
+/*
  * These are only useful for models that have only one possibility
  * of GPU.  If the BIOS model handles both ATI and Intel, don't use
  * these quirks.
@@ -6168,6 +6191,47 @@ static const struct tpacpi_quirk brightness_quirk_table[] __initconst = {
        TPACPI_Q_IBM('7', '5', TPACPI_BRGHT_Q_NOEC),    /* X41 Tablet */
 };
 
+/*
+ * Returns < 0 for error, otherwise sets tp_features.bright_*
+ * and bright_maxlvl.
+ */
+static void __init tpacpi_detect_brightness_capabilities(void)
+{
+       unsigned int b;
+
+       vdbg_printk(TPACPI_DBG_INIT,
+                   "detecting firmware brightness interface capabilities\n");
+
+       /* we could run a quirks check here (same table used by
+        * brightness_init) if needed */
+
+       /*
+        * We always attempt to detect acpi support, so as to switch
+        * Lenovo Vista BIOS to ACPI brightness mode even if we are not
+        * going to publish a backlight interface
+        */
+       b = tpacpi_check_std_acpi_brightness_support();
+       switch (b) {
+       case 16:
+               bright_maxlvl = 15;
+               printk(TPACPI_INFO
+                      "detected a 16-level brightness capable ThinkPad\n");
+               break;
+       case 8:
+       case 0:
+               bright_maxlvl = 7;
+               printk(TPACPI_INFO
+                      "detected a 8-level brightness capable ThinkPad\n");
+               break;
+       default:
+               printk(TPACPI_ERR
+                      "Unsupported brightness interface, "
+                      "please contact %s\n", TPACPI_MAIL);
+               tp_features.bright_unkfw = 1;
+               bright_maxlvl = b - 1;
+       }
+}
+
 static int __init brightness_init(struct ibm_init_struct *iibm)
 {
        struct backlight_properties props;
@@ -6181,34 +6245,11 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
        quirks = tpacpi_check_quirks(brightness_quirk_table,
                                ARRAY_SIZE(brightness_quirk_table));
 
-       /*
-        * We always attempt to detect acpi support, so as to switch
-        * Lenovo Vista BIOS to ACPI brightness mode even if we are not
-        * going to publish a backlight interface
-        */
-       b = tpacpi_check_std_acpi_brightness_support();
-       if (b > 0) {
+       /* tpacpi_detect_brightness_capabilities() must have run already */
 
-               if (acpi_video_backlight_support()) {
-                       if (brightness_enable > 1) {
-                               printk(TPACPI_NOTICE
-                                      "Standard ACPI backlight interface "
-                                      "available, not loading native one.\n");
-                               return 1;
-                       } else if (brightness_enable == 1) {
-                               printk(TPACPI_NOTICE
-                                      "Backlight control force enabled, even if standard "
-                                      "ACPI backlight interface is available\n");
-                       }
-               } else {
-                       if (brightness_enable > 1) {
-                               printk(TPACPI_NOTICE
-                                      "Standard ACPI backlight interface not "
-                                      "available, thinkpad_acpi native "
-                                      "brightness control enabled\n");
-                       }
-               }
-       }
+       /* if it is unknown, we don't handle it: it wouldn't be safe */
+       if (tp_features.bright_unkfw)
+               return 1;
 
        if (!brightness_enable) {
                dbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT,
@@ -6217,14 +6258,25 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
                return 1;
        }
 
-       if (b > 16) {
-               printk(TPACPI_ERR
-                      "Unsupported brightness interface, "
-                      "please contact %s\n", TPACPI_MAIL);
-               return 1;
+       if (acpi_video_backlight_support()) {
+               if (brightness_enable > 1) {
+                       printk(TPACPI_INFO
+                              "Standard ACPI backlight interface "
+                              "available, not loading native one.\n");
+                       return 1;
+               } else if (brightness_enable == 1) {
+                       printk(TPACPI_WARN
+                               "Cannot enable backlight brightness support, "
+                               "ACPI is already handling it.  Refer to the "
+                               "acpi_backlight kernel parameter\n");
+                       return 1;
+               }
+       } else if (tp_features.bright_acpimode && brightness_enable > 1) {
+               printk(TPACPI_NOTICE
+                       "Standard ACPI backlight interface not "
+                       "available, thinkpad_acpi native "
+                       "brightness control enabled\n");
        }
-       if (b == 16)
-               tp_features.bright_16levels = 1;
 
        /*
         * Check for module parameter bogosity, note that we
@@ -6248,7 +6300,7 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
        }
 
        /* Safety */
-       if (thinkpad_id.vendor != PCI_VENDOR_ID_IBM &&
+       if (!tpacpi_is_ibm() &&
            (brightness_mode == TPACPI_BRGHT_MODE_ECNVRAM ||
             brightness_mode == TPACPI_BRGHT_MODE_EC))
                return -EINVAL;
@@ -6256,12 +6308,10 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
        if (tpacpi_brightness_get_raw(&b) < 0)
                return 1;
 
-       if (tp_features.bright_16levels)
-               printk(TPACPI_INFO
-                      "detected a 16-level brightness capable ThinkPad\n");
-
        memset(&props, 0, sizeof(struct backlight_properties));
-       props.max_brightness = (tp_features.bright_16levels) ? 15 : 7;
+       props.type = BACKLIGHT_PLATFORM;
+       props.max_brightness = bright_maxlvl;
+       props.brightness = b & TP_EC_BACKLIGHT_LVLMSK;
        ibm_backlight_device = backlight_device_register(TPACPI_BACKLIGHT_DEV_NAME,
                                                         NULL, NULL,
                                                         &ibm_backlight_data,
@@ -6284,7 +6334,10 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
                        "or not on your ThinkPad\n", TPACPI_MAIL);
        }
 
-       ibm_backlight_device->props.brightness = b & TP_EC_BACKLIGHT_LVLMSK;
+       /* Added by mistake in early 2007.  Probably useless, but it could
+        * be working around some unknown firmware problem where the value
+        * read at startup doesn't match the real hardware state... so leave
+        * it in place just in case */
        backlight_update_status(ibm_backlight_device);
 
        vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_BRGHT,
@@ -6292,7 +6345,7 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
                        "as change notification\n");
        tpacpi_hotkey_driver_mask_set(hotkey_driver_mask
                                | TP_ACPI_HKEY_BRGHTUP_MASK
-                               | TP_ACPI_HKEY_BRGHTDWN_MASK);;
+                               | TP_ACPI_HKEY_BRGHTDWN_MASK);
        return 0;
 }
 
@@ -6327,9 +6380,8 @@ static int brightness_read(struct seq_file *m)
        } else {
                seq_printf(m, "level:\t\t%d\n", level);
                seq_printf(m, "commands:\tup, down\n");
-               seq_printf(m, "commands:\tlevel <level>"
-                              " (<level> is 0-%d)\n",
-                              (tp_features.bright_16levels) ? 15 : 7);
+               seq_printf(m, "commands:\tlevel <level> (<level> is 0-%d)\n",
+                              bright_maxlvl);
        }
 
        return 0;
@@ -6340,7 +6392,6 @@ static int brightness_write(char *buf)
        int level;
        int rc;
        char *cmd;
-       int max_level = (tp_features.bright_16levels) ? 15 : 7;
 
        level = brightness_get(NULL);
        if (level < 0)
@@ -6348,13 +6399,13 @@ static int brightness_write(char *buf)
 
        while ((cmd = next_cmd(&buf))) {
                if (strlencmp(cmd, "up") == 0) {
-                       if (level < max_level)
+                       if (level < bright_maxlvl)
                                level++;
                } else if (strlencmp(cmd, "down") == 0) {
                        if (level > 0)
                                level--;
                } else if (sscanf(cmd, "level %d", &level) == 1 &&
-                          level >= 0 && level <= max_level) {
+                          level >= 0 && level <= bright_maxlvl) {
                        /* new level set */
                } else
                        return -EINVAL;
@@ -6668,6 +6719,8 @@ static int volume_alsa_vol_get(struct snd_kcontrol *kcontrol,
 static int volume_alsa_vol_put(struct snd_kcontrol *kcontrol,
                                struct snd_ctl_elem_value *ucontrol)
 {
+       tpacpi_disclose_usertask("ALSA", "set volume to %ld\n",
+                                ucontrol->value.integer.value[0]);
        return volume_alsa_set_volume(ucontrol->value.integer.value[0]);
 }
 
@@ -6691,6 +6744,9 @@ static int volume_alsa_mute_get(struct snd_kcontrol *kcontrol,
 static int volume_alsa_mute_put(struct snd_kcontrol *kcontrol,
                                struct snd_ctl_elem_value *ucontrol)
 {
+       tpacpi_disclose_usertask("ALSA", "%smute\n",
+                                ucontrol->value.integer.value[0] ?
+                                       "un" : "");
        return volume_alsa_set_mute(!ucontrol->value.integer.value[0]);
 }
 
@@ -7137,7 +7193,7 @@ static struct ibm_struct volume_driver_data = {
  *             TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
  *
  *     FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
- *     boot. Apparently the EC does not intialize it, so unless ACPI DSDT
+ *     boot. Apparently the EC does not initialize it, so unless ACPI DSDT
  *     does so, its initial value is meaningless (0x07).
  *
  *     For firmware bugs, refer to:
@@ -7967,9 +8023,11 @@ static int __init fan_init(struct ibm_init_struct *iibm)
        tp_features.second_fan = 0;
        fan_control_desired_level = 7;
 
-       TPACPI_ACPIHANDLE_INIT(fans);
-       TPACPI_ACPIHANDLE_INIT(gfan);
-       TPACPI_ACPIHANDLE_INIT(sfan);
+       if (tpacpi_is_ibm()) {
+               TPACPI_ACPIHANDLE_INIT(fans);
+               TPACPI_ACPIHANDLE_INIT(gfan);
+               TPACPI_ACPIHANDLE_INIT(sfan);
+       }
 
        quirks = tpacpi_check_quirks(fan_quirk_table,
                                     ARRAY_SIZE(fan_quirk_table));
@@ -8439,7 +8497,6 @@ static void ibm_exit(struct ibm_struct *ibm)
                                           ibm->acpi->type,
                                           dispatch_acpi_notify);
                ibm->flags.acpi_notify_installed = 0;
-               ibm->flags.acpi_notify_installed = 0;
        }
 
        if (ibm->flags.proc_created) {
@@ -8563,8 +8620,7 @@ static bool __pure __init tpacpi_is_valid_fw_id(const char* const s,
                tpacpi_is_fw_digit(s[1]) &&
                s[2] == t && s[3] == 'T' &&
                tpacpi_is_fw_digit(s[4]) &&
-               tpacpi_is_fw_digit(s[5]) &&
-               s[6] == 'W' && s[7] == 'W';
+               tpacpi_is_fw_digit(s[5]);
 }
 
 /* returns 0 - probe ok, or < 0 - probe error.
@@ -8661,6 +8717,10 @@ static int __init probe_for_thinkpad(void)
        if (acpi_disabled)
                return -ENODEV;
 
+       /* It would be dangerous to run the driver in this case */
+       if (!tpacpi_is_ibm() && !tpacpi_is_lenovo())
+               return -ENODEV;
+
        /*
         * Non-ancient models have better DMI tagging, but very old models
         * don't.  tpacpi_is_fw_known() is a cheat to help in that case.
@@ -8669,8 +8729,8 @@ static int __init probe_for_thinkpad(void)
                      (thinkpad_id.ec_model != 0) ||
                      tpacpi_is_fw_known();
 
-       /* ec is required because many other handles are relative to it */
-       TPACPI_ACPIHANDLE_INIT(ec);
+       /* The EC handler is required */
+       tpacpi_acpi_handle_locate("ec", TPACPI_ACPI_EC_HID, &ec_handle);
        if (!ec_handle) {
                if (is_thinkpad)
                        printk(TPACPI_ERR
@@ -8684,12 +8744,34 @@ static int __init probe_for_thinkpad(void)
        return 0;
 }
 
+static void __init thinkpad_acpi_init_banner(void)
+{
+       printk(TPACPI_INFO "%s v%s\n", TPACPI_DESC, TPACPI_VERSION);
+       printk(TPACPI_INFO "%s\n", TPACPI_URL);
+
+       printk(TPACPI_INFO "ThinkPad BIOS %s, EC %s\n",
+               (thinkpad_id.bios_version_str) ?
+                       thinkpad_id.bios_version_str : "unknown",
+               (thinkpad_id.ec_version_str) ?
+                       thinkpad_id.ec_version_str : "unknown");
+
+       BUG_ON(!thinkpad_id.vendor);
+
+       if (thinkpad_id.model_str)
+               printk(TPACPI_INFO "%s %s, model %s\n",
+                       (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ?
+                               "IBM" : ((thinkpad_id.vendor ==
+                                               PCI_VENDOR_ID_LENOVO) ?
+                                       "Lenovo" : "Unknown vendor"),
+                       thinkpad_id.model_str,
+                       (thinkpad_id.nummodel_str) ?
+                               thinkpad_id.nummodel_str : "unknown");
+}
 
 /* Module init, exit, parameters */
 
 static struct ibm_init_struct ibms_init[] __initdata = {
        {
-               .init = thinkpad_acpi_driver_init,
                .data = &thinkpad_acpi_driver_data,
        },
        {
@@ -8736,9 +8818,6 @@ static struct ibm_init_struct ibms_init[] __initdata = {
                .data = &thermal_driver_data,
        },
        {
-               .data = &ecdump_driver_data,
-       },
-       {
                .init = brightness_init,
                .data = &brightness_driver_data,
        },
@@ -8846,7 +8925,6 @@ TPACPI_PARAM(light);
 TPACPI_PARAM(cmos);
 TPACPI_PARAM(led);
 TPACPI_PARAM(beep);
-TPACPI_PARAM(ecdump);
 TPACPI_PARAM(brightness);
 TPACPI_PARAM(volume);
 TPACPI_PARAM(fan);
@@ -8959,6 +9037,9 @@ static int __init thinkpad_acpi_module_init(void)
 
        /* Driver initialization */
 
+       thinkpad_acpi_init_banner();
+       tpacpi_check_outdated_fw();
+
        TPACPI_ACPIHANDLE_INIT(ecrd);
        TPACPI_ACPIHANDLE_INIT(ecwr);
 
@@ -9058,13 +9139,16 @@ static int __init thinkpad_acpi_module_init(void)
                tpacpi_inputdev->name = "ThinkPad Extra Buttons";
                tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0";
                tpacpi_inputdev->id.bustype = BUS_HOST;
-               tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ?
-                                               thinkpad_id.vendor :
-                                               PCI_VENDOR_ID_IBM;
+               tpacpi_inputdev->id.vendor = thinkpad_id.vendor;
                tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT;
                tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION;
                tpacpi_inputdev->dev.parent = &tpacpi_pdev->dev;
        }
+
+       /* Init subdriver dependencies */
+       tpacpi_detect_brightness_capabilities();
+
+       /* Init subdrivers */
        for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
                ret = ibm_init(&ibms_init[i]);
                if (ret >= 0 && *ibms_init[i].param)