2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2007 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.18"
25 #define TPACPI_SYSFS_VERSION 0x020101
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
226 u32 bright_16levels
:1;
228 u32 fan_ctrl_status_undef
:1;
229 u32 input_device_registered
:1;
230 u32 platform_drv_registered
:1;
231 u32 platform_drv_attrs_registered
:1;
232 u32 sensors_pdrv_registered
:1;
233 u32 sensors_pdrv_attrs_registered
:1;
234 u32 sensors_pdev_attrs_registered
:1;
235 u32 hotkey_poll_active
:1;
238 struct thinkpad_id_data
{
239 unsigned int vendor
; /* ThinkPad vendor:
240 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
242 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
243 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
245 u16 bios_model
; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */
250 static struct thinkpad_id_data thinkpad_id
;
253 TPACPI_LIFE_INIT
= 0,
258 static int experimental
;
259 static u32 dbg_level
;
261 /****************************************************************************
262 ****************************************************************************
264 * ACPI Helpers and device model
266 ****************************************************************************
267 ****************************************************************************/
269 /*************************************************************************
273 static acpi_handle root_handle
;
275 #define TPACPI_HANDLE(object, parent, paths...) \
276 static acpi_handle object##_handle; \
277 static acpi_handle *object##_parent = &parent##_handle; \
278 static char *object##_path; \
279 static char *object##_paths[] = { paths }
281 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
282 "\\_SB.PCI.ISA.EC", /* 570 */
283 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
284 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
285 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
286 "\\_SB.PCI0.ICH3.EC0", /* R31 */
287 "\\_SB.PCI0.LPC.EC", /* all others */
290 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
291 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
293 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
295 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
296 "\\CMS", /* R40, R40e */
299 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
300 "^HKEY", /* R30, R31 */
301 "HKEY", /* all others */
305 /*************************************************************************
309 static int acpi_evalf(acpi_handle handle
,
310 void *res
, char *method
, char *fmt
, ...)
313 struct acpi_object_list params
;
314 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
315 struct acpi_buffer result
, *resultp
;
316 union acpi_object out_obj
;
324 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
337 params
.pointer
= &in_objs
[0];
344 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
345 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
347 /* add more types as needed */
349 printk(TPACPI_ERR
"acpi_evalf() called "
350 "with invalid format character '%c'\n", c
);
356 if (res_type
!= 'v') {
357 result
.length
= sizeof(out_obj
);
358 result
.pointer
= &out_obj
;
363 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
368 *(int *)res
= out_obj
.integer
.value
;
369 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
372 success
= status
== AE_OK
;
374 /* add more types as needed */
376 printk(TPACPI_ERR
"acpi_evalf() called "
377 "with invalid format character '%c'\n", res_type
);
381 if (!success
&& !quiet
)
382 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
383 method
, fmt0
, status
);
388 static int acpi_ec_read(int i
, u8
*p
)
393 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
397 if (ec_read(i
, p
) < 0)
404 static int acpi_ec_write(int i
, u8 v
)
407 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
410 if (ec_write(i
, v
) < 0)
417 static int _sta(acpi_handle handle
)
421 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
427 static int issue_thinkpad_cmos_command(int cmos_cmd
)
432 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
438 /*************************************************************************
442 #define TPACPI_ACPIHANDLE_INIT(object) \
443 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
444 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
446 static void drv_acpi_handle_init(char *name
,
447 acpi_handle
*handle
, acpi_handle parent
,
448 char **paths
, int num_paths
, char **path
)
453 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
456 for (i
= 0; i
< num_paths
; i
++) {
457 status
= acpi_get_handle(parent
, paths
[i
], handle
);
458 if (ACPI_SUCCESS(status
)) {
460 dbg_printk(TPACPI_DBG_INIT
,
461 "Found ACPI handle %s for %s\n",
467 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
472 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
474 struct ibm_struct
*ibm
= data
;
476 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
479 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
482 ibm
->acpi
->notify(ibm
, event
);
485 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
492 if (!*ibm
->acpi
->handle
)
495 vdbg_printk(TPACPI_DBG_INIT
,
496 "setting up ACPI notify for %s\n", ibm
->name
);
498 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
500 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
505 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
506 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
507 TPACPI_ACPI_EVENT_PREFIX
,
510 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
511 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
512 if (ACPI_FAILURE(status
)) {
513 if (status
== AE_ALREADY_EXISTS
) {
515 "another device driver is already "
516 "handling %s events\n", ibm
->name
);
519 "acpi_install_notify_handler(%s) failed: %d\n",
524 ibm
->flags
.acpi_notify_installed
= 1;
528 static int __init
tpacpi_device_add(struct acpi_device
*device
)
533 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
537 dbg_printk(TPACPI_DBG_INIT
,
538 "registering %s as an ACPI driver\n", ibm
->name
);
542 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
543 if (!ibm
->acpi
->driver
) {
544 printk(TPACPI_ERR
"kzalloc(ibm->driver) failed\n");
548 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
549 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
551 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
553 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
555 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
557 kfree(ibm
->acpi
->driver
);
558 ibm
->acpi
->driver
= NULL
;
560 ibm
->flags
.acpi_driver_registered
= 1;
566 /****************************************************************************
567 ****************************************************************************
571 ****************************************************************************
572 ****************************************************************************/
574 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
575 int count
, int *eof
, void *data
)
577 struct ibm_struct
*ibm
= data
;
580 if (!ibm
|| !ibm
->read
)
583 len
= ibm
->read(page
);
587 if (len
<= off
+ count
)
599 static int dispatch_procfs_write(struct file
*file
,
600 const char __user
*userbuf
,
601 unsigned long count
, void *data
)
603 struct ibm_struct
*ibm
= data
;
607 if (!ibm
|| !ibm
->write
)
610 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
614 if (copy_from_user(kernbuf
, userbuf
, count
)) {
620 strcat(kernbuf
, ",");
621 ret
= ibm
->write(kernbuf
);
630 static char *next_cmd(char **cmds
)
635 while ((end
= strchr(start
, ',')) && end
== start
)
647 /****************************************************************************
648 ****************************************************************************
650 * Device model: input, hwmon and platform
652 ****************************************************************************
653 ****************************************************************************/
655 static struct platform_device
*tpacpi_pdev
;
656 static struct platform_device
*tpacpi_sensors_pdev
;
657 static struct device
*tpacpi_hwmon
;
658 static struct input_dev
*tpacpi_inputdev
;
659 static struct mutex tpacpi_inputdev_send_mutex
;
660 static LIST_HEAD(tpacpi_all_drivers
);
662 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
665 struct ibm_struct
*ibm
, *itmp
;
667 list_for_each_entry_safe(ibm
, itmp
,
671 (ibm
->suspend
)(state
);
677 static int tpacpi_resume_handler(struct platform_device
*pdev
)
679 struct ibm_struct
*ibm
, *itmp
;
681 list_for_each_entry_safe(ibm
, itmp
,
691 static struct platform_driver tpacpi_pdriver
= {
693 .name
= TPACPI_DRVR_NAME
,
694 .owner
= THIS_MODULE
,
696 .suspend
= tpacpi_suspend_handler
,
697 .resume
= tpacpi_resume_handler
,
700 static struct platform_driver tpacpi_hwmon_pdriver
= {
702 .name
= TPACPI_HWMON_DRVR_NAME
,
703 .owner
= THIS_MODULE
,
707 /*************************************************************************
708 * sysfs support helpers
711 struct attribute_set
{
712 unsigned int members
, max_members
;
713 struct attribute_group group
;
716 struct attribute_set_obj
{
717 struct attribute_set s
;
719 } __attribute__((packed
));
721 static struct attribute_set
*create_attr_set(unsigned int max_members
,
724 struct attribute_set_obj
*sobj
;
726 if (max_members
== 0)
729 /* Allocates space for implicit NULL at the end too */
730 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
731 max_members
* sizeof(struct attribute
*),
735 sobj
->s
.max_members
= max_members
;
736 sobj
->s
.group
.attrs
= &sobj
->a
;
737 sobj
->s
.group
.name
= name
;
742 #define destroy_attr_set(_set) \
745 /* not multi-threaded safe, use it in a single thread per set */
746 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
751 if (s
->members
>= s
->max_members
)
754 s
->group
.attrs
[s
->members
] = attr
;
760 static int add_many_to_attr_set(struct attribute_set
*s
,
761 struct attribute
**attr
,
766 for (i
= 0; i
< count
; i
++) {
767 res
= add_to_attr_set(s
, attr
[i
]);
775 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
777 sysfs_remove_group(kobj
, &s
->group
);
781 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
782 sysfs_create_group(_kobj, &_attr_set->group)
784 static int parse_strtoul(const char *buf
,
785 unsigned long max
, unsigned long *value
)
789 while (*buf
&& isspace(*buf
))
791 *value
= simple_strtoul(buf
, &endp
, 0);
792 while (*endp
&& isspace(*endp
))
794 if (*endp
|| *value
> max
)
800 /*************************************************************************
801 * thinkpad-acpi driver attributes
804 /* interface_version --------------------------------------------------- */
805 static ssize_t
tpacpi_driver_interface_version_show(
806 struct device_driver
*drv
,
809 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
812 static DRIVER_ATTR(interface_version
, S_IRUGO
,
813 tpacpi_driver_interface_version_show
, NULL
);
815 /* debug_level --------------------------------------------------------- */
816 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
819 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
822 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
823 const char *buf
, size_t count
)
827 if (parse_strtoul(buf
, 0xffff, &t
))
835 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
836 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
838 /* version ------------------------------------------------------------- */
839 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
842 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
843 TPACPI_DESC
, TPACPI_VERSION
);
846 static DRIVER_ATTR(version
, S_IRUGO
,
847 tpacpi_driver_version_show
, NULL
);
849 /* --------------------------------------------------------------------- */
851 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
852 &driver_attr_debug_level
, &driver_attr_version
,
853 &driver_attr_interface_version
,
856 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
862 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
863 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
870 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
874 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
875 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
878 /****************************************************************************
879 ****************************************************************************
883 ****************************************************************************
884 ****************************************************************************/
886 /*************************************************************************
887 * thinkpad-acpi init subdriver
890 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
892 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
893 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
895 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
896 (thinkpad_id
.bios_version_str
) ?
897 thinkpad_id
.bios_version_str
: "unknown",
898 (thinkpad_id
.ec_version_str
) ?
899 thinkpad_id
.ec_version_str
: "unknown");
901 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
902 printk(TPACPI_INFO
"%s %s\n",
903 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
904 "IBM" : ((thinkpad_id
.vendor
==
905 PCI_VENDOR_ID_LENOVO
) ?
906 "Lenovo" : "Unknown vendor"),
907 thinkpad_id
.model_str
);
912 static int thinkpad_acpi_driver_read(char *p
)
916 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
917 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
922 static struct ibm_struct thinkpad_acpi_driver_data
= {
924 .read
= thinkpad_acpi_driver_read
,
927 /*************************************************************************
931 enum { /* hot key scan codes (derived from ACPI DSDT) */
932 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
933 TP_ACPI_HOTKEYSCAN_FNF2
,
934 TP_ACPI_HOTKEYSCAN_FNF3
,
935 TP_ACPI_HOTKEYSCAN_FNF4
,
936 TP_ACPI_HOTKEYSCAN_FNF5
,
937 TP_ACPI_HOTKEYSCAN_FNF6
,
938 TP_ACPI_HOTKEYSCAN_FNF7
,
939 TP_ACPI_HOTKEYSCAN_FNF8
,
940 TP_ACPI_HOTKEYSCAN_FNF9
,
941 TP_ACPI_HOTKEYSCAN_FNF10
,
942 TP_ACPI_HOTKEYSCAN_FNF11
,
943 TP_ACPI_HOTKEYSCAN_FNF12
,
944 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
945 TP_ACPI_HOTKEYSCAN_FNINSERT
,
946 TP_ACPI_HOTKEYSCAN_FNDELETE
,
947 TP_ACPI_HOTKEYSCAN_FNHOME
,
948 TP_ACPI_HOTKEYSCAN_FNEND
,
949 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
950 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
951 TP_ACPI_HOTKEYSCAN_FNSPACE
,
952 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
953 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
954 TP_ACPI_HOTKEYSCAN_MUTE
,
955 TP_ACPI_HOTKEYSCAN_THINKPAD
,
958 enum { /* Keys available through NVRAM polling */
959 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
960 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
963 enum { /* Positions of some of the keys in hotkey masks */
964 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
965 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
966 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
967 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
968 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
969 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
970 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
971 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
972 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
973 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
974 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
977 enum { /* NVRAM to ACPI HKEY group map */
978 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
979 TP_ACPI_HKEY_ZOOM_MASK
|
980 TP_ACPI_HKEY_DISPSWTCH_MASK
|
981 TP_ACPI_HKEY_HIBERNATE_MASK
,
982 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
983 TP_ACPI_HKEY_BRGHTDWN_MASK
,
984 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
985 TP_ACPI_HKEY_VOLDWN_MASK
|
986 TP_ACPI_HKEY_MUTE_MASK
,
989 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
990 struct tp_nvram_state
{
991 u16 thinkpad_toggle
:1;
993 u16 display_toggle
:1;
994 u16 thinklight_toggle
:1;
995 u16 hibernate_toggle
:1;
996 u16 displayexp_toggle
:1;
998 u16 brightness_toggle
:1;
1002 u8 brightness_level
;
1006 static struct task_struct
*tpacpi_hotkey_task
;
1007 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1008 static int hotkey_poll_freq
= 10; /* Hz */
1009 static struct mutex hotkey_thread_mutex
;
1010 static struct mutex hotkey_thread_data_mutex
;
1011 static unsigned int hotkey_config_change
;
1013 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1015 #define hotkey_source_mask 0U
1017 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1019 static struct mutex hotkey_mutex
;
1021 static int hotkey_orig_status
;
1022 static u32 hotkey_orig_mask
;
1023 static u32 hotkey_all_mask
;
1024 static u32 hotkey_reserved_mask
;
1025 static u32 hotkey_mask
;
1027 static unsigned int hotkey_report_mode
;
1029 static u16
*hotkey_keycode_map
;
1031 static struct attribute_set
*hotkey_dev_attributes
;
1033 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1034 #define HOTKEY_CONFIG_CRITICAL_START \
1036 mutex_lock(&hotkey_thread_data_mutex); \
1037 hotkey_config_change++; \
1039 #define HOTKEY_CONFIG_CRITICAL_END \
1040 mutex_unlock(&hotkey_thread_data_mutex);
1042 #define HOTKEY_CONFIG_CRITICAL_START
1043 #define HOTKEY_CONFIG_CRITICAL_END
1044 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1046 static int hotkey_get_wlsw(int *status
)
1048 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1054 * Call with hotkey_mutex held
1056 static int hotkey_mask_get(void)
1060 if (tp_features
.hotkey_mask
) {
1061 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1064 hotkey_mask
= m
| (hotkey_source_mask
& hotkey_mask
);
1070 * Call with hotkey_mutex held
1072 static int hotkey_mask_set(u32 mask
)
1077 if (tp_features
.hotkey_mask
) {
1078 HOTKEY_CONFIG_CRITICAL_START
1079 for (i
= 0; i
< 32; i
++) {
1081 /* enable in firmware mask only keys not in NVRAM
1082 * mode, but enable the key in the cached hotkey_mask
1083 * regardless of mode, or the key will end up
1084 * disabled by hotkey_mask_get() */
1085 if (!acpi_evalf(hkey_handle
,
1086 NULL
, "MHKM", "vdd", i
+ 1,
1087 !!((mask
& ~hotkey_source_mask
) & m
))) {
1091 hotkey_mask
= (hotkey_mask
& ~m
) | (mask
& m
);
1094 HOTKEY_CONFIG_CRITICAL_END
1096 /* hotkey_mask_get must be called unconditionally below */
1097 if (!hotkey_mask_get() && !rc
&&
1098 (hotkey_mask
& ~hotkey_source_mask
) !=
1099 (mask
& ~hotkey_source_mask
)) {
1100 printk(TPACPI_NOTICE
1101 "requested hot key mask 0x%08x, but "
1102 "firmware forced it to 0x%08x\n",
1106 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1107 HOTKEY_CONFIG_CRITICAL_START
1108 hotkey_mask
= mask
& hotkey_source_mask
;
1109 HOTKEY_CONFIG_CRITICAL_END
1111 if (hotkey_mask
!= mask
) {
1112 printk(TPACPI_NOTICE
1113 "requested hot key mask 0x%08x, "
1114 "forced to 0x%08x (NVRAM poll mask is "
1115 "0x%08x): no firmware mask support\n",
1116 mask
, hotkey_mask
, hotkey_source_mask
);
1121 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1127 static int hotkey_status_get(int *status
)
1129 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1135 static int hotkey_status_set(int status
)
1137 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1143 static void tpacpi_input_send_radiosw(void)
1147 mutex_lock(&tpacpi_inputdev_send_mutex
);
1149 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
1150 input_report_switch(tpacpi_inputdev
,
1152 input_sync(tpacpi_inputdev
);
1155 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1158 static void tpacpi_input_send_key(unsigned int scancode
)
1160 unsigned int keycode
;
1162 keycode
= hotkey_keycode_map
[scancode
];
1164 if (keycode
!= KEY_RESERVED
) {
1165 mutex_lock(&tpacpi_inputdev_send_mutex
);
1167 input_report_key(tpacpi_inputdev
, keycode
, 1);
1168 if (keycode
== KEY_UNKNOWN
)
1169 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1171 input_sync(tpacpi_inputdev
);
1173 input_report_key(tpacpi_inputdev
, keycode
, 0);
1174 if (keycode
== KEY_UNKNOWN
)
1175 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1177 input_sync(tpacpi_inputdev
);
1179 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1183 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1184 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
1186 static void tpacpi_hotkey_send_key(unsigned int scancode
)
1188 tpacpi_input_send_key(scancode
);
1189 if (hotkey_report_mode
< 2) {
1190 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
1191 0x80, 0x1001 + scancode
);
1195 static void hotkey_read_nvram(struct tp_nvram_state
*n
, u32 m
)
1199 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
1200 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
1201 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
1202 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
1203 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
1204 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
1206 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
1207 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
1208 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
1210 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
1211 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
1212 n
->displayexp_toggle
=
1213 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
1215 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
1216 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
1217 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
1218 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
1219 n
->brightness_toggle
=
1220 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
1222 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
1223 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
1224 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
1225 >> TP_NVRAM_POS_LEVEL_VOLUME
;
1226 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
1227 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
1231 #define TPACPI_COMPARE_KEY(__scancode, __member) \
1233 if ((mask & (1 << __scancode)) && \
1234 oldn->__member != newn->__member) \
1235 tpacpi_hotkey_send_key(__scancode); \
1238 #define TPACPI_MAY_SEND_KEY(__scancode) \
1239 do { if (mask & (1 << __scancode)) \
1240 tpacpi_hotkey_send_key(__scancode); } while (0)
1242 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
1243 struct tp_nvram_state
*newn
,
1246 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
1247 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
1248 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
1249 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
1251 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
1253 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
1256 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
1257 if (oldn
->mute
!= newn
->mute
) {
1258 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1260 if (oldn
->volume_level
> newn
->volume_level
) {
1261 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1262 } else if (oldn
->volume_level
< newn
->volume_level
) {
1263 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1264 } else if (oldn
->mute
== newn
->mute
) {
1265 /* repeated key presses that didn't change state */
1267 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1268 } else if (newn
->volume_level
!= 0) {
1269 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1271 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1276 /* handle brightness */
1277 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
1278 if (oldn
->brightness_level
< newn
->brightness_level
) {
1279 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1280 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
1281 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1283 /* repeated key presses that didn't change state */
1284 if (newn
->brightness_level
!= 0) {
1285 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1287 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1293 #undef TPACPI_COMPARE_KEY
1294 #undef TPACPI_MAY_SEND_KEY
1296 static int hotkey_kthread(void *data
)
1298 struct tp_nvram_state s
[2];
1300 unsigned int si
, so
;
1302 unsigned int change_detector
, must_reset
;
1304 mutex_lock(&hotkey_thread_mutex
);
1306 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
1315 /* Initial state for compares */
1316 mutex_lock(&hotkey_thread_data_mutex
);
1317 change_detector
= hotkey_config_change
;
1318 mask
= hotkey_source_mask
& hotkey_mask
;
1319 mutex_unlock(&hotkey_thread_data_mutex
);
1320 hotkey_read_nvram(&s
[so
], mask
);
1322 while (!kthread_should_stop() && hotkey_poll_freq
) {
1324 t
= 1000/hotkey_poll_freq
;
1325 t
= msleep_interruptible(t
);
1326 if (unlikely(kthread_should_stop()))
1328 must_reset
= try_to_freeze();
1329 if (t
> 0 && !must_reset
)
1332 mutex_lock(&hotkey_thread_data_mutex
);
1333 if (must_reset
|| hotkey_config_change
!= change_detector
) {
1334 /* forget old state on thaw or config change */
1337 change_detector
= hotkey_config_change
;
1339 mask
= hotkey_source_mask
& hotkey_mask
;
1340 mutex_unlock(&hotkey_thread_data_mutex
);
1343 hotkey_read_nvram(&s
[si
], mask
);
1344 if (likely(si
!= so
)) {
1345 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
1355 mutex_unlock(&hotkey_thread_mutex
);
1359 static void hotkey_poll_stop_sync(void)
1361 if (tpacpi_hotkey_task
) {
1362 if (frozen(tpacpi_hotkey_task
) ||
1363 freezing(tpacpi_hotkey_task
))
1364 thaw_process(tpacpi_hotkey_task
);
1366 kthread_stop(tpacpi_hotkey_task
);
1367 tpacpi_hotkey_task
= NULL
;
1368 mutex_lock(&hotkey_thread_mutex
);
1369 /* at this point, the thread did exit */
1370 mutex_unlock(&hotkey_thread_mutex
);
1374 /* call with hotkey_mutex held */
1375 static void hotkey_poll_setup(int may_warn
)
1377 if ((hotkey_source_mask
& hotkey_mask
) != 0 &&
1378 hotkey_poll_freq
> 0 &&
1379 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1380 if (!tpacpi_hotkey_task
) {
1381 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1384 if (IS_ERR(tpacpi_hotkey_task
)) {
1385 tpacpi_hotkey_task
= NULL
;
1387 "could not create kernel thread "
1388 "for hotkey polling\n");
1392 hotkey_poll_stop_sync();
1394 hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1395 printk(TPACPI_NOTICE
1396 "hot keys 0x%08x require polling, "
1397 "which is currently disabled\n",
1398 hotkey_source_mask
);
1403 static void hotkey_poll_setup_safe(int may_warn
)
1405 mutex_lock(&hotkey_mutex
);
1406 hotkey_poll_setup(may_warn
);
1407 mutex_unlock(&hotkey_mutex
);
1410 static int hotkey_inputdev_open(struct input_dev
*dev
)
1412 switch (tpacpi_lifecycle
) {
1413 case TPACPI_LIFE_INIT
:
1415 * hotkey_init will call hotkey_poll_setup_safe
1416 * at the appropriate moment
1419 case TPACPI_LIFE_EXITING
:
1421 case TPACPI_LIFE_RUNNING
:
1422 hotkey_poll_setup_safe(0);
1426 /* Should only happen if tpacpi_lifecycle is corrupt */
1431 static void hotkey_inputdev_close(struct input_dev
*dev
)
1433 /* disable hotkey polling when possible */
1434 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
)
1435 hotkey_poll_setup_safe(0);
1437 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1439 /* sysfs hotkey enable ------------------------------------------------- */
1440 static ssize_t
hotkey_enable_show(struct device
*dev
,
1441 struct device_attribute
*attr
,
1446 res
= hotkey_status_get(&status
);
1450 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1453 static ssize_t
hotkey_enable_store(struct device
*dev
,
1454 struct device_attribute
*attr
,
1455 const char *buf
, size_t count
)
1460 if (parse_strtoul(buf
, 1, &t
))
1463 res
= hotkey_status_set(t
);
1465 return (res
) ? res
: count
;
1468 static struct device_attribute dev_attr_hotkey_enable
=
1469 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
1470 hotkey_enable_show
, hotkey_enable_store
);
1472 /* sysfs hotkey mask --------------------------------------------------- */
1473 static ssize_t
hotkey_mask_show(struct device
*dev
,
1474 struct device_attribute
*attr
,
1479 if (mutex_lock_interruptible(&hotkey_mutex
))
1480 return -ERESTARTSYS
;
1481 res
= hotkey_mask_get();
1482 mutex_unlock(&hotkey_mutex
);
1485 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
1488 static ssize_t
hotkey_mask_store(struct device
*dev
,
1489 struct device_attribute
*attr
,
1490 const char *buf
, size_t count
)
1495 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
1498 if (mutex_lock_interruptible(&hotkey_mutex
))
1499 return -ERESTARTSYS
;
1501 res
= hotkey_mask_set(t
);
1503 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1504 hotkey_poll_setup(1);
1507 mutex_unlock(&hotkey_mutex
);
1509 return (res
) ? res
: count
;
1512 static struct device_attribute dev_attr_hotkey_mask
=
1513 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
1514 hotkey_mask_show
, hotkey_mask_store
);
1516 /* sysfs hotkey bios_enabled ------------------------------------------- */
1517 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
1518 struct device_attribute
*attr
,
1521 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
1524 static struct device_attribute dev_attr_hotkey_bios_enabled
=
1525 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
1527 /* sysfs hotkey bios_mask ---------------------------------------------- */
1528 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
1529 struct device_attribute
*attr
,
1532 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
1535 static struct device_attribute dev_attr_hotkey_bios_mask
=
1536 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
1538 /* sysfs hotkey all_mask ----------------------------------------------- */
1539 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
1540 struct device_attribute
*attr
,
1543 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1544 hotkey_all_mask
| hotkey_source_mask
);
1547 static struct device_attribute dev_attr_hotkey_all_mask
=
1548 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
1550 /* sysfs hotkey recommended_mask --------------------------------------- */
1551 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
1552 struct device_attribute
*attr
,
1555 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1556 (hotkey_all_mask
| hotkey_source_mask
)
1557 & ~hotkey_reserved_mask
);
1560 static struct device_attribute dev_attr_hotkey_recommended_mask
=
1561 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
1562 hotkey_recommended_mask_show
, NULL
);
1564 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1566 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
1567 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
1568 struct device_attribute
*attr
,
1571 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
1574 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
1575 struct device_attribute
*attr
,
1576 const char *buf
, size_t count
)
1580 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
1581 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
1584 if (mutex_lock_interruptible(&hotkey_mutex
))
1585 return -ERESTARTSYS
;
1587 HOTKEY_CONFIG_CRITICAL_START
1588 hotkey_source_mask
= t
;
1589 HOTKEY_CONFIG_CRITICAL_END
1591 hotkey_poll_setup(1);
1593 mutex_unlock(&hotkey_mutex
);
1598 static struct device_attribute dev_attr_hotkey_source_mask
=
1599 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
1600 hotkey_source_mask_show
, hotkey_source_mask_store
);
1602 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
1603 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
1604 struct device_attribute
*attr
,
1607 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
1610 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
1611 struct device_attribute
*attr
,
1612 const char *buf
, size_t count
)
1616 if (parse_strtoul(buf
, 25, &t
))
1619 if (mutex_lock_interruptible(&hotkey_mutex
))
1620 return -ERESTARTSYS
;
1622 hotkey_poll_freq
= t
;
1624 hotkey_poll_setup(1);
1625 mutex_unlock(&hotkey_mutex
);
1630 static struct device_attribute dev_attr_hotkey_poll_freq
=
1631 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
1632 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
1634 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1636 /* sysfs hotkey radio_sw ----------------------------------------------- */
1637 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
1638 struct device_attribute
*attr
,
1642 res
= hotkey_get_wlsw(&s
);
1646 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1649 static struct device_attribute dev_attr_hotkey_radio_sw
=
1650 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
1652 /* sysfs hotkey report_mode -------------------------------------------- */
1653 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
1654 struct device_attribute
*attr
,
1657 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1658 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
1661 static struct device_attribute dev_attr_hotkey_report_mode
=
1662 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
1664 /* --------------------------------------------------------------------- */
1666 static struct attribute
*hotkey_attributes
[] __initdata
= {
1667 &dev_attr_hotkey_enable
.attr
,
1668 &dev_attr_hotkey_bios_enabled
.attr
,
1669 &dev_attr_hotkey_report_mode
.attr
,
1670 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1671 &dev_attr_hotkey_mask
.attr
,
1672 &dev_attr_hotkey_all_mask
.attr
,
1673 &dev_attr_hotkey_recommended_mask
.attr
,
1674 &dev_attr_hotkey_source_mask
.attr
,
1675 &dev_attr_hotkey_poll_freq
.attr
,
1679 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
1680 &dev_attr_hotkey_bios_mask
.attr
,
1681 #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1682 &dev_attr_hotkey_mask
.attr
,
1683 &dev_attr_hotkey_all_mask
.attr
,
1684 &dev_attr_hotkey_recommended_mask
.attr
,
1688 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
1690 /* Requirements for changing the default keymaps:
1692 * 1. Many of the keys are mapped to KEY_RESERVED for very
1693 * good reasons. Do not change them unless you have deep
1694 * knowledge on the IBM and Lenovo ThinkPad firmware for
1695 * the various ThinkPad models. The driver behaves
1696 * differently for KEY_RESERVED: such keys have their
1697 * hot key mask *unset* in mask_recommended, and also
1698 * in the initial hot key mask programmed into the
1699 * firmware at driver load time, which means the firm-
1700 * ware may react very differently if you change them to
1703 * 2. You must be subscribed to the linux-thinkpad and
1704 * ibm-acpi-devel mailing lists, and you should read the
1705 * list archives since 2007 if you want to change the
1706 * keymaps. This requirement exists so that you will
1707 * know the past history of problems with the thinkpad-
1708 * acpi driver keymaps, and also that you will be
1709 * listening to any bug reports;
1711 * 3. Do not send thinkpad-acpi specific patches directly to
1712 * for merging, *ever*. Send them to the linux-acpi
1713 * mailinglist for comments. Merging is to be done only
1714 * through acpi-test and the ACPI maintainer.
1716 * If the above is too much to ask, don't change the keymap.
1717 * Ask the thinkpad-acpi maintainer to do it, instead.
1719 static u16 ibm_keycode_map
[] __initdata
= {
1720 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1721 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
1722 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1723 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1725 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
1726 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1727 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1728 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1730 /* brightness: firmware always reacts to them, unless
1731 * X.org did some tricks in the radeon BIOS scratch
1732 * registers of *some* models */
1733 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1734 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1736 /* Thinklight: firmware always react to it */
1737 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1739 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1740 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1742 /* Volume: firmware always react to it and reprograms
1743 * the built-in *extra* mixer. Never map it to control
1744 * another mixer by default. */
1745 KEY_RESERVED
, /* 0x14: VOLUME UP */
1746 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1747 KEY_RESERVED
, /* 0x16: MUTE */
1749 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1751 /* (assignments unknown, please report if found) */
1752 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1753 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1755 static u16 lenovo_keycode_map
[] __initdata
= {
1756 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1757 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
1758 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1759 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1761 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
1762 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1763 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1764 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1766 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1767 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1769 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1771 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1772 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1774 /* Volume: z60/z61, T60 (BIOS version?): firmware always
1775 * react to it and reprograms the built-in *extra* mixer.
1776 * Never map it to control another mixer by default.
1778 * T60?, T61, R60?, R61: firmware and EC tries to send
1779 * these over the regular keyboard, so these are no-ops,
1780 * but there are still weird bugs re. MUTE, so do not
1781 * change unless you get test reports from all Lenovo
1782 * models. May cause the BIOS to interfere with the
1785 KEY_RESERVED
, /* 0x14: VOLUME UP */
1786 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1787 KEY_RESERVED
, /* 0x16: MUTE */
1789 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1791 /* (assignments unknown, please report if found) */
1792 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1793 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1796 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
1797 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
1798 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
1804 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
1806 BUG_ON(!tpacpi_inputdev
);
1807 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
1808 tpacpi_inputdev
->close
!= NULL
);
1810 TPACPI_ACPIHANDLE_INIT(hkey
);
1811 mutex_init(&hotkey_mutex
);
1813 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1814 mutex_init(&hotkey_thread_mutex
);
1815 mutex_init(&hotkey_thread_data_mutex
);
1818 /* hotkey not supported on 570 */
1819 tp_features
.hotkey
= hkey_handle
!= NULL
;
1821 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
1822 str_supported(tp_features
.hotkey
));
1824 if (tp_features
.hotkey
) {
1825 hotkey_dev_attributes
= create_attr_set(10, NULL
);
1826 if (!hotkey_dev_attributes
)
1828 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1830 ARRAY_SIZE(hotkey_attributes
));
1834 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1835 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
1836 for HKEY interface version 0x100 */
1837 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
1838 if ((hkeyv
>> 8) != 1) {
1839 printk(TPACPI_ERR
"unknown version of the "
1840 "HKEY interface: 0x%x\n", hkeyv
);
1841 printk(TPACPI_ERR
"please report this to %s\n",
1845 * MHKV 0x100 in A31, R40, R40e,
1846 * T4x, X31, and later
1848 tp_features
.hotkey_mask
= 1;
1852 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
1853 str_supported(tp_features
.hotkey_mask
));
1855 if (tp_features
.hotkey_mask
) {
1856 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
1859 "missing MHKA handler, "
1860 "please report this to %s\n",
1862 /* FN+F12, FN+F4, FN+F3 */
1863 hotkey_all_mask
= 0x080cU
;
1867 /* hotkey_source_mask *must* be zero for
1868 * the first hotkey_mask_get */
1869 res
= hotkey_status_get(&hotkey_orig_status
);
1870 if (!res
&& tp_features
.hotkey_mask
) {
1871 res
= hotkey_mask_get();
1872 hotkey_orig_mask
= hotkey_mask
;
1874 res
= add_many_to_attr_set(
1875 hotkey_dev_attributes
,
1876 hotkey_mask_attributes
,
1877 ARRAY_SIZE(hotkey_mask_attributes
));
1881 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1882 if (tp_features
.hotkey_mask
) {
1883 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
1886 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
;
1889 vdbg_printk(TPACPI_DBG_INIT
,
1890 "hotkey source mask 0x%08x, polling freq %d\n",
1891 hotkey_source_mask
, hotkey_poll_freq
);
1894 /* Not all thinkpads have a hardware radio switch */
1895 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
1896 tp_features
.hotkey_wlsw
= 1;
1898 "radio switch found; radios are %s\n",
1899 enabled(status
, 0));
1900 res
= add_to_attr_set(hotkey_dev_attributes
,
1901 &dev_attr_hotkey_radio_sw
.attr
);
1905 res
= register_attr_set_with_sysfs(
1906 hotkey_dev_attributes
,
1907 &tpacpi_pdev
->dev
.kobj
);
1911 /* Set up key map */
1913 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
1915 if (!hotkey_keycode_map
) {
1917 "failed to allocate memory for key map\n");
1921 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
1922 dbg_printk(TPACPI_DBG_INIT
,
1923 "using Lenovo default hot key map\n");
1924 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
1925 TPACPI_HOTKEY_MAP_SIZE
);
1927 dbg_printk(TPACPI_DBG_INIT
,
1928 "using IBM default hot key map\n");
1929 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
1930 TPACPI_HOTKEY_MAP_SIZE
);
1933 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
1934 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
1935 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
1936 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
1937 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
1938 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
1939 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
1940 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
1941 set_bit(hotkey_keycode_map
[i
],
1942 tpacpi_inputdev
->keybit
);
1944 if (i
< sizeof(hotkey_reserved_mask
)*8)
1945 hotkey_reserved_mask
|= 1 << i
;
1949 if (tp_features
.hotkey_wlsw
) {
1950 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
1951 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
1954 dbg_printk(TPACPI_DBG_INIT
,
1955 "enabling hot key handling\n");
1956 res
= hotkey_status_set(1);
1959 res
= hotkey_mask_set(((hotkey_all_mask
| hotkey_source_mask
)
1960 & ~hotkey_reserved_mask
)
1961 | hotkey_orig_mask
);
1962 if (res
< 0 && res
!= -ENXIO
)
1965 dbg_printk(TPACPI_DBG_INIT
,
1966 "legacy hot key reporting over procfs %s\n",
1967 (hotkey_report_mode
< 2) ?
1968 "enabled" : "disabled");
1970 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1971 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
1972 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
1974 hotkey_poll_setup_safe(1);
1978 return (tp_features
.hotkey
)? 0 : 1;
1981 static void hotkey_exit(void)
1983 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1984 hotkey_poll_stop_sync();
1987 if (tp_features
.hotkey
) {
1988 dbg_printk(TPACPI_DBG_EXIT
,
1989 "restoring original hot key mask\n");
1990 /* no short-circuit boolean operator below! */
1991 if ((hotkey_mask_set(hotkey_orig_mask
) |
1992 hotkey_status_set(hotkey_orig_status
)) != 0)
1994 "failed to restore hot key mask "
1995 "to BIOS defaults\n");
1998 if (hotkey_dev_attributes
) {
1999 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2000 hotkey_dev_attributes
= NULL
;
2004 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
2007 unsigned int scancode
;
2012 if (event
!= 0x80) {
2014 "unknown HKEY notification event %d\n", event
);
2015 /* forward it to userspace, maybe it knows how to handle it */
2016 acpi_bus_generate_netlink_event(
2017 ibm
->acpi
->device
->pnp
.device_class
,
2018 ibm
->acpi
->device
->dev
.bus_id
,
2024 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
2025 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
2038 switch (hkey
>> 12) {
2040 /* 0x1000-0x1FFF: key presses */
2041 scancode
= hkey
& 0xfff;
2042 if (scancode
> 0 && scancode
< 0x21) {
2044 if (!(hotkey_source_mask
& (1 << scancode
))) {
2045 tpacpi_input_send_key(scancode
);
2055 /* 0x5000-0x5FFF: On screen display helpers */
2058 /* Lenovo Vista BIOS: brightness changed */
2062 /* LID switch events. Do not propagate */
2070 /* 0x7000-0x7FFF: misc */
2071 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
2072 tpacpi_input_send_radiosw();
2076 /* fallthrough to default */
2078 /* case 2: dock-related */
2079 /* 0x2305 - T43 waking up due to bay lever
2080 * eject while aslept */
2081 /* case 3: ultra-bay related. maybe bay in dock? */
2082 /* 0x3003 - T43 after wake up by bay lever
2087 printk(TPACPI_NOTICE
2088 "unhandled HKEY event 0x%04x\n", hkey
);
2092 if (!ignore_acpi_ev
&&
2093 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
2094 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
2098 /* netlink events */
2099 if (!ignore_acpi_ev
&& send_acpi_ev
) {
2100 acpi_bus_generate_netlink_event(
2101 ibm
->acpi
->device
->pnp
.device_class
,
2102 ibm
->acpi
->device
->dev
.bus_id
,
2108 static void hotkey_resume(void)
2110 if (hotkey_mask_get())
2112 "error while trying to read hot key mask "
2114 tpacpi_input_send_radiosw();
2115 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2116 hotkey_poll_setup_safe(0);
2120 /* procfs -------------------------------------------------------------- */
2121 static int hotkey_read(char *p
)
2126 if (!tp_features
.hotkey
) {
2127 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2131 if (mutex_lock_interruptible(&hotkey_mutex
))
2132 return -ERESTARTSYS
;
2133 res
= hotkey_status_get(&status
);
2135 res
= hotkey_mask_get();
2136 mutex_unlock(&hotkey_mutex
);
2140 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
2141 if (tp_features
.hotkey_mask
) {
2142 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
2143 len
+= sprintf(p
+ len
,
2144 "commands:\tenable, disable, reset, <mask>\n");
2146 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
2147 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
2153 static int hotkey_write(char *buf
)
2159 if (!tp_features
.hotkey
)
2162 if (mutex_lock_interruptible(&hotkey_mutex
))
2163 return -ERESTARTSYS
;
2169 while ((cmd
= next_cmd(&buf
))) {
2170 if (strlencmp(cmd
, "enable") == 0) {
2172 } else if (strlencmp(cmd
, "disable") == 0) {
2174 } else if (strlencmp(cmd
, "reset") == 0) {
2175 status
= hotkey_orig_status
;
2176 mask
= hotkey_orig_mask
;
2177 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
2179 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
2187 res
= hotkey_status_set(status
);
2189 if (!res
&& mask
!= hotkey_mask
)
2190 res
= hotkey_mask_set(mask
);
2193 mutex_unlock(&hotkey_mutex
);
2197 static const struct acpi_device_id ibm_htk_device_ids
[] = {
2198 {TPACPI_ACPI_HKEY_HID
, 0},
2202 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
2203 .hid
= ibm_htk_device_ids
,
2204 .notify
= hotkey_notify
,
2205 .handle
= &hkey_handle
,
2206 .type
= ACPI_DEVICE_NOTIFY
,
2209 static struct ibm_struct hotkey_driver_data
= {
2211 .read
= hotkey_read
,
2212 .write
= hotkey_write
,
2213 .exit
= hotkey_exit
,
2214 .resume
= hotkey_resume
,
2215 .acpi
= &ibm_hotkey_acpidriver
,
2218 /*************************************************************************
2219 * Bluetooth subdriver
2223 /* ACPI GBDC/SBDC bits */
2224 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
2225 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
2226 TP_ACPI_BLUETOOTH_UNK
= 0x04, /* unknown function */
2229 static int bluetooth_get_radiosw(void);
2230 static int bluetooth_set_radiosw(int radio_on
);
2232 /* sysfs bluetooth enable ---------------------------------------------- */
2233 static ssize_t
bluetooth_enable_show(struct device
*dev
,
2234 struct device_attribute
*attr
,
2239 status
= bluetooth_get_radiosw();
2243 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
2246 static ssize_t
bluetooth_enable_store(struct device
*dev
,
2247 struct device_attribute
*attr
,
2248 const char *buf
, size_t count
)
2253 if (parse_strtoul(buf
, 1, &t
))
2256 res
= bluetooth_set_radiosw(t
);
2258 return (res
) ? res
: count
;
2261 static struct device_attribute dev_attr_bluetooth_enable
=
2262 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
2263 bluetooth_enable_show
, bluetooth_enable_store
);
2265 /* --------------------------------------------------------------------- */
2267 static struct attribute
*bluetooth_attributes
[] = {
2268 &dev_attr_bluetooth_enable
.attr
,
2272 static const struct attribute_group bluetooth_attr_group
= {
2273 .attrs
= bluetooth_attributes
,
2276 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
2281 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
2283 TPACPI_ACPIHANDLE_INIT(hkey
);
2285 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2286 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
2287 tp_features
.bluetooth
= hkey_handle
&&
2288 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
2290 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
2291 str_supported(tp_features
.bluetooth
),
2294 if (tp_features
.bluetooth
) {
2295 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
2296 /* no bluetooth hardware present in system */
2297 tp_features
.bluetooth
= 0;
2298 dbg_printk(TPACPI_DBG_INIT
,
2299 "bluetooth hardware not installed\n");
2301 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2302 &bluetooth_attr_group
);
2308 return (tp_features
.bluetooth
)? 0 : 1;
2311 static void bluetooth_exit(void)
2313 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2314 &bluetooth_attr_group
);
2317 static int bluetooth_get_radiosw(void)
2321 if (!tp_features
.bluetooth
)
2324 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2327 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
2330 static int bluetooth_set_radiosw(int radio_on
)
2334 if (!tp_features
.bluetooth
)
2337 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2340 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
2342 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
2343 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
2349 /* procfs -------------------------------------------------------------- */
2350 static int bluetooth_read(char *p
)
2353 int status
= bluetooth_get_radiosw();
2355 if (!tp_features
.bluetooth
)
2356 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2358 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2359 (status
)? "enabled" : "disabled");
2360 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2366 static int bluetooth_write(char *buf
)
2370 if (!tp_features
.bluetooth
)
2373 while ((cmd
= next_cmd(&buf
))) {
2374 if (strlencmp(cmd
, "enable") == 0) {
2375 bluetooth_set_radiosw(1);
2376 } else if (strlencmp(cmd
, "disable") == 0) {
2377 bluetooth_set_radiosw(0);
2385 static struct ibm_struct bluetooth_driver_data
= {
2386 .name
= "bluetooth",
2387 .read
= bluetooth_read
,
2388 .write
= bluetooth_write
,
2389 .exit
= bluetooth_exit
,
2392 /*************************************************************************
2397 /* ACPI GWAN/SWAN bits */
2398 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
2399 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
2400 TP_ACPI_WANCARD_UNK
= 0x04, /* unknown function */
2403 static int wan_get_radiosw(void);
2404 static int wan_set_radiosw(int radio_on
);
2406 /* sysfs wan enable ---------------------------------------------------- */
2407 static ssize_t
wan_enable_show(struct device
*dev
,
2408 struct device_attribute
*attr
,
2413 status
= wan_get_radiosw();
2417 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
2420 static ssize_t
wan_enable_store(struct device
*dev
,
2421 struct device_attribute
*attr
,
2422 const char *buf
, size_t count
)
2427 if (parse_strtoul(buf
, 1, &t
))
2430 res
= wan_set_radiosw(t
);
2432 return (res
) ? res
: count
;
2435 static struct device_attribute dev_attr_wan_enable
=
2436 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
2437 wan_enable_show
, wan_enable_store
);
2439 /* --------------------------------------------------------------------- */
2441 static struct attribute
*wan_attributes
[] = {
2442 &dev_attr_wan_enable
.attr
,
2446 static const struct attribute_group wan_attr_group
= {
2447 .attrs
= wan_attributes
,
2450 static int __init
wan_init(struct ibm_init_struct
*iibm
)
2455 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
2457 TPACPI_ACPIHANDLE_INIT(hkey
);
2459 tp_features
.wan
= hkey_handle
&&
2460 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
2462 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
2463 str_supported(tp_features
.wan
),
2466 if (tp_features
.wan
) {
2467 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
2468 /* no wan hardware present in system */
2469 tp_features
.wan
= 0;
2470 dbg_printk(TPACPI_DBG_INIT
,
2471 "wan hardware not installed\n");
2473 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2480 return (tp_features
.wan
)? 0 : 1;
2483 static void wan_exit(void)
2485 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2489 static int wan_get_radiosw(void)
2493 if (!tp_features
.wan
)
2496 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2499 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
2502 static int wan_set_radiosw(int radio_on
)
2506 if (!tp_features
.wan
)
2509 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2512 status
|= TP_ACPI_WANCARD_RADIOSSW
;
2514 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
2515 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
2521 /* procfs -------------------------------------------------------------- */
2522 static int wan_read(char *p
)
2525 int status
= wan_get_radiosw();
2527 if (!tp_features
.wan
)
2528 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2530 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2531 (status
)? "enabled" : "disabled");
2532 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2538 static int wan_write(char *buf
)
2542 if (!tp_features
.wan
)
2545 while ((cmd
= next_cmd(&buf
))) {
2546 if (strlencmp(cmd
, "enable") == 0) {
2548 } else if (strlencmp(cmd
, "disable") == 0) {
2557 static struct ibm_struct wan_driver_data
= {
2562 .flags
.experimental
= 1,
2565 /*************************************************************************
2569 enum video_access_mode
{
2570 TPACPI_VIDEO_NONE
= 0,
2571 TPACPI_VIDEO_570
, /* 570 */
2572 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
2573 TPACPI_VIDEO_NEW
, /* all others */
2576 enum { /* video status flags, based on VIDEO_570 */
2577 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
2578 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
2579 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
2582 enum { /* TPACPI_VIDEO_570 constants */
2583 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
2584 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
2585 * video_status_flags */
2586 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
2587 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
2590 static enum video_access_mode video_supported
;
2591 static int video_orig_autosw
;
2593 static int video_autosw_get(void);
2594 static int video_autosw_set(int enable
);
2596 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
2597 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
2598 "\\_SB.PCI0.VID0", /* 770e */
2599 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
2600 "\\_SB.PCI0.AGP.VID", /* all others */
2603 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
2605 static int __init
video_init(struct ibm_init_struct
*iibm
)
2609 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
2611 TPACPI_ACPIHANDLE_INIT(vid
);
2612 TPACPI_ACPIHANDLE_INIT(vid2
);
2614 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
2615 /* G41, assume IVGA doesn't change */
2616 vid_handle
= vid2_handle
;
2619 /* video switching not supported on R30, R31 */
2620 video_supported
= TPACPI_VIDEO_NONE
;
2621 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
2623 video_supported
= TPACPI_VIDEO_570
;
2624 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
2625 /* 600e/x, 770e, 770x */
2626 video_supported
= TPACPI_VIDEO_770
;
2629 video_supported
= TPACPI_VIDEO_NEW
;
2631 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
2632 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
2635 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
2638 static void video_exit(void)
2640 dbg_printk(TPACPI_DBG_EXIT
,
2641 "restoring original video autoswitch mode\n");
2642 if (video_autosw_set(video_orig_autosw
))
2643 printk(TPACPI_ERR
"error while trying to restore original "
2644 "video autoswitch mode\n");
2647 static int video_outputsw_get(void)
2652 switch (video_supported
) {
2653 case TPACPI_VIDEO_570
:
2654 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
2655 TP_ACPI_VIDEO_570_PHSCMD
))
2657 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
2659 case TPACPI_VIDEO_770
:
2660 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2663 status
|= TP_ACPI_VIDEO_S_LCD
;
2664 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2667 status
|= TP_ACPI_VIDEO_S_CRT
;
2669 case TPACPI_VIDEO_NEW
:
2670 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
2671 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2674 status
|= TP_ACPI_VIDEO_S_CRT
;
2676 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
2677 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2680 status
|= TP_ACPI_VIDEO_S_LCD
;
2681 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
2684 status
|= TP_ACPI_VIDEO_S_DVI
;
2693 static int video_outputsw_set(int status
)
2698 switch (video_supported
) {
2699 case TPACPI_VIDEO_570
:
2700 res
= acpi_evalf(NULL
, NULL
,
2701 "\\_SB.PHS2", "vdd",
2702 TP_ACPI_VIDEO_570_PHS2CMD
,
2703 status
| TP_ACPI_VIDEO_570_PHS2SET
);
2705 case TPACPI_VIDEO_770
:
2706 autosw
= video_autosw_get();
2710 res
= video_autosw_set(1);
2713 res
= acpi_evalf(vid_handle
, NULL
,
2714 "ASWT", "vdd", status
* 0x100, 0);
2715 if (!autosw
&& video_autosw_set(autosw
)) {
2717 "video auto-switch left enabled due to error\n");
2721 case TPACPI_VIDEO_NEW
:
2722 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
2723 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
2729 return (res
)? 0 : -EIO
;
2732 static int video_autosw_get(void)
2736 switch (video_supported
) {
2737 case TPACPI_VIDEO_570
:
2738 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
2741 case TPACPI_VIDEO_770
:
2742 case TPACPI_VIDEO_NEW
:
2743 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
2753 static int video_autosw_set(int enable
)
2755 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
2760 static int video_outputsw_cycle(void)
2762 int autosw
= video_autosw_get();
2768 switch (video_supported
) {
2769 case TPACPI_VIDEO_570
:
2770 res
= video_autosw_set(1);
2773 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
2775 case TPACPI_VIDEO_770
:
2776 case TPACPI_VIDEO_NEW
:
2777 res
= video_autosw_set(1);
2780 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
2785 if (!autosw
&& video_autosw_set(autosw
)) {
2787 "video auto-switch left enabled due to error\n");
2791 return (res
)? 0 : -EIO
;
2794 static int video_expand_toggle(void)
2796 switch (video_supported
) {
2797 case TPACPI_VIDEO_570
:
2798 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
2800 case TPACPI_VIDEO_770
:
2801 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
2803 case TPACPI_VIDEO_NEW
:
2804 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
2812 static int video_read(char *p
)
2817 if (video_supported
== TPACPI_VIDEO_NONE
) {
2818 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2822 status
= video_outputsw_get();
2826 autosw
= video_autosw_get();
2830 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2831 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
2832 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
2833 if (video_supported
== TPACPI_VIDEO_NEW
)
2834 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
2835 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
2836 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
2837 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
2838 if (video_supported
== TPACPI_VIDEO_NEW
)
2839 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
2840 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
2841 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
2846 static int video_write(char *buf
)
2849 int enable
, disable
, status
;
2852 if (video_supported
== TPACPI_VIDEO_NONE
)
2858 while ((cmd
= next_cmd(&buf
))) {
2859 if (strlencmp(cmd
, "lcd_enable") == 0) {
2860 enable
|= TP_ACPI_VIDEO_S_LCD
;
2861 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
2862 disable
|= TP_ACPI_VIDEO_S_LCD
;
2863 } else if (strlencmp(cmd
, "crt_enable") == 0) {
2864 enable
|= TP_ACPI_VIDEO_S_CRT
;
2865 } else if (strlencmp(cmd
, "crt_disable") == 0) {
2866 disable
|= TP_ACPI_VIDEO_S_CRT
;
2867 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2868 strlencmp(cmd
, "dvi_enable") == 0) {
2869 enable
|= TP_ACPI_VIDEO_S_DVI
;
2870 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2871 strlencmp(cmd
, "dvi_disable") == 0) {
2872 disable
|= TP_ACPI_VIDEO_S_DVI
;
2873 } else if (strlencmp(cmd
, "auto_enable") == 0) {
2874 res
= video_autosw_set(1);
2877 } else if (strlencmp(cmd
, "auto_disable") == 0) {
2878 res
= video_autosw_set(0);
2881 } else if (strlencmp(cmd
, "video_switch") == 0) {
2882 res
= video_outputsw_cycle();
2885 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
2886 res
= video_expand_toggle();
2893 if (enable
|| disable
) {
2894 status
= video_outputsw_get();
2897 res
= video_outputsw_set((status
& ~disable
) | enable
);
2905 static struct ibm_struct video_driver_data
= {
2908 .write
= video_write
,
2912 /*************************************************************************
2913 * Light (thinklight) subdriver
2916 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
2917 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
2919 static int __init
light_init(struct ibm_init_struct
*iibm
)
2921 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
2923 TPACPI_ACPIHANDLE_INIT(ledb
);
2924 TPACPI_ACPIHANDLE_INIT(lght
);
2925 TPACPI_ACPIHANDLE_INIT(cmos
);
2927 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
2928 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
2930 if (tp_features
.light
)
2931 /* light status not supported on
2932 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
2933 tp_features
.light_status
=
2934 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
2936 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
2937 str_supported(tp_features
.light
));
2939 return (tp_features
.light
)? 0 : 1;
2942 static int light_read(char *p
)
2947 if (!tp_features
.light
) {
2948 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2949 } else if (!tp_features
.light_status
) {
2950 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
2951 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2953 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
2955 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
2956 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2962 static int light_write(char *buf
)
2964 int cmos_cmd
, lght_cmd
;
2968 if (!tp_features
.light
)
2971 while ((cmd
= next_cmd(&buf
))) {
2972 if (strlencmp(cmd
, "on") == 0) {
2975 } else if (strlencmp(cmd
, "off") == 0) {
2981 success
= cmos_handle
?
2982 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
2983 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
2991 static struct ibm_struct light_driver_data
= {
2994 .write
= light_write
,
2997 /*************************************************************************
3001 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3003 static void dock_notify(struct ibm_struct
*ibm
, u32 event
);
3004 static int dock_read(char *p
);
3005 static int dock_write(char *buf
);
3007 TPACPI_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
3008 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
3009 "\\_SB.PCI0.PCI1.DOCK", /* all others */
3010 "\\_SB.PCI.ISA.SLCE", /* 570 */
3011 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
3013 /* don't list other alternatives as we install a notify handler on the 570 */
3014 TPACPI_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
3016 static const struct acpi_device_id ibm_pci_device_ids
[] = {
3017 {PCI_ROOT_HID_STRING
, 0},
3021 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
3023 .notify
= dock_notify
,
3024 .handle
= &dock_handle
,
3025 .type
= ACPI_SYSTEM_NOTIFY
,
3028 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
3029 * We just use it to get notifications of dock hotplug
3030 * in very old thinkpads */
3031 .hid
= ibm_pci_device_ids
,
3032 .notify
= dock_notify
,
3033 .handle
= &pci_handle
,
3034 .type
= ACPI_SYSTEM_NOTIFY
,
3038 static struct ibm_struct dock_driver_data
[2] = {
3042 .write
= dock_write
,
3043 .acpi
= &ibm_dock_acpidriver
[0],
3047 .acpi
= &ibm_dock_acpidriver
[1],
3051 #define dock_docked() (_sta(dock_handle) & 1)
3053 static int __init
dock_init(struct ibm_init_struct
*iibm
)
3055 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
3057 TPACPI_ACPIHANDLE_INIT(dock
);
3059 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
3060 str_supported(dock_handle
!= NULL
));
3062 return (dock_handle
)? 0 : 1;
3065 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
3069 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
3071 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
3072 dock_driver_data
[0].flags
.acpi_notify_installed
) {
3073 TPACPI_ACPIHANDLE_INIT(pci
);
3074 dock2_needed
= (pci_handle
!= NULL
);
3075 vdbg_printk(TPACPI_DBG_INIT
,
3076 "dock PCI handler for the TP 570 is %s\n",
3077 str_supported(dock2_needed
));
3079 vdbg_printk(TPACPI_DBG_INIT
,
3080 "dock subdriver part 2 not required\n");
3084 return (dock2_needed
)? 0 : 1;
3087 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
3089 int docked
= dock_docked();
3090 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
3091 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
3094 if (event
== 1 && !pci
) /* 570 */
3095 data
= 1; /* button */
3096 else if (event
== 1 && pci
) /* 570 */
3097 data
= 3; /* dock */
3098 else if (event
== 3 && docked
)
3099 data
= 1; /* button */
3100 else if (event
== 3 && !docked
)
3101 data
= 2; /* undock */
3102 else if (event
== 0 && docked
)
3103 data
= 3; /* dock */
3105 printk(TPACPI_ERR
"unknown dock event %d, status %d\n",
3106 event
, _sta(dock_handle
));
3107 data
= 0; /* unknown */
3109 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
3110 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3111 ibm
->acpi
->device
->dev
.bus_id
,
3115 static int dock_read(char *p
)
3118 int docked
= dock_docked();
3121 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3123 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
3125 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
3126 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
3132 static int dock_write(char *buf
)
3139 while ((cmd
= next_cmd(&buf
))) {
3140 if (strlencmp(cmd
, "undock") == 0) {
3141 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
3142 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
3144 } else if (strlencmp(cmd
, "dock") == 0) {
3145 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
3154 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
3156 /*************************************************************************
3160 #ifdef CONFIG_THINKPAD_ACPI_BAY
3162 TPACPI_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
3163 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
3164 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
3165 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
3166 ); /* A21e, R30, R31 */
3167 TPACPI_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
3168 "_EJ0", /* all others */
3169 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
3170 TPACPI_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
3171 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
3173 TPACPI_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
3177 static int __init
bay_init(struct ibm_init_struct
*iibm
)
3179 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
3181 TPACPI_ACPIHANDLE_INIT(bay
);
3183 TPACPI_ACPIHANDLE_INIT(bay_ej
);
3184 TPACPI_ACPIHANDLE_INIT(bay2
);
3186 TPACPI_ACPIHANDLE_INIT(bay2_ej
);
3188 tp_features
.bay_status
= bay_handle
&&
3189 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
3190 tp_features
.bay_status2
= bay2_handle
&&
3191 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
3193 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
3194 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
3195 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
3196 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
3198 vdbg_printk(TPACPI_DBG_INIT
,
3199 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
3200 str_supported(tp_features
.bay_status
),
3201 str_supported(tp_features
.bay_eject
),
3202 str_supported(tp_features
.bay_status2
),
3203 str_supported(tp_features
.bay_eject2
));
3205 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
3206 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
3209 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
3211 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
3212 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3213 ibm
->acpi
->device
->dev
.bus_id
,
3217 #define bay_occupied(b) (_sta(b##_handle) & 1)
3219 static int bay_read(char *p
)
3222 int occupied
= bay_occupied(bay
);
3223 int occupied2
= bay_occupied(bay2
);
3226 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3227 tp_features
.bay_status
?
3228 (occupied
? "occupied" : "unoccupied") :
3230 if (tp_features
.bay_status2
)
3231 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
3232 "occupied" : "unoccupied");
3234 eject
= tp_features
.bay_eject
&& occupied
;
3235 eject2
= tp_features
.bay_eject2
&& occupied2
;
3237 if (eject
&& eject2
)
3238 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
3240 len
+= sprintf(p
+ len
, "commands:\teject\n");
3242 len
+= sprintf(p
+ len
, "commands:\teject2\n");
3247 static int bay_write(char *buf
)
3251 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
3254 while ((cmd
= next_cmd(&buf
))) {
3255 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
3256 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
3258 } else if (tp_features
.bay_eject2
&&
3259 strlencmp(cmd
, "eject2") == 0) {
3260 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
3269 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
3270 .notify
= bay_notify
,
3271 .handle
= &bay_handle
,
3272 .type
= ACPI_SYSTEM_NOTIFY
,
3275 static struct ibm_struct bay_driver_data
= {
3279 .acpi
= &ibm_bay_acpidriver
,
3282 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3284 /*************************************************************************
3288 /* sysfs cmos_command -------------------------------------------------- */
3289 static ssize_t
cmos_command_store(struct device
*dev
,
3290 struct device_attribute
*attr
,
3291 const char *buf
, size_t count
)
3293 unsigned long cmos_cmd
;
3296 if (parse_strtoul(buf
, 21, &cmos_cmd
))
3299 res
= issue_thinkpad_cmos_command(cmos_cmd
);
3300 return (res
)? res
: count
;
3303 static struct device_attribute dev_attr_cmos_command
=
3304 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
3306 /* --------------------------------------------------------------------- */
3308 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
3312 vdbg_printk(TPACPI_DBG_INIT
,
3313 "initializing cmos commands subdriver\n");
3315 TPACPI_ACPIHANDLE_INIT(cmos
);
3317 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
3318 str_supported(cmos_handle
!= NULL
));
3320 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
3324 return (cmos_handle
)? 0 : 1;
3327 static void cmos_exit(void)
3329 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
3332 static int cmos_read(char *p
)
3336 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3337 R30, R31, T20-22, X20-21 */
3339 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3341 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3342 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
3348 static int cmos_write(char *buf
)
3353 while ((cmd
= next_cmd(&buf
))) {
3354 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
3355 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
3360 res
= issue_thinkpad_cmos_command(cmos_cmd
);
3368 static struct ibm_struct cmos_driver_data
= {
3371 .write
= cmos_write
,
3375 /*************************************************************************
3379 enum led_access_mode
{
3380 TPACPI_LED_NONE
= 0,
3381 TPACPI_LED_570
, /* 570 */
3382 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3383 TPACPI_LED_NEW
, /* all others */
3386 enum { /* For TPACPI_LED_OLD */
3387 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
3388 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
3389 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
3392 static enum led_access_mode led_supported
;
3394 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
3395 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
3396 /* T20-22, X20-21 */
3397 "LED", /* all others */
3400 static int __init
led_init(struct ibm_init_struct
*iibm
)
3402 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
3404 TPACPI_ACPIHANDLE_INIT(led
);
3407 /* led not supported on R30, R31 */
3408 led_supported
= TPACPI_LED_NONE
;
3409 else if (strlencmp(led_path
, "SLED") == 0)
3411 led_supported
= TPACPI_LED_570
;
3412 else if (strlencmp(led_path
, "SYSL") == 0)
3413 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3414 led_supported
= TPACPI_LED_OLD
;
3417 led_supported
= TPACPI_LED_NEW
;
3419 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
3420 str_supported(led_supported
), led_supported
);
3422 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
3425 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
3427 static int led_read(char *p
)
3431 if (!led_supported
) {
3432 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3435 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3437 if (led_supported
== TPACPI_LED_570
) {
3440 for (i
= 0; i
< 8; i
++) {
3441 if (!acpi_evalf(ec_handle
,
3442 &status
, "GLED", "dd", 1 << i
))
3444 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
3445 i
, led_status(status
));
3449 len
+= sprintf(p
+ len
, "commands:\t"
3450 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
3455 /* off, on, blink */
3456 static const int led_sled_arg1
[] = { 0, 1, 3 };
3457 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
3458 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
3459 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
3461 static int led_write(char *buf
)
3469 while ((cmd
= next_cmd(&buf
))) {
3470 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
3473 if (strstr(cmd
, "off")) {
3475 } else if (strstr(cmd
, "on")) {
3477 } else if (strstr(cmd
, "blink")) {
3482 if (led_supported
== TPACPI_LED_570
) {
3485 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
3486 led
, led_sled_arg1
[ind
]))
3488 } else if (led_supported
== TPACPI_LED_OLD
) {
3489 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
3491 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
3493 ret
= ec_write(TPACPI_LED_EC_HLBL
,
3494 led
* led_exp_hlbl
[ind
]);
3496 ret
= ec_write(TPACPI_LED_EC_HLCL
,
3497 led
* led_exp_hlcl
[ind
]);
3502 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
3503 led
, led_led_arg1
[ind
]))
3511 static struct ibm_struct led_driver_data
= {
3517 /*************************************************************************
3521 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
3523 static int __init
beep_init(struct ibm_init_struct
*iibm
)
3525 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
3527 TPACPI_ACPIHANDLE_INIT(beep
);
3529 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
3530 str_supported(beep_handle
!= NULL
));
3532 return (beep_handle
)? 0 : 1;
3535 static int beep_read(char *p
)
3540 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3542 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3543 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
3549 static int beep_write(char *buf
)
3557 while ((cmd
= next_cmd(&buf
))) {
3558 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
3559 beep_cmd
>= 0 && beep_cmd
<= 17) {
3563 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
3570 static struct ibm_struct beep_driver_data
= {
3573 .write
= beep_write
,
3576 /*************************************************************************
3580 enum thermal_access_mode
{
3581 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
3582 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
3583 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
3584 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
3585 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
3588 enum { /* TPACPI_THERMAL_TPEC_* */
3589 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
3590 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
3591 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
3594 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
3595 struct ibm_thermal_sensors_struct
{
3596 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
3599 static enum thermal_access_mode thermal_read_mode
;
3601 /* idx is zero-based */
3602 static int thermal_get_sensor(int idx
, s32
*value
)
3608 t
= TP_EC_THERMAL_TMP0
;
3610 switch (thermal_read_mode
) {
3611 #if TPACPI_MAX_THERMAL_SENSORS >= 16
3612 case TPACPI_THERMAL_TPEC_16
:
3613 if (idx
>= 8 && idx
<= 15) {
3614 t
= TP_EC_THERMAL_TMP8
;
3619 case TPACPI_THERMAL_TPEC_8
:
3621 if (!acpi_ec_read(t
+ idx
, &tmp
))
3623 *value
= tmp
* 1000;
3628 case TPACPI_THERMAL_ACPI_UPDT
:
3630 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3631 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
3633 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3635 *value
= (t
- 2732) * 100;
3640 case TPACPI_THERMAL_ACPI_TMP07
:
3642 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3643 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3645 if (t
> 127 || t
< -127)
3646 t
= TP_EC_THERMAL_TMP_NA
;
3652 case TPACPI_THERMAL_NONE
:
3660 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
3671 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
3674 for (i
= 0 ; i
< n
; i
++) {
3675 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
3683 /* sysfs temp##_input -------------------------------------------------- */
3685 static ssize_t
thermal_temp_input_show(struct device
*dev
,
3686 struct device_attribute
*attr
,
3689 struct sensor_device_attribute
*sensor_attr
=
3690 to_sensor_dev_attr(attr
);
3691 int idx
= sensor_attr
->index
;
3695 res
= thermal_get_sensor(idx
, &value
);
3698 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
3701 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
3704 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
3705 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
3706 thermal_temp_input_show, NULL, _idxB)
3708 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
3709 THERMAL_SENSOR_ATTR_TEMP(1, 0),
3710 THERMAL_SENSOR_ATTR_TEMP(2, 1),
3711 THERMAL_SENSOR_ATTR_TEMP(3, 2),
3712 THERMAL_SENSOR_ATTR_TEMP(4, 3),
3713 THERMAL_SENSOR_ATTR_TEMP(5, 4),
3714 THERMAL_SENSOR_ATTR_TEMP(6, 5),
3715 THERMAL_SENSOR_ATTR_TEMP(7, 6),
3716 THERMAL_SENSOR_ATTR_TEMP(8, 7),
3717 THERMAL_SENSOR_ATTR_TEMP(9, 8),
3718 THERMAL_SENSOR_ATTR_TEMP(10, 9),
3719 THERMAL_SENSOR_ATTR_TEMP(11, 10),
3720 THERMAL_SENSOR_ATTR_TEMP(12, 11),
3721 THERMAL_SENSOR_ATTR_TEMP(13, 12),
3722 THERMAL_SENSOR_ATTR_TEMP(14, 13),
3723 THERMAL_SENSOR_ATTR_TEMP(15, 14),
3724 THERMAL_SENSOR_ATTR_TEMP(16, 15),
3727 #define THERMAL_ATTRS(X) \
3728 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
3730 static struct attribute
*thermal_temp_input_attr
[] = {
3750 static const struct attribute_group thermal_temp_input16_group
= {
3751 .attrs
= thermal_temp_input_attr
3754 static const struct attribute_group thermal_temp_input8_group
= {
3755 .attrs
= &thermal_temp_input_attr
[8]
3758 #undef THERMAL_SENSOR_ATTR_TEMP
3759 #undef THERMAL_ATTRS
3761 /* --------------------------------------------------------------------- */
3763 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
3770 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
3772 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
3774 if (thinkpad_id
.ec_model
) {
3776 * Direct EC access mode: sensors at registers
3777 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
3778 * non-implemented, thermal sensors return 0x80 when
3783 for (i
= 0; i
< 8; i
++) {
3784 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
3790 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
3798 /* This is sheer paranoia, but we handle it anyway */
3801 "ThinkPad ACPI EC access misbehaving, "
3802 "falling back to ACPI TMPx access "
3804 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
3807 "ThinkPad ACPI EC access misbehaving, "
3808 "disabling thermal sensors access\n");
3809 thermal_read_mode
= TPACPI_THERMAL_NONE
;
3814 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
3816 } else if (acpi_tmp7
) {
3817 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
3818 /* 600e/x, 770e, 770x */
3819 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
3821 /* Standard ACPI TMPx access, max 8 sensors */
3822 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
3825 /* temperatures not supported on 570, G4x, R30, R31, R32 */
3826 thermal_read_mode
= TPACPI_THERMAL_NONE
;
3829 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
3830 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
3833 switch (thermal_read_mode
) {
3834 case TPACPI_THERMAL_TPEC_16
:
3835 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3836 &thermal_temp_input16_group
);
3840 case TPACPI_THERMAL_TPEC_8
:
3841 case TPACPI_THERMAL_ACPI_TMP07
:
3842 case TPACPI_THERMAL_ACPI_UPDT
:
3843 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3844 &thermal_temp_input8_group
);
3848 case TPACPI_THERMAL_NONE
:
3856 static void thermal_exit(void)
3858 switch (thermal_read_mode
) {
3859 case TPACPI_THERMAL_TPEC_16
:
3860 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3861 &thermal_temp_input16_group
);
3863 case TPACPI_THERMAL_TPEC_8
:
3864 case TPACPI_THERMAL_ACPI_TMP07
:
3865 case TPACPI_THERMAL_ACPI_UPDT
:
3866 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3867 &thermal_temp_input16_group
);
3869 case TPACPI_THERMAL_NONE
:
3875 static int thermal_read(char *p
)
3879 struct ibm_thermal_sensors_struct t
;
3881 n
= thermal_get_sensors(&t
);
3882 if (unlikely(n
< 0))
3885 len
+= sprintf(p
+ len
, "temperatures:\t");
3888 for (i
= 0; i
< (n
- 1); i
++)
3889 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
3890 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
3892 len
+= sprintf(p
+ len
, "not supported\n");
3897 static struct ibm_struct thermal_driver_data
= {
3899 .read
= thermal_read
,
3900 .exit
= thermal_exit
,
3903 /*************************************************************************
3907 static u8 ecdump_regs
[256];
3909 static int ecdump_read(char *p
)
3915 len
+= sprintf(p
+ len
, "EC "
3916 " +00 +01 +02 +03 +04 +05 +06 +07"
3917 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
3918 for (i
= 0; i
< 256; i
+= 16) {
3919 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
3920 for (j
= 0; j
< 16; j
++) {
3921 if (!acpi_ec_read(i
+ j
, &v
))
3923 if (v
!= ecdump_regs
[i
+ j
])
3924 len
+= sprintf(p
+ len
, " *%02x", v
);
3926 len
+= sprintf(p
+ len
, " %02x", v
);
3927 ecdump_regs
[i
+ j
] = v
;
3929 len
+= sprintf(p
+ len
, "\n");
3934 /* These are way too dangerous to advertise openly... */
3936 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
3937 " (<offset> is 00-ff, <value> is 00-ff)\n");
3938 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
3939 " (<offset> is 00-ff, <value> is 0-255)\n");
3944 static int ecdump_write(char *buf
)
3949 while ((cmd
= next_cmd(&buf
))) {
3950 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
3952 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
3956 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
3957 if (!acpi_ec_write(i
, v
))
3966 static struct ibm_struct ecdump_driver_data
= {
3968 .read
= ecdump_read
,
3969 .write
= ecdump_write
,
3970 .flags
.experimental
= 1,
3973 /*************************************************************************
3974 * Backlight/brightness subdriver
3977 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
3979 static struct backlight_device
*ibm_backlight_device
;
3980 static int brightness_offset
= 0x31;
3981 static int brightness_mode
;
3982 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
3984 static struct mutex brightness_mutex
;
3987 * ThinkPads can read brightness from two places: EC 0x31, or
3988 * CMOS NVRAM byte 0x5E, bits 0-3.
3990 static int brightness_get(struct backlight_device
*bd
)
3992 u8 lec
= 0, lcmos
= 0, level
= 0;
3994 if (brightness_mode
& 1) {
3995 if (!acpi_ec_read(brightness_offset
, &lec
))
3997 lec
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
4000 if (brightness_mode
& 2) {
4001 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
4002 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
4003 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
4004 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
4008 if (brightness_mode
== 3 && lec
!= lcmos
) {
4010 "CMOS NVRAM (%u) and EC (%u) do not agree "
4011 "on display brightness level\n",
4012 (unsigned int) lcmos
,
4013 (unsigned int) lec
);
4020 /* May return EINTR which can always be mapped to ERESTARTSYS */
4021 static int brightness_set(int value
)
4023 int cmos_cmd
, inc
, i
, res
;
4026 if (value
> ((tp_features
.bright_16levels
)? 15 : 7))
4029 res
= mutex_lock_interruptible(&brightness_mutex
);
4033 current_value
= brightness_get(NULL
);
4034 if (current_value
< 0) {
4035 res
= current_value
;
4039 cmos_cmd
= value
> current_value
?
4040 TP_CMOS_BRIGHTNESS_UP
:
4041 TP_CMOS_BRIGHTNESS_DOWN
;
4042 inc
= (value
> current_value
)? 1 : -1;
4045 for (i
= current_value
; i
!= value
; i
+= inc
) {
4046 if ((brightness_mode
& 2) &&
4047 issue_thinkpad_cmos_command(cmos_cmd
)) {
4051 if ((brightness_mode
& 1) &&
4052 !acpi_ec_write(brightness_offset
, i
+ inc
)) {
4059 mutex_unlock(&brightness_mutex
);
4063 /* sysfs backlight class ----------------------------------------------- */
4065 static int brightness_update_status(struct backlight_device
*bd
)
4067 /* it is the backlight class's job (caller) to handle
4068 * EINTR and other errors properly */
4069 return brightness_set(
4070 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
4071 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
4072 bd
->props
.brightness
: 0);
4075 static struct backlight_ops ibm_backlight_data
= {
4076 .get_brightness
= brightness_get
,
4077 .update_status
= brightness_update_status
,
4080 /* --------------------------------------------------------------------- */
4082 static int __init
tpacpi_query_bcll_levels(acpi_handle handle
)
4084 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
4085 union acpi_object
*obj
;
4088 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
4089 obj
= (union acpi_object
*)buffer
.pointer
;
4090 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
4091 printk(TPACPI_ERR
"Unknown BCLL data, "
4092 "please report this to %s\n", TPACPI_MAIL
);
4095 rc
= obj
->package
.count
;
4101 kfree(buffer
.pointer
);
4105 static acpi_status __init
brightness_find_bcll(acpi_handle handle
, u32 lvl
,
4106 void *context
, void **rv
)
4108 char name
[ACPI_PATH_SEGMENT_LENGTH
];
4109 struct acpi_buffer buffer
= { sizeof(name
), &name
};
4111 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
4112 !strncmp("BCLL", name
, sizeof(name
) - 1)) {
4113 if (tpacpi_query_bcll_levels(handle
) == 16) {
4115 return AE_CTRL_TERMINATE
;
4124 static int __init
brightness_check_levels(void)
4127 void *found_node
= NULL
;
4130 TPACPI_ACPIHANDLE_INIT(vid
);
4135 /* Search for a BCLL package with 16 levels */
4136 status
= acpi_walk_namespace(ACPI_TYPE_PACKAGE
, vid_handle
, 3,
4137 brightness_find_bcll
, NULL
,
4140 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
4143 static acpi_status __init
brightness_find_bcl(acpi_handle handle
, u32 lvl
,
4144 void *context
, void **rv
)
4146 char name
[ACPI_PATH_SEGMENT_LENGTH
];
4147 struct acpi_buffer buffer
= { sizeof(name
), &name
};
4149 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
4150 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
4152 return AE_CTRL_TERMINATE
;
4158 static int __init
brightness_check_std_acpi_support(void)
4161 void *found_node
= NULL
;
4164 TPACPI_ACPIHANDLE_INIT(vid
);
4169 /* Search for a _BCL method, but don't execute it */
4170 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
4171 brightness_find_bcl
, NULL
, &found_node
);
4173 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
4176 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
4180 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
4182 mutex_init(&brightness_mutex
);
4184 if (!brightness_enable
) {
4185 dbg_printk(TPACPI_DBG_INIT
,
4186 "brightness support disabled by "
4187 "module parameter\n");
4189 } else if (brightness_enable
> 1) {
4190 if (brightness_check_std_acpi_support()) {
4191 printk(TPACPI_NOTICE
4192 "standard ACPI backlight interface "
4193 "available, not loading native one...\n");
4198 if (!brightness_mode
) {
4199 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
4200 brightness_mode
= 2;
4202 brightness_mode
= 3;
4204 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
4208 if (brightness_mode
> 3)
4211 tp_features
.bright_16levels
=
4212 thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
&&
4213 brightness_check_levels();
4215 b
= brightness_get(NULL
);
4219 if (tp_features
.bright_16levels
)
4221 "detected a 16-level brightness capable ThinkPad\n");
4223 ibm_backlight_device
= backlight_device_register(
4224 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
4225 &ibm_backlight_data
);
4226 if (IS_ERR(ibm_backlight_device
)) {
4227 printk(TPACPI_ERR
"Could not register backlight device\n");
4228 return PTR_ERR(ibm_backlight_device
);
4230 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
4232 ibm_backlight_device
->props
.max_brightness
=
4233 (tp_features
.bright_16levels
)? 15 : 7;
4234 ibm_backlight_device
->props
.brightness
= b
;
4235 backlight_update_status(ibm_backlight_device
);
4240 static void brightness_exit(void)
4242 if (ibm_backlight_device
) {
4243 vdbg_printk(TPACPI_DBG_EXIT
,
4244 "calling backlight_device_unregister()\n");
4245 backlight_device_unregister(ibm_backlight_device
);
4246 ibm_backlight_device
= NULL
;
4250 static int brightness_read(char *p
)
4255 level
= brightness_get(NULL
);
4257 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
4259 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
4260 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
4261 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
4262 " (<level> is 0-%d)\n",
4263 (tp_features
.bright_16levels
) ? 15 : 7);
4269 static int brightness_write(char *buf
)
4274 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
4276 level
= brightness_get(NULL
);
4280 while ((cmd
= next_cmd(&buf
))) {
4281 if (strlencmp(cmd
, "up") == 0) {
4282 if (level
< max_level
)
4284 } else if (strlencmp(cmd
, "down") == 0) {
4287 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
4288 level
>= 0 && level
<= max_level
) {
4295 * Now we know what the final level should be, so we try to set it.
4296 * Doing it this way makes the syscall restartable in case of EINTR
4298 rc
= brightness_set(level
);
4299 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
4302 static struct ibm_struct brightness_driver_data
= {
4303 .name
= "brightness",
4304 .read
= brightness_read
,
4305 .write
= brightness_write
,
4306 .exit
= brightness_exit
,
4309 /*************************************************************************
4313 static int volume_offset
= 0x30;
4315 static int volume_read(char *p
)
4320 if (!acpi_ec_read(volume_offset
, &level
)) {
4321 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
4323 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
4324 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
4325 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
4326 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
4327 " (<level> is 0-15)\n");
4333 static int volume_write(char *buf
)
4335 int cmos_cmd
, inc
, i
;
4337 int new_level
, new_mute
;
4340 while ((cmd
= next_cmd(&buf
))) {
4341 if (!acpi_ec_read(volume_offset
, &level
))
4343 new_mute
= mute
= level
& 0x40;
4344 new_level
= level
= level
& 0xf;
4346 if (strlencmp(cmd
, "up") == 0) {
4350 new_level
= level
== 15 ? 15 : level
+ 1;
4351 } else if (strlencmp(cmd
, "down") == 0) {
4355 new_level
= level
== 0 ? 0 : level
- 1;
4356 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
4357 new_level
>= 0 && new_level
<= 15) {
4359 } else if (strlencmp(cmd
, "mute") == 0) {
4364 if (new_level
!= level
) {
4365 /* mute doesn't change */
4367 cmos_cmd
= (new_level
> level
) ?
4368 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
4369 inc
= new_level
> level
? 1 : -1;
4371 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
4372 !acpi_ec_write(volume_offset
, level
)))
4375 for (i
= level
; i
!= new_level
; i
+= inc
)
4376 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
4377 !acpi_ec_write(volume_offset
, i
+ inc
))
4381 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
4382 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
4387 if (new_mute
!= mute
) {
4388 /* level doesn't change */
4390 cmos_cmd
= (new_mute
) ?
4391 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
4393 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
4394 !acpi_ec_write(volume_offset
, level
+ new_mute
))
4402 static struct ibm_struct volume_driver_data
= {
4404 .read
= volume_read
,
4405 .write
= volume_write
,
4408 /*************************************************************************
4415 * TPACPI_FAN_RD_ACPI_GFAN:
4416 * ACPI GFAN method: returns fan level
4418 * see TPACPI_FAN_WR_ACPI_SFAN
4419 * EC 0x2f (HFSP) not available if GFAN exists
4421 * TPACPI_FAN_WR_ACPI_SFAN:
4422 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
4424 * EC 0x2f (HFSP) might be available *for reading*, but do not use
4427 * TPACPI_FAN_WR_TPEC:
4428 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
4429 * Supported on almost all ThinkPads
4431 * Fan speed changes of any sort (including those caused by the
4432 * disengaged mode) are usually done slowly by the firmware as the
4433 * maximum ammount of fan duty cycle change per second seems to be
4436 * Reading is not available if GFAN exists.
4437 * Writing is not available if SFAN exists.
4440 * 7 automatic mode engaged;
4441 * (default operation mode of the ThinkPad)
4442 * fan level is ignored in this mode.
4443 * 6 full speed mode (takes precedence over bit 7);
4444 * not available on all thinkpads. May disable
4445 * the tachometer while the fan controller ramps up
4446 * the speed (which can take up to a few *minutes*).
4447 * Speeds up fan to 100% duty-cycle, which is far above
4448 * the standard RPM levels. It is not impossible that
4449 * it could cause hardware damage.
4450 * 5-3 unused in some models. Extra bits for fan level
4451 * in others, but still useless as all values above
4452 * 7 map to the same speed as level 7 in these models.
4453 * 2-0 fan level (0..7 usually)
4455 * 0x07 = max (set when temperatures critical)
4456 * Some ThinkPads may have other levels, see
4457 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
4459 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
4460 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
4461 * does so, its initial value is meaningless (0x07).
4463 * For firmware bugs, refer to:
4464 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
4468 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
4469 * Main fan tachometer reading (in RPM)
4471 * This register is present on all ThinkPads with a new-style EC, and
4472 * it is known not to be present on the A21m/e, and T22, as there is
4473 * something else in offset 0x84 according to the ACPI DSDT. Other
4474 * ThinkPads from this same time period (and earlier) probably lack the
4475 * tachometer as well.
4477 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
4478 * was never fixed by IBM to report the EC firmware version string
4479 * probably support the tachometer (like the early X models), so
4480 * detecting it is quite hard. We need more data to know for sure.
4482 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
4485 * FIRMWARE BUG: may go stale while the EC is switching to full speed
4488 * For firmware bugs, refer to:
4489 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
4491 * TPACPI_FAN_WR_ACPI_FANS:
4492 * ThinkPad X31, X40, X41. Not available in the X60.
4494 * FANS ACPI handle: takes three arguments: low speed, medium speed,
4495 * high speed. ACPI DSDT seems to map these three speeds to levels
4496 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
4497 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
4499 * The speeds are stored on handles
4500 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
4502 * There are three default speed sets, acessible as handles:
4503 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
4505 * ACPI DSDT switches which set is in use depending on various
4508 * TPACPI_FAN_WR_TPEC is also available and should be used to
4509 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
4510 * but the ACPI tables just mention level 7.
4513 enum { /* Fan control constants */
4514 fan_status_offset
= 0x2f, /* EC register 0x2f */
4515 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
4516 * 0x84 must be read before 0x85 */
4518 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
4519 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
4521 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
4524 enum fan_status_access_mode
{
4525 TPACPI_FAN_NONE
= 0, /* No fan status or control */
4526 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
4527 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
4530 enum fan_control_access_mode
{
4531 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
4532 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
4533 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
4534 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
4537 enum fan_control_commands
{
4538 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
4539 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
4540 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
4541 * and also watchdog cmd */
4544 static int fan_control_allowed
;
4546 static enum fan_status_access_mode fan_status_access_mode
;
4547 static enum fan_control_access_mode fan_control_access_mode
;
4548 static enum fan_control_commands fan_control_commands
;
4550 static u8 fan_control_initial_status
;
4551 static u8 fan_control_desired_level
;
4552 static int fan_watchdog_maxinterval
;
4554 static struct mutex fan_mutex
;
4556 static void fan_watchdog_fire(struct work_struct
*ignored
);
4557 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
4559 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
4560 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
4561 "\\FSPD", /* 600e/x, 770e, 770x */
4563 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
4564 "JFNS", /* 770x-JL */
4568 * Call with fan_mutex held
4570 static void fan_update_desired_level(u8 status
)
4573 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
4575 fan_control_desired_level
= 7;
4577 fan_control_desired_level
= status
;
4581 static int fan_get_status(u8
*status
)
4586 * Add TPACPI_FAN_RD_ACPI_FANS ? */
4588 switch (fan_status_access_mode
) {
4589 case TPACPI_FAN_RD_ACPI_GFAN
:
4590 /* 570, 600e/x, 770e, 770x */
4592 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
4600 case TPACPI_FAN_RD_TPEC
:
4601 /* all except 570, 600e/x, 770e, 770x */
4602 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
4617 static int fan_get_status_safe(u8
*status
)
4622 if (mutex_lock_interruptible(&fan_mutex
))
4623 return -ERESTARTSYS
;
4624 rc
= fan_get_status(&s
);
4626 fan_update_desired_level(s
);
4627 mutex_unlock(&fan_mutex
);
4635 static int fan_get_speed(unsigned int *speed
)
4639 switch (fan_status_access_mode
) {
4640 case TPACPI_FAN_RD_TPEC
:
4641 /* all except 570, 600e/x, 770e, 770x */
4642 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
4643 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
4647 *speed
= (hi
<< 8) | lo
;
4658 static int fan_set_level(int level
)
4660 if (!fan_control_allowed
)
4663 switch (fan_control_access_mode
) {
4664 case TPACPI_FAN_WR_ACPI_SFAN
:
4665 if (level
>= 0 && level
<= 7) {
4666 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
4672 case TPACPI_FAN_WR_ACPI_FANS
:
4673 case TPACPI_FAN_WR_TPEC
:
4674 if ((level
!= TP_EC_FAN_AUTO
) &&
4675 (level
!= TP_EC_FAN_FULLSPEED
) &&
4676 ((level
< 0) || (level
> 7)))
4679 /* safety net should the EC not support AUTO
4680 * or FULLSPEED mode bits and just ignore them */
4681 if (level
& TP_EC_FAN_FULLSPEED
)
4682 level
|= 7; /* safety min speed 7 */
4683 else if (level
& TP_EC_FAN_FULLSPEED
)
4684 level
|= 4; /* safety min speed 4 */
4686 if (!acpi_ec_write(fan_status_offset
, level
))
4689 tp_features
.fan_ctrl_status_undef
= 0;
4698 static int fan_set_level_safe(int level
)
4702 if (!fan_control_allowed
)
4705 if (mutex_lock_interruptible(&fan_mutex
))
4706 return -ERESTARTSYS
;
4708 if (level
== TPACPI_FAN_LAST_LEVEL
)
4709 level
= fan_control_desired_level
;
4711 rc
= fan_set_level(level
);
4713 fan_update_desired_level(level
);
4715 mutex_unlock(&fan_mutex
);
4719 static int fan_set_enable(void)
4724 if (!fan_control_allowed
)
4727 if (mutex_lock_interruptible(&fan_mutex
))
4728 return -ERESTARTSYS
;
4730 switch (fan_control_access_mode
) {
4731 case TPACPI_FAN_WR_ACPI_FANS
:
4732 case TPACPI_FAN_WR_TPEC
:
4733 rc
= fan_get_status(&s
);
4737 /* Don't go out of emergency fan mode */
4740 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
4743 if (!acpi_ec_write(fan_status_offset
, s
))
4746 tp_features
.fan_ctrl_status_undef
= 0;
4751 case TPACPI_FAN_WR_ACPI_SFAN
:
4752 rc
= fan_get_status(&s
);
4758 /* Set fan to at least level 4 */
4761 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
4771 mutex_unlock(&fan_mutex
);
4775 static int fan_set_disable(void)
4779 if (!fan_control_allowed
)
4782 if (mutex_lock_interruptible(&fan_mutex
))
4783 return -ERESTARTSYS
;
4786 switch (fan_control_access_mode
) {
4787 case TPACPI_FAN_WR_ACPI_FANS
:
4788 case TPACPI_FAN_WR_TPEC
:
4789 if (!acpi_ec_write(fan_status_offset
, 0x00))
4792 fan_control_desired_level
= 0;
4793 tp_features
.fan_ctrl_status_undef
= 0;
4797 case TPACPI_FAN_WR_ACPI_SFAN
:
4798 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
4801 fan_control_desired_level
= 0;
4809 mutex_unlock(&fan_mutex
);
4813 static int fan_set_speed(int speed
)
4817 if (!fan_control_allowed
)
4820 if (mutex_lock_interruptible(&fan_mutex
))
4821 return -ERESTARTSYS
;
4824 switch (fan_control_access_mode
) {
4825 case TPACPI_FAN_WR_ACPI_FANS
:
4826 if (speed
>= 0 && speed
<= 65535) {
4827 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
4828 speed
, speed
, speed
))
4838 mutex_unlock(&fan_mutex
);
4842 static void fan_watchdog_reset(void)
4844 static int fan_watchdog_active
;
4846 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
4849 if (fan_watchdog_active
)
4850 cancel_delayed_work(&fan_watchdog_task
);
4852 if (fan_watchdog_maxinterval
> 0 &&
4853 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
4854 fan_watchdog_active
= 1;
4855 if (!schedule_delayed_work(&fan_watchdog_task
,
4856 msecs_to_jiffies(fan_watchdog_maxinterval
4859 "failed to schedule the fan watchdog, "
4860 "watchdog will not trigger\n");
4863 fan_watchdog_active
= 0;
4866 static void fan_watchdog_fire(struct work_struct
*ignored
)
4870 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
4873 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
4874 rc
= fan_set_enable();
4876 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
4877 "will try again later...\n", -rc
);
4878 /* reschedule for later */
4879 fan_watchdog_reset();
4884 * SYSFS fan layout: hwmon compatible (device)
4887 * 0: "disengaged" mode
4889 * 2: native EC "auto" mode (recommended, hardware default)
4891 * pwm*: set speed in manual mode, ignored otherwise.
4892 * 0 is level 0; 255 is level 7. Intermediate points done with linear
4895 * fan*_input: tachometer reading, RPM
4898 * SYSFS fan layout: extensions
4900 * fan_watchdog (driver):
4901 * fan watchdog interval in seconds, 0 disables (default), max 120
4904 /* sysfs fan pwm1_enable ----------------------------------------------- */
4905 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
4906 struct device_attribute
*attr
,
4912 res
= fan_get_status_safe(&status
);
4916 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4917 if (status
!= fan_control_initial_status
) {
4918 tp_features
.fan_ctrl_status_undef
= 0;
4920 /* Return most likely status. In fact, it
4921 * might be the only possible status */
4922 status
= TP_EC_FAN_AUTO
;
4926 if (status
& TP_EC_FAN_FULLSPEED
) {
4928 } else if (status
& TP_EC_FAN_AUTO
) {
4933 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
4936 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
4937 struct device_attribute
*attr
,
4938 const char *buf
, size_t count
)
4943 if (parse_strtoul(buf
, 2, &t
))
4948 level
= TP_EC_FAN_FULLSPEED
;
4951 level
= TPACPI_FAN_LAST_LEVEL
;
4954 level
= TP_EC_FAN_AUTO
;
4957 /* reserved for software-controlled auto mode */
4963 res
= fan_set_level_safe(level
);
4969 fan_watchdog_reset();
4974 static struct device_attribute dev_attr_fan_pwm1_enable
=
4975 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
4976 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
4978 /* sysfs fan pwm1 ------------------------------------------------------ */
4979 static ssize_t
fan_pwm1_show(struct device
*dev
,
4980 struct device_attribute
*attr
,
4986 res
= fan_get_status_safe(&status
);
4990 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4991 if (status
!= fan_control_initial_status
) {
4992 tp_features
.fan_ctrl_status_undef
= 0;
4994 status
= TP_EC_FAN_AUTO
;
4999 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
5000 status
= fan_control_desired_level
;
5005 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
5008 static ssize_t
fan_pwm1_store(struct device
*dev
,
5009 struct device_attribute
*attr
,
5010 const char *buf
, size_t count
)
5014 u8 status
, newlevel
;
5016 if (parse_strtoul(buf
, 255, &s
))
5019 /* scale down from 0-255 to 0-7 */
5020 newlevel
= (s
>> 5) & 0x07;
5022 if (mutex_lock_interruptible(&fan_mutex
))
5023 return -ERESTARTSYS
;
5025 rc
= fan_get_status(&status
);
5026 if (!rc
&& (status
&
5027 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
5028 rc
= fan_set_level(newlevel
);
5032 fan_update_desired_level(newlevel
);
5033 fan_watchdog_reset();
5037 mutex_unlock(&fan_mutex
);
5038 return (rc
)? rc
: count
;
5041 static struct device_attribute dev_attr_fan_pwm1
=
5042 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
5043 fan_pwm1_show
, fan_pwm1_store
);
5045 /* sysfs fan fan1_input ------------------------------------------------ */
5046 static ssize_t
fan_fan1_input_show(struct device
*dev
,
5047 struct device_attribute
*attr
,
5053 res
= fan_get_speed(&speed
);
5057 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
5060 static struct device_attribute dev_attr_fan_fan1_input
=
5061 __ATTR(fan1_input
, S_IRUGO
,
5062 fan_fan1_input_show
, NULL
);
5064 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
5065 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
5068 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
5071 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
5072 const char *buf
, size_t count
)
5076 if (parse_strtoul(buf
, 120, &t
))
5079 if (!fan_control_allowed
)
5082 fan_watchdog_maxinterval
= t
;
5083 fan_watchdog_reset();
5088 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
5089 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
5091 /* --------------------------------------------------------------------- */
5092 static struct attribute
*fan_attributes
[] = {
5093 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
5094 &dev_attr_fan_fan1_input
.attr
,
5098 static const struct attribute_group fan_attr_group
= {
5099 .attrs
= fan_attributes
,
5102 static int __init
fan_init(struct ibm_init_struct
*iibm
)
5106 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
5108 mutex_init(&fan_mutex
);
5109 fan_status_access_mode
= TPACPI_FAN_NONE
;
5110 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
5111 fan_control_commands
= 0;
5112 fan_watchdog_maxinterval
= 0;
5113 tp_features
.fan_ctrl_status_undef
= 0;
5114 fan_control_desired_level
= 7;
5116 TPACPI_ACPIHANDLE_INIT(fans
);
5117 TPACPI_ACPIHANDLE_INIT(gfan
);
5118 TPACPI_ACPIHANDLE_INIT(sfan
);
5121 /* 570, 600e/x, 770e, 770x */
5122 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
5124 /* all other ThinkPads: note that even old-style
5125 * ThinkPad ECs supports the fan control register */
5126 if (likely(acpi_ec_read(fan_status_offset
,
5127 &fan_control_initial_status
))) {
5128 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
5130 /* In some ThinkPads, neither the EC nor the ACPI
5131 * DSDT initialize the fan status, and it ends up
5132 * being set to 0x07 when it *could* be either
5135 * Enable for TP-1Y (T43), TP-78 (R51e),
5136 * TP-76 (R52), TP-70 (T43, R52), which are known
5138 if (fan_control_initial_status
== 0x07) {
5139 switch (thinkpad_id
.ec_model
) {
5140 case 0x5931: /* TP-1Y */
5141 case 0x3837: /* TP-78 */
5142 case 0x3637: /* TP-76 */
5143 case 0x3037: /* TP-70 */
5144 printk(TPACPI_NOTICE
5145 "fan_init: initial fan status "
5146 "is unknown, assuming it is "
5148 tp_features
.fan_ctrl_status_undef
= 1;
5154 "ThinkPad ACPI EC access misbehaving, "
5155 "fan status and control unavailable\n");
5162 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
5163 fan_control_commands
|=
5164 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
5167 /* gfan without sfan means no fan control */
5168 /* all other models implement TP EC 0x2f control */
5172 fan_control_access_mode
=
5173 TPACPI_FAN_WR_ACPI_FANS
;
5174 fan_control_commands
|=
5175 TPACPI_FAN_CMD_SPEED
|
5176 TPACPI_FAN_CMD_LEVEL
|
5177 TPACPI_FAN_CMD_ENABLE
;
5179 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
5180 fan_control_commands
|=
5181 TPACPI_FAN_CMD_LEVEL
|
5182 TPACPI_FAN_CMD_ENABLE
;
5187 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
5188 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
5189 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
5190 fan_status_access_mode
, fan_control_access_mode
);
5192 /* fan control master switch */
5193 if (!fan_control_allowed
) {
5194 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
5195 fan_control_commands
= 0;
5196 dbg_printk(TPACPI_DBG_INIT
,
5197 "fan control features disabled by parameter\n");
5200 /* update fan_control_desired_level */
5201 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
5202 fan_get_status_safe(NULL
);
5204 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
5205 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
5206 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5209 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
5210 &driver_attr_fan_watchdog
);
5218 static void fan_exit(void)
5220 vdbg_printk(TPACPI_DBG_EXIT
,
5221 "cancelling any pending fan watchdog tasks\n");
5223 /* FIXME: can we really do this unconditionally? */
5224 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
5225 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
5226 &driver_attr_fan_watchdog
);
5228 cancel_delayed_work(&fan_watchdog_task
);
5229 flush_scheduled_work();
5232 static int fan_read(char *p
)
5237 unsigned int speed
= 0;
5239 switch (fan_status_access_mode
) {
5240 case TPACPI_FAN_RD_ACPI_GFAN
:
5241 /* 570, 600e/x, 770e, 770x */
5242 rc
= fan_get_status_safe(&status
);
5246 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
5248 (status
!= 0) ? "enabled" : "disabled", status
);
5251 case TPACPI_FAN_RD_TPEC
:
5252 /* all except 570, 600e/x, 770e, 770x */
5253 rc
= fan_get_status_safe(&status
);
5257 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5258 if (status
!= fan_control_initial_status
)
5259 tp_features
.fan_ctrl_status_undef
= 0;
5261 /* Return most likely status. In fact, it
5262 * might be the only possible status */
5263 status
= TP_EC_FAN_AUTO
;
5266 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
5267 (status
!= 0) ? "enabled" : "disabled");
5269 rc
= fan_get_speed(&speed
);
5273 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
5275 if (status
& TP_EC_FAN_FULLSPEED
)
5276 /* Disengaged mode takes precedence */
5277 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
5278 else if (status
& TP_EC_FAN_AUTO
)
5279 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
5281 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
5284 case TPACPI_FAN_NONE
:
5286 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5289 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
5290 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
5292 switch (fan_control_access_mode
) {
5293 case TPACPI_FAN_WR_ACPI_SFAN
:
5294 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
5298 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
5299 "auto, disengaged, full-speed)\n");
5304 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
5305 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
5306 "commands:\twatchdog <timeout> (<timeout> "
5307 "is 0 (off), 1-120 (seconds))\n");
5309 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
5310 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
5311 " (<speed> is 0-65535)\n");
5316 static int fan_write_cmd_level(const char *cmd
, int *rc
)
5320 if (strlencmp(cmd
, "level auto") == 0)
5321 level
= TP_EC_FAN_AUTO
;
5322 else if ((strlencmp(cmd
, "level disengaged") == 0) |
5323 (strlencmp(cmd
, "level full-speed") == 0))
5324 level
= TP_EC_FAN_FULLSPEED
;
5325 else if (sscanf(cmd
, "level %d", &level
) != 1)
5328 *rc
= fan_set_level_safe(level
);
5330 printk(TPACPI_ERR
"level command accepted for unsupported "
5331 "access mode %d", fan_control_access_mode
);
5336 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
5338 if (strlencmp(cmd
, "enable") != 0)
5341 *rc
= fan_set_enable();
5343 printk(TPACPI_ERR
"enable command accepted for unsupported "
5344 "access mode %d", fan_control_access_mode
);
5349 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
5351 if (strlencmp(cmd
, "disable") != 0)
5354 *rc
= fan_set_disable();
5356 printk(TPACPI_ERR
"disable command accepted for unsupported "
5357 "access mode %d", fan_control_access_mode
);
5362 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
5367 * Support speed <low> <medium> <high> ? */
5369 if (sscanf(cmd
, "speed %d", &speed
) != 1)
5372 *rc
= fan_set_speed(speed
);
5374 printk(TPACPI_ERR
"speed command accepted for unsupported "
5375 "access mode %d", fan_control_access_mode
);
5380 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
5384 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
5387 if (interval
< 0 || interval
> 120)
5390 fan_watchdog_maxinterval
= interval
;
5395 static int fan_write(char *buf
)
5400 while (!rc
&& (cmd
= next_cmd(&buf
))) {
5401 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
5402 fan_write_cmd_level(cmd
, &rc
)) &&
5403 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
5404 (fan_write_cmd_enable(cmd
, &rc
) ||
5405 fan_write_cmd_disable(cmd
, &rc
) ||
5406 fan_write_cmd_watchdog(cmd
, &rc
))) &&
5407 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
5408 fan_write_cmd_speed(cmd
, &rc
))
5412 fan_watchdog_reset();
5418 static struct ibm_struct fan_driver_data
= {
5425 /****************************************************************************
5426 ****************************************************************************
5430 ****************************************************************************
5431 ****************************************************************************/
5433 /* sysfs name ---------------------------------------------------------- */
5434 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
5435 struct device_attribute
*attr
,
5438 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
5441 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
5442 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
5444 /* --------------------------------------------------------------------- */
5447 static struct proc_dir_entry
*proc_dir
;
5450 * Module and infrastructure proble, init and exit handling
5453 static int force_load
;
5455 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
5456 static const char * __init
str_supported(int is_supported
)
5458 static char text_unsupported
[] __initdata
= "not supported";
5460 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
5462 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
5464 static void ibm_exit(struct ibm_struct
*ibm
)
5466 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
5468 list_del_init(&ibm
->all_drivers
);
5470 if (ibm
->flags
.acpi_notify_installed
) {
5471 dbg_printk(TPACPI_DBG_EXIT
,
5472 "%s: acpi_remove_notify_handler\n", ibm
->name
);
5474 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
5476 dispatch_acpi_notify
);
5477 ibm
->flags
.acpi_notify_installed
= 0;
5478 ibm
->flags
.acpi_notify_installed
= 0;
5481 if (ibm
->flags
.proc_created
) {
5482 dbg_printk(TPACPI_DBG_EXIT
,
5483 "%s: remove_proc_entry\n", ibm
->name
);
5484 remove_proc_entry(ibm
->name
, proc_dir
);
5485 ibm
->flags
.proc_created
= 0;
5488 if (ibm
->flags
.acpi_driver_registered
) {
5489 dbg_printk(TPACPI_DBG_EXIT
,
5490 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
5492 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
5493 kfree(ibm
->acpi
->driver
);
5494 ibm
->acpi
->driver
= NULL
;
5495 ibm
->flags
.acpi_driver_registered
= 0;
5498 if (ibm
->flags
.init_called
&& ibm
->exit
) {
5500 ibm
->flags
.init_called
= 0;
5503 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
5506 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
5509 struct ibm_struct
*ibm
= iibm
->data
;
5510 struct proc_dir_entry
*entry
;
5512 BUG_ON(ibm
== NULL
);
5514 INIT_LIST_HEAD(&ibm
->all_drivers
);
5516 if (ibm
->flags
.experimental
&& !experimental
)
5519 dbg_printk(TPACPI_DBG_INIT
,
5520 "probing for %s\n", ibm
->name
);
5523 ret
= iibm
->init(iibm
);
5525 return 0; /* probe failed */
5529 ibm
->flags
.init_called
= 1;
5533 if (ibm
->acpi
->hid
) {
5534 ret
= register_tpacpi_subdriver(ibm
);
5539 if (ibm
->acpi
->notify
) {
5540 ret
= setup_acpi_notify(ibm
);
5541 if (ret
== -ENODEV
) {
5542 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
5552 dbg_printk(TPACPI_DBG_INIT
,
5553 "%s installed\n", ibm
->name
);
5556 entry
= create_proc_entry(ibm
->name
,
5557 S_IFREG
| S_IRUGO
| S_IWUSR
,
5560 printk(TPACPI_ERR
"unable to create proc entry %s\n",
5565 entry
->owner
= THIS_MODULE
;
5567 entry
->read_proc
= &dispatch_procfs_read
;
5569 entry
->write_proc
= &dispatch_procfs_write
;
5570 ibm
->flags
.proc_created
= 1;
5573 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
5578 dbg_printk(TPACPI_DBG_INIT
,
5579 "%s: at error exit path with result %d\n",
5583 return (ret
< 0)? ret
: 0;
5588 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
5590 const struct dmi_device
*dev
= NULL
;
5591 char ec_fw_string
[18];
5596 memset(tp
, 0, sizeof(*tp
));
5598 if (dmi_name_in_vendors("IBM"))
5599 tp
->vendor
= PCI_VENDOR_ID_IBM
;
5600 else if (dmi_name_in_vendors("LENOVO"))
5601 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
5605 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
5607 if (!tp
->bios_version_str
)
5609 tp
->bios_model
= tp
->bios_version_str
[0]
5610 | (tp
->bios_version_str
[1] << 8);
5613 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
5614 * X32 or newer, all Z series; Some models must have an
5615 * up-to-date BIOS or they will not be detected.
5617 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
5619 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
5620 if (sscanf(dev
->name
,
5621 "IBM ThinkPad Embedded Controller -[%17c",
5622 ec_fw_string
) == 1) {
5623 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
5624 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
5626 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
5627 tp
->ec_model
= ec_fw_string
[0]
5628 | (ec_fw_string
[1] << 8);
5633 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
5635 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
5636 kfree(tp
->model_str
);
5637 tp
->model_str
= NULL
;
5641 static int __init
probe_for_thinkpad(void)
5649 * Non-ancient models have better DMI tagging, but very old models
5652 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
5654 /* ec is required because many other handles are relative to it */
5655 TPACPI_ACPIHANDLE_INIT(ec
);
5659 "Not yet supported ThinkPad detected!\n");
5664 * Risks a regression on very old machines, but reduces potential
5665 * false positives a damn great deal
5668 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
5670 if (!is_thinkpad
&& !force_load
)
5677 /* Module init, exit, parameters */
5679 static struct ibm_init_struct ibms_init
[] __initdata
= {
5681 .init
= thinkpad_acpi_driver_init
,
5682 .data
= &thinkpad_acpi_driver_data
,
5685 .init
= hotkey_init
,
5686 .data
= &hotkey_driver_data
,
5689 .init
= bluetooth_init
,
5690 .data
= &bluetooth_driver_data
,
5694 .data
= &wan_driver_data
,
5698 .data
= &video_driver_data
,
5702 .data
= &light_driver_data
,
5704 #ifdef CONFIG_THINKPAD_ACPI_DOCK
5707 .data
= &dock_driver_data
[0],
5711 .data
= &dock_driver_data
[1],
5714 #ifdef CONFIG_THINKPAD_ACPI_BAY
5717 .data
= &bay_driver_data
,
5722 .data
= &cmos_driver_data
,
5726 .data
= &led_driver_data
,
5730 .data
= &beep_driver_data
,
5733 .init
= thermal_init
,
5734 .data
= &thermal_driver_data
,
5737 .data
= &ecdump_driver_data
,
5740 .init
= brightness_init
,
5741 .data
= &brightness_driver_data
,
5744 .data
= &volume_driver_data
,
5748 .data
= &fan_driver_data
,
5752 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
5755 struct ibm_struct
*ibm
;
5757 if (!kp
|| !kp
->name
|| !val
)
5760 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
5761 ibm
= ibms_init
[i
].data
;
5762 WARN_ON(ibm
== NULL
);
5764 if (!ibm
|| !ibm
->name
)
5767 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
5768 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
5770 strcpy(ibms_init
[i
].param
, val
);
5771 strcat(ibms_init
[i
].param
, ",");
5779 module_param(experimental
, int, 0);
5780 MODULE_PARM_DESC(experimental
,
5781 "Enables experimental features when non-zero");
5783 module_param_named(debug
, dbg_level
, uint
, 0);
5784 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
5786 module_param(force_load
, bool, 0);
5787 MODULE_PARM_DESC(force_load
,
5788 "Attempts to load the driver even on a "
5789 "mis-identified ThinkPad when true");
5791 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
5792 MODULE_PARM_DESC(fan_control
,
5793 "Enables setting fan parameters features when true");
5795 module_param_named(brightness_mode
, brightness_mode
, int, 0);
5796 MODULE_PARM_DESC(brightness_mode
,
5797 "Selects brightness control strategy: "
5798 "0=auto, 1=EC, 2=CMOS, 3=both");
5800 module_param(brightness_enable
, uint
, 0);
5801 MODULE_PARM_DESC(brightness_enable
,
5802 "Enables backlight control when 1, disables when 0");
5804 module_param(hotkey_report_mode
, uint
, 0);
5805 MODULE_PARM_DESC(hotkey_report_mode
,
5806 "used for backwards compatibility with userspace, "
5807 "see documentation");
5809 #define TPACPI_PARAM(feature) \
5810 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
5811 MODULE_PARM_DESC(feature, "Simulates thinkpad-aci procfs command " \
5812 "at module load, see documentation")
5814 TPACPI_PARAM(hotkey
);
5815 TPACPI_PARAM(bluetooth
);
5816 TPACPI_PARAM(video
);
5817 TPACPI_PARAM(light
);
5818 #ifdef CONFIG_THINKPAD_ACPI_DOCK
5821 #ifdef CONFIG_THINKPAD_ACPI_BAY
5823 #endif /* CONFIG_THINKPAD_ACPI_BAY */
5827 TPACPI_PARAM(ecdump
);
5828 TPACPI_PARAM(brightness
);
5829 TPACPI_PARAM(volume
);
5832 static void thinkpad_acpi_module_exit(void)
5834 struct ibm_struct
*ibm
, *itmp
;
5836 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
5838 list_for_each_entry_safe_reverse(ibm
, itmp
,
5839 &tpacpi_all_drivers
,
5844 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
5846 if (tpacpi_inputdev
) {
5847 if (tp_features
.input_device_registered
)
5848 input_unregister_device(tpacpi_inputdev
);
5850 input_free_device(tpacpi_inputdev
);
5854 hwmon_device_unregister(tpacpi_hwmon
);
5856 if (tp_features
.sensors_pdev_attrs_registered
)
5857 device_remove_file(&tpacpi_sensors_pdev
->dev
,
5858 &dev_attr_thinkpad_acpi_pdev_name
);
5859 if (tpacpi_sensors_pdev
)
5860 platform_device_unregister(tpacpi_sensors_pdev
);
5862 platform_device_unregister(tpacpi_pdev
);
5864 if (tp_features
.sensors_pdrv_attrs_registered
)
5865 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
5866 if (tp_features
.platform_drv_attrs_registered
)
5867 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
5869 if (tp_features
.sensors_pdrv_registered
)
5870 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
5872 if (tp_features
.platform_drv_registered
)
5873 platform_driver_unregister(&tpacpi_pdriver
);
5876 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
5878 kfree(thinkpad_id
.bios_version_str
);
5879 kfree(thinkpad_id
.ec_version_str
);
5880 kfree(thinkpad_id
.model_str
);
5884 static int __init
thinkpad_acpi_module_init(void)
5888 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
5890 /* Parameter checking */
5891 if (hotkey_report_mode
> 2)
5894 /* Driver-level probe */
5896 get_thinkpad_model_data(&thinkpad_id
);
5897 ret
= probe_for_thinkpad();
5899 thinkpad_acpi_module_exit();
5903 /* Driver initialization */
5905 TPACPI_ACPIHANDLE_INIT(ecrd
);
5906 TPACPI_ACPIHANDLE_INIT(ecwr
);
5908 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
5911 "unable to create proc dir " TPACPI_PROC_DIR
);
5912 thinkpad_acpi_module_exit();
5915 proc_dir
->owner
= THIS_MODULE
;
5917 ret
= platform_driver_register(&tpacpi_pdriver
);
5920 "unable to register main platform driver\n");
5921 thinkpad_acpi_module_exit();
5924 tp_features
.platform_drv_registered
= 1;
5926 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
5929 "unable to register hwmon platform driver\n");
5930 thinkpad_acpi_module_exit();
5933 tp_features
.sensors_pdrv_registered
= 1;
5935 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
5937 tp_features
.platform_drv_attrs_registered
= 1;
5938 ret
= tpacpi_create_driver_attributes(
5939 &tpacpi_hwmon_pdriver
.driver
);
5943 "unable to create sysfs driver attributes\n");
5944 thinkpad_acpi_module_exit();
5947 tp_features
.sensors_pdrv_attrs_registered
= 1;
5950 /* Device initialization */
5951 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
5953 if (IS_ERR(tpacpi_pdev
)) {
5954 ret
= PTR_ERR(tpacpi_pdev
);
5956 printk(TPACPI_ERR
"unable to register platform device\n");
5957 thinkpad_acpi_module_exit();
5960 tpacpi_sensors_pdev
= platform_device_register_simple(
5961 TPACPI_HWMON_DRVR_NAME
,
5963 if (IS_ERR(tpacpi_sensors_pdev
)) {
5964 ret
= PTR_ERR(tpacpi_sensors_pdev
);
5965 tpacpi_sensors_pdev
= NULL
;
5967 "unable to register hwmon platform device\n");
5968 thinkpad_acpi_module_exit();
5971 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
5972 &dev_attr_thinkpad_acpi_pdev_name
);
5975 "unable to create sysfs hwmon device attributes\n");
5976 thinkpad_acpi_module_exit();
5979 tp_features
.sensors_pdev_attrs_registered
= 1;
5980 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
5981 if (IS_ERR(tpacpi_hwmon
)) {
5982 ret
= PTR_ERR(tpacpi_hwmon
);
5983 tpacpi_hwmon
= NULL
;
5984 printk(TPACPI_ERR
"unable to register hwmon device\n");
5985 thinkpad_acpi_module_exit();
5988 mutex_init(&tpacpi_inputdev_send_mutex
);
5989 tpacpi_inputdev
= input_allocate_device();
5990 if (!tpacpi_inputdev
) {
5991 printk(TPACPI_ERR
"unable to allocate input device\n");
5992 thinkpad_acpi_module_exit();
5995 /* Prepare input device, but don't register */
5996 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
5997 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
5998 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
5999 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
6000 thinkpad_id
.vendor
:
6002 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
6003 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
6005 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
6006 ret
= ibm_init(&ibms_init
[i
]);
6007 if (ret
>= 0 && *ibms_init
[i
].param
)
6008 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
6010 thinkpad_acpi_module_exit();
6014 ret
= input_register_device(tpacpi_inputdev
);
6016 printk(TPACPI_ERR
"unable to register input device\n");
6017 thinkpad_acpi_module_exit();
6020 tp_features
.input_device_registered
= 1;
6023 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
6027 /* Please remove this in year 2009 */
6028 MODULE_ALIAS("ibm_acpi");
6031 * DMI matching for module autoloading
6033 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
6034 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
6036 * Only models listed in thinkwiki will be supported, so add yours
6037 * if it is not there yet.
6039 #define IBM_BIOS_MODULE_ALIAS(__type) \
6040 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
6042 /* Non-ancient thinkpads */
6043 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
6044 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
6046 /* Ancient thinkpad BIOSes have to be identified by
6047 * BIOS type or model number, and there are far less
6048 * BIOS types than model numbers... */
6049 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
6050 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
6051 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
6053 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
6054 MODULE_DESCRIPTION(TPACPI_DESC
);
6055 MODULE_VERSION(TPACPI_VERSION
);
6056 MODULE_LICENSE("GPL");
6058 module_init(thinkpad_acpi_module_init
);
6059 module_exit(thinkpad_acpi_module_exit
);