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.21"
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>
79 #include <acpi/acnamesp.h>
81 #include <linux/pci_ids.h>
84 /* ThinkPad CMOS commands */
85 #define TP_CMOS_VOLUME_DOWN 0
86 #define TP_CMOS_VOLUME_UP 1
87 #define TP_CMOS_VOLUME_MUTE 2
88 #define TP_CMOS_BRIGHTNESS_UP 4
89 #define TP_CMOS_BRIGHTNESS_DOWN 5
90 #define TP_CMOS_THINKLIGHT_ON 12
91 #define TP_CMOS_THINKLIGHT_OFF 13
95 TP_NVRAM_ADDR_HK2
= 0x57,
96 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
97 TP_NVRAM_ADDR_VIDEO
= 0x59,
98 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
99 TP_NVRAM_ADDR_MIXER
= 0x60,
102 /* NVRAM bit masks */
104 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
105 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
106 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
107 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
108 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
109 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
110 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
111 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
112 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
113 TP_NVRAM_MASK_MUTE
= 0x40,
114 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
115 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
116 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
120 #define TPACPI_ACPI_HKEY_HID "IBM0068"
123 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
124 #define TPACPI_HKEY_INPUT_VERSION 0x4101
127 /****************************************************************************
131 #define TPACPI_NAME "thinkpad"
132 #define TPACPI_DESC "ThinkPad ACPI Extras"
133 #define TPACPI_FILE TPACPI_NAME "_acpi"
134 #define TPACPI_URL "http://ibm-acpi.sf.net/"
135 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
137 #define TPACPI_PROC_DIR "ibm"
138 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
139 #define TPACPI_DRVR_NAME TPACPI_FILE
140 #define TPACPI_DRVR_SHORTNAME "tpacpi"
141 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
143 #define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
144 #define TPACPI_WORKQUEUE_NAME "ktpacpid"
146 #define TPACPI_MAX_ACPI_ARGS 3
148 /* rfkill switches */
150 TPACPI_RFK_BLUETOOTH_SW_ID
= 0,
151 TPACPI_RFK_WWAN_SW_ID
,
155 #define TPACPI_LOG TPACPI_FILE ": "
156 #define TPACPI_ERR KERN_ERR TPACPI_LOG
157 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
158 #define TPACPI_INFO KERN_INFO TPACPI_LOG
159 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
161 #define TPACPI_DBG_ALL 0xffff
162 #define TPACPI_DBG_INIT 0x0001
163 #define TPACPI_DBG_EXIT 0x0002
164 #define dbg_printk(a_dbg_level, format, arg...) \
165 do { if (dbg_level & a_dbg_level) \
166 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
168 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
169 #define vdbg_printk(a_dbg_level, format, arg...) \
170 dbg_printk(a_dbg_level, format, ## arg)
171 static const char *str_supported(int is_supported
);
173 #define vdbg_printk(a_dbg_level, format, arg...)
176 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
177 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
178 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
181 /****************************************************************************
182 * Driver-wide structs and misc. variables
187 struct tp_acpi_drv_struct
{
188 const struct acpi_device_id
*hid
;
189 struct acpi_driver
*driver
;
191 void (*notify
) (struct ibm_struct
*, u32
);
194 struct acpi_device
*device
;
200 int (*read
) (char *);
201 int (*write
) (char *);
203 void (*resume
) (void);
204 void (*suspend
) (pm_message_t state
);
206 struct list_head all_drivers
;
208 struct tp_acpi_drv_struct
*acpi
;
211 u8 acpi_driver_registered
:1;
212 u8 acpi_notify_installed
:1;
219 struct ibm_init_struct
{
222 int (*init
) (struct ibm_init_struct
*);
223 struct ibm_struct
*data
;
227 #ifdef CONFIG_THINKPAD_ACPI_BAY
240 u32 bright_16levels
:1;
241 u32 bright_acpimode
:1;
243 u32 fan_ctrl_status_undef
:1;
244 u32 input_device_registered
:1;
245 u32 platform_drv_registered
:1;
246 u32 platform_drv_attrs_registered
:1;
247 u32 sensors_pdrv_registered
:1;
248 u32 sensors_pdrv_attrs_registered
:1;
249 u32 sensors_pdev_attrs_registered
:1;
250 u32 hotkey_poll_active
:1;
254 u16 hotkey_mask_ff
:1;
255 u16 bright_cmos_ec_unsync
:1;
258 struct thinkpad_id_data
{
259 unsigned int vendor
; /* ThinkPad vendor:
260 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
262 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
263 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
265 u16 bios_model
; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */
268 char *model_str
; /* ThinkPad T43 */
269 char *nummodel_str
; /* 9384A9C for a 9384-A9C model */
271 static struct thinkpad_id_data thinkpad_id
;
274 TPACPI_LIFE_INIT
= 0,
279 static int experimental
;
280 static u32 dbg_level
;
282 static struct workqueue_struct
*tpacpi_wq
;
284 /* Special LED class that can defer work */
285 struct tpacpi_led_classdev
{
286 struct led_classdev led_classdev
;
287 struct work_struct work
;
288 enum led_brightness new_brightness
;
292 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
293 static int dbg_wlswemul
;
294 static int tpacpi_wlsw_emulstate
;
295 static int dbg_bluetoothemul
;
296 static int tpacpi_bluetooth_emulstate
;
297 static int dbg_wwanemul
;
298 static int tpacpi_wwan_emulstate
;
302 /****************************************************************************
303 ****************************************************************************
305 * ACPI Helpers and device model
307 ****************************************************************************
308 ****************************************************************************/
310 /*************************************************************************
314 static acpi_handle root_handle
;
316 #define TPACPI_HANDLE(object, parent, paths...) \
317 static acpi_handle object##_handle; \
318 static acpi_handle *object##_parent = &parent##_handle; \
319 static char *object##_path; \
320 static char *object##_paths[] = { paths }
322 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
323 "\\_SB.PCI.ISA.EC", /* 570 */
324 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
325 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
326 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
327 "\\_SB.PCI0.ICH3.EC0", /* R31 */
328 "\\_SB.PCI0.LPC.EC", /* all others */
331 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
332 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
334 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
336 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
337 "\\CMS", /* R40, R40e */
340 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
341 "^HKEY", /* R30, R31 */
342 "HKEY", /* all others */
345 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
346 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
347 "\\_SB.PCI0.VID0", /* 770e */
348 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
349 "\\_SB.PCI0.AGP.VID", /* all others */
353 /*************************************************************************
357 static int acpi_evalf(acpi_handle handle
,
358 void *res
, char *method
, char *fmt
, ...)
361 struct acpi_object_list params
;
362 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
363 struct acpi_buffer result
, *resultp
;
364 union acpi_object out_obj
;
372 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
385 params
.pointer
= &in_objs
[0];
392 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
393 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
395 /* add more types as needed */
397 printk(TPACPI_ERR
"acpi_evalf() called "
398 "with invalid format character '%c'\n", c
);
404 if (res_type
!= 'v') {
405 result
.length
= sizeof(out_obj
);
406 result
.pointer
= &out_obj
;
411 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
416 *(int *)res
= out_obj
.integer
.value
;
417 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
420 success
= status
== AE_OK
;
422 /* add more types as needed */
424 printk(TPACPI_ERR
"acpi_evalf() called "
425 "with invalid format character '%c'\n", res_type
);
429 if (!success
&& !quiet
)
430 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
431 method
, fmt0
, status
);
436 static int acpi_ec_read(int i
, u8
*p
)
441 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
445 if (ec_read(i
, p
) < 0)
452 static int acpi_ec_write(int i
, u8 v
)
455 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
458 if (ec_write(i
, v
) < 0)
465 #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY)
466 static int _sta(acpi_handle handle
)
470 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
477 static int issue_thinkpad_cmos_command(int cmos_cmd
)
482 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
488 /*************************************************************************
492 #define TPACPI_ACPIHANDLE_INIT(object) \
493 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
494 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
496 static void drv_acpi_handle_init(char *name
,
497 acpi_handle
*handle
, acpi_handle parent
,
498 char **paths
, int num_paths
, char **path
)
503 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
506 for (i
= 0; i
< num_paths
; i
++) {
507 status
= acpi_get_handle(parent
, paths
[i
], handle
);
508 if (ACPI_SUCCESS(status
)) {
510 dbg_printk(TPACPI_DBG_INIT
,
511 "Found ACPI handle %s for %s\n",
517 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
522 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
524 struct ibm_struct
*ibm
= data
;
526 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
529 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
532 ibm
->acpi
->notify(ibm
, event
);
535 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
542 if (!*ibm
->acpi
->handle
)
545 vdbg_printk(TPACPI_DBG_INIT
,
546 "setting up ACPI notify for %s\n", ibm
->name
);
548 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
550 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
555 ibm
->acpi
->device
->driver_data
= ibm
;
556 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
557 TPACPI_ACPI_EVENT_PREFIX
,
560 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
561 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
562 if (ACPI_FAILURE(status
)) {
563 if (status
== AE_ALREADY_EXISTS
) {
565 "another device driver is already "
566 "handling %s events\n", ibm
->name
);
569 "acpi_install_notify_handler(%s) failed: %d\n",
574 ibm
->flags
.acpi_notify_installed
= 1;
578 static int __init
tpacpi_device_add(struct acpi_device
*device
)
583 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
587 dbg_printk(TPACPI_DBG_INIT
,
588 "registering %s as an ACPI driver\n", ibm
->name
);
592 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
593 if (!ibm
->acpi
->driver
) {
595 "failed to allocate memory for ibm->acpi->driver\n");
599 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
600 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
602 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
604 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
606 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
608 kfree(ibm
->acpi
->driver
);
609 ibm
->acpi
->driver
= NULL
;
611 ibm
->flags
.acpi_driver_registered
= 1;
617 /****************************************************************************
618 ****************************************************************************
622 ****************************************************************************
623 ****************************************************************************/
625 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
626 int count
, int *eof
, void *data
)
628 struct ibm_struct
*ibm
= data
;
631 if (!ibm
|| !ibm
->read
)
634 len
= ibm
->read(page
);
638 if (len
<= off
+ count
)
650 static int dispatch_procfs_write(struct file
*file
,
651 const char __user
*userbuf
,
652 unsigned long count
, void *data
)
654 struct ibm_struct
*ibm
= data
;
658 if (!ibm
|| !ibm
->write
)
661 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
665 if (copy_from_user(kernbuf
, userbuf
, count
)) {
671 strcat(kernbuf
, ",");
672 ret
= ibm
->write(kernbuf
);
681 static char *next_cmd(char **cmds
)
686 while ((end
= strchr(start
, ',')) && end
== start
)
698 /****************************************************************************
699 ****************************************************************************
701 * Device model: input, hwmon and platform
703 ****************************************************************************
704 ****************************************************************************/
706 static struct platform_device
*tpacpi_pdev
;
707 static struct platform_device
*tpacpi_sensors_pdev
;
708 static struct device
*tpacpi_hwmon
;
709 static struct input_dev
*tpacpi_inputdev
;
710 static struct mutex tpacpi_inputdev_send_mutex
;
711 static LIST_HEAD(tpacpi_all_drivers
);
713 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
716 struct ibm_struct
*ibm
, *itmp
;
718 list_for_each_entry_safe(ibm
, itmp
,
722 (ibm
->suspend
)(state
);
728 static int tpacpi_resume_handler(struct platform_device
*pdev
)
730 struct ibm_struct
*ibm
, *itmp
;
732 list_for_each_entry_safe(ibm
, itmp
,
742 static struct platform_driver tpacpi_pdriver
= {
744 .name
= TPACPI_DRVR_NAME
,
745 .owner
= THIS_MODULE
,
747 .suspend
= tpacpi_suspend_handler
,
748 .resume
= tpacpi_resume_handler
,
751 static struct platform_driver tpacpi_hwmon_pdriver
= {
753 .name
= TPACPI_HWMON_DRVR_NAME
,
754 .owner
= THIS_MODULE
,
758 /*************************************************************************
759 * sysfs support helpers
762 struct attribute_set
{
763 unsigned int members
, max_members
;
764 struct attribute_group group
;
767 struct attribute_set_obj
{
768 struct attribute_set s
;
770 } __attribute__((packed
));
772 static struct attribute_set
*create_attr_set(unsigned int max_members
,
775 struct attribute_set_obj
*sobj
;
777 if (max_members
== 0)
780 /* Allocates space for implicit NULL at the end too */
781 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
782 max_members
* sizeof(struct attribute
*),
786 sobj
->s
.max_members
= max_members
;
787 sobj
->s
.group
.attrs
= &sobj
->a
;
788 sobj
->s
.group
.name
= name
;
793 #define destroy_attr_set(_set) \
796 /* not multi-threaded safe, use it in a single thread per set */
797 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
802 if (s
->members
>= s
->max_members
)
805 s
->group
.attrs
[s
->members
] = attr
;
811 static int add_many_to_attr_set(struct attribute_set
*s
,
812 struct attribute
**attr
,
817 for (i
= 0; i
< count
; i
++) {
818 res
= add_to_attr_set(s
, attr
[i
]);
826 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
828 sysfs_remove_group(kobj
, &s
->group
);
832 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
833 sysfs_create_group(_kobj, &_attr_set->group)
835 static int parse_strtoul(const char *buf
,
836 unsigned long max
, unsigned long *value
)
840 while (*buf
&& isspace(*buf
))
842 *value
= simple_strtoul(buf
, &endp
, 0);
843 while (*endp
&& isspace(*endp
))
845 if (*endp
|| *value
> max
)
851 static void tpacpi_disable_brightness_delay(void)
853 if (acpi_evalf(hkey_handle
, NULL
, "PWMS", "qvd", 0))
855 "ACPI backlight control delay disabled\n");
858 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
860 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
861 union acpi_object
*obj
;
864 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
865 obj
= (union acpi_object
*)buffer
.pointer
;
866 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
867 printk(TPACPI_ERR
"Unknown _BCL data, "
868 "please report this to %s\n", TPACPI_MAIL
);
871 rc
= obj
->package
.count
;
877 kfree(buffer
.pointer
);
881 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
882 u32 lvl
, void *context
, void **rv
)
884 char name
[ACPI_PATH_SEGMENT_LENGTH
];
885 struct acpi_buffer buffer
= { sizeof(name
), &name
};
887 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
888 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
890 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
891 return AE_CTRL_TERMINATE
;
898 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
900 static int __init
tpacpi_check_std_acpi_brightness_support(void)
904 void *bcl_ptr
= &bcl_levels
;
907 TPACPI_ACPIHANDLE_INIT(vid
);
913 * Search for a _BCL method, and execute it. This is safe on all
914 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
915 * BIOS in ACPI backlight control mode. We do NOT have to care
916 * about calling the _BCL method in an enabled video device, any
917 * will do for our purposes.
920 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
921 tpacpi_acpi_walk_find_bcl
, NULL
,
924 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
925 tp_features
.bright_acpimode
= 1;
926 return (bcl_levels
- 2);
932 static int __init
tpacpi_new_rfkill(const unsigned int id
,
934 const enum rfkill_type rfktype
,
936 int (*toggle_radio
)(void *, enum rfkill_state
),
937 int (*get_state
)(void *, enum rfkill_state
*))
940 enum rfkill_state initial_state
;
942 *rfk
= rfkill_allocate(&tpacpi_pdev
->dev
, rfktype
);
945 "failed to allocate memory for rfkill class\n");
950 (*rfk
)->get_state
= get_state
;
951 (*rfk
)->toggle_radio
= toggle_radio
;
953 if (!get_state(NULL
, &initial_state
))
954 (*rfk
)->state
= initial_state
;
956 res
= rfkill_register(*rfk
);
959 "failed to register %s rfkill switch: %d\n",
969 /*************************************************************************
970 * thinkpad-acpi driver attributes
973 /* interface_version --------------------------------------------------- */
974 static ssize_t
tpacpi_driver_interface_version_show(
975 struct device_driver
*drv
,
978 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
981 static DRIVER_ATTR(interface_version
, S_IRUGO
,
982 tpacpi_driver_interface_version_show
, NULL
);
984 /* debug_level --------------------------------------------------------- */
985 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
988 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
991 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
992 const char *buf
, size_t count
)
996 if (parse_strtoul(buf
, 0xffff, &t
))
1004 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1005 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
1007 /* version ------------------------------------------------------------- */
1008 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
1011 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
1012 TPACPI_DESC
, TPACPI_VERSION
);
1015 static DRIVER_ATTR(version
, S_IRUGO
,
1016 tpacpi_driver_version_show
, NULL
);
1018 /* --------------------------------------------------------------------- */
1020 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1022 static void tpacpi_send_radiosw_update(void);
1024 /* wlsw_emulstate ------------------------------------------------------ */
1025 static ssize_t
tpacpi_driver_wlsw_emulstate_show(struct device_driver
*drv
,
1028 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wlsw_emulstate
);
1031 static ssize_t
tpacpi_driver_wlsw_emulstate_store(struct device_driver
*drv
,
1032 const char *buf
, size_t count
)
1036 if (parse_strtoul(buf
, 1, &t
))
1039 if (tpacpi_wlsw_emulstate
!= t
) {
1040 tpacpi_wlsw_emulstate
= !!t
;
1041 tpacpi_send_radiosw_update();
1043 tpacpi_wlsw_emulstate
= !!t
;
1048 static DRIVER_ATTR(wlsw_emulstate
, S_IWUSR
| S_IRUGO
,
1049 tpacpi_driver_wlsw_emulstate_show
,
1050 tpacpi_driver_wlsw_emulstate_store
);
1052 /* bluetooth_emulstate ------------------------------------------------- */
1053 static ssize_t
tpacpi_driver_bluetooth_emulstate_show(
1054 struct device_driver
*drv
,
1057 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_bluetooth_emulstate
);
1060 static ssize_t
tpacpi_driver_bluetooth_emulstate_store(
1061 struct device_driver
*drv
,
1062 const char *buf
, size_t count
)
1066 if (parse_strtoul(buf
, 1, &t
))
1069 tpacpi_bluetooth_emulstate
= !!t
;
1074 static DRIVER_ATTR(bluetooth_emulstate
, S_IWUSR
| S_IRUGO
,
1075 tpacpi_driver_bluetooth_emulstate_show
,
1076 tpacpi_driver_bluetooth_emulstate_store
);
1078 /* wwan_emulstate ------------------------------------------------- */
1079 static ssize_t
tpacpi_driver_wwan_emulstate_show(
1080 struct device_driver
*drv
,
1083 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!tpacpi_wwan_emulstate
);
1086 static ssize_t
tpacpi_driver_wwan_emulstate_store(
1087 struct device_driver
*drv
,
1088 const char *buf
, size_t count
)
1092 if (parse_strtoul(buf
, 1, &t
))
1095 tpacpi_wwan_emulstate
= !!t
;
1100 static DRIVER_ATTR(wwan_emulstate
, S_IWUSR
| S_IRUGO
,
1101 tpacpi_driver_wwan_emulstate_show
,
1102 tpacpi_driver_wwan_emulstate_store
);
1106 /* --------------------------------------------------------------------- */
1108 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
1109 &driver_attr_debug_level
, &driver_attr_version
,
1110 &driver_attr_interface_version
,
1113 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
1119 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
1120 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
1124 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1125 if (!res
&& dbg_wlswemul
)
1126 res
= driver_create_file(drv
, &driver_attr_wlsw_emulstate
);
1127 if (!res
&& dbg_bluetoothemul
)
1128 res
= driver_create_file(drv
, &driver_attr_bluetooth_emulstate
);
1129 if (!res
&& dbg_wwanemul
)
1130 res
= driver_create_file(drv
, &driver_attr_wwan_emulstate
);
1136 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
1140 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
1141 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
1143 #ifdef THINKPAD_ACPI_DEBUGFACILITIES
1144 driver_remove_file(drv
, &driver_attr_wlsw_emulstate
);
1145 driver_remove_file(drv
, &driver_attr_bluetooth_emulstate
);
1146 driver_remove_file(drv
, &driver_attr_wwan_emulstate
);
1150 /****************************************************************************
1151 ****************************************************************************
1155 ****************************************************************************
1156 ****************************************************************************/
1158 /*************************************************************************
1159 * thinkpad-acpi init subdriver
1162 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
1164 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
1165 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
1167 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
1168 (thinkpad_id
.bios_version_str
) ?
1169 thinkpad_id
.bios_version_str
: "unknown",
1170 (thinkpad_id
.ec_version_str
) ?
1171 thinkpad_id
.ec_version_str
: "unknown");
1173 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
1174 printk(TPACPI_INFO
"%s %s, model %s\n",
1175 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
1176 "IBM" : ((thinkpad_id
.vendor
==
1177 PCI_VENDOR_ID_LENOVO
) ?
1178 "Lenovo" : "Unknown vendor"),
1179 thinkpad_id
.model_str
,
1180 (thinkpad_id
.nummodel_str
) ?
1181 thinkpad_id
.nummodel_str
: "unknown");
1186 static int thinkpad_acpi_driver_read(char *p
)
1190 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
1191 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
1196 static struct ibm_struct thinkpad_acpi_driver_data
= {
1198 .read
= thinkpad_acpi_driver_read
,
1201 /*************************************************************************
1205 enum { /* hot key scan codes (derived from ACPI DSDT) */
1206 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1207 TP_ACPI_HOTKEYSCAN_FNF2
,
1208 TP_ACPI_HOTKEYSCAN_FNF3
,
1209 TP_ACPI_HOTKEYSCAN_FNF4
,
1210 TP_ACPI_HOTKEYSCAN_FNF5
,
1211 TP_ACPI_HOTKEYSCAN_FNF6
,
1212 TP_ACPI_HOTKEYSCAN_FNF7
,
1213 TP_ACPI_HOTKEYSCAN_FNF8
,
1214 TP_ACPI_HOTKEYSCAN_FNF9
,
1215 TP_ACPI_HOTKEYSCAN_FNF10
,
1216 TP_ACPI_HOTKEYSCAN_FNF11
,
1217 TP_ACPI_HOTKEYSCAN_FNF12
,
1218 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1219 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1220 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1221 TP_ACPI_HOTKEYSCAN_FNHOME
,
1222 TP_ACPI_HOTKEYSCAN_FNEND
,
1223 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1224 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1225 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1226 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1227 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1228 TP_ACPI_HOTKEYSCAN_MUTE
,
1229 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1232 enum { /* Keys available through NVRAM polling */
1233 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1234 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1237 enum { /* Positions of some of the keys in hotkey masks */
1238 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1239 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1240 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1241 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1242 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1243 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1244 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1245 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1246 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1247 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1248 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1251 enum { /* NVRAM to ACPI HKEY group map */
1252 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1253 TP_ACPI_HKEY_ZOOM_MASK
|
1254 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1255 TP_ACPI_HKEY_HIBERNATE_MASK
,
1256 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1257 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1258 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1259 TP_ACPI_HKEY_VOLDWN_MASK
|
1260 TP_ACPI_HKEY_MUTE_MASK
,
1263 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1264 struct tp_nvram_state
{
1265 u16 thinkpad_toggle
:1;
1267 u16 display_toggle
:1;
1268 u16 thinklight_toggle
:1;
1269 u16 hibernate_toggle
:1;
1270 u16 displayexp_toggle
:1;
1271 u16 display_state
:1;
1272 u16 brightness_toggle
:1;
1273 u16 volume_toggle
:1;
1276 u8 brightness_level
;
1280 static struct task_struct
*tpacpi_hotkey_task
;
1281 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1282 static int hotkey_poll_freq
= 10; /* Hz */
1283 static struct mutex hotkey_thread_mutex
;
1284 static struct mutex hotkey_thread_data_mutex
;
1285 static unsigned int hotkey_config_change
;
1287 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1289 #define hotkey_source_mask 0U
1291 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1293 static struct mutex hotkey_mutex
;
1295 static enum { /* Reasons for waking up */
1296 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1297 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1298 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1299 } hotkey_wakeup_reason
;
1301 static int hotkey_autosleep_ack
;
1303 static int hotkey_orig_status
;
1304 static u32 hotkey_orig_mask
;
1305 static u32 hotkey_all_mask
;
1306 static u32 hotkey_reserved_mask
;
1307 static u32 hotkey_mask
;
1309 static unsigned int hotkey_report_mode
;
1311 static u16
*hotkey_keycode_map
;
1313 static struct attribute_set
*hotkey_dev_attributes
;
1315 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1316 #define HOTKEY_CONFIG_CRITICAL_START \
1318 mutex_lock(&hotkey_thread_data_mutex); \
1319 hotkey_config_change++; \
1321 #define HOTKEY_CONFIG_CRITICAL_END \
1322 mutex_unlock(&hotkey_thread_data_mutex);
1324 #define HOTKEY_CONFIG_CRITICAL_START
1325 #define HOTKEY_CONFIG_CRITICAL_END
1326 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1328 /* HKEY.MHKG() return bits */
1329 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1331 static int hotkey_get_wlsw(int *status
)
1333 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
1335 *status
= !!tpacpi_wlsw_emulstate
;
1339 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1344 static int hotkey_get_tablet_mode(int *status
)
1348 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
1351 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
1356 * Call with hotkey_mutex held
1358 static int hotkey_mask_get(void)
1362 if (tp_features
.hotkey_mask
) {
1363 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1366 hotkey_mask
= m
| (hotkey_source_mask
& hotkey_mask
);
1372 * Call with hotkey_mutex held
1374 static int hotkey_mask_set(u32 mask
)
1379 if (tp_features
.hotkey_mask
) {
1380 if (!tp_warned
.hotkey_mask_ff
&&
1381 (mask
== 0xffff || mask
== 0xffffff ||
1382 mask
== 0xffffffff)) {
1383 tp_warned
.hotkey_mask_ff
= 1;
1384 printk(TPACPI_NOTICE
1385 "setting the hotkey mask to 0x%08x is likely "
1386 "not the best way to go about it\n", mask
);
1387 printk(TPACPI_NOTICE
1388 "please consider using the driver defaults, "
1389 "and refer to up-to-date thinkpad-acpi "
1393 HOTKEY_CONFIG_CRITICAL_START
1394 for (i
= 0; i
< 32; i
++) {
1396 /* enable in firmware mask only keys not in NVRAM
1397 * mode, but enable the key in the cached hotkey_mask
1398 * regardless of mode, or the key will end up
1399 * disabled by hotkey_mask_get() */
1400 if (!acpi_evalf(hkey_handle
,
1401 NULL
, "MHKM", "vdd", i
+ 1,
1402 !!((mask
& ~hotkey_source_mask
) & m
))) {
1406 hotkey_mask
= (hotkey_mask
& ~m
) | (mask
& m
);
1409 HOTKEY_CONFIG_CRITICAL_END
1411 /* hotkey_mask_get must be called unconditionally below */
1412 if (!hotkey_mask_get() && !rc
&&
1413 (hotkey_mask
& ~hotkey_source_mask
) !=
1414 (mask
& ~hotkey_source_mask
)) {
1415 printk(TPACPI_NOTICE
1416 "requested hot key mask 0x%08x, but "
1417 "firmware forced it to 0x%08x\n",
1421 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1422 HOTKEY_CONFIG_CRITICAL_START
1423 hotkey_mask
= mask
& hotkey_source_mask
;
1424 HOTKEY_CONFIG_CRITICAL_END
1426 if (hotkey_mask
!= mask
) {
1427 printk(TPACPI_NOTICE
1428 "requested hot key mask 0x%08x, "
1429 "forced to 0x%08x (NVRAM poll mask is "
1430 "0x%08x): no firmware mask support\n",
1431 mask
, hotkey_mask
, hotkey_source_mask
);
1436 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1442 static int hotkey_status_get(int *status
)
1444 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1450 static int hotkey_status_set(int status
)
1452 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1458 static void tpacpi_input_send_tabletsw(void)
1462 if (tp_features
.hotkey_tablet
&&
1463 !hotkey_get_tablet_mode(&state
)) {
1464 mutex_lock(&tpacpi_inputdev_send_mutex
);
1466 input_report_switch(tpacpi_inputdev
,
1467 SW_TABLET_MODE
, !!state
);
1468 input_sync(tpacpi_inputdev
);
1470 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1474 static void tpacpi_input_send_key(unsigned int scancode
)
1476 unsigned int keycode
;
1478 keycode
= hotkey_keycode_map
[scancode
];
1480 if (keycode
!= KEY_RESERVED
) {
1481 mutex_lock(&tpacpi_inputdev_send_mutex
);
1483 input_report_key(tpacpi_inputdev
, keycode
, 1);
1484 if (keycode
== KEY_UNKNOWN
)
1485 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1487 input_sync(tpacpi_inputdev
);
1489 input_report_key(tpacpi_inputdev
, keycode
, 0);
1490 if (keycode
== KEY_UNKNOWN
)
1491 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1493 input_sync(tpacpi_inputdev
);
1495 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1499 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1500 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
1502 static void tpacpi_hotkey_send_key(unsigned int scancode
)
1504 tpacpi_input_send_key(scancode
);
1505 if (hotkey_report_mode
< 2) {
1506 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
1507 0x80, 0x1001 + scancode
);
1511 static void hotkey_read_nvram(struct tp_nvram_state
*n
, u32 m
)
1515 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
1516 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
1517 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
1518 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
1519 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
1520 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
1522 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
1523 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
1524 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
1526 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
1527 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
1528 n
->displayexp_toggle
=
1529 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
1531 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
1532 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
1533 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
1534 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
1535 n
->brightness_toggle
=
1536 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
1538 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
1539 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
1540 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
1541 >> TP_NVRAM_POS_LEVEL_VOLUME
;
1542 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
1543 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
1547 #define TPACPI_COMPARE_KEY(__scancode, __member) \
1549 if ((mask & (1 << __scancode)) && \
1550 oldn->__member != newn->__member) \
1551 tpacpi_hotkey_send_key(__scancode); \
1554 #define TPACPI_MAY_SEND_KEY(__scancode) \
1555 do { if (mask & (1 << __scancode)) \
1556 tpacpi_hotkey_send_key(__scancode); } while (0)
1558 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
1559 struct tp_nvram_state
*newn
,
1562 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
1563 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
1564 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
1565 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
1567 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
1569 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
1572 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
1573 if (oldn
->mute
!= newn
->mute
) {
1574 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1576 if (oldn
->volume_level
> newn
->volume_level
) {
1577 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1578 } else if (oldn
->volume_level
< newn
->volume_level
) {
1579 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1580 } else if (oldn
->mute
== newn
->mute
) {
1581 /* repeated key presses that didn't change state */
1583 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1584 } else if (newn
->volume_level
!= 0) {
1585 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1587 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1592 /* handle brightness */
1593 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
1594 if (oldn
->brightness_level
< newn
->brightness_level
) {
1595 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1596 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
1597 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1599 /* repeated key presses that didn't change state */
1600 if (newn
->brightness_level
!= 0) {
1601 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1603 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1609 #undef TPACPI_COMPARE_KEY
1610 #undef TPACPI_MAY_SEND_KEY
1612 static int hotkey_kthread(void *data
)
1614 struct tp_nvram_state s
[2];
1616 unsigned int si
, so
;
1618 unsigned int change_detector
, must_reset
;
1620 mutex_lock(&hotkey_thread_mutex
);
1622 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
1631 /* Initial state for compares */
1632 mutex_lock(&hotkey_thread_data_mutex
);
1633 change_detector
= hotkey_config_change
;
1634 mask
= hotkey_source_mask
& hotkey_mask
;
1635 mutex_unlock(&hotkey_thread_data_mutex
);
1636 hotkey_read_nvram(&s
[so
], mask
);
1638 while (!kthread_should_stop() && hotkey_poll_freq
) {
1640 t
= 1000/hotkey_poll_freq
;
1641 t
= msleep_interruptible(t
);
1642 if (unlikely(kthread_should_stop()))
1644 must_reset
= try_to_freeze();
1645 if (t
> 0 && !must_reset
)
1648 mutex_lock(&hotkey_thread_data_mutex
);
1649 if (must_reset
|| hotkey_config_change
!= change_detector
) {
1650 /* forget old state on thaw or config change */
1653 change_detector
= hotkey_config_change
;
1655 mask
= hotkey_source_mask
& hotkey_mask
;
1656 mutex_unlock(&hotkey_thread_data_mutex
);
1659 hotkey_read_nvram(&s
[si
], mask
);
1660 if (likely(si
!= so
)) {
1661 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
1671 mutex_unlock(&hotkey_thread_mutex
);
1675 static void hotkey_poll_stop_sync(void)
1677 if (tpacpi_hotkey_task
) {
1678 if (frozen(tpacpi_hotkey_task
) ||
1679 freezing(tpacpi_hotkey_task
))
1680 thaw_process(tpacpi_hotkey_task
);
1682 kthread_stop(tpacpi_hotkey_task
);
1683 tpacpi_hotkey_task
= NULL
;
1684 mutex_lock(&hotkey_thread_mutex
);
1685 /* at this point, the thread did exit */
1686 mutex_unlock(&hotkey_thread_mutex
);
1690 /* call with hotkey_mutex held */
1691 static void hotkey_poll_setup(int may_warn
)
1693 if ((hotkey_source_mask
& hotkey_mask
) != 0 &&
1694 hotkey_poll_freq
> 0 &&
1695 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1696 if (!tpacpi_hotkey_task
) {
1697 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1698 NULL
, TPACPI_NVRAM_KTHREAD_NAME
);
1699 if (IS_ERR(tpacpi_hotkey_task
)) {
1700 tpacpi_hotkey_task
= NULL
;
1702 "could not create kernel thread "
1703 "for hotkey polling\n");
1707 hotkey_poll_stop_sync();
1709 hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1710 printk(TPACPI_NOTICE
1711 "hot keys 0x%08x require polling, "
1712 "which is currently disabled\n",
1713 hotkey_source_mask
);
1718 static void hotkey_poll_setup_safe(int may_warn
)
1720 mutex_lock(&hotkey_mutex
);
1721 hotkey_poll_setup(may_warn
);
1722 mutex_unlock(&hotkey_mutex
);
1725 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1727 static void hotkey_poll_setup_safe(int __unused
)
1731 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1733 static int hotkey_inputdev_open(struct input_dev
*dev
)
1735 switch (tpacpi_lifecycle
) {
1736 case TPACPI_LIFE_INIT
:
1738 * hotkey_init will call hotkey_poll_setup_safe
1739 * at the appropriate moment
1742 case TPACPI_LIFE_EXITING
:
1744 case TPACPI_LIFE_RUNNING
:
1745 hotkey_poll_setup_safe(0);
1749 /* Should only happen if tpacpi_lifecycle is corrupt */
1754 static void hotkey_inputdev_close(struct input_dev
*dev
)
1756 /* disable hotkey polling when possible */
1757 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
)
1758 hotkey_poll_setup_safe(0);
1761 /* sysfs hotkey enable ------------------------------------------------- */
1762 static ssize_t
hotkey_enable_show(struct device
*dev
,
1763 struct device_attribute
*attr
,
1768 res
= hotkey_status_get(&status
);
1772 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1775 static ssize_t
hotkey_enable_store(struct device
*dev
,
1776 struct device_attribute
*attr
,
1777 const char *buf
, size_t count
)
1782 if (parse_strtoul(buf
, 1, &t
))
1785 res
= hotkey_status_set(t
);
1787 return (res
) ? res
: count
;
1790 static struct device_attribute dev_attr_hotkey_enable
=
1791 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
1792 hotkey_enable_show
, hotkey_enable_store
);
1794 /* sysfs hotkey mask --------------------------------------------------- */
1795 static ssize_t
hotkey_mask_show(struct device
*dev
,
1796 struct device_attribute
*attr
,
1801 if (mutex_lock_interruptible(&hotkey_mutex
))
1802 return -ERESTARTSYS
;
1803 res
= hotkey_mask_get();
1804 mutex_unlock(&hotkey_mutex
);
1807 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
1810 static ssize_t
hotkey_mask_store(struct device
*dev
,
1811 struct device_attribute
*attr
,
1812 const char *buf
, size_t count
)
1817 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
1820 if (mutex_lock_interruptible(&hotkey_mutex
))
1821 return -ERESTARTSYS
;
1823 res
= hotkey_mask_set(t
);
1825 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1826 hotkey_poll_setup(1);
1829 mutex_unlock(&hotkey_mutex
);
1831 return (res
) ? res
: count
;
1834 static struct device_attribute dev_attr_hotkey_mask
=
1835 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
1836 hotkey_mask_show
, hotkey_mask_store
);
1838 /* sysfs hotkey bios_enabled ------------------------------------------- */
1839 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
1840 struct device_attribute
*attr
,
1843 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
1846 static struct device_attribute dev_attr_hotkey_bios_enabled
=
1847 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
1849 /* sysfs hotkey bios_mask ---------------------------------------------- */
1850 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
1851 struct device_attribute
*attr
,
1854 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
1857 static struct device_attribute dev_attr_hotkey_bios_mask
=
1858 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
1860 /* sysfs hotkey all_mask ----------------------------------------------- */
1861 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
1862 struct device_attribute
*attr
,
1865 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1866 hotkey_all_mask
| hotkey_source_mask
);
1869 static struct device_attribute dev_attr_hotkey_all_mask
=
1870 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
1872 /* sysfs hotkey recommended_mask --------------------------------------- */
1873 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
1874 struct device_attribute
*attr
,
1877 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1878 (hotkey_all_mask
| hotkey_source_mask
)
1879 & ~hotkey_reserved_mask
);
1882 static struct device_attribute dev_attr_hotkey_recommended_mask
=
1883 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
1884 hotkey_recommended_mask_show
, NULL
);
1886 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1888 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
1889 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
1890 struct device_attribute
*attr
,
1893 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
1896 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
1897 struct device_attribute
*attr
,
1898 const char *buf
, size_t count
)
1902 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
1903 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
1906 if (mutex_lock_interruptible(&hotkey_mutex
))
1907 return -ERESTARTSYS
;
1909 HOTKEY_CONFIG_CRITICAL_START
1910 hotkey_source_mask
= t
;
1911 HOTKEY_CONFIG_CRITICAL_END
1913 hotkey_poll_setup(1);
1915 mutex_unlock(&hotkey_mutex
);
1920 static struct device_attribute dev_attr_hotkey_source_mask
=
1921 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
1922 hotkey_source_mask_show
, hotkey_source_mask_store
);
1924 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
1925 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
1926 struct device_attribute
*attr
,
1929 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
1932 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
1933 struct device_attribute
*attr
,
1934 const char *buf
, size_t count
)
1938 if (parse_strtoul(buf
, 25, &t
))
1941 if (mutex_lock_interruptible(&hotkey_mutex
))
1942 return -ERESTARTSYS
;
1944 hotkey_poll_freq
= t
;
1946 hotkey_poll_setup(1);
1947 mutex_unlock(&hotkey_mutex
);
1952 static struct device_attribute dev_attr_hotkey_poll_freq
=
1953 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
1954 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
1956 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1958 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
1959 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
1960 struct device_attribute
*attr
,
1964 res
= hotkey_get_wlsw(&s
);
1968 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1971 static struct device_attribute dev_attr_hotkey_radio_sw
=
1972 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
1974 static void hotkey_radio_sw_notify_change(void)
1976 if (tp_features
.hotkey_wlsw
)
1977 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
1981 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
1982 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
1983 struct device_attribute
*attr
,
1987 res
= hotkey_get_tablet_mode(&s
);
1991 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1994 static struct device_attribute dev_attr_hotkey_tablet_mode
=
1995 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
1997 static void hotkey_tablet_mode_notify_change(void)
1999 if (tp_features
.hotkey_tablet
)
2000 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2001 "hotkey_tablet_mode");
2004 /* sysfs hotkey report_mode -------------------------------------------- */
2005 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
2006 struct device_attribute
*attr
,
2009 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2010 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
2013 static struct device_attribute dev_attr_hotkey_report_mode
=
2014 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
2016 /* sysfs wakeup reason (pollable) -------------------------------------- */
2017 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
2018 struct device_attribute
*attr
,
2021 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
2024 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
2025 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
2027 static void hotkey_wakeup_reason_notify_change(void)
2029 if (tp_features
.hotkey_mask
)
2030 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2034 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2035 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
2036 struct device_attribute
*attr
,
2039 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
2042 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
2043 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
2044 hotkey_wakeup_hotunplug_complete_show
, NULL
);
2046 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
2048 if (tp_features
.hotkey_mask
)
2049 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
2050 "wakeup_hotunplug_complete");
2053 /* --------------------------------------------------------------------- */
2055 static struct attribute
*hotkey_attributes
[] __initdata
= {
2056 &dev_attr_hotkey_enable
.attr
,
2057 &dev_attr_hotkey_bios_enabled
.attr
,
2058 &dev_attr_hotkey_report_mode
.attr
,
2059 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2060 &dev_attr_hotkey_mask
.attr
,
2061 &dev_attr_hotkey_all_mask
.attr
,
2062 &dev_attr_hotkey_recommended_mask
.attr
,
2063 &dev_attr_hotkey_source_mask
.attr
,
2064 &dev_attr_hotkey_poll_freq
.attr
,
2068 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
2069 &dev_attr_hotkey_bios_mask
.attr
,
2070 #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2071 &dev_attr_hotkey_mask
.attr
,
2072 &dev_attr_hotkey_all_mask
.attr
,
2073 &dev_attr_hotkey_recommended_mask
.attr
,
2075 &dev_attr_hotkey_wakeup_reason
.attr
,
2076 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
2079 static void bluetooth_update_rfk(void);
2080 static void wan_update_rfk(void);
2081 static void tpacpi_send_radiosw_update(void)
2085 /* Sync these BEFORE sending any rfkill events */
2086 if (tp_features
.bluetooth
)
2087 bluetooth_update_rfk();
2088 if (tp_features
.wan
)
2091 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
2092 mutex_lock(&tpacpi_inputdev_send_mutex
);
2094 input_report_switch(tpacpi_inputdev
,
2095 SW_RFKILL_ALL
, !!wlsw
);
2096 input_sync(tpacpi_inputdev
);
2098 mutex_unlock(&tpacpi_inputdev_send_mutex
);
2100 hotkey_radio_sw_notify_change();
2103 static void hotkey_exit(void)
2105 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2106 hotkey_poll_stop_sync();
2109 if (hotkey_dev_attributes
)
2110 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2112 kfree(hotkey_keycode_map
);
2114 if (tp_features
.hotkey
) {
2115 dbg_printk(TPACPI_DBG_EXIT
,
2116 "restoring original hot key mask\n");
2117 /* no short-circuit boolean operator below! */
2118 if ((hotkey_mask_set(hotkey_orig_mask
) |
2119 hotkey_status_set(hotkey_orig_status
)) != 0)
2121 "failed to restore hot key mask "
2122 "to BIOS defaults\n");
2126 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
2128 /* Requirements for changing the default keymaps:
2130 * 1. Many of the keys are mapped to KEY_RESERVED for very
2131 * good reasons. Do not change them unless you have deep
2132 * knowledge on the IBM and Lenovo ThinkPad firmware for
2133 * the various ThinkPad models. The driver behaves
2134 * differently for KEY_RESERVED: such keys have their
2135 * hot key mask *unset* in mask_recommended, and also
2136 * in the initial hot key mask programmed into the
2137 * firmware at driver load time, which means the firm-
2138 * ware may react very differently if you change them to
2141 * 2. You must be subscribed to the linux-thinkpad and
2142 * ibm-acpi-devel mailing lists, and you should read the
2143 * list archives since 2007 if you want to change the
2144 * keymaps. This requirement exists so that you will
2145 * know the past history of problems with the thinkpad-
2146 * acpi driver keymaps, and also that you will be
2147 * listening to any bug reports;
2149 * 3. Do not send thinkpad-acpi specific patches directly to
2150 * for merging, *ever*. Send them to the linux-acpi
2151 * mailinglist for comments. Merging is to be done only
2152 * through acpi-test and the ACPI maintainer.
2154 * If the above is too much to ask, don't change the keymap.
2155 * Ask the thinkpad-acpi maintainer to do it, instead.
2157 static u16 ibm_keycode_map
[] __initdata
= {
2158 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2159 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
2160 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2161 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2163 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2164 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2165 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2166 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2168 /* brightness: firmware always reacts to them, unless
2169 * X.org did some tricks in the radeon BIOS scratch
2170 * registers of *some* models */
2171 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2172 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2174 /* Thinklight: firmware always react to it */
2175 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2177 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2178 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2180 /* Volume: firmware always react to it and reprograms
2181 * the built-in *extra* mixer. Never map it to control
2182 * another mixer by default. */
2183 KEY_RESERVED
, /* 0x14: VOLUME UP */
2184 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2185 KEY_RESERVED
, /* 0x16: MUTE */
2187 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2189 /* (assignments unknown, please report if found) */
2190 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2191 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2193 static u16 lenovo_keycode_map
[] __initdata
= {
2194 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
2195 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
2196 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
2197 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
2199 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
2200 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
2201 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
2202 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
2204 /* These either have to go through ACPI video, or
2205 * act like in the IBM ThinkPads, so don't ever
2206 * enable them by default */
2207 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
2208 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
2210 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
2212 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
2213 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
2215 /* Volume: z60/z61, T60 (BIOS version?): firmware always
2216 * react to it and reprograms the built-in *extra* mixer.
2217 * Never map it to control another mixer by default.
2219 * T60?, T61, R60?, R61: firmware and EC tries to send
2220 * these over the regular keyboard, so these are no-ops,
2221 * but there are still weird bugs re. MUTE, so do not
2222 * change unless you get test reports from all Lenovo
2223 * models. May cause the BIOS to interfere with the
2226 KEY_RESERVED
, /* 0x14: VOLUME UP */
2227 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2228 KEY_RESERVED
, /* 0x16: MUTE */
2230 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2232 /* (assignments unknown, please report if found) */
2233 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2234 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2237 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2238 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2239 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2245 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
2247 BUG_ON(!tpacpi_inputdev
);
2248 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
2249 tpacpi_inputdev
->close
!= NULL
);
2251 TPACPI_ACPIHANDLE_INIT(hkey
);
2252 mutex_init(&hotkey_mutex
);
2254 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2255 mutex_init(&hotkey_thread_mutex
);
2256 mutex_init(&hotkey_thread_data_mutex
);
2259 /* hotkey not supported on 570 */
2260 tp_features
.hotkey
= hkey_handle
!= NULL
;
2262 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
2263 str_supported(tp_features
.hotkey
));
2265 if (!tp_features
.hotkey
)
2268 tpacpi_disable_brightness_delay();
2270 hotkey_dev_attributes
= create_attr_set(13, NULL
);
2271 if (!hotkey_dev_attributes
)
2273 res
= add_many_to_attr_set(hotkey_dev_attributes
,
2275 ARRAY_SIZE(hotkey_attributes
));
2279 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2280 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2281 for HKEY interface version 0x100 */
2282 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
2283 if ((hkeyv
>> 8) != 1) {
2284 printk(TPACPI_ERR
"unknown version of the "
2285 "HKEY interface: 0x%x\n", hkeyv
);
2286 printk(TPACPI_ERR
"please report this to %s\n",
2290 * MHKV 0x100 in A31, R40, R40e,
2291 * T4x, X31, and later
2293 tp_features
.hotkey_mask
= 1;
2297 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
2298 str_supported(tp_features
.hotkey_mask
));
2300 if (tp_features
.hotkey_mask
) {
2301 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
2304 "missing MHKA handler, "
2305 "please report this to %s\n",
2307 /* FN+F12, FN+F4, FN+F3 */
2308 hotkey_all_mask
= 0x080cU
;
2312 /* hotkey_source_mask *must* be zero for
2313 * the first hotkey_mask_get */
2314 res
= hotkey_status_get(&hotkey_orig_status
);
2318 if (tp_features
.hotkey_mask
) {
2319 res
= hotkey_mask_get();
2323 hotkey_orig_mask
= hotkey_mask
;
2324 res
= add_many_to_attr_set(
2325 hotkey_dev_attributes
,
2326 hotkey_mask_attributes
,
2327 ARRAY_SIZE(hotkey_mask_attributes
));
2332 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2333 if (tp_features
.hotkey_mask
) {
2334 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
2337 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
;
2340 vdbg_printk(TPACPI_DBG_INIT
,
2341 "hotkey source mask 0x%08x, polling freq %d\n",
2342 hotkey_source_mask
, hotkey_poll_freq
);
2345 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2347 tp_features
.hotkey_wlsw
= 1;
2349 "radio switch emulation enabled\n");
2352 /* Not all thinkpads have a hardware radio switch */
2353 if (acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
2354 tp_features
.hotkey_wlsw
= 1;
2356 "radio switch found; radios are %s\n",
2357 enabled(status
, 0));
2359 if (tp_features
.hotkey_wlsw
)
2360 res
= add_to_attr_set(hotkey_dev_attributes
,
2361 &dev_attr_hotkey_radio_sw
.attr
);
2363 /* For X41t, X60t, X61t Tablets... */
2364 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
2365 tp_features
.hotkey_tablet
= 1;
2367 "possible tablet mode switch found; "
2368 "ThinkPad in %s mode\n",
2369 (status
& TP_HOTKEY_TABLET_MASK
)?
2370 "tablet" : "laptop");
2371 res
= add_to_attr_set(hotkey_dev_attributes
,
2372 &dev_attr_hotkey_tablet_mode
.attr
);
2376 res
= register_attr_set_with_sysfs(
2377 hotkey_dev_attributes
,
2378 &tpacpi_pdev
->dev
.kobj
);
2382 /* Set up key map */
2384 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
2386 if (!hotkey_keycode_map
) {
2388 "failed to allocate memory for key map\n");
2393 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
2394 dbg_printk(TPACPI_DBG_INIT
,
2395 "using Lenovo default hot key map\n");
2396 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
2397 TPACPI_HOTKEY_MAP_SIZE
);
2399 dbg_printk(TPACPI_DBG_INIT
,
2400 "using IBM default hot key map\n");
2401 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
2402 TPACPI_HOTKEY_MAP_SIZE
);
2405 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
2406 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
2407 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
2408 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
2409 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
2410 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
2411 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
2412 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
2413 set_bit(hotkey_keycode_map
[i
],
2414 tpacpi_inputdev
->keybit
);
2416 if (i
< sizeof(hotkey_reserved_mask
)*8)
2417 hotkey_reserved_mask
|= 1 << i
;
2421 if (tp_features
.hotkey_wlsw
) {
2422 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2423 set_bit(SW_RFKILL_ALL
, tpacpi_inputdev
->swbit
);
2425 if (tp_features
.hotkey_tablet
) {
2426 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2427 set_bit(SW_TABLET_MODE
, tpacpi_inputdev
->swbit
);
2430 /* Do not issue duplicate brightness change events to
2432 if (!tp_features
.bright_acpimode
)
2433 /* update bright_acpimode... */
2434 tpacpi_check_std_acpi_brightness_support();
2436 if (tp_features
.bright_acpimode
) {
2438 "This ThinkPad has standard ACPI backlight "
2439 "brightness control, supported by the ACPI "
2441 printk(TPACPI_NOTICE
2442 "Disabling thinkpad-acpi brightness events "
2445 /* The hotkey_reserved_mask change below is not
2446 * necessary while the keys are at KEY_RESERVED in the
2447 * default map, but better safe than sorry, leave it
2448 * here as a marker of what we have to do, especially
2449 * when we finally become able to set this at runtime
2450 * on response to X.org requests */
2451 hotkey_reserved_mask
|=
2452 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
2453 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
2456 dbg_printk(TPACPI_DBG_INIT
, "enabling hot key handling\n");
2457 res
= hotkey_status_set(1);
2462 res
= hotkey_mask_set(((hotkey_all_mask
| hotkey_source_mask
)
2463 & ~hotkey_reserved_mask
)
2464 | hotkey_orig_mask
);
2465 if (res
< 0 && res
!= -ENXIO
) {
2470 dbg_printk(TPACPI_DBG_INIT
,
2471 "legacy hot key reporting over procfs %s\n",
2472 (hotkey_report_mode
< 2) ?
2473 "enabled" : "disabled");
2475 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
2476 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
2478 hotkey_poll_setup_safe(1);
2479 tpacpi_send_radiosw_update();
2480 tpacpi_input_send_tabletsw();
2485 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2486 hotkey_dev_attributes
= NULL
;
2488 return (res
< 0)? res
: 1;
2491 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
2494 unsigned int scancode
;
2499 if (event
!= 0x80) {
2501 "unknown HKEY notification event %d\n", event
);
2502 /* forward it to userspace, maybe it knows how to handle it */
2503 acpi_bus_generate_netlink_event(
2504 ibm
->acpi
->device
->pnp
.device_class
,
2505 dev_name(&ibm
->acpi
->device
->dev
),
2511 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
2512 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
2525 switch (hkey
>> 12) {
2527 /* 0x1000-0x1FFF: key presses */
2528 scancode
= hkey
& 0xfff;
2529 if (scancode
> 0 && scancode
< 0x21) {
2531 if (!(hotkey_source_mask
& (1 << scancode
))) {
2532 tpacpi_input_send_key(scancode
);
2544 case 0x2304: /* suspend, undock */
2545 case 0x2404: /* hibernation, undock */
2546 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
2549 case 0x2305: /* suspend, bay eject */
2550 case 0x2405: /* hibernation, bay eject */
2551 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
2557 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
2559 "woke up due to a hot-unplug "
2561 hotkey_wakeup_reason_notify_change();
2565 /* bay-related wakeups */
2566 if (hkey
== 0x3003) {
2567 hotkey_autosleep_ack
= 1;
2570 hotkey_wakeup_hotunplug_complete_notify_change();
2576 /* dock-related wakeups */
2577 if (hkey
== 0x4003) {
2578 hotkey_autosleep_ack
= 1;
2581 hotkey_wakeup_hotunplug_complete_notify_change();
2587 /* 0x5000-0x5FFF: human interface helpers */
2589 case 0x5010: /* Lenovo new BIOS: brightness changed */
2590 case 0x500b: /* X61t: tablet pen inserted into bay */
2591 case 0x500c: /* X61t: tablet pen removed from bay */
2593 case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
2594 case 0x500a: /* X41t-X61t: swivel down (normal mode) */
2595 tpacpi_input_send_tabletsw();
2596 hotkey_tablet_mode_notify_change();
2601 /* LID switch events. Do not propagate */
2609 /* 0x7000-0x7FFF: misc */
2610 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
2611 tpacpi_send_radiosw_update();
2615 /* fallthrough to default */
2620 printk(TPACPI_NOTICE
2621 "unhandled HKEY event 0x%04x\n", hkey
);
2625 if (!ignore_acpi_ev
&&
2626 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
2627 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
2631 /* netlink events */
2632 if (!ignore_acpi_ev
&& send_acpi_ev
) {
2633 acpi_bus_generate_netlink_event(
2634 ibm
->acpi
->device
->pnp
.device_class
,
2635 dev_name(&ibm
->acpi
->device
->dev
),
2641 static void hotkey_suspend(pm_message_t state
)
2643 /* Do these on suspend, we get the events on early resume! */
2644 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
2645 hotkey_autosleep_ack
= 0;
2648 static void hotkey_resume(void)
2650 tpacpi_disable_brightness_delay();
2652 if (hotkey_mask_get())
2654 "error while trying to read hot key mask "
2656 tpacpi_send_radiosw_update();
2657 hotkey_tablet_mode_notify_change();
2658 hotkey_wakeup_reason_notify_change();
2659 hotkey_wakeup_hotunplug_complete_notify_change();
2660 hotkey_poll_setup_safe(0);
2663 /* procfs -------------------------------------------------------------- */
2664 static int hotkey_read(char *p
)
2669 if (!tp_features
.hotkey
) {
2670 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2674 if (mutex_lock_interruptible(&hotkey_mutex
))
2675 return -ERESTARTSYS
;
2676 res
= hotkey_status_get(&status
);
2678 res
= hotkey_mask_get();
2679 mutex_unlock(&hotkey_mutex
);
2683 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
2684 if (tp_features
.hotkey_mask
) {
2685 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
2686 len
+= sprintf(p
+ len
,
2687 "commands:\tenable, disable, reset, <mask>\n");
2689 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
2690 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
2696 static int hotkey_write(char *buf
)
2702 if (!tp_features
.hotkey
)
2705 if (mutex_lock_interruptible(&hotkey_mutex
))
2706 return -ERESTARTSYS
;
2712 while ((cmd
= next_cmd(&buf
))) {
2713 if (strlencmp(cmd
, "enable") == 0) {
2715 } else if (strlencmp(cmd
, "disable") == 0) {
2717 } else if (strlencmp(cmd
, "reset") == 0) {
2718 status
= hotkey_orig_status
;
2719 mask
= hotkey_orig_mask
;
2720 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
2722 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
2730 res
= hotkey_status_set(status
);
2732 if (!res
&& mask
!= hotkey_mask
)
2733 res
= hotkey_mask_set(mask
);
2736 mutex_unlock(&hotkey_mutex
);
2740 static const struct acpi_device_id ibm_htk_device_ids
[] = {
2741 {TPACPI_ACPI_HKEY_HID
, 0},
2745 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
2746 .hid
= ibm_htk_device_ids
,
2747 .notify
= hotkey_notify
,
2748 .handle
= &hkey_handle
,
2749 .type
= ACPI_DEVICE_NOTIFY
,
2752 static struct ibm_struct hotkey_driver_data
= {
2754 .read
= hotkey_read
,
2755 .write
= hotkey_write
,
2756 .exit
= hotkey_exit
,
2757 .resume
= hotkey_resume
,
2758 .suspend
= hotkey_suspend
,
2759 .acpi
= &ibm_hotkey_acpidriver
,
2762 /*************************************************************************
2763 * Bluetooth subdriver
2767 /* ACPI GBDC/SBDC bits */
2768 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
2769 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
2770 TP_ACPI_BLUETOOTH_UNK
= 0x04, /* unknown function */
2773 static struct rfkill
*tpacpi_bluetooth_rfkill
;
2775 static int bluetooth_get_radiosw(void)
2779 if (!tp_features
.bluetooth
)
2782 /* WLSW overrides bluetooth in firmware/hardware, reflect that */
2783 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
2784 return RFKILL_STATE_HARD_BLOCKED
;
2786 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2787 if (dbg_bluetoothemul
)
2788 return (tpacpi_bluetooth_emulstate
) ?
2789 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
2792 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2795 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0) ?
2796 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
2799 static void bluetooth_update_rfk(void)
2803 if (!tpacpi_bluetooth_rfkill
)
2806 status
= bluetooth_get_radiosw();
2809 rfkill_force_state(tpacpi_bluetooth_rfkill
, status
);
2812 static int bluetooth_set_radiosw(int radio_on
, int update_rfk
)
2816 if (!tp_features
.bluetooth
)
2819 /* WLSW overrides bluetooth in firmware/hardware, but there is no
2820 * reason to risk weird behaviour. */
2821 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
2825 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2826 if (dbg_bluetoothemul
) {
2827 tpacpi_bluetooth_emulstate
= !!radio_on
;
2829 bluetooth_update_rfk();
2834 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2837 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
2839 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
2840 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
2844 bluetooth_update_rfk();
2849 /* sysfs bluetooth enable ---------------------------------------------- */
2850 static ssize_t
bluetooth_enable_show(struct device
*dev
,
2851 struct device_attribute
*attr
,
2856 status
= bluetooth_get_radiosw();
2860 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2861 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
2864 static ssize_t
bluetooth_enable_store(struct device
*dev
,
2865 struct device_attribute
*attr
,
2866 const char *buf
, size_t count
)
2871 if (parse_strtoul(buf
, 1, &t
))
2874 res
= bluetooth_set_radiosw(t
, 1);
2876 return (res
) ? res
: count
;
2879 static struct device_attribute dev_attr_bluetooth_enable
=
2880 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
2881 bluetooth_enable_show
, bluetooth_enable_store
);
2883 /* --------------------------------------------------------------------- */
2885 static struct attribute
*bluetooth_attributes
[] = {
2886 &dev_attr_bluetooth_enable
.attr
,
2890 static const struct attribute_group bluetooth_attr_group
= {
2891 .attrs
= bluetooth_attributes
,
2894 static int tpacpi_bluetooth_rfk_get(void *data
, enum rfkill_state
*state
)
2896 int bts
= bluetooth_get_radiosw();
2905 static int tpacpi_bluetooth_rfk_set(void *data
, enum rfkill_state state
)
2907 return bluetooth_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
2910 static void bluetooth_exit(void)
2912 if (tpacpi_bluetooth_rfkill
)
2913 rfkill_unregister(tpacpi_bluetooth_rfkill
);
2915 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2916 &bluetooth_attr_group
);
2919 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
2924 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
2926 TPACPI_ACPIHANDLE_INIT(hkey
);
2928 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2929 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
2930 tp_features
.bluetooth
= hkey_handle
&&
2931 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
2933 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
2934 str_supported(tp_features
.bluetooth
),
2937 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
2938 if (dbg_bluetoothemul
) {
2939 tp_features
.bluetooth
= 1;
2941 "bluetooth switch emulation enabled\n");
2944 if (tp_features
.bluetooth
&&
2945 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
2946 /* no bluetooth hardware present in system */
2947 tp_features
.bluetooth
= 0;
2948 dbg_printk(TPACPI_DBG_INIT
,
2949 "bluetooth hardware not installed\n");
2952 if (!tp_features
.bluetooth
)
2955 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2956 &bluetooth_attr_group
);
2960 res
= tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID
,
2961 &tpacpi_bluetooth_rfkill
,
2962 RFKILL_TYPE_BLUETOOTH
,
2963 "tpacpi_bluetooth_sw",
2964 tpacpi_bluetooth_rfk_set
,
2965 tpacpi_bluetooth_rfk_get
);
2974 /* procfs -------------------------------------------------------------- */
2975 static int bluetooth_read(char *p
)
2978 int status
= bluetooth_get_radiosw();
2980 if (!tp_features
.bluetooth
)
2981 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2983 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2984 (status
== RFKILL_STATE_UNBLOCKED
) ?
2985 "enabled" : "disabled");
2986 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2992 static int bluetooth_write(char *buf
)
2996 if (!tp_features
.bluetooth
)
2999 while ((cmd
= next_cmd(&buf
))) {
3000 if (strlencmp(cmd
, "enable") == 0) {
3001 bluetooth_set_radiosw(1, 1);
3002 } else if (strlencmp(cmd
, "disable") == 0) {
3003 bluetooth_set_radiosw(0, 1);
3011 static struct ibm_struct bluetooth_driver_data
= {
3012 .name
= "bluetooth",
3013 .read
= bluetooth_read
,
3014 .write
= bluetooth_write
,
3015 .exit
= bluetooth_exit
,
3018 /*************************************************************************
3023 /* ACPI GWAN/SWAN bits */
3024 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
3025 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
3026 TP_ACPI_WANCARD_UNK
= 0x04, /* unknown function */
3029 static struct rfkill
*tpacpi_wan_rfkill
;
3031 static int wan_get_radiosw(void)
3035 if (!tp_features
.wan
)
3038 /* WLSW overrides WWAN in firmware/hardware, reflect that */
3039 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
)
3040 return RFKILL_STATE_HARD_BLOCKED
;
3042 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3044 return (tpacpi_wwan_emulstate
) ?
3045 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3048 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
3051 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0) ?
3052 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
;
3055 static void wan_update_rfk(void)
3059 if (!tpacpi_wan_rfkill
)
3062 status
= wan_get_radiosw();
3065 rfkill_force_state(tpacpi_wan_rfkill
, status
);
3068 static int wan_set_radiosw(int radio_on
, int update_rfk
)
3072 if (!tp_features
.wan
)
3075 /* WLSW overrides bluetooth in firmware/hardware, but there is no
3076 * reason to risk weird behaviour. */
3077 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&status
) && !status
3081 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3083 tpacpi_wwan_emulstate
= !!radio_on
;
3090 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
3093 status
|= TP_ACPI_WANCARD_RADIOSSW
;
3095 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
3096 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
3105 /* sysfs wan enable ---------------------------------------------------- */
3106 static ssize_t
wan_enable_show(struct device
*dev
,
3107 struct device_attribute
*attr
,
3112 status
= wan_get_radiosw();
3116 return snprintf(buf
, PAGE_SIZE
, "%d\n",
3117 (status
== RFKILL_STATE_UNBLOCKED
) ? 1 : 0);
3120 static ssize_t
wan_enable_store(struct device
*dev
,
3121 struct device_attribute
*attr
,
3122 const char *buf
, size_t count
)
3127 if (parse_strtoul(buf
, 1, &t
))
3130 res
= wan_set_radiosw(t
, 1);
3132 return (res
) ? res
: count
;
3135 static struct device_attribute dev_attr_wan_enable
=
3136 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
3137 wan_enable_show
, wan_enable_store
);
3139 /* --------------------------------------------------------------------- */
3141 static struct attribute
*wan_attributes
[] = {
3142 &dev_attr_wan_enable
.attr
,
3146 static const struct attribute_group wan_attr_group
= {
3147 .attrs
= wan_attributes
,
3150 static int tpacpi_wan_rfk_get(void *data
, enum rfkill_state
*state
)
3152 int wans
= wan_get_radiosw();
3161 static int tpacpi_wan_rfk_set(void *data
, enum rfkill_state state
)
3163 return wan_set_radiosw((state
== RFKILL_STATE_UNBLOCKED
), 0);
3166 static void wan_exit(void)
3168 if (tpacpi_wan_rfkill
)
3169 rfkill_unregister(tpacpi_wan_rfkill
);
3171 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3175 static int __init
wan_init(struct ibm_init_struct
*iibm
)
3180 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
3182 TPACPI_ACPIHANDLE_INIT(hkey
);
3184 tp_features
.wan
= hkey_handle
&&
3185 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
3187 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
3188 str_supported(tp_features
.wan
),
3191 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
3193 tp_features
.wan
= 1;
3195 "wwan switch emulation enabled\n");
3198 if (tp_features
.wan
&&
3199 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
3200 /* no wan hardware present in system */
3201 tp_features
.wan
= 0;
3202 dbg_printk(TPACPI_DBG_INIT
,
3203 "wan hardware not installed\n");
3206 if (!tp_features
.wan
)
3209 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3214 res
= tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID
,
3219 tpacpi_wan_rfk_get
);
3228 /* procfs -------------------------------------------------------------- */
3229 static int wan_read(char *p
)
3232 int status
= wan_get_radiosw();
3234 if (!tp_features
.wan
)
3235 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3237 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3238 (status
== RFKILL_STATE_UNBLOCKED
) ?
3239 "enabled" : "disabled");
3240 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
3246 static int wan_write(char *buf
)
3250 if (!tp_features
.wan
)
3253 while ((cmd
= next_cmd(&buf
))) {
3254 if (strlencmp(cmd
, "enable") == 0) {
3255 wan_set_radiosw(1, 1);
3256 } else if (strlencmp(cmd
, "disable") == 0) {
3257 wan_set_radiosw(0, 1);
3265 static struct ibm_struct wan_driver_data
= {
3272 /*************************************************************************
3276 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
3278 enum video_access_mode
{
3279 TPACPI_VIDEO_NONE
= 0,
3280 TPACPI_VIDEO_570
, /* 570 */
3281 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
3282 TPACPI_VIDEO_NEW
, /* all others */
3285 enum { /* video status flags, based on VIDEO_570 */
3286 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
3287 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
3288 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
3291 enum { /* TPACPI_VIDEO_570 constants */
3292 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
3293 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
3294 * video_status_flags */
3295 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
3296 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
3299 static enum video_access_mode video_supported
;
3300 static int video_orig_autosw
;
3302 static int video_autosw_get(void);
3303 static int video_autosw_set(int enable
);
3305 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
3307 static int __init
video_init(struct ibm_init_struct
*iibm
)
3311 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
3313 TPACPI_ACPIHANDLE_INIT(vid
);
3314 TPACPI_ACPIHANDLE_INIT(vid2
);
3316 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
3317 /* G41, assume IVGA doesn't change */
3318 vid_handle
= vid2_handle
;
3321 /* video switching not supported on R30, R31 */
3322 video_supported
= TPACPI_VIDEO_NONE
;
3323 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
3325 video_supported
= TPACPI_VIDEO_570
;
3326 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
3327 /* 600e/x, 770e, 770x */
3328 video_supported
= TPACPI_VIDEO_770
;
3331 video_supported
= TPACPI_VIDEO_NEW
;
3333 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
3334 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
3337 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
3340 static void video_exit(void)
3342 dbg_printk(TPACPI_DBG_EXIT
,
3343 "restoring original video autoswitch mode\n");
3344 if (video_autosw_set(video_orig_autosw
))
3345 printk(TPACPI_ERR
"error while trying to restore original "
3346 "video autoswitch mode\n");
3349 static int video_outputsw_get(void)
3354 switch (video_supported
) {
3355 case TPACPI_VIDEO_570
:
3356 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
3357 TP_ACPI_VIDEO_570_PHSCMD
))
3359 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
3361 case TPACPI_VIDEO_770
:
3362 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
3365 status
|= TP_ACPI_VIDEO_S_LCD
;
3366 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
3369 status
|= TP_ACPI_VIDEO_S_CRT
;
3371 case TPACPI_VIDEO_NEW
:
3372 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
3373 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
3376 status
|= TP_ACPI_VIDEO_S_CRT
;
3378 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
3379 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
3382 status
|= TP_ACPI_VIDEO_S_LCD
;
3383 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
3386 status
|= TP_ACPI_VIDEO_S_DVI
;
3395 static int video_outputsw_set(int status
)
3400 switch (video_supported
) {
3401 case TPACPI_VIDEO_570
:
3402 res
= acpi_evalf(NULL
, NULL
,
3403 "\\_SB.PHS2", "vdd",
3404 TP_ACPI_VIDEO_570_PHS2CMD
,
3405 status
| TP_ACPI_VIDEO_570_PHS2SET
);
3407 case TPACPI_VIDEO_770
:
3408 autosw
= video_autosw_get();
3412 res
= video_autosw_set(1);
3415 res
= acpi_evalf(vid_handle
, NULL
,
3416 "ASWT", "vdd", status
* 0x100, 0);
3417 if (!autosw
&& video_autosw_set(autosw
)) {
3419 "video auto-switch left enabled due to error\n");
3423 case TPACPI_VIDEO_NEW
:
3424 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
3425 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
3431 return (res
)? 0 : -EIO
;
3434 static int video_autosw_get(void)
3438 switch (video_supported
) {
3439 case TPACPI_VIDEO_570
:
3440 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
3443 case TPACPI_VIDEO_770
:
3444 case TPACPI_VIDEO_NEW
:
3445 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
3455 static int video_autosw_set(int enable
)
3457 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
3462 static int video_outputsw_cycle(void)
3464 int autosw
= video_autosw_get();
3470 switch (video_supported
) {
3471 case TPACPI_VIDEO_570
:
3472 res
= video_autosw_set(1);
3475 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
3477 case TPACPI_VIDEO_770
:
3478 case TPACPI_VIDEO_NEW
:
3479 res
= video_autosw_set(1);
3482 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
3487 if (!autosw
&& video_autosw_set(autosw
)) {
3489 "video auto-switch left enabled due to error\n");
3493 return (res
)? 0 : -EIO
;
3496 static int video_expand_toggle(void)
3498 switch (video_supported
) {
3499 case TPACPI_VIDEO_570
:
3500 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
3502 case TPACPI_VIDEO_770
:
3503 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
3505 case TPACPI_VIDEO_NEW
:
3506 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
3514 static int video_read(char *p
)
3519 if (video_supported
== TPACPI_VIDEO_NONE
) {
3520 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3524 status
= video_outputsw_get();
3528 autosw
= video_autosw_get();
3532 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3533 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
3534 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
3535 if (video_supported
== TPACPI_VIDEO_NEW
)
3536 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
3537 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
3538 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
3539 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
3540 if (video_supported
== TPACPI_VIDEO_NEW
)
3541 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
3542 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
3543 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
3548 static int video_write(char *buf
)
3551 int enable
, disable
, status
;
3554 if (video_supported
== TPACPI_VIDEO_NONE
)
3560 while ((cmd
= next_cmd(&buf
))) {
3561 if (strlencmp(cmd
, "lcd_enable") == 0) {
3562 enable
|= TP_ACPI_VIDEO_S_LCD
;
3563 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
3564 disable
|= TP_ACPI_VIDEO_S_LCD
;
3565 } else if (strlencmp(cmd
, "crt_enable") == 0) {
3566 enable
|= TP_ACPI_VIDEO_S_CRT
;
3567 } else if (strlencmp(cmd
, "crt_disable") == 0) {
3568 disable
|= TP_ACPI_VIDEO_S_CRT
;
3569 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
3570 strlencmp(cmd
, "dvi_enable") == 0) {
3571 enable
|= TP_ACPI_VIDEO_S_DVI
;
3572 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
3573 strlencmp(cmd
, "dvi_disable") == 0) {
3574 disable
|= TP_ACPI_VIDEO_S_DVI
;
3575 } else if (strlencmp(cmd
, "auto_enable") == 0) {
3576 res
= video_autosw_set(1);
3579 } else if (strlencmp(cmd
, "auto_disable") == 0) {
3580 res
= video_autosw_set(0);
3583 } else if (strlencmp(cmd
, "video_switch") == 0) {
3584 res
= video_outputsw_cycle();
3587 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
3588 res
= video_expand_toggle();
3595 if (enable
|| disable
) {
3596 status
= video_outputsw_get();
3599 res
= video_outputsw_set((status
& ~disable
) | enable
);
3607 static struct ibm_struct video_driver_data
= {
3610 .write
= video_write
,
3614 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
3616 /*************************************************************************
3617 * Light (thinklight) subdriver
3620 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
3621 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
3623 static int light_get_status(void)
3627 if (tp_features
.light_status
) {
3628 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
3636 static int light_set_status(int status
)
3640 if (tp_features
.light
) {
3642 rc
= acpi_evalf(cmos_handle
, NULL
, NULL
, "vd",
3644 TP_CMOS_THINKLIGHT_ON
:
3645 TP_CMOS_THINKLIGHT_OFF
);
3647 rc
= acpi_evalf(lght_handle
, NULL
, NULL
, "vd",
3650 return (rc
)? 0 : -EIO
;
3656 static void light_set_status_worker(struct work_struct
*work
)
3658 struct tpacpi_led_classdev
*data
=
3659 container_of(work
, struct tpacpi_led_classdev
, work
);
3661 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
3662 light_set_status((data
->new_brightness
!= LED_OFF
));
3665 static void light_sysfs_set(struct led_classdev
*led_cdev
,
3666 enum led_brightness brightness
)
3668 struct tpacpi_led_classdev
*data
=
3669 container_of(led_cdev
,
3670 struct tpacpi_led_classdev
,
3672 data
->new_brightness
= brightness
;
3673 queue_work(tpacpi_wq
, &data
->work
);
3676 static enum led_brightness
light_sysfs_get(struct led_classdev
*led_cdev
)
3678 return (light_get_status() == 1)? LED_FULL
: LED_OFF
;
3681 static struct tpacpi_led_classdev tpacpi_led_thinklight
= {
3683 .name
= "tpacpi::thinklight",
3684 .brightness_set
= &light_sysfs_set
,
3685 .brightness_get
= &light_sysfs_get
,
3689 static int __init
light_init(struct ibm_init_struct
*iibm
)
3693 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
3695 TPACPI_ACPIHANDLE_INIT(ledb
);
3696 TPACPI_ACPIHANDLE_INIT(lght
);
3697 TPACPI_ACPIHANDLE_INIT(cmos
);
3698 INIT_WORK(&tpacpi_led_thinklight
.work
, light_set_status_worker
);
3700 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
3701 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
3703 if (tp_features
.light
)
3704 /* light status not supported on
3705 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
3706 tp_features
.light_status
=
3707 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
3709 vdbg_printk(TPACPI_DBG_INIT
, "light is %s, light status is %s\n",
3710 str_supported(tp_features
.light
),
3711 str_supported(tp_features
.light_status
));
3713 if (!tp_features
.light
)
3716 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
3717 &tpacpi_led_thinklight
.led_classdev
);
3720 tp_features
.light
= 0;
3721 tp_features
.light_status
= 0;
3729 static void light_exit(void)
3731 led_classdev_unregister(&tpacpi_led_thinklight
.led_classdev
);
3732 if (work_pending(&tpacpi_led_thinklight
.work
))
3733 flush_workqueue(tpacpi_wq
);
3736 static int light_read(char *p
)
3741 if (!tp_features
.light
) {
3742 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3743 } else if (!tp_features
.light_status
) {
3744 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
3745 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
3747 status
= light_get_status();
3750 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
3751 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
3757 static int light_write(char *buf
)
3762 if (!tp_features
.light
)
3765 while ((cmd
= next_cmd(&buf
))) {
3766 if (strlencmp(cmd
, "on") == 0) {
3768 } else if (strlencmp(cmd
, "off") == 0) {
3774 return light_set_status(newstatus
);
3777 static struct ibm_struct light_driver_data
= {
3780 .write
= light_write
,
3784 /*************************************************************************
3788 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3790 static void dock_notify(struct ibm_struct
*ibm
, u32 event
);
3791 static int dock_read(char *p
);
3792 static int dock_write(char *buf
);
3794 TPACPI_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
3795 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
3796 "\\_SB.PCI0.PCI1.DOCK", /* all others */
3797 "\\_SB.PCI.ISA.SLCE", /* 570 */
3798 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
3800 /* don't list other alternatives as we install a notify handler on the 570 */
3801 TPACPI_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
3803 static const struct acpi_device_id ibm_pci_device_ids
[] = {
3804 {PCI_ROOT_HID_STRING
, 0},
3808 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
3810 .notify
= dock_notify
,
3811 .handle
= &dock_handle
,
3812 .type
= ACPI_SYSTEM_NOTIFY
,
3815 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
3816 * We just use it to get notifications of dock hotplug
3817 * in very old thinkpads */
3818 .hid
= ibm_pci_device_ids
,
3819 .notify
= dock_notify
,
3820 .handle
= &pci_handle
,
3821 .type
= ACPI_SYSTEM_NOTIFY
,
3825 static struct ibm_struct dock_driver_data
[2] = {
3829 .write
= dock_write
,
3830 .acpi
= &ibm_dock_acpidriver
[0],
3834 .acpi
= &ibm_dock_acpidriver
[1],
3838 #define dock_docked() (_sta(dock_handle) & 1)
3840 static int __init
dock_init(struct ibm_init_struct
*iibm
)
3842 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
3844 TPACPI_ACPIHANDLE_INIT(dock
);
3846 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
3847 str_supported(dock_handle
!= NULL
));
3849 return (dock_handle
)? 0 : 1;
3852 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
3856 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
3858 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
3859 dock_driver_data
[0].flags
.acpi_notify_installed
) {
3860 TPACPI_ACPIHANDLE_INIT(pci
);
3861 dock2_needed
= (pci_handle
!= NULL
);
3862 vdbg_printk(TPACPI_DBG_INIT
,
3863 "dock PCI handler for the TP 570 is %s\n",
3864 str_supported(dock2_needed
));
3866 vdbg_printk(TPACPI_DBG_INIT
,
3867 "dock subdriver part 2 not required\n");
3871 return (dock2_needed
)? 0 : 1;
3874 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
3876 int docked
= dock_docked();
3877 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
3878 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
3881 if (event
== 1 && !pci
) /* 570 */
3882 data
= 1; /* button */
3883 else if (event
== 1 && pci
) /* 570 */
3884 data
= 3; /* dock */
3885 else if (event
== 3 && docked
)
3886 data
= 1; /* button */
3887 else if (event
== 3 && !docked
)
3888 data
= 2; /* undock */
3889 else if (event
== 0 && docked
)
3890 data
= 3; /* dock */
3892 printk(TPACPI_ERR
"unknown dock event %d, status %d\n",
3893 event
, _sta(dock_handle
));
3894 data
= 0; /* unknown */
3896 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
3897 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3898 dev_name(&ibm
->acpi
->device
->dev
),
3902 static int dock_read(char *p
)
3905 int docked
= dock_docked();
3908 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3910 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
3912 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
3913 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
3919 static int dock_write(char *buf
)
3926 while ((cmd
= next_cmd(&buf
))) {
3927 if (strlencmp(cmd
, "undock") == 0) {
3928 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
3929 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
3931 } else if (strlencmp(cmd
, "dock") == 0) {
3932 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
3941 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
3943 /*************************************************************************
3947 #ifdef CONFIG_THINKPAD_ACPI_BAY
3949 TPACPI_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
3950 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
3951 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
3952 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
3953 ); /* A21e, R30, R31 */
3954 TPACPI_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
3955 "_EJ0", /* all others */
3956 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
3957 TPACPI_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
3958 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
3960 TPACPI_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
3964 static int __init
bay_init(struct ibm_init_struct
*iibm
)
3966 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
3968 TPACPI_ACPIHANDLE_INIT(bay
);
3970 TPACPI_ACPIHANDLE_INIT(bay_ej
);
3971 TPACPI_ACPIHANDLE_INIT(bay2
);
3973 TPACPI_ACPIHANDLE_INIT(bay2_ej
);
3975 tp_features
.bay_status
= bay_handle
&&
3976 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
3977 tp_features
.bay_status2
= bay2_handle
&&
3978 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
3980 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
3981 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
3982 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
3983 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
3985 vdbg_printk(TPACPI_DBG_INIT
,
3986 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
3987 str_supported(tp_features
.bay_status
),
3988 str_supported(tp_features
.bay_eject
),
3989 str_supported(tp_features
.bay_status2
),
3990 str_supported(tp_features
.bay_eject2
));
3992 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
3993 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
3996 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
3998 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
3999 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
4000 dev_name(&ibm
->acpi
->device
->dev
),
4004 #define bay_occupied(b) (_sta(b##_handle) & 1)
4006 static int bay_read(char *p
)
4009 int occupied
= bay_occupied(bay
);
4010 int occupied2
= bay_occupied(bay2
);
4013 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4014 tp_features
.bay_status
?
4015 (occupied
? "occupied" : "unoccupied") :
4017 if (tp_features
.bay_status2
)
4018 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
4019 "occupied" : "unoccupied");
4021 eject
= tp_features
.bay_eject
&& occupied
;
4022 eject2
= tp_features
.bay_eject2
&& occupied2
;
4024 if (eject
&& eject2
)
4025 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
4027 len
+= sprintf(p
+ len
, "commands:\teject\n");
4029 len
+= sprintf(p
+ len
, "commands:\teject2\n");
4034 static int bay_write(char *buf
)
4038 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
4041 while ((cmd
= next_cmd(&buf
))) {
4042 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
4043 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
4045 } else if (tp_features
.bay_eject2
&&
4046 strlencmp(cmd
, "eject2") == 0) {
4047 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
4056 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
4057 .notify
= bay_notify
,
4058 .handle
= &bay_handle
,
4059 .type
= ACPI_SYSTEM_NOTIFY
,
4062 static struct ibm_struct bay_driver_data
= {
4066 .acpi
= &ibm_bay_acpidriver
,
4069 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4071 /*************************************************************************
4075 /* sysfs cmos_command -------------------------------------------------- */
4076 static ssize_t
cmos_command_store(struct device
*dev
,
4077 struct device_attribute
*attr
,
4078 const char *buf
, size_t count
)
4080 unsigned long cmos_cmd
;
4083 if (parse_strtoul(buf
, 21, &cmos_cmd
))
4086 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4087 return (res
)? res
: count
;
4090 static struct device_attribute dev_attr_cmos_command
=
4091 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
4093 /* --------------------------------------------------------------------- */
4095 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
4099 vdbg_printk(TPACPI_DBG_INIT
,
4100 "initializing cmos commands subdriver\n");
4102 TPACPI_ACPIHANDLE_INIT(cmos
);
4104 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
4105 str_supported(cmos_handle
!= NULL
));
4107 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4111 return (cmos_handle
)? 0 : 1;
4114 static void cmos_exit(void)
4116 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
4119 static int cmos_read(char *p
)
4123 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
4124 R30, R31, T20-22, X20-21 */
4126 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4128 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4129 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
4135 static int cmos_write(char *buf
)
4140 while ((cmd
= next_cmd(&buf
))) {
4141 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
4142 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
4147 res
= issue_thinkpad_cmos_command(cmos_cmd
);
4155 static struct ibm_struct cmos_driver_data
= {
4158 .write
= cmos_write
,
4162 /*************************************************************************
4166 enum led_access_mode
{
4167 TPACPI_LED_NONE
= 0,
4168 TPACPI_LED_570
, /* 570 */
4169 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4170 TPACPI_LED_NEW
, /* all others */
4173 enum { /* For TPACPI_LED_OLD */
4174 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
4175 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
4176 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
4185 static enum led_access_mode led_supported
;
4187 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
4188 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
4189 /* T20-22, X20-21 */
4190 "LED", /* all others */
4193 #define TPACPI_LED_NUMLEDS 8
4194 static struct tpacpi_led_classdev
*tpacpi_leds
;
4195 static enum led_status_t tpacpi_led_state_cache
[TPACPI_LED_NUMLEDS
];
4196 static const char * const tpacpi_led_names
[TPACPI_LED_NUMLEDS
] = {
4197 /* there's a limit of 19 chars + NULL before 2.6.26 */
4199 "tpacpi:orange:batt",
4200 "tpacpi:green:batt",
4201 "tpacpi::dock_active",
4202 "tpacpi::bay_active",
4203 "tpacpi::dock_batt",
4204 "tpacpi::unknown_led",
4208 static int led_get_status(const unsigned int led
)
4211 enum led_status_t led_s
;
4213 switch (led_supported
) {
4214 case TPACPI_LED_570
:
4215 if (!acpi_evalf(ec_handle
,
4216 &status
, "GLED", "dd", 1 << led
))
4218 led_s
= (status
== 0)?
4223 tpacpi_led_state_cache
[led
] = led_s
;
4232 static int led_set_status(const unsigned int led
,
4233 const enum led_status_t ledstatus
)
4235 /* off, on, blink. Index is led_status_t */
4236 static const unsigned int led_sled_arg1
[] = { 0, 1, 3 };
4237 static const unsigned int led_led_arg1
[] = { 0, 0x80, 0xc0 };
4241 switch (led_supported
) {
4242 case TPACPI_LED_570
:
4246 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4247 (1 << led
), led_sled_arg1
[ledstatus
]))
4250 case TPACPI_LED_OLD
:
4251 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
4254 rc
= ec_write(TPACPI_LED_EC_HLMS
, (1 << led
));
4256 rc
= ec_write(TPACPI_LED_EC_HLBL
,
4257 (ledstatus
== TPACPI_LED_BLINK
) << led
);
4259 rc
= ec_write(TPACPI_LED_EC_HLCL
,
4260 (ledstatus
!= TPACPI_LED_OFF
) << led
);
4262 case TPACPI_LED_NEW
:
4264 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
4265 led
, led_led_arg1
[ledstatus
]))
4273 tpacpi_led_state_cache
[led
] = ledstatus
;
4278 static void led_sysfs_set_status(unsigned int led
,
4279 enum led_brightness brightness
)
4282 (brightness
== LED_OFF
) ?
4284 (tpacpi_led_state_cache
[led
] == TPACPI_LED_BLINK
) ?
4285 TPACPI_LED_BLINK
: TPACPI_LED_ON
);
4288 static void led_set_status_worker(struct work_struct
*work
)
4290 struct tpacpi_led_classdev
*data
=
4291 container_of(work
, struct tpacpi_led_classdev
, work
);
4293 if (likely(tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
))
4294 led_sysfs_set_status(data
->led
, data
->new_brightness
);
4297 static void led_sysfs_set(struct led_classdev
*led_cdev
,
4298 enum led_brightness brightness
)
4300 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4301 struct tpacpi_led_classdev
, led_classdev
);
4303 data
->new_brightness
= brightness
;
4304 queue_work(tpacpi_wq
, &data
->work
);
4307 static int led_sysfs_blink_set(struct led_classdev
*led_cdev
,
4308 unsigned long *delay_on
, unsigned long *delay_off
)
4310 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4311 struct tpacpi_led_classdev
, led_classdev
);
4313 /* Can we choose the flash rate? */
4314 if (*delay_on
== 0 && *delay_off
== 0) {
4315 /* yes. set them to the hardware blink rate (1 Hz) */
4316 *delay_on
= 500; /* ms */
4317 *delay_off
= 500; /* ms */
4318 } else if ((*delay_on
!= 500) || (*delay_off
!= 500))
4321 data
->new_brightness
= TPACPI_LED_BLINK
;
4322 queue_work(tpacpi_wq
, &data
->work
);
4327 static enum led_brightness
led_sysfs_get(struct led_classdev
*led_cdev
)
4331 struct tpacpi_led_classdev
*data
= container_of(led_cdev
,
4332 struct tpacpi_led_classdev
, led_classdev
);
4334 rc
= led_get_status(data
->led
);
4336 if (rc
== TPACPI_LED_OFF
|| rc
< 0)
4337 rc
= LED_OFF
; /* no error handling in led class :( */
4344 static void led_exit(void)
4348 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4349 if (tpacpi_leds
[i
].led_classdev
.name
)
4350 led_classdev_unregister(&tpacpi_leds
[i
].led_classdev
);
4356 static int __init
led_init(struct ibm_init_struct
*iibm
)
4361 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
4363 TPACPI_ACPIHANDLE_INIT(led
);
4366 /* led not supported on R30, R31 */
4367 led_supported
= TPACPI_LED_NONE
;
4368 else if (strlencmp(led_path
, "SLED") == 0)
4370 led_supported
= TPACPI_LED_570
;
4371 else if (strlencmp(led_path
, "SYSL") == 0)
4372 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
4373 led_supported
= TPACPI_LED_OLD
;
4376 led_supported
= TPACPI_LED_NEW
;
4378 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
4379 str_supported(led_supported
), led_supported
);
4381 tpacpi_leds
= kzalloc(sizeof(*tpacpi_leds
) * TPACPI_LED_NUMLEDS
,
4384 printk(TPACPI_ERR
"Out of memory for LED data\n");
4388 for (i
= 0; i
< TPACPI_LED_NUMLEDS
; i
++) {
4389 tpacpi_leds
[i
].led
= i
;
4391 tpacpi_leds
[i
].led_classdev
.brightness_set
= &led_sysfs_set
;
4392 tpacpi_leds
[i
].led_classdev
.blink_set
= &led_sysfs_blink_set
;
4393 if (led_supported
== TPACPI_LED_570
)
4394 tpacpi_leds
[i
].led_classdev
.brightness_get
=
4397 tpacpi_leds
[i
].led_classdev
.name
= tpacpi_led_names
[i
];
4399 INIT_WORK(&tpacpi_leds
[i
].work
, led_set_status_worker
);
4401 rc
= led_classdev_register(&tpacpi_pdev
->dev
,
4402 &tpacpi_leds
[i
].led_classdev
);
4404 tpacpi_leds
[i
].led_classdev
.name
= NULL
;
4410 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
4413 #define str_led_status(s) \
4414 ((s) == TPACPI_LED_OFF ? "off" : \
4415 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
4417 static int led_read(char *p
)
4421 if (!led_supported
) {
4422 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4425 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4427 if (led_supported
== TPACPI_LED_570
) {
4430 for (i
= 0; i
< 8; i
++) {
4431 status
= led_get_status(i
);
4434 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
4435 i
, str_led_status(status
));
4439 len
+= sprintf(p
+ len
, "commands:\t"
4440 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
4445 static int led_write(char *buf
)
4449 enum led_status_t s
;
4454 while ((cmd
= next_cmd(&buf
))) {
4455 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
4458 if (strstr(cmd
, "off")) {
4460 } else if (strstr(cmd
, "on")) {
4462 } else if (strstr(cmd
, "blink")) {
4463 s
= TPACPI_LED_BLINK
;
4468 rc
= led_set_status(led
, s
);
4476 static struct ibm_struct led_driver_data
= {
4483 /*************************************************************************
4487 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
4489 static int __init
beep_init(struct ibm_init_struct
*iibm
)
4491 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
4493 TPACPI_ACPIHANDLE_INIT(beep
);
4495 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
4496 str_supported(beep_handle
!= NULL
));
4498 return (beep_handle
)? 0 : 1;
4501 static int beep_read(char *p
)
4506 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4508 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
4509 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
4515 static int beep_write(char *buf
)
4523 while ((cmd
= next_cmd(&buf
))) {
4524 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
4525 beep_cmd
>= 0 && beep_cmd
<= 17) {
4529 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
4536 static struct ibm_struct beep_driver_data
= {
4539 .write
= beep_write
,
4542 /*************************************************************************
4546 enum thermal_access_mode
{
4547 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
4548 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
4549 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
4550 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
4551 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
4554 enum { /* TPACPI_THERMAL_TPEC_* */
4555 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
4556 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
4557 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
4560 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
4561 struct ibm_thermal_sensors_struct
{
4562 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
4565 static enum thermal_access_mode thermal_read_mode
;
4567 /* idx is zero-based */
4568 static int thermal_get_sensor(int idx
, s32
*value
)
4574 t
= TP_EC_THERMAL_TMP0
;
4576 switch (thermal_read_mode
) {
4577 #if TPACPI_MAX_THERMAL_SENSORS >= 16
4578 case TPACPI_THERMAL_TPEC_16
:
4579 if (idx
>= 8 && idx
<= 15) {
4580 t
= TP_EC_THERMAL_TMP8
;
4585 case TPACPI_THERMAL_TPEC_8
:
4587 if (!acpi_ec_read(t
+ idx
, &tmp
))
4589 *value
= tmp
* 1000;
4594 case TPACPI_THERMAL_ACPI_UPDT
:
4596 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
4597 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
4599 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
4601 *value
= (t
- 2732) * 100;
4606 case TPACPI_THERMAL_ACPI_TMP07
:
4608 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
4609 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
4611 if (t
> 127 || t
< -127)
4612 t
= TP_EC_THERMAL_TMP_NA
;
4618 case TPACPI_THERMAL_NONE
:
4626 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
4637 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
4640 for (i
= 0 ; i
< n
; i
++) {
4641 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
4649 /* sysfs temp##_input -------------------------------------------------- */
4651 static ssize_t
thermal_temp_input_show(struct device
*dev
,
4652 struct device_attribute
*attr
,
4655 struct sensor_device_attribute
*sensor_attr
=
4656 to_sensor_dev_attr(attr
);
4657 int idx
= sensor_attr
->index
;
4661 res
= thermal_get_sensor(idx
, &value
);
4664 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
4667 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
4670 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
4671 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
4672 thermal_temp_input_show, NULL, _idxB)
4674 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
4675 THERMAL_SENSOR_ATTR_TEMP(1, 0),
4676 THERMAL_SENSOR_ATTR_TEMP(2, 1),
4677 THERMAL_SENSOR_ATTR_TEMP(3, 2),
4678 THERMAL_SENSOR_ATTR_TEMP(4, 3),
4679 THERMAL_SENSOR_ATTR_TEMP(5, 4),
4680 THERMAL_SENSOR_ATTR_TEMP(6, 5),
4681 THERMAL_SENSOR_ATTR_TEMP(7, 6),
4682 THERMAL_SENSOR_ATTR_TEMP(8, 7),
4683 THERMAL_SENSOR_ATTR_TEMP(9, 8),
4684 THERMAL_SENSOR_ATTR_TEMP(10, 9),
4685 THERMAL_SENSOR_ATTR_TEMP(11, 10),
4686 THERMAL_SENSOR_ATTR_TEMP(12, 11),
4687 THERMAL_SENSOR_ATTR_TEMP(13, 12),
4688 THERMAL_SENSOR_ATTR_TEMP(14, 13),
4689 THERMAL_SENSOR_ATTR_TEMP(15, 14),
4690 THERMAL_SENSOR_ATTR_TEMP(16, 15),
4693 #define THERMAL_ATTRS(X) \
4694 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
4696 static struct attribute
*thermal_temp_input_attr
[] = {
4716 static const struct attribute_group thermal_temp_input16_group
= {
4717 .attrs
= thermal_temp_input_attr
4720 static const struct attribute_group thermal_temp_input8_group
= {
4721 .attrs
= &thermal_temp_input_attr
[8]
4724 #undef THERMAL_SENSOR_ATTR_TEMP
4725 #undef THERMAL_ATTRS
4727 /* --------------------------------------------------------------------- */
4729 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
4736 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
4738 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
4740 if (thinkpad_id
.ec_model
) {
4742 * Direct EC access mode: sensors at registers
4743 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
4744 * non-implemented, thermal sensors return 0x80 when
4749 for (i
= 0; i
< 8; i
++) {
4750 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
4756 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
4764 /* This is sheer paranoia, but we handle it anyway */
4767 "ThinkPad ACPI EC access misbehaving, "
4768 "falling back to ACPI TMPx access "
4770 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
4773 "ThinkPad ACPI EC access misbehaving, "
4774 "disabling thermal sensors access\n");
4775 thermal_read_mode
= TPACPI_THERMAL_NONE
;
4780 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
4782 } else if (acpi_tmp7
) {
4783 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
4784 /* 600e/x, 770e, 770x */
4785 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
4787 /* Standard ACPI TMPx access, max 8 sensors */
4788 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
4791 /* temperatures not supported on 570, G4x, R30, R31, R32 */
4792 thermal_read_mode
= TPACPI_THERMAL_NONE
;
4795 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
4796 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
4799 switch (thermal_read_mode
) {
4800 case TPACPI_THERMAL_TPEC_16
:
4801 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4802 &thermal_temp_input16_group
);
4806 case TPACPI_THERMAL_TPEC_8
:
4807 case TPACPI_THERMAL_ACPI_TMP07
:
4808 case TPACPI_THERMAL_ACPI_UPDT
:
4809 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4810 &thermal_temp_input8_group
);
4814 case TPACPI_THERMAL_NONE
:
4822 static void thermal_exit(void)
4824 switch (thermal_read_mode
) {
4825 case TPACPI_THERMAL_TPEC_16
:
4826 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4827 &thermal_temp_input16_group
);
4829 case TPACPI_THERMAL_TPEC_8
:
4830 case TPACPI_THERMAL_ACPI_TMP07
:
4831 case TPACPI_THERMAL_ACPI_UPDT
:
4832 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4833 &thermal_temp_input16_group
);
4835 case TPACPI_THERMAL_NONE
:
4841 static int thermal_read(char *p
)
4845 struct ibm_thermal_sensors_struct t
;
4847 n
= thermal_get_sensors(&t
);
4848 if (unlikely(n
< 0))
4851 len
+= sprintf(p
+ len
, "temperatures:\t");
4854 for (i
= 0; i
< (n
- 1); i
++)
4855 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
4856 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
4858 len
+= sprintf(p
+ len
, "not supported\n");
4863 static struct ibm_struct thermal_driver_data
= {
4865 .read
= thermal_read
,
4866 .exit
= thermal_exit
,
4869 /*************************************************************************
4873 static u8 ecdump_regs
[256];
4875 static int ecdump_read(char *p
)
4881 len
+= sprintf(p
+ len
, "EC "
4882 " +00 +01 +02 +03 +04 +05 +06 +07"
4883 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
4884 for (i
= 0; i
< 256; i
+= 16) {
4885 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
4886 for (j
= 0; j
< 16; j
++) {
4887 if (!acpi_ec_read(i
+ j
, &v
))
4889 if (v
!= ecdump_regs
[i
+ j
])
4890 len
+= sprintf(p
+ len
, " *%02x", v
);
4892 len
+= sprintf(p
+ len
, " %02x", v
);
4893 ecdump_regs
[i
+ j
] = v
;
4895 len
+= sprintf(p
+ len
, "\n");
4900 /* These are way too dangerous to advertise openly... */
4902 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
4903 " (<offset> is 00-ff, <value> is 00-ff)\n");
4904 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
4905 " (<offset> is 00-ff, <value> is 0-255)\n");
4910 static int ecdump_write(char *buf
)
4915 while ((cmd
= next_cmd(&buf
))) {
4916 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
4918 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
4922 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
4923 if (!acpi_ec_write(i
, v
))
4932 static struct ibm_struct ecdump_driver_data
= {
4934 .read
= ecdump_read
,
4935 .write
= ecdump_write
,
4936 .flags
.experimental
= 1,
4939 /*************************************************************************
4940 * Backlight/brightness subdriver
4943 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
4946 TP_EC_BACKLIGHT
= 0x31,
4948 /* TP_EC_BACKLIGHT bitmasks */
4949 TP_EC_BACKLIGHT_LVLMSK
= 0x1F,
4950 TP_EC_BACKLIGHT_CMDMSK
= 0xE0,
4951 TP_EC_BACKLIGHT_MAPSW
= 0x20,
4954 static struct backlight_device
*ibm_backlight_device
;
4955 static int brightness_mode
;
4956 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
4958 static struct mutex brightness_mutex
;
4961 * ThinkPads can read brightness from two places: EC 0x31, or
4962 * CMOS NVRAM byte 0x5E, bits 0-3.
4964 * EC 0x31 has the following layout
4965 * Bit 7: unknown function
4966 * Bit 6: unknown function
4967 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
4968 * Bit 4: must be set to zero to avoid problems
4969 * Bit 3-0: backlight brightness level
4971 * brightness_get_raw returns status data in the EC 0x31 layout
4973 static int brightness_get_raw(int *status
)
4975 u8 lec
= 0, lcmos
= 0, level
= 0;
4977 if (brightness_mode
& 1) {
4978 if (!acpi_ec_read(TP_EC_BACKLIGHT
, &lec
))
4980 level
= lec
& TP_EC_BACKLIGHT_LVLMSK
;
4982 if (brightness_mode
& 2) {
4983 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
4984 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
4985 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
4986 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
4990 if (brightness_mode
== 3) {
4991 *status
= lec
; /* Prefer EC, CMOS is just a backing store */
4992 lec
&= TP_EC_BACKLIGHT_LVLMSK
;
4994 tp_warned
.bright_cmos_ec_unsync
= 0;
4996 if (!tp_warned
.bright_cmos_ec_unsync
) {
4998 "CMOS NVRAM (%u) and EC (%u) do not "
4999 "agree on display brightness level\n",
5000 (unsigned int) lcmos
,
5001 (unsigned int) lec
);
5002 tp_warned
.bright_cmos_ec_unsync
= 1;
5013 /* May return EINTR which can always be mapped to ERESTARTSYS */
5014 static int brightness_set(int value
)
5016 int cmos_cmd
, inc
, i
, res
;
5020 if (value
> ((tp_features
.bright_16levels
)? 15 : 7) ||
5024 res
= mutex_lock_interruptible(&brightness_mutex
);
5028 res
= brightness_get_raw(¤t_value
);
5032 command_bits
= current_value
& TP_EC_BACKLIGHT_CMDMSK
;
5033 current_value
&= TP_EC_BACKLIGHT_LVLMSK
;
5035 cmos_cmd
= value
> current_value
?
5036 TP_CMOS_BRIGHTNESS_UP
:
5037 TP_CMOS_BRIGHTNESS_DOWN
;
5038 inc
= (value
> current_value
)? 1 : -1;
5041 for (i
= current_value
; i
!= value
; i
+= inc
) {
5042 if ((brightness_mode
& 2) &&
5043 issue_thinkpad_cmos_command(cmos_cmd
)) {
5047 if ((brightness_mode
& 1) &&
5048 !acpi_ec_write(TP_EC_BACKLIGHT
,
5049 (i
+ inc
) | command_bits
)) {
5056 mutex_unlock(&brightness_mutex
);
5060 /* sysfs backlight class ----------------------------------------------- */
5062 static int brightness_update_status(struct backlight_device
*bd
)
5064 /* it is the backlight class's job (caller) to handle
5065 * EINTR and other errors properly */
5066 return brightness_set(
5067 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
5068 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
5069 bd
->props
.brightness
: 0);
5072 static int brightness_get(struct backlight_device
*bd
)
5076 res
= brightness_get_raw(&status
);
5078 return 0; /* FIXME: teach backlight about error handling */
5080 return status
& TP_EC_BACKLIGHT_LVLMSK
;
5083 static struct backlight_ops ibm_backlight_data
= {
5084 .get_brightness
= brightness_get
,
5085 .update_status
= brightness_update_status
,
5088 /* --------------------------------------------------------------------- */
5090 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
5094 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
5096 mutex_init(&brightness_mutex
);
5099 * We always attempt to detect acpi support, so as to switch
5100 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
5101 * going to publish a backlight interface
5103 b
= tpacpi_check_std_acpi_brightness_support();
5105 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
5106 printk(TPACPI_NOTICE
5107 "Lenovo BIOS switched to ACPI backlight "
5110 if (brightness_enable
> 1) {
5111 printk(TPACPI_NOTICE
5112 "standard ACPI backlight interface "
5113 "available, not loading native one...\n");
5118 if (!brightness_enable
) {
5119 dbg_printk(TPACPI_DBG_INIT
,
5120 "brightness support disabled by "
5121 "module parameter\n");
5127 "Unsupported brightness interface, "
5128 "please contact %s\n", TPACPI_MAIL
);
5132 tp_features
.bright_16levels
= 1;
5134 if (!brightness_mode
) {
5135 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
5136 brightness_mode
= 2;
5138 brightness_mode
= 3;
5140 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
5144 if (brightness_mode
> 3)
5147 if (brightness_get_raw(&b
) < 0)
5150 if (tp_features
.bright_16levels
)
5152 "detected a 16-level brightness capable ThinkPad\n");
5154 ibm_backlight_device
= backlight_device_register(
5155 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
5156 &ibm_backlight_data
);
5157 if (IS_ERR(ibm_backlight_device
)) {
5158 printk(TPACPI_ERR
"Could not register backlight device\n");
5159 return PTR_ERR(ibm_backlight_device
);
5161 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
5163 ibm_backlight_device
->props
.max_brightness
=
5164 (tp_features
.bright_16levels
)? 15 : 7;
5165 ibm_backlight_device
->props
.brightness
= b
& TP_EC_BACKLIGHT_LVLMSK
;
5166 backlight_update_status(ibm_backlight_device
);
5171 static void brightness_exit(void)
5173 if (ibm_backlight_device
) {
5174 vdbg_printk(TPACPI_DBG_EXIT
,
5175 "calling backlight_device_unregister()\n");
5176 backlight_device_unregister(ibm_backlight_device
);
5180 static int brightness_read(char *p
)
5185 level
= brightness_get(NULL
);
5187 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
5189 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
5190 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
5191 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
5192 " (<level> is 0-%d)\n",
5193 (tp_features
.bright_16levels
) ? 15 : 7);
5199 static int brightness_write(char *buf
)
5204 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
5206 level
= brightness_get(NULL
);
5210 while ((cmd
= next_cmd(&buf
))) {
5211 if (strlencmp(cmd
, "up") == 0) {
5212 if (level
< max_level
)
5214 } else if (strlencmp(cmd
, "down") == 0) {
5217 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
5218 level
>= 0 && level
<= max_level
) {
5225 * Now we know what the final level should be, so we try to set it.
5226 * Doing it this way makes the syscall restartable in case of EINTR
5228 rc
= brightness_set(level
);
5229 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
5232 static struct ibm_struct brightness_driver_data
= {
5233 .name
= "brightness",
5234 .read
= brightness_read
,
5235 .write
= brightness_write
,
5236 .exit
= brightness_exit
,
5239 /*************************************************************************
5243 static int volume_offset
= 0x30;
5245 static int volume_read(char *p
)
5250 if (!acpi_ec_read(volume_offset
, &level
)) {
5251 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
5253 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
5254 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
5255 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
5256 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
5257 " (<level> is 0-15)\n");
5263 static int volume_write(char *buf
)
5265 int cmos_cmd
, inc
, i
;
5267 int new_level
, new_mute
;
5270 while ((cmd
= next_cmd(&buf
))) {
5271 if (!acpi_ec_read(volume_offset
, &level
))
5273 new_mute
= mute
= level
& 0x40;
5274 new_level
= level
= level
& 0xf;
5276 if (strlencmp(cmd
, "up") == 0) {
5280 new_level
= level
== 15 ? 15 : level
+ 1;
5281 } else if (strlencmp(cmd
, "down") == 0) {
5285 new_level
= level
== 0 ? 0 : level
- 1;
5286 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
5287 new_level
>= 0 && new_level
<= 15) {
5289 } else if (strlencmp(cmd
, "mute") == 0) {
5294 if (new_level
!= level
) {
5295 /* mute doesn't change */
5297 cmos_cmd
= (new_level
> level
) ?
5298 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
5299 inc
= new_level
> level
? 1 : -1;
5301 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
5302 !acpi_ec_write(volume_offset
, level
)))
5305 for (i
= level
; i
!= new_level
; i
+= inc
)
5306 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
5307 !acpi_ec_write(volume_offset
, i
+ inc
))
5311 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
5312 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
5317 if (new_mute
!= mute
) {
5318 /* level doesn't change */
5320 cmos_cmd
= (new_mute
) ?
5321 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
5323 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
5324 !acpi_ec_write(volume_offset
, level
+ new_mute
))
5332 static struct ibm_struct volume_driver_data
= {
5334 .read
= volume_read
,
5335 .write
= volume_write
,
5338 /*************************************************************************
5345 * TPACPI_FAN_RD_ACPI_GFAN:
5346 * ACPI GFAN method: returns fan level
5348 * see TPACPI_FAN_WR_ACPI_SFAN
5349 * EC 0x2f (HFSP) not available if GFAN exists
5351 * TPACPI_FAN_WR_ACPI_SFAN:
5352 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
5354 * EC 0x2f (HFSP) might be available *for reading*, but do not use
5357 * TPACPI_FAN_WR_TPEC:
5358 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
5359 * Supported on almost all ThinkPads
5361 * Fan speed changes of any sort (including those caused by the
5362 * disengaged mode) are usually done slowly by the firmware as the
5363 * maximum ammount of fan duty cycle change per second seems to be
5366 * Reading is not available if GFAN exists.
5367 * Writing is not available if SFAN exists.
5370 * 7 automatic mode engaged;
5371 * (default operation mode of the ThinkPad)
5372 * fan level is ignored in this mode.
5373 * 6 full speed mode (takes precedence over bit 7);
5374 * not available on all thinkpads. May disable
5375 * the tachometer while the fan controller ramps up
5376 * the speed (which can take up to a few *minutes*).
5377 * Speeds up fan to 100% duty-cycle, which is far above
5378 * the standard RPM levels. It is not impossible that
5379 * it could cause hardware damage.
5380 * 5-3 unused in some models. Extra bits for fan level
5381 * in others, but still useless as all values above
5382 * 7 map to the same speed as level 7 in these models.
5383 * 2-0 fan level (0..7 usually)
5385 * 0x07 = max (set when temperatures critical)
5386 * Some ThinkPads may have other levels, see
5387 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
5389 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
5390 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
5391 * does so, its initial value is meaningless (0x07).
5393 * For firmware bugs, refer to:
5394 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5398 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
5399 * Main fan tachometer reading (in RPM)
5401 * This register is present on all ThinkPads with a new-style EC, and
5402 * it is known not to be present on the A21m/e, and T22, as there is
5403 * something else in offset 0x84 according to the ACPI DSDT. Other
5404 * ThinkPads from this same time period (and earlier) probably lack the
5405 * tachometer as well.
5407 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
5408 * was never fixed by IBM to report the EC firmware version string
5409 * probably support the tachometer (like the early X models), so
5410 * detecting it is quite hard. We need more data to know for sure.
5412 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
5415 * FIRMWARE BUG: may go stale while the EC is switching to full speed
5418 * For firmware bugs, refer to:
5419 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
5421 * TPACPI_FAN_WR_ACPI_FANS:
5422 * ThinkPad X31, X40, X41. Not available in the X60.
5424 * FANS ACPI handle: takes three arguments: low speed, medium speed,
5425 * high speed. ACPI DSDT seems to map these three speeds to levels
5426 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
5427 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
5429 * The speeds are stored on handles
5430 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
5432 * There are three default speed sets, acessible as handles:
5433 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
5435 * ACPI DSDT switches which set is in use depending on various
5438 * TPACPI_FAN_WR_TPEC is also available and should be used to
5439 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
5440 * but the ACPI tables just mention level 7.
5443 enum { /* Fan control constants */
5444 fan_status_offset
= 0x2f, /* EC register 0x2f */
5445 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
5446 * 0x84 must be read before 0x85 */
5448 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
5449 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
5451 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
5454 enum fan_status_access_mode
{
5455 TPACPI_FAN_NONE
= 0, /* No fan status or control */
5456 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
5457 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
5460 enum fan_control_access_mode
{
5461 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
5462 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
5463 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
5464 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
5467 enum fan_control_commands
{
5468 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
5469 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
5470 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
5471 * and also watchdog cmd */
5474 static int fan_control_allowed
;
5476 static enum fan_status_access_mode fan_status_access_mode
;
5477 static enum fan_control_access_mode fan_control_access_mode
;
5478 static enum fan_control_commands fan_control_commands
;
5480 static u8 fan_control_initial_status
;
5481 static u8 fan_control_desired_level
;
5482 static u8 fan_control_resume_level
;
5483 static int fan_watchdog_maxinterval
;
5485 static struct mutex fan_mutex
;
5487 static void fan_watchdog_fire(struct work_struct
*ignored
);
5488 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
5490 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
5491 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
5492 "\\FSPD", /* 600e/x, 770e, 770x */
5494 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
5495 "JFNS", /* 770x-JL */
5499 * Call with fan_mutex held
5501 static void fan_update_desired_level(u8 status
)
5504 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
5506 fan_control_desired_level
= 7;
5508 fan_control_desired_level
= status
;
5512 static int fan_get_status(u8
*status
)
5517 * Add TPACPI_FAN_RD_ACPI_FANS ? */
5519 switch (fan_status_access_mode
) {
5520 case TPACPI_FAN_RD_ACPI_GFAN
:
5521 /* 570, 600e/x, 770e, 770x */
5523 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
5531 case TPACPI_FAN_RD_TPEC
:
5532 /* all except 570, 600e/x, 770e, 770x */
5533 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
5548 static int fan_get_status_safe(u8
*status
)
5553 if (mutex_lock_interruptible(&fan_mutex
))
5554 return -ERESTARTSYS
;
5555 rc
= fan_get_status(&s
);
5557 fan_update_desired_level(s
);
5558 mutex_unlock(&fan_mutex
);
5566 static int fan_get_speed(unsigned int *speed
)
5570 switch (fan_status_access_mode
) {
5571 case TPACPI_FAN_RD_TPEC
:
5572 /* all except 570, 600e/x, 770e, 770x */
5573 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
5574 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
5578 *speed
= (hi
<< 8) | lo
;
5589 static int fan_set_level(int level
)
5591 if (!fan_control_allowed
)
5594 switch (fan_control_access_mode
) {
5595 case TPACPI_FAN_WR_ACPI_SFAN
:
5596 if (level
>= 0 && level
<= 7) {
5597 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
5603 case TPACPI_FAN_WR_ACPI_FANS
:
5604 case TPACPI_FAN_WR_TPEC
:
5605 if (!(level
& TP_EC_FAN_AUTO
) &&
5606 !(level
& TP_EC_FAN_FULLSPEED
) &&
5607 ((level
< 0) || (level
> 7)))
5610 /* safety net should the EC not support AUTO
5611 * or FULLSPEED mode bits and just ignore them */
5612 if (level
& TP_EC_FAN_FULLSPEED
)
5613 level
|= 7; /* safety min speed 7 */
5614 else if (level
& TP_EC_FAN_AUTO
)
5615 level
|= 4; /* safety min speed 4 */
5617 if (!acpi_ec_write(fan_status_offset
, level
))
5620 tp_features
.fan_ctrl_status_undef
= 0;
5629 static int fan_set_level_safe(int level
)
5633 if (!fan_control_allowed
)
5636 if (mutex_lock_interruptible(&fan_mutex
))
5637 return -ERESTARTSYS
;
5639 if (level
== TPACPI_FAN_LAST_LEVEL
)
5640 level
= fan_control_desired_level
;
5642 rc
= fan_set_level(level
);
5644 fan_update_desired_level(level
);
5646 mutex_unlock(&fan_mutex
);
5650 static int fan_set_enable(void)
5655 if (!fan_control_allowed
)
5658 if (mutex_lock_interruptible(&fan_mutex
))
5659 return -ERESTARTSYS
;
5661 switch (fan_control_access_mode
) {
5662 case TPACPI_FAN_WR_ACPI_FANS
:
5663 case TPACPI_FAN_WR_TPEC
:
5664 rc
= fan_get_status(&s
);
5668 /* Don't go out of emergency fan mode */
5671 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
5674 if (!acpi_ec_write(fan_status_offset
, s
))
5677 tp_features
.fan_ctrl_status_undef
= 0;
5682 case TPACPI_FAN_WR_ACPI_SFAN
:
5683 rc
= fan_get_status(&s
);
5689 /* Set fan to at least level 4 */
5692 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
5702 mutex_unlock(&fan_mutex
);
5706 static int fan_set_disable(void)
5710 if (!fan_control_allowed
)
5713 if (mutex_lock_interruptible(&fan_mutex
))
5714 return -ERESTARTSYS
;
5717 switch (fan_control_access_mode
) {
5718 case TPACPI_FAN_WR_ACPI_FANS
:
5719 case TPACPI_FAN_WR_TPEC
:
5720 if (!acpi_ec_write(fan_status_offset
, 0x00))
5723 fan_control_desired_level
= 0;
5724 tp_features
.fan_ctrl_status_undef
= 0;
5728 case TPACPI_FAN_WR_ACPI_SFAN
:
5729 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
5732 fan_control_desired_level
= 0;
5740 mutex_unlock(&fan_mutex
);
5744 static int fan_set_speed(int speed
)
5748 if (!fan_control_allowed
)
5751 if (mutex_lock_interruptible(&fan_mutex
))
5752 return -ERESTARTSYS
;
5755 switch (fan_control_access_mode
) {
5756 case TPACPI_FAN_WR_ACPI_FANS
:
5757 if (speed
>= 0 && speed
<= 65535) {
5758 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
5759 speed
, speed
, speed
))
5769 mutex_unlock(&fan_mutex
);
5773 static void fan_watchdog_reset(void)
5775 static int fan_watchdog_active
;
5777 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
5780 if (fan_watchdog_active
)
5781 cancel_delayed_work(&fan_watchdog_task
);
5783 if (fan_watchdog_maxinterval
> 0 &&
5784 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
5785 fan_watchdog_active
= 1;
5786 if (!queue_delayed_work(tpacpi_wq
, &fan_watchdog_task
,
5787 msecs_to_jiffies(fan_watchdog_maxinterval
5790 "failed to queue the fan watchdog, "
5791 "watchdog will not trigger\n");
5794 fan_watchdog_active
= 0;
5797 static void fan_watchdog_fire(struct work_struct
*ignored
)
5801 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
5804 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
5805 rc
= fan_set_enable();
5807 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
5808 "will try again later...\n", -rc
);
5809 /* reschedule for later */
5810 fan_watchdog_reset();
5815 * SYSFS fan layout: hwmon compatible (device)
5818 * 0: "disengaged" mode
5820 * 2: native EC "auto" mode (recommended, hardware default)
5822 * pwm*: set speed in manual mode, ignored otherwise.
5823 * 0 is level 0; 255 is level 7. Intermediate points done with linear
5826 * fan*_input: tachometer reading, RPM
5829 * SYSFS fan layout: extensions
5831 * fan_watchdog (driver):
5832 * fan watchdog interval in seconds, 0 disables (default), max 120
5835 /* sysfs fan pwm1_enable ----------------------------------------------- */
5836 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
5837 struct device_attribute
*attr
,
5843 res
= fan_get_status_safe(&status
);
5847 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5848 if (status
!= fan_control_initial_status
) {
5849 tp_features
.fan_ctrl_status_undef
= 0;
5851 /* Return most likely status. In fact, it
5852 * might be the only possible status */
5853 status
= TP_EC_FAN_AUTO
;
5857 if (status
& TP_EC_FAN_FULLSPEED
) {
5859 } else if (status
& TP_EC_FAN_AUTO
) {
5864 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
5867 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
5868 struct device_attribute
*attr
,
5869 const char *buf
, size_t count
)
5874 if (parse_strtoul(buf
, 2, &t
))
5879 level
= TP_EC_FAN_FULLSPEED
;
5882 level
= TPACPI_FAN_LAST_LEVEL
;
5885 level
= TP_EC_FAN_AUTO
;
5888 /* reserved for software-controlled auto mode */
5894 res
= fan_set_level_safe(level
);
5900 fan_watchdog_reset();
5905 static struct device_attribute dev_attr_fan_pwm1_enable
=
5906 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
5907 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
5909 /* sysfs fan pwm1 ------------------------------------------------------ */
5910 static ssize_t
fan_pwm1_show(struct device
*dev
,
5911 struct device_attribute
*attr
,
5917 res
= fan_get_status_safe(&status
);
5921 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5922 if (status
!= fan_control_initial_status
) {
5923 tp_features
.fan_ctrl_status_undef
= 0;
5925 status
= TP_EC_FAN_AUTO
;
5930 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
5931 status
= fan_control_desired_level
;
5936 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
5939 static ssize_t
fan_pwm1_store(struct device
*dev
,
5940 struct device_attribute
*attr
,
5941 const char *buf
, size_t count
)
5945 u8 status
, newlevel
;
5947 if (parse_strtoul(buf
, 255, &s
))
5950 /* scale down from 0-255 to 0-7 */
5951 newlevel
= (s
>> 5) & 0x07;
5953 if (mutex_lock_interruptible(&fan_mutex
))
5954 return -ERESTARTSYS
;
5956 rc
= fan_get_status(&status
);
5957 if (!rc
&& (status
&
5958 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
5959 rc
= fan_set_level(newlevel
);
5963 fan_update_desired_level(newlevel
);
5964 fan_watchdog_reset();
5968 mutex_unlock(&fan_mutex
);
5969 return (rc
)? rc
: count
;
5972 static struct device_attribute dev_attr_fan_pwm1
=
5973 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
5974 fan_pwm1_show
, fan_pwm1_store
);
5976 /* sysfs fan fan1_input ------------------------------------------------ */
5977 static ssize_t
fan_fan1_input_show(struct device
*dev
,
5978 struct device_attribute
*attr
,
5984 res
= fan_get_speed(&speed
);
5988 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
5991 static struct device_attribute dev_attr_fan_fan1_input
=
5992 __ATTR(fan1_input
, S_IRUGO
,
5993 fan_fan1_input_show
, NULL
);
5995 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
5996 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
5999 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
6002 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
6003 const char *buf
, size_t count
)
6007 if (parse_strtoul(buf
, 120, &t
))
6010 if (!fan_control_allowed
)
6013 fan_watchdog_maxinterval
= t
;
6014 fan_watchdog_reset();
6019 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
6020 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
6022 /* --------------------------------------------------------------------- */
6023 static struct attribute
*fan_attributes
[] = {
6024 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
6025 &dev_attr_fan_fan1_input
.attr
,
6029 static const struct attribute_group fan_attr_group
= {
6030 .attrs
= fan_attributes
,
6033 static int __init
fan_init(struct ibm_init_struct
*iibm
)
6037 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
6039 mutex_init(&fan_mutex
);
6040 fan_status_access_mode
= TPACPI_FAN_NONE
;
6041 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
6042 fan_control_commands
= 0;
6043 fan_watchdog_maxinterval
= 0;
6044 tp_features
.fan_ctrl_status_undef
= 0;
6045 fan_control_desired_level
= 7;
6047 TPACPI_ACPIHANDLE_INIT(fans
);
6048 TPACPI_ACPIHANDLE_INIT(gfan
);
6049 TPACPI_ACPIHANDLE_INIT(sfan
);
6052 /* 570, 600e/x, 770e, 770x */
6053 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
6055 /* all other ThinkPads: note that even old-style
6056 * ThinkPad ECs supports the fan control register */
6057 if (likely(acpi_ec_read(fan_status_offset
,
6058 &fan_control_initial_status
))) {
6059 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
6061 /* In some ThinkPads, neither the EC nor the ACPI
6062 * DSDT initialize the fan status, and it ends up
6063 * being set to 0x07 when it *could* be either
6066 * Enable for TP-1Y (T43), TP-78 (R51e),
6067 * TP-76 (R52), TP-70 (T43, R52), which are known
6069 if (fan_control_initial_status
== 0x07) {
6070 switch (thinkpad_id
.ec_model
) {
6071 case 0x5931: /* TP-1Y */
6072 case 0x3837: /* TP-78 */
6073 case 0x3637: /* TP-76 */
6074 case 0x3037: /* TP-70 */
6075 printk(TPACPI_NOTICE
6076 "fan_init: initial fan status "
6077 "is unknown, assuming it is "
6079 tp_features
.fan_ctrl_status_undef
= 1;
6085 "ThinkPad ACPI EC access misbehaving, "
6086 "fan status and control unavailable\n");
6093 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
6094 fan_control_commands
|=
6095 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
6098 /* gfan without sfan means no fan control */
6099 /* all other models implement TP EC 0x2f control */
6103 fan_control_access_mode
=
6104 TPACPI_FAN_WR_ACPI_FANS
;
6105 fan_control_commands
|=
6106 TPACPI_FAN_CMD_SPEED
|
6107 TPACPI_FAN_CMD_LEVEL
|
6108 TPACPI_FAN_CMD_ENABLE
;
6110 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
6111 fan_control_commands
|=
6112 TPACPI_FAN_CMD_LEVEL
|
6113 TPACPI_FAN_CMD_ENABLE
;
6118 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
6119 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
6120 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
6121 fan_status_access_mode
, fan_control_access_mode
);
6123 /* fan control master switch */
6124 if (!fan_control_allowed
) {
6125 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
6126 fan_control_commands
= 0;
6127 dbg_printk(TPACPI_DBG_INIT
,
6128 "fan control features disabled by parameter\n");
6131 /* update fan_control_desired_level */
6132 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
6133 fan_get_status_safe(NULL
);
6135 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
6136 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
6137 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
6142 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
6143 &driver_attr_fan_watchdog
);
6145 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
6154 static void fan_exit(void)
6156 vdbg_printk(TPACPI_DBG_EXIT
,
6157 "cancelling any pending fan watchdog tasks\n");
6159 /* FIXME: can we really do this unconditionally? */
6160 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
6161 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
6162 &driver_attr_fan_watchdog
);
6164 cancel_delayed_work(&fan_watchdog_task
);
6165 flush_workqueue(tpacpi_wq
);
6168 static void fan_suspend(pm_message_t state
)
6172 if (!fan_control_allowed
)
6175 /* Store fan status in cache */
6176 fan_control_resume_level
= 0;
6177 rc
= fan_get_status_safe(&fan_control_resume_level
);
6179 printk(TPACPI_NOTICE
6180 "failed to read fan level for later "
6181 "restore during resume: %d\n", rc
);
6183 /* if it is undefined, don't attempt to restore it.
6185 if (tp_features
.fan_ctrl_status_undef
)
6186 fan_control_resume_level
= 0;
6189 static void fan_resume(void)
6191 u8 current_level
= 7;
6192 bool do_set
= false;
6195 /* DSDT *always* updates status on resume */
6196 tp_features
.fan_ctrl_status_undef
= 0;
6198 if (!fan_control_allowed
||
6199 !fan_control_resume_level
||
6200 (fan_get_status_safe(¤t_level
) < 0))
6203 switch (fan_control_access_mode
) {
6204 case TPACPI_FAN_WR_ACPI_SFAN
:
6205 /* never decrease fan level */
6206 do_set
= (fan_control_resume_level
> current_level
);
6208 case TPACPI_FAN_WR_ACPI_FANS
:
6209 case TPACPI_FAN_WR_TPEC
:
6210 /* never decrease fan level, scale is:
6211 * TP_EC_FAN_FULLSPEED > 7 >= TP_EC_FAN_AUTO
6213 * We expect the firmware to set either 7 or AUTO, but we
6214 * handle FULLSPEED out of paranoia.
6216 * So, we can safely only restore FULLSPEED or 7, anything
6217 * else could slow the fan. Restoring AUTO is useless, at
6218 * best that's exactly what the DSDT already set (it is the
6221 * Always keep in mind that the DSDT *will* have set the
6222 * fans to what the vendor supposes is the best level. We
6223 * muck with it only to speed the fan up.
6225 if (fan_control_resume_level
!= 7 &&
6226 !(fan_control_resume_level
& TP_EC_FAN_FULLSPEED
))
6229 do_set
= !(current_level
& TP_EC_FAN_FULLSPEED
) &&
6230 (current_level
!= fan_control_resume_level
);
6236 printk(TPACPI_NOTICE
6237 "restoring fan level to 0x%02x\n",
6238 fan_control_resume_level
);
6239 rc
= fan_set_level_safe(fan_control_resume_level
);
6241 printk(TPACPI_NOTICE
6242 "failed to restore fan level: %d\n", rc
);
6246 static int fan_read(char *p
)
6251 unsigned int speed
= 0;
6253 switch (fan_status_access_mode
) {
6254 case TPACPI_FAN_RD_ACPI_GFAN
:
6255 /* 570, 600e/x, 770e, 770x */
6256 rc
= fan_get_status_safe(&status
);
6260 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
6262 (status
!= 0) ? "enabled" : "disabled", status
);
6265 case TPACPI_FAN_RD_TPEC
:
6266 /* all except 570, 600e/x, 770e, 770x */
6267 rc
= fan_get_status_safe(&status
);
6271 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
6272 if (status
!= fan_control_initial_status
)
6273 tp_features
.fan_ctrl_status_undef
= 0;
6275 /* Return most likely status. In fact, it
6276 * might be the only possible status */
6277 status
= TP_EC_FAN_AUTO
;
6280 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
6281 (status
!= 0) ? "enabled" : "disabled");
6283 rc
= fan_get_speed(&speed
);
6287 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
6289 if (status
& TP_EC_FAN_FULLSPEED
)
6290 /* Disengaged mode takes precedence */
6291 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
6292 else if (status
& TP_EC_FAN_AUTO
)
6293 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
6295 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
6298 case TPACPI_FAN_NONE
:
6300 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
6303 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
6304 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
6306 switch (fan_control_access_mode
) {
6307 case TPACPI_FAN_WR_ACPI_SFAN
:
6308 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
6312 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
6313 "auto, disengaged, full-speed)\n");
6318 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
6319 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
6320 "commands:\twatchdog <timeout> (<timeout> "
6321 "is 0 (off), 1-120 (seconds))\n");
6323 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
6324 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
6325 " (<speed> is 0-65535)\n");
6330 static int fan_write_cmd_level(const char *cmd
, int *rc
)
6334 if (strlencmp(cmd
, "level auto") == 0)
6335 level
= TP_EC_FAN_AUTO
;
6336 else if ((strlencmp(cmd
, "level disengaged") == 0) |
6337 (strlencmp(cmd
, "level full-speed") == 0))
6338 level
= TP_EC_FAN_FULLSPEED
;
6339 else if (sscanf(cmd
, "level %d", &level
) != 1)
6342 *rc
= fan_set_level_safe(level
);
6344 printk(TPACPI_ERR
"level command accepted for unsupported "
6345 "access mode %d", fan_control_access_mode
);
6350 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
6352 if (strlencmp(cmd
, "enable") != 0)
6355 *rc
= fan_set_enable();
6357 printk(TPACPI_ERR
"enable command accepted for unsupported "
6358 "access mode %d", fan_control_access_mode
);
6363 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
6365 if (strlencmp(cmd
, "disable") != 0)
6368 *rc
= fan_set_disable();
6370 printk(TPACPI_ERR
"disable command accepted for unsupported "
6371 "access mode %d", fan_control_access_mode
);
6376 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
6381 * Support speed <low> <medium> <high> ? */
6383 if (sscanf(cmd
, "speed %d", &speed
) != 1)
6386 *rc
= fan_set_speed(speed
);
6388 printk(TPACPI_ERR
"speed command accepted for unsupported "
6389 "access mode %d", fan_control_access_mode
);
6394 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
6398 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
6401 if (interval
< 0 || interval
> 120)
6404 fan_watchdog_maxinterval
= interval
;
6409 static int fan_write(char *buf
)
6414 while (!rc
&& (cmd
= next_cmd(&buf
))) {
6415 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
6416 fan_write_cmd_level(cmd
, &rc
)) &&
6417 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
6418 (fan_write_cmd_enable(cmd
, &rc
) ||
6419 fan_write_cmd_disable(cmd
, &rc
) ||
6420 fan_write_cmd_watchdog(cmd
, &rc
))) &&
6421 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
6422 fan_write_cmd_speed(cmd
, &rc
))
6426 fan_watchdog_reset();
6432 static struct ibm_struct fan_driver_data
= {
6437 .suspend
= fan_suspend
,
6438 .resume
= fan_resume
,
6441 /****************************************************************************
6442 ****************************************************************************
6446 ****************************************************************************
6447 ****************************************************************************/
6449 /* sysfs name ---------------------------------------------------------- */
6450 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
6451 struct device_attribute
*attr
,
6454 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
6457 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
6458 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
6460 /* --------------------------------------------------------------------- */
6463 static struct proc_dir_entry
*proc_dir
;
6466 * Module and infrastructure proble, init and exit handling
6469 static int force_load
;
6471 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
6472 static const char * __init
str_supported(int is_supported
)
6474 static char text_unsupported
[] __initdata
= "not supported";
6476 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
6478 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
6480 static void ibm_exit(struct ibm_struct
*ibm
)
6482 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
6484 list_del_init(&ibm
->all_drivers
);
6486 if (ibm
->flags
.acpi_notify_installed
) {
6487 dbg_printk(TPACPI_DBG_EXIT
,
6488 "%s: acpi_remove_notify_handler\n", ibm
->name
);
6490 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
6492 dispatch_acpi_notify
);
6493 ibm
->flags
.acpi_notify_installed
= 0;
6494 ibm
->flags
.acpi_notify_installed
= 0;
6497 if (ibm
->flags
.proc_created
) {
6498 dbg_printk(TPACPI_DBG_EXIT
,
6499 "%s: remove_proc_entry\n", ibm
->name
);
6500 remove_proc_entry(ibm
->name
, proc_dir
);
6501 ibm
->flags
.proc_created
= 0;
6504 if (ibm
->flags
.acpi_driver_registered
) {
6505 dbg_printk(TPACPI_DBG_EXIT
,
6506 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
6508 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
6509 kfree(ibm
->acpi
->driver
);
6510 ibm
->acpi
->driver
= NULL
;
6511 ibm
->flags
.acpi_driver_registered
= 0;
6514 if (ibm
->flags
.init_called
&& ibm
->exit
) {
6516 ibm
->flags
.init_called
= 0;
6519 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
6522 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
6525 struct ibm_struct
*ibm
= iibm
->data
;
6526 struct proc_dir_entry
*entry
;
6528 BUG_ON(ibm
== NULL
);
6530 INIT_LIST_HEAD(&ibm
->all_drivers
);
6532 if (ibm
->flags
.experimental
&& !experimental
)
6535 dbg_printk(TPACPI_DBG_INIT
,
6536 "probing for %s\n", ibm
->name
);
6539 ret
= iibm
->init(iibm
);
6541 return 0; /* probe failed */
6545 ibm
->flags
.init_called
= 1;
6549 if (ibm
->acpi
->hid
) {
6550 ret
= register_tpacpi_subdriver(ibm
);
6555 if (ibm
->acpi
->notify
) {
6556 ret
= setup_acpi_notify(ibm
);
6557 if (ret
== -ENODEV
) {
6558 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
6568 dbg_printk(TPACPI_DBG_INIT
,
6569 "%s installed\n", ibm
->name
);
6572 entry
= create_proc_entry(ibm
->name
,
6573 S_IFREG
| S_IRUGO
| S_IWUSR
,
6576 printk(TPACPI_ERR
"unable to create proc entry %s\n",
6581 entry
->owner
= THIS_MODULE
;
6583 entry
->read_proc
= &dispatch_procfs_read
;
6585 entry
->write_proc
= &dispatch_procfs_write
;
6586 ibm
->flags
.proc_created
= 1;
6589 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
6594 dbg_printk(TPACPI_DBG_INIT
,
6595 "%s: at error exit path with result %d\n",
6599 return (ret
< 0)? ret
: 0;
6604 /* returns 0 - probe ok, or < 0 - probe error.
6605 * Probe ok doesn't mean thinkpad found.
6606 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
6607 static int __must_check __init
get_thinkpad_model_data(
6608 struct thinkpad_id_data
*tp
)
6610 const struct dmi_device
*dev
= NULL
;
6611 char ec_fw_string
[18];
6617 memset(tp
, 0, sizeof(*tp
));
6619 if (dmi_name_in_vendors("IBM"))
6620 tp
->vendor
= PCI_VENDOR_ID_IBM
;
6621 else if (dmi_name_in_vendors("LENOVO"))
6622 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
6626 s
= dmi_get_system_info(DMI_BIOS_VERSION
);
6627 tp
->bios_version_str
= kstrdup(s
, GFP_KERNEL
);
6628 if (s
&& !tp
->bios_version_str
)
6630 if (!tp
->bios_version_str
)
6632 tp
->bios_model
= tp
->bios_version_str
[0]
6633 | (tp
->bios_version_str
[1] << 8);
6636 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
6637 * X32 or newer, all Z series; Some models must have an
6638 * up-to-date BIOS or they will not be detected.
6640 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
6642 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
6643 if (sscanf(dev
->name
,
6644 "IBM ThinkPad Embedded Controller -[%17c",
6645 ec_fw_string
) == 1) {
6646 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
6647 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
6649 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
6650 if (!tp
->ec_version_str
)
6652 tp
->ec_model
= ec_fw_string
[0]
6653 | (ec_fw_string
[1] << 8);
6658 s
= dmi_get_system_info(DMI_PRODUCT_VERSION
);
6659 if (s
&& !strnicmp(s
, "ThinkPad", 8)) {
6660 tp
->model_str
= kstrdup(s
, GFP_KERNEL
);
6665 s
= dmi_get_system_info(DMI_PRODUCT_NAME
);
6666 tp
->nummodel_str
= kstrdup(s
, GFP_KERNEL
);
6667 if (s
&& !tp
->nummodel_str
)
6673 static int __init
probe_for_thinkpad(void)
6681 * Non-ancient models have better DMI tagging, but very old models
6684 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
6686 /* ec is required because many other handles are relative to it */
6687 TPACPI_ACPIHANDLE_INIT(ec
);
6691 "Not yet supported ThinkPad detected!\n");
6696 * Risks a regression on very old machines, but reduces potential
6697 * false positives a damn great deal
6700 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
6702 if (!is_thinkpad
&& !force_load
)
6709 /* Module init, exit, parameters */
6711 static struct ibm_init_struct ibms_init
[] __initdata
= {
6713 .init
= thinkpad_acpi_driver_init
,
6714 .data
= &thinkpad_acpi_driver_data
,
6717 .init
= hotkey_init
,
6718 .data
= &hotkey_driver_data
,
6721 .init
= bluetooth_init
,
6722 .data
= &bluetooth_driver_data
,
6726 .data
= &wan_driver_data
,
6728 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
6731 .data
= &video_driver_data
,
6736 .data
= &light_driver_data
,
6738 #ifdef CONFIG_THINKPAD_ACPI_DOCK
6741 .data
= &dock_driver_data
[0],
6745 .data
= &dock_driver_data
[1],
6748 #ifdef CONFIG_THINKPAD_ACPI_BAY
6751 .data
= &bay_driver_data
,
6756 .data
= &cmos_driver_data
,
6760 .data
= &led_driver_data
,
6764 .data
= &beep_driver_data
,
6767 .init
= thermal_init
,
6768 .data
= &thermal_driver_data
,
6771 .data
= &ecdump_driver_data
,
6774 .init
= brightness_init
,
6775 .data
= &brightness_driver_data
,
6778 .data
= &volume_driver_data
,
6782 .data
= &fan_driver_data
,
6786 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
6789 struct ibm_struct
*ibm
;
6791 if (!kp
|| !kp
->name
|| !val
)
6794 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
6795 ibm
= ibms_init
[i
].data
;
6796 WARN_ON(ibm
== NULL
);
6798 if (!ibm
|| !ibm
->name
)
6801 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
6802 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
6804 strcpy(ibms_init
[i
].param
, val
);
6805 strcat(ibms_init
[i
].param
, ",");
6813 module_param(experimental
, int, 0);
6814 MODULE_PARM_DESC(experimental
,
6815 "Enables experimental features when non-zero");
6817 module_param_named(debug
, dbg_level
, uint
, 0);
6818 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
6820 module_param(force_load
, bool, 0);
6821 MODULE_PARM_DESC(force_load
,
6822 "Attempts to load the driver even on a "
6823 "mis-identified ThinkPad when true");
6825 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
6826 MODULE_PARM_DESC(fan_control
,
6827 "Enables setting fan parameters features when true");
6829 module_param_named(brightness_mode
, brightness_mode
, int, 0);
6830 MODULE_PARM_DESC(brightness_mode
,
6831 "Selects brightness control strategy: "
6832 "0=auto, 1=EC, 2=CMOS, 3=both");
6834 module_param(brightness_enable
, uint
, 0);
6835 MODULE_PARM_DESC(brightness_enable
,
6836 "Enables backlight control when 1, disables when 0");
6838 module_param(hotkey_report_mode
, uint
, 0);
6839 MODULE_PARM_DESC(hotkey_report_mode
,
6840 "used for backwards compatibility with userspace, "
6841 "see documentation");
6843 #define TPACPI_PARAM(feature) \
6844 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
6845 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
6846 "at module load, see documentation")
6848 TPACPI_PARAM(hotkey
);
6849 TPACPI_PARAM(bluetooth
);
6850 TPACPI_PARAM(video
);
6851 TPACPI_PARAM(light
);
6852 #ifdef CONFIG_THINKPAD_ACPI_DOCK
6855 #ifdef CONFIG_THINKPAD_ACPI_BAY
6857 #endif /* CONFIG_THINKPAD_ACPI_BAY */
6861 TPACPI_PARAM(ecdump
);
6862 TPACPI_PARAM(brightness
);
6863 TPACPI_PARAM(volume
);
6866 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES
6867 module_param(dbg_wlswemul
, uint
, 0);
6868 MODULE_PARM_DESC(dbg_wlswemul
, "Enables WLSW emulation");
6869 module_param_named(wlsw_state
, tpacpi_wlsw_emulstate
, bool, 0);
6870 MODULE_PARM_DESC(wlsw_state
,
6871 "Initial state of the emulated WLSW switch");
6873 module_param(dbg_bluetoothemul
, uint
, 0);
6874 MODULE_PARM_DESC(dbg_bluetoothemul
, "Enables bluetooth switch emulation");
6875 module_param_named(bluetooth_state
, tpacpi_bluetooth_emulstate
, bool, 0);
6876 MODULE_PARM_DESC(bluetooth_state
,
6877 "Initial state of the emulated bluetooth switch");
6879 module_param(dbg_wwanemul
, uint
, 0);
6880 MODULE_PARM_DESC(dbg_wwanemul
, "Enables WWAN switch emulation");
6881 module_param_named(wwan_state
, tpacpi_wwan_emulstate
, bool, 0);
6882 MODULE_PARM_DESC(wwan_state
,
6883 "Initial state of the emulated WWAN switch");
6886 static void thinkpad_acpi_module_exit(void)
6888 struct ibm_struct
*ibm
, *itmp
;
6890 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
6892 list_for_each_entry_safe_reverse(ibm
, itmp
,
6893 &tpacpi_all_drivers
,
6898 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
6900 if (tpacpi_inputdev
) {
6901 if (tp_features
.input_device_registered
)
6902 input_unregister_device(tpacpi_inputdev
);
6904 input_free_device(tpacpi_inputdev
);
6908 hwmon_device_unregister(tpacpi_hwmon
);
6910 if (tp_features
.sensors_pdev_attrs_registered
)
6911 device_remove_file(&tpacpi_sensors_pdev
->dev
,
6912 &dev_attr_thinkpad_acpi_pdev_name
);
6913 if (tpacpi_sensors_pdev
)
6914 platform_device_unregister(tpacpi_sensors_pdev
);
6916 platform_device_unregister(tpacpi_pdev
);
6918 if (tp_features
.sensors_pdrv_attrs_registered
)
6919 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
6920 if (tp_features
.platform_drv_attrs_registered
)
6921 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
6923 if (tp_features
.sensors_pdrv_registered
)
6924 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
6926 if (tp_features
.platform_drv_registered
)
6927 platform_driver_unregister(&tpacpi_pdriver
);
6930 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
6933 destroy_workqueue(tpacpi_wq
);
6935 kfree(thinkpad_id
.bios_version_str
);
6936 kfree(thinkpad_id
.ec_version_str
);
6937 kfree(thinkpad_id
.model_str
);
6941 static int __init
thinkpad_acpi_module_init(void)
6945 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
6947 /* Parameter checking */
6948 if (hotkey_report_mode
> 2)
6951 /* Driver-level probe */
6953 ret
= get_thinkpad_model_data(&thinkpad_id
);
6956 "unable to get DMI data: %d\n", ret
);
6957 thinkpad_acpi_module_exit();
6960 ret
= probe_for_thinkpad();
6962 thinkpad_acpi_module_exit();
6966 /* Driver initialization */
6968 TPACPI_ACPIHANDLE_INIT(ecrd
);
6969 TPACPI_ACPIHANDLE_INIT(ecwr
);
6971 tpacpi_wq
= create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME
);
6973 thinkpad_acpi_module_exit();
6977 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
6980 "unable to create proc dir " TPACPI_PROC_DIR
);
6981 thinkpad_acpi_module_exit();
6984 proc_dir
->owner
= THIS_MODULE
;
6986 ret
= platform_driver_register(&tpacpi_pdriver
);
6989 "unable to register main platform driver\n");
6990 thinkpad_acpi_module_exit();
6993 tp_features
.platform_drv_registered
= 1;
6995 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
6998 "unable to register hwmon platform driver\n");
6999 thinkpad_acpi_module_exit();
7002 tp_features
.sensors_pdrv_registered
= 1;
7004 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
7006 tp_features
.platform_drv_attrs_registered
= 1;
7007 ret
= tpacpi_create_driver_attributes(
7008 &tpacpi_hwmon_pdriver
.driver
);
7012 "unable to create sysfs driver attributes\n");
7013 thinkpad_acpi_module_exit();
7016 tp_features
.sensors_pdrv_attrs_registered
= 1;
7019 /* Device initialization */
7020 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
7022 if (IS_ERR(tpacpi_pdev
)) {
7023 ret
= PTR_ERR(tpacpi_pdev
);
7025 printk(TPACPI_ERR
"unable to register platform device\n");
7026 thinkpad_acpi_module_exit();
7029 tpacpi_sensors_pdev
= platform_device_register_simple(
7030 TPACPI_HWMON_DRVR_NAME
,
7032 if (IS_ERR(tpacpi_sensors_pdev
)) {
7033 ret
= PTR_ERR(tpacpi_sensors_pdev
);
7034 tpacpi_sensors_pdev
= NULL
;
7036 "unable to register hwmon platform device\n");
7037 thinkpad_acpi_module_exit();
7040 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
7041 &dev_attr_thinkpad_acpi_pdev_name
);
7044 "unable to create sysfs hwmon device attributes\n");
7045 thinkpad_acpi_module_exit();
7048 tp_features
.sensors_pdev_attrs_registered
= 1;
7049 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
7050 if (IS_ERR(tpacpi_hwmon
)) {
7051 ret
= PTR_ERR(tpacpi_hwmon
);
7052 tpacpi_hwmon
= NULL
;
7053 printk(TPACPI_ERR
"unable to register hwmon device\n");
7054 thinkpad_acpi_module_exit();
7057 mutex_init(&tpacpi_inputdev_send_mutex
);
7058 tpacpi_inputdev
= input_allocate_device();
7059 if (!tpacpi_inputdev
) {
7060 printk(TPACPI_ERR
"unable to allocate input device\n");
7061 thinkpad_acpi_module_exit();
7064 /* Prepare input device, but don't register */
7065 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
7066 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
7067 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
7068 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
7069 thinkpad_id
.vendor
:
7071 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
7072 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
7074 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
7075 ret
= ibm_init(&ibms_init
[i
]);
7076 if (ret
>= 0 && *ibms_init
[i
].param
)
7077 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
7079 thinkpad_acpi_module_exit();
7083 ret
= input_register_device(tpacpi_inputdev
);
7085 printk(TPACPI_ERR
"unable to register input device\n");
7086 thinkpad_acpi_module_exit();
7089 tp_features
.input_device_registered
= 1;
7092 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
7096 /* Please remove this in year 2009 */
7097 MODULE_ALIAS("ibm_acpi");
7099 MODULE_ALIAS(TPACPI_DRVR_SHORTNAME
);
7102 * DMI matching for module autoloading
7104 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
7105 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
7107 * Only models listed in thinkwiki will be supported, so add yours
7108 * if it is not there yet.
7110 #define IBM_BIOS_MODULE_ALIAS(__type) \
7111 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
7113 /* Non-ancient thinkpads */
7114 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
7115 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
7117 /* Ancient thinkpad BIOSes have to be identified by
7118 * BIOS type or model number, and there are far less
7119 * BIOS types than model numbers... */
7120 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
7121 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
7122 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
7124 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
7125 MODULE_DESCRIPTION(TPACPI_DESC
);
7126 MODULE_VERSION(TPACPI_VERSION
);
7127 MODULE_LICENSE("GPL");
7129 module_init(thinkpad_acpi_module_init
);
7130 module_exit(thinkpad_acpi_module_exit
);