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.19-20080229"
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 <asm/uaccess.h>
72 #include <linux/dmi.h>
73 #include <linux/jiffies.h>
74 #include <linux/workqueue.h>
76 #include <acpi/acpi_drivers.h>
77 #include <acpi/acnamesp.h>
79 #include <linux/pci_ids.h>
82 /* ThinkPad CMOS commands */
83 #define TP_CMOS_VOLUME_DOWN 0
84 #define TP_CMOS_VOLUME_UP 1
85 #define TP_CMOS_VOLUME_MUTE 2
86 #define TP_CMOS_BRIGHTNESS_UP 4
87 #define TP_CMOS_BRIGHTNESS_DOWN 5
91 TP_NVRAM_ADDR_HK2
= 0x57,
92 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
93 TP_NVRAM_ADDR_VIDEO
= 0x59,
94 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
95 TP_NVRAM_ADDR_MIXER
= 0x60,
100 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
101 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
102 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
103 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
104 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
105 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
106 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
107 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
108 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
109 TP_NVRAM_MASK_MUTE
= 0x40,
110 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
111 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
112 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
116 #define TPACPI_ACPI_HKEY_HID "IBM0068"
119 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
120 #define TPACPI_HKEY_INPUT_VERSION 0x4101
123 /****************************************************************************
127 #define TPACPI_NAME "thinkpad"
128 #define TPACPI_DESC "ThinkPad ACPI Extras"
129 #define TPACPI_FILE TPACPI_NAME "_acpi"
130 #define TPACPI_URL "http://ibm-acpi.sf.net/"
131 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
133 #define TPACPI_PROC_DIR "ibm"
134 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
135 #define TPACPI_DRVR_NAME TPACPI_FILE
136 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
138 #define TPACPI_MAX_ACPI_ARGS 3
141 #define TPACPI_LOG TPACPI_FILE ": "
142 #define TPACPI_ERR KERN_ERR TPACPI_LOG
143 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
144 #define TPACPI_INFO KERN_INFO TPACPI_LOG
145 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
147 #define TPACPI_DBG_ALL 0xffff
148 #define TPACPI_DBG_ALL 0xffff
149 #define TPACPI_DBG_INIT 0x0001
150 #define TPACPI_DBG_EXIT 0x0002
151 #define dbg_printk(a_dbg_level, format, arg...) \
152 do { if (dbg_level & a_dbg_level) \
153 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
155 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
156 #define vdbg_printk(a_dbg_level, format, arg...) \
157 dbg_printk(a_dbg_level, format, ## arg)
158 static const char *str_supported(int is_supported
);
160 #define vdbg_printk(a_dbg_level, format, arg...)
163 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
164 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
165 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
168 /****************************************************************************
169 * Driver-wide structs and misc. variables
174 struct tp_acpi_drv_struct
{
175 const struct acpi_device_id
*hid
;
176 struct acpi_driver
*driver
;
178 void (*notify
) (struct ibm_struct
*, u32
);
181 struct acpi_device
*device
;
187 int (*read
) (char *);
188 int (*write
) (char *);
190 void (*resume
) (void);
191 void (*suspend
) (pm_message_t state
);
193 struct list_head all_drivers
;
195 struct tp_acpi_drv_struct
*acpi
;
198 u8 acpi_driver_registered
:1;
199 u8 acpi_notify_installed
:1;
206 struct ibm_init_struct
{
209 int (*init
) (struct ibm_init_struct
*);
210 struct ibm_struct
*data
;
214 #ifdef CONFIG_THINKPAD_ACPI_BAY
227 u32 bright_16levels
:1;
228 u32 bright_acpimode
:1;
230 u32 fan_ctrl_status_undef
:1;
231 u32 input_device_registered
:1;
232 u32 platform_drv_registered
:1;
233 u32 platform_drv_attrs_registered
:1;
234 u32 sensors_pdrv_registered
:1;
235 u32 sensors_pdrv_attrs_registered
:1;
236 u32 sensors_pdev_attrs_registered
:1;
237 u32 hotkey_poll_active
:1;
241 u16 hotkey_mask_ff
:1;
244 struct thinkpad_id_data
{
245 unsigned int vendor
; /* ThinkPad vendor:
246 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
248 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
249 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
251 u16 bios_model
; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */
256 static struct thinkpad_id_data thinkpad_id
;
259 TPACPI_LIFE_INIT
= 0,
264 static int experimental
;
265 static u32 dbg_level
;
267 /****************************************************************************
268 ****************************************************************************
270 * ACPI Helpers and device model
272 ****************************************************************************
273 ****************************************************************************/
275 /*************************************************************************
279 static acpi_handle root_handle
;
281 #define TPACPI_HANDLE(object, parent, paths...) \
282 static acpi_handle object##_handle; \
283 static acpi_handle *object##_parent = &parent##_handle; \
284 static char *object##_path; \
285 static char *object##_paths[] = { paths }
287 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
288 "\\_SB.PCI.ISA.EC", /* 570 */
289 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
290 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
291 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
292 "\\_SB.PCI0.ICH3.EC0", /* R31 */
293 "\\_SB.PCI0.LPC.EC", /* all others */
296 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
297 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
299 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
301 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
302 "\\CMS", /* R40, R40e */
305 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
306 "^HKEY", /* R30, R31 */
307 "HKEY", /* all others */
310 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
311 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
312 "\\_SB.PCI0.VID0", /* 770e */
313 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
314 "\\_SB.PCI0.AGP.VID", /* all others */
318 /*************************************************************************
322 static int acpi_evalf(acpi_handle handle
,
323 void *res
, char *method
, char *fmt
, ...)
326 struct acpi_object_list params
;
327 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
328 struct acpi_buffer result
, *resultp
;
329 union acpi_object out_obj
;
337 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
350 params
.pointer
= &in_objs
[0];
357 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
358 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
360 /* add more types as needed */
362 printk(TPACPI_ERR
"acpi_evalf() called "
363 "with invalid format character '%c'\n", c
);
369 if (res_type
!= 'v') {
370 result
.length
= sizeof(out_obj
);
371 result
.pointer
= &out_obj
;
376 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
381 *(int *)res
= out_obj
.integer
.value
;
382 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
385 success
= status
== AE_OK
;
387 /* add more types as needed */
389 printk(TPACPI_ERR
"acpi_evalf() called "
390 "with invalid format character '%c'\n", res_type
);
394 if (!success
&& !quiet
)
395 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
396 method
, fmt0
, status
);
401 static int acpi_ec_read(int i
, u8
*p
)
406 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
410 if (ec_read(i
, p
) < 0)
417 static int acpi_ec_write(int i
, u8 v
)
420 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
423 if (ec_write(i
, v
) < 0)
430 #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY)
431 static int _sta(acpi_handle handle
)
435 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
442 static int issue_thinkpad_cmos_command(int cmos_cmd
)
447 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
453 /*************************************************************************
457 #define TPACPI_ACPIHANDLE_INIT(object) \
458 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
459 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
461 static void drv_acpi_handle_init(char *name
,
462 acpi_handle
*handle
, acpi_handle parent
,
463 char **paths
, int num_paths
, char **path
)
468 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
471 for (i
= 0; i
< num_paths
; i
++) {
472 status
= acpi_get_handle(parent
, paths
[i
], handle
);
473 if (ACPI_SUCCESS(status
)) {
475 dbg_printk(TPACPI_DBG_INIT
,
476 "Found ACPI handle %s for %s\n",
482 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
487 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
489 struct ibm_struct
*ibm
= data
;
491 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
494 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
497 ibm
->acpi
->notify(ibm
, event
);
500 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
507 if (!*ibm
->acpi
->handle
)
510 vdbg_printk(TPACPI_DBG_INIT
,
511 "setting up ACPI notify for %s\n", ibm
->name
);
513 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
515 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
520 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
521 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
522 TPACPI_ACPI_EVENT_PREFIX
,
525 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
526 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
527 if (ACPI_FAILURE(status
)) {
528 if (status
== AE_ALREADY_EXISTS
) {
530 "another device driver is already "
531 "handling %s events\n", ibm
->name
);
534 "acpi_install_notify_handler(%s) failed: %d\n",
539 ibm
->flags
.acpi_notify_installed
= 1;
543 static int __init
tpacpi_device_add(struct acpi_device
*device
)
548 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
552 dbg_printk(TPACPI_DBG_INIT
,
553 "registering %s as an ACPI driver\n", ibm
->name
);
557 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
558 if (!ibm
->acpi
->driver
) {
559 printk(TPACPI_ERR
"kzalloc(ibm->driver) failed\n");
563 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
564 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
566 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
568 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
570 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
572 kfree(ibm
->acpi
->driver
);
573 ibm
->acpi
->driver
= NULL
;
575 ibm
->flags
.acpi_driver_registered
= 1;
581 /****************************************************************************
582 ****************************************************************************
586 ****************************************************************************
587 ****************************************************************************/
589 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
590 int count
, int *eof
, void *data
)
592 struct ibm_struct
*ibm
= data
;
595 if (!ibm
|| !ibm
->read
)
598 len
= ibm
->read(page
);
602 if (len
<= off
+ count
)
614 static int dispatch_procfs_write(struct file
*file
,
615 const char __user
*userbuf
,
616 unsigned long count
, void *data
)
618 struct ibm_struct
*ibm
= data
;
622 if (!ibm
|| !ibm
->write
)
625 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
629 if (copy_from_user(kernbuf
, userbuf
, count
)) {
635 strcat(kernbuf
, ",");
636 ret
= ibm
->write(kernbuf
);
645 static char *next_cmd(char **cmds
)
650 while ((end
= strchr(start
, ',')) && end
== start
)
662 /****************************************************************************
663 ****************************************************************************
665 * Device model: input, hwmon and platform
667 ****************************************************************************
668 ****************************************************************************/
670 static struct platform_device
*tpacpi_pdev
;
671 static struct platform_device
*tpacpi_sensors_pdev
;
672 static struct device
*tpacpi_hwmon
;
673 static struct input_dev
*tpacpi_inputdev
;
674 static struct mutex tpacpi_inputdev_send_mutex
;
675 static LIST_HEAD(tpacpi_all_drivers
);
677 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
680 struct ibm_struct
*ibm
, *itmp
;
682 list_for_each_entry_safe(ibm
, itmp
,
686 (ibm
->suspend
)(state
);
692 static int tpacpi_resume_handler(struct platform_device
*pdev
)
694 struct ibm_struct
*ibm
, *itmp
;
696 list_for_each_entry_safe(ibm
, itmp
,
706 static struct platform_driver tpacpi_pdriver
= {
708 .name
= TPACPI_DRVR_NAME
,
709 .owner
= THIS_MODULE
,
711 .suspend
= tpacpi_suspend_handler
,
712 .resume
= tpacpi_resume_handler
,
715 static struct platform_driver tpacpi_hwmon_pdriver
= {
717 .name
= TPACPI_HWMON_DRVR_NAME
,
718 .owner
= THIS_MODULE
,
722 /*************************************************************************
723 * sysfs support helpers
726 struct attribute_set
{
727 unsigned int members
, max_members
;
728 struct attribute_group group
;
731 struct attribute_set_obj
{
732 struct attribute_set s
;
734 } __attribute__((packed
));
736 static struct attribute_set
*create_attr_set(unsigned int max_members
,
739 struct attribute_set_obj
*sobj
;
741 if (max_members
== 0)
744 /* Allocates space for implicit NULL at the end too */
745 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
746 max_members
* sizeof(struct attribute
*),
750 sobj
->s
.max_members
= max_members
;
751 sobj
->s
.group
.attrs
= &sobj
->a
;
752 sobj
->s
.group
.name
= name
;
757 #define destroy_attr_set(_set) \
760 /* not multi-threaded safe, use it in a single thread per set */
761 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
766 if (s
->members
>= s
->max_members
)
769 s
->group
.attrs
[s
->members
] = attr
;
775 static int add_many_to_attr_set(struct attribute_set
*s
,
776 struct attribute
**attr
,
781 for (i
= 0; i
< count
; i
++) {
782 res
= add_to_attr_set(s
, attr
[i
]);
790 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
792 sysfs_remove_group(kobj
, &s
->group
);
796 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
797 sysfs_create_group(_kobj, &_attr_set->group)
799 static int parse_strtoul(const char *buf
,
800 unsigned long max
, unsigned long *value
)
804 while (*buf
&& isspace(*buf
))
806 *value
= simple_strtoul(buf
, &endp
, 0);
807 while (*endp
&& isspace(*endp
))
809 if (*endp
|| *value
> max
)
815 static int __init
tpacpi_query_bcl_levels(acpi_handle handle
)
817 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
818 union acpi_object
*obj
;
821 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
822 obj
= (union acpi_object
*)buffer
.pointer
;
823 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
824 printk(TPACPI_ERR
"Unknown _BCL data, "
825 "please report this to %s\n", TPACPI_MAIL
);
828 rc
= obj
->package
.count
;
834 kfree(buffer
.pointer
);
838 static acpi_status __init
tpacpi_acpi_walk_find_bcl(acpi_handle handle
,
839 u32 lvl
, void *context
, void **rv
)
841 char name
[ACPI_PATH_SEGMENT_LENGTH
];
842 struct acpi_buffer buffer
= { sizeof(name
), &name
};
844 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
845 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
847 **(int **)rv
= tpacpi_query_bcl_levels(handle
);
848 return AE_CTRL_TERMINATE
;
855 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
857 static int __init
tpacpi_check_std_acpi_brightness_support(void)
861 void *bcl_ptr
= &bcl_levels
;
864 TPACPI_ACPIHANDLE_INIT(vid
);
870 * Search for a _BCL method, and execute it. This is safe on all
871 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
872 * BIOS in ACPI backlight control mode. We do NOT have to care
873 * about calling the _BCL method in an enabled video device, any
874 * will do for our purposes.
877 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
878 tpacpi_acpi_walk_find_bcl
, NULL
,
881 if (ACPI_SUCCESS(status
) && bcl_levels
> 2) {
882 tp_features
.bright_acpimode
= 1;
883 return (bcl_levels
- 2);
889 /*************************************************************************
890 * thinkpad-acpi driver attributes
893 /* interface_version --------------------------------------------------- */
894 static ssize_t
tpacpi_driver_interface_version_show(
895 struct device_driver
*drv
,
898 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
901 static DRIVER_ATTR(interface_version
, S_IRUGO
,
902 tpacpi_driver_interface_version_show
, NULL
);
904 /* debug_level --------------------------------------------------------- */
905 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
908 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
911 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
912 const char *buf
, size_t count
)
916 if (parse_strtoul(buf
, 0xffff, &t
))
924 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
925 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
927 /* version ------------------------------------------------------------- */
928 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
931 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
932 TPACPI_DESC
, TPACPI_VERSION
);
935 static DRIVER_ATTR(version
, S_IRUGO
,
936 tpacpi_driver_version_show
, NULL
);
938 /* --------------------------------------------------------------------- */
940 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
941 &driver_attr_debug_level
, &driver_attr_version
,
942 &driver_attr_interface_version
,
945 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
951 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
952 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
959 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
963 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
964 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
967 /****************************************************************************
968 ****************************************************************************
972 ****************************************************************************
973 ****************************************************************************/
975 /*************************************************************************
976 * thinkpad-acpi init subdriver
979 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
981 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
982 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
984 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
985 (thinkpad_id
.bios_version_str
) ?
986 thinkpad_id
.bios_version_str
: "unknown",
987 (thinkpad_id
.ec_version_str
) ?
988 thinkpad_id
.ec_version_str
: "unknown");
990 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
991 printk(TPACPI_INFO
"%s %s\n",
992 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
993 "IBM" : ((thinkpad_id
.vendor
==
994 PCI_VENDOR_ID_LENOVO
) ?
995 "Lenovo" : "Unknown vendor"),
996 thinkpad_id
.model_str
);
1001 static int thinkpad_acpi_driver_read(char *p
)
1005 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
1006 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
1011 static struct ibm_struct thinkpad_acpi_driver_data
= {
1013 .read
= thinkpad_acpi_driver_read
,
1016 /*************************************************************************
1020 enum { /* hot key scan codes (derived from ACPI DSDT) */
1021 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
1022 TP_ACPI_HOTKEYSCAN_FNF2
,
1023 TP_ACPI_HOTKEYSCAN_FNF3
,
1024 TP_ACPI_HOTKEYSCAN_FNF4
,
1025 TP_ACPI_HOTKEYSCAN_FNF5
,
1026 TP_ACPI_HOTKEYSCAN_FNF6
,
1027 TP_ACPI_HOTKEYSCAN_FNF7
,
1028 TP_ACPI_HOTKEYSCAN_FNF8
,
1029 TP_ACPI_HOTKEYSCAN_FNF9
,
1030 TP_ACPI_HOTKEYSCAN_FNF10
,
1031 TP_ACPI_HOTKEYSCAN_FNF11
,
1032 TP_ACPI_HOTKEYSCAN_FNF12
,
1033 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
1034 TP_ACPI_HOTKEYSCAN_FNINSERT
,
1035 TP_ACPI_HOTKEYSCAN_FNDELETE
,
1036 TP_ACPI_HOTKEYSCAN_FNHOME
,
1037 TP_ACPI_HOTKEYSCAN_FNEND
,
1038 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1039 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
1040 TP_ACPI_HOTKEYSCAN_FNSPACE
,
1041 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1042 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1043 TP_ACPI_HOTKEYSCAN_MUTE
,
1044 TP_ACPI_HOTKEYSCAN_THINKPAD
,
1047 enum { /* Keys available through NVRAM polling */
1048 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
1049 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
1052 enum { /* Positions of some of the keys in hotkey masks */
1053 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
1054 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
1055 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
1056 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
1057 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
1058 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
1059 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
1060 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
1061 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
1062 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
1063 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
1066 enum { /* NVRAM to ACPI HKEY group map */
1067 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
1068 TP_ACPI_HKEY_ZOOM_MASK
|
1069 TP_ACPI_HKEY_DISPSWTCH_MASK
|
1070 TP_ACPI_HKEY_HIBERNATE_MASK
,
1071 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
1072 TP_ACPI_HKEY_BRGHTDWN_MASK
,
1073 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
1074 TP_ACPI_HKEY_VOLDWN_MASK
|
1075 TP_ACPI_HKEY_MUTE_MASK
,
1078 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1079 struct tp_nvram_state
{
1080 u16 thinkpad_toggle
:1;
1082 u16 display_toggle
:1;
1083 u16 thinklight_toggle
:1;
1084 u16 hibernate_toggle
:1;
1085 u16 displayexp_toggle
:1;
1086 u16 display_state
:1;
1087 u16 brightness_toggle
:1;
1088 u16 volume_toggle
:1;
1091 u8 brightness_level
;
1095 static struct task_struct
*tpacpi_hotkey_task
;
1096 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1097 static int hotkey_poll_freq
= 10; /* Hz */
1098 static struct mutex hotkey_thread_mutex
;
1099 static struct mutex hotkey_thread_data_mutex
;
1100 static unsigned int hotkey_config_change
;
1102 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1104 #define hotkey_source_mask 0U
1106 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1108 static struct mutex hotkey_mutex
;
1110 static enum { /* Reasons for waking up */
1111 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1112 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1113 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1114 } hotkey_wakeup_reason
;
1116 static int hotkey_autosleep_ack
;
1118 static int hotkey_orig_status
;
1119 static u32 hotkey_orig_mask
;
1120 static u32 hotkey_all_mask
;
1121 static u32 hotkey_reserved_mask
;
1122 static u32 hotkey_mask
;
1124 static unsigned int hotkey_report_mode
;
1126 static u16
*hotkey_keycode_map
;
1128 static struct attribute_set
*hotkey_dev_attributes
;
1130 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1131 #define HOTKEY_CONFIG_CRITICAL_START \
1133 mutex_lock(&hotkey_thread_data_mutex); \
1134 hotkey_config_change++; \
1136 #define HOTKEY_CONFIG_CRITICAL_END \
1137 mutex_unlock(&hotkey_thread_data_mutex);
1139 #define HOTKEY_CONFIG_CRITICAL_START
1140 #define HOTKEY_CONFIG_CRITICAL_END
1141 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1143 /* HKEY.MHKG() return bits */
1144 #define TP_HOTKEY_TABLET_MASK (1 << 3)
1146 static int hotkey_get_wlsw(int *status
)
1148 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1153 static int hotkey_get_tablet_mode(int *status
)
1157 if (!acpi_evalf(hkey_handle
, &s
, "MHKG", "d"))
1160 *status
= ((s
& TP_HOTKEY_TABLET_MASK
) != 0);
1165 * Call with hotkey_mutex held
1167 static int hotkey_mask_get(void)
1171 if (tp_features
.hotkey_mask
) {
1172 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1175 hotkey_mask
= m
| (hotkey_source_mask
& hotkey_mask
);
1181 * Call with hotkey_mutex held
1183 static int hotkey_mask_set(u32 mask
)
1188 if (tp_features
.hotkey_mask
) {
1189 if (!tp_warned
.hotkey_mask_ff
&&
1190 (mask
== 0xffff || mask
== 0xffffff ||
1191 mask
== 0xffffffff)) {
1192 tp_warned
.hotkey_mask_ff
= 1;
1193 printk(TPACPI_NOTICE
1194 "setting the hotkey mask to 0x%08x is likely "
1195 "not the best way to go about it\n", mask
);
1196 printk(TPACPI_NOTICE
1197 "please consider using the driver defaults, "
1198 "and refer to up-to-date thinkpad-acpi "
1202 HOTKEY_CONFIG_CRITICAL_START
1203 for (i
= 0; i
< 32; i
++) {
1205 /* enable in firmware mask only keys not in NVRAM
1206 * mode, but enable the key in the cached hotkey_mask
1207 * regardless of mode, or the key will end up
1208 * disabled by hotkey_mask_get() */
1209 if (!acpi_evalf(hkey_handle
,
1210 NULL
, "MHKM", "vdd", i
+ 1,
1211 !!((mask
& ~hotkey_source_mask
) & m
))) {
1215 hotkey_mask
= (hotkey_mask
& ~m
) | (mask
& m
);
1218 HOTKEY_CONFIG_CRITICAL_END
1220 /* hotkey_mask_get must be called unconditionally below */
1221 if (!hotkey_mask_get() && !rc
&&
1222 (hotkey_mask
& ~hotkey_source_mask
) !=
1223 (mask
& ~hotkey_source_mask
)) {
1224 printk(TPACPI_NOTICE
1225 "requested hot key mask 0x%08x, but "
1226 "firmware forced it to 0x%08x\n",
1230 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1231 HOTKEY_CONFIG_CRITICAL_START
1232 hotkey_mask
= mask
& hotkey_source_mask
;
1233 HOTKEY_CONFIG_CRITICAL_END
1235 if (hotkey_mask
!= mask
) {
1236 printk(TPACPI_NOTICE
1237 "requested hot key mask 0x%08x, "
1238 "forced to 0x%08x (NVRAM poll mask is "
1239 "0x%08x): no firmware mask support\n",
1240 mask
, hotkey_mask
, hotkey_source_mask
);
1245 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1251 static int hotkey_status_get(int *status
)
1253 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1259 static int hotkey_status_set(int status
)
1261 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1267 static void tpacpi_input_send_radiosw(void)
1271 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
1272 mutex_lock(&tpacpi_inputdev_send_mutex
);
1274 input_report_switch(tpacpi_inputdev
,
1276 input_sync(tpacpi_inputdev
);
1278 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1282 static void tpacpi_input_send_tabletsw(void)
1286 if (tp_features
.hotkey_tablet
&&
1287 !hotkey_get_tablet_mode(&state
)) {
1288 mutex_lock(&tpacpi_inputdev_send_mutex
);
1290 input_report_switch(tpacpi_inputdev
,
1291 SW_TABLET_MODE
, !!state
);
1292 input_sync(tpacpi_inputdev
);
1294 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1298 static void tpacpi_input_send_key(unsigned int scancode
)
1300 unsigned int keycode
;
1302 keycode
= hotkey_keycode_map
[scancode
];
1304 if (keycode
!= KEY_RESERVED
) {
1305 mutex_lock(&tpacpi_inputdev_send_mutex
);
1307 input_report_key(tpacpi_inputdev
, keycode
, 1);
1308 if (keycode
== KEY_UNKNOWN
)
1309 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1311 input_sync(tpacpi_inputdev
);
1313 input_report_key(tpacpi_inputdev
, keycode
, 0);
1314 if (keycode
== KEY_UNKNOWN
)
1315 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1317 input_sync(tpacpi_inputdev
);
1319 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1323 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1324 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
1326 static void tpacpi_hotkey_send_key(unsigned int scancode
)
1328 tpacpi_input_send_key(scancode
);
1329 if (hotkey_report_mode
< 2) {
1330 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
1331 0x80, 0x1001 + scancode
);
1335 static void hotkey_read_nvram(struct tp_nvram_state
*n
, u32 m
)
1339 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
1340 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
1341 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
1342 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
1343 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
1344 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
1346 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
1347 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
1348 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
1350 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
1351 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
1352 n
->displayexp_toggle
=
1353 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
1355 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
1356 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
1357 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
1358 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
1359 n
->brightness_toggle
=
1360 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
1362 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
1363 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
1364 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
1365 >> TP_NVRAM_POS_LEVEL_VOLUME
;
1366 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
1367 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
1371 #define TPACPI_COMPARE_KEY(__scancode, __member) \
1373 if ((mask & (1 << __scancode)) && \
1374 oldn->__member != newn->__member) \
1375 tpacpi_hotkey_send_key(__scancode); \
1378 #define TPACPI_MAY_SEND_KEY(__scancode) \
1379 do { if (mask & (1 << __scancode)) \
1380 tpacpi_hotkey_send_key(__scancode); } while (0)
1382 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
1383 struct tp_nvram_state
*newn
,
1386 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
1387 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
1388 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
1389 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
1391 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
1393 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
1396 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
1397 if (oldn
->mute
!= newn
->mute
) {
1398 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1400 if (oldn
->volume_level
> newn
->volume_level
) {
1401 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1402 } else if (oldn
->volume_level
< newn
->volume_level
) {
1403 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1404 } else if (oldn
->mute
== newn
->mute
) {
1405 /* repeated key presses that didn't change state */
1407 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1408 } else if (newn
->volume_level
!= 0) {
1409 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1411 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1416 /* handle brightness */
1417 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
1418 if (oldn
->brightness_level
< newn
->brightness_level
) {
1419 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1420 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
1421 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1423 /* repeated key presses that didn't change state */
1424 if (newn
->brightness_level
!= 0) {
1425 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1427 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1433 #undef TPACPI_COMPARE_KEY
1434 #undef TPACPI_MAY_SEND_KEY
1436 static int hotkey_kthread(void *data
)
1438 struct tp_nvram_state s
[2];
1440 unsigned int si
, so
;
1442 unsigned int change_detector
, must_reset
;
1444 mutex_lock(&hotkey_thread_mutex
);
1446 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
1455 /* Initial state for compares */
1456 mutex_lock(&hotkey_thread_data_mutex
);
1457 change_detector
= hotkey_config_change
;
1458 mask
= hotkey_source_mask
& hotkey_mask
;
1459 mutex_unlock(&hotkey_thread_data_mutex
);
1460 hotkey_read_nvram(&s
[so
], mask
);
1462 while (!kthread_should_stop() && hotkey_poll_freq
) {
1464 t
= 1000/hotkey_poll_freq
;
1465 t
= msleep_interruptible(t
);
1466 if (unlikely(kthread_should_stop()))
1468 must_reset
= try_to_freeze();
1469 if (t
> 0 && !must_reset
)
1472 mutex_lock(&hotkey_thread_data_mutex
);
1473 if (must_reset
|| hotkey_config_change
!= change_detector
) {
1474 /* forget old state on thaw or config change */
1477 change_detector
= hotkey_config_change
;
1479 mask
= hotkey_source_mask
& hotkey_mask
;
1480 mutex_unlock(&hotkey_thread_data_mutex
);
1483 hotkey_read_nvram(&s
[si
], mask
);
1484 if (likely(si
!= so
)) {
1485 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
1495 mutex_unlock(&hotkey_thread_mutex
);
1499 static void hotkey_poll_stop_sync(void)
1501 if (tpacpi_hotkey_task
) {
1502 if (frozen(tpacpi_hotkey_task
) ||
1503 freezing(tpacpi_hotkey_task
))
1504 thaw_process(tpacpi_hotkey_task
);
1506 kthread_stop(tpacpi_hotkey_task
);
1507 tpacpi_hotkey_task
= NULL
;
1508 mutex_lock(&hotkey_thread_mutex
);
1509 /* at this point, the thread did exit */
1510 mutex_unlock(&hotkey_thread_mutex
);
1514 /* call with hotkey_mutex held */
1515 static void hotkey_poll_setup(int may_warn
)
1517 if ((hotkey_source_mask
& hotkey_mask
) != 0 &&
1518 hotkey_poll_freq
> 0 &&
1519 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1520 if (!tpacpi_hotkey_task
) {
1521 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1524 if (IS_ERR(tpacpi_hotkey_task
)) {
1525 tpacpi_hotkey_task
= NULL
;
1527 "could not create kernel thread "
1528 "for hotkey polling\n");
1532 hotkey_poll_stop_sync();
1534 hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1535 printk(TPACPI_NOTICE
1536 "hot keys 0x%08x require polling, "
1537 "which is currently disabled\n",
1538 hotkey_source_mask
);
1543 static void hotkey_poll_setup_safe(int may_warn
)
1545 mutex_lock(&hotkey_mutex
);
1546 hotkey_poll_setup(may_warn
);
1547 mutex_unlock(&hotkey_mutex
);
1550 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1552 static void hotkey_poll_setup_safe(int __unused
)
1556 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1558 static int hotkey_inputdev_open(struct input_dev
*dev
)
1560 switch (tpacpi_lifecycle
) {
1561 case TPACPI_LIFE_INIT
:
1563 * hotkey_init will call hotkey_poll_setup_safe
1564 * at the appropriate moment
1567 case TPACPI_LIFE_EXITING
:
1569 case TPACPI_LIFE_RUNNING
:
1570 hotkey_poll_setup_safe(0);
1574 /* Should only happen if tpacpi_lifecycle is corrupt */
1579 static void hotkey_inputdev_close(struct input_dev
*dev
)
1581 /* disable hotkey polling when possible */
1582 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
)
1583 hotkey_poll_setup_safe(0);
1586 /* sysfs hotkey enable ------------------------------------------------- */
1587 static ssize_t
hotkey_enable_show(struct device
*dev
,
1588 struct device_attribute
*attr
,
1593 res
= hotkey_status_get(&status
);
1597 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1600 static ssize_t
hotkey_enable_store(struct device
*dev
,
1601 struct device_attribute
*attr
,
1602 const char *buf
, size_t count
)
1607 if (parse_strtoul(buf
, 1, &t
))
1610 res
= hotkey_status_set(t
);
1612 return (res
) ? res
: count
;
1615 static struct device_attribute dev_attr_hotkey_enable
=
1616 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
1617 hotkey_enable_show
, hotkey_enable_store
);
1619 /* sysfs hotkey mask --------------------------------------------------- */
1620 static ssize_t
hotkey_mask_show(struct device
*dev
,
1621 struct device_attribute
*attr
,
1626 if (mutex_lock_interruptible(&hotkey_mutex
))
1627 return -ERESTARTSYS
;
1628 res
= hotkey_mask_get();
1629 mutex_unlock(&hotkey_mutex
);
1632 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
1635 static ssize_t
hotkey_mask_store(struct device
*dev
,
1636 struct device_attribute
*attr
,
1637 const char *buf
, size_t count
)
1642 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
1645 if (mutex_lock_interruptible(&hotkey_mutex
))
1646 return -ERESTARTSYS
;
1648 res
= hotkey_mask_set(t
);
1650 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1651 hotkey_poll_setup(1);
1654 mutex_unlock(&hotkey_mutex
);
1656 return (res
) ? res
: count
;
1659 static struct device_attribute dev_attr_hotkey_mask
=
1660 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
1661 hotkey_mask_show
, hotkey_mask_store
);
1663 /* sysfs hotkey bios_enabled ------------------------------------------- */
1664 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
1665 struct device_attribute
*attr
,
1668 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
1671 static struct device_attribute dev_attr_hotkey_bios_enabled
=
1672 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
1674 /* sysfs hotkey bios_mask ---------------------------------------------- */
1675 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
1676 struct device_attribute
*attr
,
1679 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
1682 static struct device_attribute dev_attr_hotkey_bios_mask
=
1683 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
1685 /* sysfs hotkey all_mask ----------------------------------------------- */
1686 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
1687 struct device_attribute
*attr
,
1690 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1691 hotkey_all_mask
| hotkey_source_mask
);
1694 static struct device_attribute dev_attr_hotkey_all_mask
=
1695 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
1697 /* sysfs hotkey recommended_mask --------------------------------------- */
1698 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
1699 struct device_attribute
*attr
,
1702 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1703 (hotkey_all_mask
| hotkey_source_mask
)
1704 & ~hotkey_reserved_mask
);
1707 static struct device_attribute dev_attr_hotkey_recommended_mask
=
1708 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
1709 hotkey_recommended_mask_show
, NULL
);
1711 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1713 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
1714 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
1715 struct device_attribute
*attr
,
1718 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
1721 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
1722 struct device_attribute
*attr
,
1723 const char *buf
, size_t count
)
1727 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
1728 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
1731 if (mutex_lock_interruptible(&hotkey_mutex
))
1732 return -ERESTARTSYS
;
1734 HOTKEY_CONFIG_CRITICAL_START
1735 hotkey_source_mask
= t
;
1736 HOTKEY_CONFIG_CRITICAL_END
1738 hotkey_poll_setup(1);
1740 mutex_unlock(&hotkey_mutex
);
1745 static struct device_attribute dev_attr_hotkey_source_mask
=
1746 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
1747 hotkey_source_mask_show
, hotkey_source_mask_store
);
1749 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
1750 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
1751 struct device_attribute
*attr
,
1754 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
1757 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
1758 struct device_attribute
*attr
,
1759 const char *buf
, size_t count
)
1763 if (parse_strtoul(buf
, 25, &t
))
1766 if (mutex_lock_interruptible(&hotkey_mutex
))
1767 return -ERESTARTSYS
;
1769 hotkey_poll_freq
= t
;
1771 hotkey_poll_setup(1);
1772 mutex_unlock(&hotkey_mutex
);
1777 static struct device_attribute dev_attr_hotkey_poll_freq
=
1778 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
1779 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
1781 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1783 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
1784 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
1785 struct device_attribute
*attr
,
1789 res
= hotkey_get_wlsw(&s
);
1793 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1796 static struct device_attribute dev_attr_hotkey_radio_sw
=
1797 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
1799 static void hotkey_radio_sw_notify_change(void)
1801 if (tp_features
.hotkey_wlsw
)
1802 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
1806 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
1807 static ssize_t
hotkey_tablet_mode_show(struct device
*dev
,
1808 struct device_attribute
*attr
,
1812 res
= hotkey_get_tablet_mode(&s
);
1816 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1819 static struct device_attribute dev_attr_hotkey_tablet_mode
=
1820 __ATTR(hotkey_tablet_mode
, S_IRUGO
, hotkey_tablet_mode_show
, NULL
);
1822 static void hotkey_tablet_mode_notify_change(void)
1824 if (tp_features
.hotkey_tablet
)
1825 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
1826 "hotkey_tablet_mode");
1829 /* sysfs hotkey report_mode -------------------------------------------- */
1830 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
1831 struct device_attribute
*attr
,
1834 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1835 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
1838 static struct device_attribute dev_attr_hotkey_report_mode
=
1839 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
1841 /* sysfs wakeup reason (pollable) -------------------------------------- */
1842 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
1843 struct device_attribute
*attr
,
1846 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
1849 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
1850 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
1852 static void hotkey_wakeup_reason_notify_change(void)
1854 if (tp_features
.hotkey_mask
)
1855 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
1859 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
1860 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
1861 struct device_attribute
*attr
,
1864 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
1867 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
1868 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
1869 hotkey_wakeup_hotunplug_complete_show
, NULL
);
1871 static void hotkey_wakeup_hotunplug_complete_notify_change(void)
1873 if (tp_features
.hotkey_mask
)
1874 sysfs_notify(&tpacpi_pdev
->dev
.kobj
, NULL
,
1875 "wakeup_hotunplug_complete");
1878 /* --------------------------------------------------------------------- */
1880 static struct attribute
*hotkey_attributes
[] __initdata
= {
1881 &dev_attr_hotkey_enable
.attr
,
1882 &dev_attr_hotkey_bios_enabled
.attr
,
1883 &dev_attr_hotkey_report_mode
.attr
,
1884 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1885 &dev_attr_hotkey_mask
.attr
,
1886 &dev_attr_hotkey_all_mask
.attr
,
1887 &dev_attr_hotkey_recommended_mask
.attr
,
1888 &dev_attr_hotkey_source_mask
.attr
,
1889 &dev_attr_hotkey_poll_freq
.attr
,
1893 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
1894 &dev_attr_hotkey_bios_mask
.attr
,
1895 #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1896 &dev_attr_hotkey_mask
.attr
,
1897 &dev_attr_hotkey_all_mask
.attr
,
1898 &dev_attr_hotkey_recommended_mask
.attr
,
1900 &dev_attr_hotkey_wakeup_reason
.attr
,
1901 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
1904 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
1906 /* Requirements for changing the default keymaps:
1908 * 1. Many of the keys are mapped to KEY_RESERVED for very
1909 * good reasons. Do not change them unless you have deep
1910 * knowledge on the IBM and Lenovo ThinkPad firmware for
1911 * the various ThinkPad models. The driver behaves
1912 * differently for KEY_RESERVED: such keys have their
1913 * hot key mask *unset* in mask_recommended, and also
1914 * in the initial hot key mask programmed into the
1915 * firmware at driver load time, which means the firm-
1916 * ware may react very differently if you change them to
1919 * 2. You must be subscribed to the linux-thinkpad and
1920 * ibm-acpi-devel mailing lists, and you should read the
1921 * list archives since 2007 if you want to change the
1922 * keymaps. This requirement exists so that you will
1923 * know the past history of problems with the thinkpad-
1924 * acpi driver keymaps, and also that you will be
1925 * listening to any bug reports;
1927 * 3. Do not send thinkpad-acpi specific patches directly to
1928 * for merging, *ever*. Send them to the linux-acpi
1929 * mailinglist for comments. Merging is to be done only
1930 * through acpi-test and the ACPI maintainer.
1932 * If the above is too much to ask, don't change the keymap.
1933 * Ask the thinkpad-acpi maintainer to do it, instead.
1935 static u16 ibm_keycode_map
[] __initdata
= {
1936 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1937 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
1938 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1939 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1941 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
1942 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1943 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1944 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1946 /* brightness: firmware always reacts to them, unless
1947 * X.org did some tricks in the radeon BIOS scratch
1948 * registers of *some* models */
1949 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1950 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1952 /* Thinklight: firmware always react to it */
1953 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1955 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1956 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1958 /* Volume: firmware always react to it and reprograms
1959 * the built-in *extra* mixer. Never map it to control
1960 * another mixer by default. */
1961 KEY_RESERVED
, /* 0x14: VOLUME UP */
1962 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1963 KEY_RESERVED
, /* 0x16: MUTE */
1965 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1967 /* (assignments unknown, please report if found) */
1968 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1969 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1971 static u16 lenovo_keycode_map
[] __initdata
= {
1972 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1973 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
1974 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1975 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1977 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
1978 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1979 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1980 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1982 /* These either have to go through ACPI video, or
1983 * act like in the IBM ThinkPads, so don't ever
1984 * enable them by default */
1985 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1986 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1988 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1990 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1991 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1993 /* Volume: z60/z61, T60 (BIOS version?): firmware always
1994 * react to it and reprograms the built-in *extra* mixer.
1995 * Never map it to control another mixer by default.
1997 * T60?, T61, R60?, R61: firmware and EC tries to send
1998 * these over the regular keyboard, so these are no-ops,
1999 * but there are still weird bugs re. MUTE, so do not
2000 * change unless you get test reports from all Lenovo
2001 * models. May cause the BIOS to interfere with the
2004 KEY_RESERVED
, /* 0x14: VOLUME UP */
2005 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
2006 KEY_RESERVED
, /* 0x16: MUTE */
2008 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
2010 /* (assignments unknown, please report if found) */
2011 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2012 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
2015 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
2016 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
2017 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
2023 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
2025 BUG_ON(!tpacpi_inputdev
);
2026 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
2027 tpacpi_inputdev
->close
!= NULL
);
2029 TPACPI_ACPIHANDLE_INIT(hkey
);
2030 mutex_init(&hotkey_mutex
);
2032 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2033 mutex_init(&hotkey_thread_mutex
);
2034 mutex_init(&hotkey_thread_data_mutex
);
2037 /* hotkey not supported on 570 */
2038 tp_features
.hotkey
= hkey_handle
!= NULL
;
2040 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
2041 str_supported(tp_features
.hotkey
));
2043 if (tp_features
.hotkey
) {
2044 hotkey_dev_attributes
= create_attr_set(13, NULL
);
2045 if (!hotkey_dev_attributes
)
2047 res
= add_many_to_attr_set(hotkey_dev_attributes
,
2049 ARRAY_SIZE(hotkey_attributes
));
2053 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2054 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
2055 for HKEY interface version 0x100 */
2056 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
2057 if ((hkeyv
>> 8) != 1) {
2058 printk(TPACPI_ERR
"unknown version of the "
2059 "HKEY interface: 0x%x\n", hkeyv
);
2060 printk(TPACPI_ERR
"please report this to %s\n",
2064 * MHKV 0x100 in A31, R40, R40e,
2065 * T4x, X31, and later
2067 tp_features
.hotkey_mask
= 1;
2071 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
2072 str_supported(tp_features
.hotkey_mask
));
2074 if (tp_features
.hotkey_mask
) {
2075 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
2078 "missing MHKA handler, "
2079 "please report this to %s\n",
2081 /* FN+F12, FN+F4, FN+F3 */
2082 hotkey_all_mask
= 0x080cU
;
2086 /* hotkey_source_mask *must* be zero for
2087 * the first hotkey_mask_get */
2088 res
= hotkey_status_get(&hotkey_orig_status
);
2089 if (!res
&& tp_features
.hotkey_mask
) {
2090 res
= hotkey_mask_get();
2091 hotkey_orig_mask
= hotkey_mask
;
2093 res
= add_many_to_attr_set(
2094 hotkey_dev_attributes
,
2095 hotkey_mask_attributes
,
2096 ARRAY_SIZE(hotkey_mask_attributes
));
2100 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2101 if (tp_features
.hotkey_mask
) {
2102 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
2105 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
;
2108 vdbg_printk(TPACPI_DBG_INIT
,
2109 "hotkey source mask 0x%08x, polling freq %d\n",
2110 hotkey_source_mask
, hotkey_poll_freq
);
2113 /* Not all thinkpads have a hardware radio switch */
2114 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
2115 tp_features
.hotkey_wlsw
= 1;
2117 "radio switch found; radios are %s\n",
2118 enabled(status
, 0));
2119 res
= add_to_attr_set(hotkey_dev_attributes
,
2120 &dev_attr_hotkey_radio_sw
.attr
);
2123 /* For X41t, X60t, X61t Tablets... */
2124 if (!res
&& acpi_evalf(hkey_handle
, &status
, "MHKG", "qd")) {
2125 tp_features
.hotkey_tablet
= 1;
2127 "possible tablet mode switch found; "
2128 "ThinkPad in %s mode\n",
2129 (status
& TP_HOTKEY_TABLET_MASK
)?
2130 "tablet" : "laptop");
2131 res
= add_to_attr_set(hotkey_dev_attributes
,
2132 &dev_attr_hotkey_tablet_mode
.attr
);
2136 res
= register_attr_set_with_sysfs(
2137 hotkey_dev_attributes
,
2138 &tpacpi_pdev
->dev
.kobj
);
2142 /* Set up key map */
2144 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
2146 if (!hotkey_keycode_map
) {
2148 "failed to allocate memory for key map\n");
2152 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
2153 dbg_printk(TPACPI_DBG_INIT
,
2154 "using Lenovo default hot key map\n");
2155 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
2156 TPACPI_HOTKEY_MAP_SIZE
);
2158 dbg_printk(TPACPI_DBG_INIT
,
2159 "using IBM default hot key map\n");
2160 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
2161 TPACPI_HOTKEY_MAP_SIZE
);
2164 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
2165 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
2166 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
2167 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
2168 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
2169 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
2170 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
2171 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
2172 set_bit(hotkey_keycode_map
[i
],
2173 tpacpi_inputdev
->keybit
);
2175 if (i
< sizeof(hotkey_reserved_mask
)*8)
2176 hotkey_reserved_mask
|= 1 << i
;
2180 if (tp_features
.hotkey_wlsw
) {
2181 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2182 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
2184 if (tp_features
.hotkey_tablet
) {
2185 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
2186 set_bit(SW_TABLET_MODE
, tpacpi_inputdev
->swbit
);
2189 /* Do not issue duplicate brightness change events to
2191 if (!tp_features
.bright_acpimode
)
2192 /* update bright_acpimode... */
2193 tpacpi_check_std_acpi_brightness_support();
2195 if (tp_features
.bright_acpimode
) {
2197 "This ThinkPad has standard ACPI backlight "
2198 "brightness control, supported by the ACPI "
2200 printk(TPACPI_NOTICE
2201 "Disabling thinkpad-acpi brightness events "
2204 /* The hotkey_reserved_mask change below is not
2205 * necessary while the keys are at KEY_RESERVED in the
2206 * default map, but better safe than sorry, leave it
2207 * here as a marker of what we have to do, especially
2208 * when we finally become able to set this at runtime
2209 * on response to X.org requests */
2210 hotkey_reserved_mask
|=
2211 (1 << TP_ACPI_HOTKEYSCAN_FNHOME
)
2212 | (1 << TP_ACPI_HOTKEYSCAN_FNEND
);
2215 dbg_printk(TPACPI_DBG_INIT
,
2216 "enabling hot key handling\n");
2217 res
= hotkey_status_set(1);
2220 res
= hotkey_mask_set(((hotkey_all_mask
| hotkey_source_mask
)
2221 & ~hotkey_reserved_mask
)
2222 | hotkey_orig_mask
);
2223 if (res
< 0 && res
!= -ENXIO
)
2226 dbg_printk(TPACPI_DBG_INIT
,
2227 "legacy hot key reporting over procfs %s\n",
2228 (hotkey_report_mode
< 2) ?
2229 "enabled" : "disabled");
2231 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
2232 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
2234 hotkey_poll_setup_safe(1);
2235 tpacpi_input_send_radiosw();
2236 tpacpi_input_send_tabletsw();
2239 return (tp_features
.hotkey
)? 0 : 1;
2242 static void hotkey_exit(void)
2244 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2245 hotkey_poll_stop_sync();
2248 if (tp_features
.hotkey
) {
2249 dbg_printk(TPACPI_DBG_EXIT
,
2250 "restoring original hot key mask\n");
2251 /* no short-circuit boolean operator below! */
2252 if ((hotkey_mask_set(hotkey_orig_mask
) |
2253 hotkey_status_set(hotkey_orig_status
)) != 0)
2255 "failed to restore hot key mask "
2256 "to BIOS defaults\n");
2259 if (hotkey_dev_attributes
) {
2260 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2261 hotkey_dev_attributes
= NULL
;
2265 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
2268 unsigned int scancode
;
2273 if (event
!= 0x80) {
2275 "unknown HKEY notification event %d\n", event
);
2276 /* forward it to userspace, maybe it knows how to handle it */
2277 acpi_bus_generate_netlink_event(
2278 ibm
->acpi
->device
->pnp
.device_class
,
2279 ibm
->acpi
->device
->dev
.bus_id
,
2285 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
2286 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
2299 switch (hkey
>> 12) {
2301 /* 0x1000-0x1FFF: key presses */
2302 scancode
= hkey
& 0xfff;
2303 if (scancode
> 0 && scancode
< 0x21) {
2305 if (!(hotkey_source_mask
& (1 << scancode
))) {
2306 tpacpi_input_send_key(scancode
);
2318 case 0x2304: /* suspend, undock */
2319 case 0x2404: /* hibernation, undock */
2320 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
2323 case 0x2305: /* suspend, bay eject */
2324 case 0x2405: /* hibernation, bay eject */
2325 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
2331 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
2333 "woke up due to a hot-unplug "
2335 hotkey_wakeup_reason_notify_change();
2339 /* bay-related wakeups */
2340 if (hkey
== 0x3003) {
2341 hotkey_autosleep_ack
= 1;
2344 hotkey_wakeup_hotunplug_complete_notify_change();
2350 /* dock-related wakeups */
2351 if (hkey
== 0x4003) {
2352 hotkey_autosleep_ack
= 1;
2355 hotkey_wakeup_hotunplug_complete_notify_change();
2361 /* 0x5000-0x5FFF: human interface helpers */
2363 case 0x5010: /* Lenovo new BIOS: brightness changed */
2364 case 0x500b: /* X61t: tablet pen inserted into bay */
2365 case 0x500c: /* X61t: tablet pen removed from bay */
2367 case 0x5009: /* X41t-X61t: swivel up (tablet mode) */
2368 case 0x500a: /* X41t-X61t: swivel down (normal mode) */
2369 tpacpi_input_send_tabletsw();
2370 hotkey_tablet_mode_notify_change();
2375 /* LID switch events. Do not propagate */
2383 /* 0x7000-0x7FFF: misc */
2384 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
2385 tpacpi_input_send_radiosw();
2386 hotkey_radio_sw_notify_change();
2390 /* fallthrough to default */
2395 printk(TPACPI_NOTICE
2396 "unhandled HKEY event 0x%04x\n", hkey
);
2400 if (!ignore_acpi_ev
&&
2401 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
2402 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
2406 /* netlink events */
2407 if (!ignore_acpi_ev
&& send_acpi_ev
) {
2408 acpi_bus_generate_netlink_event(
2409 ibm
->acpi
->device
->pnp
.device_class
,
2410 ibm
->acpi
->device
->dev
.bus_id
,
2416 static void hotkey_suspend(pm_message_t state
)
2418 /* Do these on suspend, we get the events on early resume! */
2419 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
2420 hotkey_autosleep_ack
= 0;
2423 static void hotkey_resume(void)
2425 if (hotkey_mask_get())
2427 "error while trying to read hot key mask "
2429 tpacpi_input_send_radiosw();
2430 hotkey_radio_sw_notify_change();
2431 hotkey_tablet_mode_notify_change();
2432 hotkey_wakeup_reason_notify_change();
2433 hotkey_wakeup_hotunplug_complete_notify_change();
2434 hotkey_poll_setup_safe(0);
2437 /* procfs -------------------------------------------------------------- */
2438 static int hotkey_read(char *p
)
2443 if (!tp_features
.hotkey
) {
2444 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2448 if (mutex_lock_interruptible(&hotkey_mutex
))
2449 return -ERESTARTSYS
;
2450 res
= hotkey_status_get(&status
);
2452 res
= hotkey_mask_get();
2453 mutex_unlock(&hotkey_mutex
);
2457 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
2458 if (tp_features
.hotkey_mask
) {
2459 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
2460 len
+= sprintf(p
+ len
,
2461 "commands:\tenable, disable, reset, <mask>\n");
2463 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
2464 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
2470 static int hotkey_write(char *buf
)
2476 if (!tp_features
.hotkey
)
2479 if (mutex_lock_interruptible(&hotkey_mutex
))
2480 return -ERESTARTSYS
;
2486 while ((cmd
= next_cmd(&buf
))) {
2487 if (strlencmp(cmd
, "enable") == 0) {
2489 } else if (strlencmp(cmd
, "disable") == 0) {
2491 } else if (strlencmp(cmd
, "reset") == 0) {
2492 status
= hotkey_orig_status
;
2493 mask
= hotkey_orig_mask
;
2494 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
2496 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
2504 res
= hotkey_status_set(status
);
2506 if (!res
&& mask
!= hotkey_mask
)
2507 res
= hotkey_mask_set(mask
);
2510 mutex_unlock(&hotkey_mutex
);
2514 static const struct acpi_device_id ibm_htk_device_ids
[] = {
2515 {TPACPI_ACPI_HKEY_HID
, 0},
2519 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
2520 .hid
= ibm_htk_device_ids
,
2521 .notify
= hotkey_notify
,
2522 .handle
= &hkey_handle
,
2523 .type
= ACPI_DEVICE_NOTIFY
,
2526 static struct ibm_struct hotkey_driver_data
= {
2528 .read
= hotkey_read
,
2529 .write
= hotkey_write
,
2530 .exit
= hotkey_exit
,
2531 .resume
= hotkey_resume
,
2532 .suspend
= hotkey_suspend
,
2533 .acpi
= &ibm_hotkey_acpidriver
,
2536 /*************************************************************************
2537 * Bluetooth subdriver
2541 /* ACPI GBDC/SBDC bits */
2542 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
2543 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
2544 TP_ACPI_BLUETOOTH_UNK
= 0x04, /* unknown function */
2547 static int bluetooth_get_radiosw(void);
2548 static int bluetooth_set_radiosw(int radio_on
);
2550 /* sysfs bluetooth enable ---------------------------------------------- */
2551 static ssize_t
bluetooth_enable_show(struct device
*dev
,
2552 struct device_attribute
*attr
,
2557 status
= bluetooth_get_radiosw();
2561 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
2564 static ssize_t
bluetooth_enable_store(struct device
*dev
,
2565 struct device_attribute
*attr
,
2566 const char *buf
, size_t count
)
2571 if (parse_strtoul(buf
, 1, &t
))
2574 res
= bluetooth_set_radiosw(t
);
2576 return (res
) ? res
: count
;
2579 static struct device_attribute dev_attr_bluetooth_enable
=
2580 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
2581 bluetooth_enable_show
, bluetooth_enable_store
);
2583 /* --------------------------------------------------------------------- */
2585 static struct attribute
*bluetooth_attributes
[] = {
2586 &dev_attr_bluetooth_enable
.attr
,
2590 static const struct attribute_group bluetooth_attr_group
= {
2591 .attrs
= bluetooth_attributes
,
2594 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
2599 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
2601 TPACPI_ACPIHANDLE_INIT(hkey
);
2603 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2604 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
2605 tp_features
.bluetooth
= hkey_handle
&&
2606 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
2608 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
2609 str_supported(tp_features
.bluetooth
),
2612 if (tp_features
.bluetooth
) {
2613 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
2614 /* no bluetooth hardware present in system */
2615 tp_features
.bluetooth
= 0;
2616 dbg_printk(TPACPI_DBG_INIT
,
2617 "bluetooth hardware not installed\n");
2619 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2620 &bluetooth_attr_group
);
2626 return (tp_features
.bluetooth
)? 0 : 1;
2629 static void bluetooth_exit(void)
2631 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2632 &bluetooth_attr_group
);
2635 static int bluetooth_get_radiosw(void)
2639 if (!tp_features
.bluetooth
)
2642 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2645 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
2648 static int bluetooth_set_radiosw(int radio_on
)
2652 if (!tp_features
.bluetooth
)
2655 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2658 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
2660 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
2661 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
2667 /* procfs -------------------------------------------------------------- */
2668 static int bluetooth_read(char *p
)
2671 int status
= bluetooth_get_radiosw();
2673 if (!tp_features
.bluetooth
)
2674 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2676 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2677 (status
)? "enabled" : "disabled");
2678 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2684 static int bluetooth_write(char *buf
)
2688 if (!tp_features
.bluetooth
)
2691 while ((cmd
= next_cmd(&buf
))) {
2692 if (strlencmp(cmd
, "enable") == 0) {
2693 bluetooth_set_radiosw(1);
2694 } else if (strlencmp(cmd
, "disable") == 0) {
2695 bluetooth_set_radiosw(0);
2703 static struct ibm_struct bluetooth_driver_data
= {
2704 .name
= "bluetooth",
2705 .read
= bluetooth_read
,
2706 .write
= bluetooth_write
,
2707 .exit
= bluetooth_exit
,
2710 /*************************************************************************
2715 /* ACPI GWAN/SWAN bits */
2716 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
2717 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
2718 TP_ACPI_WANCARD_UNK
= 0x04, /* unknown function */
2721 static int wan_get_radiosw(void);
2722 static int wan_set_radiosw(int radio_on
);
2724 /* sysfs wan enable ---------------------------------------------------- */
2725 static ssize_t
wan_enable_show(struct device
*dev
,
2726 struct device_attribute
*attr
,
2731 status
= wan_get_radiosw();
2735 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
2738 static ssize_t
wan_enable_store(struct device
*dev
,
2739 struct device_attribute
*attr
,
2740 const char *buf
, size_t count
)
2745 if (parse_strtoul(buf
, 1, &t
))
2748 res
= wan_set_radiosw(t
);
2750 return (res
) ? res
: count
;
2753 static struct device_attribute dev_attr_wan_enable
=
2754 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
2755 wan_enable_show
, wan_enable_store
);
2757 /* --------------------------------------------------------------------- */
2759 static struct attribute
*wan_attributes
[] = {
2760 &dev_attr_wan_enable
.attr
,
2764 static const struct attribute_group wan_attr_group
= {
2765 .attrs
= wan_attributes
,
2768 static int __init
wan_init(struct ibm_init_struct
*iibm
)
2773 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
2775 TPACPI_ACPIHANDLE_INIT(hkey
);
2777 tp_features
.wan
= hkey_handle
&&
2778 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
2780 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
2781 str_supported(tp_features
.wan
),
2784 if (tp_features
.wan
) {
2785 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
2786 /* no wan hardware present in system */
2787 tp_features
.wan
= 0;
2788 dbg_printk(TPACPI_DBG_INIT
,
2789 "wan hardware not installed\n");
2791 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2798 return (tp_features
.wan
)? 0 : 1;
2801 static void wan_exit(void)
2803 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2807 static int wan_get_radiosw(void)
2811 if (!tp_features
.wan
)
2814 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2817 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
2820 static int wan_set_radiosw(int radio_on
)
2824 if (!tp_features
.wan
)
2827 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2830 status
|= TP_ACPI_WANCARD_RADIOSSW
;
2832 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
2833 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
2839 /* procfs -------------------------------------------------------------- */
2840 static int wan_read(char *p
)
2843 int status
= wan_get_radiosw();
2845 if (!tp_features
.wan
)
2846 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2848 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2849 (status
)? "enabled" : "disabled");
2850 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2856 static int wan_write(char *buf
)
2860 if (!tp_features
.wan
)
2863 while ((cmd
= next_cmd(&buf
))) {
2864 if (strlencmp(cmd
, "enable") == 0) {
2866 } else if (strlencmp(cmd
, "disable") == 0) {
2875 static struct ibm_struct wan_driver_data
= {
2880 .flags
.experimental
= 1,
2883 /*************************************************************************
2887 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
2889 enum video_access_mode
{
2890 TPACPI_VIDEO_NONE
= 0,
2891 TPACPI_VIDEO_570
, /* 570 */
2892 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
2893 TPACPI_VIDEO_NEW
, /* all others */
2896 enum { /* video status flags, based on VIDEO_570 */
2897 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
2898 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
2899 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
2902 enum { /* TPACPI_VIDEO_570 constants */
2903 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
2904 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
2905 * video_status_flags */
2906 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
2907 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
2910 static enum video_access_mode video_supported
;
2911 static int video_orig_autosw
;
2913 static int video_autosw_get(void);
2914 static int video_autosw_set(int enable
);
2916 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
2918 static int __init
video_init(struct ibm_init_struct
*iibm
)
2922 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
2924 TPACPI_ACPIHANDLE_INIT(vid
);
2925 TPACPI_ACPIHANDLE_INIT(vid2
);
2927 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
2928 /* G41, assume IVGA doesn't change */
2929 vid_handle
= vid2_handle
;
2932 /* video switching not supported on R30, R31 */
2933 video_supported
= TPACPI_VIDEO_NONE
;
2934 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
2936 video_supported
= TPACPI_VIDEO_570
;
2937 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
2938 /* 600e/x, 770e, 770x */
2939 video_supported
= TPACPI_VIDEO_770
;
2942 video_supported
= TPACPI_VIDEO_NEW
;
2944 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
2945 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
2948 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
2951 static void video_exit(void)
2953 dbg_printk(TPACPI_DBG_EXIT
,
2954 "restoring original video autoswitch mode\n");
2955 if (video_autosw_set(video_orig_autosw
))
2956 printk(TPACPI_ERR
"error while trying to restore original "
2957 "video autoswitch mode\n");
2960 static int video_outputsw_get(void)
2965 switch (video_supported
) {
2966 case TPACPI_VIDEO_570
:
2967 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
2968 TP_ACPI_VIDEO_570_PHSCMD
))
2970 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
2972 case TPACPI_VIDEO_770
:
2973 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2976 status
|= TP_ACPI_VIDEO_S_LCD
;
2977 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2980 status
|= TP_ACPI_VIDEO_S_CRT
;
2982 case TPACPI_VIDEO_NEW
:
2983 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
2984 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2987 status
|= TP_ACPI_VIDEO_S_CRT
;
2989 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
2990 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2993 status
|= TP_ACPI_VIDEO_S_LCD
;
2994 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
2997 status
|= TP_ACPI_VIDEO_S_DVI
;
3006 static int video_outputsw_set(int status
)
3011 switch (video_supported
) {
3012 case TPACPI_VIDEO_570
:
3013 res
= acpi_evalf(NULL
, NULL
,
3014 "\\_SB.PHS2", "vdd",
3015 TP_ACPI_VIDEO_570_PHS2CMD
,
3016 status
| TP_ACPI_VIDEO_570_PHS2SET
);
3018 case TPACPI_VIDEO_770
:
3019 autosw
= video_autosw_get();
3023 res
= video_autosw_set(1);
3026 res
= acpi_evalf(vid_handle
, NULL
,
3027 "ASWT", "vdd", status
* 0x100, 0);
3028 if (!autosw
&& video_autosw_set(autosw
)) {
3030 "video auto-switch left enabled due to error\n");
3034 case TPACPI_VIDEO_NEW
:
3035 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
3036 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
3042 return (res
)? 0 : -EIO
;
3045 static int video_autosw_get(void)
3049 switch (video_supported
) {
3050 case TPACPI_VIDEO_570
:
3051 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
3054 case TPACPI_VIDEO_770
:
3055 case TPACPI_VIDEO_NEW
:
3056 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
3066 static int video_autosw_set(int enable
)
3068 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
3073 static int video_outputsw_cycle(void)
3075 int autosw
= video_autosw_get();
3081 switch (video_supported
) {
3082 case TPACPI_VIDEO_570
:
3083 res
= video_autosw_set(1);
3086 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
3088 case TPACPI_VIDEO_770
:
3089 case TPACPI_VIDEO_NEW
:
3090 res
= video_autosw_set(1);
3093 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
3098 if (!autosw
&& video_autosw_set(autosw
)) {
3100 "video auto-switch left enabled due to error\n");
3104 return (res
)? 0 : -EIO
;
3107 static int video_expand_toggle(void)
3109 switch (video_supported
) {
3110 case TPACPI_VIDEO_570
:
3111 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
3113 case TPACPI_VIDEO_770
:
3114 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
3116 case TPACPI_VIDEO_NEW
:
3117 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
3125 static int video_read(char *p
)
3130 if (video_supported
== TPACPI_VIDEO_NONE
) {
3131 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3135 status
= video_outputsw_get();
3139 autosw
= video_autosw_get();
3143 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3144 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
3145 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
3146 if (video_supported
== TPACPI_VIDEO_NEW
)
3147 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
3148 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
3149 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
3150 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
3151 if (video_supported
== TPACPI_VIDEO_NEW
)
3152 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
3153 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
3154 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
3159 static int video_write(char *buf
)
3162 int enable
, disable
, status
;
3165 if (video_supported
== TPACPI_VIDEO_NONE
)
3171 while ((cmd
= next_cmd(&buf
))) {
3172 if (strlencmp(cmd
, "lcd_enable") == 0) {
3173 enable
|= TP_ACPI_VIDEO_S_LCD
;
3174 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
3175 disable
|= TP_ACPI_VIDEO_S_LCD
;
3176 } else if (strlencmp(cmd
, "crt_enable") == 0) {
3177 enable
|= TP_ACPI_VIDEO_S_CRT
;
3178 } else if (strlencmp(cmd
, "crt_disable") == 0) {
3179 disable
|= TP_ACPI_VIDEO_S_CRT
;
3180 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
3181 strlencmp(cmd
, "dvi_enable") == 0) {
3182 enable
|= TP_ACPI_VIDEO_S_DVI
;
3183 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
3184 strlencmp(cmd
, "dvi_disable") == 0) {
3185 disable
|= TP_ACPI_VIDEO_S_DVI
;
3186 } else if (strlencmp(cmd
, "auto_enable") == 0) {
3187 res
= video_autosw_set(1);
3190 } else if (strlencmp(cmd
, "auto_disable") == 0) {
3191 res
= video_autosw_set(0);
3194 } else if (strlencmp(cmd
, "video_switch") == 0) {
3195 res
= video_outputsw_cycle();
3198 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
3199 res
= video_expand_toggle();
3206 if (enable
|| disable
) {
3207 status
= video_outputsw_get();
3210 res
= video_outputsw_set((status
& ~disable
) | enable
);
3218 static struct ibm_struct video_driver_data
= {
3221 .write
= video_write
,
3225 #endif /* CONFIG_THINKPAD_ACPI_VIDEO */
3227 /*************************************************************************
3228 * Light (thinklight) subdriver
3231 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
3232 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
3234 static int __init
light_init(struct ibm_init_struct
*iibm
)
3236 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
3238 TPACPI_ACPIHANDLE_INIT(ledb
);
3239 TPACPI_ACPIHANDLE_INIT(lght
);
3240 TPACPI_ACPIHANDLE_INIT(cmos
);
3242 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
3243 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
3245 if (tp_features
.light
)
3246 /* light status not supported on
3247 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
3248 tp_features
.light_status
=
3249 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
3251 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
3252 str_supported(tp_features
.light
));
3254 return (tp_features
.light
)? 0 : 1;
3257 static int light_read(char *p
)
3262 if (!tp_features
.light
) {
3263 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3264 } else if (!tp_features
.light_status
) {
3265 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
3266 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
3268 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
3270 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
3271 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
3277 static int light_write(char *buf
)
3279 int cmos_cmd
, lght_cmd
;
3283 if (!tp_features
.light
)
3286 while ((cmd
= next_cmd(&buf
))) {
3287 if (strlencmp(cmd
, "on") == 0) {
3290 } else if (strlencmp(cmd
, "off") == 0) {
3296 success
= cmos_handle
?
3297 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
3298 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
3306 static struct ibm_struct light_driver_data
= {
3309 .write
= light_write
,
3312 /*************************************************************************
3316 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3318 static void dock_notify(struct ibm_struct
*ibm
, u32 event
);
3319 static int dock_read(char *p
);
3320 static int dock_write(char *buf
);
3322 TPACPI_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
3323 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
3324 "\\_SB.PCI0.PCI1.DOCK", /* all others */
3325 "\\_SB.PCI.ISA.SLCE", /* 570 */
3326 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
3328 /* don't list other alternatives as we install a notify handler on the 570 */
3329 TPACPI_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
3331 static const struct acpi_device_id ibm_pci_device_ids
[] = {
3332 {PCI_ROOT_HID_STRING
, 0},
3336 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
3338 .notify
= dock_notify
,
3339 .handle
= &dock_handle
,
3340 .type
= ACPI_SYSTEM_NOTIFY
,
3343 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
3344 * We just use it to get notifications of dock hotplug
3345 * in very old thinkpads */
3346 .hid
= ibm_pci_device_ids
,
3347 .notify
= dock_notify
,
3348 .handle
= &pci_handle
,
3349 .type
= ACPI_SYSTEM_NOTIFY
,
3353 static struct ibm_struct dock_driver_data
[2] = {
3357 .write
= dock_write
,
3358 .acpi
= &ibm_dock_acpidriver
[0],
3362 .acpi
= &ibm_dock_acpidriver
[1],
3366 #define dock_docked() (_sta(dock_handle) & 1)
3368 static int __init
dock_init(struct ibm_init_struct
*iibm
)
3370 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
3372 TPACPI_ACPIHANDLE_INIT(dock
);
3374 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
3375 str_supported(dock_handle
!= NULL
));
3377 return (dock_handle
)? 0 : 1;
3380 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
3384 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
3386 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
3387 dock_driver_data
[0].flags
.acpi_notify_installed
) {
3388 TPACPI_ACPIHANDLE_INIT(pci
);
3389 dock2_needed
= (pci_handle
!= NULL
);
3390 vdbg_printk(TPACPI_DBG_INIT
,
3391 "dock PCI handler for the TP 570 is %s\n",
3392 str_supported(dock2_needed
));
3394 vdbg_printk(TPACPI_DBG_INIT
,
3395 "dock subdriver part 2 not required\n");
3399 return (dock2_needed
)? 0 : 1;
3402 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
3404 int docked
= dock_docked();
3405 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
3406 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
3409 if (event
== 1 && !pci
) /* 570 */
3410 data
= 1; /* button */
3411 else if (event
== 1 && pci
) /* 570 */
3412 data
= 3; /* dock */
3413 else if (event
== 3 && docked
)
3414 data
= 1; /* button */
3415 else if (event
== 3 && !docked
)
3416 data
= 2; /* undock */
3417 else if (event
== 0 && docked
)
3418 data
= 3; /* dock */
3420 printk(TPACPI_ERR
"unknown dock event %d, status %d\n",
3421 event
, _sta(dock_handle
));
3422 data
= 0; /* unknown */
3424 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
3425 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3426 ibm
->acpi
->device
->dev
.bus_id
,
3430 static int dock_read(char *p
)
3433 int docked
= dock_docked();
3436 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3438 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
3440 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
3441 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
3447 static int dock_write(char *buf
)
3454 while ((cmd
= next_cmd(&buf
))) {
3455 if (strlencmp(cmd
, "undock") == 0) {
3456 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
3457 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
3459 } else if (strlencmp(cmd
, "dock") == 0) {
3460 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
3469 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
3471 /*************************************************************************
3475 #ifdef CONFIG_THINKPAD_ACPI_BAY
3477 TPACPI_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
3478 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
3479 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
3480 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
3481 ); /* A21e, R30, R31 */
3482 TPACPI_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
3483 "_EJ0", /* all others */
3484 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
3485 TPACPI_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
3486 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
3488 TPACPI_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
3492 static int __init
bay_init(struct ibm_init_struct
*iibm
)
3494 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
3496 TPACPI_ACPIHANDLE_INIT(bay
);
3498 TPACPI_ACPIHANDLE_INIT(bay_ej
);
3499 TPACPI_ACPIHANDLE_INIT(bay2
);
3501 TPACPI_ACPIHANDLE_INIT(bay2_ej
);
3503 tp_features
.bay_status
= bay_handle
&&
3504 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
3505 tp_features
.bay_status2
= bay2_handle
&&
3506 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
3508 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
3509 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
3510 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
3511 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
3513 vdbg_printk(TPACPI_DBG_INIT
,
3514 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
3515 str_supported(tp_features
.bay_status
),
3516 str_supported(tp_features
.bay_eject
),
3517 str_supported(tp_features
.bay_status2
),
3518 str_supported(tp_features
.bay_eject2
));
3520 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
3521 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
3524 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
3526 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
3527 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3528 ibm
->acpi
->device
->dev
.bus_id
,
3532 #define bay_occupied(b) (_sta(b##_handle) & 1)
3534 static int bay_read(char *p
)
3537 int occupied
= bay_occupied(bay
);
3538 int occupied2
= bay_occupied(bay2
);
3541 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3542 tp_features
.bay_status
?
3543 (occupied
? "occupied" : "unoccupied") :
3545 if (tp_features
.bay_status2
)
3546 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
3547 "occupied" : "unoccupied");
3549 eject
= tp_features
.bay_eject
&& occupied
;
3550 eject2
= tp_features
.bay_eject2
&& occupied2
;
3552 if (eject
&& eject2
)
3553 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
3555 len
+= sprintf(p
+ len
, "commands:\teject\n");
3557 len
+= sprintf(p
+ len
, "commands:\teject2\n");
3562 static int bay_write(char *buf
)
3566 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
3569 while ((cmd
= next_cmd(&buf
))) {
3570 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
3571 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
3573 } else if (tp_features
.bay_eject2
&&
3574 strlencmp(cmd
, "eject2") == 0) {
3575 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
3584 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
3585 .notify
= bay_notify
,
3586 .handle
= &bay_handle
,
3587 .type
= ACPI_SYSTEM_NOTIFY
,
3590 static struct ibm_struct bay_driver_data
= {
3594 .acpi
= &ibm_bay_acpidriver
,
3597 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3599 /*************************************************************************
3603 /* sysfs cmos_command -------------------------------------------------- */
3604 static ssize_t
cmos_command_store(struct device
*dev
,
3605 struct device_attribute
*attr
,
3606 const char *buf
, size_t count
)
3608 unsigned long cmos_cmd
;
3611 if (parse_strtoul(buf
, 21, &cmos_cmd
))
3614 res
= issue_thinkpad_cmos_command(cmos_cmd
);
3615 return (res
)? res
: count
;
3618 static struct device_attribute dev_attr_cmos_command
=
3619 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
3621 /* --------------------------------------------------------------------- */
3623 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
3627 vdbg_printk(TPACPI_DBG_INIT
,
3628 "initializing cmos commands subdriver\n");
3630 TPACPI_ACPIHANDLE_INIT(cmos
);
3632 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
3633 str_supported(cmos_handle
!= NULL
));
3635 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
3639 return (cmos_handle
)? 0 : 1;
3642 static void cmos_exit(void)
3644 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
3647 static int cmos_read(char *p
)
3651 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3652 R30, R31, T20-22, X20-21 */
3654 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3656 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3657 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
3663 static int cmos_write(char *buf
)
3668 while ((cmd
= next_cmd(&buf
))) {
3669 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
3670 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
3675 res
= issue_thinkpad_cmos_command(cmos_cmd
);
3683 static struct ibm_struct cmos_driver_data
= {
3686 .write
= cmos_write
,
3690 /*************************************************************************
3694 enum led_access_mode
{
3695 TPACPI_LED_NONE
= 0,
3696 TPACPI_LED_570
, /* 570 */
3697 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3698 TPACPI_LED_NEW
, /* all others */
3701 enum { /* For TPACPI_LED_OLD */
3702 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
3703 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
3704 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
3707 static enum led_access_mode led_supported
;
3709 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
3710 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
3711 /* T20-22, X20-21 */
3712 "LED", /* all others */
3715 static int __init
led_init(struct ibm_init_struct
*iibm
)
3717 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
3719 TPACPI_ACPIHANDLE_INIT(led
);
3722 /* led not supported on R30, R31 */
3723 led_supported
= TPACPI_LED_NONE
;
3724 else if (strlencmp(led_path
, "SLED") == 0)
3726 led_supported
= TPACPI_LED_570
;
3727 else if (strlencmp(led_path
, "SYSL") == 0)
3728 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3729 led_supported
= TPACPI_LED_OLD
;
3732 led_supported
= TPACPI_LED_NEW
;
3734 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
3735 str_supported(led_supported
), led_supported
);
3737 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
3740 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
3742 static int led_read(char *p
)
3746 if (!led_supported
) {
3747 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3750 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3752 if (led_supported
== TPACPI_LED_570
) {
3755 for (i
= 0; i
< 8; i
++) {
3756 if (!acpi_evalf(ec_handle
,
3757 &status
, "GLED", "dd", 1 << i
))
3759 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
3760 i
, led_status(status
));
3764 len
+= sprintf(p
+ len
, "commands:\t"
3765 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
3770 /* off, on, blink */
3771 static const int led_sled_arg1
[] = { 0, 1, 3 };
3772 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
3773 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
3774 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
3776 static int led_write(char *buf
)
3784 while ((cmd
= next_cmd(&buf
))) {
3785 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
3788 if (strstr(cmd
, "off")) {
3790 } else if (strstr(cmd
, "on")) {
3792 } else if (strstr(cmd
, "blink")) {
3797 if (led_supported
== TPACPI_LED_570
) {
3800 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
3801 led
, led_sled_arg1
[ind
]))
3803 } else if (led_supported
== TPACPI_LED_OLD
) {
3804 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
3806 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
3808 ret
= ec_write(TPACPI_LED_EC_HLBL
,
3809 led
* led_exp_hlbl
[ind
]);
3811 ret
= ec_write(TPACPI_LED_EC_HLCL
,
3812 led
* led_exp_hlcl
[ind
]);
3817 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
3818 led
, led_led_arg1
[ind
]))
3826 static struct ibm_struct led_driver_data
= {
3832 /*************************************************************************
3836 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
3838 static int __init
beep_init(struct ibm_init_struct
*iibm
)
3840 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
3842 TPACPI_ACPIHANDLE_INIT(beep
);
3844 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
3845 str_supported(beep_handle
!= NULL
));
3847 return (beep_handle
)? 0 : 1;
3850 static int beep_read(char *p
)
3855 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3857 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3858 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
3864 static int beep_write(char *buf
)
3872 while ((cmd
= next_cmd(&buf
))) {
3873 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
3874 beep_cmd
>= 0 && beep_cmd
<= 17) {
3878 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
3885 static struct ibm_struct beep_driver_data
= {
3888 .write
= beep_write
,
3891 /*************************************************************************
3895 enum thermal_access_mode
{
3896 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
3897 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
3898 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
3899 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
3900 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
3903 enum { /* TPACPI_THERMAL_TPEC_* */
3904 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
3905 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
3906 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
3909 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
3910 struct ibm_thermal_sensors_struct
{
3911 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
3914 static enum thermal_access_mode thermal_read_mode
;
3916 /* idx is zero-based */
3917 static int thermal_get_sensor(int idx
, s32
*value
)
3923 t
= TP_EC_THERMAL_TMP0
;
3925 switch (thermal_read_mode
) {
3926 #if TPACPI_MAX_THERMAL_SENSORS >= 16
3927 case TPACPI_THERMAL_TPEC_16
:
3928 if (idx
>= 8 && idx
<= 15) {
3929 t
= TP_EC_THERMAL_TMP8
;
3934 case TPACPI_THERMAL_TPEC_8
:
3936 if (!acpi_ec_read(t
+ idx
, &tmp
))
3938 *value
= tmp
* 1000;
3943 case TPACPI_THERMAL_ACPI_UPDT
:
3945 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3946 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
3948 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3950 *value
= (t
- 2732) * 100;
3955 case TPACPI_THERMAL_ACPI_TMP07
:
3957 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3958 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3960 if (t
> 127 || t
< -127)
3961 t
= TP_EC_THERMAL_TMP_NA
;
3967 case TPACPI_THERMAL_NONE
:
3975 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
3986 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
3989 for (i
= 0 ; i
< n
; i
++) {
3990 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
3998 /* sysfs temp##_input -------------------------------------------------- */
4000 static ssize_t
thermal_temp_input_show(struct device
*dev
,
4001 struct device_attribute
*attr
,
4004 struct sensor_device_attribute
*sensor_attr
=
4005 to_sensor_dev_attr(attr
);
4006 int idx
= sensor_attr
->index
;
4010 res
= thermal_get_sensor(idx
, &value
);
4013 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
4016 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
4019 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
4020 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
4021 thermal_temp_input_show, NULL, _idxB)
4023 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
4024 THERMAL_SENSOR_ATTR_TEMP(1, 0),
4025 THERMAL_SENSOR_ATTR_TEMP(2, 1),
4026 THERMAL_SENSOR_ATTR_TEMP(3, 2),
4027 THERMAL_SENSOR_ATTR_TEMP(4, 3),
4028 THERMAL_SENSOR_ATTR_TEMP(5, 4),
4029 THERMAL_SENSOR_ATTR_TEMP(6, 5),
4030 THERMAL_SENSOR_ATTR_TEMP(7, 6),
4031 THERMAL_SENSOR_ATTR_TEMP(8, 7),
4032 THERMAL_SENSOR_ATTR_TEMP(9, 8),
4033 THERMAL_SENSOR_ATTR_TEMP(10, 9),
4034 THERMAL_SENSOR_ATTR_TEMP(11, 10),
4035 THERMAL_SENSOR_ATTR_TEMP(12, 11),
4036 THERMAL_SENSOR_ATTR_TEMP(13, 12),
4037 THERMAL_SENSOR_ATTR_TEMP(14, 13),
4038 THERMAL_SENSOR_ATTR_TEMP(15, 14),
4039 THERMAL_SENSOR_ATTR_TEMP(16, 15),
4042 #define THERMAL_ATTRS(X) \
4043 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
4045 static struct attribute
*thermal_temp_input_attr
[] = {
4065 static const struct attribute_group thermal_temp_input16_group
= {
4066 .attrs
= thermal_temp_input_attr
4069 static const struct attribute_group thermal_temp_input8_group
= {
4070 .attrs
= &thermal_temp_input_attr
[8]
4073 #undef THERMAL_SENSOR_ATTR_TEMP
4074 #undef THERMAL_ATTRS
4076 /* --------------------------------------------------------------------- */
4078 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
4085 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
4087 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
4089 if (thinkpad_id
.ec_model
) {
4091 * Direct EC access mode: sensors at registers
4092 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
4093 * non-implemented, thermal sensors return 0x80 when
4098 for (i
= 0; i
< 8; i
++) {
4099 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
4105 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
4113 /* This is sheer paranoia, but we handle it anyway */
4116 "ThinkPad ACPI EC access misbehaving, "
4117 "falling back to ACPI TMPx access "
4119 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
4122 "ThinkPad ACPI EC access misbehaving, "
4123 "disabling thermal sensors access\n");
4124 thermal_read_mode
= TPACPI_THERMAL_NONE
;
4129 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
4131 } else if (acpi_tmp7
) {
4132 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
4133 /* 600e/x, 770e, 770x */
4134 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
4136 /* Standard ACPI TMPx access, max 8 sensors */
4137 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
4140 /* temperatures not supported on 570, G4x, R30, R31, R32 */
4141 thermal_read_mode
= TPACPI_THERMAL_NONE
;
4144 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
4145 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
4148 switch (thermal_read_mode
) {
4149 case TPACPI_THERMAL_TPEC_16
:
4150 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4151 &thermal_temp_input16_group
);
4155 case TPACPI_THERMAL_TPEC_8
:
4156 case TPACPI_THERMAL_ACPI_TMP07
:
4157 case TPACPI_THERMAL_ACPI_UPDT
:
4158 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4159 &thermal_temp_input8_group
);
4163 case TPACPI_THERMAL_NONE
:
4171 static void thermal_exit(void)
4173 switch (thermal_read_mode
) {
4174 case TPACPI_THERMAL_TPEC_16
:
4175 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4176 &thermal_temp_input16_group
);
4178 case TPACPI_THERMAL_TPEC_8
:
4179 case TPACPI_THERMAL_ACPI_TMP07
:
4180 case TPACPI_THERMAL_ACPI_UPDT
:
4181 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
4182 &thermal_temp_input16_group
);
4184 case TPACPI_THERMAL_NONE
:
4190 static int thermal_read(char *p
)
4194 struct ibm_thermal_sensors_struct t
;
4196 n
= thermal_get_sensors(&t
);
4197 if (unlikely(n
< 0))
4200 len
+= sprintf(p
+ len
, "temperatures:\t");
4203 for (i
= 0; i
< (n
- 1); i
++)
4204 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
4205 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
4207 len
+= sprintf(p
+ len
, "not supported\n");
4212 static struct ibm_struct thermal_driver_data
= {
4214 .read
= thermal_read
,
4215 .exit
= thermal_exit
,
4218 /*************************************************************************
4222 static u8 ecdump_regs
[256];
4224 static int ecdump_read(char *p
)
4230 len
+= sprintf(p
+ len
, "EC "
4231 " +00 +01 +02 +03 +04 +05 +06 +07"
4232 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
4233 for (i
= 0; i
< 256; i
+= 16) {
4234 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
4235 for (j
= 0; j
< 16; j
++) {
4236 if (!acpi_ec_read(i
+ j
, &v
))
4238 if (v
!= ecdump_regs
[i
+ j
])
4239 len
+= sprintf(p
+ len
, " *%02x", v
);
4241 len
+= sprintf(p
+ len
, " %02x", v
);
4242 ecdump_regs
[i
+ j
] = v
;
4244 len
+= sprintf(p
+ len
, "\n");
4249 /* These are way too dangerous to advertise openly... */
4251 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
4252 " (<offset> is 00-ff, <value> is 00-ff)\n");
4253 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
4254 " (<offset> is 00-ff, <value> is 0-255)\n");
4259 static int ecdump_write(char *buf
)
4264 while ((cmd
= next_cmd(&buf
))) {
4265 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
4267 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
4271 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
4272 if (!acpi_ec_write(i
, v
))
4281 static struct ibm_struct ecdump_driver_data
= {
4283 .read
= ecdump_read
,
4284 .write
= ecdump_write
,
4285 .flags
.experimental
= 1,
4288 /*************************************************************************
4289 * Backlight/brightness subdriver
4292 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
4294 static struct backlight_device
*ibm_backlight_device
;
4295 static int brightness_offset
= 0x31;
4296 static int brightness_mode
;
4297 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
4299 static struct mutex brightness_mutex
;
4302 * ThinkPads can read brightness from two places: EC 0x31, or
4303 * CMOS NVRAM byte 0x5E, bits 0-3.
4305 static int brightness_get(struct backlight_device
*bd
)
4307 u8 lec
= 0, lcmos
= 0, level
= 0;
4309 if (brightness_mode
& 1) {
4310 if (!acpi_ec_read(brightness_offset
, &lec
))
4312 lec
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
4315 if (brightness_mode
& 2) {
4316 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
4317 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
4318 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
4319 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
4323 if (brightness_mode
== 3 && lec
!= lcmos
) {
4325 "CMOS NVRAM (%u) and EC (%u) do not agree "
4326 "on display brightness level\n",
4327 (unsigned int) lcmos
,
4328 (unsigned int) lec
);
4335 /* May return EINTR which can always be mapped to ERESTARTSYS */
4336 static int brightness_set(int value
)
4338 int cmos_cmd
, inc
, i
, res
;
4341 if (value
> ((tp_features
.bright_16levels
)? 15 : 7))
4344 res
= mutex_lock_interruptible(&brightness_mutex
);
4348 current_value
= brightness_get(NULL
);
4349 if (current_value
< 0) {
4350 res
= current_value
;
4354 cmos_cmd
= value
> current_value
?
4355 TP_CMOS_BRIGHTNESS_UP
:
4356 TP_CMOS_BRIGHTNESS_DOWN
;
4357 inc
= (value
> current_value
)? 1 : -1;
4360 for (i
= current_value
; i
!= value
; i
+= inc
) {
4361 if ((brightness_mode
& 2) &&
4362 issue_thinkpad_cmos_command(cmos_cmd
)) {
4366 if ((brightness_mode
& 1) &&
4367 !acpi_ec_write(brightness_offset
, i
+ inc
)) {
4374 mutex_unlock(&brightness_mutex
);
4378 /* sysfs backlight class ----------------------------------------------- */
4380 static int brightness_update_status(struct backlight_device
*bd
)
4382 /* it is the backlight class's job (caller) to handle
4383 * EINTR and other errors properly */
4384 return brightness_set(
4385 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
4386 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
4387 bd
->props
.brightness
: 0);
4390 static struct backlight_ops ibm_backlight_data
= {
4391 .get_brightness
= brightness_get
,
4392 .update_status
= brightness_update_status
,
4395 /* --------------------------------------------------------------------- */
4397 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
4401 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
4403 mutex_init(&brightness_mutex
);
4406 * We always attempt to detect acpi support, so as to switch
4407 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
4408 * going to publish a backlight interface
4410 b
= tpacpi_check_std_acpi_brightness_support();
4412 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
4413 printk(TPACPI_NOTICE
4414 "Lenovo BIOS switched to ACPI backlight "
4417 if (brightness_enable
> 1) {
4418 printk(TPACPI_NOTICE
4419 "standard ACPI backlight interface "
4420 "available, not loading native one...\n");
4425 if (!brightness_enable
) {
4426 dbg_printk(TPACPI_DBG_INIT
,
4427 "brightness support disabled by "
4428 "module parameter\n");
4434 "Unsupported brightness interface, "
4435 "please contact %s\n", TPACPI_MAIL
);
4439 tp_features
.bright_16levels
= 1;
4441 if (!brightness_mode
) {
4442 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
4443 brightness_mode
= 2;
4445 brightness_mode
= 3;
4447 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
4451 if (brightness_mode
> 3)
4454 b
= brightness_get(NULL
);
4458 if (tp_features
.bright_16levels
)
4460 "detected a 16-level brightness capable ThinkPad\n");
4462 ibm_backlight_device
= backlight_device_register(
4463 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
4464 &ibm_backlight_data
);
4465 if (IS_ERR(ibm_backlight_device
)) {
4466 printk(TPACPI_ERR
"Could not register backlight device\n");
4467 return PTR_ERR(ibm_backlight_device
);
4469 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
4471 ibm_backlight_device
->props
.max_brightness
=
4472 (tp_features
.bright_16levels
)? 15 : 7;
4473 ibm_backlight_device
->props
.brightness
= b
;
4474 backlight_update_status(ibm_backlight_device
);
4479 static void brightness_exit(void)
4481 if (ibm_backlight_device
) {
4482 vdbg_printk(TPACPI_DBG_EXIT
,
4483 "calling backlight_device_unregister()\n");
4484 backlight_device_unregister(ibm_backlight_device
);
4485 ibm_backlight_device
= NULL
;
4489 static int brightness_read(char *p
)
4494 level
= brightness_get(NULL
);
4496 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
4498 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
4499 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
4500 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
4501 " (<level> is 0-%d)\n",
4502 (tp_features
.bright_16levels
) ? 15 : 7);
4508 static int brightness_write(char *buf
)
4513 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
4515 level
= brightness_get(NULL
);
4519 while ((cmd
= next_cmd(&buf
))) {
4520 if (strlencmp(cmd
, "up") == 0) {
4521 if (level
< max_level
)
4523 } else if (strlencmp(cmd
, "down") == 0) {
4526 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
4527 level
>= 0 && level
<= max_level
) {
4534 * Now we know what the final level should be, so we try to set it.
4535 * Doing it this way makes the syscall restartable in case of EINTR
4537 rc
= brightness_set(level
);
4538 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
4541 static struct ibm_struct brightness_driver_data
= {
4542 .name
= "brightness",
4543 .read
= brightness_read
,
4544 .write
= brightness_write
,
4545 .exit
= brightness_exit
,
4548 /*************************************************************************
4552 static int volume_offset
= 0x30;
4554 static int volume_read(char *p
)
4559 if (!acpi_ec_read(volume_offset
, &level
)) {
4560 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
4562 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
4563 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
4564 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
4565 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
4566 " (<level> is 0-15)\n");
4572 static int volume_write(char *buf
)
4574 int cmos_cmd
, inc
, i
;
4576 int new_level
, new_mute
;
4579 while ((cmd
= next_cmd(&buf
))) {
4580 if (!acpi_ec_read(volume_offset
, &level
))
4582 new_mute
= mute
= level
& 0x40;
4583 new_level
= level
= level
& 0xf;
4585 if (strlencmp(cmd
, "up") == 0) {
4589 new_level
= level
== 15 ? 15 : level
+ 1;
4590 } else if (strlencmp(cmd
, "down") == 0) {
4594 new_level
= level
== 0 ? 0 : level
- 1;
4595 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
4596 new_level
>= 0 && new_level
<= 15) {
4598 } else if (strlencmp(cmd
, "mute") == 0) {
4603 if (new_level
!= level
) {
4604 /* mute doesn't change */
4606 cmos_cmd
= (new_level
> level
) ?
4607 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
4608 inc
= new_level
> level
? 1 : -1;
4610 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
4611 !acpi_ec_write(volume_offset
, level
)))
4614 for (i
= level
; i
!= new_level
; i
+= inc
)
4615 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
4616 !acpi_ec_write(volume_offset
, i
+ inc
))
4620 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
4621 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
4626 if (new_mute
!= mute
) {
4627 /* level doesn't change */
4629 cmos_cmd
= (new_mute
) ?
4630 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
4632 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
4633 !acpi_ec_write(volume_offset
, level
+ new_mute
))
4641 static struct ibm_struct volume_driver_data
= {
4643 .read
= volume_read
,
4644 .write
= volume_write
,
4647 /*************************************************************************
4654 * TPACPI_FAN_RD_ACPI_GFAN:
4655 * ACPI GFAN method: returns fan level
4657 * see TPACPI_FAN_WR_ACPI_SFAN
4658 * EC 0x2f (HFSP) not available if GFAN exists
4660 * TPACPI_FAN_WR_ACPI_SFAN:
4661 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
4663 * EC 0x2f (HFSP) might be available *for reading*, but do not use
4666 * TPACPI_FAN_WR_TPEC:
4667 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
4668 * Supported on almost all ThinkPads
4670 * Fan speed changes of any sort (including those caused by the
4671 * disengaged mode) are usually done slowly by the firmware as the
4672 * maximum ammount of fan duty cycle change per second seems to be
4675 * Reading is not available if GFAN exists.
4676 * Writing is not available if SFAN exists.
4679 * 7 automatic mode engaged;
4680 * (default operation mode of the ThinkPad)
4681 * fan level is ignored in this mode.
4682 * 6 full speed mode (takes precedence over bit 7);
4683 * not available on all thinkpads. May disable
4684 * the tachometer while the fan controller ramps up
4685 * the speed (which can take up to a few *minutes*).
4686 * Speeds up fan to 100% duty-cycle, which is far above
4687 * the standard RPM levels. It is not impossible that
4688 * it could cause hardware damage.
4689 * 5-3 unused in some models. Extra bits for fan level
4690 * in others, but still useless as all values above
4691 * 7 map to the same speed as level 7 in these models.
4692 * 2-0 fan level (0..7 usually)
4694 * 0x07 = max (set when temperatures critical)
4695 * Some ThinkPads may have other levels, see
4696 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
4698 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
4699 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
4700 * does so, its initial value is meaningless (0x07).
4702 * For firmware bugs, refer to:
4703 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
4707 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
4708 * Main fan tachometer reading (in RPM)
4710 * This register is present on all ThinkPads with a new-style EC, and
4711 * it is known not to be present on the A21m/e, and T22, as there is
4712 * something else in offset 0x84 according to the ACPI DSDT. Other
4713 * ThinkPads from this same time period (and earlier) probably lack the
4714 * tachometer as well.
4716 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
4717 * was never fixed by IBM to report the EC firmware version string
4718 * probably support the tachometer (like the early X models), so
4719 * detecting it is quite hard. We need more data to know for sure.
4721 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
4724 * FIRMWARE BUG: may go stale while the EC is switching to full speed
4727 * For firmware bugs, refer to:
4728 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
4730 * TPACPI_FAN_WR_ACPI_FANS:
4731 * ThinkPad X31, X40, X41. Not available in the X60.
4733 * FANS ACPI handle: takes three arguments: low speed, medium speed,
4734 * high speed. ACPI DSDT seems to map these three speeds to levels
4735 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
4736 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
4738 * The speeds are stored on handles
4739 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
4741 * There are three default speed sets, acessible as handles:
4742 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
4744 * ACPI DSDT switches which set is in use depending on various
4747 * TPACPI_FAN_WR_TPEC is also available and should be used to
4748 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
4749 * but the ACPI tables just mention level 7.
4752 enum { /* Fan control constants */
4753 fan_status_offset
= 0x2f, /* EC register 0x2f */
4754 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
4755 * 0x84 must be read before 0x85 */
4757 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
4758 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
4760 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
4763 enum fan_status_access_mode
{
4764 TPACPI_FAN_NONE
= 0, /* No fan status or control */
4765 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
4766 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
4769 enum fan_control_access_mode
{
4770 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
4771 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
4772 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
4773 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
4776 enum fan_control_commands
{
4777 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
4778 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
4779 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
4780 * and also watchdog cmd */
4783 static int fan_control_allowed
;
4785 static enum fan_status_access_mode fan_status_access_mode
;
4786 static enum fan_control_access_mode fan_control_access_mode
;
4787 static enum fan_control_commands fan_control_commands
;
4789 static u8 fan_control_initial_status
;
4790 static u8 fan_control_desired_level
;
4791 static int fan_watchdog_maxinterval
;
4793 static struct mutex fan_mutex
;
4795 static void fan_watchdog_fire(struct work_struct
*ignored
);
4796 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
4798 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
4799 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
4800 "\\FSPD", /* 600e/x, 770e, 770x */
4802 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
4803 "JFNS", /* 770x-JL */
4807 * Call with fan_mutex held
4809 static void fan_update_desired_level(u8 status
)
4812 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
4814 fan_control_desired_level
= 7;
4816 fan_control_desired_level
= status
;
4820 static int fan_get_status(u8
*status
)
4825 * Add TPACPI_FAN_RD_ACPI_FANS ? */
4827 switch (fan_status_access_mode
) {
4828 case TPACPI_FAN_RD_ACPI_GFAN
:
4829 /* 570, 600e/x, 770e, 770x */
4831 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
4839 case TPACPI_FAN_RD_TPEC
:
4840 /* all except 570, 600e/x, 770e, 770x */
4841 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
4856 static int fan_get_status_safe(u8
*status
)
4861 if (mutex_lock_interruptible(&fan_mutex
))
4862 return -ERESTARTSYS
;
4863 rc
= fan_get_status(&s
);
4865 fan_update_desired_level(s
);
4866 mutex_unlock(&fan_mutex
);
4874 static int fan_get_speed(unsigned int *speed
)
4878 switch (fan_status_access_mode
) {
4879 case TPACPI_FAN_RD_TPEC
:
4880 /* all except 570, 600e/x, 770e, 770x */
4881 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
4882 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
4886 *speed
= (hi
<< 8) | lo
;
4897 static int fan_set_level(int level
)
4899 if (!fan_control_allowed
)
4902 switch (fan_control_access_mode
) {
4903 case TPACPI_FAN_WR_ACPI_SFAN
:
4904 if (level
>= 0 && level
<= 7) {
4905 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
4911 case TPACPI_FAN_WR_ACPI_FANS
:
4912 case TPACPI_FAN_WR_TPEC
:
4913 if ((level
!= TP_EC_FAN_AUTO
) &&
4914 (level
!= TP_EC_FAN_FULLSPEED
) &&
4915 ((level
< 0) || (level
> 7)))
4918 /* safety net should the EC not support AUTO
4919 * or FULLSPEED mode bits and just ignore them */
4920 if (level
& TP_EC_FAN_FULLSPEED
)
4921 level
|= 7; /* safety min speed 7 */
4922 else if (level
& TP_EC_FAN_AUTO
)
4923 level
|= 4; /* safety min speed 4 */
4925 if (!acpi_ec_write(fan_status_offset
, level
))
4928 tp_features
.fan_ctrl_status_undef
= 0;
4937 static int fan_set_level_safe(int level
)
4941 if (!fan_control_allowed
)
4944 if (mutex_lock_interruptible(&fan_mutex
))
4945 return -ERESTARTSYS
;
4947 if (level
== TPACPI_FAN_LAST_LEVEL
)
4948 level
= fan_control_desired_level
;
4950 rc
= fan_set_level(level
);
4952 fan_update_desired_level(level
);
4954 mutex_unlock(&fan_mutex
);
4958 static int fan_set_enable(void)
4963 if (!fan_control_allowed
)
4966 if (mutex_lock_interruptible(&fan_mutex
))
4967 return -ERESTARTSYS
;
4969 switch (fan_control_access_mode
) {
4970 case TPACPI_FAN_WR_ACPI_FANS
:
4971 case TPACPI_FAN_WR_TPEC
:
4972 rc
= fan_get_status(&s
);
4976 /* Don't go out of emergency fan mode */
4979 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
4982 if (!acpi_ec_write(fan_status_offset
, s
))
4985 tp_features
.fan_ctrl_status_undef
= 0;
4990 case TPACPI_FAN_WR_ACPI_SFAN
:
4991 rc
= fan_get_status(&s
);
4997 /* Set fan to at least level 4 */
5000 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
5010 mutex_unlock(&fan_mutex
);
5014 static int fan_set_disable(void)
5018 if (!fan_control_allowed
)
5021 if (mutex_lock_interruptible(&fan_mutex
))
5022 return -ERESTARTSYS
;
5025 switch (fan_control_access_mode
) {
5026 case TPACPI_FAN_WR_ACPI_FANS
:
5027 case TPACPI_FAN_WR_TPEC
:
5028 if (!acpi_ec_write(fan_status_offset
, 0x00))
5031 fan_control_desired_level
= 0;
5032 tp_features
.fan_ctrl_status_undef
= 0;
5036 case TPACPI_FAN_WR_ACPI_SFAN
:
5037 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
5040 fan_control_desired_level
= 0;
5048 mutex_unlock(&fan_mutex
);
5052 static int fan_set_speed(int speed
)
5056 if (!fan_control_allowed
)
5059 if (mutex_lock_interruptible(&fan_mutex
))
5060 return -ERESTARTSYS
;
5063 switch (fan_control_access_mode
) {
5064 case TPACPI_FAN_WR_ACPI_FANS
:
5065 if (speed
>= 0 && speed
<= 65535) {
5066 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
5067 speed
, speed
, speed
))
5077 mutex_unlock(&fan_mutex
);
5081 static void fan_watchdog_reset(void)
5083 static int fan_watchdog_active
;
5085 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
5088 if (fan_watchdog_active
)
5089 cancel_delayed_work(&fan_watchdog_task
);
5091 if (fan_watchdog_maxinterval
> 0 &&
5092 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
5093 fan_watchdog_active
= 1;
5094 if (!schedule_delayed_work(&fan_watchdog_task
,
5095 msecs_to_jiffies(fan_watchdog_maxinterval
5098 "failed to schedule the fan watchdog, "
5099 "watchdog will not trigger\n");
5102 fan_watchdog_active
= 0;
5105 static void fan_watchdog_fire(struct work_struct
*ignored
)
5109 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
5112 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
5113 rc
= fan_set_enable();
5115 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
5116 "will try again later...\n", -rc
);
5117 /* reschedule for later */
5118 fan_watchdog_reset();
5123 * SYSFS fan layout: hwmon compatible (device)
5126 * 0: "disengaged" mode
5128 * 2: native EC "auto" mode (recommended, hardware default)
5130 * pwm*: set speed in manual mode, ignored otherwise.
5131 * 0 is level 0; 255 is level 7. Intermediate points done with linear
5134 * fan*_input: tachometer reading, RPM
5137 * SYSFS fan layout: extensions
5139 * fan_watchdog (driver):
5140 * fan watchdog interval in seconds, 0 disables (default), max 120
5143 /* sysfs fan pwm1_enable ----------------------------------------------- */
5144 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
5145 struct device_attribute
*attr
,
5151 res
= fan_get_status_safe(&status
);
5155 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5156 if (status
!= fan_control_initial_status
) {
5157 tp_features
.fan_ctrl_status_undef
= 0;
5159 /* Return most likely status. In fact, it
5160 * might be the only possible status */
5161 status
= TP_EC_FAN_AUTO
;
5165 if (status
& TP_EC_FAN_FULLSPEED
) {
5167 } else if (status
& TP_EC_FAN_AUTO
) {
5172 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
5175 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
5176 struct device_attribute
*attr
,
5177 const char *buf
, size_t count
)
5182 if (parse_strtoul(buf
, 2, &t
))
5187 level
= TP_EC_FAN_FULLSPEED
;
5190 level
= TPACPI_FAN_LAST_LEVEL
;
5193 level
= TP_EC_FAN_AUTO
;
5196 /* reserved for software-controlled auto mode */
5202 res
= fan_set_level_safe(level
);
5208 fan_watchdog_reset();
5213 static struct device_attribute dev_attr_fan_pwm1_enable
=
5214 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
5215 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
5217 /* sysfs fan pwm1 ------------------------------------------------------ */
5218 static ssize_t
fan_pwm1_show(struct device
*dev
,
5219 struct device_attribute
*attr
,
5225 res
= fan_get_status_safe(&status
);
5229 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5230 if (status
!= fan_control_initial_status
) {
5231 tp_features
.fan_ctrl_status_undef
= 0;
5233 status
= TP_EC_FAN_AUTO
;
5238 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
5239 status
= fan_control_desired_level
;
5244 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
5247 static ssize_t
fan_pwm1_store(struct device
*dev
,
5248 struct device_attribute
*attr
,
5249 const char *buf
, size_t count
)
5253 u8 status
, newlevel
;
5255 if (parse_strtoul(buf
, 255, &s
))
5258 /* scale down from 0-255 to 0-7 */
5259 newlevel
= (s
>> 5) & 0x07;
5261 if (mutex_lock_interruptible(&fan_mutex
))
5262 return -ERESTARTSYS
;
5264 rc
= fan_get_status(&status
);
5265 if (!rc
&& (status
&
5266 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
5267 rc
= fan_set_level(newlevel
);
5271 fan_update_desired_level(newlevel
);
5272 fan_watchdog_reset();
5276 mutex_unlock(&fan_mutex
);
5277 return (rc
)? rc
: count
;
5280 static struct device_attribute dev_attr_fan_pwm1
=
5281 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
5282 fan_pwm1_show
, fan_pwm1_store
);
5284 /* sysfs fan fan1_input ------------------------------------------------ */
5285 static ssize_t
fan_fan1_input_show(struct device
*dev
,
5286 struct device_attribute
*attr
,
5292 res
= fan_get_speed(&speed
);
5296 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
5299 static struct device_attribute dev_attr_fan_fan1_input
=
5300 __ATTR(fan1_input
, S_IRUGO
,
5301 fan_fan1_input_show
, NULL
);
5303 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
5304 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
5307 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
5310 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
5311 const char *buf
, size_t count
)
5315 if (parse_strtoul(buf
, 120, &t
))
5318 if (!fan_control_allowed
)
5321 fan_watchdog_maxinterval
= t
;
5322 fan_watchdog_reset();
5327 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
5328 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
5330 /* --------------------------------------------------------------------- */
5331 static struct attribute
*fan_attributes
[] = {
5332 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
5333 &dev_attr_fan_fan1_input
.attr
,
5337 static const struct attribute_group fan_attr_group
= {
5338 .attrs
= fan_attributes
,
5341 static int __init
fan_init(struct ibm_init_struct
*iibm
)
5345 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
5347 mutex_init(&fan_mutex
);
5348 fan_status_access_mode
= TPACPI_FAN_NONE
;
5349 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
5350 fan_control_commands
= 0;
5351 fan_watchdog_maxinterval
= 0;
5352 tp_features
.fan_ctrl_status_undef
= 0;
5353 fan_control_desired_level
= 7;
5355 TPACPI_ACPIHANDLE_INIT(fans
);
5356 TPACPI_ACPIHANDLE_INIT(gfan
);
5357 TPACPI_ACPIHANDLE_INIT(sfan
);
5360 /* 570, 600e/x, 770e, 770x */
5361 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
5363 /* all other ThinkPads: note that even old-style
5364 * ThinkPad ECs supports the fan control register */
5365 if (likely(acpi_ec_read(fan_status_offset
,
5366 &fan_control_initial_status
))) {
5367 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
5369 /* In some ThinkPads, neither the EC nor the ACPI
5370 * DSDT initialize the fan status, and it ends up
5371 * being set to 0x07 when it *could* be either
5374 * Enable for TP-1Y (T43), TP-78 (R51e),
5375 * TP-76 (R52), TP-70 (T43, R52), which are known
5377 if (fan_control_initial_status
== 0x07) {
5378 switch (thinkpad_id
.ec_model
) {
5379 case 0x5931: /* TP-1Y */
5380 case 0x3837: /* TP-78 */
5381 case 0x3637: /* TP-76 */
5382 case 0x3037: /* TP-70 */
5383 printk(TPACPI_NOTICE
5384 "fan_init: initial fan status "
5385 "is unknown, assuming it is "
5387 tp_features
.fan_ctrl_status_undef
= 1;
5393 "ThinkPad ACPI EC access misbehaving, "
5394 "fan status and control unavailable\n");
5401 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
5402 fan_control_commands
|=
5403 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
5406 /* gfan without sfan means no fan control */
5407 /* all other models implement TP EC 0x2f control */
5411 fan_control_access_mode
=
5412 TPACPI_FAN_WR_ACPI_FANS
;
5413 fan_control_commands
|=
5414 TPACPI_FAN_CMD_SPEED
|
5415 TPACPI_FAN_CMD_LEVEL
|
5416 TPACPI_FAN_CMD_ENABLE
;
5418 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
5419 fan_control_commands
|=
5420 TPACPI_FAN_CMD_LEVEL
|
5421 TPACPI_FAN_CMD_ENABLE
;
5426 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
5427 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
5428 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
5429 fan_status_access_mode
, fan_control_access_mode
);
5431 /* fan control master switch */
5432 if (!fan_control_allowed
) {
5433 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
5434 fan_control_commands
= 0;
5435 dbg_printk(TPACPI_DBG_INIT
,
5436 "fan control features disabled by parameter\n");
5439 /* update fan_control_desired_level */
5440 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
5441 fan_get_status_safe(NULL
);
5443 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
5444 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
5445 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5448 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
5449 &driver_attr_fan_watchdog
);
5457 static void fan_exit(void)
5459 vdbg_printk(TPACPI_DBG_EXIT
,
5460 "cancelling any pending fan watchdog tasks\n");
5462 /* FIXME: can we really do this unconditionally? */
5463 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
5464 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
5465 &driver_attr_fan_watchdog
);
5467 cancel_delayed_work(&fan_watchdog_task
);
5468 flush_scheduled_work();
5471 static int fan_read(char *p
)
5476 unsigned int speed
= 0;
5478 switch (fan_status_access_mode
) {
5479 case TPACPI_FAN_RD_ACPI_GFAN
:
5480 /* 570, 600e/x, 770e, 770x */
5481 rc
= fan_get_status_safe(&status
);
5485 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
5487 (status
!= 0) ? "enabled" : "disabled", status
);
5490 case TPACPI_FAN_RD_TPEC
:
5491 /* all except 570, 600e/x, 770e, 770x */
5492 rc
= fan_get_status_safe(&status
);
5496 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5497 if (status
!= fan_control_initial_status
)
5498 tp_features
.fan_ctrl_status_undef
= 0;
5500 /* Return most likely status. In fact, it
5501 * might be the only possible status */
5502 status
= TP_EC_FAN_AUTO
;
5505 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
5506 (status
!= 0) ? "enabled" : "disabled");
5508 rc
= fan_get_speed(&speed
);
5512 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
5514 if (status
& TP_EC_FAN_FULLSPEED
)
5515 /* Disengaged mode takes precedence */
5516 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
5517 else if (status
& TP_EC_FAN_AUTO
)
5518 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
5520 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
5523 case TPACPI_FAN_NONE
:
5525 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5528 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
5529 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
5531 switch (fan_control_access_mode
) {
5532 case TPACPI_FAN_WR_ACPI_SFAN
:
5533 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
5537 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
5538 "auto, disengaged, full-speed)\n");
5543 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
5544 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
5545 "commands:\twatchdog <timeout> (<timeout> "
5546 "is 0 (off), 1-120 (seconds))\n");
5548 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
5549 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
5550 " (<speed> is 0-65535)\n");
5555 static int fan_write_cmd_level(const char *cmd
, int *rc
)
5559 if (strlencmp(cmd
, "level auto") == 0)
5560 level
= TP_EC_FAN_AUTO
;
5561 else if ((strlencmp(cmd
, "level disengaged") == 0) |
5562 (strlencmp(cmd
, "level full-speed") == 0))
5563 level
= TP_EC_FAN_FULLSPEED
;
5564 else if (sscanf(cmd
, "level %d", &level
) != 1)
5567 *rc
= fan_set_level_safe(level
);
5569 printk(TPACPI_ERR
"level command accepted for unsupported "
5570 "access mode %d", fan_control_access_mode
);
5575 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
5577 if (strlencmp(cmd
, "enable") != 0)
5580 *rc
= fan_set_enable();
5582 printk(TPACPI_ERR
"enable command accepted for unsupported "
5583 "access mode %d", fan_control_access_mode
);
5588 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
5590 if (strlencmp(cmd
, "disable") != 0)
5593 *rc
= fan_set_disable();
5595 printk(TPACPI_ERR
"disable command accepted for unsupported "
5596 "access mode %d", fan_control_access_mode
);
5601 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
5606 * Support speed <low> <medium> <high> ? */
5608 if (sscanf(cmd
, "speed %d", &speed
) != 1)
5611 *rc
= fan_set_speed(speed
);
5613 printk(TPACPI_ERR
"speed command accepted for unsupported "
5614 "access mode %d", fan_control_access_mode
);
5619 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
5623 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
5626 if (interval
< 0 || interval
> 120)
5629 fan_watchdog_maxinterval
= interval
;
5634 static int fan_write(char *buf
)
5639 while (!rc
&& (cmd
= next_cmd(&buf
))) {
5640 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
5641 fan_write_cmd_level(cmd
, &rc
)) &&
5642 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
5643 (fan_write_cmd_enable(cmd
, &rc
) ||
5644 fan_write_cmd_disable(cmd
, &rc
) ||
5645 fan_write_cmd_watchdog(cmd
, &rc
))) &&
5646 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
5647 fan_write_cmd_speed(cmd
, &rc
))
5651 fan_watchdog_reset();
5657 static struct ibm_struct fan_driver_data
= {
5664 /****************************************************************************
5665 ****************************************************************************
5669 ****************************************************************************
5670 ****************************************************************************/
5672 /* sysfs name ---------------------------------------------------------- */
5673 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
5674 struct device_attribute
*attr
,
5677 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
5680 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
5681 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
5683 /* --------------------------------------------------------------------- */
5686 static struct proc_dir_entry
*proc_dir
;
5689 * Module and infrastructure proble, init and exit handling
5692 static int force_load
;
5694 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
5695 static const char * __init
str_supported(int is_supported
)
5697 static char text_unsupported
[] __initdata
= "not supported";
5699 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
5701 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
5703 static void ibm_exit(struct ibm_struct
*ibm
)
5705 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
5707 list_del_init(&ibm
->all_drivers
);
5709 if (ibm
->flags
.acpi_notify_installed
) {
5710 dbg_printk(TPACPI_DBG_EXIT
,
5711 "%s: acpi_remove_notify_handler\n", ibm
->name
);
5713 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
5715 dispatch_acpi_notify
);
5716 ibm
->flags
.acpi_notify_installed
= 0;
5717 ibm
->flags
.acpi_notify_installed
= 0;
5720 if (ibm
->flags
.proc_created
) {
5721 dbg_printk(TPACPI_DBG_EXIT
,
5722 "%s: remove_proc_entry\n", ibm
->name
);
5723 remove_proc_entry(ibm
->name
, proc_dir
);
5724 ibm
->flags
.proc_created
= 0;
5727 if (ibm
->flags
.acpi_driver_registered
) {
5728 dbg_printk(TPACPI_DBG_EXIT
,
5729 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
5731 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
5732 kfree(ibm
->acpi
->driver
);
5733 ibm
->acpi
->driver
= NULL
;
5734 ibm
->flags
.acpi_driver_registered
= 0;
5737 if (ibm
->flags
.init_called
&& ibm
->exit
) {
5739 ibm
->flags
.init_called
= 0;
5742 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
5745 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
5748 struct ibm_struct
*ibm
= iibm
->data
;
5749 struct proc_dir_entry
*entry
;
5751 BUG_ON(ibm
== NULL
);
5753 INIT_LIST_HEAD(&ibm
->all_drivers
);
5755 if (ibm
->flags
.experimental
&& !experimental
)
5758 dbg_printk(TPACPI_DBG_INIT
,
5759 "probing for %s\n", ibm
->name
);
5762 ret
= iibm
->init(iibm
);
5764 return 0; /* probe failed */
5768 ibm
->flags
.init_called
= 1;
5772 if (ibm
->acpi
->hid
) {
5773 ret
= register_tpacpi_subdriver(ibm
);
5778 if (ibm
->acpi
->notify
) {
5779 ret
= setup_acpi_notify(ibm
);
5780 if (ret
== -ENODEV
) {
5781 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
5791 dbg_printk(TPACPI_DBG_INIT
,
5792 "%s installed\n", ibm
->name
);
5795 entry
= create_proc_entry(ibm
->name
,
5796 S_IFREG
| S_IRUGO
| S_IWUSR
,
5799 printk(TPACPI_ERR
"unable to create proc entry %s\n",
5804 entry
->owner
= THIS_MODULE
;
5806 entry
->read_proc
= &dispatch_procfs_read
;
5808 entry
->write_proc
= &dispatch_procfs_write
;
5809 ibm
->flags
.proc_created
= 1;
5812 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
5817 dbg_printk(TPACPI_DBG_INIT
,
5818 "%s: at error exit path with result %d\n",
5822 return (ret
< 0)? ret
: 0;
5827 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
5829 const struct dmi_device
*dev
= NULL
;
5830 char ec_fw_string
[18];
5835 memset(tp
, 0, sizeof(*tp
));
5837 if (dmi_name_in_vendors("IBM"))
5838 tp
->vendor
= PCI_VENDOR_ID_IBM
;
5839 else if (dmi_name_in_vendors("LENOVO"))
5840 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
5844 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
5846 if (!tp
->bios_version_str
)
5848 tp
->bios_model
= tp
->bios_version_str
[0]
5849 | (tp
->bios_version_str
[1] << 8);
5852 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
5853 * X32 or newer, all Z series; Some models must have an
5854 * up-to-date BIOS or they will not be detected.
5856 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
5858 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
5859 if (sscanf(dev
->name
,
5860 "IBM ThinkPad Embedded Controller -[%17c",
5861 ec_fw_string
) == 1) {
5862 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
5863 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
5865 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
5866 tp
->ec_model
= ec_fw_string
[0]
5867 | (ec_fw_string
[1] << 8);
5872 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
5874 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
5875 kfree(tp
->model_str
);
5876 tp
->model_str
= NULL
;
5880 static int __init
probe_for_thinkpad(void)
5888 * Non-ancient models have better DMI tagging, but very old models
5891 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
5893 /* ec is required because many other handles are relative to it */
5894 TPACPI_ACPIHANDLE_INIT(ec
);
5898 "Not yet supported ThinkPad detected!\n");
5903 * Risks a regression on very old machines, but reduces potential
5904 * false positives a damn great deal
5907 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
5909 if (!is_thinkpad
&& !force_load
)
5916 /* Module init, exit, parameters */
5918 static struct ibm_init_struct ibms_init
[] __initdata
= {
5920 .init
= thinkpad_acpi_driver_init
,
5921 .data
= &thinkpad_acpi_driver_data
,
5924 .init
= hotkey_init
,
5925 .data
= &hotkey_driver_data
,
5928 .init
= bluetooth_init
,
5929 .data
= &bluetooth_driver_data
,
5933 .data
= &wan_driver_data
,
5935 #ifdef CONFIG_THINKPAD_ACPI_VIDEO
5938 .data
= &video_driver_data
,
5943 .data
= &light_driver_data
,
5945 #ifdef CONFIG_THINKPAD_ACPI_DOCK
5948 .data
= &dock_driver_data
[0],
5952 .data
= &dock_driver_data
[1],
5955 #ifdef CONFIG_THINKPAD_ACPI_BAY
5958 .data
= &bay_driver_data
,
5963 .data
= &cmos_driver_data
,
5967 .data
= &led_driver_data
,
5971 .data
= &beep_driver_data
,
5974 .init
= thermal_init
,
5975 .data
= &thermal_driver_data
,
5978 .data
= &ecdump_driver_data
,
5981 .init
= brightness_init
,
5982 .data
= &brightness_driver_data
,
5985 .data
= &volume_driver_data
,
5989 .data
= &fan_driver_data
,
5993 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
5996 struct ibm_struct
*ibm
;
5998 if (!kp
|| !kp
->name
|| !val
)
6001 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
6002 ibm
= ibms_init
[i
].data
;
6003 WARN_ON(ibm
== NULL
);
6005 if (!ibm
|| !ibm
->name
)
6008 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
6009 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
6011 strcpy(ibms_init
[i
].param
, val
);
6012 strcat(ibms_init
[i
].param
, ",");
6020 module_param(experimental
, int, 0);
6021 MODULE_PARM_DESC(experimental
,
6022 "Enables experimental features when non-zero");
6024 module_param_named(debug
, dbg_level
, uint
, 0);
6025 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
6027 module_param(force_load
, bool, 0);
6028 MODULE_PARM_DESC(force_load
,
6029 "Attempts to load the driver even on a "
6030 "mis-identified ThinkPad when true");
6032 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
6033 MODULE_PARM_DESC(fan_control
,
6034 "Enables setting fan parameters features when true");
6036 module_param_named(brightness_mode
, brightness_mode
, int, 0);
6037 MODULE_PARM_DESC(brightness_mode
,
6038 "Selects brightness control strategy: "
6039 "0=auto, 1=EC, 2=CMOS, 3=both");
6041 module_param(brightness_enable
, uint
, 0);
6042 MODULE_PARM_DESC(brightness_enable
,
6043 "Enables backlight control when 1, disables when 0");
6045 module_param(hotkey_report_mode
, uint
, 0);
6046 MODULE_PARM_DESC(hotkey_report_mode
,
6047 "used for backwards compatibility with userspace, "
6048 "see documentation");
6050 #define TPACPI_PARAM(feature) \
6051 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
6052 MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command " \
6053 "at module load, see documentation")
6055 TPACPI_PARAM(hotkey
);
6056 TPACPI_PARAM(bluetooth
);
6057 TPACPI_PARAM(video
);
6058 TPACPI_PARAM(light
);
6059 #ifdef CONFIG_THINKPAD_ACPI_DOCK
6062 #ifdef CONFIG_THINKPAD_ACPI_BAY
6064 #endif /* CONFIG_THINKPAD_ACPI_BAY */
6068 TPACPI_PARAM(ecdump
);
6069 TPACPI_PARAM(brightness
);
6070 TPACPI_PARAM(volume
);
6073 static void thinkpad_acpi_module_exit(void)
6075 struct ibm_struct
*ibm
, *itmp
;
6077 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
6079 list_for_each_entry_safe_reverse(ibm
, itmp
,
6080 &tpacpi_all_drivers
,
6085 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
6087 if (tpacpi_inputdev
) {
6088 if (tp_features
.input_device_registered
)
6089 input_unregister_device(tpacpi_inputdev
);
6091 input_free_device(tpacpi_inputdev
);
6095 hwmon_device_unregister(tpacpi_hwmon
);
6097 if (tp_features
.sensors_pdev_attrs_registered
)
6098 device_remove_file(&tpacpi_sensors_pdev
->dev
,
6099 &dev_attr_thinkpad_acpi_pdev_name
);
6100 if (tpacpi_sensors_pdev
)
6101 platform_device_unregister(tpacpi_sensors_pdev
);
6103 platform_device_unregister(tpacpi_pdev
);
6105 if (tp_features
.sensors_pdrv_attrs_registered
)
6106 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
6107 if (tp_features
.platform_drv_attrs_registered
)
6108 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
6110 if (tp_features
.sensors_pdrv_registered
)
6111 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
6113 if (tp_features
.platform_drv_registered
)
6114 platform_driver_unregister(&tpacpi_pdriver
);
6117 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
6119 kfree(thinkpad_id
.bios_version_str
);
6120 kfree(thinkpad_id
.ec_version_str
);
6121 kfree(thinkpad_id
.model_str
);
6125 static int __init
thinkpad_acpi_module_init(void)
6129 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
6131 /* Parameter checking */
6132 if (hotkey_report_mode
> 2)
6135 /* Driver-level probe */
6137 get_thinkpad_model_data(&thinkpad_id
);
6138 ret
= probe_for_thinkpad();
6140 thinkpad_acpi_module_exit();
6144 /* Driver initialization */
6146 TPACPI_ACPIHANDLE_INIT(ecrd
);
6147 TPACPI_ACPIHANDLE_INIT(ecwr
);
6149 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
6152 "unable to create proc dir " TPACPI_PROC_DIR
);
6153 thinkpad_acpi_module_exit();
6156 proc_dir
->owner
= THIS_MODULE
;
6158 ret
= platform_driver_register(&tpacpi_pdriver
);
6161 "unable to register main platform driver\n");
6162 thinkpad_acpi_module_exit();
6165 tp_features
.platform_drv_registered
= 1;
6167 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
6170 "unable to register hwmon platform driver\n");
6171 thinkpad_acpi_module_exit();
6174 tp_features
.sensors_pdrv_registered
= 1;
6176 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
6178 tp_features
.platform_drv_attrs_registered
= 1;
6179 ret
= tpacpi_create_driver_attributes(
6180 &tpacpi_hwmon_pdriver
.driver
);
6184 "unable to create sysfs driver attributes\n");
6185 thinkpad_acpi_module_exit();
6188 tp_features
.sensors_pdrv_attrs_registered
= 1;
6191 /* Device initialization */
6192 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
6194 if (IS_ERR(tpacpi_pdev
)) {
6195 ret
= PTR_ERR(tpacpi_pdev
);
6197 printk(TPACPI_ERR
"unable to register platform device\n");
6198 thinkpad_acpi_module_exit();
6201 tpacpi_sensors_pdev
= platform_device_register_simple(
6202 TPACPI_HWMON_DRVR_NAME
,
6204 if (IS_ERR(tpacpi_sensors_pdev
)) {
6205 ret
= PTR_ERR(tpacpi_sensors_pdev
);
6206 tpacpi_sensors_pdev
= NULL
;
6208 "unable to register hwmon platform device\n");
6209 thinkpad_acpi_module_exit();
6212 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
6213 &dev_attr_thinkpad_acpi_pdev_name
);
6216 "unable to create sysfs hwmon device attributes\n");
6217 thinkpad_acpi_module_exit();
6220 tp_features
.sensors_pdev_attrs_registered
= 1;
6221 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
6222 if (IS_ERR(tpacpi_hwmon
)) {
6223 ret
= PTR_ERR(tpacpi_hwmon
);
6224 tpacpi_hwmon
= NULL
;
6225 printk(TPACPI_ERR
"unable to register hwmon device\n");
6226 thinkpad_acpi_module_exit();
6229 mutex_init(&tpacpi_inputdev_send_mutex
);
6230 tpacpi_inputdev
= input_allocate_device();
6231 if (!tpacpi_inputdev
) {
6232 printk(TPACPI_ERR
"unable to allocate input device\n");
6233 thinkpad_acpi_module_exit();
6236 /* Prepare input device, but don't register */
6237 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
6238 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
6239 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
6240 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
6241 thinkpad_id
.vendor
:
6243 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
6244 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
6246 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
6247 ret
= ibm_init(&ibms_init
[i
]);
6248 if (ret
>= 0 && *ibms_init
[i
].param
)
6249 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
6251 thinkpad_acpi_module_exit();
6255 ret
= input_register_device(tpacpi_inputdev
);
6257 printk(TPACPI_ERR
"unable to register input device\n");
6258 thinkpad_acpi_module_exit();
6261 tp_features
.input_device_registered
= 1;
6264 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
6268 /* Please remove this in year 2009 */
6269 MODULE_ALIAS("ibm_acpi");
6272 * DMI matching for module autoloading
6274 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
6275 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
6277 * Only models listed in thinkwiki will be supported, so add yours
6278 * if it is not there yet.
6280 #define IBM_BIOS_MODULE_ALIAS(__type) \
6281 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
6283 /* Non-ancient thinkpads */
6284 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
6285 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
6287 /* Ancient thinkpad BIOSes have to be identified by
6288 * BIOS type or model number, and there are far less
6289 * BIOS types than model numbers... */
6290 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
6291 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
6292 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
6294 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
6295 MODULE_DESCRIPTION(TPACPI_DESC
);
6296 MODULE_VERSION(TPACPI_VERSION
);
6297 MODULE_LICENSE("GPL");
6299 module_init(thinkpad_acpi_module_init
);
6300 module_exit(thinkpad_acpi_module_exit
);