2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2008 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_ALERT KERN_ALERT TPACPI_LOG
178 #define TPACPI_CRIT KERN_CRIT TPACPI_LOG
179 #define TPACPI_ERR KERN_ERR TPACPI_LOG
180 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
181 #define TPACPI_INFO KERN_INFO TPACPI_LOG
182 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
184 #define TPACPI_DBG_ALL 0xffff
185 #define TPACPI_DBG_INIT 0x0001
186 #define TPACPI_DBG_EXIT 0x0002
187 #define dbg_printk(a_dbg_level, format, arg...) \
188 do { if (dbg_level & a_dbg_level) \
189 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
191 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
192 #define vdbg_printk(a_dbg_level, format, arg...) \
193 dbg_printk(a_dbg_level, format, ## arg)
194 static const char *str_supported(int is_supported);
196 #define vdbg_printk(a_dbg_level, format, arg...)
199 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
200 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
201 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
204 /****************************************************************************
205 * Driver-wide structs and misc. variables
210 struct tp_acpi_drv_struct {
211 const struct acpi_device_id *hid;
212 struct acpi_driver *driver;
214 void (*notify) (struct ibm_struct *, u32);
217 struct acpi_device *device;
223 int (*read) (char *);
224 int (*write) (char *);
226 void (*resume) (void);
227 void (*suspend) (pm_message_t state);
228 void (*shutdown) (void);
230 struct list_head all_drivers;
232 struct tp_acpi_drv_struct *acpi;
235 u8 acpi_driver_registered:1;
236 u8 acpi_notify_installed:1;
243 struct ibm_init_struct {
246 int (*init) (struct ibm_init_struct *);
247 struct ibm_struct *data;
251 #ifdef CONFIG_THINKPAD_ACPI_BAY
264 u32 bright_16levels:1;
265 u32 bright_acpimode:1;
268 u32 fan_ctrl_status_undef:1;
269 u32 input_device_registered:1;
270 u32 platform_drv_registered:1;
271 u32 platform_drv_attrs_registered:1;
272 u32 sensors_pdrv_registered:1;
273 u32 sensors_pdrv_attrs_registered:1;
274 u32 sensors_pdev_attrs_registered:1;
275 u32 hotkey_poll_active:1;
279 u16 hotkey_mask_ff:1;
280 u16 bright_cmos_ec_unsync:1;
283 struct thinkpad_id_data {
284 unsigned int vendor; /* ThinkPad vendor:
285 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
287 char *bios_version_str; /* Something like 1ZET51WW (1.03z) */
288 char *ec_version_str; /* Something like 1ZHT51WW-1.04a */
290 u16 bios_model; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */
293 char *model_str; /* ThinkPad T43 */
294 char *nummodel_str; /* 9384A9C for a 9384-A9C model */
296 static struct thinkpad_id_data thinkpad_id;
299 TPACPI_LIFE_INIT = 0,
304 static int experimental;
305 static u32 dbg_level;
307 static struct workqueue_struct *tpacpi_wq;
309 /* Special LED class that can defer work */
310 struct tpacpi_led_classdev {
311 struct led_classdev led_classdev;
312 struct work_struct work;
313 enum led_brightness new_brightness;
317 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
318 static int dbg_wlswemul;
319 static int tpacpi_wlsw_emulstate;
320 static int dbg_bluetoothemul;
321 static int tpacpi_bluetooth_emulstate;
322 static int dbg_wwanemul;
323 static int tpacpi_wwan_emulstate;
324 static int dbg_uwbemul;
325 static int tpacpi_uwb_emulstate;
329 /****************************************************************************
330 ****************************************************************************
332 * ACPI Helpers and device model
334 ****************************************************************************
335 ****************************************************************************/
337 /*************************************************************************
341 static acpi_handle root_handle;
343 #define TPACPI_HANDLE(object, parent, paths...) \
344 static acpi_handle object##_handle; \
345 static acpi_handle *object##_parent = &parent##_handle; \
346 static char *object##_path; \
347 static char *object##_paths[] = { paths }
349 TPACPI_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
350 "\\_SB.PCI.ISA.EC", /* 570 */
351 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
352 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
353 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
354 "\\_SB.PCI0.ICH3.EC0", /* R31 */
355 "\\_SB.PCI0.LPC.EC", /* all others */
358 TPACPI_HANDLE(ecrd, ec, "ECRD"); /* 570 */
359 TPACPI_HANDLE(ecwr, ec, "ECWR"); /* 570 */
361 TPACPI_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, */
363 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
364 "\\CMS", /* R40, R40e */
367 TPACPI_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
368 "^HKEY", /* R30, R31 */
369 "HKEY", /* all others */
372 TPACPI_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */
373 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
374 "\\_SB.PCI0.VID0", /* 770e */
375 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
376 "\\_SB.PCI0.AGP.VID", /* all others */
380 /*************************************************************************
384 static int acpi_evalf(acpi_handle handle,
385 void *res, char *method, char *fmt, ...)
388 struct acpi_object_list params;
389 union acpi_object in_objs[TPACPI_MAX_ACPI_ARGS];
390 struct acpi_buffer result, *resultp;
391 union acpi_object out_obj;
399 printk(TPACPI_ERR "acpi_evalf() called with empty format\n");
412 params.pointer = &in_objs[0];
419 in_objs[params.count].integer.value = va_arg(ap, int);
420 in_objs[params.count++].type = ACPI_TYPE_INTEGER;
422 /* add more types as needed */
424 printk(TPACPI_ERR "acpi_evalf() called "
425 "with invalid format character '%c'\n", c);
431 if (res_type != 'v') {
432 result.length = sizeof(out_obj);
433 result.pointer = &out_obj;
438 status = acpi_evaluate_object(handle, method, ¶ms, resultp);
443 *(int *)res = out_obj.integer.value;
444 success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER;
447 success = status == AE_OK;
449 /* add more types as needed */
451 printk(TPACPI_ERR "acpi_evalf() called "
452 "with invalid format character '%c'\n", res_type);
456 if (!success && !quiet)
457 printk(TPACPI_ERR "acpi_evalf(%s, %s, ...) failed: %d\n",
458 method, fmt0, status);
463 static int acpi_ec_read(int i, u8 *p)
468 if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i))
472 if (ec_read(i, p) < 0)
479 static int acpi_ec_write(int i, u8 v)
482 if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v))
485 if (ec_write(i, v) < 0)
492 #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY)
493 static int _sta(acpi_handle handle)
497 if (!handle || !acpi_evalf(handle, &status, "_STA", "d"))
504 static int issue_thinkpad_cmos_command(int cmos_cmd)
509 if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd))
515 /*************************************************************************
519 #define TPACPI_ACPIHANDLE_INIT(object) \
520 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
521 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
523 static void drv_acpi_handle_init(char *name,
524 acpi_handle *handle, acpi_handle parent,
525 char **paths, int num_paths, char **path)
530 vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n",
533 for (i = 0; i < num_paths; i++) {
534 status = acpi_get_handle(parent, paths[i], handle);
535 if (ACPI_SUCCESS(status)) {
537 dbg_printk(TPACPI_DBG_INIT,
538 "Found ACPI handle %s for %s\n",
544 vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n",
549 static void dispatch_acpi_notify(acpi_handle handle, u32 event, void *data)
551 struct ibm_struct *ibm = data;
553 if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING)
556 if (!ibm || !ibm->acpi || !ibm->acpi->notify)
559 ibm->acpi->notify(ibm, event);
562 static int __init setup_acpi_notify(struct ibm_struct *ibm)
569 if (!*ibm->acpi->handle)
572 vdbg_printk(TPACPI_DBG_INIT,
573 "setting up ACPI notify for %s\n", ibm->name);
575 rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device);
577 printk(TPACPI_ERR "acpi_bus_get_device(%s) failed: %d\n",
582 ibm->acpi->device->driver_data = ibm;
583 sprintf(acpi_device_class(ibm->acpi->device), "%s/%s",
584 TPACPI_ACPI_EVENT_PREFIX,
587 status = acpi_install_notify_handler(*ibm->acpi->handle,
588 ibm->acpi->type, dispatch_acpi_notify, ibm);
589 if (ACPI_FAILURE(status)) {
590 if (status == AE_ALREADY_EXISTS) {
592 "another device driver is already "
593 "handling %s events\n", ibm->name);
596 "acpi_install_notify_handler(%s) failed: %d\n",
601 ibm->flags.acpi_notify_installed = 1;
605 static int __init tpacpi_device_add(struct acpi_device *device)
610 static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
614 dbg_printk(TPACPI_DBG_INIT,
615 "registering %s as an ACPI driver\n", ibm->name);
619 ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
620 if (!ibm->acpi->driver) {
622 "failed to allocate memory for ibm->acpi->driver\n");
626 sprintf(ibm->acpi->driver->name, "%s_%s", TPACPI_NAME, ibm->name);
627 ibm->acpi->driver->ids = ibm->acpi->hid;
629 ibm->acpi->driver->ops.add = &tpacpi_device_add;
631 rc = acpi_bus_register_driver(ibm->acpi->driver);
633 printk(TPACPI_ERR "acpi_bus_register_driver(%s) failed: %d\n",
635 kfree(ibm->acpi->driver);
636 ibm->acpi->driver = NULL;
638 ibm->flags.acpi_driver_registered = 1;
644 /****************************************************************************
645 ****************************************************************************
649 ****************************************************************************
650 ****************************************************************************/
652 static int dispatch_procfs_read(char *page, char **start, off_t off,
653 int count, int *eof, void *data)
655 struct ibm_struct *ibm = data;
658 if (!ibm || !ibm->read)
661 len = ibm->read(page);
665 if (len <= off + count)
677 static int dispatch_procfs_write(struct file *file,
678 const char __user *userbuf,
679 unsigned long count, void *data)
681 struct ibm_struct *ibm = data;
685 if (!ibm || !ibm->write)
688 kernbuf = kmalloc(count + 2, GFP_KERNEL);
692 if (copy_from_user(kernbuf, userbuf, count)) {
698 strcat(kernbuf, ",");
699 ret = ibm->write(kernbuf);
708 static char *next_cmd(char **cmds)
713 while ((end = strchr(start, ',')) && end == start)
725 /****************************************************************************
726 ****************************************************************************
728 * Device model: input, hwmon and platform
730 ****************************************************************************
731 ****************************************************************************/
733 static struct platform_device *tpacpi_pdev;
734 static struct platform_device *tpacpi_sensors_pdev;
735 static struct device *tpacpi_hwmon;
736 static struct input_dev *tpacpi_inputdev;
737 static struct mutex tpacpi_inputdev_send_mutex;
738 static LIST_HEAD(tpacpi_all_drivers);
740 static int tpacpi_suspend_handler(struct platform_device *pdev,
743 struct ibm_struct *ibm, *itmp;
745 list_for_each_entry_safe(ibm, itmp,
749 (ibm->suspend)(state);
755 static int tpacpi_resume_handler(struct platform_device *pdev)
757 struct ibm_struct *ibm, *itmp;
759 list_for_each_entry_safe(ibm, itmp,
769 static void tpacpi_shutdown_handler(struct platform_device *pdev)
771 struct ibm_struct *ibm, *itmp;
773 list_for_each_entry_safe(ibm, itmp,
781 static struct platform_driver tpacpi_pdriver = {
783 .name = TPACPI_DRVR_NAME,
784 .owner = THIS_MODULE,
786 .suspend = tpacpi_suspend_handler,
787 .resume = tpacpi_resume_handler,
788 .shutdown = tpacpi_shutdown_handler,
791 static struct platform_driver tpacpi_hwmon_pdriver = {
793 .name = TPACPI_HWMON_DRVR_NAME,
794 .owner = THIS_MODULE,
798 /*************************************************************************
799 * sysfs support helpers
802 struct attribute_set {
803 unsigned int members, max_members;
804 struct attribute_group group;
807 struct attribute_set_obj {
808 struct attribute_set s;
810 } __attribute__((packed));
812 static struct attribute_set *create_attr_set(unsigned int max_members,
815 struct attribute_set_obj *sobj;
817 if (max_members == 0)
820 /* Allocates space for implicit NULL at the end too */
821 sobj = kzalloc(sizeof(struct attribute_set_obj) +
822 max_members * sizeof(struct attribute *),
826 sobj->s.max_members = max_members;
827 sobj->s.group.attrs = &sobj->a;
828 sobj->s.group.name = name;
833 #define destroy_attr_set(_set) \
836 /* not multi-threaded safe, use it in a single thread per set */
837 static int add_to_attr_set(struct attribute_set *s, struct attribute *attr)
842 if (s->members >= s->max_members)
845 s->group.attrs[s->members] = attr;
851 static int add_many_to_attr_set(struct attribute_set *s,
852 struct attribute **attr,
857 for (i = 0; i < count; i++) {
858 res = add_to_attr_set(s, attr[i]);
866 static void delete_attr_set(struct attribute_set *s, struct kobject *kobj)
868 sysfs_remove_group(kobj, &s->group);
872 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
873 sysfs_create_group(_kobj, &_attr_set->group)
875 static int parse_strtoul(const char *buf,
876 unsigned long max, unsigned long *value)
880 while (*buf && isspace(*buf))
882 *value = simple_strtoul(buf, &endp, 0);
883 while (*endp && isspace(*endp))
885 if (*endp || *value > max)
891 static void tpacpi_disable_brightness_delay(void)
893 if (acpi_evalf(hkey_handle, NULL, "PWMS", "qvd", 0))
895 "ACPI backlight control delay disabled\n");
898 static int __init tpacpi_query_bcl_levels(acpi_handle handle)
900 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
901 union acpi_object *obj;
904 if (ACPI_SUCCESS(acpi_evaluate_object(handle, NULL, NULL, &buffer))) {
905 obj = (union acpi_object *)buffer.pointer;
906 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
907 printk(TPACPI_ERR "Unknown _BCL data, "
908 "please report this to %s\n", TPACPI_MAIL);
911 rc = obj->package.count;
917 kfree(buffer.pointer);
921 static acpi_status __init tpacpi_acpi_walk_find_bcl(acpi_handle handle,
922 u32 lvl, void *context, void **rv)
924 char name[ACPI_PATH_SEGMENT_LENGTH];
925 struct acpi_buffer buffer = { sizeof(name), &name };
927 if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) &&
928 !strncmp("_BCL", name, sizeof(name) - 1)) {
930 **(int **)rv = tpacpi_query_bcl_levels(handle);
931 return AE_CTRL_TERMINATE;
938 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
940 static int __init tpacpi_check_std_acpi_brightness_support(void)
944 void *bcl_ptr = &bcl_levels;
947 TPACPI_ACPIHANDLE_INIT(vid);
953 * Search for a _BCL method, and execute it. This is safe on all
954 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
955 * BIOS in ACPI backlight control mode. We do NOT have to care
956 * about calling the _BCL method in an enabled video device, any
957 * will do for our purposes.
960 status = acpi_walk_namespace(ACPI_TYPE_METHOD, vid_handle, 3,
961 tpacpi_acpi_walk_find_bcl, NULL,
964 if (ACPI_SUCCESS(status) && bcl_levels > 2) {
965 tp_features.bright_acpimode = 1;
966 return (bcl_levels - 2);
972 static int __init tpacpi_new_rfkill(const unsigned int id,
974 const enum rfkill_type rfktype,
976 const bool set_default,
977 int (*toggle_radio)(void *, enum rfkill_state),
978 int (*get_state)(void *, enum rfkill_state *))
981 enum rfkill_state initial_state = RFKILL_STATE_SOFT_BLOCKED;
983 res = get_state(NULL, &initial_state);
986 "failed to read initial state for %s, error %d; "
987 "will turn radio off\n", name, res);
988 } else if (set_default) {
989 /* try to set the initial state as the default for the rfkill
990 * type, since we ask the firmware to preserve it across S5 in
992 rfkill_set_default(rfktype,
993 (initial_state == RFKILL_STATE_UNBLOCKED) ?
994 RFKILL_STATE_UNBLOCKED :
995 RFKILL_STATE_SOFT_BLOCKED);
998 *rfk = rfkill_allocate(&tpacpi_pdev->dev, rfktype);
1001 "failed to allocate memory for rfkill class\n");
1005 (*rfk)->name = name;
1006 (*rfk)->get_state = get_state;
1007 (*rfk)->toggle_radio = toggle_radio;
1008 (*rfk)->state = initial_state;
1010 res = rfkill_register(*rfk);
1013 "failed to register %s rfkill switch: %d\n",
1023 /*************************************************************************
1024 * thinkpad-acpi driver attributes
1027 /* interface_version --------------------------------------------------- */
1028 static ssize_t tpacpi_driver_interface_version_show(
1029 struct device_driver *drv,
1032 return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION);
1035 static DRIVER_ATTR(interface_version, S_IRUGO,
1036 tpacpi_driver_interface_version_show, NULL);
1038 /* debug_level --------------------------------------------------------- */
1039 static ssize_t tpacpi_driver_debug_show(struct device_driver *drv,
1042 return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level);
1045 static ssize_t tpacpi_driver_debug_store(struct device_driver *drv,
1046 const char *buf, size_t count)
1050 if (parse_strtoul(buf, 0xffff, &t))
1058 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
1059 tpacpi_driver_debug_show, tpacpi_driver_debug_store);
1061 /* version ------------------------------------------------------------- */
1062 static ssize_t tpacpi_driver_version_show(struct device_driver *drv,
1065 return snprintf(buf, PAGE_SIZE, "%s v%s\n",
1066 TPACPI_DESC, TPACPI_VERSION);
1069 static DRIVER_ATTR(version, S_IRUGO,
1070 tpacpi_driver_version_show, NULL);
1072 /* --------------------------------------------------------------------- */
1074 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1076 static void tpacpi_send_radiosw_update(void);
1078 /* wlsw_emulstate ------------------------------------------------------ */
1079 static ssize_t tpacpi_driver_wlsw_emulstate_show(struct device_driver *drv,
1082 return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wlsw_emulstate);
1085 static ssize_t tpacpi_driver_wlsw_emulstate_store(struct device_driver *drv,
1086 const char *buf, size_t count)
1090 if (parse_strtoul(buf, 1, &t))
1093 if (tpacpi_wlsw_emulstate != t) {
1094 tpacpi_wlsw_emulstate = !!t;
1095 tpacpi_send_radiosw_update();
1097 tpacpi_wlsw_emulstate = !!t;
1102 static DRIVER_ATTR(wlsw_emulstate, S_IWUSR | S_IRUGO,
1103 tpacpi_driver_wlsw_emulstate_show,
1104 tpacpi_driver_wlsw_emulstate_store);
1106 /* bluetooth_emulstate ------------------------------------------------- */
1107 static ssize_t tpacpi_driver_bluetooth_emulstate_show(
1108 struct device_driver *drv,
1111 return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_bluetooth_emulstate);
1114 static ssize_t tpacpi_driver_bluetooth_emulstate_store(
1115 struct device_driver *drv,
1116 const char *buf, size_t count)
1120 if (parse_strtoul(buf, 1, &t))
1123 tpacpi_bluetooth_emulstate = !!t;
1128 static DRIVER_ATTR(bluetooth_emulstate, S_IWUSR | S_IRUGO,
1129 tpacpi_driver_bluetooth_emulstate_show,
1130 tpacpi_driver_bluetooth_emulstate_store);
1132 /* wwan_emulstate ------------------------------------------------- */
1133 static ssize_t tpacpi_driver_wwan_emulstate_show(
1134 struct device_driver *drv,
1137 return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_wwan_emulstate);
1140 static ssize_t tpacpi_driver_wwan_emulstate_store(
1141 struct device_driver *drv,
1142 const char *buf, size_t count)
1146 if (parse_strtoul(buf, 1, &t))
1149 tpacpi_wwan_emulstate = !!t;
1154 static DRIVER_ATTR(wwan_emulstate, S_IWUSR | S_IRUGO,
1155 tpacpi_driver_wwan_emulstate_show,
1156 tpacpi_driver_wwan_emulstate_store);
1158 /* uwb_emulstate ------------------------------------------------- */
1159 static ssize_t tpacpi_driver_uwb_emulstate_show(
1160 struct device_driver *drv,
1163 return snprintf(buf, PAGE_SIZE, "%d\n", !!tpacpi_uwb_emulstate);
1166 static ssize_t tpacpi_driver_uwb_emulstate_store(
1167 struct device_driver *drv,
1168 const char *buf, size_t count)
1172 if (parse_strtoul(buf, 1, &t))
1175 tpacpi_uwb_emulstate = !!t;
1180 static DRIVER_ATTR(uwb_emulstate, S_IWUSR | S_IRUGO,
1181 tpacpi_driver_uwb_emulstate_show,
1182 tpacpi_driver_uwb_emulstate_store);
1185 /* --------------------------------------------------------------------- */
1187 static struct driver_attribute *tpacpi_driver_attributes[] = {
1188 &driver_attr_debug_level, &driver_attr_version,
1189 &driver_attr_interface_version,
1192 static int __init tpacpi_create_driver_attributes(struct device_driver *drv)
1198 while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) {
1199 res = driver_create_file(drv, tpacpi_driver_attributes[i]);
1203 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1204 if (!res && dbg_wlswemul)
1205 res = driver_create_file(drv, &driver_attr_wlsw_emulstate);
1206 if (!res && dbg_bluetoothemul)
1207 res = driver_create_file(drv, &driver_attr_bluetooth_emulstate);
1208 if (!res && dbg_wwanemul)
1209 res = driver_create_file(drv, &driver_attr_wwan_emulstate);
1210 if (!res && dbg_uwbemul)
1211 res = driver_create_file(drv, &driver_attr_uwb_emulstate);
1217 static void tpacpi_remove_driver_attributes(struct device_driver *drv)
1221 for (i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++)
1222 driver_remove_file(drv, tpacpi_driver_attributes[i]);
1224 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1225 driver_remove_file(drv, &driver_attr_wlsw_emulstate);
1226 driver_remove_file(drv, &driver_attr_bluetooth_emulstate);
1227 driver_remove_file(drv, &driver_attr_wwan_emulstate);
1228 driver_remove_file(drv, &driver_attr_uwb_emulstate);
1232 /****************************************************************************
1233 ****************************************************************************
1237 ****************************************************************************
1238 ****************************************************************************/
1240 /*************************************************************************
1241 * thinkpad-acpi init subdriver
1244 static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm)
1246 printk(TPACPI_INFO "%s v%s\n", TPACPI_DESC, TPACPI_VERSION);
1247 printk(TPACPI_INFO "%s\n", TPACPI_URL);
1249 printk(TPACPI_INFO "ThinkPad BIOS %s, EC %s\n",
1250 (thinkpad_id.bios_version_str) ?
1251 thinkpad_id.bios_version_str : "unknown",
1252 (thinkpad_id.ec_version_str) ?
1253 thinkpad_id.ec_version_str : "unknown");
1255 if (thinkpad_id.vendor && thinkpad_id.model_str)
1256 printk(TPACPI_INFO "%s %s, model %s\n",
1257 (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ?
1258 "IBM" : ((thinkpad_id.vendor ==
1259 PCI_VENDOR_ID_LENOVO) ?
1260 "Lenovo" : "Unknown vendor"),
1261 thinkpad_id.model_str,
1262 (thinkpad_id.nummodel_str) ?
1263 thinkpad_id.nummodel_str : "unknown");
1268 static int thinkpad_acpi_driver_read(char *p)
1272 len += sprintf(p + len, "driver:\t\t%s\n", TPACPI_DESC);
1273 len += sprintf(p + len, "version:\t%s\n", TPACPI_VERSION);
1278 static struct ibm_struct thinkpad_acpi_driver_data = {
1280 .read = thinkpad_acpi_driver_read,
1283 /*************************************************************************
1287 enum { /* hot key scan codes (derived from ACPI DSDT) */
1288 TP_ACPI_HOTKEYSCAN_FNF1 = 0,
1289 TP_ACPI_HOTKEYSCAN_FNF2,
1290 TP_ACPI_HOTKEYSCAN_FNF3,
1291 TP_ACPI_HOTKEYSCAN_FNF4,
1292 TP_ACPI_HOTKEYSCAN_FNF5,
1293 TP_ACPI_HOTKEYSCAN_FNF6,
1294 TP_ACPI_HOTKEYSCAN_FNF7,
1295 TP_ACPI_HOTKEYSCAN_FNF8,
1296 TP_ACPI_HOTKEYSCAN_FNF9,
1297 TP_ACPI_HOTKEYSCAN_FNF10,
1298 TP_ACPI_HOTKEYSCAN_FNF11,
1299 TP_ACPI_HOTKEYSCAN_FNF12,
1300 TP_ACPI_HOTKEYSCAN_FNBACKSPACE,
1301 TP_ACPI_HOTKEYSCAN_FNINSERT,
1302 TP_ACPI_HOTKEYSCAN_FNDELETE,
1303 TP_ACPI_HOTKEYSCAN_FNHOME,
1304 TP_ACPI_HOTKEYSCAN_FNEND,
1305 TP_ACPI_HOTKEYSCAN_FNPAGEUP,
1306 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN,
1307 TP_ACPI_HOTKEYSCAN_FNSPACE,
1308 TP_ACPI_HOTKEYSCAN_VOLUMEUP,
1309 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN,
1310 TP_ACPI_HOTKEYSCAN_MUTE,
1311 TP_ACPI_HOTKEYSCAN_THINKPAD,
1314 enum { /* Keys available through NVRAM polling */
1315 TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U,
1316 TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U,
1319 enum { /* Positions of some of the keys in hotkey masks */
1320 TP_ACPI_HKEY_DISPSWTCH_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF7,
1321 TP_ACPI_HKEY_DISPXPAND_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF8,
1322 TP_ACPI_HKEY_HIBERNATE_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNF12,
1323 TP_ACPI_HKEY_BRGHTUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNHOME,
1324 TP_ACPI_HKEY_BRGHTDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNEND,
1325 TP_ACPI_HKEY_THNKLGHT_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP,
1326 TP_ACPI_HKEY_ZOOM_MASK = 1 << TP_ACPI_HOTKEYSCAN_FNSPACE,
1327 TP_ACPI_HKEY_VOLUP_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP,
1328 TP_ACPI_HKEY_VOLDWN_MASK = 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN,
1329 TP_ACPI_HKEY_MUTE_MASK = 1 << TP_ACPI_HOTKEYSCAN_MUTE,
1330 TP_ACPI_HKEY_THINKPAD_MASK = 1 << TP_ACPI_HOTKEYSCAN_THINKPAD,
1333 enum { /* NVRAM to ACPI HKEY group map */
1334 TP_NVRAM_HKEY_GROUP_HK2 = TP_ACPI_HKEY_THINKPAD_MASK |
1335 TP_ACPI_HKEY_ZOOM_MASK |
1336 TP_ACPI_HKEY_DISPSWTCH_MASK |
1337 TP_ACPI_HKEY_HIBERNATE_MASK,
1338 TP_NVRAM_HKEY_GROUP_BRIGHTNESS = TP_ACPI_HKEY_BRGHTUP_MASK |
1339 TP_ACPI_HKEY_BRGHTDWN_MASK,
1340 TP_NVRAM_HKEY_GROUP_VOLUME = TP_ACPI_HKEY_VOLUP_MASK |
1341 TP_ACPI_HKEY_VOLDWN_MASK |
1342 TP_ACPI_HKEY_MUTE_MASK,
1345 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1346 struct tp_nvram_state {
1347 u16 thinkpad_toggle:1;
1349 u16 display_toggle:1;
1350 u16 thinklight_toggle:1;
1351 u16 hibernate_toggle:1;
1352 u16 displayexp_toggle:1;
1353 u16 display_state:1;
1354 u16 brightness_toggle:1;
1355 u16 volume_toggle:1;
1358 u8 brightness_level;
1362 static struct task_struct *tpacpi_hotkey_task;
1363 static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */
1364 static int hotkey_poll_freq = 10; /* Hz */
1365 static struct mutex hotkey_thread_mutex;
1366 static struct mutex hotkey_thread_data_mutex;
1367 static unsigned int hotkey_config_change;
1369 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1371 #define hotkey_source_mask 0U
1373 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1375 static struct mutex hotkey_mutex;
1377 static enum { /* Reasons for waking up */
1378 TP_ACPI_WAKEUP_NONE = 0, /* None or unknown */
1379 TP_ACPI_WAKEUP_BAYEJ, /* Bay ejection request */
1380 TP_ACPI_WAKEUP_UNDOCK, /* Undock request */
1381 } hotkey_wakeup_reason;
1383 static int hotkey_autosleep_ack;
1385 static int hotkey_orig_status;
1386 static u32 hotkey_orig_mask;
1387 static u32 hotkey_all_mask;
1388 static u32 hotkey_reserved_mask;
1389 static u32 hotkey_mask;
1391 static unsigned int hotkey_report_mode;
1393 static u16 *hotkey_keycode_map;
1395 static struct attribute_set *hotkey_dev_attributes;
1397 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1398 #define HOTKEY_CONFIG_CRITICAL_START \
1400 mutex_lock(&hotkey_thread_data_mutex); \
1401 hotkey_config_change++; \
1403 #define HOTKEY_CONFIG_CRITICAL_END \
1404 mutex_unlock(&hotkey_thread_data_mutex);
1406 #define HOTKEY_CONFIG_CRITICAL_START
1407 #define HOTKEY_CONFIG_CRITICAL_END
1408 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1410 /* HKEY.MHKG() return bits */
1411 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1413 static int hotkey_get_wlsw(int *status)
1415 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1417 *status = !!tpacpi_wlsw_emulstate;
1421 if (!acpi_evalf(hkey_handle, status, "WLSW", "d"))
1426 static int hotkey_get_tablet_mode(int *status)
1430 if (!acpi_evalf(hkey_handle, &s, "MHKG", "d"))
1433 *status = ((s & TP_HOTKEY_TABLET_MASK) != 0);
1438 * Call with hotkey_mutex held
1440 static int hotkey_mask_get(void)
1444 if (tp_features.hotkey_mask) {
1445 if (!acpi_evalf(hkey_handle, &m, "DHKN", "d"))
1448 hotkey_mask = m | (hotkey_source_mask & hotkey_mask);
1454 * Call with hotkey_mutex held
1456 static int hotkey_mask_set(u32 mask)
1461 if (tp_features.hotkey_mask) {
1462 if (!tp_warned.hotkey_mask_ff &&
1463 (mask == 0xffff || mask == 0xffffff ||
1464 mask == 0xffffffff)) {
1465 tp_warned.hotkey_mask_ff = 1;
1466 printk(TPACPI_NOTICE
1467 "setting the hotkey mask to 0x%08x is likely "
1468 "not the best way to go about it\n", mask);
1469 printk(TPACPI_NOTICE
1470 "please consider using the driver defaults, "
1471 "and refer to up-to-date thinkpad-acpi "
1475 HOTKEY_CONFIG_CRITICAL_START
1476 for (i = 0; i < 32; i++) {
1478 /* enable in firmware mask only keys not in NVRAM
1479 * mode, but enable the key in the cached hotkey_mask
1480 * regardless of mode, or the key will end up
1481 * disabled by hotkey_mask_get() */
1482 if (!acpi_evalf(hkey_handle,
1483 NULL, "MHKM", "vdd", i + 1,
1484 !!((mask & ~hotkey_source_mask) & m))) {
1488 hotkey_mask = (hotkey_mask & ~m) | (mask & m);
1491 HOTKEY_CONFIG_CRITICAL_END
1493 /* hotkey_mask_get must be called unconditionally below */
1494 if (!hotkey_mask_get() && !rc &&
1495 (hotkey_mask & ~hotkey_source_mask) !=
1496 (mask & ~hotkey_source_mask)) {
1497 printk(TPACPI_NOTICE
1498 "requested hot key mask 0x%08x, but "
1499 "firmware forced it to 0x%08x\n",
1503 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1504 HOTKEY_CONFIG_CRITICAL_START
1505 hotkey_mask = mask & hotkey_source_mask;
1506 HOTKEY_CONFIG_CRITICAL_END
1508 if (hotkey_mask != mask) {
1509 printk(TPACPI_NOTICE
1510 "requested hot key mask 0x%08x, "
1511 "forced to 0x%08x (NVRAM poll mask is "
1512 "0x%08x): no firmware mask support\n",
1513 mask, hotkey_mask, hotkey_source_mask);
1518 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1524 static int hotkey_status_get(int *status)
1526 if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
1532 static int hotkey_status_set(int status)
1534 if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
1540 static void tpacpi_input_send_tabletsw(void)
1544 if (tp_features.hotkey_tablet &&
1545 !hotkey_get_tablet_mode(&state)) {
1546 mutex_lock(&tpacpi_inputdev_send_mutex);
1548 input_report_switch(tpacpi_inputdev,
1549 SW_TABLET_MODE, !!state);
1550 input_sync(tpacpi_inputdev);
1552 mutex_unlock(&tpacpi_inputdev_send_mutex);
1556 static void tpacpi_input_send_key(unsigned int scancode)
1558 unsigned int keycode;
1560 keycode = hotkey_keycode_map[scancode];
1562 if (keycode != KEY_RESERVED) {
1563 mutex_lock(&tpacpi_inputdev_send_mutex);
1565 input_report_key(tpacpi_inputdev, keycode, 1);
1566 if (keycode == KEY_UNKNOWN)
1567 input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN,
1569 input_sync(tpacpi_inputdev);
1571 input_report_key(tpacpi_inputdev, keycode, 0);
1572 if (keycode == KEY_UNKNOWN)
1573 input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN,
1575 input_sync(tpacpi_inputdev);
1577 mutex_unlock(&tpacpi_inputdev_send_mutex);
1581 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1582 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver;
1584 static void tpacpi_hotkey_send_key(unsigned int scancode)
1586 tpacpi_input_send_key(scancode);
1587 if (hotkey_report_mode < 2) {
1588 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver.device,
1589 0x80, 0x1001 + scancode);
1593 static void hotkey_read_nvram(struct tp_nvram_state *n, u32 m)
1597 if (m & TP_NVRAM_HKEY_GROUP_HK2) {
1598 d = nvram_read_byte(TP_NVRAM_ADDR_HK2);
1599 n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD);
1600 n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM);
1601 n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY);
1602 n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE);
1604 if (m & TP_ACPI_HKEY_THNKLGHT_MASK) {
1605 d = nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT);
1606 n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT);
1608 if (m & TP_ACPI_HKEY_DISPXPAND_MASK) {
1609 d = nvram_read_byte(TP_NVRAM_ADDR_VIDEO);
1610 n->displayexp_toggle =
1611 !!(d & TP_NVRAM_MASK_HKT_DISPEXPND);
1613 if (m & TP_NVRAM_HKEY_GROUP_BRIGHTNESS) {
1614 d = nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS);
1615 n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS)
1616 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS;
1617 n->brightness_toggle =
1618 !!(d & TP_NVRAM_MASK_HKT_BRIGHTNESS);
1620 if (m & TP_NVRAM_HKEY_GROUP_VOLUME) {
1621 d = nvram_read_byte(TP_NVRAM_ADDR_MIXER);
1622 n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME)
1623 >> TP_NVRAM_POS_LEVEL_VOLUME;
1624 n->mute = !!(d & TP_NVRAM_MASK_MUTE);
1625 n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME);
1629 #define TPACPI_COMPARE_KEY(__scancode, __member) \
1631 if ((mask & (1 << __scancode)) && \
1632 oldn->__member != newn->__member) \
1633 tpacpi_hotkey_send_key(__scancode); \
1636 #define TPACPI_MAY_SEND_KEY(__scancode) \
1637 do { if (mask & (1 << __scancode)) \
1638 tpacpi_hotkey_send_key(__scancode); } while (0)
1640 static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
1641 struct tp_nvram_state *newn,
1644 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
1645 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
1646 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
1647 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12, hibernate_toggle);
1649 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP, thinklight_toggle);
1651 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8, displayexp_toggle);
1654 if (oldn->volume_toggle != newn->volume_toggle) {
1655 if (oldn->mute != newn->mute) {
1656 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
1658 if (oldn->volume_level > newn->volume_level) {
1659 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
1660 } else if (oldn->volume_level < newn->volume_level) {
1661 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
1662 } else if (oldn->mute == newn->mute) {
1663 /* repeated key presses that didn't change state */
1665 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
1666 } else if (newn->volume_level != 0) {
1667 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
1669 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
1674 /* handle brightness */
1675 if (oldn->brightness_toggle != newn->brightness_toggle) {
1676 if (oldn->brightness_level < newn->brightness_level) {
1677 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
1678 } else if (oldn->brightness_level > newn->brightness_level) {
1679 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
1681 /* repeated key presses that didn't change state */
1682 if (newn->brightness_level != 0) {
1683 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
1685 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
1691 #undef TPACPI_COMPARE_KEY
1692 #undef TPACPI_MAY_SEND_KEY
1694 static int hotkey_kthread(void *data)
1696 struct tp_nvram_state s[2];
1698 unsigned int si, so;
1700 unsigned int change_detector, must_reset;
1702 mutex_lock(&hotkey_thread_mutex);
1704 if (tpacpi_lifecycle == TPACPI_LIFE_EXITING)
1713 /* Initial state for compares */
1714 mutex_lock(&hotkey_thread_data_mutex);
1715 change_detector = hotkey_config_change;
1716 mask = hotkey_source_mask & hotkey_mask;
1717 mutex_unlock(&hotkey_thread_data_mutex);
1718 hotkey_read_nvram(&s[so], mask);
1720 while (!kthread_should_stop() && hotkey_poll_freq) {
1722 t = 1000/hotkey_poll_freq;
1723 t = msleep_interruptible(t);
1724 if (unlikely(kthread_should_stop()))
1726 must_reset = try_to_freeze();
1727 if (t > 0 && !must_reset)
1730 mutex_lock(&hotkey_thread_data_mutex);
1731 if (must_reset || hotkey_config_change != change_detector) {
1732 /* forget old state on thaw or config change */
1735 change_detector = hotkey_config_change;
1737 mask = hotkey_source_mask & hotkey_mask;
1738 mutex_unlock(&hotkey_thread_data_mutex);
1741 hotkey_read_nvram(&s[si], mask);
1742 if (likely(si != so)) {
1743 hotkey_compare_and_issue_event(&s[so], &s[si],
1753 mutex_unlock(&hotkey_thread_mutex);
1757 static void hotkey_poll_stop_sync(void)
1759 if (tpacpi_hotkey_task) {
1760 if (frozen(tpacpi_hotkey_task) ||
1761 freezing(tpacpi_hotkey_task))
1762 thaw_process(tpacpi_hotkey_task);
1764 kthread_stop(tpacpi_hotkey_task);
1765 tpacpi_hotkey_task = NULL;
1766 mutex_lock(&hotkey_thread_mutex);
1767 /* at this point, the thread did exit */
1768 mutex_unlock(&hotkey_thread_mutex);
1772 /* call with hotkey_mutex held */
1773 static void hotkey_poll_setup(int may_warn)
1775 if ((hotkey_source_mask & hotkey_mask) != 0 &&
1776 hotkey_poll_freq > 0 &&
1777 (tpacpi_inputdev->users > 0 || hotkey_report_mode < 2)) {
1778 if (!tpacpi_hotkey_task) {
1779 tpacpi_hotkey_task = kthread_run(hotkey_kthread,
1780 NULL, TPACPI_NVRAM_KTHREAD_NAME);
1781 if (IS_ERR(tpacpi_hotkey_task)) {
1782 tpacpi_hotkey_task = NULL;
1784 "could not create kernel thread "
1785 "for hotkey polling\n");
1789 hotkey_poll_stop_sync();
1791 hotkey_source_mask != 0 && hotkey_poll_freq == 0) {
1792 printk(TPACPI_NOTICE
1793 "hot keys 0x%08x require polling, "
1794 "which is currently disabled\n",
1795 hotkey_source_mask);
1800 static void hotkey_poll_setup_safe(int may_warn)
1802 mutex_lock(&hotkey_mutex);
1803 hotkey_poll_setup(may_warn);
1804 mutex_unlock(&hotkey_mutex);
1807 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1809 static void hotkey_poll_setup_safe(int __unused)
1813 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1815 static int hotkey_inputdev_open(struct input_dev *dev)
1817 switch (tpacpi_lifecycle) {
1818 case TPACPI_LIFE_INIT:
1820 * hotkey_init will call hotkey_poll_setup_safe
1821 * at the appropriate moment
1824 case TPACPI_LIFE_EXITING:
1826 case TPACPI_LIFE_RUNNING:
1827 hotkey_poll_setup_safe(0);
1831 /* Should only happen if tpacpi_lifecycle is corrupt */
1836 static void hotkey_inputdev_close(struct input_dev *dev)
1838 /* disable hotkey polling when possible */
1839 if (tpacpi_lifecycle == TPACPI_LIFE_RUNNING)
1840 hotkey_poll_setup_safe(0);
1843 /* sysfs hotkey enable ------------------------------------------------- */
1844 static ssize_t hotkey_enable_show(struct device *dev,
1845 struct device_attribute *attr,
1850 res = hotkey_status_get(&status);
1854 return snprintf(buf, PAGE_SIZE, "%d\n", status);
1857 static ssize_t hotkey_enable_store(struct device *dev,
1858 struct device_attribute *attr,
1859 const char *buf, size_t count)
1864 if (parse_strtoul(buf, 1, &t))
1867 res = hotkey_status_set(t);
1869 return (res) ? res : count;
1872 static struct device_attribute dev_attr_hotkey_enable =
1873 __ATTR(hotkey_enable, S_IWUSR | S_IRUGO,
1874 hotkey_enable_show, hotkey_enable_store);
1876 /* sysfs hotkey mask --------------------------------------------------- */
1877 static ssize_t hotkey_mask_show(struct device *dev,
1878 struct device_attribute *attr,
1883 if (mutex_lock_killable(&hotkey_mutex))
1884 return -ERESTARTSYS;
1885 res = hotkey_mask_get();
1886 mutex_unlock(&hotkey_mutex);
1889 res : snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_mask);
1892 static ssize_t hotkey_mask_store(struct device *dev,
1893 struct device_attribute *attr,
1894 const char *buf, size_t count)
1899 if (parse_strtoul(buf, 0xffffffffUL, &t))
1902 if (mutex_lock_killable(&hotkey_mutex))
1903 return -ERESTARTSYS;
1905 res = hotkey_mask_set(t);
1907 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1908 hotkey_poll_setup(1);
1911 mutex_unlock(&hotkey_mutex);
1913 return (res) ? res : count;
1916 static struct device_attribute dev_attr_hotkey_mask =
1917 __ATTR(hotkey_mask, S_IWUSR | S_IRUGO,
1918 hotkey_mask_show, hotkey_mask_store);
1920 /* sysfs hotkey bios_enabled ------------------------------------------- */
1921 static ssize_t hotkey_bios_enabled_show(struct device *dev,
1922 struct device_attribute *attr,
1925 return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_orig_status);
1928 static struct device_attribute dev_attr_hotkey_bios_enabled =
1929 __ATTR(hotkey_bios_enabled, S_IRUGO, hotkey_bios_enabled_show, NULL);
1931 /* sysfs hotkey bios_mask ---------------------------------------------- */
1932 static ssize_t hotkey_bios_mask_show(struct device *dev,
1933 struct device_attribute *attr,
1936 return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_orig_mask);
1939 static struct device_attribute dev_attr_hotkey_bios_mask =
1940 __ATTR(hotkey_bios_mask, S_IRUGO, hotkey_bios_mask_show, NULL);
1942 /* sysfs hotkey all_mask ----------------------------------------------- */
1943 static ssize_t hotkey_all_mask_show(struct device *dev,
1944 struct device_attribute *attr,
1947 return snprintf(buf, PAGE_SIZE, "0x%08x\n",
1948 hotkey_all_mask | hotkey_source_mask);
1951 static struct device_attribute dev_attr_hotkey_all_mask =
1952 __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL);
1954 /* sysfs hotkey recommended_mask --------------------------------------- */
1955 static ssize_t hotkey_recommended_mask_show(struct device *dev,
1956 struct device_attribute *attr,
1959 return snprintf(buf, PAGE_SIZE, "0x%08x\n",
1960 (hotkey_all_mask | hotkey_source_mask)
1961 & ~hotkey_reserved_mask);
1964 static struct device_attribute dev_attr_hotkey_recommended_mask =
1965 __ATTR(hotkey_recommended_mask, S_IRUGO,
1966 hotkey_recommended_mask_show, NULL);
1968 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1970 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
1971 static ssize_t hotkey_source_mask_show(struct device *dev,
1972 struct device_attribute *attr,
1975 return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_source_mask);
1978 static ssize_t hotkey_source_mask_store(struct device *dev,
1979 struct device_attribute *attr,
1980 const char *buf, size_t count)
1984 if (parse_strtoul(buf, 0xffffffffUL, &t) ||
1985 ((t & ~TPACPI_HKEY_NVRAM_KNOWN_MASK) != 0))
1988 if (mutex_lock_killable(&hotkey_mutex))
1989 return -ERESTARTSYS;
1991 HOTKEY_CONFIG_CRITICAL_START
1992 hotkey_source_mask = t;
1993 HOTKEY_CONFIG_CRITICAL_END
1995 hotkey_poll_setup(1);
1997 mutex_unlock(&hotkey_mutex);
2002 static struct device_attribute dev_attr_hotkey_source_mask =
2003 __ATTR(hotkey_source_mask, S_IWUSR | S_IRUGO,
2004 hotkey_source_mask_show, hotkey_source_mask_store);
2006 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2007 static ssize_t hotkey_poll_freq_show(struct device *dev,
2008 struct device_attribute *attr,
2011 return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_poll_freq);
2014 static ssize_t hotkey_poll_freq_store(struct device *dev,
2015 struct device_attribute *attr,
2016 const char *buf, size_t count)
2020 if (parse_strtoul(buf, 25, &t))
2023 if (mutex_lock_killable(&hotkey_mutex))
2024 return -ERESTARTSYS;
2026 hotkey_poll_freq = t;
2028 hotkey_poll_setup(1);
2029 mutex_unlock(&hotkey_mutex);
2034 static struct device_attribute dev_attr_hotkey_poll_freq =
2035 __ATTR(hotkey_poll_freq, S_IWUSR | S_IRUGO,
2036 hotkey_poll_freq_show, hotkey_poll_freq_store);
2038 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
2040 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2041 static ssize_t hotkey_radio_sw_show(struct device *dev,
2042 struct device_attribute *attr,
2046 res = hotkey_get_wlsw(&s);
2050 return snprintf(buf, PAGE_SIZE, "%d\n", !!s);
2053 static struct device_attribute dev_attr_hotkey_radio_sw =
2054 __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL);
2056 static void hotkey_radio_sw_notify_change(void)
2058 if (tp_features.hotkey_wlsw)
2059 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL,
2063 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2064 static ssize_t hotkey_tablet_mode_show(struct device *dev,
2065 struct device_attribute *attr,
2069 res = hotkey_get_tablet_mode(&s);
2073 return snprintf(buf, PAGE_SIZE, "%d\n", !!s);
2076 static struct device_attribute dev_attr_hotkey_tablet_mode =
2077 __ATTR(hotkey_tablet_mode, S_IRUGO, hotkey_tablet_mode_show, NULL);
2079 static void hotkey_tablet_mode_notify_change(void)
2081 if (tp_features.hotkey_tablet)
2082 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL,
2083 "hotkey_tablet_mode");
2086 /* sysfs hotkey report_mode -------------------------------------------- */
2087 static ssize_t hotkey_report_mode_show(struct device *dev,
2088 struct device_attribute *attr,
2091 return snprintf(buf, PAGE_SIZE, "%d\n",
2092 (hotkey_report_mode != 0) ? hotkey_report_mode : 1);
2095 static struct device_attribute dev_attr_hotkey_report_mode =
2096 __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL);
2098 /* sysfs wakeup reason (pollable) -------------------------------------- */
2099 static ssize_t hotkey_wakeup_reason_show(struct device *dev,
2100 struct device_attribute *attr,
2103 return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_wakeup_reason);
2106 static struct device_attribute dev_attr_hotkey_wakeup_reason =
2107 __ATTR(wakeup_reason, S_IRUGO, hotkey_wakeup_reason_show, NULL);
2109 static void hotkey_wakeup_reason_notify_change(void)
2111 if (tp_features.hotkey_mask)
2112 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL,
2116 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2117 static ssize_t hotkey_wakeup_hotunplug_complete_show(struct device *dev,
2118 struct device_attribute *attr,
2121 return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_autosleep_ack);
2124 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete =
2125 __ATTR(wakeup_hotunplug_complete, S_IRUGO,
2126 hotkey_wakeup_hotunplug_complete_show, NULL);
2128 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2130 if (tp_features.hotkey_mask)
2131 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL,
2132 "wakeup_hotunplug_complete");
2135 /* --------------------------------------------------------------------- */
2137 static struct attribute *hotkey_attributes[] __initdata = {
2138 &dev_attr_hotkey_enable.attr,
2139 &dev_attr_hotkey_bios_enabled.attr,
2140 &dev_attr_hotkey_report_mode.attr,
2141 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2142 &dev_attr_hotkey_mask.attr,
2143 &dev_attr_hotkey_all_mask.attr,
2144 &dev_attr_hotkey_recommended_mask.attr,
2145 &dev_attr_hotkey_source_mask.attr,
2146 &dev_attr_hotkey_poll_freq.attr,
2150 static struct attribute *hotkey_mask_attributes[] __initdata = {
2151 &dev_attr_hotkey_bios_mask.attr,
2152 #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2153 &dev_attr_hotkey_mask.attr,
2154 &dev_attr_hotkey_all_mask.attr,
2155 &dev_attr_hotkey_recommended_mask.attr,
2157 &dev_attr_hotkey_wakeup_reason.attr,
2158 &dev_attr_hotkey_wakeup_hotunplug_complete.attr,
2161 static void bluetooth_update_rfk(void);
2162 static void wan_update_rfk(void);
2163 static void uwb_update_rfk(void);
2164 static void tpacpi_send_radiosw_update(void)
2168 /* Sync these BEFORE sending any rfkill events */
2169 if (tp_features.bluetooth)
2170 bluetooth_update_rfk();
2171 if (tp_features.wan)
2173 if (tp_features.uwb)
2176 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw)) {
2177 mutex_lock(&tpacpi_inputdev_send_mutex);
2179 input_report_switch(tpacpi_inputdev,
2180 SW_RFKILL_ALL, !!wlsw);
2181 input_sync(tpacpi_inputdev);
2183 mutex_unlock(&tpacpi_inputdev_send_mutex);
2185 hotkey_radio_sw_notify_change();
2188 static void hotkey_exit(void)
2190 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2191 hotkey_poll_stop_sync();
2194 if (hotkey_dev_attributes)
2195 delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj);
2197 kfree(hotkey_keycode_map);
2199 if (tp_features.hotkey) {
2200 dbg_printk(TPACPI_DBG_EXIT,
2201 "restoring original hot key mask\n");
2202 /* no short-circuit boolean operator below! */
2203 if ((hotkey_mask_set(hotkey_orig_mask) |
2204 hotkey_status_set(hotkey_orig_status)) != 0)
2206 "failed to restore hot key mask "
2207 "to BIOS defaults\n");
2211 static int __init hotkey_init(struct ibm_init_struct *iibm)
2213 /* Requirements for changing the default keymaps:
2215 * 1. Many of the keys are mapped to KEY_RESERVED for very
2216 * good reasons. Do not change them unless you have deep
2217 * knowledge on the IBM and Lenovo ThinkPad firmware for
2218 * the various ThinkPad models. The driver behaves
2219 * differently for KEY_RESERVED: such keys have their
2220 * hot key mask *unset* in mask_recommended, and also
2221 * in the initial hot key mask programmed into the
2222 * firmware at driver load time, which means the firm-
2223 * ware may react very differently if you change them to
2226 * 2. You must be subscribed to the linux-thinkpad and
2227 * ibm-acpi-devel mailing lists, and you should read the
2228 * list archives since 2007 if you want to change the
2229 * keymaps. This requirement exists so that you will
2230 * know the past history of problems with the thinkpad-
2231 * acpi driver keymaps, and also that you will be
2232 * listening to any bug reports;
2234 * 3. Do not send thinkpad-acpi specific patches directly to
2235 * for merging, *ever*. Send them to the linux-acpi
2236 * mailinglist for comments. Merging is to be done only
2237 * through acpi-test and the ACPI maintainer.
2239 * If the above is too much to ask, don't change the keymap.
2240 * Ask the thinkpad-acpi maintainer to do it, instead.
2242 static u16 ibm_keycode_map[] __initdata = {
2243 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2244 KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP,
2245 KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8,
2246 KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND,
2248 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2249 KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */
2250 KEY_UNKNOWN, /* 0x0D: FN+INSERT */
2251 KEY_UNKNOWN, /* 0x0E: FN+DELETE */
2253 /* brightness: firmware always reacts to them, unless
2254 * X.org did some tricks in the radeon BIOS scratch
2255 * registers of *some* models */
2256 KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */
2257 KEY_RESERVED, /* 0x10: FN+END (brightness down) */
2259 /* Thinklight: firmware always react to it */
2260 KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */
2262 KEY_UNKNOWN, /* 0x12: FN+PGDOWN */
2263 KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */
2265 /* Volume: firmware always react to it and reprograms
2266 * the built-in *extra* mixer. Never map it to control
2267 * another mixer by default. */
2268 KEY_RESERVED, /* 0x14: VOLUME UP */
2269 KEY_RESERVED, /* 0x15: VOLUME DOWN */
2270 KEY_RESERVED, /* 0x16: MUTE */
2272 KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2274 /* (assignments unknown, please report if found) */
2275 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
2276 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
2278 static u16 lenovo_keycode_map[] __initdata = {
2279 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2280 KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP,
2281 KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8,
2282 KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND,
2284 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2285 KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */
2286 KEY_UNKNOWN, /* 0x0D: FN+INSERT */
2287 KEY_UNKNOWN, /* 0x0E: FN+DELETE */
2289 /* These either have to go through ACPI video, or
2290 * act like in the IBM ThinkPads, so don't ever
2291 * enable them by default */
2292 KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */
2293 KEY_RESERVED, /* 0x10: FN+END (brightness down) */
2295 KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */
2297 KEY_UNKNOWN, /* 0x12: FN+PGDOWN */
2298 KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */
2300 /* Volume: z60/z61, T60 (BIOS version?): firmware always
2301 * react to it and reprograms the built-in *extra* mixer.
2302 * Never map it to control another mixer by default.
2304 * T60?, T61, R60?, R61: firmware and EC tries to send
2305 * these over the regular keyboard, so these are no-ops,
2306 * but there are still weird bugs re. MUTE, so do not
2307 * change unless you get test reports from all Lenovo
2308 * models. May cause the BIOS to interfere with the
2311 KEY_RESERVED, /* 0x14: VOLUME UP */
2312 KEY_RESERVED, /* 0x15: VOLUME DOWN */
2313 KEY_RESERVED, /* 0x16: MUTE */
2315 KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2317 /* (assignments unknown, please report if found) */
2318 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
2319 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
2322 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2323 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2324 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2330 vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n");
2332 BUG_ON(!tpacpi_inputdev);
2333 BUG_ON(tpacpi_inputdev->open != NULL ||
2334 tpacpi_inputdev->close != NULL);
2336 TPACPI_ACPIHANDLE_INIT(hkey);
2337 mutex_init(&hotkey_mutex);
2339 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2340 mutex_init(&hotkey_thread_mutex);
2341 mutex_init(&hotkey_thread_data_mutex);
2344 /* hotkey not supported on 570 */
2345 tp_features.hotkey = hkey_handle != NULL;
2347 vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n",
2348 str_supported(tp_features.hotkey));
2350 if (!tp_features.hotkey)
2353 tpacpi_disable_brightness_delay();
2355 hotkey_dev_attributes = create_attr_set(13, NULL);
2356 if (!hotkey_dev_attributes)
2358 res = add_many_to_attr_set(hotkey_dev_attributes,
2360 ARRAY_SIZE(hotkey_attributes));
2364 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2365 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2366 for HKEY interface version 0x100 */
2367 if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) {
2368 if ((hkeyv >> 8) != 1) {
2369 printk(TPACPI_ERR "unknown version of the "
2370 "HKEY interface: 0x%x\n", hkeyv);
2371 printk(TPACPI_ERR "please report this to %s\n",
2375 * MHKV 0x100 in A31, R40, R40e,
2376 * T4x, X31, and later
2378 tp_features.hotkey_mask = 1;
2382 vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n",
2383 str_supported(tp_features.hotkey_mask));
2385 if (tp_features.hotkey_mask) {
2386 if (!acpi_evalf(hkey_handle, &hotkey_all_mask,
2389 "missing MHKA handler, "
2390 "please report this to %s\n",
2392 /* FN+F12, FN+F4, FN+F3 */
2393 hotkey_all_mask = 0x080cU;
2397 /* hotkey_source_mask *must* be zero for
2398 * the first hotkey_mask_get */
2399 res = hotkey_status_get(&hotkey_orig_status);
2403 if (tp_features.hotkey_mask) {
2404 res = hotkey_mask_get();
2408 hotkey_orig_mask = hotkey_mask;
2409 res = add_many_to_attr_set(
2410 hotkey_dev_attributes,
2411 hotkey_mask_attributes,
2412 ARRAY_SIZE(hotkey_mask_attributes));
2417 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2418 if (tp_features.hotkey_mask) {
2419 hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK
2422 hotkey_source_mask = TPACPI_HKEY_NVRAM_GOOD_MASK;
2425 vdbg_printk(TPACPI_DBG_INIT,
2426 "hotkey source mask 0x%08x, polling freq %d\n",
2427 hotkey_source_mask, hotkey_poll_freq);
2430 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2432 tp_features.hotkey_wlsw = 1;
2434 "radio switch emulation enabled\n");
2437 /* Not all thinkpads have a hardware radio switch */
2438 if (acpi_evalf(hkey_handle, &status, "WLSW", "qd")) {
2439 tp_features.hotkey_wlsw = 1;
2441 "radio switch found; radios are %s\n",
2442 enabled(status, 0));
2444 if (tp_features.hotkey_wlsw)
2445 res = add_to_attr_set(hotkey_dev_attributes,
2446 &dev_attr_hotkey_radio_sw.attr);
2448 /* For X41t, X60t, X61t Tablets... */
2449 if (!res && acpi_evalf(hkey_handle, &status, "MHKG", "qd")) {
2450 tp_features.hotkey_tablet = 1;
2452 "possible tablet mode switch found; "
2453 "ThinkPad in %s mode\n",
2454 (status & TP_HOTKEY_TABLET_MASK)?
2455 "tablet" : "laptop");
2456 res = add_to_attr_set(hotkey_dev_attributes,
2457 &dev_attr_hotkey_tablet_mode.attr);
2461 res = register_attr_set_with_sysfs(
2462 hotkey_dev_attributes,
2463 &tpacpi_pdev->dev.kobj);
2467 /* Set up key map */
2469 hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE,
2471 if (!hotkey_keycode_map) {
2473 "failed to allocate memory for key map\n");
2478 if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) {
2479 dbg_printk(TPACPI_DBG_INIT,
2480 "using Lenovo default hot key map\n");
2481 memcpy(hotkey_keycode_map, &lenovo_keycode_map,
2482 TPACPI_HOTKEY_MAP_SIZE);
2484 dbg_printk(TPACPI_DBG_INIT,
2485 "using IBM default hot key map\n");
2486 memcpy(hotkey_keycode_map, &ibm_keycode_map,
2487 TPACPI_HOTKEY_MAP_SIZE);
2490 set_bit(EV_KEY, tpacpi_inputdev->evbit);
2491 set_bit(EV_MSC, tpacpi_inputdev->evbit);
2492 set_bit(MSC_SCAN, tpacpi_inputdev->mscbit);
2493 tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE;
2494 tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN;
2495 tpacpi_inputdev->keycode = hotkey_keycode_map;
2496 for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) {
2497 if (hotkey_keycode_map[i] != KEY_RESERVED) {
2498 set_bit(hotkey_keycode_map[i],
2499 tpacpi_inputdev->keybit);
2501 if (i < sizeof(hotkey_reserved_mask)*8)
2502 hotkey_reserved_mask |= 1 << i;
2506 if (tp_features.hotkey_wlsw) {
2507 set_bit(EV_SW, tpacpi_inputdev->evbit);
2508 set_bit(SW_RFKILL_ALL, tpacpi_inputdev->swbit);
2510 if (tp_features.hotkey_tablet) {
2511 set_bit(EV_SW, tpacpi_inputdev->evbit);
2512 set_bit(SW_TABLET_MODE, tpacpi_inputdev->swbit);
2515 /* Do not issue duplicate brightness change events to
2517 if (!tp_features.bright_acpimode)
2518 /* update bright_acpimode... */
2519 tpacpi_check_std_acpi_brightness_support();
2521 if (tp_features.bright_acpimode) {
2523 "This ThinkPad has standard ACPI backlight "
2524 "brightness control, supported by the ACPI "
2526 printk(TPACPI_NOTICE
2527 "Disabling thinkpad-acpi brightness events "
2530 /* The hotkey_reserved_mask change below is not
2531 * necessary while the keys are at KEY_RESERVED in the
2532 * default map, but better safe than sorry, leave it
2533 * here as a marker of what we have to do, especially
2534 * when we finally become able to set this at runtime
2535 * on response to X.org requests */
2536 hotkey_reserved_mask |=
2537 (1 << TP_ACPI_HOTKEYSCAN_FNHOME)
2538 | (1 << TP_ACPI_HOTKEYSCAN_FNEND);
2541 dbg_printk(TPACPI_DBG_INIT, "enabling hot key handling\n");
2542 res = hotkey_status_set(1);
2547 res = hotkey_mask_set(((hotkey_all_mask | hotkey_source_mask)
2548 & ~hotkey_reserved_mask)
2549 | hotkey_orig_mask);
2550 if (res < 0 && res != -ENXIO) {
2555 dbg_printk(TPACPI_DBG_INIT,
2556 "legacy hot key reporting over procfs %s\n",
2557 (hotkey_report_mode < 2) ?
2558 "enabled" : "disabled");
2560 tpacpi_inputdev->open = &hotkey_inputdev_open;
2561 tpacpi_inputdev->close = &hotkey_inputdev_close;
2563 hotkey_poll_setup_safe(1);
2564 tpacpi_send_radiosw_update();
2565 tpacpi_input_send_tabletsw();
2570 delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj);
2571 hotkey_dev_attributes = NULL;
2573 return (res < 0)? res : 1;
2576 static bool hotkey_notify_hotkey(const u32 hkey,
2578 bool *ignore_acpi_ev)
2580 /* 0x1000-0x1FFF: key presses */
2581 unsigned int scancode = hkey & 0xfff;
2582 *send_acpi_ev = true;
2583 *ignore_acpi_ev = false;
2585 if (scancode > 0 && scancode < 0x21) {
2587 if (!(hotkey_source_mask & (1 << scancode))) {
2588 tpacpi_input_send_key(scancode);
2589 *send_acpi_ev = false;
2591 *ignore_acpi_ev = true;
2598 static bool hotkey_notify_wakeup(const u32 hkey,
2600 bool *ignore_acpi_ev)
2602 /* 0x2000-0x2FFF: Wakeup reason */
2603 *send_acpi_ev = true;
2604 *ignore_acpi_ev = false;
2607 case 0x2304: /* suspend, undock */
2608 case 0x2404: /* hibernation, undock */
2609 hotkey_wakeup_reason = TP_ACPI_WAKEUP_UNDOCK;
2610 *ignore_acpi_ev = true;
2613 case 0x2305: /* suspend, bay eject */
2614 case 0x2405: /* hibernation, bay eject */
2615 hotkey_wakeup_reason = TP_ACPI_WAKEUP_BAYEJ;
2616 *ignore_acpi_ev = true;
2619 case 0x2313: /* Battery on critical low level (S3) */
2620 case 0x2413: /* Battery on critical low level (S4) */
2622 "EMERGENCY WAKEUP: battery almost empty\n");
2623 /* how to auto-heal: */
2624 /* 2313: woke up from S3, go to S4/S5 */
2625 /* 2413: woke up from S4, go to S5 */
2632 if (hotkey_wakeup_reason != TP_ACPI_WAKEUP_NONE) {
2634 "woke up due to a hot-unplug "
2636 hotkey_wakeup_reason_notify_change();
2641 static bool hotkey_notify_usrevent(const u32 hkey,
2643 bool *ignore_acpi_ev)
2645 /* 0x5000-0x5FFF: human interface helpers */
2646 *send_acpi_ev = true;
2647 *ignore_acpi_ev = false;
2650 case 0x5010: /* Lenovo new BIOS: brightness changed */
2651 case 0x500b: /* X61t: tablet pen inserted into bay */
2652 case 0x500c: /* X61t: tablet pen removed from bay */
2655 case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
2656 case 0x500a: /* X41t-X61t: swivel down (normal mode) */
2657 tpacpi_input_send_tabletsw();
2658 hotkey_tablet_mode_notify_change();
2659 *send_acpi_ev = false;
2664 /* LID switch events. Do not propagate */
2665 *ignore_acpi_ev = true;
2673 static bool hotkey_notify_thermal(const u32 hkey,
2675 bool *ignore_acpi_ev)
2677 /* 0x6000-0x6FFF: thermal alarms */
2678 *send_acpi_ev = true;
2679 *ignore_acpi_ev = false;
2684 "THERMAL ALARM: battery is too hot!\n");
2685 /* recommended action: warn user through gui */
2689 "THERMAL EMERGENCY: battery is extremely hot!\n");
2690 /* recommended action: immediate sleep/hibernate */
2695 "a sensor reports something is too hot!\n");
2696 /* recommended action: warn user through gui, that */
2697 /* some internal component is too hot */
2701 "THERMAL EMERGENCY: "
2702 "a sensor reports something is extremely hot!\n");
2703 /* recommended action: immediate sleep/hibernate */
2707 "EC reports that Thermal Table has changed\n");
2708 /* recommended action: do nothing, we don't have
2709 * Lenovo ATM information */
2713 "THERMAL ALERT: unknown thermal alarm received\n");
2718 static void hotkey_notify(struct ibm_struct *ibm, u32 event)
2722 bool ignore_acpi_ev;
2725 if (event != 0x80) {
2727 "unknown HKEY notification event %d\n", event);
2728 /* forward it to userspace, maybe it knows how to handle it */
2729 acpi_bus_generate_netlink_event(
2730 ibm->acpi->device->pnp.device_class,
2731 dev_name(&ibm->acpi->device->dev),
2737 if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) {
2738 printk(TPACPI_ERR "failed to retrieve HKEY event\n");
2747 send_acpi_ev = true;
2748 ignore_acpi_ev = false;
2750 switch (hkey >> 12) {
2752 /* 0x1000-0x1FFF: key presses */
2753 known_ev = hotkey_notify_hotkey(hkey, &send_acpi_ev,
2757 /* 0x2000-0x2FFF: Wakeup reason */
2758 known_ev = hotkey_notify_wakeup(hkey, &send_acpi_ev,
2762 /* 0x3000-0x3FFF: bay-related wakeups */
2763 if (hkey == 0x3003) {
2764 hotkey_autosleep_ack = 1;
2767 hotkey_wakeup_hotunplug_complete_notify_change();
2774 /* 0x4000-0x4FFF: dock-related wakeups */
2775 if (hkey == 0x4003) {
2776 hotkey_autosleep_ack = 1;
2779 hotkey_wakeup_hotunplug_complete_notify_change();
2786 /* 0x5000-0x5FFF: human interface helpers */
2787 known_ev = hotkey_notify_usrevent(hkey, &send_acpi_ev,
2791 /* 0x6000-0x6FFF: thermal alarms */
2792 known_ev = hotkey_notify_thermal(hkey, &send_acpi_ev,
2796 /* 0x7000-0x7FFF: misc */
2797 if (tp_features.hotkey_wlsw && hkey == 0x7000) {
2798 tpacpi_send_radiosw_update();
2803 /* fallthrough to default */
2808 printk(TPACPI_NOTICE
2809 "unhandled HKEY event 0x%04x\n", hkey);
2810 printk(TPACPI_NOTICE
2811 "please report the conditions when this "
2812 "event happened to %s\n", TPACPI_MAIL);
2816 if (!ignore_acpi_ev &&
2817 (send_acpi_ev || hotkey_report_mode < 2)) {
2818 acpi_bus_generate_proc_event(ibm->acpi->device,
2822 /* netlink events */
2823 if (!ignore_acpi_ev && send_acpi_ev) {
2824 acpi_bus_generate_netlink_event(
2825 ibm->acpi->device->pnp.device_class,
2826 dev_name(&ibm->acpi->device->dev),
2832 static void hotkey_suspend(pm_message_t state)
2834 /* Do these on suspend, we get the events on early resume! */
2835 hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE;
2836 hotkey_autosleep_ack = 0;
2839 static void hotkey_resume(void)
2841 tpacpi_disable_brightness_delay();
2843 if (hotkey_mask_get())
2845 "error while trying to read hot key mask "
2847 tpacpi_send_radiosw_update();
2848 hotkey_tablet_mode_notify_change();
2849 hotkey_wakeup_reason_notify_change();
2850 hotkey_wakeup_hotunplug_complete_notify_change();
2851 hotkey_poll_setup_safe(0);
2854 /* procfs -------------------------------------------------------------- */
2855 static int hotkey_read(char *p)
2860 if (!tp_features.hotkey) {
2861 len += sprintf(p + len, "status:\t\tnot supported\n");
2865 if (mutex_lock_killable(&hotkey_mutex))
2866 return -ERESTARTSYS;
2867 res = hotkey_status_get(&status);
2869 res = hotkey_mask_get();
2870 mutex_unlock(&hotkey_mutex);
2874 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
2875 if (tp_features.hotkey_mask) {
2876 len += sprintf(p + len, "mask:\t\t0x%08x\n", hotkey_mask);
2877 len += sprintf(p + len,
2878 "commands:\tenable, disable, reset, <mask>\n");
2880 len += sprintf(p + len, "mask:\t\tnot supported\n");
2881 len += sprintf(p + len, "commands:\tenable, disable, reset\n");
2887 static int hotkey_write(char *buf)
2893 if (!tp_features.hotkey)
2896 if (mutex_lock_killable(&hotkey_mutex))
2897 return -ERESTARTSYS;
2903 while ((cmd = next_cmd(&buf))) {
2904 if (strlencmp(cmd, "enable") == 0) {
2906 } else if (strlencmp(cmd, "disable") == 0) {
2908 } else if (strlencmp(cmd, "reset") == 0) {
2909 status = hotkey_orig_status;
2910 mask = hotkey_orig_mask;
2911 } else if (sscanf(cmd, "0x%x", &mask) == 1) {
2913 } else if (sscanf(cmd, "%x", &mask) == 1) {
2921 res = hotkey_status_set(status);
2923 if (!res && mask != hotkey_mask)
2924 res = hotkey_mask_set(mask);
2927 mutex_unlock(&hotkey_mutex);
2931 static const struct acpi_device_id ibm_htk_device_ids[] = {
2932 {TPACPI_ACPI_HKEY_HID, 0},
2936 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = {
2937 .hid = ibm_htk_device_ids,
2938 .notify = hotkey_notify,
2939 .handle = &hkey_handle,
2940 .type = ACPI_DEVICE_NOTIFY,
2943 static struct ibm_struct hotkey_driver_data = {
2945 .read = hotkey_read,
2946 .write = hotkey_write,
2947 .exit = hotkey_exit,
2948 .resume = hotkey_resume,
2949 .suspend = hotkey_suspend,
2950 .acpi = &ibm_hotkey_acpidriver,
2953 /*************************************************************************
2954 * Bluetooth subdriver
2958 /* ACPI GBDC/SBDC bits */
2959 TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */
2960 TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */
2961 TP_ACPI_BLUETOOTH_RESUMECTRL = 0x04, /* Bluetooth state at resume:
2966 /* ACPI \BLTH commands */
2967 TP_ACPI_BLTH_GET_ULTRAPORT_ID = 0x00, /* Get Ultraport BT ID */
2968 TP_ACPI_BLTH_GET_PWR_ON_RESUME = 0x01, /* Get power-on-resume state */
2969 TP_ACPI_BLTH_PWR_ON_ON_RESUME = 0x02, /* Resume powered on */
2970 TP_ACPI_BLTH_PWR_OFF_ON_RESUME = 0x03, /* Resume powered off */
2971 TP_ACPI_BLTH_SAVE_STATE = 0x05, /* Save state for S4/S5 */
2974 static struct rfkill *tpacpi_bluetooth_rfkill;
2976 static void bluetooth_suspend(pm_message_t state)
2978 /* Try to make sure radio will resume powered off */
2979 acpi_evalf(NULL, NULL, "\\BLTH", "vd",
2980 TP_ACPI_BLTH_PWR_OFF_ON_RESUME);
2983 static int bluetooth_get_radiosw(void)
2987 if (!tp_features.bluetooth)
2990 /* WLSW overrides bluetooth in firmware/hardware, reflect that */
2991 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status)
2992 return RFKILL_STATE_HARD_BLOCKED;
2994 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2995 if (dbg_bluetoothemul)
2996 return (tpacpi_bluetooth_emulstate) ?
2997 RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED;
3000 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
3003 return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0) ?
3004 RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED;
3007 static void bluetooth_update_rfk(void)
3011 if (!tpacpi_bluetooth_rfkill)
3014 status = bluetooth_get_radiosw();
3017 rfkill_force_state(tpacpi_bluetooth_rfkill, status);
3020 static int bluetooth_set_radiosw(int radio_on, int update_rfk)
3024 if (!tp_features.bluetooth)
3027 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3028 * reason to risk weird behaviour. */
3029 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status
3033 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3034 if (dbg_bluetoothemul) {
3035 tpacpi_bluetooth_emulstate = !!radio_on;
3037 bluetooth_update_rfk();
3042 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */
3044 status = TP_ACPI_BLUETOOTH_RADIOSSW;
3047 if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
3051 bluetooth_update_rfk();
3056 /* sysfs bluetooth enable ---------------------------------------------- */
3057 static ssize_t bluetooth_enable_show(struct device *dev,
3058 struct device_attribute *attr,
3063 status = bluetooth_get_radiosw();
3067 return snprintf(buf, PAGE_SIZE, "%d\n",
3068 (status == RFKILL_STATE_UNBLOCKED) ? 1 : 0);
3071 static ssize_t bluetooth_enable_store(struct device *dev,
3072 struct device_attribute *attr,
3073 const char *buf, size_t count)
3078 if (parse_strtoul(buf, 1, &t))
3081 res = bluetooth_set_radiosw(t, 1);
3083 return (res) ? res : count;
3086 static struct device_attribute dev_attr_bluetooth_enable =
3087 __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO,
3088 bluetooth_enable_show, bluetooth_enable_store);
3090 /* --------------------------------------------------------------------- */
3092 static struct attribute *bluetooth_attributes[] = {
3093 &dev_attr_bluetooth_enable.attr,
3097 static const struct attribute_group bluetooth_attr_group = {
3098 .attrs = bluetooth_attributes,
3101 static int tpacpi_bluetooth_rfk_get(void *data, enum rfkill_state *state)
3103 int bts = bluetooth_get_radiosw();
3112 static int tpacpi_bluetooth_rfk_set(void *data, enum rfkill_state state)
3114 return bluetooth_set_radiosw((state == RFKILL_STATE_UNBLOCKED), 0);
3117 static void bluetooth_shutdown(void)
3119 /* Order firmware to save current state to NVRAM */
3120 if (!acpi_evalf(NULL, NULL, "\\BLTH", "vd",
3121 TP_ACPI_BLTH_SAVE_STATE))
3122 printk(TPACPI_NOTICE
3123 "failed to save bluetooth state to NVRAM\n");
3126 static void bluetooth_exit(void)
3128 bluetooth_shutdown();
3130 if (tpacpi_bluetooth_rfkill)
3131 rfkill_unregister(tpacpi_bluetooth_rfkill);
3133 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
3134 &bluetooth_attr_group);
3137 static int __init bluetooth_init(struct ibm_init_struct *iibm)
3142 vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n");
3144 TPACPI_ACPIHANDLE_INIT(hkey);
3146 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3147 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
3148 tp_features.bluetooth = hkey_handle &&
3149 acpi_evalf(hkey_handle, &status, "GBDC", "qd");
3151 vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s, status 0x%02x\n",
3152 str_supported(tp_features.bluetooth),
3155 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3156 if (dbg_bluetoothemul) {
3157 tp_features.bluetooth = 1;
3159 "bluetooth switch emulation enabled\n");
3162 if (tp_features.bluetooth &&
3163 !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) {
3164 /* no bluetooth hardware present in system */
3165 tp_features.bluetooth = 0;
3166 dbg_printk(TPACPI_DBG_INIT,
3167 "bluetooth hardware not installed\n");
3170 if (!tp_features.bluetooth)
3173 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
3174 &bluetooth_attr_group);
3178 res = tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID,
3179 &tpacpi_bluetooth_rfkill,
3180 RFKILL_TYPE_BLUETOOTH,
3181 "tpacpi_bluetooth_sw",
3183 tpacpi_bluetooth_rfk_set,
3184 tpacpi_bluetooth_rfk_get);
3193 /* procfs -------------------------------------------------------------- */
3194 static int bluetooth_read(char *p)
3197 int status = bluetooth_get_radiosw();
3199 if (!tp_features.bluetooth)
3200 len += sprintf(p + len, "status:\t\tnot supported\n");
3202 len += sprintf(p + len, "status:\t\t%s\n",
3203 (status == RFKILL_STATE_UNBLOCKED) ?
3204 "enabled" : "disabled");
3205 len += sprintf(p + len, "commands:\tenable, disable\n");
3211 static int bluetooth_write(char *buf)
3215 if (!tp_features.bluetooth)
3218 while ((cmd = next_cmd(&buf))) {
3219 if (strlencmp(cmd, "enable") == 0) {
3220 bluetooth_set_radiosw(1, 1);
3221 } else if (strlencmp(cmd, "disable") == 0) {
3222 bluetooth_set_radiosw(0, 1);
3230 static struct ibm_struct bluetooth_driver_data = {
3231 .name = "bluetooth",
3232 .read = bluetooth_read,
3233 .write = bluetooth_write,
3234 .exit = bluetooth_exit,
3235 .suspend = bluetooth_suspend,
3236 .shutdown = bluetooth_shutdown,
3239 /*************************************************************************
3244 /* ACPI GWAN/SWAN bits */
3245 TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */
3246 TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */
3247 TP_ACPI_WANCARD_RESUMECTRL = 0x04, /* Wan state at resume:
3251 static struct rfkill *tpacpi_wan_rfkill;
3253 static void wan_suspend(pm_message_t state)
3255 /* Try to make sure radio will resume powered off */
3256 acpi_evalf(NULL, NULL, "\\WGSV", "qvd",
3257 TP_ACPI_WGSV_PWR_OFF_ON_RESUME);
3260 static int wan_get_radiosw(void)
3264 if (!tp_features.wan)
3267 /* WLSW overrides WWAN in firmware/hardware, reflect that */
3268 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status)
3269 return RFKILL_STATE_HARD_BLOCKED;
3271 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3273 return (tpacpi_wwan_emulstate) ?
3274 RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED;
3277 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
3280 return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0) ?
3281 RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED;
3284 static void wan_update_rfk(void)
3288 if (!tpacpi_wan_rfkill)
3291 status = wan_get_radiosw();
3294 rfkill_force_state(tpacpi_wan_rfkill, status);
3297 static int wan_set_radiosw(int radio_on, int update_rfk)
3301 if (!tp_features.wan)
3304 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3305 * reason to risk weird behaviour. */
3306 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status
3310 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3312 tpacpi_wwan_emulstate = !!radio_on;
3319 /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */
3321 status = TP_ACPI_WANCARD_RADIOSSW;
3324 if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
3333 /* sysfs wan enable ---------------------------------------------------- */
3334 static ssize_t wan_enable_show(struct device *dev,
3335 struct device_attribute *attr,
3340 status = wan_get_radiosw();
3344 return snprintf(buf, PAGE_SIZE, "%d\n",
3345 (status == RFKILL_STATE_UNBLOCKED) ? 1 : 0);
3348 static ssize_t wan_enable_store(struct device *dev,
3349 struct device_attribute *attr,
3350 const char *buf, size_t count)
3355 if (parse_strtoul(buf, 1, &t))
3358 res = wan_set_radiosw(t, 1);
3360 return (res) ? res : count;
3363 static struct device_attribute dev_attr_wan_enable =
3364 __ATTR(wwan_enable, S_IWUSR | S_IRUGO,
3365 wan_enable_show, wan_enable_store);
3367 /* --------------------------------------------------------------------- */
3369 static struct attribute *wan_attributes[] = {
3370 &dev_attr_wan_enable.attr,
3374 static const struct attribute_group wan_attr_group = {
3375 .attrs = wan_attributes,
3378 static int tpacpi_wan_rfk_get(void *data, enum rfkill_state *state)
3380 int wans = wan_get_radiosw();
3389 static int tpacpi_wan_rfk_set(void *data, enum rfkill_state state)
3391 return wan_set_radiosw((state == RFKILL_STATE_UNBLOCKED), 0);
3394 static void wan_shutdown(void)
3396 /* Order firmware to save current state to NVRAM */
3397 if (!acpi_evalf(NULL, NULL, "\\WGSV", "vd",
3398 TP_ACPI_WGSV_SAVE_STATE))
3399 printk(TPACPI_NOTICE
3400 "failed to save WWAN state to NVRAM\n");
3403 static void wan_exit(void)
3407 if (tpacpi_wan_rfkill)
3408 rfkill_unregister(tpacpi_wan_rfkill);
3410 sysfs_remove_group(&tpacpi_pdev->dev.kobj,
3414 static int __init wan_init(struct ibm_init_struct *iibm)
3419 vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n");
3421 TPACPI_ACPIHANDLE_INIT(hkey);
3423 tp_features.wan = hkey_handle &&
3424 acpi_evalf(hkey_handle, &status, "GWAN", "qd");
3426 vdbg_printk(TPACPI_DBG_INIT, "wan is %s, status 0x%02x\n",
3427 str_supported(tp_features.wan),
3430 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3432 tp_features.wan = 1;
3434 "wwan switch emulation enabled\n");
3437 if (tp_features.wan &&
3438 !(status & TP_ACPI_WANCARD_HWPRESENT)) {
3439 /* no wan hardware present in system */
3440 tp_features.wan = 0;
3441 dbg_printk(TPACPI_DBG_INIT,
3442 "wan hardware not installed\n");
3445 if (!tp_features.wan)
3448 res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
3453 res = tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID,
3459 tpacpi_wan_rfk_get);
3468 /* procfs -------------------------------------------------------------- */
3469 static int wan_read(char *p)
3472 int status = wan_get_radiosw();
3474 if (!tp_features.wan)
3475 len += sprintf(p + len, "status:\t\tnot supported\n");
3477 len += sprintf(p + len, "status:\t\t%s\n",
3478 (status == RFKILL_STATE_UNBLOCKED) ?
3479 "enabled" : "disabled");
3480 len += sprintf(p + len, "commands:\tenable, disable\n");
3486 static int wan_write(char *buf)
3490 if (!tp_features.wan)
3493 while ((cmd = next_cmd(&buf))) {
3494 if (strlencmp(cmd, "enable") == 0) {
3495 wan_set_radiosw(1, 1);
3496 } else if (strlencmp(cmd, "disable") == 0) {
3497 wan_set_radiosw(0, 1);
3505 static struct ibm_struct wan_driver_data = {
3510 .suspend = wan_suspend,
3511 .shutdown = wan_shutdown,
3514 /*************************************************************************
3519 /* ACPI GUWB/SUWB bits */
3520 TP_ACPI_UWB_HWPRESENT = 0x01, /* UWB hw available */
3521 TP_ACPI_UWB_RADIOSSW = 0x02, /* UWB radio enabled */
3524 static struct rfkill *tpacpi_uwb_rfkill;
3526 static int uwb_get_radiosw(void)
3530 if (!tp_features.uwb)
3533 /* WLSW overrides UWB in firmware/hardware, reflect that */
3534 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status)
3535 return RFKILL_STATE_HARD_BLOCKED;
3537 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3539 return (tpacpi_uwb_emulstate) ?
3540 RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED;
3543 if (!acpi_evalf(hkey_handle, &status, "GUWB", "d"))
3546 return ((status & TP_ACPI_UWB_RADIOSSW) != 0) ?
3547 RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED;
3550 static void uwb_update_rfk(void)
3554 if (!tpacpi_uwb_rfkill)
3557 status = uwb_get_radiosw();
3560 rfkill_force_state(tpacpi_uwb_rfkill, status);
3563 static int uwb_set_radiosw(int radio_on, int update_rfk)
3567 if (!tp_features.uwb)
3570 /* WLSW overrides UWB in firmware/hardware, but there is no
3571 * reason to risk weird behaviour. */
3572 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status
3576 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3578 tpacpi_uwb_emulstate = !!radio_on;
3585 status = (radio_on) ? TP_ACPI_UWB_RADIOSSW : 0;
3586 if (!acpi_evalf(hkey_handle, NULL, "SUWB", "vd", status))
3595 /* --------------------------------------------------------------------- */
3597 static int tpacpi_uwb_rfk_get(void *data, enum rfkill_state *state)
3599 int uwbs = uwb_get_radiosw();
3608 static int tpacpi_uwb_rfk_set(void *data, enum rfkill_state state)
3610 return uwb_set_radiosw((state == RFKILL_STATE_UNBLOCKED), 0);
3613 static void uwb_exit(void)
3615 if (tpacpi_uwb_rfkill)
3616 rfkill_unregister(tpacpi_uwb_rfkill);
3619 static int __init uwb_init(struct ibm_init_struct *iibm)
3624 vdbg_printk(TPACPI_DBG_INIT, "initializing uwb subdriver\n");
3626 TPACPI_ACPIHANDLE_INIT(hkey);
3628 tp_features.uwb = hkey_handle &&
3629 acpi_evalf(hkey_handle, &status, "GUWB", "qd");
3631 vdbg_printk(TPACPI_DBG_INIT, "uwb is %s, status 0x%02x\n",
3632 str_supported(tp_features.uwb),
3635 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3637 tp_features.uwb = 1;
3639 "uwb switch emulation enabled\n");
3642 if (tp_features.uwb &&
3643 !(status & TP_ACPI_UWB_HWPRESENT)) {
3644 /* no uwb hardware present in system */
3645 tp_features.uwb = 0;
3646 dbg_printk(TPACPI_DBG_INIT,
3647 "uwb hardware not installed\n");
3650 if (!tp_features.uwb)
3653 res = tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID,
3659 tpacpi_uwb_rfk_get);
3664 static struct ibm_struct uwb_driver_data = {
3667 .flags.experimental = 1,
3670 /*************************************************************************
3674 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
3676 enum video_access_mode {
3677 TPACPI_VIDEO_NONE = 0,
3678 TPACPI_VIDEO_570, /* 570 */
3679 TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */
3680 TPACPI_VIDEO_NEW, /* all others */
3683 enum { /* video status flags, based on VIDEO_570 */
3684 TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */
3685 TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */
3686 TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */
3689 enum { /* TPACPI_VIDEO_570 constants */
3690 TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */
3691 TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to
3692 * video_status_flags */
3693 TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */
3694 TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */
3697 static enum video_access_mode video_supported;
3698 static int video_orig_autosw;
3700 static int video_autosw_get(void);
3701 static int video_autosw_set(int enable);
3703 TPACPI_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */
3705 static int __init video_init(struct ibm_init_struct *iibm)
3709 vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n");
3711 TPACPI_ACPIHANDLE_INIT(vid);
3712 TPACPI_ACPIHANDLE_INIT(vid2);
3714 if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
3715 /* G41, assume IVGA doesn't change */
3716 vid_handle = vid2_handle;
3719 /* video switching not supported on R30, R31 */
3720 video_supported = TPACPI_VIDEO_NONE;
3721 else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
3723 video_supported = TPACPI_VIDEO_570;
3724 else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
3725 /* 600e/x, 770e, 770x */
3726 video_supported = TPACPI_VIDEO_770;
3729 video_supported = TPACPI_VIDEO_NEW;
3731 vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n",
3732 str_supported(video_supported != TPACPI_VIDEO_NONE),
3735 return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1;
3738 static void video_exit(void)
3740 dbg_printk(TPACPI_DBG_EXIT,
3741 "restoring original video autoswitch mode\n");
3742 if (video_autosw_set(video_orig_autosw))
3743 printk(TPACPI_ERR "error while trying to restore original "
3744 "video autoswitch mode\n");
3747 static int video_outputsw_get(void)
3752 switch (video_supported) {
3753 case TPACPI_VIDEO_570:
3754 if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd",
3755 TP_ACPI_VIDEO_570_PHSCMD))
3757 status = i & TP_ACPI_VIDEO_570_PHSMASK;
3759 case TPACPI_VIDEO_770:
3760 if (!acpi_evalf(NULL, &i, "\\VCDL", "d"))
3763 status |= TP_ACPI_VIDEO_S_LCD;
3764 if (!acpi_evalf(NULL, &i, "\\VCDC", "d"))
3767 status |= TP_ACPI_VIDEO_S_CRT;
3769 case TPACPI_VIDEO_NEW:
3770 if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) ||
3771 !acpi_evalf(NULL, &i, "\\VCDC", "d"))
3774 status |= TP_ACPI_VIDEO_S_CRT;
3776 if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) ||
3777 !acpi_evalf(NULL, &i, "\\VCDL", "d"))
3780 status |= TP_ACPI_VIDEO_S_LCD;
3781 if (!acpi_evalf(NULL, &i, "\\VCDD", "d"))
3784 status |= TP_ACPI_VIDEO_S_DVI;
3793 static int video_outputsw_set(int status)
3798 switch (video_supported) {
3799 case TPACPI_VIDEO_570:
3800 res = acpi_evalf(NULL, NULL,
3801 "\\_SB.PHS2", "vdd",
3802 TP_ACPI_VIDEO_570_PHS2CMD,
3803 status | TP_ACPI_VIDEO_570_PHS2SET);
3805 case TPACPI_VIDEO_770:
3806 autosw = video_autosw_get();
3810 res = video_autosw_set(1);
3813 res = acpi_evalf(vid_handle, NULL,
3814 "ASWT", "vdd", status * 0x100, 0);
3815 if (!autosw && video_autosw_set(autosw)) {
3817 "video auto-switch left enabled due to error\n");
3821 case TPACPI_VIDEO_NEW:
3822 res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) &&
3823 acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1);
3829 return (res)? 0 : -EIO;
3832 static int video_autosw_get(void)
3836 switch (video_supported) {
3837 case TPACPI_VIDEO_570:
3838 if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d"))
3841 case TPACPI_VIDEO_770:
3842 case TPACPI_VIDEO_NEW:
3843 if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d"))
3853 static int video_autosw_set(int enable)
3855 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0))
3860 static int video_outputsw_cycle(void)
3862 int autosw = video_autosw_get();
3868 switch (video_supported) {
3869 case TPACPI_VIDEO_570:
3870 res = video_autosw_set(1);
3873 res = acpi_evalf(ec_handle, NULL, "_Q16", "v");
3875 case TPACPI_VIDEO_770:
3876 case TPACPI_VIDEO_NEW:
3877 res = video_autosw_set(1);
3880 res = acpi_evalf(vid_handle, NULL, "VSWT", "v");
3885 if (!autosw && video_autosw_set(autosw)) {
3887 "video auto-switch left enabled due to error\n");
3891 return (res)? 0 : -EIO;
3894 static int video_expand_toggle(void)
3896 switch (video_supported) {
3897 case TPACPI_VIDEO_570:
3898 return acpi_evalf(ec_handle, NULL, "_Q17", "v")?
3900 case TPACPI_VIDEO_770:
3901 return acpi_evalf(vid_handle, NULL, "VEXP", "v")?
3903 case TPACPI_VIDEO_NEW:
3904 return acpi_evalf(NULL, NULL, "\\VEXP", "v")?
3912 static int video_read(char *p)
3917 if (video_supported == TPACPI_VIDEO_NONE) {
3918 len += sprintf(p + len, "status:\t\tnot supported\n");
3922 status = video_outputsw_get();
3926 autosw = video_autosw_get();
3930 len += sprintf(p + len, "status:\t\tsupported\n");
3931 len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
3932 len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
3933 if (video_supported == TPACPI_VIDEO_NEW)
3934 len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
3935 len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
3936 len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
3937 len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
3938 if (video_supported == TPACPI_VIDEO_NEW)
3939 len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
3940 len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
3941 len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
3946 static int video_write(char *buf)
3949 int enable, disable, status;
3952 if (video_supported == TPACPI_VIDEO_NONE)
3958 while ((cmd = next_cmd(&buf))) {
3959 if (strlencmp(cmd, "lcd_enable") == 0) {
3960 enable |= TP_ACPI_VIDEO_S_LCD;
3961 } else if (strlencmp(cmd, "lcd_disable") == 0) {
3962 disable |= TP_ACPI_VIDEO_S_LCD;
3963 } else if (strlencmp(cmd, "crt_enable") == 0) {
3964 enable |= TP_ACPI_VIDEO_S_CRT;
3965 } else if (strlencmp(cmd, "crt_disable") == 0) {
3966 disable |= TP_ACPI_VIDEO_S_CRT;
3967 } else if (video_supported == TPACPI_VIDEO_NEW &&
3968 strlencmp(cmd, "dvi_enable") == 0) {
3969 enable |= TP_ACPI_VIDEO_S_DVI;
3970 } else if (video_supported == TPACPI_VIDEO_NEW &&
3971 strlencmp(cmd, "dvi_disable") == 0) {
3972 disable |= TP_ACPI_VIDEO_S_DVI;
3973 } else if (strlencmp(cmd, "auto_enable") == 0) {
3974 res = video_autosw_set(1);
3977 } else if (strlencmp(cmd, "auto_disable") == 0) {
3978 res = video_autosw_set(0);
3981 } else if (strlencmp(cmd, "video_switch") == 0) {
3982 res = video_outputsw_cycle();
3985 } else if (strlencmp(cmd, "expand_toggle") == 0) {
3986 res = video_expand_toggle();
3993 if (enable || disable) {
3994 status = video_outputsw_get();
3997 res = video_outputsw_set((status & ~disable) | enable);
4005 static struct ibm_struct video_driver_data = {
4008 .write = video_write,
4012 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
4014 /*************************************************************************
4015 * Light (thinklight) subdriver
4018 TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
4019 TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */
4021 static int light_get_status(void)
4025 if (tp_features.light_status) {
4026 if (!acpi_evalf(ec_handle, &status, "KBLT", "d"))
4034 static int light_set_status(int status)
4038 if (tp_features.light) {
4040 rc = acpi_evalf(cmos_handle, NULL, NULL, "vd",
4042 TP_CMOS_THINKLIGHT_ON :
4043 TP_CMOS_THINKLIGHT_OFF);
4045 rc = acpi_evalf(lght_handle, NULL, NULL, "vd",
4048 return (rc)? 0 : -EIO;
4054 static void light_set_status_worker(struct work_struct *work)
4056 struct tpacpi_led_classdev *data =
4057 container_of(work, struct tpacpi_led_classdev, work);
4059 if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING))
4060 light_set_status((data->new_brightness != LED_OFF));
4063 static void light_sysfs_set(struct led_classdev *led_cdev,
4064 enum led_brightness brightness)
4066 struct tpacpi_led_classdev *data =
4067 container_of(led_cdev,
4068 struct tpacpi_led_classdev,
4070 data->new_brightness = brightness;
4071 queue_work(tpacpi_wq, &data->work);
4074 static enum led_brightness light_sysfs_get(struct led_classdev *led_cdev)
4076 return (light_get_status() == 1)? LED_FULL : LED_OFF;
4079 static struct tpacpi_led_classdev tpacpi_led_thinklight = {
4081 .name = "tpacpi::thinklight",
4082 .brightness_set = &light_sysfs_set,
4083 .brightness_get = &light_sysfs_get,
4087 static int __init light_init(struct ibm_init_struct *iibm)
4091 vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n");
4093 TPACPI_ACPIHANDLE_INIT(ledb);
4094 TPACPI_ACPIHANDLE_INIT(lght);
4095 TPACPI_ACPIHANDLE_INIT(cmos);
4096 INIT_WORK(&tpacpi_led_thinklight.work, light_set_status_worker);
4098 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
4099 tp_features.light = (cmos_handle || lght_handle) && !ledb_handle;
4101 if (tp_features.light)
4102 /* light status not supported on
4103 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
4104 tp_features.light_status =
4105 acpi_evalf(ec_handle, NULL, "KBLT", "qv");
4107 vdbg_printk(TPACPI_DBG_INIT, "light is %s, light status is %s\n",
4108 str_supported(tp_features.light),
4109 str_supported(tp_features.light_status));
4111 if (!tp_features.light)
4114 rc = led_classdev_register(&tpacpi_pdev->dev,
4115 &tpacpi_led_thinklight.led_classdev);
4118 tp_features.light = 0;
4119 tp_features.light_status = 0;
4127 static void light_exit(void)
4129 led_classdev_unregister(&tpacpi_led_thinklight.led_classdev);
4130 if (work_pending(&tpacpi_led_thinklight.work))
4131 flush_workqueue(tpacpi_wq);
4134 static int light_read(char *p)
4139 if (!tp_features.light) {
4140 len += sprintf(p + len, "status:\t\tnot supported\n");
4141 } else if (!tp_features.light_status) {
4142 len += sprintf(p + len, "status:\t\tunknown\n");
4143 len += sprintf(p + len, "commands:\ton, off\n");
4145 status = light_get_status();
4148 len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0));
4149 len += sprintf(p + len, "commands:\ton, off\n");
4155 static int light_write(char *buf)
4160 if (!tp_features.light)
4163 while ((cmd = next_cmd(&buf))) {
4164 if (strlencmp(cmd, "on") == 0) {
4166 } else if (strlencmp(cmd, "off") == 0) {
4172 return light_set_status(newstatus);
4175 static struct ibm_struct light_driver_data = {
4178 .write = light_write,
4182 /*************************************************************************
4186 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4188 static void dock_notify(struct ibm_struct *ibm, u32 event);
4189 static int dock_read(char *p);
4190 static int dock_write(char *buf);
4192 TPACPI_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
4193 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
4194 "\\_SB.PCI0.PCI1.DOCK", /* all others */
4195 "\\_SB.PCI.ISA.SLCE", /* 570 */
4196 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
4198 /* don't list other alternatives as we install a notify handler on the 570 */
4199 TPACPI_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
4201 static const struct acpi_device_id ibm_pci_device_ids[] = {
4202 {PCI_ROOT_HID_STRING, 0},
4206 static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = {
4208 .notify = dock_notify,
4209 .handle = &dock_handle,
4210 .type = ACPI_SYSTEM_NOTIFY,
4213 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
4214 * We just use it to get notifications of dock hotplug
4215 * in very old thinkpads */
4216 .hid = ibm_pci_device_ids,
4217 .notify = dock_notify,
4218 .handle = &pci_handle,
4219 .type = ACPI_SYSTEM_NOTIFY,
4223 static struct ibm_struct dock_driver_data[2] = {
4227 .write = dock_write,
4228 .acpi = &ibm_dock_acpidriver[0],
4232 .acpi = &ibm_dock_acpidriver[1],
4236 #define dock_docked() (_sta(dock_handle) & 1)
4238 static int __init dock_init(struct ibm_init_struct *iibm)
4240 vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n");
4242 TPACPI_ACPIHANDLE_INIT(dock);
4244 vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n",
4245 str_supported(dock_handle != NULL));
4247 return (dock_handle)? 0 : 1;
4250 static int __init dock_init2(struct ibm_init_struct *iibm)
4254 vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver part 2\n");
4256 if (dock_driver_data[0].flags.acpi_driver_registered &&
4257 dock_driver_data[0].flags.acpi_notify_installed) {
4258 TPACPI_ACPIHANDLE_INIT(pci);
4259 dock2_needed = (pci_handle != NULL);
4260 vdbg_printk(TPACPI_DBG_INIT,
4261 "dock PCI handler for the TP 570 is %s\n",
4262 str_supported(dock2_needed));
4264 vdbg_printk(TPACPI_DBG_INIT,
4265 "dock subdriver part 2 not required\n");
4269 return (dock2_needed)? 0 : 1;
4272 static void dock_notify(struct ibm_struct *ibm, u32 event)
4274 int docked = dock_docked();
4275 int pci = ibm->acpi->hid && ibm->acpi->device &&
4276 acpi_match_device_ids(ibm->acpi->device, ibm_pci_device_ids);
4279 if (event == 1 && !pci) /* 570 */
4280 data = 1; /* button */
4281 else if (event == 1 && pci) /* 570 */
4282 data = 3; /* dock */
4283 else if (event == 3 && docked)
4284 data = 1; /* button */
4285 else if (event == 3 && !docked)
4286 data = 2; /* undock */
4287 else if (event == 0 && docked)
4288 data = 3; /* dock */
4290 printk(TPACPI_ERR "unknown dock event %d, status %d\n",
4291 event, _sta(dock_handle));
4292 data = 0; /* unknown */
4294 acpi_bus_generate_proc_event(ibm->acpi->device, event, data);
4295 acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class,
4296 dev_name(&ibm->acpi->device->dev),
4300 static int dock_read(char *p)
4303 int docked = dock_docked();
4306 len += sprintf(p + len, "status:\t\tnot supported\n");
4308 len += sprintf(p + len, "status:\t\tundocked\n");
4310 len += sprintf(p + len, "status:\t\tdocked\n");
4311 len += sprintf(p + len, "commands:\tdock, undock\n");
4317 static int dock_write(char *buf)
4324 while ((cmd = next_cmd(&buf))) {
4325 if (strlencmp(cmd, "undock") == 0) {
4326 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) ||
4327 !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1))
4329 } else if (strlencmp(cmd, "dock") == 0) {
4330 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1))
4339 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
4341 /*************************************************************************
4345 #ifdef CONFIG_THINKPAD_ACPI_BAY
4347 TPACPI_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
4348 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
4349 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
4350 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
4351 ); /* A21e, R30, R31 */
4352 TPACPI_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */
4353 "_EJ0", /* all others */
4354 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
4355 TPACPI_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
4356 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
4358 TPACPI_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */
4362 static int __init bay_init(struct ibm_init_struct *iibm)
4364 vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n");
4366 TPACPI_ACPIHANDLE_INIT(bay);
4368 TPACPI_ACPIHANDLE_INIT(bay_ej);
4369 TPACPI_ACPIHANDLE_INIT(bay2);
4371 TPACPI_ACPIHANDLE_INIT(bay2_ej);
4373 tp_features.bay_status = bay_handle &&
4374 acpi_evalf(bay_handle, NULL, "_STA", "qv");
4375 tp_features.bay_status2 = bay2_handle &&
4376 acpi_evalf(bay2_handle, NULL, "_STA", "qv");
4378 tp_features.bay_eject = bay_handle && bay_ej_handle &&
4379 (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental);
4380 tp_features.bay_eject2 = bay2_handle && bay2_ej_handle &&
4381 (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
4383 vdbg_printk(TPACPI_DBG_INIT,
4384 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
4385 str_supported(tp_features.bay_status),
4386 str_supported(tp_features.bay_eject),
4387 str_supported(tp_features.bay_status2),
4388 str_supported(tp_features.bay_eject2));
4390 return (tp_features.bay_status || tp_features.bay_eject ||
4391 tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1;
4394 static void bay_notify(struct ibm_struct *ibm, u32 event)
4396 acpi_bus_generate_proc_event(ibm->acpi->device, event, 0);
4397 acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class,
4398 dev_name(&ibm->acpi->device->dev),
4402 #define bay_occupied(b) (_sta(b##_handle) & 1)
4404 static int bay_read(char *p)
4407 int occupied = bay_occupied(bay);
4408 int occupied2 = bay_occupied(bay2);
4411 len += sprintf(p + len, "status:\t\t%s\n",
4412 tp_features.bay_status ?
4413 (occupied ? "occupied" : "unoccupied") :
4415 if (tp_features.bay_status2)
4416 len += sprintf(p + len, "status2:\t%s\n", occupied2 ?
4417 "occupied" : "unoccupied");
4419 eject = tp_features.bay_eject && occupied;
4420 eject2 = tp_features.bay_eject2 && occupied2;
4422 if (eject && eject2)
4423 len += sprintf(p + len, "commands:\teject, eject2\n");
4425 len += sprintf(p + len, "commands:\teject\n");
4427 len += sprintf(p + len, "commands:\teject2\n");
4432 static int bay_write(char *buf)
4436 if (!tp_features.bay_eject && !tp_features.bay_eject2)
4439 while ((cmd = next_cmd(&buf))) {
4440 if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) {
4441 if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1))
4443 } else if (tp_features.bay_eject2 &&
4444 strlencmp(cmd, "eject2") == 0) {
4445 if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1))
4454 static struct tp_acpi_drv_struct ibm_bay_acpidriver = {
4455 .notify = bay_notify,
4456 .handle = &bay_handle,
4457 .type = ACPI_SYSTEM_NOTIFY,
4460 static struct ibm_struct bay_driver_data = {
4464 .acpi = &ibm_bay_acpidriver,
4467 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4469 /*************************************************************************
4473 /* sysfs cmos_command -------------------------------------------------- */
4474 static ssize_t cmos_command_store(struct device *dev,
4475 struct device_attribute *attr,
4476 const char *buf, size_t count)
4478 unsigned long cmos_cmd;
4481 if (parse_strtoul(buf, 21, &cmos_cmd))
4484 res = issue_thinkpad_cmos_command(cmos_cmd);
4485 return (res)? res : count;
4488 static struct device_attribute dev_attr_cmos_command =
4489 __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store);
4491 /* --------------------------------------------------------------------- */
4493 static int __init cmos_init(struct ibm_init_struct *iibm)
4497 vdbg_printk(TPACPI_DBG_INIT,
4498 "initializing cmos commands subdriver\n");
4500 TPACPI_ACPIHANDLE_INIT(cmos);
4502 vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n",
4503 str_supported(cmos_handle != NULL));
4505 res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command);
4509 return (cmos_handle)? 0 : 1;
4512 static void cmos_exit(void)
4514 device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command);
4517 static int cmos_read(char *p)
4521 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4522 R30, R31, T20-22, X20-21 */
4524 len += sprintf(p + len, "status:\t\tnot supported\n");
4526 len += sprintf(p + len, "status:\t\tsupported\n");
4527 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n");
4533 static int cmos_write(char *buf)
4538 while ((cmd = next_cmd(&buf))) {
4539 if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
4540 cmos_cmd >= 0 && cmos_cmd <= 21) {
4545 res = issue_thinkpad_cmos_command(cmos_cmd);
4553 static struct ibm_struct cmos_driver_data = {
4556 .write = cmos_write,
4560 /*************************************************************************
4564 enum led_access_mode {
4565 TPACPI_LED_NONE = 0,
4566 TPACPI_LED_570, /* 570 */
4567 TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4568 TPACPI_LED_NEW, /* all others */
4571 enum { /* For TPACPI_LED_OLD */
4572 TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */
4573 TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */
4574 TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */
4583 static enum led_access_mode led_supported;
4585 TPACPI_HANDLE(led, ec, "SLED", /* 570 */
4586 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4587 /* T20-22, X20-21 */
4588 "LED", /* all others */
4591 #define TPACPI_LED_NUMLEDS 8
4592 static struct tpacpi_led_classdev *tpacpi_leds;
4593 static enum led_status_t tpacpi_led_state_cache[TPACPI_LED_NUMLEDS];
4594 static const char * const tpacpi_led_names[TPACPI_LED_NUMLEDS] = {
4595 /* there's a limit of 19 chars + NULL before 2.6.26 */
4597 "tpacpi:orange:batt",
4598 "tpacpi:green:batt",
4599 "tpacpi::dock_active",
4600 "tpacpi::bay_active",
4601 "tpacpi::dock_batt",
4602 "tpacpi::unknown_led",
4606 static int led_get_status(const unsigned int led)
4609 enum led_status_t led_s;
4611 switch (led_supported) {
4612 case TPACPI_LED_570:
4613 if (!acpi_evalf(ec_handle,
4614 &status, "GLED", "dd", 1 << led))
4616 led_s = (status == 0)?
4621 tpacpi_led_state_cache[led] = led_s;
4630 static int led_set_status(const unsigned int led,
4631 const enum led_status_t ledstatus)
4633 /* off, on, blink. Index is led_status_t */
4634 static const unsigned int led_sled_arg1[] = { 0, 1, 3 };
4635 static const unsigned int led_led_arg1[] = { 0, 0x80, 0xc0 };
4639 switch (led_supported) {
4640 case TPACPI_LED_570:
4644 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
4645 (1 << led), led_sled_arg1[ledstatus]))
4648 case TPACPI_LED_OLD:
4649 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
4652 rc = ec_write(TPACPI_LED_EC_HLMS, (1 << led));
4654 rc = ec_write(TPACPI_LED_EC_HLBL,
4655 (ledstatus == TPACPI_LED_BLINK) << led);
4657 rc = ec_write(TPACPI_LED_EC_HLCL,
4658 (ledstatus != TPACPI_LED_OFF) << led);
4660 case TPACPI_LED_NEW:
4662 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
4663 led, led_led_arg1[ledstatus]))
4671 tpacpi_led_state_cache[led] = ledstatus;
4676 static void led_sysfs_set_status(unsigned int led,
4677 enum led_brightness brightness)
4680 (brightness == LED_OFF) ?
4682 (tpacpi_led_state_cache[led] == TPACPI_LED_BLINK) ?
4683 TPACPI_LED_BLINK : TPACPI_LED_ON);
4686 static void led_set_status_worker(struct work_struct *work)
4688 struct tpacpi_led_classdev *data =
4689 container_of(work, struct tpacpi_led_classdev, work);
4691 if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING))
4692 led_sysfs_set_status(data->led, data->new_brightness);
4695 static void led_sysfs_set(struct led_classdev *led_cdev,
4696 enum led_brightness brightness)
4698 struct tpacpi_led_classdev *data = container_of(led_cdev,
4699 struct tpacpi_led_classdev, led_classdev);
4701 data->new_brightness = brightness;
4702 queue_work(tpacpi_wq, &data->work);
4705 static int led_sysfs_blink_set(struct led_classdev *led_cdev,
4706 unsigned long *delay_on, unsigned long *delay_off)
4708 struct tpacpi_led_classdev *data = container_of(led_cdev,
4709 struct tpacpi_led_classdev, led_classdev);
4711 /* Can we choose the flash rate? */
4712 if (*delay_on == 0 && *delay_off == 0) {
4713 /* yes. set them to the hardware blink rate (1 Hz) */
4714 *delay_on = 500; /* ms */
4715 *delay_off = 500; /* ms */
4716 } else if ((*delay_on != 500) || (*delay_off != 500))
4719 data->new_brightness = TPACPI_LED_BLINK;
4720 queue_work(tpacpi_wq, &data->work);
4725 static enum led_brightness led_sysfs_get(struct led_classdev *led_cdev)
4729 struct tpacpi_led_classdev *data = container_of(led_cdev,
4730 struct tpacpi_led_classdev, led_classdev);
4732 rc = led_get_status(data->led);
4734 if (rc == TPACPI_LED_OFF || rc < 0)
4735 rc = LED_OFF; /* no error handling in led class :( */
4742 static void led_exit(void)
4746 for (i = 0; i < TPACPI_LED_NUMLEDS; i++) {
4747 if (tpacpi_leds[i].led_classdev.name)
4748 led_classdev_unregister(&tpacpi_leds[i].led_classdev);
4754 static int __init led_init(struct ibm_init_struct *iibm)
4759 vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n");
4761 TPACPI_ACPIHANDLE_INIT(led);
4764 /* led not supported on R30, R31 */
4765 led_supported = TPACPI_LED_NONE;
4766 else if (strlencmp(led_path, "SLED") == 0)
4768 led_supported = TPACPI_LED_570;
4769 else if (strlencmp(led_path, "SYSL") == 0)
4770 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4771 led_supported = TPACPI_LED_OLD;
4774 led_supported = TPACPI_LED_NEW;
4776 vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n",
4777 str_supported(led_supported), led_supported);
4779 tpacpi_leds = kzalloc(sizeof(*tpacpi_leds) * TPACPI_LED_NUMLEDS,
4782 printk(TPACPI_ERR "Out of memory for LED data\n");
4786 for (i = 0; i < TPACPI_LED_NUMLEDS; i++) {
4787 tpacpi_leds[i].led = i;
4789 tpacpi_leds[i].led_classdev.brightness_set = &led_sysfs_set;
4790 tpacpi_leds[i].led_classdev.blink_set = &led_sysfs_blink_set;
4791 if (led_supported == TPACPI_LED_570)
4792 tpacpi_leds[i].led_classdev.brightness_get =
4795 tpacpi_leds[i].led_classdev.name = tpacpi_led_names[i];
4797 INIT_WORK(&tpacpi_leds[i].work, led_set_status_worker);
4799 rc = led_classdev_register(&tpacpi_pdev->dev,
4800 &tpacpi_leds[i].led_classdev);
4802 tpacpi_leds[i].led_classdev.name = NULL;
4808 return (led_supported != TPACPI_LED_NONE)? 0 : 1;
4811 #define str_led_status(s) \
4812 ((s) == TPACPI_LED_OFF ? "off" : \
4813 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
4815 static int led_read(char *p)
4819 if (!led_supported) {
4820 len += sprintf(p + len, "status:\t\tnot supported\n");
4823 len += sprintf(p + len, "status:\t\tsupported\n");
4825 if (led_supported == TPACPI_LED_570) {
4828 for (i = 0; i < 8; i++) {
4829 status = led_get_status(i);
4832 len += sprintf(p + len, "%d:\t\t%s\n",
4833 i, str_led_status(status));
4837 len += sprintf(p + len, "commands:\t"
4838 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
4843 static int led_write(char *buf)
4847 enum led_status_t s;
4852 while ((cmd = next_cmd(&buf))) {
4853 if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7)
4856 if (strstr(cmd, "off")) {
4858 } else if (strstr(cmd, "on")) {
4860 } else if (strstr(cmd, "blink")) {
4861 s = TPACPI_LED_BLINK;
4866 rc = led_set_status(led, s);
4874 static struct ibm_struct led_driver_data = {
4881 /*************************************************************************
4885 TPACPI_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */
4887 static int __init beep_init(struct ibm_init_struct *iibm)
4889 vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n");
4891 TPACPI_ACPIHANDLE_INIT(beep);
4893 vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n",
4894 str_supported(beep_handle != NULL));
4896 return (beep_handle)? 0 : 1;
4899 static int beep_read(char *p)
4904 len += sprintf(p + len, "status:\t\tnot supported\n");
4906 len += sprintf(p + len, "status:\t\tsupported\n");
4907 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n");
4913 static int beep_write(char *buf)
4921 while ((cmd = next_cmd(&buf))) {
4922 if (sscanf(cmd, "%u", &beep_cmd) == 1 &&
4923 beep_cmd >= 0 && beep_cmd <= 17) {
4927 if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0))
4934 static struct ibm_struct beep_driver_data = {
4937 .write = beep_write,
4940 /*************************************************************************
4944 enum thermal_access_mode {
4945 TPACPI_THERMAL_NONE = 0, /* No thermal support */
4946 TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
4947 TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
4948 TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */
4949 TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
4952 enum { /* TPACPI_THERMAL_TPEC_* */
4953 TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */
4954 TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */
4955 TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */
4958 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
4959 struct ibm_thermal_sensors_struct {
4960 s32 temp[TPACPI_MAX_THERMAL_SENSORS];
4963 static enum thermal_access_mode thermal_read_mode;
4965 /* idx is zero-based */
4966 static int thermal_get_sensor(int idx, s32 *value)
4972 t = TP_EC_THERMAL_TMP0;
4974 switch (thermal_read_mode) {
4975 #if TPACPI_MAX_THERMAL_SENSORS >= 16
4976 case TPACPI_THERMAL_TPEC_16:
4977 if (idx >= 8 && idx <= 15) {
4978 t = TP_EC_THERMAL_TMP8;
4983 case TPACPI_THERMAL_TPEC_8:
4985 if (!acpi_ec_read(t + idx, &tmp))
4987 *value = tmp * 1000;
4992 case TPACPI_THERMAL_ACPI_UPDT:
4994 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
4995 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
4997 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
4999 *value = (t - 2732) * 100;
5004 case TPACPI_THERMAL_ACPI_TMP07:
5006 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
5007 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
5009 if (t > 127 || t < -127)
5010 t = TP_EC_THERMAL_TMP_NA;
5016 case TPACPI_THERMAL_NONE:
5024 static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
5035 if (thermal_read_mode == TPACPI_THERMAL_TPEC_16)
5038 for (i = 0 ; i < n; i++) {
5039 res = thermal_get_sensor(i, &s->temp[i]);
5047 /* sysfs temp##_input -------------------------------------------------- */
5049 static ssize_t thermal_temp_input_show(struct device *dev,
5050 struct device_attribute *attr,
5053 struct sensor_device_attribute *sensor_attr =
5054 to_sensor_dev_attr(attr);
5055 int idx = sensor_attr->index;
5059 res = thermal_get_sensor(idx, &value);
5062 if (value == TP_EC_THERMAL_TMP_NA * 1000)
5065 return snprintf(buf, PAGE_SIZE, "%d\n", value);
5068 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
5069 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
5070 thermal_temp_input_show, NULL, _idxB)
5072 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = {
5073 THERMAL_SENSOR_ATTR_TEMP(1, 0),
5074 THERMAL_SENSOR_ATTR_TEMP(2, 1),
5075 THERMAL_SENSOR_ATTR_TEMP(3, 2),
5076 THERMAL_SENSOR_ATTR_TEMP(4, 3),
5077 THERMAL_SENSOR_ATTR_TEMP(5, 4),
5078 THERMAL_SENSOR_ATTR_TEMP(6, 5),
5079 THERMAL_SENSOR_ATTR_TEMP(7, 6),
5080 THERMAL_SENSOR_ATTR_TEMP(8, 7),
5081 THERMAL_SENSOR_ATTR_TEMP(9, 8),
5082 THERMAL_SENSOR_ATTR_TEMP(10, 9),
5083 THERMAL_SENSOR_ATTR_TEMP(11, 10),
5084 THERMAL_SENSOR_ATTR_TEMP(12, 11),
5085 THERMAL_SENSOR_ATTR_TEMP(13, 12),
5086 THERMAL_SENSOR_ATTR_TEMP(14, 13),
5087 THERMAL_SENSOR_ATTR_TEMP(15, 14),
5088 THERMAL_SENSOR_ATTR_TEMP(16, 15),
5091 #define THERMAL_ATTRS(X) \
5092 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
5094 static struct attribute *thermal_temp_input_attr[] = {
5114 static const struct attribute_group thermal_temp_input16_group = {
5115 .attrs = thermal_temp_input_attr
5118 static const struct attribute_group thermal_temp_input8_group = {
5119 .attrs = &thermal_temp_input_attr[8]
5122 #undef THERMAL_SENSOR_ATTR_TEMP
5123 #undef THERMAL_ATTRS
5125 /* --------------------------------------------------------------------- */
5127 static int __init thermal_init(struct ibm_init_struct *iibm)
5134 vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n");
5136 acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
5138 if (thinkpad_id.ec_model) {
5140 * Direct EC access mode: sensors at registers
5141 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
5142 * non-implemented, thermal sensors return 0x80 when
5147 for (i = 0; i < 8; i++) {
5148 if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) {
5154 if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) {
5162 /* This is sheer paranoia, but we handle it anyway */
5165 "ThinkPad ACPI EC access misbehaving, "
5166 "falling back to ACPI TMPx access "
5168 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
5171 "ThinkPad ACPI EC access misbehaving, "
5172 "disabling thermal sensors access\n");
5173 thermal_read_mode = TPACPI_THERMAL_NONE;
5178 TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8;
5180 } else if (acpi_tmp7) {
5181 if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
5182 /* 600e/x, 770e, 770x */
5183 thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT;
5185 /* Standard ACPI TMPx access, max 8 sensors */
5186 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
5189 /* temperatures not supported on 570, G4x, R30, R31, R32 */
5190 thermal_read_mode = TPACPI_THERMAL_NONE;
5193 vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n",
5194 str_supported(thermal_read_mode != TPACPI_THERMAL_NONE),
5197 switch (thermal_read_mode) {
5198 case TPACPI_THERMAL_TPEC_16:
5199 res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj,
5200 &thermal_temp_input16_group);
5204 case TPACPI_THERMAL_TPEC_8:
5205 case TPACPI_THERMAL_ACPI_TMP07:
5206 case TPACPI_THERMAL_ACPI_UPDT:
5207 res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj,
5208 &thermal_temp_input8_group);
5212 case TPACPI_THERMAL_NONE:
5220 static void thermal_exit(void)
5222 switch (thermal_read_mode) {
5223 case TPACPI_THERMAL_TPEC_16:
5224 sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj,
5225 &thermal_temp_input16_group);
5227 case TPACPI_THERMAL_TPEC_8:
5228 case TPACPI_THERMAL_ACPI_TMP07:
5229 case TPACPI_THERMAL_ACPI_UPDT:
5230 sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj,
5231 &thermal_temp_input16_group);
5233 case TPACPI_THERMAL_NONE:
5239 static int thermal_read(char *p)
5243 struct ibm_thermal_sensors_struct t;
5245 n = thermal_get_sensors(&t);
5246 if (unlikely(n < 0))
5249 len += sprintf(p + len, "temperatures:\t");
5252 for (i = 0; i < (n - 1); i++)
5253 len += sprintf(p + len, "%d ", t.temp[i] / 1000);
5254 len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
5256 len += sprintf(p + len, "not supported\n");
5261 static struct ibm_struct thermal_driver_data = {
5263 .read = thermal_read,
5264 .exit = thermal_exit,
5267 /*************************************************************************
5271 static u8 ecdump_regs[256];
5273 static int ecdump_read(char *p)
5279 len += sprintf(p + len, "EC "
5280 " +00 +01 +02 +03 +04 +05 +06 +07"
5281 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
5282 for (i = 0; i < 256; i += 16) {
5283 len += sprintf(p + len, "EC 0x%02x:", i);
5284 for (j = 0; j < 16; j++) {
5285 if (!acpi_ec_read(i + j, &v))
5287 if (v != ecdump_regs[i + j])
5288 len += sprintf(p + len, " *%02x", v);
5290 len += sprintf(p + len, " %02x", v);
5291 ecdump_regs[i + j] = v;
5293 len += sprintf(p + len, "\n");
5298 /* These are way too dangerous to advertise openly... */
5300 len += sprintf(p + len, "commands:\t0x<offset> 0x<value>"
5301 " (<offset> is 00-ff, <value> is 00-ff)\n");
5302 len += sprintf(p + len, "commands:\t0x<offset> <value> "
5303 " (<offset> is 00-ff, <value> is 0-255)\n");
5308 static int ecdump_write(char *buf)
5313 while ((cmd = next_cmd(&buf))) {
5314 if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) {
5316 } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) {
5320 if (i >= 0 && i < 256 && v >= 0 && v < 256) {
5321 if (!acpi_ec_write(i, v))
5330 static struct ibm_struct ecdump_driver_data = {
5332 .read = ecdump_read,
5333 .write = ecdump_write,
5334 .flags.experimental = 1,
5337 /*************************************************************************
5338 * Backlight/brightness subdriver
5341 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
5344 TP_EC_BACKLIGHT = 0x31,
5346 /* TP_EC_BACKLIGHT bitmasks */
5347 TP_EC_BACKLIGHT_LVLMSK = 0x1F,
5348 TP_EC_BACKLIGHT_CMDMSK = 0xE0,
5349 TP_EC_BACKLIGHT_MAPSW = 0x20,
5352 static struct backlight_device *ibm_backlight_device;
5353 static int brightness_mode;
5354 static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */
5356 static struct mutex brightness_mutex;
5359 * ThinkPads can read brightness from two places: EC 0x31, or
5360 * CMOS NVRAM byte 0x5E, bits 0-3.
5362 * EC 0x31 has the following layout
5363 * Bit 7: unknown function
5364 * Bit 6: unknown function
5365 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
5366 * Bit 4: must be set to zero to avoid problems
5367 * Bit 3-0: backlight brightness level
5369 * brightness_get_raw returns status data in the EC 0x31 layout
5371 static int brightness_get_raw(int *status)
5373 u8 lec = 0, lcmos = 0, level = 0;
5375 if (brightness_mode & 1) {
5376 if (!acpi_ec_read(TP_EC_BACKLIGHT, &lec))
5378 level = lec & TP_EC_BACKLIGHT_LVLMSK;
5380 if (brightness_mode & 2) {
5381 lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS)
5382 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS)
5383 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS;
5384 lcmos &= (tp_features.bright_16levels)? 0x0f : 0x07;
5388 if (brightness_mode == 3) {
5389 *status = lec; /* Prefer EC, CMOS is just a backing store */
5390 lec &= TP_EC_BACKLIGHT_LVLMSK;
5392 tp_warned.bright_cmos_ec_unsync = 0;
5394 if (!tp_warned.bright_cmos_ec_unsync) {
5396 "CMOS NVRAM (%u) and EC (%u) do not "
5397 "agree on display brightness level\n",
5398 (unsigned int) lcmos,
5399 (unsigned int) lec);
5400 tp_warned.bright_cmos_ec_unsync = 1;
5411 /* May return EINTR which can always be mapped to ERESTARTSYS */
5412 static int brightness_set(int value)
5414 int cmos_cmd, inc, i, res;
5418 if (value > ((tp_features.bright_16levels)? 15 : 7) ||
5422 res = mutex_lock_killable(&brightness_mutex);
5426 res = brightness_get_raw(¤t_value);
5430 command_bits = current_value & TP_EC_BACKLIGHT_CMDMSK;
5431 current_value &= TP_EC_BACKLIGHT_LVLMSK;
5433 cmos_cmd = value > current_value ?
5434 TP_CMOS_BRIGHTNESS_UP :
5435 TP_CMOS_BRIGHTNESS_DOWN;
5436 inc = (value > current_value)? 1 : -1;
5439 for (i = current_value; i != value; i += inc) {
5440 if ((brightness_mode & 2) &&
5441 issue_thinkpad_cmos_command(cmos_cmd)) {
5445 if ((brightness_mode & 1) &&
5446 !acpi_ec_write(TP_EC_BACKLIGHT,
5447 (i + inc) | command_bits)) {
5454 mutex_unlock(&brightness_mutex);
5458 /* sysfs backlight class ----------------------------------------------- */
5460 static int brightness_update_status(struct backlight_device *bd)
5462 /* it is the backlight class's job (caller) to handle
5463 * EINTR and other errors properly */
5464 return brightness_set(
5465 (bd->props.fb_blank == FB_BLANK_UNBLANK &&
5466 bd->props.power == FB_BLANK_UNBLANK) ?
5467 bd->props.brightness : 0);
5470 static int brightness_get(struct backlight_device *bd)
5474 res = brightness_get_raw(&status);
5476 return 0; /* FIXME: teach backlight about error handling */
5478 return status & TP_EC_BACKLIGHT_LVLMSK;
5481 static struct backlight_ops ibm_backlight_data = {
5482 .get_brightness = brightness_get,
5483 .update_status = brightness_update_status,
5486 /* --------------------------------------------------------------------- */
5488 static int __init brightness_init(struct ibm_init_struct *iibm)
5492 vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n");
5494 mutex_init(&brightness_mutex);
5497 * We always attempt to detect acpi support, so as to switch
5498 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
5499 * going to publish a backlight interface
5501 b = tpacpi_check_std_acpi_brightness_support();
5504 if (acpi_video_backlight_support()) {
5505 if (brightness_enable > 1) {
5506 printk(TPACPI_NOTICE
5507 "Standard ACPI backlight interface "
5508 "available, not loading native one.\n");
5510 } else if (brightness_enable == 1) {
5511 printk(TPACPI_NOTICE
5512 "Backlight control force enabled, even if standard "
5513 "ACPI backlight interface is available\n");
5516 if (brightness_enable > 1) {
5517 printk(TPACPI_NOTICE
5518 "Standard ACPI backlight interface not "
5519 "available, thinkpad_acpi native "
5520 "brightness control enabled\n");
5525 if (!brightness_enable) {
5526 dbg_printk(TPACPI_DBG_INIT,
5527 "brightness support disabled by "
5528 "module parameter\n");
5534 "Unsupported brightness interface, "
5535 "please contact %s\n", TPACPI_MAIL);
5539 tp_features.bright_16levels = 1;
5541 if (!brightness_mode) {
5542 if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO)
5543 brightness_mode = 2;
5545 brightness_mode = 3;
5547 dbg_printk(TPACPI_DBG_INIT, "selected brightness_mode=%d\n",
5551 if (brightness_mode > 3)
5554 if (brightness_get_raw(&b) < 0)
5557 if (tp_features.bright_16levels)
5559 "detected a 16-level brightness capable ThinkPad\n");
5561 ibm_backlight_device = backlight_device_register(
5562 TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL,
5563 &ibm_backlight_data);
5564 if (IS_ERR(ibm_backlight_device)) {
5565 printk(TPACPI_ERR "Could not register backlight device\n");
5566 return PTR_ERR(ibm_backlight_device);
5568 vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n");
5570 ibm_backlight_device->props.max_brightness =
5571 (tp_features.bright_16levels)? 15 : 7;
5572 ibm_backlight_device->props.brightness = b & TP_EC_BACKLIGHT_LVLMSK;
5573 backlight_update_status(ibm_backlight_device);
5578 static void brightness_exit(void)
5580 if (ibm_backlight_device) {
5581 vdbg_printk(TPACPI_DBG_EXIT,
5582 "calling backlight_device_unregister()\n");
5583 backlight_device_unregister(ibm_backlight_device);
5587 static int brightness_read(char *p)
5592 level = brightness_get(NULL);
5594 len += sprintf(p + len, "level:\t\tunreadable\n");
5596 len += sprintf(p + len, "level:\t\t%d\n", level);
5597 len += sprintf(p + len, "commands:\tup, down\n");
5598 len += sprintf(p + len, "commands:\tlevel <level>"
5599 " (<level> is 0-%d)\n",
5600 (tp_features.bright_16levels) ? 15 : 7);
5606 static int brightness_write(char *buf)
5611 int max_level = (tp_features.bright_16levels) ? 15 : 7;
5613 level = brightness_get(NULL);
5617 while ((cmd = next_cmd(&buf))) {
5618 if (strlencmp(cmd, "up") == 0) {
5619 if (level < max_level)
5621 } else if (strlencmp(cmd, "down") == 0) {
5624 } else if (sscanf(cmd, "level %d", &level) == 1 &&
5625 level >= 0 && level <= max_level) {
5632 * Now we know what the final level should be, so we try to set it.
5633 * Doing it this way makes the syscall restartable in case of EINTR
5635 rc = brightness_set(level);
5636 return (rc == -EINTR)? ERESTARTSYS : rc;
5639 static struct ibm_struct brightness_driver_data = {
5640 .name = "brightness",
5641 .read = brightness_read,
5642 .write = brightness_write,
5643 .exit = brightness_exit,
5646 /*************************************************************************
5650 static int volume_offset = 0x30;
5652 static int volume_read(char *p)
5657 if (!acpi_ec_read(volume_offset, &level)) {
5658 len += sprintf(p + len, "level:\t\tunreadable\n");
5660 len += sprintf(p + len, "level:\t\t%d\n", level & 0xf);
5661 len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6));
5662 len += sprintf(p + len, "commands:\tup, down, mute\n");
5663 len += sprintf(p + len, "commands:\tlevel <level>"
5664 " (<level> is 0-15)\n");
5670 static int volume_write(char *buf)
5672 int cmos_cmd, inc, i;
5674 int new_level, new_mute;
5677 while ((cmd = next_cmd(&buf))) {
5678 if (!acpi_ec_read(volume_offset, &level))
5680 new_mute = mute = level & 0x40;
5681 new_level = level = level & 0xf;
5683 if (strlencmp(cmd, "up") == 0) {
5687 new_level = level == 15 ? 15 : level + 1;
5688 } else if (strlencmp(cmd, "down") == 0) {
5692 new_level = level == 0 ? 0 : level - 1;
5693 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
5694 new_level >= 0 && new_level <= 15) {
5696 } else if (strlencmp(cmd, "mute") == 0) {
5701 if (new_level != level) {
5702 /* mute doesn't change */
5704 cmos_cmd = (new_level > level) ?
5705 TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN;
5706 inc = new_level > level ? 1 : -1;
5708 if (mute && (issue_thinkpad_cmos_command(cmos_cmd) ||
5709 !acpi_ec_write(volume_offset, level)))
5712 for (i = level; i != new_level; i += inc)
5713 if (issue_thinkpad_cmos_command(cmos_cmd) ||
5714 !acpi_ec_write(volume_offset, i + inc))
5718 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) ||
5719 !acpi_ec_write(volume_offset, new_level + mute))) {
5724 if (new_mute != mute) {
5725 /* level doesn't change */
5727 cmos_cmd = (new_mute) ?
5728 TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP;
5730 if (issue_thinkpad_cmos_command(cmos_cmd) ||
5731 !acpi_ec_write(volume_offset, level + new_mute))
5739 static struct ibm_struct volume_driver_data = {
5741 .read = volume_read,
5742 .write = volume_write,
5745 /*************************************************************************
5752 * TPACPI_FAN_RD_ACPI_GFAN:
5753 * ACPI GFAN method: returns fan level
5755 * see TPACPI_FAN_WR_ACPI_SFAN
5756 * EC 0x2f (HFSP) not available if GFAN exists
5758 * TPACPI_FAN_WR_ACPI_SFAN:
5759 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
5761 * EC 0x2f (HFSP) might be available *for reading*, but do not use
5764 * TPACPI_FAN_WR_TPEC:
5765 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
5766 * Supported on almost all ThinkPads
5768 * Fan speed changes of any sort (including those caused by the
5769 * disengaged mode) are usually done slowly by the firmware as the
5770 * maximum ammount of fan duty cycle change per second seems to be
5773 * Reading is not available if GFAN exists.
5774 * Writing is not available if SFAN exists.
5777 * 7 automatic mode engaged;
5778 * (default operation mode of the ThinkPad)
5779 * fan level is ignored in this mode.
5780 * 6 full speed mode (takes precedence over bit 7);
5781 * not available on all thinkpads. May disable
5782 * the tachometer while the fan controller ramps up
5783 * the speed (which can take up to a few *minutes*).
5784 * Speeds up fan to 100% duty-cycle, which is far above
5785 * the standard RPM levels. It is not impossible that
5786 * it could cause hardware damage.
5787 * 5-3 unused in some models. Extra bits for fan level
5788 * in others, but still useless as all values above
5789 * 7 map to the same speed as level 7 in these models.
5790 * 2-0 fan level (0..7 usually)
5792 * 0x07 = max (set when temperatures critical)
5793 * Some ThinkPads may have other levels, see
5794 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
5796 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
5797 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
5798 * does so, its initial value is meaningless (0x07).
5800 * For firmware bugs, refer to:
5801 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5805 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
5806 * Main fan tachometer reading (in RPM)
5808 * This register is present on all ThinkPads with a new-style EC, and
5809 * it is known not to be present on the A21m/e, and T22, as there is
5810 * something else in offset 0x84 according to the ACPI DSDT. Other
5811 * ThinkPads from this same time period (and earlier) probably lack the
5812 * tachometer as well.
5814 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
5815 * was never fixed by IBM to report the EC firmware version string
5816 * probably support the tachometer (like the early X models), so
5817 * detecting it is quite hard. We need more data to know for sure.
5819 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
5822 * FIRMWARE BUG: may go stale while the EC is switching to full speed
5825 * For firmware bugs, refer to:
5826 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5828 * TPACPI_FAN_WR_ACPI_FANS:
5829 * ThinkPad X31, X40, X41. Not available in the X60.
5831 * FANS ACPI handle: takes three arguments: low speed, medium speed,
5832 * high speed. ACPI DSDT seems to map these three speeds to levels
5833 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
5834 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
5836 * The speeds are stored on handles
5837 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
5839 * There are three default speed sets, acessible as handles:
5840 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
5842 * ACPI DSDT switches which set is in use depending on various
5845 * TPACPI_FAN_WR_TPEC is also available and should be used to
5846 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
5847 * but the ACPI tables just mention level 7.
5850 enum { /* Fan control constants */
5851 fan_status_offset = 0x2f, /* EC register 0x2f */
5852 fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
5853 * 0x84 must be read before 0x85 */
5855 TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */
5856 TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */
5858 TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */
5861 enum fan_status_access_mode {
5862 TPACPI_FAN_NONE = 0, /* No fan status or control */
5863 TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */
5864 TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
5867 enum fan_control_access_mode {
5868 TPACPI_FAN_WR_NONE = 0, /* No fan control */
5869 TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */
5870 TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */
5871 TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */
5874 enum fan_control_commands {
5875 TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */
5876 TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */
5877 TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd,
5878 * and also watchdog cmd */
5881 static int fan_control_allowed;
5883 static enum fan_status_access_mode fan_status_access_mode;
5884 static enum fan_control_access_mode fan_control_access_mode;
5885 static enum fan_control_commands fan_control_commands;
5887 static u8 fan_control_initial_status;
5888 static u8 fan_control_desired_level;
5889 static u8 fan_control_resume_level;
5890 static int fan_watchdog_maxinterval;
5892 static struct mutex fan_mutex;
5894 static void fan_watchdog_fire(struct work_struct *ignored);
5895 static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire);
5897 TPACPI_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */
5898 TPACPI_HANDLE(gfan, ec, "GFAN", /* 570 */
5899 "\\FSPD", /* 600e/x, 770e, 770x */
5901 TPACPI_HANDLE(sfan, ec, "SFAN", /* 570 */
5902 "JFNS", /* 770x-JL */
5906 * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
5907 * HFSP register at boot, so it contains 0x07 but the Thinkpad could
5908 * be in auto mode (0x80).
5910 * This is corrected by any write to HFSP either by the driver, or
5913 * We assume 0x07 really means auto mode while this quirk is active,
5914 * as this is far more likely than the ThinkPad being in level 7,
5915 * which is only used by the firmware during thermal emergencies.
5918 static void fan_quirk1_detect(void)
5920 /* In some ThinkPads, neither the EC nor the ACPI
5921 * DSDT initialize the HFSP register, and it ends up
5922 * being initially set to 0x07 when it *could* be
5923 * either 0x07 or 0x80.
5925 * Enable for TP-1Y (T43), TP-78 (R51e),
5926 * TP-76 (R52), TP-70 (T43, R52), which are known
5928 if (fan_control_initial_status == 0x07) {
5929 switch (thinkpad_id.ec_model) {
5930 case 0x5931: /* TP-1Y */
5931 case 0x3837: /* TP-78 */
5932 case 0x3637: /* TP-76 */
5933 case 0x3037: /* TP-70 */
5934 printk(TPACPI_NOTICE
5935 "fan_init: initial fan status is unknown, "
5936 "assuming it is in auto mode\n");
5937 tp_features.fan_ctrl_status_undef = 1;
5943 static void fan_quirk1_handle(u8 *fan_status)
5945 if (unlikely(tp_features.fan_ctrl_status_undef)) {
5946 if (*fan_status != fan_control_initial_status) {
5947 /* something changed the HFSP regisnter since
5948 * driver init time, so it is not undefined
5950 tp_features.fan_ctrl_status_undef = 0;
5952 /* Return most likely status. In fact, it
5953 * might be the only possible status */
5954 *fan_status = TP_EC_FAN_AUTO;
5960 * Call with fan_mutex held
5962 static void fan_update_desired_level(u8 status)
5965 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) {
5967 fan_control_desired_level = 7;
5969 fan_control_desired_level = status;
5973 static int fan_get_status(u8 *status)
5978 * Add TPACPI_FAN_RD_ACPI_FANS ? */
5980 switch (fan_status_access_mode) {
5981 case TPACPI_FAN_RD_ACPI_GFAN:
5982 /* 570, 600e/x, 770e, 770x */
5984 if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
5992 case TPACPI_FAN_RD_TPEC:
5993 /* all except 570, 600e/x, 770e, 770x */
5994 if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
5997 if (likely(status)) {
5999 fan_quirk1_handle(status);
6011 static int fan_get_status_safe(u8 *status)
6016 if (mutex_lock_killable(&fan_mutex))
6017 return -ERESTARTSYS;
6018 rc = fan_get_status(&s);
6020 fan_update_desired_level(s);
6021 mutex_unlock(&fan_mutex);
6029 static int fan_get_speed(unsigned int *speed)
6033 switch (fan_status_access_mode) {
6034 case TPACPI_FAN_RD_TPEC:
6035 /* all except 570, 600e/x, 770e, 770x */
6036 if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
6037 !acpi_ec_read(fan_rpm_offset + 1, &hi)))
6041 *speed = (hi << 8) | lo;
6052 static int fan_set_level(int level)
6054 if (!fan_control_allowed)
6057 switch (fan_control_access_mode) {
6058 case TPACPI_FAN_WR_ACPI_SFAN:
6059 if (level >= 0 && level <= 7) {
6060 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
6066 case TPACPI_FAN_WR_ACPI_FANS:
6067 case TPACPI_FAN_WR_TPEC:
6068 if (!(level & TP_EC_FAN_AUTO) &&
6069 !(level & TP_EC_FAN_FULLSPEED) &&
6070 ((level < 0) || (level > 7)))
6073 /* safety net should the EC not support AUTO
6074 * or FULLSPEED mode bits and just ignore them */
6075 if (level & TP_EC_FAN_FULLSPEED)
6076 level |= 7; /* safety min speed 7 */
6077 else if (level & TP_EC_FAN_AUTO)
6078 level |= 4; /* safety min speed 4 */
6080 if (!acpi_ec_write(fan_status_offset, level))
6083 tp_features.fan_ctrl_status_undef = 0;
6092 static int fan_set_level_safe(int level)
6096 if (!fan_control_allowed)
6099 if (mutex_lock_killable(&fan_mutex))
6100 return -ERESTARTSYS;
6102 if (level == TPACPI_FAN_LAST_LEVEL)
6103 level = fan_control_desired_level;
6105 rc = fan_set_level(level);
6107 fan_update_desired_level(level);
6109 mutex_unlock(&fan_mutex);
6113 static int fan_set_enable(void)
6118 if (!fan_control_allowed)
6121 if (mutex_lock_killable(&fan_mutex))
6122 return -ERESTARTSYS;
6124 switch (fan_control_access_mode) {
6125 case TPACPI_FAN_WR_ACPI_FANS:
6126 case TPACPI_FAN_WR_TPEC:
6127 rc = fan_get_status(&s);
6131 /* Don't go out of emergency fan mode */
6134 s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */
6137 if (!acpi_ec_write(fan_status_offset, s))
6140 tp_features.fan_ctrl_status_undef = 0;
6145 case TPACPI_FAN_WR_ACPI_SFAN:
6146 rc = fan_get_status(&s);
6152 /* Set fan to at least level 4 */
6155 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s))
6165 mutex_unlock(&fan_mutex);
6169 static int fan_set_disable(void)
6173 if (!fan_control_allowed)
6176 if (mutex_lock_killable(&fan_mutex))
6177 return -ERESTARTSYS;
6180 switch (fan_control_access_mode) {
6181 case TPACPI_FAN_WR_ACPI_FANS:
6182 case TPACPI_FAN_WR_TPEC:
6183 if (!acpi_ec_write(fan_status_offset, 0x00))
6186 fan_control_desired_level = 0;
6187 tp_features.fan_ctrl_status_undef = 0;
6191 case TPACPI_FAN_WR_ACPI_SFAN:
6192 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00))
6195 fan_control_desired_level = 0;
6203 mutex_unlock(&fan_mutex);
6207 static int fan_set_speed(int speed)
6211 if (!fan_control_allowed)
6214 if (mutex_lock_killable(&fan_mutex))
6215 return -ERESTARTSYS;
6218 switch (fan_control_access_mode) {
6219 case TPACPI_FAN_WR_ACPI_FANS:
6220 if (speed >= 0 && speed <= 65535) {
6221 if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
6222 speed, speed, speed))
6232 mutex_unlock(&fan_mutex);
6236 static void fan_watchdog_reset(void)
6238 static int fan_watchdog_active;
6240 if (fan_control_access_mode == TPACPI_FAN_WR_NONE)
6243 if (fan_watchdog_active)
6244 cancel_delayed_work(&fan_watchdog_task);
6246 if (fan_watchdog_maxinterval > 0 &&
6247 tpacpi_lifecycle != TPACPI_LIFE_EXITING) {
6248 fan_watchdog_active = 1;
6249 if (!queue_delayed_work(tpacpi_wq, &fan_watchdog_task,
6250 msecs_to_jiffies(fan_watchdog_maxinterval
6253 "failed to queue the fan watchdog, "
6254 "watchdog will not trigger\n");
6257 fan_watchdog_active = 0;
6260 static void fan_watchdog_fire(struct work_struct *ignored)
6264 if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING)
6267 printk(TPACPI_NOTICE "fan watchdog: enabling fan\n");
6268 rc = fan_set_enable();
6270 printk(TPACPI_ERR "fan watchdog: error %d while enabling fan, "
6271 "will try again later...\n", -rc);
6272 /* reschedule for later */
6273 fan_watchdog_reset();
6278 * SYSFS fan layout: hwmon compatible (device)
6281 * 0: "disengaged" mode
6283 * 2: native EC "auto" mode (recommended, hardware default)
6285 * pwm*: set speed in manual mode, ignored otherwise.
6286 * 0 is level 0; 255 is level 7. Intermediate points done with linear
6289 * fan*_input: tachometer reading, RPM
6292 * SYSFS fan layout: extensions
6294 * fan_watchdog (driver):
6295 * fan watchdog interval in seconds, 0 disables (default), max 120
6298 /* sysfs fan pwm1_enable ----------------------------------------------- */
6299 static ssize_t fan_pwm1_enable_show(struct device *dev,
6300 struct device_attribute *attr,
6306 res = fan_get_status_safe(&status);
6310 if (status & TP_EC_FAN_FULLSPEED) {
6312 } else if (status & TP_EC_FAN_AUTO) {
6317 return snprintf(buf, PAGE_SIZE, "%d\n", mode);
6320 static ssize_t fan_pwm1_enable_store(struct device *dev,
6321 struct device_attribute *attr,
6322 const char *buf, size_t count)
6327 if (parse_strtoul(buf, 2, &t))
6332 level = TP_EC_FAN_FULLSPEED;
6335 level = TPACPI_FAN_LAST_LEVEL;
6338 level = TP_EC_FAN_AUTO;
6341 /* reserved for software-controlled auto mode */
6347 res = fan_set_level_safe(level);
6353 fan_watchdog_reset();
6358 static struct device_attribute dev_attr_fan_pwm1_enable =
6359 __ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
6360 fan_pwm1_enable_show, fan_pwm1_enable_store);
6362 /* sysfs fan pwm1 ------------------------------------------------------ */
6363 static ssize_t fan_pwm1_show(struct device *dev,
6364 struct device_attribute *attr,
6370 res = fan_get_status_safe(&status);
6375 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0)
6376 status = fan_control_desired_level;
6381 return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7);
6384 static ssize_t fan_pwm1_store(struct device *dev,
6385 struct device_attribute *attr,
6386 const char *buf, size_t count)
6390 u8 status, newlevel;
6392 if (parse_strtoul(buf, 255, &s))
6395 /* scale down from 0-255 to 0-7 */
6396 newlevel = (s >> 5) & 0x07;
6398 if (mutex_lock_killable(&fan_mutex))
6399 return -ERESTARTSYS;
6401 rc = fan_get_status(&status);
6402 if (!rc && (status &
6403 (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) {
6404 rc = fan_set_level(newlevel);
6408 fan_update_desired_level(newlevel);
6409 fan_watchdog_reset();
6413 mutex_unlock(&fan_mutex);
6414 return (rc)? rc : count;
6417 static struct device_attribute dev_attr_fan_pwm1 =
6418 __ATTR(pwm1, S_IWUSR | S_IRUGO,
6419 fan_pwm1_show, fan_pwm1_store);
6421 /* sysfs fan fan1_input ------------------------------------------------ */
6422 static ssize_t fan_fan1_input_show(struct device *dev,
6423 struct device_attribute *attr,
6429 res = fan_get_speed(&speed);
6433 return snprintf(buf, PAGE_SIZE, "%u\n", speed);
6436 static struct device_attribute dev_attr_fan_fan1_input =
6437 __ATTR(fan1_input, S_IRUGO,
6438 fan_fan1_input_show, NULL);
6440 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
6441 static ssize_t fan_fan_watchdog_show(struct device_driver *drv,
6444 return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval);
6447 static ssize_t fan_fan_watchdog_store(struct device_driver *drv,
6448 const char *buf, size_t count)
6452 if (parse_strtoul(buf, 120, &t))
6455 if (!fan_control_allowed)
6458 fan_watchdog_maxinterval = t;
6459 fan_watchdog_reset();
6464 static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO,
6465 fan_fan_watchdog_show, fan_fan_watchdog_store);
6467 /* --------------------------------------------------------------------- */
6468 static struct attribute *fan_attributes[] = {
6469 &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr,
6470 &dev_attr_fan_fan1_input.attr,
6474 static const struct attribute_group fan_attr_group = {
6475 .attrs = fan_attributes,
6478 static int __init fan_init(struct ibm_init_struct *iibm)
6482 vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n");
6484 mutex_init(&fan_mutex);
6485 fan_status_access_mode = TPACPI_FAN_NONE;
6486 fan_control_access_mode = TPACPI_FAN_WR_NONE;
6487 fan_control_commands = 0;
6488 fan_watchdog_maxinterval = 0;
6489 tp_features.fan_ctrl_status_undef = 0;
6490 fan_control_desired_level = 7;
6492 TPACPI_ACPIHANDLE_INIT(fans);
6493 TPACPI_ACPIHANDLE_INIT(gfan);
6494 TPACPI_ACPIHANDLE_INIT(sfan);
6497 /* 570, 600e/x, 770e, 770x */
6498 fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN;
6500 /* all other ThinkPads: note that even old-style
6501 * ThinkPad ECs supports the fan control register */
6502 if (likely(acpi_ec_read(fan_status_offset,
6503 &fan_control_initial_status))) {
6504 fan_status_access_mode = TPACPI_FAN_RD_TPEC;
6505 fan_quirk1_detect();
6508 "ThinkPad ACPI EC access misbehaving, "
6509 "fan status and control unavailable\n");
6516 fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN;
6517 fan_control_commands |=
6518 TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE;
6521 /* gfan without sfan means no fan control */
6522 /* all other models implement TP EC 0x2f control */
6526 fan_control_access_mode =
6527 TPACPI_FAN_WR_ACPI_FANS;
6528 fan_control_commands |=
6529 TPACPI_FAN_CMD_SPEED |
6530 TPACPI_FAN_CMD_LEVEL |
6531 TPACPI_FAN_CMD_ENABLE;
6533 fan_control_access_mode = TPACPI_FAN_WR_TPEC;
6534 fan_control_commands |=
6535 TPACPI_FAN_CMD_LEVEL |
6536 TPACPI_FAN_CMD_ENABLE;
6541 vdbg_printk(TPACPI_DBG_INIT, "fan is %s, modes %d, %d\n",
6542 str_supported(fan_status_access_mode != TPACPI_FAN_NONE ||
6543 fan_control_access_mode != TPACPI_FAN_WR_NONE),
6544 fan_status_access_mode, fan_control_access_mode);
6546 /* fan control master switch */
6547 if (!fan_control_allowed) {
6548 fan_control_access_mode = TPACPI_FAN_WR_NONE;
6549 fan_control_commands = 0;
6550 dbg_printk(TPACPI_DBG_INIT,
6551 "fan control features disabled by parameter\n");
6554 /* update fan_control_desired_level */
6555 if (fan_status_access_mode != TPACPI_FAN_NONE)
6556 fan_get_status_safe(NULL);
6558 if (fan_status_access_mode != TPACPI_FAN_NONE ||
6559 fan_control_access_mode != TPACPI_FAN_WR_NONE) {
6560 rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj,
6565 rc = driver_create_file(&tpacpi_hwmon_pdriver.driver,
6566 &driver_attr_fan_watchdog);
6568 sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj,
6577 static void fan_exit(void)
6579 vdbg_printk(TPACPI_DBG_EXIT,
6580 "cancelling any pending fan watchdog tasks\n");
6582 /* FIXME: can we really do this unconditionally? */
6583 sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, &fan_attr_group);
6584 driver_remove_file(&tpacpi_hwmon_pdriver.driver,
6585 &driver_attr_fan_watchdog);
6587 cancel_delayed_work(&fan_watchdog_task);
6588 flush_workqueue(tpacpi_wq);
6591 static void fan_suspend(pm_message_t state)
6595 if (!fan_control_allowed)
6598 /* Store fan status in cache */
6599 fan_control_resume_level = 0;
6600 rc = fan_get_status_safe(&fan_control_resume_level);
6602 printk(TPACPI_NOTICE
6603 "failed to read fan level for later "
6604 "restore during resume: %d\n", rc);
6606 /* if it is undefined, don't attempt to restore it.
6608 if (tp_features.fan_ctrl_status_undef)
6609 fan_control_resume_level = 0;
6612 static void fan_resume(void)
6614 u8 current_level = 7;
6615 bool do_set = false;
6618 /* DSDT *always* updates status on resume */
6619 tp_features.fan_ctrl_status_undef = 0;
6621 if (!fan_control_allowed ||
6622 !fan_control_resume_level ||
6623 (fan_get_status_safe(¤t_level) < 0))
6626 switch (fan_control_access_mode) {
6627 case TPACPI_FAN_WR_ACPI_SFAN:
6628 /* never decrease fan level */
6629 do_set = (fan_control_resume_level > current_level);
6631 case TPACPI_FAN_WR_ACPI_FANS:
6632 case TPACPI_FAN_WR_TPEC:
6633 /* never decrease fan level, scale is:
6634 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
6636 * We expect the firmware to set either 7 or AUTO, but we
6637 * handle FULLSPEED out of paranoia.
6639 * So, we can safely only restore FULLSPEED or 7, anything
6640 * else could slow the fan. Restoring AUTO is useless, at
6641 * best that's exactly what the DSDT already set (it is the
6644 * Always keep in mind that the DSDT *will* have set the
6645 * fans to what the vendor supposes is the best level. We
6646 * muck with it only to speed the fan up.
6648 if (fan_control_resume_level != 7 &&
6649 !(fan_control_resume_level & TP_EC_FAN_FULLSPEED))
6652 do_set = !(current_level & TP_EC_FAN_FULLSPEED) &&
6653 (current_level != fan_control_resume_level);
6659 printk(TPACPI_NOTICE
6660 "restoring fan level to 0x%02x\n",
6661 fan_control_resume_level);
6662 rc = fan_set_level_safe(fan_control_resume_level);
6664 printk(TPACPI_NOTICE
6665 "failed to restore fan level: %d\n", rc);
6669 static int fan_read(char *p)
6674 unsigned int speed = 0;
6676 switch (fan_status_access_mode) {
6677 case TPACPI_FAN_RD_ACPI_GFAN:
6678 /* 570, 600e/x, 770e, 770x */
6679 rc = fan_get_status_safe(&status);
6683 len += sprintf(p + len, "status:\t\t%s\n"
6685 (status != 0) ? "enabled" : "disabled", status);
6688 case TPACPI_FAN_RD_TPEC:
6689 /* all except 570, 600e/x, 770e, 770x */
6690 rc = fan_get_status_safe(&status);
6694 len += sprintf(p + len, "status:\t\t%s\n",
6695 (status != 0) ? "enabled" : "disabled");
6697 rc = fan_get_speed(&speed);
6701 len += sprintf(p + len, "speed:\t\t%d\n", speed);
6703 if (status & TP_EC_FAN_FULLSPEED)
6704 /* Disengaged mode takes precedence */
6705 len += sprintf(p + len, "level:\t\tdisengaged\n");
6706 else if (status & TP_EC_FAN_AUTO)
6707 len += sprintf(p + len, "level:\t\tauto\n");
6709 len += sprintf(p + len, "level:\t\t%d\n", status);
6712 case TPACPI_FAN_NONE:
6714 len += sprintf(p + len, "status:\t\tnot supported\n");
6717 if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) {
6718 len += sprintf(p + len, "commands:\tlevel <level>");
6720 switch (fan_control_access_mode) {
6721 case TPACPI_FAN_WR_ACPI_SFAN:
6722 len += sprintf(p + len, " (<level> is 0-7)\n");
6726 len += sprintf(p + len, " (<level> is 0-7, "
6727 "auto, disengaged, full-speed)\n");
6732 if (fan_control_commands & TPACPI_FAN_CMD_ENABLE)
6733 len += sprintf(p + len, "commands:\tenable, disable\n"
6734 "commands:\twatchdog <timeout> (<timeout> "
6735 "is 0 (off), 1-120 (seconds))\n");
6737 if (fan_control_commands & TPACPI_FAN_CMD_SPEED)
6738 len += sprintf(p + len, "commands:\tspeed <speed>"
6739 " (<speed> is 0-65535)\n");
6744 static int fan_write_cmd_level(const char *cmd, int *rc)
6748 if (strlencmp(cmd, "level auto") == 0)
6749 level = TP_EC_FAN_AUTO;
6750 else if ((strlencmp(cmd, "level disengaged") == 0) |
6751 (strlencmp(cmd, "level full-speed") == 0))
6752 level = TP_EC_FAN_FULLSPEED;
6753 else if (sscanf(cmd, "level %d", &level) != 1)
6756 *rc = fan_set_level_safe(level);
6758 printk(TPACPI_ERR "level command accepted for unsupported "
6759 "access mode %d", fan_control_access_mode);
6764 static int fan_write_cmd_enable(const char *cmd, int *rc)
6766 if (strlencmp(cmd, "enable") != 0)
6769 *rc = fan_set_enable();
6771 printk(TPACPI_ERR "enable command accepted for unsupported "
6772 "access mode %d", fan_control_access_mode);
6777 static int fan_write_cmd_disable(const char *cmd, int *rc)
6779 if (strlencmp(cmd, "disable") != 0)
6782 *rc = fan_set_disable();
6784 printk(TPACPI_ERR "disable command accepted for unsupported "
6785 "access mode %d", fan_control_access_mode);
6790 static int fan_write_cmd_speed(const char *cmd, int *rc)
6795 * Support speed <low> <medium> <high> ? */
6797 if (sscanf(cmd, "speed %d", &speed) != 1)
6800 *rc = fan_set_speed(speed);
6802 printk(TPACPI_ERR "speed command accepted for unsupported "
6803 "access mode %d", fan_control_access_mode);
6808 static int fan_write_cmd_watchdog(const char *cmd, int *rc)
6812 if (sscanf(cmd, "watchdog %d", &interval) != 1)
6815 if (interval < 0 || interval > 120)
6818 fan_watchdog_maxinterval = interval;
6823 static int fan_write(char *buf)
6828 while (!rc && (cmd = next_cmd(&buf))) {
6829 if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) &&
6830 fan_write_cmd_level(cmd, &rc)) &&
6831 !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) &&
6832 (fan_write_cmd_enable(cmd, &rc) ||
6833 fan_write_cmd_disable(cmd, &rc) ||
6834 fan_write_cmd_watchdog(cmd, &rc))) &&
6835 !((fan_control_commands & TPACPI_FAN_CMD_SPEED) &&
6836 fan_write_cmd_speed(cmd, &rc))
6840 fan_watchdog_reset();
6846 static struct ibm_struct fan_driver_data = {
6851 .suspend = fan_suspend,
6852 .resume = fan_resume,
6855 /****************************************************************************
6856 ****************************************************************************
6860 ****************************************************************************
6861 ****************************************************************************/
6863 /* sysfs name ---------------------------------------------------------- */
6864 static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev,
6865 struct device_attribute *attr,
6868 return snprintf(buf, PAGE_SIZE, "%s\n", TPACPI_NAME);
6871 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name =
6872 __ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL);
6874 /* --------------------------------------------------------------------- */
6877 static struct proc_dir_entry *proc_dir;
6880 * Module and infrastructure proble, init and exit handling
6883 static int force_load;
6885 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
6886 static const char * __init str_supported(int is_supported)
6888 static char text_unsupported[] __initdata = "not supported";
6890 return (is_supported)? &text_unsupported[4] : &text_unsupported[0];
6892 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
6894 static void ibm_exit(struct ibm_struct *ibm)
6896 dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name);
6898 list_del_init(&ibm->all_drivers);
6900 if (ibm->flags.acpi_notify_installed) {
6901 dbg_printk(TPACPI_DBG_EXIT,
6902 "%s: acpi_remove_notify_handler\n", ibm->name);
6904 acpi_remove_notify_handler(*ibm->acpi->handle,
6906 dispatch_acpi_notify);
6907 ibm->flags.acpi_notify_installed = 0;
6908 ibm->flags.acpi_notify_installed = 0;
6911 if (ibm->flags.proc_created) {
6912 dbg_printk(TPACPI_DBG_EXIT,
6913 "%s: remove_proc_entry\n", ibm->name);
6914 remove_proc_entry(ibm->name, proc_dir);
6915 ibm->flags.proc_created = 0;
6918 if (ibm->flags.acpi_driver_registered) {
6919 dbg_printk(TPACPI_DBG_EXIT,
6920 "%s: acpi_bus_unregister_driver\n", ibm->name);
6922 acpi_bus_unregister_driver(ibm->acpi->driver);
6923 kfree(ibm->acpi->driver);
6924 ibm->acpi->driver = NULL;
6925 ibm->flags.acpi_driver_registered = 0;
6928 if (ibm->flags.init_called && ibm->exit) {
6930 ibm->flags.init_called = 0;
6933 dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name);
6936 static int __init ibm_init(struct ibm_init_struct *iibm)
6939 struct ibm_struct *ibm = iibm->data;
6940 struct proc_dir_entry *entry;
6942 BUG_ON(ibm == NULL);
6944 INIT_LIST_HEAD(&ibm->all_drivers);
6946 if (ibm->flags.experimental && !experimental)
6949 dbg_printk(TPACPI_DBG_INIT,
6950 "probing for %s\n", ibm->name);
6953 ret = iibm->init(iibm);
6955 return 0; /* probe failed */
6959 ibm->flags.init_called = 1;
6963 if (ibm->acpi->hid) {
6964 ret = register_tpacpi_subdriver(ibm);
6969 if (ibm->acpi->notify) {
6970 ret = setup_acpi_notify(ibm);
6971 if (ret == -ENODEV) {
6972 printk(TPACPI_NOTICE "disabling subdriver %s\n",
6982 dbg_printk(TPACPI_DBG_INIT,
6983 "%s installed\n", ibm->name);
6986 entry = create_proc_entry(ibm->name,
6987 S_IFREG | S_IRUGO | S_IWUSR,
6990 printk(TPACPI_ERR "unable to create proc entry %s\n",
6995 entry->owner = THIS_MODULE;
6997 entry->read_proc = &dispatch_procfs_read;
6999 entry->write_proc = &dispatch_procfs_write;
7000 ibm->flags.proc_created = 1;
7003 list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers);
7008 dbg_printk(TPACPI_DBG_INIT,
7009 "%s: at error exit path with result %d\n",
7013 return (ret < 0)? ret : 0;
7018 /* returns 0 - probe ok, or < 0 - probe error.
7019 * Probe ok doesn't mean thinkpad found.
7020 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
7021 static int __must_check __init get_thinkpad_model_data(
7022 struct thinkpad_id_data *tp)
7024 const struct dmi_device *dev = NULL;
7025 char ec_fw_string[18];
7031 memset(tp, 0, sizeof(*tp));
7033 if (dmi_name_in_vendors("IBM"))
7034 tp->vendor = PCI_VENDOR_ID_IBM;
7035 else if (dmi_name_in_vendors("LENOVO"))
7036 tp->vendor = PCI_VENDOR_ID_LENOVO;
7040 s = dmi_get_system_info(DMI_BIOS_VERSION);
7041 tp->bios_version_str = kstrdup(s, GFP_KERNEL);
7042 if (s && !tp->bios_version_str)
7044 if (!tp->bios_version_str)
7046 tp->bios_model = tp->bios_version_str[0]
7047 | (tp->bios_version_str[1] << 8);
7050 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
7051 * X32 or newer, all Z series; Some models must have an
7052 * up-to-date BIOS or they will not be detected.
7054 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7056 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
7057 if (sscanf(dev->name,
7058 "IBM ThinkPad Embedded Controller -[%17c",
7059 ec_fw_string) == 1) {
7060 ec_fw_string[sizeof(ec_fw_string) - 1] = 0;
7061 ec_fw_string[strcspn(ec_fw_string, " ]")] = 0;
7063 tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL);
7064 if (!tp->ec_version_str)
7066 tp->ec_model = ec_fw_string[0]
7067 | (ec_fw_string[1] << 8);
7072 s = dmi_get_system_info(DMI_PRODUCT_VERSION);
7073 if (s && !strnicmp(s, "ThinkPad", 8)) {
7074 tp->model_str = kstrdup(s, GFP_KERNEL);
7079 s = dmi_get_system_info(DMI_PRODUCT_NAME);
7080 tp->nummodel_str = kstrdup(s, GFP_KERNEL);
7081 if (s && !tp->nummodel_str)
7087 static int __init probe_for_thinkpad(void)
7095 * Non-ancient models have better DMI tagging, but very old models
7098 is_thinkpad = (thinkpad_id.model_str != NULL);
7100 /* ec is required because many other handles are relative to it */
7101 TPACPI_ACPIHANDLE_INIT(ec);
7105 "Not yet supported ThinkPad detected!\n");
7110 * Risks a regression on very old machines, but reduces potential
7111 * false positives a damn great deal
7114 is_thinkpad = (thinkpad_id.vendor == PCI_VENDOR_ID_IBM);
7116 if (!is_thinkpad && !force_load)
7123 /* Module init, exit, parameters */
7125 static struct ibm_init_struct ibms_init[] __initdata = {
7127 .init = thinkpad_acpi_driver_init,
7128 .data = &thinkpad_acpi_driver_data,
7131 .init = hotkey_init,
7132 .data = &hotkey_driver_data,
7135 .init = bluetooth_init,
7136 .data = &bluetooth_driver_data,
7140 .data = &wan_driver_data,
7144 .data = &uwb_driver_data,
7146 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
7149 .data = &video_driver_data,
7154 .data = &light_driver_data,
7156 #ifdef CONFIG_THINKPAD_ACPI_DOCK
7159 .data = &dock_driver_data[0],
7163 .data = &dock_driver_data[1],
7166 #ifdef CONFIG_THINKPAD_ACPI_BAY
7169 .data = &bay_driver_data,
7174 .data = &cmos_driver_data,
7178 .data = &led_driver_data,
7182 .data = &beep_driver_data,
7185 .init = thermal_init,
7186 .data = &thermal_driver_data,
7189 .data = &ecdump_driver_data,
7192 .init = brightness_init,
7193 .data = &brightness_driver_data,
7196 .data = &volume_driver_data,
7200 .data = &fan_driver_data,
7204 static int __init set_ibm_param(const char *val, struct kernel_param *kp)
7207 struct ibm_struct *ibm;
7209 if (!kp || !kp->name || !val)
7212 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
7213 ibm = ibms_init[i].data;
7214 WARN_ON(ibm == NULL);
7216 if (!ibm || !ibm->name)
7219 if (strcmp(ibm->name, kp->name) == 0 && ibm->write) {
7220 if (strlen(val) > sizeof(ibms_init[i].param) - 2)
7222 strcpy(ibms_init[i].param, val);
7223 strcat(ibms_init[i].param, ",");
7231 module_param(experimental, int, 0);
7232 MODULE_PARM_DESC(experimental,
7233 "Enables experimental features when non-zero");
7235 module_param_named(debug, dbg_level, uint, 0);
7236 MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
7238 module_param(force_load, bool, 0);
7239 MODULE_PARM_DESC(force_load,
7240 "Attempts to load the driver even on a "
7241 "mis-identified ThinkPad when true");
7243 module_param_named(fan_control, fan_control_allowed, bool, 0);
7244 MODULE_PARM_DESC(fan_control,
7245 "Enables setting fan parameters features when true");
7247 module_param_named(brightness_mode, brightness_mode, int, 0);
7248 MODULE_PARM_DESC(brightness_mode,
7249 "Selects brightness control strategy: "
7250 "0=auto, 1=EC, 2=CMOS, 3=both");
7252 module_param(brightness_enable, uint, 0);
7253 MODULE_PARM_DESC(brightness_enable,
7254 "Enables backlight control when 1, disables when 0");
7256 module_param(hotkey_report_mode, uint, 0);
7257 MODULE_PARM_DESC(hotkey_report_mode,
7258 "used for backwards compatibility with userspace, "
7259 "see documentation");
7261 #define TPACPI_PARAM(feature) \
7262 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
7263 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
7264 "at module load, see documentation")
7266 TPACPI_PARAM(hotkey);
7267 TPACPI_PARAM(bluetooth);
7268 TPACPI_PARAM(video);
7269 TPACPI_PARAM(light);
7270 #ifdef CONFIG_THINKPAD_ACPI_DOCK
7273 #ifdef CONFIG_THINKPAD_ACPI_BAY
7275 #endif /* CONFIG_THINKPAD_ACPI_BAY */
7279 TPACPI_PARAM(ecdump);
7280 TPACPI_PARAM(brightness);
7281 TPACPI_PARAM(volume);
7284 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
7285 module_param(dbg_wlswemul, uint, 0);
7286 MODULE_PARM_DESC(dbg_wlswemul, "Enables WLSW emulation");
7287 module_param_named(wlsw_state, tpacpi_wlsw_emulstate, bool, 0);
7288 MODULE_PARM_DESC(wlsw_state,
7289 "Initial state of the emulated WLSW switch");
7291 module_param(dbg_bluetoothemul, uint, 0);
7292 MODULE_PARM_DESC(dbg_bluetoothemul, "Enables bluetooth switch emulation");
7293 module_param_named(bluetooth_state, tpacpi_bluetooth_emulstate, bool, 0);
7294 MODULE_PARM_DESC(bluetooth_state,
7295 "Initial state of the emulated bluetooth switch");
7297 module_param(dbg_wwanemul, uint, 0);
7298 MODULE_PARM_DESC(dbg_wwanemul, "Enables WWAN switch emulation");
7299 module_param_named(wwan_state, tpacpi_wwan_emulstate, bool, 0);
7300 MODULE_PARM_DESC(wwan_state,
7301 "Initial state of the emulated WWAN switch");
7303 module_param(dbg_uwbemul, uint, 0);
7304 MODULE_PARM_DESC(dbg_uwbemul, "Enables UWB switch emulation");
7305 module_param_named(uwb_state, tpacpi_uwb_emulstate, bool, 0);
7306 MODULE_PARM_DESC(uwb_state,
7307 "Initial state of the emulated UWB switch");
7310 static void thinkpad_acpi_module_exit(void)
7312 struct ibm_struct *ibm, *itmp;
7314 tpacpi_lifecycle = TPACPI_LIFE_EXITING;
7316 list_for_each_entry_safe_reverse(ibm, itmp,
7317 &tpacpi_all_drivers,
7322 dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n");
7324 if (tpacpi_inputdev) {
7325 if (tp_features.input_device_registered)
7326 input_unregister_device(tpacpi_inputdev);
7328 input_free_device(tpacpi_inputdev);
7332 hwmon_device_unregister(tpacpi_hwmon);
7334 if (tp_features.sensors_pdev_attrs_registered)
7335 device_remove_file(&tpacpi_sensors_pdev->dev,
7336 &dev_attr_thinkpad_acpi_pdev_name);
7337 if (tpacpi_sensors_pdev)
7338 platform_device_unregister(tpacpi_sensors_pdev);
7340 platform_device_unregister(tpacpi_pdev);
7342 if (tp_features.sensors_pdrv_attrs_registered)
7343 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver.driver);
7344 if (tp_features.platform_drv_attrs_registered)
7345 tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver);
7347 if (tp_features.sensors_pdrv_registered)
7348 platform_driver_unregister(&tpacpi_hwmon_pdriver);
7350 if (tp_features.platform_drv_registered)
7351 platform_driver_unregister(&tpacpi_pdriver);
7354 remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir);
7357 destroy_workqueue(tpacpi_wq);
7359 kfree(thinkpad_id.bios_version_str);
7360 kfree(thinkpad_id.ec_version_str);
7361 kfree(thinkpad_id.model_str);
7365 static int __init thinkpad_acpi_module_init(void)
7369 tpacpi_lifecycle = TPACPI_LIFE_INIT;
7371 /* Parameter checking */
7372 if (hotkey_report_mode > 2)
7375 /* Driver-level probe */
7377 ret = get_thinkpad_model_data(&thinkpad_id);
7380 "unable to get DMI data: %d\n", ret);
7381 thinkpad_acpi_module_exit();
7384 ret = probe_for_thinkpad();
7386 thinkpad_acpi_module_exit();
7390 /* Driver initialization */
7392 TPACPI_ACPIHANDLE_INIT(ecrd);
7393 TPACPI_ACPIHANDLE_INIT(ecwr);
7395 tpacpi_wq = create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME);
7397 thinkpad_acpi_module_exit();
7401 proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir);
7404 "unable to create proc dir " TPACPI_PROC_DIR);
7405 thinkpad_acpi_module_exit();
7408 proc_dir->owner = THIS_MODULE;
7410 ret = platform_driver_register(&tpacpi_pdriver);
7413 "unable to register main platform driver\n");
7414 thinkpad_acpi_module_exit();
7417 tp_features.platform_drv_registered = 1;
7419 ret = platform_driver_register(&tpacpi_hwmon_pdriver);
7422 "unable to register hwmon platform driver\n");
7423 thinkpad_acpi_module_exit();
7426 tp_features.sensors_pdrv_registered = 1;
7428 ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver);
7430 tp_features.platform_drv_attrs_registered = 1;
7431 ret = tpacpi_create_driver_attributes(
7432 &tpacpi_hwmon_pdriver.driver);
7436 "unable to create sysfs driver attributes\n");
7437 thinkpad_acpi_module_exit();
7440 tp_features.sensors_pdrv_attrs_registered = 1;
7443 /* Device initialization */
7444 tpacpi_pdev = platform_device_register_simple(TPACPI_DRVR_NAME, -1,
7446 if (IS_ERR(tpacpi_pdev)) {
7447 ret = PTR_ERR(tpacpi_pdev);
7449 printk(TPACPI_ERR "unable to register platform device\n");
7450 thinkpad_acpi_module_exit();
7453 tpacpi_sensors_pdev = platform_device_register_simple(
7454 TPACPI_HWMON_DRVR_NAME,
7456 if (IS_ERR(tpacpi_sensors_pdev)) {
7457 ret = PTR_ERR(tpacpi_sensors_pdev);
7458 tpacpi_sensors_pdev = NULL;
7460 "unable to register hwmon platform device\n");
7461 thinkpad_acpi_module_exit();
7464 ret = device_create_file(&tpacpi_sensors_pdev->dev,
7465 &dev_attr_thinkpad_acpi_pdev_name);
7468 "unable to create sysfs hwmon device attributes\n");
7469 thinkpad_acpi_module_exit();
7472 tp_features.sensors_pdev_attrs_registered = 1;
7473 tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev);
7474 if (IS_ERR(tpacpi_hwmon)) {
7475 ret = PTR_ERR(tpacpi_hwmon);
7476 tpacpi_hwmon = NULL;
7477 printk(TPACPI_ERR "unable to register hwmon device\n");
7478 thinkpad_acpi_module_exit();
7481 mutex_init(&tpacpi_inputdev_send_mutex);
7482 tpacpi_inputdev = input_allocate_device();
7483 if (!tpacpi_inputdev) {
7484 printk(TPACPI_ERR "unable to allocate input device\n");
7485 thinkpad_acpi_module_exit();
7488 /* Prepare input device, but don't register */
7489 tpacpi_inputdev->name = "ThinkPad Extra Buttons";
7490 tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0";
7491 tpacpi_inputdev->id.bustype = BUS_HOST;
7492 tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ?
7493 thinkpad_id.vendor :
7495 tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT;
7496 tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION;
7498 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
7499 ret = ibm_init(&ibms_init[i]);
7500 if (ret >= 0 && *ibms_init[i].param)
7501 ret = ibms_init[i].data->write(ibms_init[i].param);
7503 thinkpad_acpi_module_exit();
7507 ret = input_register_device(tpacpi_inputdev);
7509 printk(TPACPI_ERR "unable to register input device\n");
7510 thinkpad_acpi_module_exit();
7513 tp_features.input_device_registered = 1;
7516 tpacpi_lifecycle = TPACPI_LIFE_RUNNING;
7520 /* Please remove this in year 2009 */
7521 MODULE_ALIAS("ibm_acpi");
7523 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME);
7526 * DMI matching for module autoloading
7528 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7529 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
7531 * Only models listed in thinkwiki will be supported, so add yours
7532 * if it is not there yet.
7534 #define IBM_BIOS_MODULE_ALIAS(__type) \
7535 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
7537 /* Non-ancient thinkpads */
7538 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
7539 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
7541 /* Ancient thinkpad BIOSes have to be identified by
7542 * BIOS type or model number, and there are far less
7543 * BIOS types than model numbers... */
7544 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
7545 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
7546 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
7548 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
7549 MODULE_DESCRIPTION(TPACPI_DESC);
7550 MODULE_VERSION(TPACPI_VERSION);
7551 MODULE_LICENSE("GPL");
7553 module_init(thinkpad_acpi_module_init);
7554 module_exit(thinkpad_acpi_module_exit);