2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2009 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #define TPACPI_VERSION "0.22"
25 #define TPACPI_SYSFS_VERSION 0x020200
29 * 2007-10-20 changelog trimmed down
31 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
34 * 2006-11-22 0.13 new maintainer
35 * changelog now lives in git commit history, and will
36 * not be updated further in-file.
38 * 2005-03-17 0.11 support for 600e, 770x
39 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
41 * 2005-01-16 0.9 use MODULE_VERSION
42 * thanks to Henrik Brix Andersen <brix@gentoo.org>
43 * fix parameter passing on module loading
44 * thanks to Rusty Russell <rusty@rustcorp.com.au>
45 * thanks to Jim Radford <radford@blackbean.org>
46 * 2004-11-08 0.8 fix init error case, don't return from a macro
47 * thanks to Chris Wright <chrisw@osdl.org>
50 #include <linux/kernel.h>
51 #include <linux/module.h>
52 #include <linux/init.h>
53 #include <linux/types.h>
54 #include <linux/string.h>
55 #include <linux/list.h>
56 #include <linux/mutex.h>
57 #include <linux/kthread.h>
58 #include <linux/freezer.h>
59 #include <linux/delay.h>
61 #include <linux/nvram.h>
62 #include <linux/proc_fs.h>
63 #include <linux/sysfs.h>
64 #include <linux/backlight.h>
66 #include <linux/platform_device.h>
67 #include <linux/hwmon.h>
68 #include <linux/hwmon-sysfs.h>
69 #include <linux/input.h>
70 #include <linux/leds.h>
71 #include <linux/rfkill.h>
72 #include <asm/uaccess.h>
74 #include <linux/dmi.h>
75 #include <linux/jiffies.h>
76 #include <linux/workqueue.h>
78 #include <acpi/acpi_drivers.h>
80 #include <linux/pci_ids.h>
83 /* ThinkPad CMOS commands */
84 #define TP_CMOS_VOLUME_DOWN 0
85 #define TP_CMOS_VOLUME_UP 1
86 #define TP_CMOS_VOLUME_MUTE 2
87 #define TP_CMOS_BRIGHTNESS_UP 4
88 #define TP_CMOS_BRIGHTNESS_DOWN 5
89 #define TP_CMOS_THINKLIGHT_ON 12
90 #define TP_CMOS_THINKLIGHT_OFF 13
94 TP_NVRAM_ADDR_HK2 = 0x57,
95 TP_NVRAM_ADDR_THINKLIGHT = 0x58,
96 TP_NVRAM_ADDR_VIDEO = 0x59,
97 TP_NVRAM_ADDR_BRIGHTNESS = 0x5e,
98 TP_NVRAM_ADDR_MIXER = 0x60,
101 /* NVRAM bit masks */
103 TP_NVRAM_MASK_HKT_THINKPAD = 0x08,
104 TP_NVRAM_MASK_HKT_ZOOM = 0x20,
105 TP_NVRAM_MASK_HKT_DISPLAY = 0x40,
106 TP_NVRAM_MASK_HKT_HIBERNATE = 0x80,
107 TP_NVRAM_MASK_THINKLIGHT = 0x10,
108 TP_NVRAM_MASK_HKT_DISPEXPND = 0x30,
109 TP_NVRAM_MASK_HKT_BRIGHTNESS = 0x20,
110 TP_NVRAM_MASK_LEVEL_BRIGHTNESS = 0x0f,
111 TP_NVRAM_POS_LEVEL_BRIGHTNESS = 0,
112 TP_NVRAM_MASK_MUTE = 0x40,
113 TP_NVRAM_MASK_HKT_VOLUME = 0x80,
114 TP_NVRAM_MASK_LEVEL_VOLUME = 0x0f,
115 TP_NVRAM_POS_LEVEL_VOLUME = 0,
119 #define TPACPI_ACPI_HKEY_HID "IBM0068"
122 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
123 #define TPACPI_HKEY_INPUT_VERSION 0x4101
125 /* ACPI \WGSV commands */
127 TP_ACPI_WGSV_GET_STATE = 0x01, /* Get state information */
128 TP_ACPI_WGSV_PWR_ON_ON_RESUME = 0x02, /* Resume WWAN powered on */
129 TP_ACPI_WGSV_PWR_OFF_ON_RESUME = 0x03, /* Resume WWAN powered off */
130 TP_ACPI_WGSV_SAVE_STATE = 0x04, /* Save state for S4/S5 */
133 /* TP_ACPI_WGSV_GET_STATE bits */
135 TP_ACPI_WGSV_STATE_WWANEXIST = 0x0001, /* WWAN hw available */
136 TP_ACPI_WGSV_STATE_WWANPWR = 0x0002, /* WWAN radio enabled */
137 TP_ACPI_WGSV_STATE_WWANPWRRES = 0x0004, /* WWAN state at resume */
138 TP_ACPI_WGSV_STATE_WWANBIOSOFF = 0x0008, /* WWAN disabled in BIOS */
139 TP_ACPI_WGSV_STATE_BLTHEXIST = 0x0001, /* BLTH hw available */
140 TP_ACPI_WGSV_STATE_BLTHPWR = 0x0002, /* BLTH radio enabled */
141 TP_ACPI_WGSV_STATE_BLTHPWRRES = 0x0004, /* BLTH state at resume */
142 TP_ACPI_WGSV_STATE_BLTHBIOSOFF = 0x0008, /* BLTH disabled in BIOS */
143 TP_ACPI_WGSV_STATE_UWBEXIST = 0x0010, /* UWB hw available */
144 TP_ACPI_WGSV_STATE_UWBPWR = 0x0020, /* UWB radio enabled */
147 /****************************************************************************
151 #define TPACPI_NAME "thinkpad"
152 #define TPACPI_DESC "ThinkPad ACPI Extras"
153 #define TPACPI_FILE TPACPI_NAME "_acpi"
154 #define TPACPI_URL "http://ibm-acpi.sf.net/"
155 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
157 #define TPACPI_PROC_DIR "ibm"
158 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
159 #define TPACPI_DRVR_NAME TPACPI_FILE
160 #define TPACPI_DRVR_SHORTNAME "tpacpi"
161 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
163 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
164 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
166 #define TPACPI_MAX_ACPI_ARGS 3
168 /* rfkill switches */
170 TPACPI_RFK_BLUETOOTH_SW_ID = 0,
171 TPACPI_RFK_WWAN_SW_ID,
172 TPACPI_RFK_UWB_SW_ID,
176 #define TPACPI_LOG TPACPI_FILE ": "
177 #define TPACPI_EMERG KERN_EMERG TPACPI_LOG
178 #define TPACPI_ALERT KERN_ALERT TPACPI_LOG
179 #define TPACPI_CRIT KERN_CRIT TPACPI_LOG
180 #define TPACPI_ERR KERN_ERR TPACPI_LOG
181 #define TPACPI_WARN KERN_WARNING TPACPI_LOG
182 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
183 #define TPACPI_INFO KERN_INFO TPACPI_LOG
184 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
186 /* Debugging printk groups */
187 #define TPACPI_DBG_ALL 0xffff
188 #define TPACPI_DBG_INIT 0x0001
189 #define TPACPI_DBG_EXIT 0x0002
191 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
192 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
193 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
196 /****************************************************************************
197 * Driver-wide structs and misc. variables
202 struct tp_acpi_drv_struct {
203 const struct acpi_device_id *hid;
204 struct acpi_driver *driver;
206 void (*notify) (struct ibm_struct *, u32);
209 struct acpi_device *device;
215 int (*read) (char *);
216 int (*write) (char *);
218 void (*resume) (void);
219 void (*suspend) (pm_message_t state);
220 void (*shutdown) (void);
222 struct list_head all_drivers;
224 struct tp_acpi_drv_struct *acpi;
227 u8 acpi_driver_registered:1;
228 u8 acpi_notify_installed:1;
235 struct ibm_init_struct {
238 int (*init) (struct ibm_init_struct *);
239 struct ibm_struct *data;
243 #ifdef CONFIG_THINKPAD_ACPI_BAY
256 u32 bright_16levels:1;
257 u32 bright_acpimode:1;
260 u32 fan_ctrl_status_undef:1;
261 u32 input_device_registered:1;
262 u32 platform_drv_registered:1;
263 u32 platform_drv_attrs_registered:1;
264 u32 sensors_pdrv_registered:1;
265 u32 sensors_pdrv_attrs_registered:1;
266 u32 sensors_pdev_attrs_registered:1;
267 u32 hotkey_poll_active:1;
271 u16 hotkey_mask_ff:1;
272 u16 bright_cmos_ec_unsync:1;
275 struct thinkpad_id_data {
276 unsigned int vendor; /* ThinkPad vendor:
277 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
279 char *bios_version_str; /* Something like 1ZET51WW (1.03z) */
280 char *ec_version_str; /* Something like 1ZHT51WW-1.04a */
282 u16 bios_model; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */
285 char *model_str; /* ThinkPad T43 */
286 char *nummodel_str; /* 9384A9C for a 9384-A9C model */
288 static struct thinkpad_id_data thinkpad_id;
291 TPACPI_LIFE_INIT = 0,
296 static int experimental;
297 static u32 dbg_level;
299 static struct workqueue_struct *tpacpi_wq;
301 /* Special LED class that can defer work */
302 struct tpacpi_led_classdev {
303 struct led_classdev led_classdev;
304 struct work_struct work;
305 enum led_brightness new_brightness;
309 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
310 static int dbg_wlswemul;
311 static int tpacpi_wlsw_emulstate;
312 static int dbg_bluetoothemul;
313 static int tpacpi_bluetooth_emulstate;
314 static int dbg_wwanemul;
315 static int tpacpi_wwan_emulstate;
316 static int dbg_uwbemul;
317 static int tpacpi_uwb_emulstate;
321 /*************************************************************************
325 #define dbg_printk(a_dbg_level, format, arg...) \
326 do { if (dbg_level & (a_dbg_level)) \
327 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
330 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
331 #define vdbg_printk dbg_printk
332 static const char *str_supported(int is_supported);
334 #define vdbg_printk(a_dbg_level, format, arg...) \
339 /****************************************************************************
340 ****************************************************************************
342 * ACPI Helpers and device model
344 ****************************************************************************
345 ****************************************************************************/
347 /*************************************************************************
351 static acpi_handle root_handle;
353 #define TPACPI_HANDLE(object, parent, paths...) \
354 static acpi_handle object##_handle; \
355 static acpi_handle *object##_parent = &parent##_handle; \
356 static char *object##_path; \
357 static char *object##_paths[] = { paths }
359 TPACPI_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
360 "\\_SB.PCI.ISA.EC", /* 570 */
361 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
362 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
363 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
364 "\\_SB.PCI0.ICH3.EC0", /* R31 */
365 "\\_SB.PCI0.LPC.EC", /* all others */
368 TPACPI_HANDLE(ecrd, ec, "ECRD"); /* 570 */
369 TPACPI_HANDLE(ecwr, ec, "ECWR"); /* 570 */
371 TPACPI_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, */
373 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
374 "\\CMS", /* R40, R40e */
377 TPACPI_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
378 "^HKEY", /* R30, R31 */
379 "HKEY", /* all others */
382 TPACPI_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */
383 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
384 "\\_SB.PCI0.VID0", /* 770e */
385 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
386 "\\_SB.PCI0.AGP.VID", /* all others */
390 /*************************************************************************
394 static int acpi_evalf(acpi_handle handle,
395 void *res, char *method, char *fmt, ...)
398 struct acpi_object_list params;
399 union acpi_object in_objs[TPACPI_MAX_ACPI_ARGS];
400 struct acpi_buffer result, *resultp;
401 union acpi_object out_obj;
409 printk(TPACPI_ERR "acpi_evalf() called with empty format\n");
422 params.pointer = &in_objs[0];
429 in_objs[params.count].integer.value = va_arg(ap, int);
430 in_objs[params.count++].type = ACPI_TYPE_INTEGER;
432 /* add more types as needed */
434 printk(TPACPI_ERR "acpi_evalf() called "
435 "with invalid format character '%c'\n", c);
441 if (res_type != 'v') {
442 result.length = sizeof(out_obj);
443 result.pointer = &out_obj;
448 status = acpi_evaluate_object(handle, method, ¶ms, resultp);
453 *(int *)res = out_obj.integer.value;
454 success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER;
457 success = status == AE_OK;
459 /* add more types as needed */
461 printk(TPACPI_ERR "acpi_evalf() called "
462 "with invalid format character '%c'\n", res_type);
466 if (!success && !quiet)
467 printk(TPACPI_ERR "acpi_evalf(%s, %s, ...) failed: %d\n",
468 method, fmt0, status);
473 static int acpi_ec_read(int i, u8 *p)
478 if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i))
482 if (ec_read(i, p) < 0)
489 static int acpi_ec_write(int i, u8 v)
492 if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v))
495 if (ec_write(i, v) < 0)
502 #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY)
503 static int _sta(acpi_handle handle)
507 if (!handle || !acpi_evalf(handle, &status, "_STA", "d"))
514 static int issue_thinkpad_cmos_command(int cmos_cmd)
519 if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd))
525 /*************************************************************************
529 #define TPACPI_ACPIHANDLE_INIT(object) \
530 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
531 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
533 static void drv_acpi_handle_init(char *name,
534 acpi_handle *handle, acpi_handle parent,
535 char **paths, int num_paths, char **path)
540 vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n",
543 for (i = 0; i < num_paths; i++) {
544 status = acpi_get_handle(parent, paths[i], handle);
545 if (ACPI_SUCCESS(status)) {
547 dbg_printk(TPACPI_DBG_INIT,
548 "Found ACPI handle %s for %s\n",
554 vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n",
559 static void dispatch_acpi_notify(acpi_handle handle, u32 event, void *data)
561 struct ibm_struct *ibm = data;
563 if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING)
566 if (!ibm || !ibm->acpi || !ibm->acpi->notify)
569 ibm->acpi->notify(ibm, event);
572 static int __init setup_acpi_notify(struct ibm_struct *ibm)
579 if (!*ibm->acpi->handle)
582 vdbg_printk(TPACPI_DBG_INIT,
583 "setting up ACPI notify for %s\n", ibm->name);
585 rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device);
587 printk(TPACPI_ERR "acpi_bus_get_device(%s) failed: %d\n",
592 ibm->acpi->device->driver_data = ibm;
593 sprintf(acpi_device_class(ibm->acpi->device), "%s/%s",
594 TPACPI_ACPI_EVENT_PREFIX,
597 status = acpi_install_notify_handler(*ibm->acpi->handle,
598 ibm->acpi->type, dispatch_acpi_notify, ibm);
599 if (ACPI_FAILURE(status)) {
600 if (status == AE_ALREADY_EXISTS) {
602 "another device driver is already "
603 "handling %s events\n", ibm->name);
606 "acpi_install_notify_handler(%s) failed: %d\n",
611 ibm->flags.acpi_notify_installed = 1;
615 static int __init tpacpi_device_add(struct acpi_device *device)
620 static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
624 dbg_printk(TPACPI_DBG_INIT,
625 "registering %s as an ACPI driver\n", ibm->name);
629 ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
630 if (!ibm->acpi->driver) {
632 "failed to allocate memory for ibm->acpi->driver\n");
636 sprintf(ibm->acpi->driver->name, "%s_%s", TPACPI_NAME, ibm->name);
637 ibm->acpi->driver->ids = ibm->acpi->hid;
639 ibm->acpi->driver->ops.add = &tpacpi_device_add;
641 rc = acpi_bus_register_driver(ibm->acpi->driver);
643 printk(TPACPI_ERR "acpi_bus_register_driver(%s) failed: %d\n",
645 kfree(ibm->acpi->driver);
646 ibm->acpi->driver = NULL;
648 ibm->flags.acpi_driver_registered = 1;
654 /****************************************************************************
655 ****************************************************************************
659 ****************************************************************************
660 ****************************************************************************/
662 static int dispatch_procfs_read(char *page, char **start, off_t off,
663 int count, int *eof, void *data)
665 struct ibm_struct *ibm = data;
668 if (!ibm || !ibm->read)
671 len = ibm->read(page);
675 if (len <= off + count)
687 static int dispatch_procfs_write(struct file *file,
688 const char __user *userbuf,
689 unsigned long count, void *data)
691 struct ibm_struct *ibm = data;
695 if (!ibm || !ibm->write)
698 kernbuf = kmalloc(count + 2, GFP_KERNEL);
702 if (copy_from_user(kernbuf, userbuf, count)) {
708 strcat(kernbuf, ",");
709 ret = ibm->write(kernbuf);
718 static char *next_cmd(char **cmds)
723 while ((end = strchr(start, ',')) && end == start)
735 /****************************************************************************
736 ****************************************************************************
738 * Device model: input, hwmon and platform
740 ****************************************************************************
741 ****************************************************************************/
743 static struct platform_device *tpacpi_pdev;
744 static struct platform_device *tpacpi_sensors_pdev;
745 static struct device *tpacpi_hwmon;
746 static struct input_dev *tpacpi_inputdev;
747 static struct mutex tpacpi_inputdev_send_mutex;
748 static LIST_HEAD(tpacpi_all_drivers);
750 static int tpacpi_suspend_handler(struct platform_device *pdev,
753 struct ibm_struct *ibm, *itmp;
755 list_for_each_entry_safe(ibm, itmp,
759 (ibm->suspend)(state);
765 static int tpacpi_resume_handler(struct platform_device *pdev)
767 struct ibm_struct *ibm, *itmp;
769 list_for_each_entry_safe(ibm, itmp,
779 static void tpacpi_shutdown_handler(struct platform_device *pdev)
781 struct ibm_struct *ibm, *itmp;
783 list_for_each_entry_safe(ibm, itmp,
791 static struct platform_driver tpacpi_pdriver = {
793 .name = TPACPI_DRVR_NAME,
794 .owner = THIS_MODULE,
796 .suspend = tpacpi_suspend_handler,
797 .resume = tpacpi_resume_handler,
798 .shutdown = tpacpi_shutdown_handler,
801 static struct platform_driver tpacpi_hwmon_pdriver = {
803 .name = TPACPI_HWMON_DRVR_NAME,
804 .owner = THIS_MODULE,
808 /*************************************************************************
809 * sysfs support helpers
812 struct attribute_set {
813 unsigned int members, max_members;
814 struct attribute_group group;
817 struct attribute_set_obj {
818 struct attribute_set s;
820 } __attribute__((packed));
822 static struct attribute_set *create_attr_set(unsigned int max_members,
825 struct attribute_set_obj *sobj;
827 if (max_members == 0)
830 /* Allocates space for implicit NULL at the end too */
831 sobj = kzalloc(sizeof(struct attribute_set_obj) +
832 max_members * sizeof(struct attribute *),
836 sobj->s.max_members = max_members;
837 sobj->s.group.attrs = &sobj->a;
838 sobj->s.group.name = name;
843 #define destroy_attr_set(_set) \
846 /* not multi-threaded safe, use it in a single thread per set */
847 static int add_to_attr_set(struct attribute_set *s, struct attribute *attr)
852 if (s->members >= s->max_members)
855 s->group.attrs[s->members] = attr;
861 static int add_many_to_attr_set(struct attribute_set *s,
862 struct attribute **attr,
867 for (i = 0; i < count; i++) {
868 res = add_to_attr_set(s, attr[i]);
876 static void delete_attr_set(struct attribute_set *s, struct kobject *kobj)
878 sysfs_remove_group(kobj, &s->group);
882 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
883 sysfs_create_group(_kobj, &_attr_set->group)
885 static int parse_strtoul(const char *buf,
886 unsigned long max, unsigned long *value)
890 while (*buf && isspace(*buf))
892 *value = simple_strtoul(buf, &endp, 0);
893 while (*endp && isspace(*endp))
895 if (*endp || *value > max)
901 static void tpacpi_disable_brightness_delay(void)
903 if (acpi_evalf(hkey_handle, NULL, "PWMS", "qvd", 0))
905 "ACPI backlight control delay disabled\n");
908 static int __init tpacpi_query_bcl_levels(acpi_handle handle)
910 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
911 union acpi_object *obj;
914 if (ACPI_SUCCESS(acpi_evaluate_object(handle, NULL, NULL, &buffer))) {
915 obj = (union acpi_object *)buffer.pointer;
916 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
917 printk(TPACPI_ERR "Unknown _BCL data, "
918 "please report this to %s\n", TPACPI_MAIL);
921 rc = obj->package.count;
927 kfree(buffer.pointer);
931 static acpi_status __init tpacpi_acpi_walk_find_bcl(acpi_handle handle,
932 u32 lvl, void *context, void **rv)
934 char name[ACPI_PATH_SEGMENT_LENGTH];
935 struct acpi_buffer buffer = { sizeof(name), &name };
937 if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) &&
938 !strncmp("_BCL", name, sizeof(name) - 1)) {
940 **(int **)rv = tpacpi_query_bcl_levels(handle);
941 return AE_CTRL_TERMINATE;
948 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
950 static int __init tpacpi_check_std_acpi_brightness_support(void)
954 void *bcl_ptr = &bcl_levels;
957 TPACPI_ACPIHANDLE_INIT(vid);
963 * Search for a _BCL method, and execute it. This is safe on all
964 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
965 * BIOS in ACPI backlight control mode. We do NOT have to care
966 * about calling the _BCL method in an enabled video device, any
967 * will do for our purposes.
970 status = acpi_walk_namespace(ACPI_TYPE_METHOD, vid_handle, 3,
971 tpacpi_acpi_walk_find_bcl, NULL,
974 if (ACPI_SUCCESS(status) && bcl_levels > 2) {
975 tp_features.bright_acpimode = 1;
976 return (bcl_levels - 2);
982 static int __init tpacpi_new_rfkill(const unsigned int id,
984 const enum rfkill_type rfktype,
986 const bool set_default,
987 int (*toggle_radio)(void *, enum rfkill_state),
988 int (*get_state)(void *, enum rfkill_state *))
991 enum rfkill_state initial_state = RFKILL_STATE_SOFT_BLOCKED;
993 res = get_state(NULL, &initial_state);
996 "failed to read initial state for %s, error %d; "
997 "will turn radio off\n", name, res);
998 } else if (set_default) {
999 /* try to set the initial state as the default for the rfkill
1000 * type, since we ask the firmware to preserve it across S5 in
1002 rfkill_set_default(rfktype,
1003 (initial_state == RFKILL_STATE_UNBLOCKED) ?
1004 RFKILL_STATE_UNBLOCKED :
1005 RFKILL_STATE_SOFT_BLOCKED);
1008 *rfk = rfkill_allocate(&tpacpi_pdev->dev, rfktype);
1011 "failed to allocate memory for rfkill class\n");
1015 (*rfk)->name = name;
1016 (*rfk)->get_state = get_state;
1017 (*rfk)->toggle_radio = toggle_radio;
1018 (*rfk)->state = initial_state;
1020 res = rfkill_register(*rfk);
1023 "failed to register %s rfkill switch: %d\n",
1033 /*************************************************************************
1034 * thinkpad-acpi driver attributes
1037 /* interface_version --------------------------------------------------- */
1038 static ssize_t tpacpi_driver_interface_version_show(
1039 struct device_driver *drv,
1042 return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION);
1045 static DRIVER_ATTR(interface_version, S_IRUGO,
1046 tpacpi_driver_interface_version_show, NULL);
1048 /* debug_level --------------------------------------------------------- */
1049 static ssize_t tpacpi_driver_debug_show(struct device_driver *drv,
1052 return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level);
1055 static ssize_t tpacpi_driver_debug_store(struct device_driver *drv,
1056 const char *buf, size_t count)
1060 if (parse_strtoul(buf, 0xffff, &t))
1068 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
1069 tpacpi_driver_debug_show, tpacpi_driver_debug_store);
1071 /* version ------------------------------------------------------------- */
1072 static ssize_t tpacpi_driver_version_show(struct device_driver *drv,
1075 return snprintf(buf, PAGE_SIZE, "%s v%s\n",
1076 TPACPI_DESC, TPACPI_VERSION);
1079 static DRIVER_ATTR(version, S_IRUGO,
1080 tpacpi_driver_version_show, NULL);
1082 /* --------------------------------------------------------------------- */
1084 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1086 static void tpacpi_send_radiosw_update(void);
1088 /* wlsw_emulstate ------------------------------------------------------ */
1089 static ssize_t tpacpi_driver_wlsw_emulstate_show(struct device_driver *drv,
1092 return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wlsw_emulstate);
1095 static ssize_t tpacpi_driver_wlsw_emulstate_store(struct device_driver *drv,
1096 const char *buf, size_t count)
1100 if (parse_strtoul(buf, 1, &t))
1103 if (tpacpi_wlsw_emulstate != t) {
1104 tpacpi_wlsw_emulstate = !!t;
1105 tpacpi_send_radiosw_update();
1107 tpacpi_wlsw_emulstate = !!t;
1112 static DRIVER_ATTR(wlsw_emulstate, S_IWUSR | S_IRUGO,
1113 tpacpi_driver_wlsw_emulstate_show,
1114 tpacpi_driver_wlsw_emulstate_store);
1116 /* bluetooth_emulstate ------------------------------------------------- */
1117 static ssize_t tpacpi_driver_bluetooth_emulstate_show(
1118 struct device_driver *drv,
1121 return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_bluetooth_emulstate);
1124 static ssize_t tpacpi_driver_bluetooth_emulstate_store(
1125 struct device_driver *drv,
1126 const char *buf, size_t count)
1130 if (parse_strtoul(buf, 1, &t))
1133 tpacpi_bluetooth_emulstate = !!t;
1138 static DRIVER_ATTR(bluetooth_emulstate, S_IWUSR | S_IRUGO,
1139 tpacpi_driver_bluetooth_emulstate_show,
1140 tpacpi_driver_bluetooth_emulstate_store);
1142 /* wwan_emulstate ------------------------------------------------- */
1143 static ssize_t tpacpi_driver_wwan_emulstate_show(
1144 struct device_driver *drv,
1147 return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wwan_emulstate);
1150 static ssize_t tpacpi_driver_wwan_emulstate_store(
1151 struct device_driver *drv,
1152 const char *buf, size_t count)
1156 if (parse_strtoul(buf, 1, &t))
1159 tpacpi_wwan_emulstate = !!t;
1164 static DRIVER_ATTR(wwan_emulstate, S_IWUSR | S_IRUGO,
1165 tpacpi_driver_wwan_emulstate_show,
1166 tpacpi_driver_wwan_emulstate_store);
1168 /* uwb_emulstate ------------------------------------------------- */
1169 static ssize_t tpacpi_driver_uwb_emulstate_show(
1170 struct device_driver *drv,
1173 return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_uwb_emulstate);
1176 static ssize_t tpacpi_driver_uwb_emulstate_store(
1177 struct device_driver *drv,
1178 const char *buf, size_t count)
1182 if (parse_strtoul(buf, 1, &t))
1185 tpacpi_uwb_emulstate = !!t;
1190 static DRIVER_ATTR(uwb_emulstate, S_IWUSR | S_IRUGO,
1191 tpacpi_driver_uwb_emulstate_show,
1192 tpacpi_driver_uwb_emulstate_store);
1195 /* --------------------------------------------------------------------- */
1197 static struct driver_attribute *tpacpi_driver_attributes[] = {
1198 &driver_attr_debug_level, &driver_attr_version,
1199 &driver_attr_interface_version,
1202 static int __init tpacpi_create_driver_attributes(struct device_driver *drv)
1208 while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) {
1209 res = driver_create_file(drv, tpacpi_driver_attributes[i]);
1213 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1214 if (!res && dbg_wlswemul)
1215 res = driver_create_file(drv, &driver_attr_wlsw_emulstate);
1216 if (!res && dbg_bluetoothemul)
1217 res = driver_create_file(drv, &driver_attr_bluetooth_emulstate);
1218 if (!res && dbg_wwanemul)
1219 res = driver_create_file(drv, &driver_attr_wwan_emulstate);
1220 if (!res && dbg_uwbemul)
1221 res = driver_create_file(drv, &driver_attr_uwb_emulstate);
1227 static void tpacpi_remove_driver_attributes(struct device_driver *drv)
1231 for (i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++)
1232 driver_remove_file(drv, tpacpi_driver_attributes[i]);
1234 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1235 driver_remove_file(drv, &driver_attr_wlsw_emulstate);
1236 driver_remove_file(drv, &driver_attr_bluetooth_emulstate);
1237 driver_remove_file(drv, &driver_attr_wwan_emulstate);
1238 driver_remove_file(drv, &driver_attr_uwb_emulstate);
1242 /****************************************************************************
1243 ****************************************************************************
1247 ****************************************************************************
1248 ****************************************************************************/
1250 /*************************************************************************
1251 * thinkpad-acpi init subdriver
1254 static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm)
1256 printk(TPACPI_INFO "%s v%s\n", TPACPI_DESC, TPACPI_VERSION);
1257 printk(TPACPI_INFO "%s\n", TPACPI_URL);
1259 printk(TPACPI_INFO "ThinkPad BIOS %s, EC %s\n",
1260 (thinkpad_id.bios_version_str) ?
1261 thinkpad_id.bios_version_str : "unknown",
1262 (thinkpad_id.ec_version_str) ?
1263 thinkpad_id.ec_version_str : "unknown");
1265 if (thinkpad_id.vendor && thinkpad_id.model_str)
1266 printk(TPACPI_INFO "%s %s, model %s\n",
1267 (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ?
1268 "IBM" : ((thinkpad_id.vendor ==
1269 PCI_VENDOR_ID_LENOVO) ?
1270 "Lenovo" : "Unknown vendor"),
1271 thinkpad_id.model_str,
1272 (thinkpad_id.nummodel_str) ?
1273 thinkpad_id.nummodel_str : "unknown");
1278 static int thinkpad_acpi_driver_read(char *p)
1282 len += sprintf(p + len, "driver:\t\t%s\n", TPACPI_DESC);
1283 len += sprintf(p + len, "version:\t%s\n", TPACPI_VERSION);
1288 static struct ibm_struct thinkpad_acpi_driver_data = {
1290 .read = thinkpad_acpi_driver_read,
1293 /*************************************************************************
1297 enum { /* hot key scan codes (derived from ACPI DSDT) */
1298 TP_ACPI_HOTKEYSCAN_FNF1 = 0,
1299 TP_ACPI_HOTKEYSCAN_FNF2,
1300 TP_ACPI_HOTKEYSCAN_FNF3,
1301 TP_ACPI_HOTKEYSCAN_FNF4,
1302 TP_ACPI_HOTKEYSCAN_FNF5,
1303 TP_ACPI_HOTKEYSCAN_FNF6,
1304 TP_ACPI_HOTKEYSCAN_FNF7,
1305 TP_ACPI_HOTKEYSCAN_FNF8,
1306 TP_ACPI_HOTKEYSCAN_FNF9,
1307 TP_ACPI_HOTKEYSCAN_FNF10,
1308 TP_ACPI_HOTKEYSCAN_FNF11,
1309 TP_ACPI_HOTKEYSCAN_FNF12,
1310 TP_ACPI_HOTKEYSCAN_FNBACKSPACE,
1311 TP_ACPI_HOTKEYSCAN_FNINSERT,
1312 TP_ACPI_HOTKEYSCAN_FNDELETE,
1313 TP_ACPI_HOTKEYSCAN_FNHOME,
1314 TP_ACPI_HOTKEYSCAN_FNEND,
1315 TP_ACPI_HOTKEYSCAN_FNPAGEUP,
1316 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN,
1317 TP_ACPI_HOTKEYSCAN_FNSPACE,
1318 TP_ACPI_HOTKEYSCAN_VOLUMEUP,
1319 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN,
1320 TP_ACPI_HOTKEYSCAN_MUTE,
1321 TP_ACPI_HOTKEYSCAN_THINKPAD,
1324 enum { /* Keys available through NVRAM polling */
1325 TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U,
1326 TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U,
1329 enum { /* Positions of some of the keys in hotkey masks */
1330 TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7,
1331 TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8,
1332 TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12,
1333 TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME,
1334 TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND,
1335 TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP,
1336 TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE,
1337 TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP,
1338 TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN,
1339 TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE,
1340 TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD,
1343 enum { /* NVRAM to ACPI HKEY group map */
1344 TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK |
1345 TP_ACPI_HKEY_ZOOM_MASK |
1346 TP_ACPI_HKEY_DISPSWTCH_MASK |
1347 TP_ACPI_HKEY_HIBERNATE_MASK,
1348 TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK |
1349 TP_ACPI_HKEY_BRGHTDWN_MASK,
1350 TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK |
1351 TP_ACPI_HKEY_VOLDWN_MASK |
1352 TP_ACPI_HKEY_MUTE_MASK,
1355 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1356 struct tp_nvram_state {
1357 u16 thinkpad_toggle:1;
1359 u16 display_toggle:1;
1360 u16 thinklight_toggle:1;
1361 u16 hibernate_toggle:1;
1362 u16 displayexp_toggle:1;
1363 u16 display_state:1;
1364 u16 brightness_toggle:1;
1365 u16 volume_toggle:1;
1368 u8 brightness_level;
1372 static struct task_struct *tpacpi_hotkey_task;
1373 static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */
1374 static int hotkey_poll_freq = 10; /* Hz */
1375 static struct mutex hotkey_thread_mutex;
1376 static struct mutex hotkey_thread_data_mutex;
1377 static unsigned int hotkey_config_change;
1379 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1381 #define hotkey_source_mask 0U
1383 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1385 static struct mutex hotkey_mutex;
1387 static enum { /* Reasons for waking up */
1388 TP_ACPI_WAKEUP_NONE = 0, /* None or unknown */
1389 TP_ACPI_WAKEUP_BAYEJ, /* Bay ejection request */
1390 TP_ACPI_WAKEUP_UNDOCK, /* Undock request */
1391 } hotkey_wakeup_reason;
1393 static int hotkey_autosleep_ack;
1395 static int hotkey_orig_status;
1396 static u32 hotkey_orig_mask;
1397 static u32 hotkey_all_mask;
1398 static u32 hotkey_reserved_mask;
1399 static u32 hotkey_mask;
1401 static unsigned int hotkey_report_mode;
1403 static u16 *hotkey_keycode_map;
1405 static struct attribute_set *hotkey_dev_attributes;
1407 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1408 #define HOTKEY_CONFIG_CRITICAL_START \
1410 mutex_lock(&hotkey_thread_data_mutex); \
1411 hotkey_config_change++; \
1413 #define HOTKEY_CONFIG_CRITICAL_END \
1414 mutex_unlock(&hotkey_thread_data_mutex);
1416 #define HOTKEY_CONFIG_CRITICAL_START
1417 #define HOTKEY_CONFIG_CRITICAL_END
1418 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1420 /* HKEY.MHKG() return bits */
1421 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1423 static int hotkey_get_wlsw(int *status)
1425 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1427 *status = !!tpacpi_wlsw_emulstate;
1431 if (!acpi_evalf(hkey_handle, status, "WLSW", "d"))
1436 static int hotkey_get_tablet_mode(int *status)
1440 if (!acpi_evalf(hkey_handle, &s, "MHKG", "d"))
1443 *status = ((s & TP_HOTKEY_TABLET_MASK) != 0);
1448 * Call with hotkey_mutex held
1450 static int hotkey_mask_get(void)
1454 if (tp_features.hotkey_mask) {
1455 if (!acpi_evalf(hkey_handle, &m, "DHKN", "d"))
1458 hotkey_mask = m | (hotkey_source_mask & hotkey_mask);
1464 * Call with hotkey_mutex held
1466 static int hotkey_mask_set(u32 mask)
1471 if (tp_features.hotkey_mask) {
1472 if (!tp_warned.hotkey_mask_ff &&
1473 (mask == 0xffff || mask == 0xffffff ||
1474 mask == 0xffffffff)) {
1475 tp_warned.hotkey_mask_ff = 1;
1476 printk(TPACPI_NOTICE
1477 "setting the hotkey mask to 0x%08x is likely "
1478 "not the best way to go about it\n", mask);
1479 printk(TPACPI_NOTICE
1480 "please consider using the driver defaults, "
1481 "and refer to up-to-date thinkpad-acpi "
1485 HOTKEY_CONFIG_CRITICAL_START
1486 for (i = 0; i < 32; i++) {
1488 /* enable in firmware mask only keys not in NVRAM
1489 * mode, but enable the key in the cached hotkey_mask
1490 * regardless of mode, or the key will end up
1491 * disabled by hotkey_mask_get() */
1492 if (!acpi_evalf(hkey_handle,
1493 NULL, "MHKM", "vdd", i + 1,
1494 !!((mask & ~hotkey_source_mask) & m))) {
1498 hotkey_mask = (hotkey_mask & ~m) | (mask & m);
1501 HOTKEY_CONFIG_CRITICAL_END
1503 /* hotkey_mask_get must be called unconditionally below */
1504 if (!hotkey_mask_get() && !rc &&
1505 (hotkey_mask & ~hotkey_source_mask) !=
1506 (mask & ~hotkey_source_mask)) {
1507 printk(TPACPI_NOTICE
1508 "requested hot key mask 0x%08x, but "
1509 "firmware forced it to 0x%08x\n",
1513 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1514 HOTKEY_CONFIG_CRITICAL_START
1515 hotkey_mask = mask & hotkey_source_mask;
1516 HOTKEY_CONFIG_CRITICAL_END
1518 if (hotkey_mask != mask) {
1519 printk(TPACPI_NOTICE
1520 "requested hot key mask 0x%08x, "
1521 "forced to 0x%08x (NVRAM poll mask is "
1522 "0x%08x): no firmware mask support\n",
1523 mask, hotkey_mask, hotkey_source_mask);
1528 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1534 static int hotkey_status_get(int *status)
1536 if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
1542 static int hotkey_status_set(int status)
1544 if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
1550 static void tpacpi_input_send_tabletsw(void)
1554 if (tp_features.hotkey_tablet &&
1555 !hotkey_get_tablet_mode(&state)) {
1556 mutex_lock(&tpacpi_inputdev_send_mutex);
1558 input_report_switch(tpacpi_inputdev,
1559 SW_TABLET_MODE, !!state);
1560 input_sync(tpacpi_inputdev);
1562 mutex_unlock(&tpacpi_inputdev_send_mutex);
1566 static void tpacpi_input_send_key(unsigned int scancode)
1568 unsigned int keycode;
1570 keycode = hotkey_keycode_map[scancode];
1572 if (keycode != KEY_RESERVED) {
1573 mutex_lock(&tpacpi_inputdev_send_mutex);
1575 input_report_key(tpacpi_inputdev, keycode, 1);
1576 if (keycode == KEY_UNKNOWN)
1577 input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN,
1579 input_sync(tpacpi_inputdev);
1581 input_report_key(tpacpi_inputdev, keycode, 0);
1582 if (keycode == KEY_UNKNOWN)
1583 input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN,
1585 input_sync(tpacpi_inputdev);
1587 mutex_unlock(&tpacpi_inputdev_send_mutex);
1591 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1592 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver;
1594 static void tpacpi_hotkey_send_key(unsigned int scancode)
1596 tpacpi_input_send_key(scancode);
1597 if (hotkey_report_mode < 2) {
1598 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device,
1599 0x80, 0x1001 + scancode);
1603 static void hotkey_read_nvram(struct tp_nvram_state *n, u32 m)
1607 if (m & TP_NVRAM_HKEY_GROUP_HK2) {
1608 d = nvram_read_byte(TP_NVRAM_ADDR_HK2);
1609 n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD);
1610 n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM);
1611 n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY);
1612 n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE);
1614 if (m & TP_ACPI_HKEY_THNKLGHT_MASK) {
1615 d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT);
1616 n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT);
1618 if (m & TP_ACPI_HKEY_DISPXPAND_MASK) {
1619 d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO);
1620 n->displayexp_toggle =
1621 !!(d & TP_NVRAM_MASK_HKT_DISPEXPND);
1623 if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) {
1624 d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS);
1625 n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS)
1626 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS;
1627 n->brightness_toggle =
1628 !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS);
1630 if (m & TP_NVRAM_HKEY_GROUP_VOLUME) {
1631 d = nvram_read_byte(TP_NVRAM_ADDR_MIXER);
1632 n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME)
1633 >> TP_NVRAM_POS_LEVEL_VOLUME;
1634 n->mute = !!(d & TP_NVRAM_MASK_MUTE);
1635 n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME);
1639 #define TPACPI_COMPARE_KEY(__scancode, __member) \
1641 if ((mask & (1 << __scancode)) && \
1642 oldn->__member != newn->__member) \
1643 tpacpi_hotkey_send_key(__scancode); \
1646 #define TPACPI_MAY_SEND_KEY(__scancode) \
1647 do { if (mask & (1 << __scancode)) \
1648 tpacpi_hotkey_send_key(__scancode); } while (0)
1650 static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
1651 struct tp_nvram_state *newn,
1654 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
1655 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
1656 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
1657 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle);
1659 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle);
1661 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle);
1664 if (oldn->volume_toggle != newn->volume_toggle) {
1665 if (oldn->mute != newn->mute) {
1666 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
1668 if (oldn->volume_level > newn->volume_level) {
1669 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
1670 } else if (oldn->volume_level < newn->volume_level) {
1671 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
1672 } else if (oldn->mute == newn->mute) {
1673 /* repeated key presses that didn't change state */
1675 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
1676 } else if (newn->volume_level != 0) {
1677 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
1679 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
1684 /* handle brightness */
1685 if (oldn->brightness_toggle != newn->brightness_toggle) {
1686 if (oldn->brightness_level < newn->brightness_level) {
1687 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
1688 } else if (oldn->brightness_level > newn->brightness_level) {
1689 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
1691 /* repeated key presses that didn't change state */
1692 if (newn->brightness_level != 0) {
1693 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
1695 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
1701 #undef TPACPI_COMPARE_KEY
1702 #undef TPACPI_MAY_SEND_KEY
1704 static int hotkey_kthread(void *data)
1706 struct tp_nvram_state s[2];
1708 unsigned int si, so;
1710 unsigned int change_detector, must_reset;
1712 mutex_lock(&hotkey_thread_mutex);
1714 if (tpacpi_lifecycle == TPACPI_LIFE_EXITING)
1723 /* Initial state for compares */
1724 mutex_lock(&hotkey_thread_data_mutex);
1725 change_detector = hotkey_config_change;
1726 mask = hotkey_source_mask & hotkey_mask;
1727 mutex_unlock(&hotkey_thread_data_mutex);
1728 hotkey_read_nvram(&s[so], mask);
1730 while (!kthread_should_stop() && hotkey_poll_freq) {
1732 t = 1000/hotkey_poll_freq;
1733 t = msleep_interruptible(t);
1734 if (unlikely(kthread_should_stop()))
1736 must_reset = try_to_freeze();
1737 if (t > 0 && !must_reset)
1740 mutex_lock(&hotkey_thread_data_mutex);
1741 if (must_reset || hotkey_config_change != change_detector) {
1742 /* forget old state on thaw or config change */
1745 change_detector = hotkey_config_change;
1747 mask = hotkey_source_mask & hotkey_mask;
1748 mutex_unlock(&hotkey_thread_data_mutex);
1751 hotkey_read_nvram(&s[si], mask);
1752 if (likely(si != so)) {
1753 hotkey_compare_and_issue_event(&s[so], &s[si],
1763 mutex_unlock(&hotkey_thread_mutex);
1767 static void hotkey_poll_stop_sync(void)
1769 if (tpacpi_hotkey_task) {
1770 if (frozen(tpacpi_hotkey_task) ||
1771 freezing(tpacpi_hotkey_task))
1772 thaw_process(tpacpi_hotkey_task);
1774 kthread_stop(tpacpi_hotkey_task);
1775 tpacpi_hotkey_task = NULL;
1776 mutex_lock(&hotkey_thread_mutex);
1777 /* at this point, the thread did exit */
1778 mutex_unlock(&hotkey_thread_mutex);
1782 /* call with hotkey_mutex held */
1783 static void hotkey_poll_setup(int may_warn)
1785 if ((hotkey_source_mask & hotkey_mask) != 0 &&
1786 hotkey_poll_freq > 0 &&
1787 (tpacpi_inputdev->users > 0 || hotkey_report_mode < 2)) {
1788 if (!tpacpi_hotkey_task) {
1789 tpacpi_hotkey_task = kthread_run(hotkey_kthread,
1790 NULL, TPACPI_NVRAM_KTHREAD_NAME);
1791 if (IS_ERR(tpacpi_hotkey_task)) {
1792 tpacpi_hotkey_task = NULL;
1794 "could not create kernel thread "
1795 "for hotkey polling\n");
1799 hotkey_poll_stop_sync();
1801 hotkey_source_mask != 0 && hotkey_poll_freq == 0) {
1802 printk(TPACPI_NOTICE
1803 "hot keys 0x%08x require polling, "
1804 "which is currently disabled\n",
1805 hotkey_source_mask);
1810 static void hotkey_poll_setup_safe(int may_warn)
1812 mutex_lock(&hotkey_mutex);
1813 hotkey_poll_setup(may_warn);
1814 mutex_unlock(&hotkey_mutex);
1817 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1819 static void hotkey_poll_setup_safe(int __unused)
1823 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1825 static int hotkey_inputdev_open(struct input_dev *dev)
1827 switch (tpacpi_lifecycle) {
1828 case TPACPI_LIFE_INIT:
1830 * hotkey_init will call hotkey_poll_setup_safe
1831 * at the appropriate moment
1834 case TPACPI_LIFE_EXITING:
1836 case TPACPI_LIFE_RUNNING:
1837 hotkey_poll_setup_safe(0);
1841 /* Should only happen if tpacpi_lifecycle is corrupt */
1846 static void hotkey_inputdev_close(struct input_dev *dev)
1848 /* disable hotkey polling when possible */
1849 if (tpacpi_lifecycle == TPACPI_LIFE_RUNNING)
1850 hotkey_poll_setup_safe(0);
1853 /* sysfs hotkey enable ------------------------------------------------- */
1854 static ssize_t hotkey_enable_show(struct device *dev,
1855 struct device_attribute *attr,
1860 res = hotkey_status_get(&status);
1864 return snprintf(buf, PAGE_SIZE, "%d\n", status);
1867 static ssize_t hotkey_enable_store(struct device *dev,
1868 struct device_attribute *attr,
1869 const char *buf, size_t count)
1874 if (parse_strtoul(buf, 1, &t))
1877 res = hotkey_status_set(t);
1879 return (res) ? res : count;
1882 static struct device_attribute dev_attr_hotkey_enable =
1883 __ATTR(hotkey_enable, S_IWUSR | S_IRUGO,
1884 hotkey_enable_show, hotkey_enable_store);
1886 /* sysfs hotkey mask --------------------------------------------------- */
1887 static ssize_t hotkey_mask_show(struct device *dev,
1888 struct device_attribute *attr,
1893 if (mutex_lock_killable(&hotkey_mutex))
1894 return -ERESTARTSYS;
1895 res = hotkey_mask_get();
1896 mutex_unlock(&hotkey_mutex);
1899 res : snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_mask);
1902 static ssize_t hotkey_mask_store(struct device *dev,
1903 struct device_attribute *attr,
1904 const char *buf, size_t count)
1909 if (parse_strtoul(buf, 0xffffffffUL, &t))
1912 if (mutex_lock_killable(&hotkey_mutex))
1913 return -ERESTARTSYS;
1915 res = hotkey_mask_set(t);
1917 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1918 hotkey_poll_setup(1);
1921 mutex_unlock(&hotkey_mutex);
1923 return (res) ? res : count;
1926 static struct device_attribute dev_attr_hotkey_mask =
1927 __ATTR(hotkey_mask, S_IWUSR | S_IRUGO,
1928 hotkey_mask_show, hotkey_mask_store);
1930 /* sysfs hotkey bios_enabled ------------------------------------------- */
1931 static ssize_t hotkey_bios_enabled_show(struct device *dev,
1932 struct device_attribute *attr,
1935 return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_orig_status);
1938 static struct device_attribute dev_attr_hotkey_bios_enabled =
1939 __ATTR(hotkey_bios_enabled, S_IRUGO, hotkey_bios_enabled_show, NULL);
1941 /* sysfs hotkey bios_mask ---------------------------------------------- */
1942 static ssize_t hotkey_bios_mask_show(struct device *dev,
1943 struct device_attribute *attr,
1946 return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_orig_mask);
1949 static struct device_attribute dev_attr_hotkey_bios_mask =
1950 __ATTR(hotkey_bios_mask, S_IRUGO, hotkey_bios_mask_show, NULL);
1952 /* sysfs hotkey all_mask ----------------------------------------------- */
1953 static ssize_t hotkey_all_mask_show(struct device *dev,
1954 struct device_attribute *attr,
1957 return snprintf(buf, PAGE_SIZE, "0x%08x\n",
1958 hotkey_all_mask | hotkey_source_mask);
1961 static struct device_attribute dev_attr_hotkey_all_mask =
1962 __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL);
1964 /* sysfs hotkey recommended_mask --------------------------------------- */
1965 static ssize_t hotkey_recommended_mask_show(struct device *dev,
1966 struct device_attribute *attr,
1969 return snprintf(buf, PAGE_SIZE, "0x%08x\n",
1970 (hotkey_all_mask | hotkey_source_mask)
1971 & ~hotkey_reserved_mask);
1974 static struct device_attribute dev_attr_hotkey_recommended_mask =
1975 __ATTR(hotkey_recommended_mask, S_IRUGO,
1976 hotkey_recommended_mask_show, NULL);
1978 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1980 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
1981 static ssize_t hotkey_source_mask_show(struct device *dev,
1982 struct device_attribute *attr,
1985 return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask);
1988 static ssize_t hotkey_source_mask_store(struct device *dev,
1989 struct device_attribute *attr,
1990 const char *buf, size_t count)
1994 if (parse_strtoul(buf, 0xffffffffUL, &t) ||
1995 ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0))
1998 if (mutex_lock_killable(&hotkey_mutex))
1999 return -ERESTARTSYS;
2001 HOTKEY_CONFIG_CRITICAL_START
2002 hotkey_source_mask = t;
2003 HOTKEY_CONFIG_CRITICAL_END
2005 hotkey_poll_setup(1);
2007 mutex_unlock(&hotkey_mutex);
2012 static struct device_attribute dev_attr_hotkey_source_mask =
2013 __ATTR(hotkey_source_mask, S_IWUSR | S_IRUGO,
2014 hotkey_source_mask_show, hotkey_source_mask_store);
2016 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2017 static ssize_t hotkey_poll_freq_show(struct device *dev,
2018 struct device_attribute *attr,
2021 return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq);
2024 static ssize_t hotkey_poll_freq_store(struct device *dev,
2025 struct device_attribute *attr,
2026 const char *buf, size_t count)
2030 if (parse_strtoul(buf, 25, &t))
2033 if (mutex_lock_killable(&hotkey_mutex))
2034 return -ERESTARTSYS;
2036 hotkey_poll_freq = t;
2038 hotkey_poll_setup(1);
2039 mutex_unlock(&hotkey_mutex);
2044 static struct device_attribute dev_attr_hotkey_poll_freq =
2045 __ATTR(hotkey_poll_freq, S_IWUSR | S_IRUGO,
2046 hotkey_poll_freq_show, hotkey_poll_freq_store);
2048 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2050 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2051 static ssize_t hotkey_radio_sw_show(struct device *dev,
2052 struct device_attribute *attr,
2056 res = hotkey_get_wlsw(&s);
2060 return snprintf(buf, PAGE_SIZE, "%d\n", !!s);
2063 static struct device_attribute dev_attr_hotkey_radio_sw =
2064 __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL);
2066 static void hotkey_radio_sw_notify_change(void)
2068 if (tp_features.hotkey_wlsw)
2069 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL,
2073 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2074 static ssize_t hotkey_tablet_mode_show(struct device *dev,
2075 struct device_attribute *attr,
2079 res = hotkey_get_tablet_mode(&s);
2083 return snprintf(buf, PAGE_SIZE, "%d\n", !!s);
2086 static struct device_attribute dev_attr_hotkey_tablet_mode =
2087 __ATTR(hotkey_tablet_mode, S_IRUGO, hotkey_tablet_mode_show, NULL);
2089 static void hotkey_tablet_mode_notify_change(void)
2091 if (tp_features.hotkey_tablet)
2092 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL,
2093 "hotkey_tablet_mode");
2096 /* sysfs hotkey report_mode -------------------------------------------- */
2097 static ssize_t hotkey_report_mode_show(struct device *dev,
2098 struct device_attribute *attr,
2101 return snprintf(buf, PAGE_SIZE, "%d\n",
2102 (hotkey_report_mode != 0) ? hotkey_report_mode : 1);
2105 static struct device_attribute dev_attr_hotkey_report_mode =
2106 __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL);
2108 /* sysfs wakeup reason (pollable) -------------------------------------- */
2109 static ssize_t hotkey_wakeup_reason_show(struct device *dev,
2110 struct device_attribute *attr,
2113 return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason);
2116 static struct device_attribute dev_attr_hotkey_wakeup_reason =
2117 __ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL);
2119 static void hotkey_wakeup_reason_notify_change(void)
2121 if (tp_features.hotkey_mask)
2122 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL,
2126 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2127 static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev,
2128 struct device_attribute *attr,
2131 return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack);
2134 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete =
2135 __ATTR(wakeup_hotunplug_complete, S_IRUGO,
2136 hotkey_wakeup_hotunplug_complete_show, NULL);
2138 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2140 if (tp_features.hotkey_mask)
2141 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL,
2142 "wakeup_hotunplug_complete");
2145 /* --------------------------------------------------------------------- */
2147 static struct attribute *hotkey_attributes[] __initdata = {
2148 &dev_attr_hotkey_enable.attr,
2149 &dev_attr_hotkey_bios_enabled.attr,
2150 &dev_attr_hotkey_report_mode.attr,
2151 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2152 &dev_attr_hotkey_mask.attr,
2153 &dev_attr_hotkey_all_mask.attr,
2154 &dev_attr_hotkey_recommended_mask.attr,
2155 &dev_attr_hotkey_source_mask.attr,
2156 &dev_attr_hotkey_poll_freq.attr,
2160 static struct attribute *hotkey_mask_attributes[] __initdata = {
2161 &dev_attr_hotkey_bios_mask.attr,
2162 #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2163 &dev_attr_hotkey_mask.attr,
2164 &dev_attr_hotkey_all_mask.attr,
2165 &dev_attr_hotkey_recommended_mask.attr,
2167 &dev_attr_hotkey_wakeup_reason.attr,
2168 &dev_attr_hotkey_wakeup_hotunplug_complete.attr,
2171 static void bluetooth_update_rfk(void);
2172 static void wan_update_rfk(void);
2173 static void uwb_update_rfk(void);
2174 static void tpacpi_send_radiosw_update(void)
2178 /* Sync these BEFORE sending any rfkill events */
2179 if (tp_features.bluetooth)
2180 bluetooth_update_rfk();
2181 if (tp_features.wan)
2183 if (tp_features.uwb)
2186 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw)) {
2187 mutex_lock(&tpacpi_inputdev_send_mutex);
2189 input_report_switch(tpacpi_inputdev,
2190 SW_RFKILL_ALL, !!wlsw);
2191 input_sync(tpacpi_inputdev);
2193 mutex_unlock(&tpacpi_inputdev_send_mutex);
2195 hotkey_radio_sw_notify_change();
2198 static void hotkey_exit(void)
2200 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2201 hotkey_poll_stop_sync();
2204 if (hotkey_dev_attributes)
2205 delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj);
2207 kfree(hotkey_keycode_map);
2209 if (tp_features.hotkey) {
2210 dbg_printk(TPACPI_DBG_EXIT,
2211 "restoring original hot key mask\n");
2212 /* no short-circuit boolean operator below! */
2213 if ((hotkey_mask_set(hotkey_orig_mask) |
2214 hotkey_status_set(hotkey_orig_status)) != 0)
2216 "failed to restore hot key mask "
2217 "to BIOS defaults\n");
2221 static int __init hotkey_init(struct ibm_init_struct *iibm)
2223 /* Requirements for changing the default keymaps:
2225 * 1. Many of the keys are mapped to KEY_RESERVED for very
2226 * good reasons. Do not change them unless you have deep
2227 * knowledge on the IBM and Lenovo ThinkPad firmware for
2228 * the various ThinkPad models. The driver behaves
2229 * differently for KEY_RESERVED: such keys have their
2230 * hot key mask *unset* in mask_recommended, and also
2231 * in the initial hot key mask programmed into the
2232 * firmware at driver load time, which means the firm-
2233 * ware may react very differently if you change them to
2236 * 2. You must be subscribed to the linux-thinkpad and
2237 * ibm-acpi-devel mailing lists, and you should read the
2238 * list archives since 2007 if you want to change the
2239 * keymaps. This requirement exists so that you will
2240 * know the past history of problems with the thinkpad-
2241 * acpi driver keymaps, and also that you will be
2242 * listening to any bug reports;
2244 * 3. Do not send thinkpad-acpi specific patches directly to
2245 * for merging, *ever*. Send them to the linux-acpi
2246 * mailinglist for comments. Merging is to be done only
2247 * through acpi-test and the ACPI maintainer.
2249 * If the above is too much to ask, don't change the keymap.
2250 * Ask the thinkpad-acpi maintainer to do it, instead.
2252 static u16 ibm_keycode_map[] __initdata = {
2253 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2254 KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP,
2255 KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8,
2256 KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND,
2258 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2259 KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */
2260 KEY_UNKNOWN, /* 0x0D: FN+INSERT */
2261 KEY_UNKNOWN, /* 0x0E: FN+DELETE */
2263 /* brightness: firmware always reacts to them, unless
2264 * X.org did some tricks in the radeon BIOS scratch
2265 * registers of *some* models */
2266 KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */
2267 KEY_RESERVED, /* 0x10: FN+END (brightness down) */
2269 /* Thinklight: firmware always react to it */
2270 KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */
2272 KEY_UNKNOWN, /* 0x12: FN+PGDOWN */
2273 KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */
2275 /* Volume: firmware always react to it and reprograms
2276 * the built-in *extra* mixer. Never map it to control
2277 * another mixer by default. */
2278 KEY_RESERVED, /* 0x14: VOLUME UP */
2279 KEY_RESERVED, /* 0x15: VOLUME DOWN */
2280 KEY_RESERVED, /* 0x16: MUTE */
2282 KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2284 /* (assignments unknown, please report if found) */
2285 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
2286 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
2288 static u16 lenovo_keycode_map[] __initdata = {
2289 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2290 KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP,
2291 KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8,
2292 KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND,
2294 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2295 KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */
2296 KEY_UNKNOWN, /* 0x0D: FN+INSERT */
2297 KEY_UNKNOWN, /* 0x0E: FN+DELETE */
2299 /* These either have to go through ACPI video, or
2300 * act like in the IBM ThinkPads, so don't ever
2301 * enable them by default */
2302 KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */
2303 KEY_RESERVED, /* 0x10: FN+END (brightness down) */
2305 KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */
2307 KEY_UNKNOWN, /* 0x12: FN+PGDOWN */
2308 KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */
2310 /* Volume: z60/z61, T60 (BIOS version?): firmware always
2311 * react to it and reprograms the built-in *extra* mixer.
2312 * Never map it to control another mixer by default.
2314 * T60?, T61, R60?, R61: firmware and EC tries to send
2315 * these over the regular keyboard, so these are no-ops,
2316 * but there are still weird bugs re. MUTE, so do not
2317 * change unless you get test reports from all Lenovo
2318 * models. May cause the BIOS to interfere with the
2321 KEY_RESERVED, /* 0x14: VOLUME UP */
2322 KEY_RESERVED, /* 0x15: VOLUME DOWN */
2323 KEY_RESERVED, /* 0x16: MUTE */
2325 KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2327 /* (assignments unknown, please report if found) */
2328 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
2329 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
2332 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2333 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2334 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2340 vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n");
2342 BUG_ON(!tpacpi_inputdev);
2343 BUG_ON(tpacpi_inputdev->open != NULL ||
2344 tpacpi_inputdev->close != NULL);
2346 TPACPI_ACPIHANDLE_INIT(hkey);
2347 mutex_init(&hotkey_mutex);
2349 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2350 mutex_init(&hotkey_thread_mutex);
2351 mutex_init(&hotkey_thread_data_mutex);
2354 /* hotkey not supported on 570 */
2355 tp_features.hotkey = hkey_handle != NULL;
2357 vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n",
2358 str_supported(tp_features.hotkey));
2360 if (!tp_features.hotkey)
2363 tpacpi_disable_brightness_delay();
2365 hotkey_dev_attributes = create_attr_set(13, NULL);
2366 if (!hotkey_dev_attributes)
2368 res = add_many_to_attr_set(hotkey_dev_attributes,
2370 ARRAY_SIZE(hotkey_attributes));
2374 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2375 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2376 for HKEY interface version 0x100 */
2377 if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) {
2378 if ((hkeyv >> 8) != 1) {
2379 printk(TPACPI_ERR "unknown version of the "
2380 "HKEY interface: 0x%x\n", hkeyv);
2381 printk(TPACPI_ERR "please report this to %s\n",
2385 * MHKV 0x100 in A31, R40, R40e,
2386 * T4x, X31, and later
2388 tp_features.hotkey_mask = 1;
2392 vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n",
2393 str_supported(tp_features.hotkey_mask));
2395 if (tp_features.hotkey_mask) {
2396 if (!acpi_evalf(hkey_handle, &hotkey_all_mask,
2399 "missing MHKA handler, "
2400 "please report this to %s\n",
2402 /* FN+F12, FN+F4, FN+F3 */
2403 hotkey_all_mask = 0x080cU;
2407 /* hotkey_source_mask *must* be zero for
2408 * the first hotkey_mask_get */
2409 res = hotkey_status_get(&hotkey_orig_status);
2413 if (tp_features.hotkey_mask) {
2414 res = hotkey_mask_get();
2418 hotkey_orig_mask = hotkey_mask;
2419 res = add_many_to_attr_set(
2420 hotkey_dev_attributes,
2421 hotkey_mask_attributes,
2422 ARRAY_SIZE(hotkey_mask_attributes));
2427 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2428 if (tp_features.hotkey_mask) {
2429 hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK
2432 hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK;
2435 vdbg_printk(TPACPI_DBG_INIT,
2436 "hotkey source mask 0x%08x, polling freq %d\n",
2437 hotkey_source_mask, hotkey_poll_freq);
2440 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2442 tp_features.hotkey_wlsw = 1;
2444 "radio switch emulation enabled\n");
2447 /* Not all thinkpads have a hardware radio switch */
2448 if (acpi_evalf(hkey_handle, &status, "WLSW", "qd")) {
2449 tp_features.hotkey_wlsw = 1;
2451 "radio switch found; radios are %s\n",
2452 enabled(status, 0));
2454 if (tp_features.hotkey_wlsw)
2455 res = add_to_attr_set(hotkey_dev_attributes,
2456 &dev_attr_hotkey_radio_sw.attr);
2458 /* For X41t, X60t, X61t Tablets... */
2459 if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) {
2460 tp_features.hotkey_tablet = 1;
2462 "possible tablet mode switch found; "
2463 "ThinkPad in %s mode\n",
2464 (status & TP_HOTKEY_TABLET_MASK)?
2465 "tablet" : "laptop");
2466 res = add_to_attr_set(hotkey_dev_attributes,
2467 &dev_attr_hotkey_tablet_mode.attr);
2471 res = register_attr_set_with_sysfs(
2472 hotkey_dev_attributes,
2473 &tpacpi_pdev->dev.kobj);
2477 /* Set up key map */
2479 hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE,
2481 if (!hotkey_keycode_map) {
2483 "failed to allocate memory for key map\n");
2488 if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) {
2489 dbg_printk(TPACPI_DBG_INIT,
2490 "using Lenovo default hot key map\n");
2491 memcpy(hotkey_keycode_map, &lenovo_keycode_map,
2492 TPACPI_HOTKEY_MAP_SIZE);
2494 dbg_printk(TPACPI_DBG_INIT,
2495 "using IBM default hot key map\n");
2496 memcpy(hotkey_keycode_map, &ibm_keycode_map,
2497 TPACPI_HOTKEY_MAP_SIZE);
2500 set_bit(EV_KEY, tpacpi_inputdev->evbit);
2501 set_bit(EV_MSC, tpacpi_inputdev->evbit);
2502 set_bit(MSC_SCAN, tpacpi_inputdev->mscbit);
2503 tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE;
2504 tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN;
2505 tpacpi_inputdev->keycode = hotkey_keycode_map;
2506 for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) {
2507 if (hotkey_keycode_map[i] != KEY_RESERVED) {
2508 set_bit(hotkey_keycode_map[i],
2509 tpacpi_inputdev->keybit);
2511 if (i < sizeof(hotkey_reserved_mask)*8)
2512 hotkey_reserved_mask |= 1 << i;
2516 if (tp_features.hotkey_wlsw) {
2517 set_bit(EV_SW, tpacpi_inputdev->evbit);
2518 set_bit(SW_RFKILL_ALL, tpacpi_inputdev->swbit);
2520 if (tp_features.hotkey_tablet) {
2521 set_bit(EV_SW, tpacpi_inputdev->evbit);
2522 set_bit(SW_TABLET_MODE, tpacpi_inputdev->swbit);
2525 /* Do not issue duplicate brightness change events to
2527 if (!tp_features.bright_acpimode)
2528 /* update bright_acpimode... */
2529 tpacpi_check_std_acpi_brightness_support();
2531 if (tp_features.bright_acpimode) {
2533 "This ThinkPad has standard ACPI backlight "
2534 "brightness control, supported by the ACPI "
2536 printk(TPACPI_NOTICE
2537 "Disabling thinkpad-acpi brightness events "
2540 /* The hotkey_reserved_mask change below is not
2541 * necessary while the keys are at KEY_RESERVED in the
2542 * default map, but better safe than sorry, leave it
2543 * here as a marker of what we have to do, especially
2544 * when we finally become able to set this at runtime
2545 * on response to X.org requests */
2546 hotkey_reserved_mask |=
2547 (1 << TP_ACPI_HOTKEYSCAN_FNHOME)
2548 | (1 << TP_ACPI_HOTKEYSCAN_FNEND);
2551 dbg_printk(TPACPI_DBG_INIT, "enabling hot key handling\n");
2552 res = hotkey_status_set(1);
2557 res = hotkey_mask_set(((hotkey_all_mask | hotkey_source_mask)
2558 & ~hotkey_reserved_mask)
2559 | hotkey_orig_mask);
2560 if (res < 0 && res != -ENXIO) {
2565 dbg_printk(TPACPI_DBG_INIT,
2566 "legacy hot key reporting over procfs %s\n",
2567 (hotkey_report_mode < 2) ?
2568 "enabled" : "disabled");
2570 tpacpi_inputdev->open = &hotkey_inputdev_open;
2571 tpacpi_inputdev->close = &hotkey_inputdev_close;
2573 hotkey_poll_setup_safe(1);
2574 tpacpi_send_radiosw_update();
2575 tpacpi_input_send_tabletsw();
2580 delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj);
2581 hotkey_dev_attributes = NULL;
2583 return (res < 0)? res : 1;
2586 static bool hotkey_notify_hotkey(const u32 hkey,
2588 bool *ignore_acpi_ev)
2590 /* 0x1000-0x1FFF: key presses */
2591 unsigned int scancode = hkey & 0xfff;
2592 *send_acpi_ev = true;
2593 *ignore_acpi_ev = false;
2595 if (scancode > 0 && scancode < 0x21) {
2597 if (!(hotkey_source_mask & (1 << scancode))) {
2598 tpacpi_input_send_key(scancode);
2599 *send_acpi_ev = false;
2601 *ignore_acpi_ev = true;
2608 static bool hotkey_notify_wakeup(const u32 hkey,
2610 bool *ignore_acpi_ev)
2612 /* 0x2000-0x2FFF: Wakeup reason */
2613 *send_acpi_ev = true;
2614 *ignore_acpi_ev = false;
2617 case 0x2304: /* suspend, undock */
2618 case 0x2404: /* hibernation, undock */
2619 hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK;
2620 *ignore_acpi_ev = true;
2623 case 0x2305: /* suspend, bay eject */
2624 case 0x2405: /* hibernation, bay eject */
2625 hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ;
2626 *ignore_acpi_ev = true;
2629 case 0x2313: /* Battery on critical low level (S3) */
2630 case 0x2413: /* Battery on critical low level (S4) */
2632 "EMERGENCY WAKEUP: battery almost empty\n");
2633 /* how to auto-heal: */
2634 /* 2313: woke up from S3, go to S4/S5 */
2635 /* 2413: woke up from S4, go to S5 */
2642 if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) {
2644 "woke up due to a hot-unplug "
2646 hotkey_wakeup_reason_notify_change();
2651 static bool hotkey_notify_usrevent(const u32 hkey,
2653 bool *ignore_acpi_ev)
2655 /* 0x5000-0x5FFF: human interface helpers */
2656 *send_acpi_ev = true;
2657 *ignore_acpi_ev = false;
2660 case 0x5010: /* Lenovo new BIOS: brightness changed */
2661 case 0x500b: /* X61t: tablet pen inserted into bay */
2662 case 0x500c: /* X61t: tablet pen removed from bay */
2665 case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
2666 case 0x500a: /* X41t-X61t: swivel down (normal mode) */
2667 tpacpi_input_send_tabletsw();
2668 hotkey_tablet_mode_notify_change();
2669 *send_acpi_ev = false;
2674 /* LID switch events. Do not propagate */
2675 *ignore_acpi_ev = true;
2683 static bool hotkey_notify_thermal(const u32 hkey,
2685 bool *ignore_acpi_ev)
2687 /* 0x6000-0x6FFF: thermal alarms */
2688 *send_acpi_ev = true;
2689 *ignore_acpi_ev = false;
2694 "THERMAL ALARM: battery is too hot!\n");
2695 /* recommended action: warn user through gui */
2699 "THERMAL EMERGENCY: battery is extremely hot!\n");
2700 /* recommended action: immediate sleep/hibernate */
2705 "a sensor reports something is too hot!\n");
2706 /* recommended action: warn user through gui, that */
2707 /* some internal component is too hot */
2711 "THERMAL EMERGENCY: "
2712 "a sensor reports something is extremely hot!\n");
2713 /* recommended action: immediate sleep/hibernate */
2717 "EC reports that Thermal Table has changed\n");
2718 /* recommended action: do nothing, we don't have
2719 * Lenovo ATM information */
2723 "THERMAL ALERT: unknown thermal alarm received\n");
2728 static void hotkey_notify(struct ibm_struct *ibm, u32 event)
2732 bool ignore_acpi_ev;
2735 if (event != 0x80) {
2737 "unknown HKEY notification event %d\n", event);
2738 /* forward it to userspace, maybe it knows how to handle it */
2739 acpi_bus_generate_netlink_event(
2740 ibm->acpi->device->pnp.device_class,
2741 dev_name(&ibm->acpi->device->dev),
2747 if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) {
2748 printk(TPACPI_ERR "failed to retrieve HKEY event\n");
2757 send_acpi_ev = true;
2758 ignore_acpi_ev = false;
2760 switch (hkey >> 12) {
2762 /* 0x1000-0x1FFF: key presses */
2763 known_ev = hotkey_notify_hotkey(hkey, &send_acpi_ev,
2767 /* 0x2000-0x2FFF: Wakeup reason */
2768 known_ev = hotkey_notify_wakeup(hkey, &send_acpi_ev,
2772 /* 0x3000-0x3FFF: bay-related wakeups */
2773 if (hkey == 0x3003) {
2774 hotkey_autosleep_ack = 1;
2777 hotkey_wakeup_hotunplug_complete_notify_change();
2784 /* 0x4000-0x4FFF: dock-related wakeups */
2785 if (hkey == 0x4003) {
2786 hotkey_autosleep_ack = 1;
2789 hotkey_wakeup_hotunplug_complete_notify_change();
2796 /* 0x5000-0x5FFF: human interface helpers */
2797 known_ev = hotkey_notify_usrevent(hkey, &send_acpi_ev,
2801 /* 0x6000-0x6FFF: thermal alarms */
2802 known_ev = hotkey_notify_thermal(hkey, &send_acpi_ev,
2806 /* 0x7000-0x7FFF: misc */
2807 if (tp_features.hotkey_wlsw && hkey == 0x7000) {
2808 tpacpi_send_radiosw_update();
2813 /* fallthrough to default */
2818 printk(TPACPI_NOTICE
2819 "unhandled HKEY event 0x%04x\n", hkey);
2820 printk(TPACPI_NOTICE
2821 "please report the conditions when this "
2822 "event happened to %s\n", TPACPI_MAIL);
2826 if (!ignore_acpi_ev &&
2827 (send_acpi_ev || hotkey_report_mode < 2)) {
2828 acpi_bus_generate_proc_event(ibm->acpi->device,
2832 /* netlink events */
2833 if (!ignore_acpi_ev && send_acpi_ev) {
2834 acpi_bus_generate_netlink_event(
2835 ibm->acpi->device->pnp.device_class,
2836 dev_name(&ibm->acpi->device->dev),
2842 static void hotkey_suspend(pm_message_t state)
2844 /* Do these on suspend, we get the events on early resume! */
2845 hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE;
2846 hotkey_autosleep_ack = 0;
2849 static void hotkey_resume(void)
2851 tpacpi_disable_brightness_delay();
2853 if (hotkey_mask_get())
2855 "error while trying to read hot key mask "
2857 tpacpi_send_radiosw_update();
2858 hotkey_tablet_mode_notify_change();
2859 hotkey_wakeup_reason_notify_change();
2860 hotkey_wakeup_hotunplug_complete_notify_change();
2861 hotkey_poll_setup_safe(0);
2864 /* procfs -------------------------------------------------------------- */
2865 static int hotkey_read(char *p)
2870 if (!tp_features.hotkey) {
2871 len += sprintf(p + len, "status:\t\tnot supported\n");
2875 if (mutex_lock_killable(&hotkey_mutex))
2876 return -ERESTARTSYS;
2877 res = hotkey_status_get(&status);
2879 res = hotkey_mask_get();
2880 mutex_unlock(&hotkey_mutex);
2884 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
2885 if (tp_features.hotkey_mask) {
2886 len += sprintf(p + len, "mask:\t\t0x%08x\n", hotkey_mask);
2887 len += sprintf(p + len,
2888 "commands:\tenable, disable, reset, <mask>\n");
2890 len += sprintf(p + len, "mask:\t\tnot supported\n");
2891 len += sprintf(p + len, "commands:\tenable, disable, reset\n");
2897 static int hotkey_write(char *buf)
2903 if (!tp_features.hotkey)
2906 if (mutex_lock_killable(&hotkey_mutex))
2907 return -ERESTARTSYS;
2913 while ((cmd = next_cmd(&buf))) {
2914 if (strlencmp(cmd, "enable") == 0) {
2916 } else if (strlencmp(cmd, "disable") == 0) {
2918 } else if (strlencmp(cmd, "reset") == 0) {
2919 status = hotkey_orig_status;
2920 mask = hotkey_orig_mask;
2921 } else if (sscanf(cmd, "0x%x", &mask) == 1) {
2923 } else if (sscanf(cmd, "%x", &mask) == 1) {
2931 res = hotkey_status_set(status);
2933 if (!res && mask != hotkey_mask)
2934 res = hotkey_mask_set(mask);
2937 mutex_unlock(&hotkey_mutex);
2941 static const struct acpi_device_id ibm_htk_device_ids[] = {
2942 {TPACPI_ACPI_HKEY_HID, 0},
2946 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = {
2947 .hid = ibm_htk_device_ids,
2948 .notify = hotkey_notify,
2949 .handle = &hkey_handle,
2950 .type = ACPI_DEVICE_NOTIFY,
2953 static struct ibm_struct hotkey_driver_data = {
2955 .read = hotkey_read,
2956 .write = hotkey_write,
2957 .exit = hotkey_exit,
2958 .resume = hotkey_resume,
2959 .suspend = hotkey_suspend,
2960 .acpi = &ibm_hotkey_acpidriver,
2963 /*************************************************************************
2964 * Bluetooth subdriver
2968 /* ACPI GBDC/SBDC bits */
2969 TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */
2970 TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */
2971 TP_ACPI_BLUETOOTH_RESUMECTRL = 0x04, /* Bluetooth state at resume:
2976 /* ACPI \BLTH commands */
2977 TP_ACPI_BLTH_GET_ULTRAPORT_ID = 0x00, /* Get Ultraport BT ID */
2978 TP_ACPI_BLTH_GET_PWR_ON_RESUME = 0x01, /* Get power-on-resume state */
2979 TP_ACPI_BLTH_PWR_ON_ON_RESUME = 0x02, /* Resume powered on */
2980 TP_ACPI_BLTH_PWR_OFF_ON_RESUME = 0x03, /* Resume powered off */
2981 TP_ACPI_BLTH_SAVE_STATE = 0x05, /* Save state for S4/S5 */
2984 static struct rfkill *tpacpi_bluetooth_rfkill;
2986 static void bluetooth_suspend(pm_message_t state)
2988 /* Try to make sure radio will resume powered off */
2989 acpi_evalf(NULL, NULL, "\\BLTH", "vd",
2990 TP_ACPI_BLTH_PWR_OFF_ON_RESUME);
2993 static int bluetooth_get_radiosw(void)
2997 if (!tp_features.bluetooth)
3000 /* WLSW overrides bluetooth in firmware/hardware, reflect that */
3001 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status)
3002 return RFKILL_STATE_HARD_BLOCKED;
3004 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3005 if (dbg_bluetoothemul)
3006 return (tpacpi_bluetooth_emulstate) ?
3007 RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED;
3010 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
3013 return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0) ?
3014 RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED;
3017 static void bluetooth_update_rfk(void)
3021 if (!tpacpi_bluetooth_rfkill)
3024 status = bluetooth_get_radiosw();
3027 rfkill_force_state(tpacpi_bluetooth_rfkill, status);
3030 static int bluetooth_set_radiosw(int radio_on, int update_rfk)
3034 if (!tp_features.bluetooth)
3037 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3038 * reason to risk weird behaviour. */
3039 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status
3043 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3044 if (dbg_bluetoothemul) {
3045 tpacpi_bluetooth_emulstate = !!radio_on;
3047 bluetooth_update_rfk();
3052 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */
3054 status = TP_ACPI_BLUETOOTH_RADIOSSW;
3057 if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
3061 bluetooth_update_rfk();
3066 /* sysfs bluetooth enable ---------------------------------------------- */
3067 static ssize_t bluetooth_enable_show(struct device *dev,
3068 struct device_attribute *attr,
3073 status = bluetooth_get_radiosw();
3077 return snprintf(buf, PAGE_SIZE, "%d\n",
3078 (status == RFKILL_STATE_UNBLOCKED) ? 1 : 0);
3081 static ssize_t bluetooth_enable_store(struct device *dev,
3082 struct device_attribute *attr,
3083 const char *buf, size_t count)
3088 if (parse_strtoul(buf, 1, &t))
3091 res = bluetooth_set_radiosw(t, 1);
3093 return (res) ? res : count;
3096 static struct device_attribute dev_attr_bluetooth_enable =
3097 __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO,
3098 bluetooth_enable_show, bluetooth_enable_store);
3100 /* --------------------------------------------------------------------- */
3102 static struct attribute *bluetooth_attributes[] = {
3103 &dev_attr_bluetooth_enable.attr,
3107 static const struct attribute_group bluetooth_attr_group = {
3108 .attrs = bluetooth_attributes,
3111 static int tpacpi_bluetooth_rfk_get(void *data, enum rfkill_state *state)
3113 int bts = bluetooth_get_radiosw();
3122 static int tpacpi_bluetooth_rfk_set(void *data, enum rfkill_state state)
3124 return bluetooth_set_radiosw((state == RFKILL_STATE_UNBLOCKED), 0);
3127 static void bluetooth_shutdown(void)
3129 /* Order firmware to save current state to NVRAM */
3130 if (!acpi_evalf(NULL, NULL, "\\BLTH", "vd",
3131 TP_ACPI_BLTH_SAVE_STATE))
3132 printk(TPACPI_NOTICE
3133 "failed to save bluetooth state to NVRAM\n");
3136 static void bluetooth_exit(void)
3138 bluetooth_shutdown();
3140 if (tpacpi_bluetooth_rfkill)
3141 rfkill_unregister(tpacpi_bluetooth_rfkill);
3143 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
3144 &bluetooth_attr_group);
3147 static int __init bluetooth_init(struct ibm_init_struct *iibm)
3152 vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n");
3154 TPACPI_ACPIHANDLE_INIT(hkey);
3156 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3157 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
3158 tp_features.bluetooth = hkey_handle &&
3159 acpi_evalf(hkey_handle, &status, "GBDC", "qd");
3161 vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s, status 0x%02x\n",
3162 str_supported(tp_features.bluetooth),
3165 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3166 if (dbg_bluetoothemul) {
3167 tp_features.bluetooth = 1;
3169 "bluetooth switch emulation enabled\n");
3172 if (tp_features.bluetooth &&
3173 !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) {
3174 /* no bluetooth hardware present in system */
3175 tp_features.bluetooth = 0;
3176 dbg_printk(TPACPI_DBG_INIT,
3177 "bluetooth hardware not installed\n");
3180 if (!tp_features.bluetooth)
3183 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
3184 &bluetooth_attr_group);
3188 res = tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID,
3189 &tpacpi_bluetooth_rfkill,
3190 RFKILL_TYPE_BLUETOOTH,
3191 "tpacpi_bluetooth_sw",
3193 tpacpi_bluetooth_rfk_set,
3194 tpacpi_bluetooth_rfk_get);
3203 /* procfs -------------------------------------------------------------- */
3204 static int bluetooth_read(char *p)
3207 int status = bluetooth_get_radiosw();
3209 if (!tp_features.bluetooth)
3210 len += sprintf(p + len, "status:\t\tnot supported\n");
3212 len += sprintf(p + len, "status:\t\t%s\n",
3213 (status == RFKILL_STATE_UNBLOCKED) ?
3214 "enabled" : "disabled");
3215 len += sprintf(p + len, "commands:\tenable, disable\n");
3221 static int bluetooth_write(char *buf)
3225 if (!tp_features.bluetooth)
3228 while ((cmd = next_cmd(&buf))) {
3229 if (strlencmp(cmd, "enable") == 0) {
3230 bluetooth_set_radiosw(1, 1);
3231 } else if (strlencmp(cmd, "disable") == 0) {
3232 bluetooth_set_radiosw(0, 1);
3240 static struct ibm_struct bluetooth_driver_data = {
3241 .name = "bluetooth",
3242 .read = bluetooth_read,
3243 .write = bluetooth_write,
3244 .exit = bluetooth_exit,
3245 .suspend = bluetooth_suspend,
3246 .shutdown = bluetooth_shutdown,
3249 /*************************************************************************
3254 /* ACPI GWAN/SWAN bits */
3255 TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */
3256 TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */
3257 TP_ACPI_WANCARD_RESUMECTRL = 0x04, /* Wan state at resume:
3261 static struct rfkill *tpacpi_wan_rfkill;
3263 static void wan_suspend(pm_message_t state)
3265 /* Try to make sure radio will resume powered off */
3266 acpi_evalf(NULL, NULL, "\\WGSV", "qvd",
3267 TP_ACPI_WGSV_PWR_OFF_ON_RESUME);
3270 static int wan_get_radiosw(void)
3274 if (!tp_features.wan)
3277 /* WLSW overrides WWAN in firmware/hardware, reflect that */
3278 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status)
3279 return RFKILL_STATE_HARD_BLOCKED;
3281 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3283 return (tpacpi_wwan_emulstate) ?
3284 RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED;
3287 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
3290 return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0) ?
3291 RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED;
3294 static void wan_update_rfk(void)
3298 if (!tpacpi_wan_rfkill)
3301 status = wan_get_radiosw();
3304 rfkill_force_state(tpacpi_wan_rfkill, status);
3307 static int wan_set_radiosw(int radio_on, int update_rfk)
3311 if (!tp_features.wan)
3314 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3315 * reason to risk weird behaviour. */
3316 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status
3320 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3322 tpacpi_wwan_emulstate = !!radio_on;
3329 /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */
3331 status = TP_ACPI_WANCARD_RADIOSSW;
3334 if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
3343 /* sysfs wan enable ---------------------------------------------------- */
3344 static ssize_t wan_enable_show(struct device *dev,
3345 struct device_attribute *attr,
3350 status = wan_get_radiosw();
3354 return snprintf(buf, PAGE_SIZE, "%d\n",
3355 (status == RFKILL_STATE_UNBLOCKED) ? 1 : 0);
3358 static ssize_t wan_enable_store(struct device *dev,
3359 struct device_attribute *attr,
3360 const char *buf, size_t count)
3365 if (parse_strtoul(buf, 1, &t))
3368 res = wan_set_radiosw(t, 1);
3370 return (res) ? res : count;
3373 static struct device_attribute dev_attr_wan_enable =
3374 __ATTR(wwan_enable, S_IWUSR | S_IRUGO,
3375 wan_enable_show, wan_enable_store);
3377 /* --------------------------------------------------------------------- */
3379 static struct attribute *wan_attributes[] = {
3380 &dev_attr_wan_enable.attr,
3384 static const struct attribute_group wan_attr_group = {
3385 .attrs = wan_attributes,
3388 static int tpacpi_wan_rfk_get(void *data, enum rfkill_state *state)
3390 int wans = wan_get_radiosw();
3399 static int tpacpi_wan_rfk_set(void *data, enum rfkill_state state)
3401 return wan_set_radiosw((state == RFKILL_STATE_UNBLOCKED), 0);
3404 static void wan_shutdown(void)
3406 /* Order firmware to save current state to NVRAM */
3407 if (!acpi_evalf(NULL, NULL, "\\WGSV", "vd",
3408 TP_ACPI_WGSV_SAVE_STATE))
3409 printk(TPACPI_NOTICE
3410 "failed to save WWAN state to NVRAM\n");
3413 static void wan_exit(void)
3417 if (tpacpi_wan_rfkill)
3418 rfkill_unregister(tpacpi_wan_rfkill);
3420 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
3424 static int __init wan_init(struct ibm_init_struct *iibm)
3429 vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n");
3431 TPACPI_ACPIHANDLE_INIT(hkey);
3433 tp_features.wan = hkey_handle &&
3434 acpi_evalf(hkey_handle, &status, "GWAN", "qd");
3436 vdbg_printk(TPACPI_DBG_INIT, "wan is %s, status 0x%02x\n",
3437 str_supported(tp_features.wan),
3440 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3442 tp_features.wan = 1;
3444 "wwan switch emulation enabled\n");
3447 if (tp_features.wan &&
3448 !(status & TP_ACPI_WANCARD_HWPRESENT)) {
3449 /* no wan hardware present in system */
3450 tp_features.wan = 0;
3451 dbg_printk(TPACPI_DBG_INIT,
3452 "wan hardware not installed\n");
3455 if (!tp_features.wan)
3458 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
3463 res = tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID,
3469 tpacpi_wan_rfk_get);
3478 /* procfs -------------------------------------------------------------- */
3479 static int wan_read(char *p)
3482 int status = wan_get_radiosw();
3484 if (!tp_features.wan)
3485 len += sprintf(p + len, "status:\t\tnot supported\n");
3487 len += sprintf(p + len, "status:\t\t%s\n",
3488 (status == RFKILL_STATE_UNBLOCKED) ?
3489 "enabled" : "disabled");
3490 len += sprintf(p + len, "commands:\tenable, disable\n");
3496 static int wan_write(char *buf)
3500 if (!tp_features.wan)
3503 while ((cmd = next_cmd(&buf))) {
3504 if (strlencmp(cmd, "enable") == 0) {
3505 wan_set_radiosw(1, 1);
3506 } else if (strlencmp(cmd, "disable") == 0) {
3507 wan_set_radiosw(0, 1);
3515 static struct ibm_struct wan_driver_data = {
3520 .suspend = wan_suspend,
3521 .shutdown = wan_shutdown,
3524 /*************************************************************************
3529 /* ACPI GUWB/SUWB bits */
3530 TP_ACPI_UWB_HWPRESENT = 0x01, /* UWB hw available */
3531 TP_ACPI_UWB_RADIOSSW = 0x02, /* UWB radio enabled */
3534 static struct rfkill *tpacpi_uwb_rfkill;
3536 static int uwb_get_radiosw(void)
3540 if (!tp_features.uwb)
3543 /* WLSW overrides UWB in firmware/hardware, reflect that */
3544 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status)
3545 return RFKILL_STATE_HARD_BLOCKED;
3547 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3549 return (tpacpi_uwb_emulstate) ?
3550 RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED;
3553 if (!acpi_evalf(hkey_handle, &status, "GUWB", "d"))
3556 return ((status & TP_ACPI_UWB_RADIOSSW) != 0) ?
3557 RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED;
3560 static void uwb_update_rfk(void)
3564 if (!tpacpi_uwb_rfkill)
3567 status = uwb_get_radiosw();
3570 rfkill_force_state(tpacpi_uwb_rfkill, status);
3573 static int uwb_set_radiosw(int radio_on, int update_rfk)
3577 if (!tp_features.uwb)
3580 /* WLSW overrides UWB in firmware/hardware, but there is no
3581 * reason to risk weird behaviour. */
3582 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status
3586 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3588 tpacpi_uwb_emulstate = !!radio_on;
3595 status = (radio_on) ? TP_ACPI_UWB_RADIOSSW : 0;
3596 if (!acpi_evalf(hkey_handle, NULL, "SUWB", "vd", status))
3605 /* --------------------------------------------------------------------- */
3607 static int tpacpi_uwb_rfk_get(void *data, enum rfkill_state *state)
3609 int uwbs = uwb_get_radiosw();
3618 static int tpacpi_uwb_rfk_set(void *data, enum rfkill_state state)
3620 return uwb_set_radiosw((state == RFKILL_STATE_UNBLOCKED), 0);
3623 static void uwb_exit(void)
3625 if (tpacpi_uwb_rfkill)
3626 rfkill_unregister(tpacpi_uwb_rfkill);
3629 static int __init uwb_init(struct ibm_init_struct *iibm)
3634 vdbg_printk(TPACPI_DBG_INIT, "initializing uwb subdriver\n");
3636 TPACPI_ACPIHANDLE_INIT(hkey);
3638 tp_features.uwb = hkey_handle &&
3639 acpi_evalf(hkey_handle, &status, "GUWB", "qd");
3641 vdbg_printk(TPACPI_DBG_INIT, "uwb is %s, status 0x%02x\n",
3642 str_supported(tp_features.uwb),
3645 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3647 tp_features.uwb = 1;
3649 "uwb switch emulation enabled\n");
3652 if (tp_features.uwb &&
3653 !(status & TP_ACPI_UWB_HWPRESENT)) {
3654 /* no uwb hardware present in system */
3655 tp_features.uwb = 0;
3656 dbg_printk(TPACPI_DBG_INIT,
3657 "uwb hardware not installed\n");
3660 if (!tp_features.uwb)
3663 res = tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID,
3669 tpacpi_uwb_rfk_get);
3674 static struct ibm_struct uwb_driver_data = {
3677 .flags.experimental = 1,
3680 /*************************************************************************
3684 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
3686 enum video_access_mode {
3687 TPACPI_VIDEO_NONE = 0,
3688 TPACPI_VIDEO_570, /* 570 */
3689 TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */
3690 TPACPI_VIDEO_NEW, /* all others */
3693 enum { /* video status flags, based on VIDEO_570 */
3694 TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */
3695 TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */
3696 TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */
3699 enum { /* TPACPI_VIDEO_570 constants */
3700 TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */
3701 TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to
3702 * video_status_flags */
3703 TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */
3704 TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */
3707 static enum video_access_mode video_supported;
3708 static int video_orig_autosw;
3710 static int video_autosw_get(void);
3711 static int video_autosw_set(int enable);
3713 TPACPI_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */
3715 static int __init video_init(struct ibm_init_struct *iibm)
3719 vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n");
3721 TPACPI_ACPIHANDLE_INIT(vid);
3722 TPACPI_ACPIHANDLE_INIT(vid2);
3724 if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
3725 /* G41, assume IVGA doesn't change */
3726 vid_handle = vid2_handle;
3729 /* video switching not supported on R30, R31 */
3730 video_supported = TPACPI_VIDEO_NONE;
3731 else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
3733 video_supported = TPACPI_VIDEO_570;
3734 else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
3735 /* 600e/x, 770e, 770x */
3736 video_supported = TPACPI_VIDEO_770;
3739 video_supported = TPACPI_VIDEO_NEW;
3741 vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n",
3742 str_supported(video_supported != TPACPI_VIDEO_NONE),
3745 return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1;
3748 static void video_exit(void)
3750 dbg_printk(TPACPI_DBG_EXIT,
3751 "restoring original video autoswitch mode\n");
3752 if (video_autosw_set(video_orig_autosw))
3753 printk(TPACPI_ERR "error while trying to restore original "
3754 "video autoswitch mode\n");
3757 static int video_outputsw_get(void)
3762 switch (video_supported) {
3763 case TPACPI_VIDEO_570:
3764 if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd",
3765 TP_ACPI_VIDEO_570_PHSCMD))
3767 status = i & TP_ACPI_VIDEO_570_PHSMASK;
3769 case TPACPI_VIDEO_770:
3770 if (!acpi_evalf(NULL, &i, "\\VCDL", "d"))
3773 status |= TP_ACPI_VIDEO_S_LCD;
3774 if (!acpi_evalf(NULL, &i, "\\VCDC", "d"))
3777 status |= TP_ACPI_VIDEO_S_CRT;
3779 case TPACPI_VIDEO_NEW:
3780 if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) ||
3781 !acpi_evalf(NULL, &i, "\\VCDC", "d"))
3784 status |= TP_ACPI_VIDEO_S_CRT;
3786 if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) ||
3787 !acpi_evalf(NULL, &i, "\\VCDL", "d"))
3790 status |= TP_ACPI_VIDEO_S_LCD;
3791 if (!acpi_evalf(NULL, &i, "\\VCDD", "d"))
3794 status |= TP_ACPI_VIDEO_S_DVI;
3803 static int video_outputsw_set(int status)
3808 switch (video_supported) {
3809 case TPACPI_VIDEO_570:
3810 res = acpi_evalf(NULL, NULL,
3811 "\\_SB.PHS2", "vdd",
3812 TP_ACPI_VIDEO_570_PHS2CMD,
3813 status | TP_ACPI_VIDEO_570_PHS2SET);
3815 case TPACPI_VIDEO_770:
3816 autosw = video_autosw_get();
3820 res = video_autosw_set(1);
3823 res = acpi_evalf(vid_handle, NULL,
3824 "ASWT", "vdd", status * 0x100, 0);
3825 if (!autosw && video_autosw_set(autosw)) {
3827 "video auto-switch left enabled due to error\n");
3831 case TPACPI_VIDEO_NEW:
3832 res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) &&
3833 acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1);
3839 return (res)? 0 : -EIO;
3842 static int video_autosw_get(void)
3846 switch (video_supported) {
3847 case TPACPI_VIDEO_570:
3848 if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d"))
3851 case TPACPI_VIDEO_770:
3852 case TPACPI_VIDEO_NEW:
3853 if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d"))
3863 static int video_autosw_set(int enable)
3865 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0))
3870 static int video_outputsw_cycle(void)
3872 int autosw = video_autosw_get();
3878 switch (video_supported) {
3879 case TPACPI_VIDEO_570:
3880 res = video_autosw_set(1);
3883 res = acpi_evalf(ec_handle, NULL, "_Q16", "v");
3885 case TPACPI_VIDEO_770:
3886 case TPACPI_VIDEO_NEW:
3887 res = video_autosw_set(1);
3890 res = acpi_evalf(vid_handle, NULL, "VSWT", "v");
3895 if (!autosw && video_autosw_set(autosw)) {
3897 "video auto-switch left enabled due to error\n");
3901 return (res)? 0 : -EIO;
3904 static int video_expand_toggle(void)
3906 switch (video_supported) {
3907 case TPACPI_VIDEO_570:
3908 return acpi_evalf(ec_handle, NULL, "_Q17", "v")?
3910 case TPACPI_VIDEO_770:
3911 return acpi_evalf(vid_handle, NULL, "VEXP", "v")?
3913 case TPACPI_VIDEO_NEW:
3914 return acpi_evalf(NULL, NULL, "\\VEXP", "v")?
3922 static int video_read(char *p)
3927 if (video_supported == TPACPI_VIDEO_NONE) {
3928 len += sprintf(p + len, "status:\t\tnot supported\n");
3932 status = video_outputsw_get();
3936 autosw = video_autosw_get();
3940 len += sprintf(p + len, "status:\t\tsupported\n");
3941 len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
3942 len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
3943 if (video_supported == TPACPI_VIDEO_NEW)
3944 len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
3945 len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
3946 len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
3947 len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
3948 if (video_supported == TPACPI_VIDEO_NEW)
3949 len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
3950 len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
3951 len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
3956 static int video_write(char *buf)
3959 int enable, disable, status;
3962 if (video_supported == TPACPI_VIDEO_NONE)
3968 while ((cmd = next_cmd(&buf))) {
3969 if (strlencmp(cmd, "lcd_enable") == 0) {
3970 enable |= TP_ACPI_VIDEO_S_LCD;
3971 } else if (strlencmp(cmd, "lcd_disable") == 0) {
3972 disable |= TP_ACPI_VIDEO_S_LCD;
3973 } else if (strlencmp(cmd, "crt_enable") == 0) {
3974 enable |= TP_ACPI_VIDEO_S_CRT;
3975 } else if (strlencmp(cmd, "crt_disable") == 0) {
3976 disable |= TP_ACPI_VIDEO_S_CRT;
3977 } else if (video_supported == TPACPI_VIDEO_NEW &&
3978 strlencmp(cmd, "dvi_enable") == 0) {
3979 enable |= TP_ACPI_VIDEO_S_DVI;
3980 } else if (video_supported == TPACPI_VIDEO_NEW &&
3981 strlencmp(cmd, "dvi_disable") == 0) {
3982 disable |= TP_ACPI_VIDEO_S_DVI;
3983 } else if (strlencmp(cmd, "auto_enable") == 0) {
3984 res = video_autosw_set(1);
3987 } else if (strlencmp(cmd, "auto_disable") == 0) {
3988 res = video_autosw_set(0);
3991 } else if (strlencmp(cmd, "video_switch") == 0) {
3992 res = video_outputsw_cycle();
3995 } else if (strlencmp(cmd, "expand_toggle") == 0) {
3996 res = video_expand_toggle();
4003 if (enable || disable) {
4004 status = video_outputsw_get();
4007 res = video_outputsw_set((status & ~disable) | enable);
4015 static struct ibm_struct video_driver_data = {
4018 .write = video_write,
4022 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4024 /*************************************************************************
4025 * Light (thinklight) subdriver
4028 TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4029 TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */
4031 static int light_get_status(void)
4035 if (tp_features.light_status) {
4036 if (!acpi_evalf(ec_handle, &status, "KBLT", "d"))
4044 static int light_set_status(int status)
4048 if (tp_features.light) {
4050 rc = acpi_evalf(cmos_handle, NULL, NULL, "vd",
4052 TP_CMOS_THINKLIGHT_ON :
4053 TP_CMOS_THINKLIGHT_OFF);
4055 rc = acpi_evalf(lght_handle, NULL, NULL, "vd",
4058 return (rc)? 0 : -EIO;
4064 static void light_set_status_worker(struct work_struct *work)
4066 struct tpacpi_led_classdev *data =
4067 container_of(work, struct tpacpi_led_classdev, work);
4069 if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING))
4070 light_set_status((data->new_brightness != LED_OFF));
4073 static void light_sysfs_set(struct led_classdev *led_cdev,
4074 enum led_brightness brightness)
4076 struct tpacpi_led_classdev *data =
4077 container_of(led_cdev,
4078 struct tpacpi_led_classdev,
4080 data->new_brightness = brightness;
4081 queue_work(tpacpi_wq, &data->work);
4084 static enum led_brightness light_sysfs_get(struct led_classdev *led_cdev)
4086 return (light_get_status() == 1)? LED_FULL : LED_OFF;
4089 static struct tpacpi_led_classdev tpacpi_led_thinklight = {
4091 .name = "tpacpi::thinklight",
4092 .brightness_set = &light_sysfs_set,
4093 .brightness_get = &light_sysfs_get,
4097 static int __init light_init(struct ibm_init_struct *iibm)
4101 vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n");
4103 TPACPI_ACPIHANDLE_INIT(ledb);
4104 TPACPI_ACPIHANDLE_INIT(lght);
4105 TPACPI_ACPIHANDLE_INIT(cmos);
4106 INIT_WORK(&tpacpi_led_thinklight.work, light_set_status_worker);
4108 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4109 tp_features.light = (cmos_handle || lght_handle) && !ledb_handle;
4111 if (tp_features.light)
4112 /* light status not supported on
4113 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4114 tp_features.light_status =
4115 acpi_evalf(ec_handle, NULL, "KBLT", "qv");
4117 vdbg_printk(TPACPI_DBG_INIT, "light is %s, light status is %s\n",
4118 str_supported(tp_features.light),
4119 str_supported(tp_features.light_status));
4121 if (!tp_features.light)
4124 rc = led_classdev_register(&tpacpi_pdev->dev,
4125 &tpacpi_led_thinklight.led_classdev);
4128 tp_features.light = 0;
4129 tp_features.light_status = 0;
4137 static void light_exit(void)
4139 led_classdev_unregister(&tpacpi_led_thinklight.led_classdev);
4140 if (work_pending(&tpacpi_led_thinklight.work))
4141 flush_workqueue(tpacpi_wq);
4144 static int light_read(char *p)
4149 if (!tp_features.light) {
4150 len += sprintf(p + len, "status:\t\tnot supported\n");
4151 } else if (!tp_features.light_status) {
4152 len += sprintf(p + len, "status:\t\tunknown\n");
4153 len += sprintf(p + len, "commands:\ton, off\n");
4155 status = light_get_status();
4158 len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0));
4159 len += sprintf(p + len, "commands:\ton, off\n");
4165 static int light_write(char *buf)
4170 if (!tp_features.light)
4173 while ((cmd = next_cmd(&buf))) {
4174 if (strlencmp(cmd, "on") == 0) {
4176 } else if (strlencmp(cmd, "off") == 0) {
4182 return light_set_status(newstatus);
4185 static struct ibm_struct light_driver_data = {
4188 .write = light_write,
4192 /*************************************************************************
4196 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4198 static void dock_notify(struct ibm_struct *ibm, u32 event);
4199 static int dock_read(char *p);
4200 static int dock_write(char *buf);
4202 TPACPI_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
4203 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
4204 "\\_SB.PCI0.PCI1.DOCK", /* all others */
4205 "\\_SB.PCI.ISA.SLCE", /* 570 */
4206 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
4208 /* don't list other alternatives as we install a notify handler on the 570 */
4209 TPACPI_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
4211 static const struct acpi_device_id ibm_pci_device_ids[] = {
4212 {PCI_ROOT_HID_STRING, 0},
4216 static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = {
4218 .notify = dock_notify,
4219 .handle = &dock_handle,
4220 .type = ACPI_SYSTEM_NOTIFY,
4223 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
4224 * We just use it to get notifications of dock hotplug
4225 * in very old thinkpads */
4226 .hid = ibm_pci_device_ids,
4227 .notify = dock_notify,
4228 .handle = &pci_handle,
4229 .type = ACPI_SYSTEM_NOTIFY,
4233 static struct ibm_struct dock_driver_data[2] = {
4237 .write = dock_write,
4238 .acpi = &ibm_dock_acpidriver[0],
4242 .acpi = &ibm_dock_acpidriver[1],
4246 #define dock_docked() (_sta(dock_handle) & 1)
4248 static int __init dock_init(struct ibm_init_struct *iibm)
4250 vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n");
4252 TPACPI_ACPIHANDLE_INIT(dock);
4254 vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n",
4255 str_supported(dock_handle != NULL));
4257 return (dock_handle)? 0 : 1;
4260 static int __init dock_init2(struct ibm_init_struct *iibm)
4264 vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver part 2\n");
4266 if (dock_driver_data[0].flags.acpi_driver_registered &&
4267 dock_driver_data[0].flags.acpi_notify_installed) {
4268 TPACPI_ACPIHANDLE_INIT(pci);
4269 dock2_needed = (pci_handle != NULL);
4270 vdbg_printk(TPACPI_DBG_INIT,
4271 "dock PCI handler for the TP 570 is %s\n",
4272 str_supported(dock2_needed));
4274 vdbg_printk(TPACPI_DBG_INIT,
4275 "dock subdriver part 2 not required\n");
4279 return (dock2_needed)? 0 : 1;
4282 static void dock_notify(struct ibm_struct *ibm, u32 event)
4284 int docked = dock_docked();
4285 int pci = ibm->acpi->hid && ibm->acpi->device &&
4286 acpi_match_device_ids(ibm->acpi->device, ibm_pci_device_ids);
4289 if (event == 1 && !pci) /* 570 */
4290 data = 1; /* button */
4291 else if (event == 1 && pci) /* 570 */
4292 data = 3; /* dock */
4293 else if (event == 3 && docked)
4294 data = 1; /* button */
4295 else if (event == 3 && !docked)
4296 data = 2; /* undock */
4297 else if (event == 0 && docked)
4298 data = 3; /* dock */
4300 printk(TPACPI_ERR "unknown dock event %d, status %d\n",
4301 event, _sta(dock_handle));
4302 data = 0; /* unknown */
4304 acpi_bus_generate_proc_event(ibm->acpi->device, event, data);
4305 acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class,
4306 dev_name(&ibm->acpi->device->dev),
4310 static int dock_read(char *p)
4313 int docked = dock_docked();
4316 len += sprintf(p + len, "status:\t\tnot supported\n");
4318 len += sprintf(p + len, "status:\t\tundocked\n");
4320 len += sprintf(p + len, "status:\t\tdocked\n");
4321 len += sprintf(p + len, "commands:\tdock, undock\n");
4327 static int dock_write(char *buf)
4334 while ((cmd = next_cmd(&buf))) {
4335 if (strlencmp(cmd, "undock") == 0) {
4336 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) ||
4337 !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1))
4339 } else if (strlencmp(cmd, "dock") == 0) {
4340 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1))
4349 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
4351 /*************************************************************************
4355 #ifdef CONFIG_THINKPAD_ACPI_BAY
4357 TPACPI_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
4358 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
4359 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
4360 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
4361 ); /* A21e, R30, R31 */
4362 TPACPI_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */
4363 "_EJ0", /* all others */
4364 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
4365 TPACPI_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
4366 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
4368 TPACPI_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */
4372 static int __init bay_init(struct ibm_init_struct *iibm)
4374 vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n");
4376 TPACPI_ACPIHANDLE_INIT(bay);
4378 TPACPI_ACPIHANDLE_INIT(bay_ej);
4379 TPACPI_ACPIHANDLE_INIT(bay2);
4381 TPACPI_ACPIHANDLE_INIT(bay2_ej);
4383 tp_features.bay_status = bay_handle &&
4384 acpi_evalf(bay_handle, NULL, "_STA", "qv");
4385 tp_features.bay_status2 = bay2_handle &&
4386 acpi_evalf(bay2_handle, NULL, "_STA", "qv");
4388 tp_features.bay_eject = bay_handle && bay_ej_handle &&
4389 (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental);
4390 tp_features.bay_eject2 = bay2_handle && bay2_ej_handle &&
4391 (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
4393 vdbg_printk(TPACPI_DBG_INIT,
4394 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
4395 str_supported(tp_features.bay_status),
4396 str_supported(tp_features.bay_eject),
4397 str_supported(tp_features.bay_status2),
4398 str_supported(tp_features.bay_eject2));
4400 return (tp_features.bay_status || tp_features.bay_eject ||
4401 tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1;
4404 static void bay_notify(struct ibm_struct *ibm, u32 event)
4406 acpi_bus_generate_proc_event(ibm->acpi->device, event, 0);
4407 acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class,
4408 dev_name(&ibm->acpi->device->dev),
4412 #define bay_occupied(b) (_sta(b##_handle) & 1)
4414 static int bay_read(char *p)
4417 int occupied = bay_occupied(bay);
4418 int occupied2 = bay_occupied(bay2);
4421 len += sprintf(p + len, "status:\t\t%s\n",
4422 tp_features.bay_status ?
4423 (occupied ? "occupied" : "unoccupied") :
4425 if (tp_features.bay_status2)
4426 len += sprintf(p + len, "status2:\t%s\n", occupied2 ?
4427 "occupied" : "unoccupied");
4429 eject = tp_features.bay_eject && occupied;
4430 eject2 = tp_features.bay_eject2 && occupied2;
4432 if (eject && eject2)
4433 len += sprintf(p + len, "commands:\teject, eject2\n");
4435 len += sprintf(p + len, "commands:\teject\n");
4437 len += sprintf(p + len, "commands:\teject2\n");
4442 static int bay_write(char *buf)
4446 if (!tp_features.bay_eject && !tp_features.bay_eject2)
4449 while ((cmd = next_cmd(&buf))) {
4450 if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) {
4451 if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1))
4453 } else if (tp_features.bay_eject2 &&
4454 strlencmp(cmd, "eject2") == 0) {
4455 if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1))
4464 static struct tp_acpi_drv_struct ibm_bay_acpidriver = {
4465 .notify = bay_notify,
4466 .handle = &bay_handle,
4467 .type = ACPI_SYSTEM_NOTIFY,
4470 static struct ibm_struct bay_driver_data = {
4474 .acpi = &ibm_bay_acpidriver,
4477 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4479 /*************************************************************************
4483 /* sysfs cmos_command -------------------------------------------------- */
4484 static ssize_t cmos_command_store(struct device *dev,
4485 struct device_attribute *attr,
4486 const char *buf, size_t count)
4488 unsigned long cmos_cmd;
4491 if (parse_strtoul(buf, 21, &cmos_cmd))
4494 res = issue_thinkpad_cmos_command(cmos_cmd);
4495 return (res)? res : count;
4498 static struct device_attribute dev_attr_cmos_command =
4499 __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store);
4501 /* --------------------------------------------------------------------- */
4503 static int __init cmos_init(struct ibm_init_struct *iibm)
4507 vdbg_printk(TPACPI_DBG_INIT,
4508 "initializing cmos commands subdriver\n");
4510 TPACPI_ACPIHANDLE_INIT(cmos);
4512 vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n",
4513 str_supported(cmos_handle != NULL));
4515 res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command);
4519 return (cmos_handle)? 0 : 1;
4522 static void cmos_exit(void)
4524 device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command);
4527 static int cmos_read(char *p)
4531 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4532 R30, R31, T20-22, X20-21 */
4534 len += sprintf(p + len, "status:\t\tnot supported\n");
4536 len += sprintf(p + len, "status:\t\tsupported\n");
4537 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n");
4543 static int cmos_write(char *buf)
4548 while ((cmd = next_cmd(&buf))) {
4549 if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
4550 cmos_cmd >= 0 && cmos_cmd <= 21) {
4555 res = issue_thinkpad_cmos_command(cmos_cmd);
4563 static struct ibm_struct cmos_driver_data = {
4566 .write = cmos_write,
4570 /*************************************************************************
4574 enum led_access_mode {
4575 TPACPI_LED_NONE = 0,
4576 TPACPI_LED_570, /* 570 */
4577 TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4578 TPACPI_LED_NEW, /* all others */
4581 enum { /* For TPACPI_LED_OLD */
4582 TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */
4583 TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */
4584 TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */
4593 static enum led_access_mode led_supported;
4595 TPACPI_HANDLE(led, ec, "SLED", /* 570 */
4596 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4597 /* T20-22, X20-21 */
4598 "LED", /* all others */
4601 #define TPACPI_LED_NUMLEDS 8
4602 static struct tpacpi_led_classdev *tpacpi_leds;
4603 static enum led_status_t tpacpi_led_state_cache[TPACPI_LED_NUMLEDS];
4604 static const char * const tpacpi_led_names[TPACPI_LED_NUMLEDS] = {
4605 /* there's a limit of 19 chars + NULL before 2.6.26 */
4607 "tpacpi:orange:batt",
4608 "tpacpi:green:batt",
4609 "tpacpi::dock_active",
4610 "tpacpi::bay_active",
4611 "tpacpi::dock_batt",
4612 "tpacpi::unknown_led",
4616 static int led_get_status(const unsigned int led)
4619 enum led_status_t led_s;
4621 switch (led_supported) {
4622 case TPACPI_LED_570:
4623 if (!acpi_evalf(ec_handle,
4624 &status, "GLED", "dd", 1 << led))
4626 led_s = (status == 0)?
4631 tpacpi_led_state_cache[led] = led_s;
4640 static int led_set_status(const unsigned int led,
4641 const enum led_status_t ledstatus)
4643 /* off, on, blink. Index is led_status_t */
4644 static const unsigned int led_sled_arg1[] = { 0, 1, 3 };
4645 static const unsigned int led_led_arg1[] = { 0, 0x80, 0xc0 };
4649 switch (led_supported) {
4650 case TPACPI_LED_570:
4654 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
4655 (1 << led), led_sled_arg1[ledstatus]))
4658 case TPACPI_LED_OLD:
4659 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
4662 rc = ec_write(TPACPI_LED_EC_HLMS, (1 << led));
4664 rc = ec_write(TPACPI_LED_EC_HLBL,
4665 (ledstatus == TPACPI_LED_BLINK) << led);
4667 rc = ec_write(TPACPI_LED_EC_HLCL,
4668 (ledstatus != TPACPI_LED_OFF) << led);
4670 case TPACPI_LED_NEW:
4672 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
4673 led, led_led_arg1[ledstatus]))
4681 tpacpi_led_state_cache[led] = ledstatus;
4686 static void led_sysfs_set_status(unsigned int led,
4687 enum led_brightness brightness)
4690 (brightness == LED_OFF) ?
4692 (tpacpi_led_state_cache[led] == TPACPI_LED_BLINK) ?
4693 TPACPI_LED_BLINK : TPACPI_LED_ON);
4696 static void led_set_status_worker(struct work_struct *work)
4698 struct tpacpi_led_classdev *data =
4699 container_of(work, struct tpacpi_led_classdev, work);
4701 if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING))
4702 led_sysfs_set_status(data->led, data->new_brightness);
4705 static void led_sysfs_set(struct led_classdev *led_cdev,
4706 enum led_brightness brightness)
4708 struct tpacpi_led_classdev *data = container_of(led_cdev,
4709 struct tpacpi_led_classdev, led_classdev);
4711 data->new_brightness = brightness;
4712 queue_work(tpacpi_wq, &data->work);
4715 static int led_sysfs_blink_set(struct led_classdev *led_cdev,
4716 unsigned long *delay_on, unsigned long *delay_off)
4718 struct tpacpi_led_classdev *data = container_of(led_cdev,
4719 struct tpacpi_led_classdev, led_classdev);
4721 /* Can we choose the flash rate? */
4722 if (*delay_on == 0 && *delay_off == 0) {
4723 /* yes. set them to the hardware blink rate (1 Hz) */
4724 *delay_on = 500; /* ms */
4725 *delay_off = 500; /* ms */
4726 } else if ((*delay_on != 500) || (*delay_off != 500))
4729 data->new_brightness = TPACPI_LED_BLINK;
4730 queue_work(tpacpi_wq, &data->work);
4735 static enum led_brightness led_sysfs_get(struct led_classdev *led_cdev)
4739 struct tpacpi_led_classdev *data = container_of(led_cdev,
4740 struct tpacpi_led_classdev, led_classdev);
4742 rc = led_get_status(data->led);
4744 if (rc == TPACPI_LED_OFF || rc < 0)
4745 rc = LED_OFF; /* no error handling in led class :( */
4752 static void led_exit(void)
4756 for (i = 0; i < TPACPI_LED_NUMLEDS; i++) {
4757 if (tpacpi_leds[i].led_classdev.name)
4758 led_classdev_unregister(&tpacpi_leds[i].led_classdev);
4764 static int __init led_init(struct ibm_init_struct *iibm)
4769 vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n");
4771 TPACPI_ACPIHANDLE_INIT(led);
4774 /* led not supported on R30, R31 */
4775 led_supported = TPACPI_LED_NONE;
4776 else if (strlencmp(led_path, "SLED") == 0)
4778 led_supported = TPACPI_LED_570;
4779 else if (strlencmp(led_path, "SYSL") == 0)
4780 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4781 led_supported = TPACPI_LED_OLD;
4784 led_supported = TPACPI_LED_NEW;
4786 vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n",
4787 str_supported(led_supported), led_supported);
4789 tpacpi_leds = kzalloc(sizeof(*tpacpi_leds) * TPACPI_LED_NUMLEDS,
4792 printk(TPACPI_ERR "Out of memory for LED data\n");
4796 for (i = 0; i < TPACPI_LED_NUMLEDS; i++) {
4797 tpacpi_leds[i].led = i;
4799 tpacpi_leds[i].led_classdev.brightness_set = &led_sysfs_set;
4800 tpacpi_leds[i].led_classdev.blink_set = &led_sysfs_blink_set;
4801 if (led_supported == TPACPI_LED_570)
4802 tpacpi_leds[i].led_classdev.brightness_get =
4805 tpacpi_leds[i].led_classdev.name = tpacpi_led_names[i];
4807 INIT_WORK(&tpacpi_leds[i].work, led_set_status_worker);
4809 rc = led_classdev_register(&tpacpi_pdev->dev,
4810 &tpacpi_leds[i].led_classdev);
4812 tpacpi_leds[i].led_classdev.name = NULL;
4818 return (led_supported != TPACPI_LED_NONE)? 0 : 1;
4821 #define str_led_status(s) \
4822 ((s) == TPACPI_LED_OFF ? "off" : \
4823 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
4825 static int led_read(char *p)
4829 if (!led_supported) {
4830 len += sprintf(p + len, "status:\t\tnot supported\n");
4833 len += sprintf(p + len, "status:\t\tsupported\n");
4835 if (led_supported == TPACPI_LED_570) {
4838 for (i = 0; i < 8; i++) {
4839 status = led_get_status(i);
4842 len += sprintf(p + len, "%d:\t\t%s\n",
4843 i, str_led_status(status));
4847 len += sprintf(p + len, "commands:\t"
4848 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
4853 static int led_write(char *buf)
4857 enum led_status_t s;
4862 while ((cmd = next_cmd(&buf))) {
4863 if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7)
4866 if (strstr(cmd, "off")) {
4868 } else if (strstr(cmd, "on")) {
4870 } else if (strstr(cmd, "blink")) {
4871 s = TPACPI_LED_BLINK;
4876 rc = led_set_status(led, s);
4884 static struct ibm_struct led_driver_data = {
4891 /*************************************************************************
4895 TPACPI_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */
4897 static int __init beep_init(struct ibm_init_struct *iibm)
4899 vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n");
4901 TPACPI_ACPIHANDLE_INIT(beep);
4903 vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n",
4904 str_supported(beep_handle != NULL));
4906 return (beep_handle)? 0 : 1;
4909 static int beep_read(char *p)
4914 len += sprintf(p + len, "status:\t\tnot supported\n");
4916 len += sprintf(p + len, "status:\t\tsupported\n");
4917 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n");
4923 static int beep_write(char *buf)
4931 while ((cmd = next_cmd(&buf))) {
4932 if (sscanf(cmd, "%u", &beep_cmd) == 1 &&
4933 beep_cmd >= 0 && beep_cmd <= 17) {
4937 if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0))
4944 static struct ibm_struct beep_driver_data = {
4947 .write = beep_write,
4950 /*************************************************************************
4954 enum thermal_access_mode {
4955 TPACPI_THERMAL_NONE = 0, /* No thermal support */
4956 TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
4957 TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
4958 TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */
4959 TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
4962 enum { /* TPACPI_THERMAL_TPEC_* */
4963 TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */
4964 TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */
4965 TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */
4968 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
4969 struct ibm_thermal_sensors_struct {
4970 s32 temp[TPACPI_MAX_THERMAL_SENSORS];
4973 static enum thermal_access_mode thermal_read_mode;
4975 /* idx is zero-based */
4976 static int thermal_get_sensor(int idx, s32 *value)
4982 t = TP_EC_THERMAL_TMP0;
4984 switch (thermal_read_mode) {
4985 #if TPACPI_MAX_THERMAL_SENSORS >= 16
4986 case TPACPI_THERMAL_TPEC_16:
4987 if (idx >= 8 && idx <= 15) {
4988 t = TP_EC_THERMAL_TMP8;
4993 case TPACPI_THERMAL_TPEC_8:
4995 if (!acpi_ec_read(t + idx, &tmp))
4997 *value = tmp * 1000;
5002 case TPACPI_THERMAL_ACPI_UPDT:
5004 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
5005 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
5007 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
5009 *value = (t - 2732) * 100;
5014 case TPACPI_THERMAL_ACPI_TMP07:
5016 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
5017 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
5019 if (t > 127 || t < -127)
5020 t = TP_EC_THERMAL_TMP_NA;
5026 case TPACPI_THERMAL_NONE:
5034 static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
5045 if (thermal_read_mode == TPACPI_THERMAL_TPEC_16)
5048 for (i = 0 ; i < n; i++) {
5049 res = thermal_get_sensor(i, &s->temp[i]);
5057 /* sysfs temp##_input -------------------------------------------------- */
5059 static ssize_t thermal_temp_input_show(struct device *dev,
5060 struct device_attribute *attr,
5063 struct sensor_device_attribute *sensor_attr =
5064 to_sensor_dev_attr(attr);
5065 int idx = sensor_attr->index;
5069 res = thermal_get_sensor(idx, &value);
5072 if (value == TP_EC_THERMAL_TMP_NA * 1000)
5075 return snprintf(buf, PAGE_SIZE, "%d\n", value);
5078 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5079 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5080 thermal_temp_input_show, NULL, _idxB)
5082 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = {
5083 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5084 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5085 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5086 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5087 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5088 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5089 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5090 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5091 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5092 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5093 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5094 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5095 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5096 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5097 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5098 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5101 #define THERMAL_ATTRS(X) \
5102 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5104 static struct attribute *thermal_temp_input_attr[] = {
5124 static const struct attribute_group thermal_temp_input16_group = {
5125 .attrs = thermal_temp_input_attr
5128 static const struct attribute_group thermal_temp_input8_group = {
5129 .attrs = &thermal_temp_input_attr[8]
5132 #undef THERMAL_SENSOR_ATTR_TEMP
5133 #undef THERMAL_ATTRS
5135 /* --------------------------------------------------------------------- */
5137 static int __init thermal_init(struct ibm_init_struct *iibm)
5144 vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n");
5146 acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
5148 if (thinkpad_id.ec_model) {
5150 * Direct EC access mode: sensors at registers
5151 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5152 * non-implemented, thermal sensors return 0x80 when
5157 for (i = 0; i < 8; i++) {
5158 if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) {
5164 if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) {
5172 /* This is sheer paranoia, but we handle it anyway */
5175 "ThinkPad ACPI EC access misbehaving, "
5176 "falling back to ACPI TMPx access "
5178 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
5181 "ThinkPad ACPI EC access misbehaving, "
5182 "disabling thermal sensors access\n");
5183 thermal_read_mode = TPACPI_THERMAL_NONE;
5188 TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8;
5190 } else if (acpi_tmp7) {
5191 if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
5192 /* 600e/x, 770e, 770x */
5193 thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT;
5195 /* Standard ACPI TMPx access, max 8 sensors */
5196 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
5199 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5200 thermal_read_mode = TPACPI_THERMAL_NONE;
5203 vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n",
5204 str_supported(thermal_read_mode != TPACPI_THERMAL_NONE),
5207 switch (thermal_read_mode) {
5208 case TPACPI_THERMAL_TPEC_16:
5209 res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj,
5210 &thermal_temp_input16_group);
5214 case TPACPI_THERMAL_TPEC_8:
5215 case TPACPI_THERMAL_ACPI_TMP07:
5216 case TPACPI_THERMAL_ACPI_UPDT:
5217 res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj,
5218 &thermal_temp_input8_group);
5222 case TPACPI_THERMAL_NONE:
5230 static void thermal_exit(void)
5232 switch (thermal_read_mode) {
5233 case TPACPI_THERMAL_TPEC_16:
5234 sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj,
5235 &thermal_temp_input16_group);
5237 case TPACPI_THERMAL_TPEC_8:
5238 case TPACPI_THERMAL_ACPI_TMP07:
5239 case TPACPI_THERMAL_ACPI_UPDT:
5240 sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj,
5241 &thermal_temp_input16_group);
5243 case TPACPI_THERMAL_NONE:
5249 static int thermal_read(char *p)
5253 struct ibm_thermal_sensors_struct t;
5255 n = thermal_get_sensors(&t);
5256 if (unlikely(n < 0))
5259 len += sprintf(p + len, "temperatures:\t");
5262 for (i = 0; i < (n - 1); i++)
5263 len += sprintf(p + len, "%d ", t.temp[i] / 1000);
5264 len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
5266 len += sprintf(p + len, "not supported\n");
5271 static struct ibm_struct thermal_driver_data = {
5273 .read = thermal_read,
5274 .exit = thermal_exit,
5277 /*************************************************************************
5281 static u8 ecdump_regs[256];
5283 static int ecdump_read(char *p)
5289 len += sprintf(p + len, "EC "
5290 " +00 +01 +02 +03 +04 +05 +06 +07"
5291 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5292 for (i = 0; i < 256; i += 16) {
5293 len += sprintf(p + len, "EC 0x%02x:", i);
5294 for (j = 0; j < 16; j++) {
5295 if (!acpi_ec_read(i + j, &v))
5297 if (v != ecdump_regs[i + j])
5298 len += sprintf(p + len, " *%02x", v);
5300 len += sprintf(p + len, " %02x", v);
5301 ecdump_regs[i + j] = v;
5303 len += sprintf(p + len, "\n");
5308 /* These are way too dangerous to advertise openly... */
5310 len += sprintf(p + len, "commands:\t0x<offset> 0x<value>"
5311 " (<offset> is 00-ff, <value> is 00-ff)\n");
5312 len += sprintf(p + len, "commands:\t0x<offset> <value> "
5313 " (<offset> is 00-ff, <value> is 0-255)\n");
5318 static int ecdump_write(char *buf)
5323 while ((cmd = next_cmd(&buf))) {
5324 if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) {
5326 } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) {
5330 if (i >= 0 && i < 256 && v >= 0 && v < 256) {
5331 if (!acpi_ec_write(i, v))
5340 static struct ibm_struct ecdump_driver_data = {
5342 .read = ecdump_read,
5343 .write = ecdump_write,
5344 .flags.experimental = 1,
5347 /*************************************************************************
5348 * Backlight/brightness subdriver
5351 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5354 TP_EC_BACKLIGHT = 0x31,
5356 /* TP_EC_BACKLIGHT bitmasks */
5357 TP_EC_BACKLIGHT_LVLMSK = 0x1F,
5358 TP_EC_BACKLIGHT_CMDMSK = 0xE0,
5359 TP_EC_BACKLIGHT_MAPSW = 0x20,
5362 static struct backlight_device *ibm_backlight_device;
5363 static int brightness_mode;
5364 static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */
5366 static struct mutex brightness_mutex;
5369 * ThinkPads can read brightness from two places: EC 0x31, or
5370 * CMOS NVRAM byte 0x5E, bits 0-3.
5372 * EC 0x31 has the following layout
5373 * Bit 7: unknown function
5374 * Bit 6: unknown function
5375 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5376 * Bit 4: must be set to zero to avoid problems
5377 * Bit 3-0: backlight brightness level
5379 * brightness_get_raw returns status data in the EC 0x31 layout
5381 static int brightness_get_raw(int *status)
5383 u8 lec = 0, lcmos = 0, level = 0;
5385 if (brightness_mode & 1) {
5386 if (!acpi_ec_read(TP_EC_BACKLIGHT, &lec))
5388 level = lec & TP_EC_BACKLIGHT_LVLMSK;
5390 if (brightness_mode & 2) {
5391 lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS)
5392 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS)
5393 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS;
5394 lcmos &= (tp_features.bright_16levels)? 0x0f : 0x07;
5398 if (brightness_mode == 3) {
5399 *status = lec; /* Prefer EC, CMOS is just a backing store */
5400 lec &= TP_EC_BACKLIGHT_LVLMSK;
5402 tp_warned.bright_cmos_ec_unsync = 0;
5404 if (!tp_warned.bright_cmos_ec_unsync) {
5406 "CMOS NVRAM (%u) and EC (%u) do not "
5407 "agree on display brightness level\n",
5408 (unsigned int) lcmos,
5409 (unsigned int) lec);
5410 tp_warned.bright_cmos_ec_unsync = 1;
5421 /* May return EINTR which can always be mapped to ERESTARTSYS */
5422 static int brightness_set(int value)
5424 int cmos_cmd, inc, i, res;
5428 if (value > ((tp_features.bright_16levels)? 15 : 7) ||
5432 res = mutex_lock_killable(&brightness_mutex);
5436 res = brightness_get_raw(¤t_value);
5440 command_bits = current_value & TP_EC_BACKLIGHT_CMDMSK;
5441 current_value &= TP_EC_BACKLIGHT_LVLMSK;
5443 cmos_cmd = value > current_value ?
5444 TP_CMOS_BRIGHTNESS_UP :
5445 TP_CMOS_BRIGHTNESS_DOWN;
5446 inc = (value > current_value)? 1 : -1;
5449 for (i = current_value; i != value; i += inc) {
5450 if ((brightness_mode & 2) &&
5451 issue_thinkpad_cmos_command(cmos_cmd)) {
5455 if ((brightness_mode & 1) &&
5456 !acpi_ec_write(TP_EC_BACKLIGHT,
5457 (i + inc) | command_bits)) {
5464 mutex_unlock(&brightness_mutex);
5468 /* sysfs backlight class ----------------------------------------------- */
5470 static int brightness_update_status(struct backlight_device *bd)
5472 /* it is the backlight class's job (caller) to handle
5473 * EINTR and other errors properly */
5474 return brightness_set(
5475 (bd->props.fb_blank == FB_BLANK_UNBLANK &&
5476 bd->props.power == FB_BLANK_UNBLANK) ?
5477 bd->props.brightness : 0);
5480 static int brightness_get(struct backlight_device *bd)
5484 res = brightness_get_raw(&status);
5486 return 0; /* FIXME: teach backlight about error handling */
5488 return status & TP_EC_BACKLIGHT_LVLMSK;
5491 static struct backlight_ops ibm_backlight_data = {
5492 .get_brightness = brightness_get,
5493 .update_status = brightness_update_status,
5496 /* --------------------------------------------------------------------- */
5498 static int __init brightness_init(struct ibm_init_struct *iibm)
5502 vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n");
5504 mutex_init(&brightness_mutex);
5507 * We always attempt to detect acpi support, so as to switch
5508 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
5509 * going to publish a backlight interface
5511 b = tpacpi_check_std_acpi_brightness_support();
5514 if (acpi_video_backlight_support()) {
5515 if (brightness_enable > 1) {
5516 printk(TPACPI_NOTICE
5517 "Standard ACPI backlight interface "
5518 "available, not loading native one.\n");
5520 } else if (brightness_enable == 1) {
5521 printk(TPACPI_NOTICE
5522 "Backlight control force enabled, even if standard "
5523 "ACPI backlight interface is available\n");
5526 if (brightness_enable > 1) {
5527 printk(TPACPI_NOTICE
5528 "Standard ACPI backlight interface not "
5529 "available, thinkpad_acpi native "
5530 "brightness control enabled\n");
5535 if (!brightness_enable) {
5536 dbg_printk(TPACPI_DBG_INIT,
5537 "brightness support disabled by "
5538 "module parameter\n");
5544 "Unsupported brightness interface, "
5545 "please contact %s\n", TPACPI_MAIL);
5549 tp_features.bright_16levels = 1;
5551 if (!brightness_mode) {
5552 if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO)
5553 brightness_mode = 2;
5555 brightness_mode = 3;
5557 dbg_printk(TPACPI_DBG_INIT, "selected brightness_mode=%d\n",
5561 if (brightness_mode > 3)
5564 if (brightness_get_raw(&b) < 0)
5567 if (tp_features.bright_16levels)
5569 "detected a 16-level brightness capable ThinkPad\n");
5571 ibm_backlight_device = backlight_device_register(
5572 TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL,
5573 &ibm_backlight_data);
5574 if (IS_ERR(ibm_backlight_device)) {
5575 printk(TPACPI_ERR "Could not register backlight device\n");
5576 return PTR_ERR(ibm_backlight_device);
5578 vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n");
5580 ibm_backlight_device->props.max_brightness =
5581 (tp_features.bright_16levels)? 15 : 7;
5582 ibm_backlight_device->props.brightness = b & TP_EC_BACKLIGHT_LVLMSK;
5583 backlight_update_status(ibm_backlight_device);
5588 static void brightness_exit(void)
5590 if (ibm_backlight_device) {
5591 vdbg_printk(TPACPI_DBG_EXIT,
5592 "calling backlight_device_unregister()\n");
5593 backlight_device_unregister(ibm_backlight_device);
5597 static int brightness_read(char *p)
5602 level = brightness_get(NULL);
5604 len += sprintf(p + len, "level:\t\tunreadable\n");
5606 len += sprintf(p + len, "level:\t\t%d\n", level);
5607 len += sprintf(p + len, "commands:\tup, down\n");
5608 len += sprintf(p + len, "commands:\tlevel <level>"
5609 " (<level> is 0-%d)\n",
5610 (tp_features.bright_16levels) ? 15 : 7);
5616 static int brightness_write(char *buf)
5621 int max_level = (tp_features.bright_16levels) ? 15 : 7;
5623 level = brightness_get(NULL);
5627 while ((cmd = next_cmd(&buf))) {
5628 if (strlencmp(cmd, "up") == 0) {
5629 if (level < max_level)
5631 } else if (strlencmp(cmd, "down") == 0) {
5634 } else if (sscanf(cmd, "level %d", &level) == 1 &&
5635 level >= 0 && level <= max_level) {
5642 * Now we know what the final level should be, so we try to set it.
5643 * Doing it this way makes the syscall restartable in case of EINTR
5645 rc = brightness_set(level);
5646 return (rc == -EINTR)? ERESTARTSYS : rc;
5649 static struct ibm_struct brightness_driver_data = {
5650 .name = "brightness",
5651 .read = brightness_read,
5652 .write = brightness_write,
5653 .exit = brightness_exit,
5656 /*************************************************************************
5660 static int volume_offset = 0x30;
5662 static int volume_read(char *p)
5667 if (!acpi_ec_read(volume_offset, &level)) {
5668 len += sprintf(p + len, "level:\t\tunreadable\n");
5670 len += sprintf(p + len, "level:\t\t%d\n", level & 0xf);
5671 len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6));
5672 len += sprintf(p + len, "commands:\tup, down, mute\n");
5673 len += sprintf(p + len, "commands:\tlevel <level>"
5674 " (<level> is 0-15)\n");
5680 static int volume_write(char *buf)
5682 int cmos_cmd, inc, i;
5684 int new_level, new_mute;
5687 while ((cmd = next_cmd(&buf))) {
5688 if (!acpi_ec_read(volume_offset, &level))
5690 new_mute = mute = level & 0x40;
5691 new_level = level = level & 0xf;
5693 if (strlencmp(cmd, "up") == 0) {
5697 new_level = level == 15 ? 15 : level + 1;
5698 } else if (strlencmp(cmd, "down") == 0) {
5702 new_level = level == 0 ? 0 : level - 1;
5703 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
5704 new_level >= 0 && new_level <= 15) {
5706 } else if (strlencmp(cmd, "mute") == 0) {
5711 if (new_level != level) {
5712 /* mute doesn't change */
5714 cmos_cmd = (new_level > level) ?
5715 TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN;
5716 inc = new_level > level ? 1 : -1;
5718 if (mute && (issue_thinkpad_cmos_command(cmos_cmd) ||
5719 !acpi_ec_write(volume_offset, level)))
5722 for (i = level; i != new_level; i += inc)
5723 if (issue_thinkpad_cmos_command(cmos_cmd) ||
5724 !acpi_ec_write(volume_offset, i + inc))
5728 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) ||
5729 !acpi_ec_write(volume_offset, new_level + mute))) {
5734 if (new_mute != mute) {
5735 /* level doesn't change */
5737 cmos_cmd = (new_mute) ?
5738 TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP;
5740 if (issue_thinkpad_cmos_command(cmos_cmd) ||
5741 !acpi_ec_write(volume_offset, level + new_mute))
5749 static struct ibm_struct volume_driver_data = {
5751 .read = volume_read,
5752 .write = volume_write,
5755 /*************************************************************************
5762 * TPACPI_FAN_RD_ACPI_GFAN:
5763 * ACPI GFAN method: returns fan level
5765 * see TPACPI_FAN_WR_ACPI_SFAN
5766 * EC 0x2f (HFSP) not available if GFAN exists
5768 * TPACPI_FAN_WR_ACPI_SFAN:
5769 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
5771 * EC 0x2f (HFSP) might be available *for reading*, but do not use
5774 * TPACPI_FAN_WR_TPEC:
5775 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
5776 * Supported on almost all ThinkPads
5778 * Fan speed changes of any sort (including those caused by the
5779 * disengaged mode) are usually done slowly by the firmware as the
5780 * maximum ammount of fan duty cycle change per second seems to be
5783 * Reading is not available if GFAN exists.
5784 * Writing is not available if SFAN exists.
5787 * 7 automatic mode engaged;
5788 * (default operation mode of the ThinkPad)
5789 * fan level is ignored in this mode.
5790 * 6 full speed mode (takes precedence over bit 7);
5791 * not available on all thinkpads. May disable
5792 * the tachometer while the fan controller ramps up
5793 * the speed (which can take up to a few *minutes*).
5794 * Speeds up fan to 100% duty-cycle, which is far above
5795 * the standard RPM levels. It is not impossible that
5796 * it could cause hardware damage.
5797 * 5-3 unused in some models. Extra bits for fan level
5798 * in others, but still useless as all values above
5799 * 7 map to the same speed as level 7 in these models.
5800 * 2-0 fan level (0..7 usually)
5802 * 0x07 = max (set when temperatures critical)
5803 * Some ThinkPads may have other levels, see
5804 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
5806 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
5807 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
5808 * does so, its initial value is meaningless (0x07).
5810 * For firmware bugs, refer to:
5811 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5815 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
5816 * Main fan tachometer reading (in RPM)
5818 * This register is present on all ThinkPads with a new-style EC, and
5819 * it is known not to be present on the A21m/e, and T22, as there is
5820 * something else in offset 0x84 according to the ACPI DSDT. Other
5821 * ThinkPads from this same time period (and earlier) probably lack the
5822 * tachometer as well.
5824 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
5825 * was never fixed by IBM to report the EC firmware version string
5826 * probably support the tachometer (like the early X models), so
5827 * detecting it is quite hard. We need more data to know for sure.
5829 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
5832 * FIRMWARE BUG: may go stale while the EC is switching to full speed
5835 * For firmware bugs, refer to:
5836 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5838 * TPACPI_FAN_WR_ACPI_FANS:
5839 * ThinkPad X31, X40, X41. Not available in the X60.
5841 * FANS ACPI handle: takes three arguments: low speed, medium speed,
5842 * high speed. ACPI DSDT seems to map these three speeds to levels
5843 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
5844 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
5846 * The speeds are stored on handles
5847 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
5849 * There are three default speed sets, acessible as handles:
5850 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
5852 * ACPI DSDT switches which set is in use depending on various
5855 * TPACPI_FAN_WR_TPEC is also available and should be used to
5856 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
5857 * but the ACPI tables just mention level 7.
5860 enum { /* Fan control constants */
5861 fan_status_offset = 0x2f, /* EC register 0x2f */
5862 fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
5863 * 0x84 must be read before 0x85 */
5865 TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */
5866 TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */
5868 TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */
5871 enum fan_status_access_mode {
5872 TPACPI_FAN_NONE = 0, /* No fan status or control */
5873 TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */
5874 TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
5877 enum fan_control_access_mode {
5878 TPACPI_FAN_WR_NONE = 0, /* No fan control */
5879 TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */
5880 TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */
5881 TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */
5884 enum fan_control_commands {
5885 TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */
5886 TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */
5887 TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd,
5888 * and also watchdog cmd */
5891 static int fan_control_allowed;
5893 static enum fan_status_access_mode fan_status_access_mode;
5894 static enum fan_control_access_mode fan_control_access_mode;
5895 static enum fan_control_commands fan_control_commands;
5897 static u8 fan_control_initial_status;
5898 static u8 fan_control_desired_level;
5899 static u8 fan_control_resume_level;
5900 static int fan_watchdog_maxinterval;
5902 static struct mutex fan_mutex;
5904 static void fan_watchdog_fire(struct work_struct *ignored);
5905 static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire);
5907 TPACPI_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */
5908 TPACPI_HANDLE(gfan, ec, "GFAN", /* 570 */
5909 "\\FSPD", /* 600e/x, 770e, 770x */
5911 TPACPI_HANDLE(sfan, ec, "SFAN", /* 570 */
5912 "JFNS", /* 770x-JL */
5916 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
5917 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
5918 * be in auto mode (0x80).
5920 * This is corrected by any write to HFSP either by the driver, or
5923 * We assume 0x07 really means auto mode while this quirk is active,
5924 * as this is far more likely than the ThinkPad being in level 7,
5925 * which is only used by the firmware during thermal emergencies.
5928 static void fan_quirk1_detect(void)
5930 /* In some ThinkPads, neither the EC nor the ACPI
5931 * DSDT initialize the HFSP register, and it ends up
5932 * being initially set to 0x07 when it *could* be
5933 * either 0x07 or 0x80.
5935 * Enable for TP-1Y (T43), TP-78 (R51e),
5936 * TP-76 (R52), TP-70 (T43, R52), which are known
5938 if (fan_control_initial_status == 0x07) {
5939 switch (thinkpad_id.ec_model) {
5940 case 0x5931: /* TP-1Y */
5941 case 0x3837: /* TP-78 */
5942 case 0x3637: /* TP-76 */
5943 case 0x3037: /* TP-70 */
5944 printk(TPACPI_NOTICE
5945 "fan_init: initial fan status is unknown, "
5946 "assuming it is in auto mode\n");
5947 tp_features.fan_ctrl_status_undef = 1;
5953 static void fan_quirk1_handle(u8 *fan_status)
5955 if (unlikely(tp_features.fan_ctrl_status_undef)) {
5956 if (*fan_status != fan_control_initial_status) {
5957 /* something changed the HFSP regisnter since
5958 * driver init time, so it is not undefined
5960 tp_features.fan_ctrl_status_undef = 0;
5962 /* Return most likely status. In fact, it
5963 * might be the only possible status */
5964 *fan_status = TP_EC_FAN_AUTO;
5970 * Call with fan_mutex held
5972 static void fan_update_desired_level(u8 status)
5975 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) {
5977 fan_control_desired_level = 7;
5979 fan_control_desired_level = status;
5983 static int fan_get_status(u8 *status)
5988 * Add TPACPI_FAN_RD_ACPI_FANS ? */
5990 switch (fan_status_access_mode) {
5991 case TPACPI_FAN_RD_ACPI_GFAN:
5992 /* 570, 600e/x, 770e, 770x */
5994 if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
6002 case TPACPI_FAN_RD_TPEC:
6003 /* all except 570, 600e/x, 770e, 770x */
6004 if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
6007 if (likely(status)) {
6009 fan_quirk1_handle(status);
6021 static int fan_get_status_safe(u8 *status)
6026 if (mutex_lock_killable(&fan_mutex))
6027 return -ERESTARTSYS;
6028 rc = fan_get_status(&s);
6030 fan_update_desired_level(s);
6031 mutex_unlock(&fan_mutex);
6039 static int fan_get_speed(unsigned int *speed)
6043 switch (fan_status_access_mode) {
6044 case TPACPI_FAN_RD_TPEC:
6045 /* all except 570, 600e/x, 770e, 770x */
6046 if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
6047 !acpi_ec_read(fan_rpm_offset + 1, &hi)))
6051 *speed = (hi << 8) | lo;
6062 static int fan_set_level(int level)
6064 if (!fan_control_allowed)
6067 switch (fan_control_access_mode) {
6068 case TPACPI_FAN_WR_ACPI_SFAN:
6069 if (level >= 0 && level <= 7) {
6070 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
6076 case TPACPI_FAN_WR_ACPI_FANS:
6077 case TPACPI_FAN_WR_TPEC:
6078 if (!(level & TP_EC_FAN_AUTO) &&
6079 !(level & TP_EC_FAN_FULLSPEED) &&
6080 ((level < 0) || (level > 7)))
6083 /* safety net should the EC not support AUTO
6084 * or FULLSPEED mode bits and just ignore them */
6085 if (level & TP_EC_FAN_FULLSPEED)
6086 level |= 7; /* safety min speed 7 */
6087 else if (level & TP_EC_FAN_AUTO)
6088 level |= 4; /* safety min speed 4 */
6090 if (!acpi_ec_write(fan_status_offset, level))
6093 tp_features.fan_ctrl_status_undef = 0;
6102 static int fan_set_level_safe(int level)
6106 if (!fan_control_allowed)
6109 if (mutex_lock_killable(&fan_mutex))
6110 return -ERESTARTSYS;
6112 if (level == TPACPI_FAN_LAST_LEVEL)
6113 level = fan_control_desired_level;
6115 rc = fan_set_level(level);
6117 fan_update_desired_level(level);
6119 mutex_unlock(&fan_mutex);
6123 static int fan_set_enable(void)
6128 if (!fan_control_allowed)
6131 if (mutex_lock_killable(&fan_mutex))
6132 return -ERESTARTSYS;
6134 switch (fan_control_access_mode) {
6135 case TPACPI_FAN_WR_ACPI_FANS:
6136 case TPACPI_FAN_WR_TPEC:
6137 rc = fan_get_status(&s);
6141 /* Don't go out of emergency fan mode */
6144 s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */
6147 if (!acpi_ec_write(fan_status_offset, s))
6150 tp_features.fan_ctrl_status_undef = 0;
6155 case TPACPI_FAN_WR_ACPI_SFAN:
6156 rc = fan_get_status(&s);
6162 /* Set fan to at least level 4 */
6165 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s))
6175 mutex_unlock(&fan_mutex);
6179 static int fan_set_disable(void)
6183 if (!fan_control_allowed)
6186 if (mutex_lock_killable(&fan_mutex))
6187 return -ERESTARTSYS;
6190 switch (fan_control_access_mode) {
6191 case TPACPI_FAN_WR_ACPI_FANS:
6192 case TPACPI_FAN_WR_TPEC:
6193 if (!acpi_ec_write(fan_status_offset, 0x00))
6196 fan_control_desired_level = 0;
6197 tp_features.fan_ctrl_status_undef = 0;
6201 case TPACPI_FAN_WR_ACPI_SFAN:
6202 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00))
6205 fan_control_desired_level = 0;
6213 mutex_unlock(&fan_mutex);
6217 static int fan_set_speed(int speed)
6221 if (!fan_control_allowed)
6224 if (mutex_lock_killable(&fan_mutex))
6225 return -ERESTARTSYS;
6228 switch (fan_control_access_mode) {
6229 case TPACPI_FAN_WR_ACPI_FANS:
6230 if (speed >= 0 && speed <= 65535) {
6231 if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
6232 speed, speed, speed))
6242 mutex_unlock(&fan_mutex);
6246 static void fan_watchdog_reset(void)
6248 static int fan_watchdog_active;
6250 if (fan_control_access_mode == TPACPI_FAN_WR_NONE)
6253 if (fan_watchdog_active)
6254 cancel_delayed_work(&fan_watchdog_task);
6256 if (fan_watchdog_maxinterval > 0 &&
6257 tpacpi_lifecycle != TPACPI_LIFE_EXITING) {
6258 fan_watchdog_active = 1;
6259 if (!queue_delayed_work(tpacpi_wq, &fan_watchdog_task,
6260 msecs_to_jiffies(fan_watchdog_maxinterval
6263 "failed to queue the fan watchdog, "
6264 "watchdog will not trigger\n");
6267 fan_watchdog_active = 0;
6270 static void fan_watchdog_fire(struct work_struct *ignored)
6274 if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING)
6277 printk(TPACPI_NOTICE "fan watchdog: enabling fan\n");
6278 rc = fan_set_enable();
6280 printk(TPACPI_ERR "fan watchdog: error %d while enabling fan, "
6281 "will try again later...\n", -rc);
6282 /* reschedule for later */
6283 fan_watchdog_reset();
6288 * SYSFS fan layout: hwmon compatible (device)
6291 * 0: "disengaged" mode
6293 * 2: native EC "auto" mode (recommended, hardware default)
6295 * pwm*: set speed in manual mode, ignored otherwise.
6296 * 0 is level 0; 255 is level 7. Intermediate points done with linear
6299 * fan*_input: tachometer reading, RPM
6302 * SYSFS fan layout: extensions
6304 * fan_watchdog (driver):
6305 * fan watchdog interval in seconds, 0 disables (default), max 120
6308 /* sysfs fan pwm1_enable ----------------------------------------------- */
6309 static ssize_t fan_pwm1_enable_show(struct device *dev,
6310 struct device_attribute *attr,
6316 res = fan_get_status_safe(&status);
6320 if (status & TP_EC_FAN_FULLSPEED) {
6322 } else if (status & TP_EC_FAN_AUTO) {
6327 return snprintf(buf, PAGE_SIZE, "%d\n", mode);
6330 static ssize_t fan_pwm1_enable_store(struct device *dev,
6331 struct device_attribute *attr,
6332 const char *buf, size_t count)
6337 if (parse_strtoul(buf, 2, &t))
6342 level = TP_EC_FAN_FULLSPEED;
6345 level = TPACPI_FAN_LAST_LEVEL;
6348 level = TP_EC_FAN_AUTO;
6351 /* reserved for software-controlled auto mode */
6357 res = fan_set_level_safe(level);
6363 fan_watchdog_reset();
6368 static struct device_attribute dev_attr_fan_pwm1_enable =
6369 __ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
6370 fan_pwm1_enable_show, fan_pwm1_enable_store);
6372 /* sysfs fan pwm1 ------------------------------------------------------ */
6373 static ssize_t fan_pwm1_show(struct device *dev,
6374 struct device_attribute *attr,
6380 res = fan_get_status_safe(&status);
6385 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0)
6386 status = fan_control_desired_level;
6391 return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7);
6394 static ssize_t fan_pwm1_store(struct device *dev,
6395 struct device_attribute *attr,
6396 const char *buf, size_t count)
6400 u8 status, newlevel;
6402 if (parse_strtoul(buf, 255, &s))
6405 /* scale down from 0-255 to 0-7 */
6406 newlevel = (s >> 5) & 0x07;
6408 if (mutex_lock_killable(&fan_mutex))
6409 return -ERESTARTSYS;
6411 rc = fan_get_status(&status);
6412 if (!rc && (status &
6413 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) {
6414 rc = fan_set_level(newlevel);
6418 fan_update_desired_level(newlevel);
6419 fan_watchdog_reset();
6423 mutex_unlock(&fan_mutex);
6424 return (rc)? rc : count;
6427 static struct device_attribute dev_attr_fan_pwm1 =
6428 __ATTR(pwm1, S_IWUSR | S_IRUGO,
6429 fan_pwm1_show, fan_pwm1_store);
6431 /* sysfs fan fan1_input ------------------------------------------------ */
6432 static ssize_t fan_fan1_input_show(struct device *dev,
6433 struct device_attribute *attr,
6439 res = fan_get_speed(&speed);
6443 return snprintf(buf, PAGE_SIZE, "%u\n", speed);
6446 static struct device_attribute dev_attr_fan_fan1_input =
6447 __ATTR(fan1_input, S_IRUGO,
6448 fan_fan1_input_show, NULL);
6450 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
6451 static ssize_t fan_fan_watchdog_show(struct device_driver *drv,
6454 return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval);
6457 static ssize_t fan_fan_watchdog_store(struct device_driver *drv,
6458 const char *buf, size_t count)
6462 if (parse_strtoul(buf, 120, &t))
6465 if (!fan_control_allowed)
6468 fan_watchdog_maxinterval = t;
6469 fan_watchdog_reset();
6474 static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO,
6475 fan_fan_watchdog_show, fan_fan_watchdog_store);
6477 /* --------------------------------------------------------------------- */
6478 static struct attribute *fan_attributes[] = {
6479 &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr,
6480 &dev_attr_fan_fan1_input.attr,
6484 static const struct attribute_group fan_attr_group = {
6485 .attrs = fan_attributes,
6488 static int __init fan_init(struct ibm_init_struct *iibm)
6492 vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n");
6494 mutex_init(&fan_mutex);
6495 fan_status_access_mode = TPACPI_FAN_NONE;
6496 fan_control_access_mode = TPACPI_FAN_WR_NONE;
6497 fan_control_commands = 0;
6498 fan_watchdog_maxinterval = 0;
6499 tp_features.fan_ctrl_status_undef = 0;
6500 fan_control_desired_level = 7;
6502 TPACPI_ACPIHANDLE_INIT(fans);
6503 TPACPI_ACPIHANDLE_INIT(gfan);
6504 TPACPI_ACPIHANDLE_INIT(sfan);
6507 /* 570, 600e/x, 770e, 770x */
6508 fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN;
6510 /* all other ThinkPads: note that even old-style
6511 * ThinkPad ECs supports the fan control register */
6512 if (likely(acpi_ec_read(fan_status_offset,
6513 &fan_control_initial_status))) {
6514 fan_status_access_mode = TPACPI_FAN_RD_TPEC;
6515 fan_quirk1_detect();
6518 "ThinkPad ACPI EC access misbehaving, "
6519 "fan status and control unavailable\n");
6526 fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN;
6527 fan_control_commands |=
6528 TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE;
6531 /* gfan without sfan means no fan control */
6532 /* all other models implement TP EC 0x2f control */
6536 fan_control_access_mode =
6537 TPACPI_FAN_WR_ACPI_FANS;
6538 fan_control_commands |=
6539 TPACPI_FAN_CMD_SPEED |
6540 TPACPI_FAN_CMD_LEVEL |
6541 TPACPI_FAN_CMD_ENABLE;
6543 fan_control_access_mode = TPACPI_FAN_WR_TPEC;
6544 fan_control_commands |=
6545 TPACPI_FAN_CMD_LEVEL |
6546 TPACPI_FAN_CMD_ENABLE;
6551 vdbg_printk(TPACPI_DBG_INIT, "fan is %s, modes %d, %d\n",
6552 str_supported(fan_status_access_mode != TPACPI_FAN_NONE ||
6553 fan_control_access_mode != TPACPI_FAN_WR_NONE),
6554 fan_status_access_mode, fan_control_access_mode);
6556 /* fan control master switch */
6557 if (!fan_control_allowed) {
6558 fan_control_access_mode = TPACPI_FAN_WR_NONE;
6559 fan_control_commands = 0;
6560 dbg_printk(TPACPI_DBG_INIT,
6561 "fan control features disabled by parameter\n");
6564 /* update fan_control_desired_level */
6565 if (fan_status_access_mode != TPACPI_FAN_NONE)
6566 fan_get_status_safe(NULL);
6568 if (fan_status_access_mode != TPACPI_FAN_NONE ||
6569 fan_control_access_mode != TPACPI_FAN_WR_NONE) {
6570 rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj,
6575 rc = driver_create_file(&tpacpi_hwmon_pdriver.driver,
6576 &driver_attr_fan_watchdog);
6578 sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj,
6587 static void fan_exit(void)
6589 vdbg_printk(TPACPI_DBG_EXIT,
6590 "cancelling any pending fan watchdog tasks\n");
6592 /* FIXME: can we really do this unconditionally? */
6593 sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, &fan_attr_group);
6594 driver_remove_file(&tpacpi_hwmon_pdriver.driver,
6595 &driver_attr_fan_watchdog);
6597 cancel_delayed_work(&fan_watchdog_task);
6598 flush_workqueue(tpacpi_wq);
6601 static void fan_suspend(pm_message_t state)
6605 if (!fan_control_allowed)
6608 /* Store fan status in cache */
6609 fan_control_resume_level = 0;
6610 rc = fan_get_status_safe(&fan_control_resume_level);
6612 printk(TPACPI_NOTICE
6613 "failed to read fan level for later "
6614 "restore during resume: %d\n", rc);
6616 /* if it is undefined, don't attempt to restore it.
6618 if (tp_features.fan_ctrl_status_undef)
6619 fan_control_resume_level = 0;
6622 static void fan_resume(void)
6624 u8 current_level = 7;
6625 bool do_set = false;
6628 /* DSDT *always* updates status on resume */
6629 tp_features.fan_ctrl_status_undef = 0;
6631 if (!fan_control_allowed ||
6632 !fan_control_resume_level ||
6633 (fan_get_status_safe(¤t_level) < 0))
6636 switch (fan_control_access_mode) {
6637 case TPACPI_FAN_WR_ACPI_SFAN:
6638 /* never decrease fan level */
6639 do_set = (fan_control_resume_level > current_level);
6641 case TPACPI_FAN_WR_ACPI_FANS:
6642 case TPACPI_FAN_WR_TPEC:
6643 /* never decrease fan level, scale is:
6644 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
6646 * We expect the firmware to set either 7 or AUTO, but we
6647 * handle FULLSPEED out of paranoia.
6649 * So, we can safely only restore FULLSPEED or 7, anything
6650 * else could slow the fan. Restoring AUTO is useless, at
6651 * best that's exactly what the DSDT already set (it is the
6654 * Always keep in mind that the DSDT *will* have set the
6655 * fans to what the vendor supposes is the best level. We
6656 * muck with it only to speed the fan up.
6658 if (fan_control_resume_level != 7 &&
6659 !(fan_control_resume_level & TP_EC_FAN_FULLSPEED))
6662 do_set = !(current_level & TP_EC_FAN_FULLSPEED) &&
6663 (current_level != fan_control_resume_level);
6669 printk(TPACPI_NOTICE
6670 "restoring fan level to 0x%02x\n",
6671 fan_control_resume_level);
6672 rc = fan_set_level_safe(fan_control_resume_level);
6674 printk(TPACPI_NOTICE
6675 "failed to restore fan level: %d\n", rc);
6679 static int fan_read(char *p)
6684 unsigned int speed = 0;
6686 switch (fan_status_access_mode) {
6687 case TPACPI_FAN_RD_ACPI_GFAN:
6688 /* 570, 600e/x, 770e, 770x */
6689 rc = fan_get_status_safe(&status);
6693 len += sprintf(p + len, "status:\t\t%s\n"
6695 (status != 0) ? "enabled" : "disabled", status);
6698 case TPACPI_FAN_RD_TPEC:
6699 /* all except 570, 600e/x, 770e, 770x */
6700 rc = fan_get_status_safe(&status);
6704 len += sprintf(p + len, "status:\t\t%s\n",
6705 (status != 0) ? "enabled" : "disabled");
6707 rc = fan_get_speed(&speed);
6711 len += sprintf(p + len, "speed:\t\t%d\n", speed);
6713 if (status & TP_EC_FAN_FULLSPEED)
6714 /* Disengaged mode takes precedence */
6715 len += sprintf(p + len, "level:\t\tdisengaged\n");
6716 else if (status & TP_EC_FAN_AUTO)
6717 len += sprintf(p + len, "level:\t\tauto\n");
6719 len += sprintf(p + len, "level:\t\t%d\n", status);
6722 case TPACPI_FAN_NONE:
6724 len += sprintf(p + len, "status:\t\tnot supported\n");
6727 if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) {
6728 len += sprintf(p + len, "commands:\tlevel <level>");
6730 switch (fan_control_access_mode) {
6731 case TPACPI_FAN_WR_ACPI_SFAN:
6732 len += sprintf(p + len, " (<level> is 0-7)\n");
6736 len += sprintf(p + len, " (<level> is 0-7, "
6737 "auto, disengaged, full-speed)\n");
6742 if (fan_control_commands & TPACPI_FAN_CMD_ENABLE)
6743 len += sprintf(p + len, "commands:\tenable, disable\n"
6744 "commands:\twatchdog <timeout> (<timeout> "
6745 "is 0 (off), 1-120 (seconds))\n");
6747 if (fan_control_commands & TPACPI_FAN_CMD_SPEED)
6748 len += sprintf(p + len, "commands:\tspeed <speed>"
6749 " (<speed> is 0-65535)\n");
6754 static int fan_write_cmd_level(const char *cmd, int *rc)
6758 if (strlencmp(cmd, "level auto") == 0)
6759 level = TP_EC_FAN_AUTO;
6760 else if ((strlencmp(cmd, "level disengaged") == 0) |
6761 (strlencmp(cmd, "level full-speed") == 0))
6762 level = TP_EC_FAN_FULLSPEED;
6763 else if (sscanf(cmd, "level %d", &level) != 1)
6766 *rc = fan_set_level_safe(level);
6768 printk(TPACPI_ERR "level command accepted for unsupported "
6769 "access mode %d", fan_control_access_mode);
6774 static int fan_write_cmd_enable(const char *cmd, int *rc)
6776 if (strlencmp(cmd, "enable") != 0)
6779 *rc = fan_set_enable();
6781 printk(TPACPI_ERR "enable command accepted for unsupported "
6782 "access mode %d", fan_control_access_mode);
6787 static int fan_write_cmd_disable(const char *cmd, int *rc)
6789 if (strlencmp(cmd, "disable") != 0)
6792 *rc = fan_set_disable();
6794 printk(TPACPI_ERR "disable command accepted for unsupported "
6795 "access mode %d", fan_control_access_mode);
6800 static int fan_write_cmd_speed(const char *cmd, int *rc)
6805 * Support speed <low> <medium> <high> ? */
6807 if (sscanf(cmd, "speed %d", &speed) != 1)
6810 *rc = fan_set_speed(speed);
6812 printk(TPACPI_ERR "speed command accepted for unsupported "
6813 "access mode %d", fan_control_access_mode);
6818 static int fan_write_cmd_watchdog(const char *cmd, int *rc)
6822 if (sscanf(cmd, "watchdog %d", &interval) != 1)
6825 if (interval < 0 || interval > 120)
6828 fan_watchdog_maxinterval = interval;
6833 static int fan_write(char *buf)
6838 while (!rc && (cmd = next_cmd(&buf))) {
6839 if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) &&
6840 fan_write_cmd_level(cmd, &rc)) &&
6841 !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) &&
6842 (fan_write_cmd_enable(cmd, &rc) ||
6843 fan_write_cmd_disable(cmd, &rc) ||
6844 fan_write_cmd_watchdog(cmd, &rc))) &&
6845 !((fan_control_commands & TPACPI_FAN_CMD_SPEED) &&
6846 fan_write_cmd_speed(cmd, &rc))
6850 fan_watchdog_reset();
6856 static struct ibm_struct fan_driver_data = {
6861 .suspend = fan_suspend,
6862 .resume = fan_resume,
6865 /****************************************************************************
6866 ****************************************************************************
6870 ****************************************************************************
6871 ****************************************************************************/
6873 /* sysfs name ---------------------------------------------------------- */
6874 static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev,
6875 struct device_attribute *attr,
6878 return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME);
6881 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name =
6882 __ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL);
6884 /* --------------------------------------------------------------------- */
6887 static struct proc_dir_entry *proc_dir;
6890 * Module and infrastructure proble, init and exit handling
6893 static int force_load;
6895 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
6896 static const char * __init str_supported(int is_supported)
6898 static char text_unsupported[] __initdata = "not supported";
6900 return (is_supported)? &text_unsupported[4] : &text_unsupported[0];
6902 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
6904 static void ibm_exit(struct ibm_struct *ibm)
6906 dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name);
6908 list_del_init(&ibm->all_drivers);
6910 if (ibm->flags.acpi_notify_installed) {
6911 dbg_printk(TPACPI_DBG_EXIT,
6912 "%s: acpi_remove_notify_handler\n", ibm->name);
6914 acpi_remove_notify_handler(*ibm->acpi->handle,
6916 dispatch_acpi_notify);
6917 ibm->flags.acpi_notify_installed = 0;
6918 ibm->flags.acpi_notify_installed = 0;
6921 if (ibm->flags.proc_created) {
6922 dbg_printk(TPACPI_DBG_EXIT,
6923 "%s: remove_proc_entry\n", ibm->name);
6924 remove_proc_entry(ibm->name, proc_dir);
6925 ibm->flags.proc_created = 0;
6928 if (ibm->flags.acpi_driver_registered) {
6929 dbg_printk(TPACPI_DBG_EXIT,
6930 "%s: acpi_bus_unregister_driver\n", ibm->name);
6932 acpi_bus_unregister_driver(ibm->acpi->driver);
6933 kfree(ibm->acpi->driver);
6934 ibm->acpi->driver = NULL;
6935 ibm->flags.acpi_driver_registered = 0;
6938 if (ibm->flags.init_called && ibm->exit) {
6940 ibm->flags.init_called = 0;
6943 dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name);
6946 static int __init ibm_init(struct ibm_init_struct *iibm)
6949 struct ibm_struct *ibm = iibm->data;
6950 struct proc_dir_entry *entry;
6952 BUG_ON(ibm == NULL);
6954 INIT_LIST_HEAD(&ibm->all_drivers);
6956 if (ibm->flags.experimental && !experimental)
6959 dbg_printk(TPACPI_DBG_INIT,
6960 "probing for %s\n", ibm->name);
6963 ret = iibm->init(iibm);
6965 return 0; /* probe failed */
6969 ibm->flags.init_called = 1;
6973 if (ibm->acpi->hid) {
6974 ret = register_tpacpi_subdriver(ibm);
6979 if (ibm->acpi->notify) {
6980 ret = setup_acpi_notify(ibm);
6981 if (ret == -ENODEV) {
6982 printk(TPACPI_NOTICE "disabling subdriver %s\n",
6992 dbg_printk(TPACPI_DBG_INIT,
6993 "%s installed\n", ibm->name);
6996 entry = create_proc_entry(ibm->name,
6997 S_IFREG | S_IRUGO | S_IWUSR,
7000 printk(TPACPI_ERR "unable to create proc entry %s\n",
7005 entry->owner = THIS_MODULE;
7007 entry->read_proc = &dispatch_procfs_read;
7009 entry->write_proc = &dispatch_procfs_write;
7010 ibm->flags.proc_created = 1;
7013 list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers);
7018 dbg_printk(TPACPI_DBG_INIT,
7019 "%s: at error exit path with result %d\n",
7023 return (ret < 0)? ret : 0;
7028 /* returns 0 - probe ok, or < 0 - probe error.
7029 * Probe ok doesn't mean thinkpad found.
7030 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
7031 static int __must_check __init get_thinkpad_model_data(
7032 struct thinkpad_id_data *tp)
7034 const struct dmi_device *dev = NULL;
7035 char ec_fw_string[18];
7041 memset(tp, 0, sizeof(*tp));
7043 if (dmi_name_in_vendors("IBM"))
7044 tp->vendor = PCI_VENDOR_ID_IBM;
7045 else if (dmi_name_in_vendors("LENOVO"))
7046 tp->vendor = PCI_VENDOR_ID_LENOVO;
7050 s = dmi_get_system_info(DMI_BIOS_VERSION);
7051 tp->bios_version_str = kstrdup(s, GFP_KERNEL);
7052 if (s && !tp->bios_version_str)
7054 if (!tp->bios_version_str)
7056 tp->bios_model = tp->bios_version_str[0]
7057 | (tp->bios_version_str[1] << 8);
7060 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
7061 * X32 or newer, all Z series; Some models must have an
7062 * up-to-date BIOS or they will not be detected.
7064 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7066 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
7067 if (sscanf(dev->name,
7068 "IBM ThinkPad Embedded Controller -[%17c",
7069 ec_fw_string) == 1) {
7070 ec_fw_string[sizeof(ec_fw_string) - 1] = 0;
7071 ec_fw_string[strcspn(ec_fw_string, " ]")] = 0;
7073 tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL);
7074 if (!tp->ec_version_str)
7076 tp->ec_model = ec_fw_string[0]
7077 | (ec_fw_string[1] << 8);
7082 s = dmi_get_system_info(DMI_PRODUCT_VERSION);
7083 if (s && !strnicmp(s, "ThinkPad", 8)) {
7084 tp->model_str = kstrdup(s, GFP_KERNEL);
7089 s = dmi_get_system_info(DMI_PRODUCT_NAME);
7090 tp->nummodel_str = kstrdup(s, GFP_KERNEL);
7091 if (s && !tp->nummodel_str)
7097 static int __init probe_for_thinkpad(void)
7105 * Non-ancient models have better DMI tagging, but very old models
7108 is_thinkpad = (thinkpad_id.model_str != NULL);
7110 /* ec is required because many other handles are relative to it */
7111 TPACPI_ACPIHANDLE_INIT(ec);
7115 "Not yet supported ThinkPad detected!\n");
7120 * Risks a regression on very old machines, but reduces potential
7121 * false positives a damn great deal
7124 is_thinkpad = (thinkpad_id.vendor == PCI_VENDOR_ID_IBM);
7126 if (!is_thinkpad && !force_load)
7133 /* Module init, exit, parameters */
7135 static struct ibm_init_struct ibms_init[] __initdata = {
7137 .init = thinkpad_acpi_driver_init,
7138 .data = &thinkpad_acpi_driver_data,
7141 .init = hotkey_init,
7142 .data = &hotkey_driver_data,
7145 .init = bluetooth_init,
7146 .data = &bluetooth_driver_data,
7150 .data = &wan_driver_data,
7154 .data = &uwb_driver_data,
7156 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
7159 .data = &video_driver_data,
7164 .data = &light_driver_data,
7166 #ifdef CONFIG_THINKPAD_ACPI_DOCK
7169 .data = &dock_driver_data[0],
7173 .data = &dock_driver_data[1],
7176 #ifdef CONFIG_THINKPAD_ACPI_BAY
7179 .data = &bay_driver_data,
7184 .data = &cmos_driver_data,
7188 .data = &led_driver_data,
7192 .data = &beep_driver_data,
7195 .init = thermal_init,
7196 .data = &thermal_driver_data,
7199 .data = &ecdump_driver_data,
7202 .init = brightness_init,
7203 .data = &brightness_driver_data,
7206 .data = &volume_driver_data,
7210 .data = &fan_driver_data,
7214 static int __init set_ibm_param(const char *val, struct kernel_param *kp)
7217 struct ibm_struct *ibm;
7219 if (!kp || !kp->name || !val)
7222 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
7223 ibm = ibms_init[i].data;
7224 WARN_ON(ibm == NULL);
7226 if (!ibm || !ibm->name)
7229 if (strcmp(ibm->name, kp->name) == 0 && ibm->write) {
7230 if (strlen(val) > sizeof(ibms_init[i].param) - 2)
7232 strcpy(ibms_init[i].param, val);
7233 strcat(ibms_init[i].param, ",");
7241 module_param(experimental, int, 0);
7242 MODULE_PARM_DESC(experimental,
7243 "Enables experimental features when non-zero");
7245 module_param_named(debug, dbg_level, uint, 0);
7246 MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
7248 module_param(force_load, bool, 0);
7249 MODULE_PARM_DESC(force_load,
7250 "Attempts to load the driver even on a "
7251 "mis-identified ThinkPad when true");
7253 module_param_named(fan_control, fan_control_allowed, bool, 0);
7254 MODULE_PARM_DESC(fan_control,
7255 "Enables setting fan parameters features when true");
7257 module_param_named(brightness_mode, brightness_mode, int, 0);
7258 MODULE_PARM_DESC(brightness_mode,
7259 "Selects brightness control strategy: "
7260 "0=auto, 1=EC, 2=CMOS, 3=both");
7262 module_param(brightness_enable, uint, 0);
7263 MODULE_PARM_DESC(brightness_enable,
7264 "Enables backlight control when 1, disables when 0");
7266 module_param(hotkey_report_mode, uint, 0);
7267 MODULE_PARM_DESC(hotkey_report_mode,
7268 "used for backwards compatibility with userspace, "
7269 "see documentation");
7271 #define TPACPI_PARAM(feature) \
7272 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
7273 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
7274 "at module load, see documentation")
7276 TPACPI_PARAM(hotkey);
7277 TPACPI_PARAM(bluetooth);
7278 TPACPI_PARAM(video);
7279 TPACPI_PARAM(light);
7280 #ifdef CONFIG_THINKPAD_ACPI_DOCK
7283 #ifdef CONFIG_THINKPAD_ACPI_BAY
7285 #endif /* CONFIG_THINKPAD_ACPI_BAY */
7289 TPACPI_PARAM(ecdump);
7290 TPACPI_PARAM(brightness);
7291 TPACPI_PARAM(volume);
7294 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
7295 module_param(dbg_wlswemul, uint, 0);
7296 MODULE_PARM_DESC(dbg_wlswemul, "Enables WLSW emulation");
7297 module_param_named(wlsw_state, tpacpi_wlsw_emulstate, bool, 0);
7298 MODULE_PARM_DESC(wlsw_state,
7299 "Initial state of the emulated WLSW switch");
7301 module_param(dbg_bluetoothemul, uint, 0);
7302 MODULE_PARM_DESC(dbg_bluetoothemul, "Enables bluetooth switch emulation");
7303 module_param_named(bluetooth_state, tpacpi_bluetooth_emulstate, bool, 0);
7304 MODULE_PARM_DESC(bluetooth_state,
7305 "Initial state of the emulated bluetooth switch");
7307 module_param(dbg_wwanemul, uint, 0);
7308 MODULE_PARM_DESC(dbg_wwanemul, "Enables WWAN switch emulation");
7309 module_param_named(wwan_state, tpacpi_wwan_emulstate, bool, 0);
7310 MODULE_PARM_DESC(wwan_state,
7311 "Initial state of the emulated WWAN switch");
7313 module_param(dbg_uwbemul, uint, 0);
7314 MODULE_PARM_DESC(dbg_uwbemul, "Enables UWB switch emulation");
7315 module_param_named(uwb_state, tpacpi_uwb_emulstate, bool, 0);
7316 MODULE_PARM_DESC(uwb_state,
7317 "Initial state of the emulated UWB switch");
7320 static void thinkpad_acpi_module_exit(void)
7322 struct ibm_struct *ibm, *itmp;
7324 tpacpi_lifecycle = TPACPI_LIFE_EXITING;
7326 list_for_each_entry_safe_reverse(ibm, itmp,
7327 &tpacpi_all_drivers,
7332 dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n");
7334 if (tpacpi_inputdev) {
7335 if (tp_features.input_device_registered)
7336 input_unregister_device(tpacpi_inputdev);
7338 input_free_device(tpacpi_inputdev);
7342 hwmon_device_unregister(tpacpi_hwmon);
7344 if (tp_features.sensors_pdev_attrs_registered)
7345 device_remove_file(&tpacpi_sensors_pdev->dev,
7346 &dev_attr_thinkpad_acpi_pdev_name);
7347 if (tpacpi_sensors_pdev)
7348 platform_device_unregister(tpacpi_sensors_pdev);
7350 platform_device_unregister(tpacpi_pdev);
7352 if (tp_features.sensors_pdrv_attrs_registered)
7353 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver);
7354 if (tp_features.platform_drv_attrs_registered)
7355 tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver);
7357 if (tp_features.sensors_pdrv_registered)
7358 platform_driver_unregister(&tpacpi_hwmon_pdriver);
7360 if (tp_features.platform_drv_registered)
7361 platform_driver_unregister(&tpacpi_pdriver);
7364 remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir);
7367 destroy_workqueue(tpacpi_wq);
7369 kfree(thinkpad_id.bios_version_str);
7370 kfree(thinkpad_id.ec_version_str);
7371 kfree(thinkpad_id.model_str);
7375 static int __init thinkpad_acpi_module_init(void)
7379 tpacpi_lifecycle = TPACPI_LIFE_INIT;
7381 /* Parameter checking */
7382 if (hotkey_report_mode > 2)
7385 /* Driver-level probe */
7387 ret = get_thinkpad_model_data(&thinkpad_id);
7390 "unable to get DMI data: %d\n", ret);
7391 thinkpad_acpi_module_exit();
7394 ret = probe_for_thinkpad();
7396 thinkpad_acpi_module_exit();
7400 /* Driver initialization */
7402 TPACPI_ACPIHANDLE_INIT(ecrd);
7403 TPACPI_ACPIHANDLE_INIT(ecwr);
7405 tpacpi_wq = create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME);
7407 thinkpad_acpi_module_exit();
7411 proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir);
7414 "unable to create proc dir " TPACPI_PROC_DIR);
7415 thinkpad_acpi_module_exit();
7418 proc_dir->owner = THIS_MODULE;
7420 ret = platform_driver_register(&tpacpi_pdriver);
7423 "unable to register main platform driver\n");
7424 thinkpad_acpi_module_exit();
7427 tp_features.platform_drv_registered = 1;
7429 ret = platform_driver_register(&tpacpi_hwmon_pdriver);
7432 "unable to register hwmon platform driver\n");
7433 thinkpad_acpi_module_exit();
7436 tp_features.sensors_pdrv_registered = 1;
7438 ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver);
7440 tp_features.platform_drv_attrs_registered = 1;
7441 ret = tpacpi_create_driver_attributes(
7442 &tpacpi_hwmon_pdriver.driver);
7446 "unable to create sysfs driver attributes\n");
7447 thinkpad_acpi_module_exit();
7450 tp_features.sensors_pdrv_attrs_registered = 1;
7453 /* Device initialization */
7454 tpacpi_pdev = platform_device_register_simple(TPACPI_DRVR_NAME, -1,
7456 if (IS_ERR(tpacpi_pdev)) {
7457 ret = PTR_ERR(tpacpi_pdev);
7459 printk(TPACPI_ERR "unable to register platform device\n");
7460 thinkpad_acpi_module_exit();
7463 tpacpi_sensors_pdev = platform_device_register_simple(
7464 TPACPI_HWMON_DRVR_NAME,
7466 if (IS_ERR(tpacpi_sensors_pdev)) {
7467 ret = PTR_ERR(tpacpi_sensors_pdev);
7468 tpacpi_sensors_pdev = NULL;
7470 "unable to register hwmon platform device\n");
7471 thinkpad_acpi_module_exit();
7474 ret = device_create_file(&tpacpi_sensors_pdev->dev,
7475 &dev_attr_thinkpad_acpi_pdev_name);
7478 "unable to create sysfs hwmon device attributes\n");
7479 thinkpad_acpi_module_exit();
7482 tp_features.sensors_pdev_attrs_registered = 1;
7483 tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev);
7484 if (IS_ERR(tpacpi_hwmon)) {
7485 ret = PTR_ERR(tpacpi_hwmon);
7486 tpacpi_hwmon = NULL;
7487 printk(TPACPI_ERR "unable to register hwmon device\n");
7488 thinkpad_acpi_module_exit();
7491 mutex_init(&tpacpi_inputdev_send_mutex);
7492 tpacpi_inputdev = input_allocate_device();
7493 if (!tpacpi_inputdev) {
7494 printk(TPACPI_ERR "unable to allocate input device\n");
7495 thinkpad_acpi_module_exit();
7498 /* Prepare input device, but don't register */
7499 tpacpi_inputdev->name = "ThinkPad Extra Buttons";
7500 tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0";
7501 tpacpi_inputdev->id.bustype = BUS_HOST;
7502 tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ?
7503 thinkpad_id.vendor :
7505 tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT;
7506 tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION;
7508 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
7509 ret = ibm_init(&ibms_init[i]);
7510 if (ret >= 0 && *ibms_init[i].param)
7511 ret = ibms_init[i].data->write(ibms_init[i].param);
7513 thinkpad_acpi_module_exit();
7517 ret = input_register_device(tpacpi_inputdev);
7519 printk(TPACPI_ERR "unable to register input device\n");
7520 thinkpad_acpi_module_exit();
7523 tp_features.input_device_registered = 1;
7526 tpacpi_lifecycle = TPACPI_LIFE_RUNNING;
7530 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME);
7533 * DMI matching for module autoloading
7535 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7536 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
7538 * Only models listed in thinkwiki will be supported, so add yours
7539 * if it is not there yet.
7541 #define IBM_BIOS_MODULE_ALIAS(__type) \
7542 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW*")
7544 /* Non-ancient thinkpads */
7545 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
7546 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
7548 /* Ancient thinkpad BIOSes have to be identified by
7549 * BIOS type or model number, and there are far less
7550 * BIOS types than model numbers... */
7551 IBM_BIOS_MODULE_ALIAS("I[BDHIMNOTWVYZ]");
7552 IBM_BIOS_MODULE_ALIAS("1[0368A-GIKM-PST]");
7553 IBM_BIOS_MODULE_ALIAS("K[UX-Z]");
7555 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
7556 MODULE_DESCRIPTION(TPACPI_DESC);
7557 MODULE_VERSION(TPACPI_VERSION);
7558 MODULE_LICENSE("GPL");
7560 module_init(thinkpad_acpi_module_init);
7561 module_exit(thinkpad_acpi_module_exit);