/* * thinkpad_acpi.c - ThinkPad ACPI Extras * * * Copyright (C) 2004-2005 Borislav Deianov * Copyright (C) 2006-2008 Henrique de Moraes Holschuh * * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ #define TPACPI_VERSION "0.21" #define TPACPI_SYSFS_VERSION 0x020200 /* * Changelog: * 2007-10-20 changelog trimmed down * * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to * drivers/misc. * * 2006-11-22 0.13 new maintainer * changelog now lives in git commit history, and will * not be updated further in-file. * * 2005-03-17 0.11 support for 600e, 770x * thanks to Jamie Lentin * * 2005-01-16 0.9 use MODULE_VERSION * thanks to Henrik Brix Andersen * fix parameter passing on module loading * thanks to Rusty Russell * thanks to Jim Radford * 2004-11-08 0.8 fix init error case, don't return from a macro * thanks to Chris Wright */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* ThinkPad CMOS commands */ #define TP_CMOS_VOLUME_DOWN 0 #define TP_CMOS_VOLUME_UP 1 #define TP_CMOS_VOLUME_MUTE 2 #define TP_CMOS_BRIGHTNESS_UP 4 #define TP_CMOS_BRIGHTNESS_DOWN 5 #define TP_CMOS_THINKLIGHT_ON 12 #define TP_CMOS_THINKLIGHT_OFF 13 /* NVRAM Addresses */ enum tp_nvram_addr { TP_NVRAM_ADDR_HK2 = 0x57, TP_NVRAM_ADDR_THINKLIGHT = 0x58, TP_NVRAM_ADDR_VIDEO = 0x59, TP_NVRAM_ADDR_BRIGHTNESS = 0x5e, TP_NVRAM_ADDR_MIXER = 0x60, }; /* NVRAM bit masks */ enum { TP_NVRAM_MASK_HKT_THINKPAD = 0x08, TP_NVRAM_MASK_HKT_ZOOM = 0x20, TP_NVRAM_MASK_HKT_DISPLAY = 0x40, TP_NVRAM_MASK_HKT_HIBERNATE = 0x80, TP_NVRAM_MASK_THINKLIGHT = 0x10, TP_NVRAM_MASK_HKT_DISPEXPND = 0x30, TP_NVRAM_MASK_HKT_BRIGHTNESS = 0x20, TP_NVRAM_MASK_LEVEL_BRIGHTNESS = 0x0f, TP_NVRAM_POS_LEVEL_BRIGHTNESS = 0, TP_NVRAM_MASK_MUTE = 0x40, TP_NVRAM_MASK_HKT_VOLUME = 0x80, TP_NVRAM_MASK_LEVEL_VOLUME = 0x0f, TP_NVRAM_POS_LEVEL_VOLUME = 0, }; /* ACPI HIDs */ #define TPACPI_ACPI_HKEY_HID "IBM0068" /* Input IDs */ #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */ #define TPACPI_HKEY_INPUT_VERSION 0x4101 /**************************************************************************** * Main driver */ #define TPACPI_NAME "thinkpad" #define TPACPI_DESC "ThinkPad ACPI Extras" #define TPACPI_FILE TPACPI_NAME "_acpi" #define TPACPI_URL "http://ibm-acpi.sf.net/" #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net" #define TPACPI_PROC_DIR "ibm" #define TPACPI_ACPI_EVENT_PREFIX "ibm" #define TPACPI_DRVR_NAME TPACPI_FILE #define TPACPI_DRVR_SHORTNAME "tpacpi" #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon" #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd" #define TPACPI_WORKQUEUE_NAME "ktpacpid" #define TPACPI_MAX_ACPI_ARGS 3 /* rfkill switches */ enum { TPACPI_RFK_BLUETOOTH_SW_ID = 0, TPACPI_RFK_WWAN_SW_ID, }; /* Debugging */ #define TPACPI_LOG TPACPI_FILE ": " #define TPACPI_ERR KERN_ERR TPACPI_LOG #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG #define TPACPI_INFO KERN_INFO TPACPI_LOG #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG #define TPACPI_DBG_ALL 0xffff #define TPACPI_DBG_INIT 0x0001 #define TPACPI_DBG_EXIT 0x0002 #define dbg_printk(a_dbg_level, format, arg...) \ do { if (dbg_level & a_dbg_level) \ printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \ } while (0) #ifdef CONFIG_THINKPAD_ACPI_DEBUG #define vdbg_printk(a_dbg_level, format, arg...) \ dbg_printk(a_dbg_level, format, ## arg) static const char *str_supported(int is_supported); #else #define vdbg_printk(a_dbg_level, format, arg...) #endif #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off") #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") #define strlencmp(a, b) (strncmp((a), (b), strlen(b))) /**************************************************************************** * Driver-wide structs and misc. variables */ struct ibm_struct; struct tp_acpi_drv_struct { const struct acpi_device_id *hid; struct acpi_driver *driver; void (*notify) (struct ibm_struct *, u32); acpi_handle *handle; u32 type; struct acpi_device *device; }; struct ibm_struct { char *name; int (*read) (char *); int (*write) (char *); void (*exit) (void); void (*resume) (void); void (*suspend) (pm_message_t state); struct list_head all_drivers; struct tp_acpi_drv_struct *acpi; struct { u8 acpi_driver_registered:1; u8 acpi_notify_installed:1; u8 proc_created:1; u8 init_called:1; u8 experimental:1; } flags; }; struct ibm_init_struct { char param[32]; int (*init) (struct ibm_init_struct *); struct ibm_struct *data; }; static struct { #ifdef CONFIG_THINKPAD_ACPI_BAY u32 bay_status:1; u32 bay_eject:1; u32 bay_status2:1; u32 bay_eject2:1; #endif u32 bluetooth:1; u32 hotkey:1; u32 hotkey_mask:1; u32 hotkey_wlsw:1; u32 hotkey_tablet:1; u32 light:1; u32 light_status:1; u32 bright_16levels:1; u32 bright_acpimode:1; u32 wan:1; u32 fan_ctrl_status_undef:1; u32 input_device_registered:1; u32 platform_drv_registered:1; u32 platform_drv_attrs_registered:1; u32 sensors_pdrv_registered:1; u32 sensors_pdrv_attrs_registered:1; u32 sensors_pdev_attrs_registered:1; u32 hotkey_poll_active:1; } tp_features; static struct { u16 hotkey_mask_ff:1; u16 bright_cmos_ec_unsync:1; } tp_warned; struct thinkpad_id_data { unsigned int vendor; /* ThinkPad vendor: * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */ char *bios_version_str; /* Something like 1ZET51WW (1.03z) */ char *ec_version_str; /* Something like 1ZHT51WW-1.04a */ u16 bios_model; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */ u16 ec_model; char *model_str; /* ThinkPad T43 */ char *nummodel_str; /* 9384A9C for a 9384-A9C model */ }; static struct thinkpad_id_data thinkpad_id; static enum { TPACPI_LIFE_INIT = 0, TPACPI_LIFE_RUNNING, TPACPI_LIFE_EXITING, } tpacpi_lifecycle; static int experimental; static u32 dbg_level; static struct workqueue_struct *tpacpi_wq; /* Special LED class that can defer work */ struct tpacpi_led_classdev { struct led_classdev led_classdev; struct work_struct work; enum led_brightness new_brightness; unsigned int led; }; /**************************************************************************** **************************************************************************** * * ACPI Helpers and device model * **************************************************************************** ****************************************************************************/ /************************************************************************* * ACPI basic handles */ static acpi_handle root_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 */ ); TPACPI_HANDLE(ecrd, ec, "ECRD"); /* 570 */ TPACPI_HANDLE(ecwr, ec, "ECWR"); /* 570 */ TPACPI_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, */ /* T4x, X31, X40 */ "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ "\\CMS", /* R40, R40e */ ); /* all others */ TPACPI_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ "^HKEY", /* R30, R31 */ "HKEY", /* all others */ ); /* 570 */ 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.VID", /* all others */ ); /* R30, R31 */ /************************************************************************* * ACPI helpers */ static int acpi_evalf(acpi_handle handle, void *res, char *method, char *fmt, ...) { char *fmt0 = fmt; struct acpi_object_list params; union acpi_object in_objs[TPACPI_MAX_ACPI_ARGS]; struct acpi_buffer result, *resultp; union acpi_object out_obj; acpi_status status; va_list ap; char res_type; int success; int quiet; if (!*fmt) { printk(TPACPI_ERR "acpi_evalf() called with empty format\n"); return 0; } if (*fmt == 'q') { quiet = 1; fmt++; } else quiet = 0; res_type = *(fmt++); params.count = 0; params.pointer = &in_objs[0]; va_start(ap, fmt); while (*fmt) { char c = *(fmt++); switch (c) { case 'd': /* int */ in_objs[params.count].integer.value = va_arg(ap, int); in_objs[params.count++].type = ACPI_TYPE_INTEGER; break; /* add more types as needed */ default: printk(TPACPI_ERR "acpi_evalf() called " "with invalid format character '%c'\n", c); return 0; } } va_end(ap); if (res_type != 'v') { result.length = sizeof(out_obj); result.pointer = &out_obj; resultp = &result; } else resultp = NULL; status = acpi_evaluate_object(handle, method, ¶ms, resultp); switch (res_type) { case 'd': /* int */ if (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; break; /* add more types as needed */ default: printk(TPACPI_ERR "acpi_evalf() called " "with invalid format character '%c'\n", res_type); return 0; } if (!success && !quiet) printk(TPACPI_ERR "acpi_evalf(%s, %s, ...) failed: %d\n", method, fmt0, status); return success; } static int acpi_ec_read(int i, u8 *p) { int v; if (ecrd_handle) { if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) return 0; *p = v; } else { if (ec_read(i, p) < 0) return 0; } return 1; } static int acpi_ec_write(int i, u8 v) { if (ecwr_handle) { if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) return 0; } else { if (ec_write(i, v) < 0) return 0; } return 1; } #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY) static int _sta(acpi_handle handle) { int status; if (!handle || !acpi_evalf(handle, &status, "_STA", "d")) status = 0; return status; } #endif static int issue_thinkpad_cmos_command(int cmos_cmd) { if (!cmos_handle) return -ENXIO; if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd)) return -EIO; return 0; } /************************************************************************* * ACPI device model */ #define TPACPI_ACPIHANDLE_INIT(object) \ drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \ object##_paths, ARRAY_SIZE(object##_paths), &object##_path) static void drv_acpi_handle_init(char *name, acpi_handle *handle, acpi_handle parent, char **paths, int num_paths, char **path) { int i; acpi_status status; vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n", 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); return; } } vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n", name); *handle = NULL; } static void dispatch_acpi_notify(acpi_handle handle, u32 event, void *data) { struct ibm_struct *ibm = data; if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) return; if (!ibm || !ibm->acpi || !ibm->acpi->notify) return; ibm->acpi->notify(ibm, event); } static int __init setup_acpi_notify(struct ibm_struct *ibm) { acpi_status status; int rc; BUG_ON(!ibm->acpi); if (!*ibm->acpi->handle) return 0; vdbg_printk(TPACPI_DBG_INIT, "setting up ACPI notify for %s\n", ibm->name); rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device); if (rc < 0) { printk(TPACPI_ERR "acpi_bus_get_device(%s) failed: %d\n", ibm->name, rc); return -ENODEV; } ibm->acpi->device->driver_data = ibm; sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", TPACPI_ACPI_EVENT_PREFIX, ibm->name); status = acpi_install_notify_handler(*ibm->acpi->handle, ibm->acpi->type, dispatch_acpi_notify, ibm); if (ACPI_FAILURE(status)) { if (status == AE_ALREADY_EXISTS) { printk(TPACPI_NOTICE "another device driver is already " "handling %s events\n", ibm->name); } else { printk(TPACPI_ERR "acpi_install_notify_handler(%s) failed: %d\n", ibm->name, status); } return -ENODEV; } ibm->flags.acpi_notify_installed = 1; return 0; } static int __init tpacpi_device_add(struct acpi_device *device) { return 0; } static int __init register_tpacpi_subdriver(struct ibm_struct *ibm) { int rc; dbg_printk(TPACPI_DBG_INIT, "registering %s as an ACPI driver\n", ibm->name); BUG_ON(!ibm->acpi); ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); if (!ibm->acpi->driver) { printk(TPACPI_ERR "failed to allocate memory for ibm->acpi->driver\n"); return -ENOMEM; } sprintf(ibm->acpi->driver->name, "%s_%s", TPACPI_NAME, ibm->name); ibm->acpi->driver->ids = ibm->acpi->hid; ibm->acpi->driver->ops.add = &tpacpi_device_add; rc = acpi_bus_register_driver(ibm->acpi->driver); if (rc < 0) { printk(TPACPI_ERR "acpi_bus_register_driver(%s) failed: %d\n", ibm->name, rc); kfree(ibm->acpi->driver); ibm->acpi->driver = NULL; } else if (!rc) ibm->flags.acpi_driver_registered = 1; return rc; } /**************************************************************************** **************************************************************************** * * Procfs Helpers * **************************************************************************** ****************************************************************************/ static int dispatch_procfs_read(char *page, char **start, off_t off, int count, int *eof, void *data) { struct ibm_struct *ibm = data; int len; if (!ibm || !ibm->read) return -EINVAL; len = ibm->read(page); if (len < 0) return len; if (len <= off + count) *eof = 1; *start = page + off; len -= off; if (len > count) len = count; if (len < 0) len = 0; return len; } static int dispatch_procfs_write(struct file *file, const char __user *userbuf, unsigned long count, void *data) { struct ibm_struct *ibm = data; char *kernbuf; int ret; if (!ibm || !ibm->write) return -EINVAL; kernbuf = kmalloc(count + 2, GFP_KERNEL); if (!kernbuf) return -ENOMEM; if (copy_from_user(kernbuf, userbuf, count)) { kfree(kernbuf); return -EFAULT; } kernbuf[count] = 0; strcat(kernbuf, ","); ret = ibm->write(kernbuf); if (ret == 0) ret = count; kfree(kernbuf); return ret; } static char *next_cmd(char **cmds) { char *start = *cmds; char *end; while ((end = strchr(start, ',')) && end == start) start = end + 1; if (!end) return NULL; *end = 0; *cmds = end + 1; return start; } /**************************************************************************** **************************************************************************** * * Device model: input, hwmon and platform * **************************************************************************** ****************************************************************************/ static struct platform_device *tpacpi_pdev; static struct platform_device *tpacpi_sensors_pdev; static struct device *tpacpi_hwmon; static struct input_dev *tpacpi_inputdev; static struct mutex tpacpi_inputdev_send_mutex; static LIST_HEAD(tpacpi_all_drivers); static int tpacpi_suspend_handler(struct platform_device *pdev, pm_message_t state) { struct ibm_struct *ibm, *itmp; list_for_each_entry_safe(ibm, itmp, &tpacpi_all_drivers, all_drivers) { if (ibm->suspend) (ibm->suspend)(state); } return 0; } static int tpacpi_resume_handler(struct platform_device *pdev) { struct ibm_struct *ibm, *itmp; list_for_each_entry_safe(ibm, itmp, &tpacpi_all_drivers, all_drivers) { if (ibm->resume) (ibm->resume)(); } return 0; } static struct platform_driver tpacpi_pdriver = { .driver = { .name = TPACPI_DRVR_NAME, .owner = THIS_MODULE, }, .suspend = tpacpi_suspend_handler, .resume = tpacpi_resume_handler, }; static struct platform_driver tpacpi_hwmon_pdriver = { .driver = { .name = TPACPI_HWMON_DRVR_NAME, .owner = THIS_MODULE, }, }; /************************************************************************* * sysfs support helpers */ struct attribute_set { unsigned int members, max_members; struct attribute_group group; }; struct attribute_set_obj { struct attribute_set s; struct attribute *a; } __attribute__((packed)); static struct attribute_set *create_attr_set(unsigned int max_members, const char *name) { struct attribute_set_obj *sobj; if (max_members == 0) return NULL; /* Allocates space for implicit NULL at the end too */ sobj = kzalloc(sizeof(struct attribute_set_obj) + max_members * sizeof(struct attribute *), GFP_KERNEL); if (!sobj) return NULL; sobj->s.max_members = max_members; sobj->s.group.attrs = &sobj->a; sobj->s.group.name = name; return &sobj->s; } #define destroy_attr_set(_set) \ kfree(_set); /* not multi-threaded safe, use it in a single thread per set */ static int add_to_attr_set(struct attribute_set *s, struct attribute *attr) { if (!s || !attr) return -EINVAL; if (s->members >= s->max_members) return -ENOMEM; s->group.attrs[s->members] = attr; s->members++; return 0; } static int add_many_to_attr_set(struct attribute_set *s, struct attribute **attr, unsigned int count) { int i, res; for (i = 0; i < count; i++) { res = add_to_attr_set(s, attr[i]); if (res) return res; } return 0; } static void delete_attr_set(struct attribute_set *s, struct kobject *kobj) { sysfs_remove_group(kobj, &s->group); destroy_attr_set(s); } #define register_attr_set_with_sysfs(_attr_set, _kobj) \ sysfs_create_group(_kobj, &_attr_set->group) static int parse_strtoul(const char *buf, unsigned long max, unsigned long *value) { char *endp; while (*buf && isspace(*buf)) buf++; *value = simple_strtoul(buf, &endp, 0); while (*endp && isspace(*endp)) endp++; if (*endp || *value > max) return -EINVAL; return 0; } static void tpacpi_disable_brightness_delay(void) { if (acpi_evalf(hkey_handle, NULL, "PWMS", "qvd", 0)) printk(TPACPI_NOTICE "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, &bcl_ptr); if (ACPI_SUCCESS(status) && bcl_levels > 2) { tp_features.bright_acpimode = 1; return (bcl_levels - 2); } return 0; } static int __init tpacpi_new_rfkill(const unsigned int id, struct rfkill **rfk, const enum rfkill_type rfktype, const char *name, int (*toggle_radio)(void *, enum rfkill_state), int (*get_state)(void *, enum rfkill_state *)) { int res; enum rfkill_state initial_state; *rfk = rfkill_allocate(&tpacpi_pdev->dev, rfktype); if (!*rfk) { printk(TPACPI_ERR "failed to allocate memory for rfkill class\n"); return -ENOMEM; } (*rfk)->name = name; (*rfk)->get_state = get_state; (*rfk)->toggle_radio = toggle_radio; if (!get_state(NULL, &initial_state)) (*rfk)->state = initial_state; res = rfkill_register(*rfk); if (res < 0) { printk(TPACPI_ERR "failed to register %s rfkill switch: %d\n", name, res); rfkill_free(*rfk); *rfk = NULL; return res; } return 0; } /************************************************************************* * thinkpad-acpi driver attributes */ /* interface_version --------------------------------------------------- */ static ssize_t tpacpi_driver_interface_version_show( struct device_driver *drv, char *buf) { return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); } static DRIVER_ATTR(interface_version, S_IRUGO, tpacpi_driver_interface_version_show, NULL); /* debug_level --------------------------------------------------------- */ static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, char *buf) { return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); } static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, const char *buf, size_t count) { unsigned long t; if (parse_strtoul(buf, 0xffff, &t)) return -EINVAL; dbg_level = t; return count; } static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, tpacpi_driver_debug_show, tpacpi_driver_debug_store); /* version ------------------------------------------------------------- */ static ssize_t tpacpi_driver_version_show(struct device_driver *drv, char *buf) { return snprintf(buf, PAGE_SIZE, "%s v%s\n", TPACPI_DESC, TPACPI_VERSION); } static DRIVER_ATTR(version, S_IRUGO, tpacpi_driver_version_show, NULL); /* --------------------------------------------------------------------- */ static struct driver_attribute *tpacpi_driver_attributes[] = { &driver_attr_debug_level, &driver_attr_version, &driver_attr_interface_version, }; static int __init tpacpi_create_driver_attributes(struct device_driver *drv) { int i, res; i = 0; res = 0; while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { res = driver_create_file(drv, tpacpi_driver_attributes[i]); i++; } return res; } static void tpacpi_remove_driver_attributes(struct device_driver *drv) { int i; for (i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) driver_remove_file(drv, tpacpi_driver_attributes[i]); } /**************************************************************************** **************************************************************************** * * Subdrivers * **************************************************************************** ****************************************************************************/ /************************************************************************* * thinkpad-acpi init 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"); return 0; } static int thinkpad_acpi_driver_read(char *p) { int len = 0; len += sprintf(p + len, "driver:\t\t%s\n", TPACPI_DESC); len += sprintf(p + len, "version:\t%s\n", TPACPI_VERSION); return len; } static struct ibm_struct thinkpad_acpi_driver_data = { .name = "driver", .read = thinkpad_acpi_driver_read, }; /************************************************************************* * Hotkey subdriver */ enum { /* hot key scan codes (derived from ACPI DSDT) */ TP_ACPI_HOTKEYSCAN_FNF1 = 0, TP_ACPI_HOTKEYSCAN_FNF2, TP_ACPI_HOTKEYSCAN_FNF3, TP_ACPI_HOTKEYSCAN_FNF4, TP_ACPI_HOTKEYSCAN_FNF5, TP_ACPI_HOTKEYSCAN_FNF6, TP_ACPI_HOTKEYSCAN_FNF7, TP_ACPI_HOTKEYSCAN_FNF8, TP_ACPI_HOTKEYSCAN_FNF9, TP_ACPI_HOTKEYSCAN_FNF10, TP_ACPI_HOTKEYSCAN_FNF11, TP_ACPI_HOTKEYSCAN_FNF12, TP_ACPI_HOTKEYSCAN_FNBACKSPACE, TP_ACPI_HOTKEYSCAN_FNINSERT, TP_ACPI_HOTKEYSCAN_FNDELETE, TP_ACPI_HOTKEYSCAN_FNHOME, TP_ACPI_HOTKEYSCAN_FNEND, TP_ACPI_HOTKEYSCAN_FNPAGEUP, TP_ACPI_HOTKEYSCAN_FNPAGEDOWN, TP_ACPI_HOTKEYSCAN_FNSPACE, TP_ACPI_HOTKEYSCAN_VOLUMEUP, TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, TP_ACPI_HOTKEYSCAN_MUTE, TP_ACPI_HOTKEYSCAN_THINKPAD, }; enum { /* Keys available through NVRAM polling */ TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, }; enum { /* Positions of some of the keys in hotkey masks */ TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7, TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8, TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12, TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME, TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND, TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP, TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE, TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP, TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN, TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE, TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD, }; enum { /* NVRAM to ACPI HKEY group map */ TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK | TP_ACPI_HKEY_ZOOM_MASK | TP_ACPI_HKEY_DISPSWTCH_MASK | TP_ACPI_HKEY_HIBERNATE_MASK, TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK | TP_ACPI_HKEY_BRGHTDWN_MASK, TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK | TP_ACPI_HKEY_VOLDWN_MASK | TP_ACPI_HKEY_MUTE_MASK, }; #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL struct tp_nvram_state { u16 thinkpad_toggle:1; u16 zoom_toggle:1; u16 display_toggle:1; u16 thinklight_toggle:1; u16 hibernate_toggle:1; u16 displayexp_toggle:1; u16 display_state:1; u16 brightness_toggle:1; u16 volume_toggle:1; u16 mute:1; u8 brightness_level; u8 volume_level; }; static struct task_struct *tpacpi_hotkey_task; static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */ static int hotkey_poll_freq = 10; /* Hz */ static struct mutex hotkey_thread_mutex; static struct mutex hotkey_thread_data_mutex; static unsigned int hotkey_config_change; #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ #define hotkey_source_mask 0U #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ static struct mutex hotkey_mutex; static enum { /* Reasons for waking up */ TP_ACPI_WAKEUP_NONE = 0, /* None or unknown */ TP_ACPI_WAKEUP_BAYEJ, /* Bay ejection request */ TP_ACPI_WAKEUP_UNDOCK, /* Undock request */ } hotkey_wakeup_reason; static int hotkey_autosleep_ack; static int hotkey_orig_status; static u32 hotkey_orig_mask; static u32 hotkey_all_mask; static u32 hotkey_reserved_mask; static u32 hotkey_mask; static unsigned int hotkey_report_mode; static u16 *hotkey_keycode_map; static struct attribute_set *hotkey_dev_attributes; #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL #define HOTKEY_CONFIG_CRITICAL_START \ do { \ mutex_lock(&hotkey_thread_data_mutex); \ hotkey_config_change++; \ } while (0); #define HOTKEY_CONFIG_CRITICAL_END \ mutex_unlock(&hotkey_thread_data_mutex); #else #define HOTKEY_CONFIG_CRITICAL_START #define HOTKEY_CONFIG_CRITICAL_END #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ /* HKEY.MHKG() return bits */ #define TP_HOTKEY_TABLET_MASK (1 << 3) static int hotkey_get_wlsw(int *status) { if (!acpi_evalf(hkey_handle, status, "WLSW", "d")) return -EIO; return 0; } static int hotkey_get_tablet_mode(int *status) { int s; if (!acpi_evalf(hkey_handle, &s, "MHKG", "d")) return -EIO; *status = ((s & TP_HOTKEY_TABLET_MASK) != 0); return 0; } /* * Call with hotkey_mutex held */ static int hotkey_mask_get(void) { u32 m = 0; if (tp_features.hotkey_mask) { if (!acpi_evalf(hkey_handle, &m, "DHKN", "d")) return -EIO; } hotkey_mask = m | (hotkey_source_mask & hotkey_mask); return 0; } /* * Call with hotkey_mutex held */ static int hotkey_mask_set(u32 mask) { int i; int rc = 0; if (tp_features.hotkey_mask) { if (!tp_warned.hotkey_mask_ff && (mask == 0xffff || mask == 0xffffff || mask == 0xffffffff)) { tp_warned.hotkey_mask_ff = 1; printk(TPACPI_NOTICE "setting the hotkey mask to 0x%08x is likely " "not the best way to go about it\n", mask); printk(TPACPI_NOTICE "please consider using the driver defaults, " "and refer to up-to-date thinkpad-acpi " "documentation\n"); } HOTKEY_CONFIG_CRITICAL_START for (i = 0; i < 32; i++) { u32 m = 1 << i; /* enable in firmware mask only keys not in NVRAM * mode, but enable the key in the cached hotkey_mask * regardless of mode, or the key will end up * disabled by hotkey_mask_get() */ if (!acpi_evalf(hkey_handle, NULL, "MHKM", "vdd", i + 1, !!((mask & ~hotkey_source_mask) & m))) { rc = -EIO; break; } else { hotkey_mask = (hotkey_mask & ~m) | (mask & m); } } HOTKEY_CONFIG_CRITICAL_END /* hotkey_mask_get must be called unconditionally below */ if (!hotkey_mask_get() && !rc && (hotkey_mask & ~hotkey_source_mask) != (mask & ~hotkey_source_mask)) { printk(TPACPI_NOTICE "requested hot key mask 0x%08x, but " "firmware forced it to 0x%08x\n", mask, hotkey_mask); } } else { #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL HOTKEY_CONFIG_CRITICAL_START hotkey_mask = mask & hotkey_source_mask; HOTKEY_CONFIG_CRITICAL_END hotkey_mask_get(); if (hotkey_mask != mask) { printk(TPACPI_NOTICE "requested hot key mask 0x%08x, " "forced to 0x%08x (NVRAM poll mask is " "0x%08x): no firmware mask support\n", mask, hotkey_mask, hotkey_source_mask); } #else hotkey_mask_get(); rc = -ENXIO; #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ } return rc; } static int hotkey_status_get(int *status) { if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) return -EIO; return 0; } static int hotkey_status_set(int status) { if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status)) return -EIO; return 0; } static void tpacpi_input_send_tabletsw(void) { int state; if (tp_features.hotkey_tablet && !hotkey_get_tablet_mode(&state)) { mutex_lock(&tpacpi_inputdev_send_mutex); input_report_switch(tpacpi_inputdev, SW_TABLET_MODE, !!state); input_sync(tpacpi_inputdev); mutex_unlock(&tpacpi_inputdev_send_mutex); } } static void tpacpi_input_send_key(unsigned int scancode) { unsigned int keycode; keycode = hotkey_keycode_map[scancode]; if (keycode != KEY_RESERVED) { mutex_lock(&tpacpi_inputdev_send_mutex); 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_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); } } #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL static struct tp_acpi_drv_struct ibm_hotkey_acpidriver; static void tpacpi_hotkey_send_key(unsigned int scancode) { tpacpi_input_send_key(scancode); if (hotkey_report_mode < 2) { acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device, 0x80, 0x1001 + scancode); } } static void hotkey_read_nvram(struct tp_nvram_state *n, u32 m) { u8 d; if (m & TP_NVRAM_HKEY_GROUP_HK2) { d = nvram_read_byte(TP_NVRAM_ADDR_HK2); n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); } if (m & TP_ACPI_HKEY_THNKLGHT_MASK) { d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT); n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); } if (m & TP_ACPI_HKEY_DISPXPAND_MASK) { d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO); n->displayexp_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPEXPND); } if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) { d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS); n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; n->brightness_toggle = !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS); } if (m & TP_NVRAM_HKEY_GROUP_VOLUME) { d = nvram_read_byte(TP_NVRAM_ADDR_MIXER); n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) >> TP_NVRAM_POS_LEVEL_VOLUME; n->mute = !!(d & TP_NVRAM_MASK_MUTE); n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); } } #define TPACPI_COMPARE_KEY(__scancode, __member) \ do { \ if ((mask & (1 << __scancode)) && \ oldn->__member != newn->__member) \ tpacpi_hotkey_send_key(__scancode); \ } while (0) #define TPACPI_MAY_SEND_KEY(__scancode) \ do { if (mask & (1 << __scancode)) \ tpacpi_hotkey_send_key(__scancode); } while (0) static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn, struct tp_nvram_state *newn, u32 mask) { 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); TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle); TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle); TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle); /* handle volume */ if (oldn->volume_toggle != newn->volume_toggle) { if (oldn->mute != newn->mute) { 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) { 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 { TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN); } } } /* 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) { 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); } } } } #undef TPACPI_COMPARE_KEY #undef TPACPI_MAY_SEND_KEY static int hotkey_kthread(void *data) { struct tp_nvram_state s[2]; u32 mask; unsigned int si, so; unsigned long t; unsigned int change_detector, must_reset; mutex_lock(&hotkey_thread_mutex); if (tpacpi_lifecycle == TPACPI_LIFE_EXITING) goto exit; set_freezable(); so = 0; si = 1; t = 0; /* Initial state for compares */ mutex_lock(&hotkey_thread_data_mutex); change_detector = hotkey_config_change; mask = hotkey_source_mask & hotkey_mask; mutex_unlock(&hotkey_thread_data_mutex); hotkey_read_nvram(&s[so], mask); while (!kthread_should_stop() && hotkey_poll_freq) { if (t == 0) t = 1000/hotkey_poll_freq; t = msleep_interruptible(t); if (unlikely(kthread_should_stop())) break; must_reset = try_to_freeze(); if (t > 0 && !must_reset) continue; mutex_lock(&hotkey_thread_data_mutex); if (must_reset || hotkey_config_change != change_detector) { /* forget old state on thaw or config change */ si = so; t = 0; change_detector = hotkey_config_change; } mask = hotkey_source_mask & hotkey_mask; mutex_unlock(&hotkey_thread_data_mutex); if (likely(mask)) { hotkey_read_nvram(&s[si], mask); if (likely(si != so)) { hotkey_compare_and_issue_event(&s[so], &s[si], mask); } } so = si; si ^= 1; } exit: mutex_unlock(&hotkey_thread_mutex); return 0; } static void hotkey_poll_stop_sync(void) { if (tpacpi_hotkey_task) { if (frozen(tpacpi_hotkey_task) || freezing(tpacpi_hotkey_task)) thaw_process(tpacpi_hotkey_task); kthread_stop(tpacpi_hotkey_task); tpacpi_hotkey_task = NULL; mutex_lock(&hotkey_thread_mutex); /* at this point, the thread did exit */ mutex_unlock(&hotkey_thread_mutex); } } /* call with hotkey_mutex held */ static void hotkey_poll_setup(int may_warn) { if ((hotkey_source_mask & hotkey_mask) != 0 && hotkey_poll_freq > 0 && (tpacpi_inputdev->users > 0 || hotkey_report_mode < 2)) { if (!tpacpi_hotkey_task) { tpacpi_hotkey_task = kthread_run(hotkey_kthread, NULL, TPACPI_NVRAM_KTHREAD_NAME); if (IS_ERR(tpacpi_hotkey_task)) { tpacpi_hotkey_task = NULL; printk(TPACPI_ERR "could not create kernel thread " "for hotkey polling\n"); } } } else { hotkey_poll_stop_sync(); if (may_warn && hotkey_source_mask != 0 && hotkey_poll_freq == 0) { printk(TPACPI_NOTICE "hot keys 0x%08x require polling, " "which is currently disabled\n", hotkey_source_mask); } } } static void hotkey_poll_setup_safe(int may_warn) { mutex_lock(&hotkey_mutex); hotkey_poll_setup(may_warn); mutex_unlock(&hotkey_mutex); } #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ static void hotkey_poll_setup_safe(int __unused) { } #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ static int hotkey_inputdev_open(struct input_dev *dev) { switch (tpacpi_lifecycle) { case TPACPI_LIFE_INIT: /* * hotkey_init will call hotkey_poll_setup_safe * at the appropriate moment */ return 0; case TPACPI_LIFE_EXITING: return -EBUSY; case TPACPI_LIFE_RUNNING: hotkey_poll_setup_safe(0); return 0; } /* Should only happen if tpacpi_lifecycle is corrupt */ BUG(); return -EBUSY; } static void hotkey_inputdev_close(struct input_dev *dev) { /* disable hotkey polling when possible */ if (tpacpi_lifecycle == TPACPI_LIFE_RUNNING) hotkey_poll_setup_safe(0); } /* sysfs hotkey enable ------------------------------------------------- */ static ssize_t hotkey_enable_show(struct device *dev, struct device_attribute *attr, char *buf) { int res, status; res = hotkey_status_get(&status); if (res) return res; return snprintf(buf, PAGE_SIZE, "%d\n", status); } static ssize_t hotkey_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { unsigned long t; int res; if (parse_strtoul(buf, 1, &t)) return -EINVAL; res = hotkey_status_set(t); return (res) ? res : count; } static struct device_attribute dev_attr_hotkey_enable = __ATTR(hotkey_enable, S_IWUSR | S_IRUGO, hotkey_enable_show, hotkey_enable_store); /* sysfs hotkey mask --------------------------------------------------- */ static ssize_t hotkey_mask_show(struct device *dev, struct device_attribute *attr, char *buf) { int res; if (mutex_lock_interruptible(&hotkey_mutex)) return -ERESTARTSYS; res = hotkey_mask_get(); mutex_unlock(&hotkey_mutex); return (res)? res : snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_mask); } static ssize_t hotkey_mask_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { unsigned long t; int res; if (parse_strtoul(buf, 0xffffffffUL, &t)) return -EINVAL; if (mutex_lock_interruptible(&hotkey_mutex)) return -ERESTARTSYS; res = hotkey_mask_set(t); #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL hotkey_poll_setup(1); #endif mutex_unlock(&hotkey_mutex); return (res) ? res : count; } static struct device_attribute dev_attr_hotkey_mask = __ATTR(hotkey_mask, S_IWUSR | S_IRUGO, hotkey_mask_show, hotkey_mask_store); /* sysfs hotkey bios_enabled ------------------------------------------- */ static ssize_t hotkey_bios_enabled_show(struct device *dev, struct device_attribute *attr, char *buf) { return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_orig_status); } static struct device_attribute dev_attr_hotkey_bios_enabled = __ATTR(hotkey_bios_enabled, S_IRUGO, hotkey_bios_enabled_show, NULL); /* sysfs hotkey bios_mask ---------------------------------------------- */ static ssize_t hotkey_bios_mask_show(struct device *dev, struct device_attribute *attr, char *buf) { return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_orig_mask); } static struct device_attribute dev_attr_hotkey_bios_mask = __ATTR(hotkey_bios_mask, S_IRUGO, hotkey_bios_mask_show, NULL); /* sysfs hotkey all_mask ----------------------------------------------- */ static ssize_t hotkey_all_mask_show(struct device *dev, struct device_attribute *attr, char *buf) { return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_all_mask | hotkey_source_mask); } static struct device_attribute dev_attr_hotkey_all_mask = __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL); /* sysfs hotkey recommended_mask --------------------------------------- */ static ssize_t hotkey_recommended_mask_show(struct device *dev, struct device_attribute *attr, char *buf) { return snprintf(buf, PAGE_SIZE, "0x%08x\n", (hotkey_all_mask | hotkey_source_mask) & ~hotkey_reserved_mask); } static struct device_attribute dev_attr_hotkey_recommended_mask = __ATTR(hotkey_recommended_mask, S_IRUGO, hotkey_recommended_mask_show, NULL); #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL /* sysfs hotkey hotkey_source_mask ------------------------------------- */ static ssize_t hotkey_source_mask_show(struct device *dev, struct device_attribute *attr, char *buf) { return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask); } static ssize_t hotkey_source_mask_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { unsigned long t; if (parse_strtoul(buf, 0xffffffffUL, &t) || ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0)) return -EINVAL; if (mutex_lock_interruptible(&hotkey_mutex)) return -ERESTARTSYS; HOTKEY_CONFIG_CRITICAL_START hotkey_source_mask = t; HOTKEY_CONFIG_CRITICAL_END hotkey_poll_setup(1); mutex_unlock(&hotkey_mutex); return count; } static struct device_attribute dev_attr_hotkey_source_mask = __ATTR(hotkey_source_mask, S_IWUSR | S_IRUGO, hotkey_source_mask_show, hotkey_source_mask_store); /* sysfs hotkey hotkey_poll_freq --------------------------------------- */ static ssize_t hotkey_poll_freq_show(struct device *dev, struct device_attribute *attr, char *buf) { return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq); } static ssize_t hotkey_poll_freq_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { unsigned long t; if (parse_strtoul(buf, 25, &t)) return -EINVAL; if (mutex_lock_interruptible(&hotkey_mutex)) return -ERESTARTSYS; hotkey_poll_freq = t; hotkey_poll_setup(1); mutex_unlock(&hotkey_mutex); return count; } static struct device_attribute dev_attr_hotkey_poll_freq = __ATTR(hotkey_poll_freq, S_IWUSR | S_IRUGO, hotkey_poll_freq_show, hotkey_poll_freq_store); #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ /* sysfs hotkey radio_sw (pollable) ------------------------------------ */ static ssize_t hotkey_radio_sw_show(struct device *dev, struct device_attribute *attr, char *buf) { int res, s; res = hotkey_get_wlsw(&s); if (res < 0) return res; return snprintf(buf, PAGE_SIZE, "%d\n", !!s); } static struct device_attribute dev_attr_hotkey_radio_sw = __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); static void hotkey_radio_sw_notify_change(void) { if (tp_features.hotkey_wlsw) sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, "hotkey_radio_sw"); } /* sysfs hotkey tablet mode (pollable) --------------------------------- */ static ssize_t hotkey_tablet_mode_show(struct device *dev, struct device_attribute *attr, char *buf) { int res, s; res = hotkey_get_tablet_mode(&s); if (res < 0) return res; return snprintf(buf, PAGE_SIZE, "%d\n", !!s); } static struct device_attribute dev_attr_hotkey_tablet_mode = __ATTR(hotkey_tablet_mode, S_IRUGO, hotkey_tablet_mode_show, NULL); static void hotkey_tablet_mode_notify_change(void) { if (tp_features.hotkey_tablet) sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, "hotkey_tablet_mode"); } /* sysfs hotkey report_mode -------------------------------------------- */ static ssize_t hotkey_report_mode_show(struct device *dev, struct device_attribute *attr, char *buf) { return snprintf(buf, PAGE_SIZE, "%d\n", (hotkey_report_mode != 0) ? hotkey_report_mode : 1); } static struct device_attribute dev_attr_hotkey_report_mode = __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL); /* sysfs wakeup reason (pollable) -------------------------------------- */ static ssize_t hotkey_wakeup_reason_show(struct device *dev, struct device_attribute *attr, char *buf) { return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason); } static struct device_attribute dev_attr_hotkey_wakeup_reason = __ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL); static void hotkey_wakeup_reason_notify_change(void) { if (tp_features.hotkey_mask) sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, "wakeup_reason"); } /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */ static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev, struct device_attribute *attr, char *buf) { return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack); } static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete = __ATTR(wakeup_hotunplug_complete, S_IRUGO, hotkey_wakeup_hotunplug_complete_show, NULL); static void hotkey_wakeup_hotunplug_complete_notify_change(void) { if (tp_features.hotkey_mask) sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, "wakeup_hotunplug_complete"); } /* --------------------------------------------------------------------- */ static struct attribute *hotkey_attributes[] __initdata = { &dev_attr_hotkey_enable.attr, &dev_attr_hotkey_bios_enabled.attr, &dev_attr_hotkey_report_mode.attr, #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL &dev_attr_hotkey_mask.attr, &dev_attr_hotkey_all_mask.attr, &dev_attr_hotkey_recommended_mask.attr, &dev_attr_hotkey_source_mask.attr, &dev_attr_hotkey_poll_freq.attr, #endif }; static struct attribute *hotkey_mask_attributes[] __initdata = { &dev_attr_hotkey_bios_mask.attr, #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL &dev_attr_hotkey_mask.attr, &dev_attr_hotkey_all_mask.attr, &dev_attr_hotkey_recommended_mask.attr, #endif &dev_attr_hotkey_wakeup_reason.attr, &dev_attr_hotkey_wakeup_hotunplug_complete.attr, }; static void bluetooth_update_rfk(void); static void wan_update_rfk(void); static void tpacpi_send_radiosw_update(void) { int wlsw; /* Sync these BEFORE sending any rfkill events */ if (tp_features.bluetooth) bluetooth_update_rfk(); if (tp_features.wan) wan_update_rfk(); if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw)) { mutex_lock(&tpacpi_inputdev_send_mutex); input_report_switch(tpacpi_inputdev, SW_RFKILL_ALL, !!wlsw); input_sync(tpacpi_inputdev); mutex_unlock(&tpacpi_inputdev_send_mutex); } hotkey_radio_sw_notify_change(); } static void hotkey_exit(void) { #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL hotkey_poll_stop_sync(); #endif if (hotkey_dev_attributes) delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); kfree(hotkey_keycode_map); if (tp_features.hotkey) { dbg_printk(TPACPI_DBG_EXIT, "restoring original hot key mask\n"); /* no short-circuit boolean operator below! */ if ((hotkey_mask_set(hotkey_orig_mask) | hotkey_status_set(hotkey_orig_status)) != 0) printk(TPACPI_ERR "failed to restore hot key mask " "to BIOS defaults\n"); } } static int __init hotkey_init(struct ibm_init_struct *iibm) { /* Requirements for changing the default keymaps: * * 1. Many of the keys are mapped to KEY_RESERVED for very * good reasons. Do not change them unless you have deep * knowledge on the IBM and Lenovo ThinkPad firmware for * the various ThinkPad models. The driver behaves * differently for KEY_RESERVED: such keys have their * hot key mask *unset* in mask_recommended, and also * in the initial hot key mask programmed into the * firmware at driver load time, which means the firm- * ware may react very differently if you change them to * something else; * * 2. You must be subscribed to the linux-thinkpad and * ibm-acpi-devel mailing lists, and you should read the * list archives since 2007 if you want to change the * keymaps. This requirement exists so that you will * know the past history of problems with the thinkpad- * acpi driver keymaps, and also that you will be * listening to any bug reports; * * 3. Do not send thinkpad-acpi specific patches directly to * for merging, *ever*. Send them to the linux-acpi * mailinglist for comments. Merging is to be done only * through acpi-test and the ACPI maintainer. * * 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 = { /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ KEY_FN_F1, KEY_FN_F2, 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, /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ KEY_UNKNOWN, /* 0x0D: FN+INSERT */ KEY_UNKNOWN, /* 0x0E: FN+DELETE */ /* brightness: firmware always reacts to them, unless * X.org did some tricks in the radeon BIOS scratch * registers of *some* models */ KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ KEY_RESERVED, /* 0x10: FN+END (brightness down) */ /* Thinklight: firmware always react to it */ KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ /* Volume: firmware always react to it and reprograms * the built-in *extra* mixer. Never map it to control * another mixer by default. */ KEY_RESERVED, /* 0x14: VOLUME UP */ KEY_RESERVED, /* 0x15: VOLUME DOWN */ KEY_RESERVED, /* 0x16: MUTE */ KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ /* (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 = { /* 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_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND, /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */ KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ KEY_UNKNOWN, /* 0x0D: FN+INSERT */ KEY_UNKNOWN, /* 0x0E: FN+DELETE */ /* These either have to go through ACPI video, or * act like in the IBM ThinkPads, so don't ever * enable them by default */ KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ KEY_RESERVED, /* 0x10: FN+END (brightness down) */ KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ /* Volume: z60/z61, T60 (BIOS version?): firmware always * react to it and reprograms the built-in *extra* mixer. * Never map it to control another mixer by default. * * T60?, T61, R60?, R61: firmware and EC tries to send * these over the regular keyboard, so these are no-ops, * but there are still weird bugs re. MUTE, so do not * change unless you get test reports from all Lenovo * models. May cause the BIOS to interfere with the * HDA mixer. */ KEY_RESERVED, /* 0x14: VOLUME UP */ KEY_RESERVED, /* 0x15: VOLUME DOWN */ KEY_RESERVED, /* 0x16: MUTE */ KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ /* (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]) int res, i; int status; int hkeyv; vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n"); BUG_ON(!tpacpi_inputdev); BUG_ON(tpacpi_inputdev->open != NULL || tpacpi_inputdev->close != NULL); TPACPI_ACPIHANDLE_INIT(hkey); mutex_init(&hotkey_mutex); #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL mutex_init(&hotkey_thread_mutex); mutex_init(&hotkey_thread_data_mutex); #endif /* hotkey not supported on 570 */ tp_features.hotkey = hkey_handle != NULL; vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n", str_supported(tp_features.hotkey)); if (!tp_features.hotkey) return 1; tpacpi_disable_brightness_delay(); hotkey_dev_attributes = create_attr_set(13, NULL); if (!hotkey_dev_attributes) return -ENOMEM; res = add_many_to_attr_set(hotkey_dev_attributes, hotkey_attributes, ARRAY_SIZE(hotkey_attributes)); if (res) goto err_exit; /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking for HKEY interface version 0x100 */ if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { if ((hkeyv >> 8) != 1) { printk(TPACPI_ERR "unknown version of the " "HKEY interface: 0x%x\n", hkeyv); printk(TPACPI_ERR "please report this to %s\n", TPACPI_MAIL); } else { /* * MHKV 0x100 in A31, R40, R40e, * T4x, X31, and later */ tp_features.hotkey_mask = 1; } } vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n", str_supported(tp_features.hotkey_mask)); if (tp_features.hotkey_mask) { if (!acpi_evalf(hkey_handle, &hotkey_all_mask, "MHKA", "qd")) { printk(TPACPI_ERR "missing MHKA handler, " "please report this to %s\n", TPACPI_MAIL); /* FN+F12, FN+F4, FN+F3 */ hotkey_all_mask = 0x080cU; } } /* hotkey_source_mask *must* be zero for * the first hotkey_mask_get */ res = hotkey_status_get(&hotkey_orig_status); if (res) goto err_exit; if (tp_features.hotkey_mask) { res = hotkey_mask_get(); if (res) goto err_exit; hotkey_orig_mask = hotkey_mask; res = add_many_to_attr_set( hotkey_dev_attributes, hotkey_mask_attributes, ARRAY_SIZE(hotkey_mask_attributes)); if (res) goto err_exit; } #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL if (tp_features.hotkey_mask) { hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK & ~hotkey_all_mask; } else { hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK; } vdbg_printk(TPACPI_DBG_INIT, "hotkey source mask 0x%08x, polling freq %d\n", hotkey_source_mask, hotkey_poll_freq); #endif /* Not all thinkpads have a hardware radio switch */ if (acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { tp_features.hotkey_wlsw = 1; printk(TPACPI_INFO "radio switch found; radios are %s\n", enabled(status, 0)); } if (tp_features.hotkey_wlsw) res = add_to_attr_set(hotkey_dev_attributes, &dev_attr_hotkey_radio_sw.attr); /* For X41t, X60t, X61t Tablets... */ if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) { tp_features.hotkey_tablet = 1; printk(TPACPI_INFO "possible tablet mode switch found; " "ThinkPad in %s mode\n", (status & TP_HOTKEY_TABLET_MASK)? "tablet" : "laptop"); res = add_to_attr_set(hotkey_dev_attributes, &dev_attr_hotkey_tablet_mode.attr); } if (!res) res = register_attr_set_with_sysfs( hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); if (res) goto err_exit; /* Set up key map */ hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, GFP_KERNEL); if (!hotkey_keycode_map) { printk(TPACPI_ERR "failed to allocate memory for key map\n"); res = -ENOMEM; goto err_exit; } if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) { dbg_printk(TPACPI_DBG_INIT, "using Lenovo default hot key map\n"); memcpy(hotkey_keycode_map, &lenovo_keycode_map, TPACPI_HOTKEY_MAP_SIZE); } else { dbg_printk(TPACPI_DBG_INIT, "using IBM default hot key map\n"); memcpy(hotkey_keycode_map, &ibm_keycode_map, TPACPI_HOTKEY_MAP_SIZE); } set_bit(EV_KEY, tpacpi_inputdev->evbit); set_bit(EV_MSC, tpacpi_inputdev->evbit); set_bit(MSC_SCAN, tpacpi_inputdev->mscbit); tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE; tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN; tpacpi_inputdev->keycode = hotkey_keycode_map; for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) { if (hotkey_keycode_map[i] != KEY_RESERVED) { set_bit(hotkey_keycode_map[i], tpacpi_inputdev->keybit); } else { if (i < sizeof(hotkey_reserved_mask)*8) hotkey_reserved_mask |= 1 << i; } } if (tp_features.hotkey_wlsw) { set_bit(EV_SW, tpacpi_inputdev->evbit); set_bit(SW_RFKILL_ALL, tpacpi_inputdev->swbit); } if (tp_features.hotkey_tablet) { set_bit(EV_SW, tpacpi_inputdev->evbit); set_bit(SW_TABLET_MODE, tpacpi_inputdev->swbit); } /* Do not issue duplicate brightness change events to * userspace */ if (!tp_features.bright_acpimode) /* update bright_acpimode... */ tpacpi_check_std_acpi_brightness_support(); if (tp_features.bright_acpimode) { printk(TPACPI_INFO "This ThinkPad has standard ACPI backlight " "brightness control, supported by the ACPI " "video driver\n"); printk(TPACPI_NOTICE "Disabling thinkpad-acpi brightness events " "by default...\n"); /* The hotkey_reserved_mask change below is not * necessary while the keys are at KEY_RESERVED in the * default map, but better safe than sorry, leave it * here as a marker of what we have to do, especially * when we finally become able to set this at runtime * on response to X.org requests */ hotkey_reserved_mask |= (1 << TP_ACPI_HOTKEYSCAN_FNHOME) | (1 << TP_ACPI_HOTKEYSCAN_FNEND); } dbg_printk(TPACPI_DBG_INIT, "enabling hot key handling\n"); res = hotkey_status_set(1); if (res) { hotkey_exit(); return res; } res = hotkey_mask_set(((hotkey_all_mask | hotkey_source_mask) & ~hotkey_reserved_mask) | hotkey_orig_mask); if (res < 0 && res != -ENXIO) { hotkey_exit(); return res; } dbg_printk(TPACPI_DBG_INIT, "legacy hot key reporting over procfs %s\n", (hotkey_report_mode < 2) ? "enabled" : "disabled"); tpacpi_inputdev->open = &hotkey_inputdev_open; tpacpi_inputdev->close = &hotkey_inputdev_close; hotkey_poll_setup_safe(1); tpacpi_send_radiosw_update(); tpacpi_input_send_tabletsw(); return 0; err_exit: delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); hotkey_dev_attributes = NULL; return (res < 0)? res : 1; } static void hotkey_notify(struct ibm_struct *ibm, u32 event) { u32 hkey; unsigned int scancode; int send_acpi_ev; int ignore_acpi_ev; int unk_ev; if (event != 0x80) { printk(TPACPI_ERR "unknown HKEY notification event %d\n", event); /* forward it to userspace, maybe it knows how to handle it */ acpi_bus_generate_netlink_event( ibm->acpi->device->pnp.device_class, ibm->acpi->device->dev.bus_id, event, 0); return; } while (1) { if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { printk(TPACPI_ERR "failed to retrieve HKEY event\n"); return; } if (hkey == 0) { /* queue empty */ return; } send_acpi_ev = 1; ignore_acpi_ev = 0; unk_ev = 0; switch (hkey >> 12) { case 1: /* 0x1000-0x1FFF: key presses */ scancode = hkey & 0xfff; if (scancode > 0 && scancode < 0x21) { scancode--; if (!(hotkey_source_mask & (1 << scancode))) { tpacpi_input_send_key(scancode); send_acpi_ev = 0; } else { ignore_acpi_ev = 1; } } else { unk_ev = 1; } break; case 2: /* Wakeup reason */ switch (hkey) { case 0x2304: /* suspend, undock */ case 0x2404: /* hibernation, undock */ hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK; ignore_acpi_ev = 1; break; case 0x2305: /* suspend, bay eject */ case 0x2405: /* hibernation, bay eject */ hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ; ignore_acpi_ev = 1; break; default: unk_ev = 1; } if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) { printk(TPACPI_INFO "woke up due to a hot-unplug " "request...\n"); hotkey_wakeup_reason_notify_change(); } break; case 3: /* bay-related wakeups */ if (hkey == 0x3003) { hotkey_autosleep_ack = 1; printk(TPACPI_INFO "bay ejected\n"); hotkey_wakeup_hotunplug_complete_notify_change(); } else { unk_ev = 1; } break; case 4: /* dock-related wakeups */ if (hkey == 0x4003) { hotkey_autosleep_ack = 1; printk(TPACPI_INFO "undocked\n"); hotkey_wakeup_hotunplug_complete_notify_change(); } else { unk_ev = 1; } break; case 5: /* 0x5000-0x5FFF: human interface helpers */ switch (hkey) { case 0x5010: /* Lenovo new BIOS: brightness changed */ case 0x500b: /* X61t: tablet pen inserted into bay */ case 0x500c: /* X61t: tablet pen removed from bay */ break; case 0x5009: /* X41t-X61t: swivel up (tablet mode) */ case 0x500a: /* X41t-X61t: swivel down (normal mode) */ tpacpi_input_send_tabletsw(); hotkey_tablet_mode_notify_change(); send_acpi_ev = 0; break; case 0x5001: case 0x5002: /* LID switch events. Do not propagate */ ignore_acpi_ev = 1; break; default: unk_ev = 1; } break; case 7: /* 0x7000-0x7FFF: misc */ if (tp_features.hotkey_wlsw && hkey == 0x7000) { tpacpi_send_radiosw_update(); send_acpi_ev = 0; break; } /* fallthrough to default */ default: unk_ev = 1;