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 #if defined(CONFIG_THINKPAD_ACPI_DOCK) || defined(CONFIG_THINKPAD_ACPI_BAY)
418 static int _sta(acpi_handle handle
)
422 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
429 static int issue_thinkpad_cmos_command(int cmos_cmd
)
434 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
440 /*************************************************************************
444 #define TPACPI_ACPIHANDLE_INIT(object) \
445 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
446 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
448 static void drv_acpi_handle_init(char *name
,
449 acpi_handle
*handle
, acpi_handle parent
,
450 char **paths
, int num_paths
, char **path
)
455 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
458 for (i
= 0; i
< num_paths
; i
++) {
459 status
= acpi_get_handle(parent
, paths
[i
], handle
);
460 if (ACPI_SUCCESS(status
)) {
462 dbg_printk(TPACPI_DBG_INIT
,
463 "Found ACPI handle %s for %s\n",
469 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
474 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
476 struct ibm_struct
*ibm
= data
;
478 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
481 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
484 ibm
->acpi
->notify(ibm
, event
);
487 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
494 if (!*ibm
->acpi
->handle
)
497 vdbg_printk(TPACPI_DBG_INIT
,
498 "setting up ACPI notify for %s\n", ibm
->name
);
500 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
502 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
507 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
508 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
509 TPACPI_ACPI_EVENT_PREFIX
,
512 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
513 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
514 if (ACPI_FAILURE(status
)) {
515 if (status
== AE_ALREADY_EXISTS
) {
517 "another device driver is already "
518 "handling %s events\n", ibm
->name
);
521 "acpi_install_notify_handler(%s) failed: %d\n",
526 ibm
->flags
.acpi_notify_installed
= 1;
530 static int __init
tpacpi_device_add(struct acpi_device
*device
)
535 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
539 dbg_printk(TPACPI_DBG_INIT
,
540 "registering %s as an ACPI driver\n", ibm
->name
);
544 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
545 if (!ibm
->acpi
->driver
) {
546 printk(TPACPI_ERR
"kzalloc(ibm->driver) failed\n");
550 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
551 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
553 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
555 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
557 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
559 kfree(ibm
->acpi
->driver
);
560 ibm
->acpi
->driver
= NULL
;
562 ibm
->flags
.acpi_driver_registered
= 1;
568 /****************************************************************************
569 ****************************************************************************
573 ****************************************************************************
574 ****************************************************************************/
576 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
577 int count
, int *eof
, void *data
)
579 struct ibm_struct
*ibm
= data
;
582 if (!ibm
|| !ibm
->read
)
585 len
= ibm
->read(page
);
589 if (len
<= off
+ count
)
601 static int dispatch_procfs_write(struct file
*file
,
602 const char __user
*userbuf
,
603 unsigned long count
, void *data
)
605 struct ibm_struct
*ibm
= data
;
609 if (!ibm
|| !ibm
->write
)
612 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
616 if (copy_from_user(kernbuf
, userbuf
, count
)) {
622 strcat(kernbuf
, ",");
623 ret
= ibm
->write(kernbuf
);
632 static char *next_cmd(char **cmds
)
637 while ((end
= strchr(start
, ',')) && end
== start
)
649 /****************************************************************************
650 ****************************************************************************
652 * Device model: input, hwmon and platform
654 ****************************************************************************
655 ****************************************************************************/
657 static struct platform_device
*tpacpi_pdev
;
658 static struct platform_device
*tpacpi_sensors_pdev
;
659 static struct device
*tpacpi_hwmon
;
660 static struct input_dev
*tpacpi_inputdev
;
661 static struct mutex tpacpi_inputdev_send_mutex
;
662 static LIST_HEAD(tpacpi_all_drivers
);
664 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
667 struct ibm_struct
*ibm
, *itmp
;
669 list_for_each_entry_safe(ibm
, itmp
,
673 (ibm
->suspend
)(state
);
679 static int tpacpi_resume_handler(struct platform_device
*pdev
)
681 struct ibm_struct
*ibm
, *itmp
;
683 list_for_each_entry_safe(ibm
, itmp
,
693 static struct platform_driver tpacpi_pdriver
= {
695 .name
= TPACPI_DRVR_NAME
,
696 .owner
= THIS_MODULE
,
698 .suspend
= tpacpi_suspend_handler
,
699 .resume
= tpacpi_resume_handler
,
702 static struct platform_driver tpacpi_hwmon_pdriver
= {
704 .name
= TPACPI_HWMON_DRVR_NAME
,
705 .owner
= THIS_MODULE
,
709 /*************************************************************************
710 * sysfs support helpers
713 struct attribute_set
{
714 unsigned int members
, max_members
;
715 struct attribute_group group
;
718 struct attribute_set_obj
{
719 struct attribute_set s
;
721 } __attribute__((packed
));
723 static struct attribute_set
*create_attr_set(unsigned int max_members
,
726 struct attribute_set_obj
*sobj
;
728 if (max_members
== 0)
731 /* Allocates space for implicit NULL at the end too */
732 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
733 max_members
* sizeof(struct attribute
*),
737 sobj
->s
.max_members
= max_members
;
738 sobj
->s
.group
.attrs
= &sobj
->a
;
739 sobj
->s
.group
.name
= name
;
744 #define destroy_attr_set(_set) \
747 /* not multi-threaded safe, use it in a single thread per set */
748 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
753 if (s
->members
>= s
->max_members
)
756 s
->group
.attrs
[s
->members
] = attr
;
762 static int add_many_to_attr_set(struct attribute_set
*s
,
763 struct attribute
**attr
,
768 for (i
= 0; i
< count
; i
++) {
769 res
= add_to_attr_set(s
, attr
[i
]);
777 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
779 sysfs_remove_group(kobj
, &s
->group
);
783 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
784 sysfs_create_group(_kobj, &_attr_set->group)
786 static int parse_strtoul(const char *buf
,
787 unsigned long max
, unsigned long *value
)
791 while (*buf
&& isspace(*buf
))
793 *value
= simple_strtoul(buf
, &endp
, 0);
794 while (*endp
&& isspace(*endp
))
796 if (*endp
|| *value
> max
)
802 /*************************************************************************
803 * thinkpad-acpi driver attributes
806 /* interface_version --------------------------------------------------- */
807 static ssize_t
tpacpi_driver_interface_version_show(
808 struct device_driver
*drv
,
811 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
814 static DRIVER_ATTR(interface_version
, S_IRUGO
,
815 tpacpi_driver_interface_version_show
, NULL
);
817 /* debug_level --------------------------------------------------------- */
818 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
821 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
824 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
825 const char *buf
, size_t count
)
829 if (parse_strtoul(buf
, 0xffff, &t
))
837 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
838 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
840 /* version ------------------------------------------------------------- */
841 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
844 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
845 TPACPI_DESC
, TPACPI_VERSION
);
848 static DRIVER_ATTR(version
, S_IRUGO
,
849 tpacpi_driver_version_show
, NULL
);
851 /* --------------------------------------------------------------------- */
853 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
854 &driver_attr_debug_level
, &driver_attr_version
,
855 &driver_attr_interface_version
,
858 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
864 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
865 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
872 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
876 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
877 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
880 /****************************************************************************
881 ****************************************************************************
885 ****************************************************************************
886 ****************************************************************************/
888 /*************************************************************************
889 * thinkpad-acpi init subdriver
892 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
894 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
895 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
897 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
898 (thinkpad_id
.bios_version_str
) ?
899 thinkpad_id
.bios_version_str
: "unknown",
900 (thinkpad_id
.ec_version_str
) ?
901 thinkpad_id
.ec_version_str
: "unknown");
903 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
904 printk(TPACPI_INFO
"%s %s\n",
905 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
906 "IBM" : ((thinkpad_id
.vendor
==
907 PCI_VENDOR_ID_LENOVO
) ?
908 "Lenovo" : "Unknown vendor"),
909 thinkpad_id
.model_str
);
914 static int thinkpad_acpi_driver_read(char *p
)
918 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
919 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
924 static struct ibm_struct thinkpad_acpi_driver_data
= {
926 .read
= thinkpad_acpi_driver_read
,
929 /*************************************************************************
933 enum { /* hot key scan codes (derived from ACPI DSDT) */
934 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
935 TP_ACPI_HOTKEYSCAN_FNF2
,
936 TP_ACPI_HOTKEYSCAN_FNF3
,
937 TP_ACPI_HOTKEYSCAN_FNF4
,
938 TP_ACPI_HOTKEYSCAN_FNF5
,
939 TP_ACPI_HOTKEYSCAN_FNF6
,
940 TP_ACPI_HOTKEYSCAN_FNF7
,
941 TP_ACPI_HOTKEYSCAN_FNF8
,
942 TP_ACPI_HOTKEYSCAN_FNF9
,
943 TP_ACPI_HOTKEYSCAN_FNF10
,
944 TP_ACPI_HOTKEYSCAN_FNF11
,
945 TP_ACPI_HOTKEYSCAN_FNF12
,
946 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
947 TP_ACPI_HOTKEYSCAN_FNINSERT
,
948 TP_ACPI_HOTKEYSCAN_FNDELETE
,
949 TP_ACPI_HOTKEYSCAN_FNHOME
,
950 TP_ACPI_HOTKEYSCAN_FNEND
,
951 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
952 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
953 TP_ACPI_HOTKEYSCAN_FNSPACE
,
954 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
955 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
956 TP_ACPI_HOTKEYSCAN_MUTE
,
957 TP_ACPI_HOTKEYSCAN_THINKPAD
,
960 enum { /* Keys available through NVRAM polling */
961 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
962 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
965 enum { /* Positions of some of the keys in hotkey masks */
966 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
967 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
968 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
969 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
970 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
971 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
972 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
973 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
974 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
975 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
976 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
979 enum { /* NVRAM to ACPI HKEY group map */
980 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
981 TP_ACPI_HKEY_ZOOM_MASK
|
982 TP_ACPI_HKEY_DISPSWTCH_MASK
|
983 TP_ACPI_HKEY_HIBERNATE_MASK
,
984 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
985 TP_ACPI_HKEY_BRGHTDWN_MASK
,
986 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
987 TP_ACPI_HKEY_VOLDWN_MASK
|
988 TP_ACPI_HKEY_MUTE_MASK
,
991 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
992 struct tp_nvram_state
{
993 u16 thinkpad_toggle
:1;
995 u16 display_toggle
:1;
996 u16 thinklight_toggle
:1;
997 u16 hibernate_toggle
:1;
998 u16 displayexp_toggle
:1;
1000 u16 brightness_toggle
:1;
1001 u16 volume_toggle
:1;
1004 u8 brightness_level
;
1008 static struct task_struct
*tpacpi_hotkey_task
;
1009 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1010 static int hotkey_poll_freq
= 10; /* Hz */
1011 static struct mutex hotkey_thread_mutex
;
1012 static struct mutex hotkey_thread_data_mutex
;
1013 static unsigned int hotkey_config_change
;
1015 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1017 #define hotkey_source_mask 0U
1019 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1021 static struct mutex hotkey_mutex
;
1023 static enum { /* Reasons for waking up */
1024 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1025 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1026 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1027 } hotkey_wakeup_reason
;
1029 static int hotkey_autosleep_ack
;
1031 static int hotkey_orig_status
;
1032 static u32 hotkey_orig_mask
;
1033 static u32 hotkey_all_mask
;
1034 static u32 hotkey_reserved_mask
;
1035 static u32 hotkey_mask
;
1037 static unsigned int hotkey_report_mode
;
1039 static u16
*hotkey_keycode_map
;
1041 static struct attribute_set
*hotkey_dev_attributes
;
1043 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1044 #define HOTKEY_CONFIG_CRITICAL_START \
1046 mutex_lock(&hotkey_thread_data_mutex); \
1047 hotkey_config_change++; \
1049 #define HOTKEY_CONFIG_CRITICAL_END \
1050 mutex_unlock(&hotkey_thread_data_mutex);
1052 #define HOTKEY_CONFIG_CRITICAL_START
1053 #define HOTKEY_CONFIG_CRITICAL_END
1054 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1056 static int hotkey_get_wlsw(int *status
)
1058 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1064 * Call with hotkey_mutex held
1066 static int hotkey_mask_get(void)
1070 if (tp_features
.hotkey_mask
) {
1071 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1074 hotkey_mask
= m
| (hotkey_source_mask
& hotkey_mask
);
1080 * Call with hotkey_mutex held
1082 static int hotkey_mask_set(u32 mask
)
1087 if (tp_features
.hotkey_mask
) {
1088 HOTKEY_CONFIG_CRITICAL_START
1089 for (i
= 0; i
< 32; i
++) {
1091 /* enable in firmware mask only keys not in NVRAM
1092 * mode, but enable the key in the cached hotkey_mask
1093 * regardless of mode, or the key will end up
1094 * disabled by hotkey_mask_get() */
1095 if (!acpi_evalf(hkey_handle
,
1096 NULL
, "MHKM", "vdd", i
+ 1,
1097 !!((mask
& ~hotkey_source_mask
) & m
))) {
1101 hotkey_mask
= (hotkey_mask
& ~m
) | (mask
& m
);
1104 HOTKEY_CONFIG_CRITICAL_END
1106 /* hotkey_mask_get must be called unconditionally below */
1107 if (!hotkey_mask_get() && !rc
&&
1108 (hotkey_mask
& ~hotkey_source_mask
) !=
1109 (mask
& ~hotkey_source_mask
)) {
1110 printk(TPACPI_NOTICE
1111 "requested hot key mask 0x%08x, but "
1112 "firmware forced it to 0x%08x\n",
1116 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1117 HOTKEY_CONFIG_CRITICAL_START
1118 hotkey_mask
= mask
& hotkey_source_mask
;
1119 HOTKEY_CONFIG_CRITICAL_END
1121 if (hotkey_mask
!= mask
) {
1122 printk(TPACPI_NOTICE
1123 "requested hot key mask 0x%08x, "
1124 "forced to 0x%08x (NVRAM poll mask is "
1125 "0x%08x): no firmware mask support\n",
1126 mask
, hotkey_mask
, hotkey_source_mask
);
1131 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1137 static int hotkey_status_get(int *status
)
1139 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1145 static int hotkey_status_set(int status
)
1147 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1153 static void tpacpi_input_send_radiosw(void)
1157 mutex_lock(&tpacpi_inputdev_send_mutex
);
1159 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
1160 input_report_switch(tpacpi_inputdev
,
1162 input_sync(tpacpi_inputdev
);
1165 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1168 static void tpacpi_input_send_key(unsigned int scancode
)
1170 unsigned int keycode
;
1172 keycode
= hotkey_keycode_map
[scancode
];
1174 if (keycode
!= KEY_RESERVED
) {
1175 mutex_lock(&tpacpi_inputdev_send_mutex
);
1177 input_report_key(tpacpi_inputdev
, keycode
, 1);
1178 if (keycode
== KEY_UNKNOWN
)
1179 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1181 input_sync(tpacpi_inputdev
);
1183 input_report_key(tpacpi_inputdev
, keycode
, 0);
1184 if (keycode
== KEY_UNKNOWN
)
1185 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1187 input_sync(tpacpi_inputdev
);
1189 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1193 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1194 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
1196 static void tpacpi_hotkey_send_key(unsigned int scancode
)
1198 tpacpi_input_send_key(scancode
);
1199 if (hotkey_report_mode
< 2) {
1200 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
1201 0x80, 0x1001 + scancode
);
1205 static void hotkey_read_nvram(struct tp_nvram_state
*n
, u32 m
)
1209 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
1210 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
1211 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
1212 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
1213 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
1214 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
1216 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
1217 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
1218 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
1220 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
1221 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
1222 n
->displayexp_toggle
=
1223 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
1225 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
1226 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
1227 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
1228 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
1229 n
->brightness_toggle
=
1230 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
1232 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
1233 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
1234 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
1235 >> TP_NVRAM_POS_LEVEL_VOLUME
;
1236 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
1237 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
1241 #define TPACPI_COMPARE_KEY(__scancode, __member) \
1243 if ((mask & (1 << __scancode)) && \
1244 oldn->__member != newn->__member) \
1245 tpacpi_hotkey_send_key(__scancode); \
1248 #define TPACPI_MAY_SEND_KEY(__scancode) \
1249 do { if (mask & (1 << __scancode)) \
1250 tpacpi_hotkey_send_key(__scancode); } while (0)
1252 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
1253 struct tp_nvram_state
*newn
,
1256 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
1257 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
1258 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
1259 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
1261 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
1263 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
1266 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
1267 if (oldn
->mute
!= newn
->mute
) {
1268 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1270 if (oldn
->volume_level
> newn
->volume_level
) {
1271 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1272 } else if (oldn
->volume_level
< newn
->volume_level
) {
1273 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1274 } else if (oldn
->mute
== newn
->mute
) {
1275 /* repeated key presses that didn't change state */
1277 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1278 } else if (newn
->volume_level
!= 0) {
1279 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1281 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1286 /* handle brightness */
1287 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
1288 if (oldn
->brightness_level
< newn
->brightness_level
) {
1289 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1290 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
1291 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1293 /* repeated key presses that didn't change state */
1294 if (newn
->brightness_level
!= 0) {
1295 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1297 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1303 #undef TPACPI_COMPARE_KEY
1304 #undef TPACPI_MAY_SEND_KEY
1306 static int hotkey_kthread(void *data
)
1308 struct tp_nvram_state s
[2];
1310 unsigned int si
, so
;
1312 unsigned int change_detector
, must_reset
;
1314 mutex_lock(&hotkey_thread_mutex
);
1316 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
1325 /* Initial state for compares */
1326 mutex_lock(&hotkey_thread_data_mutex
);
1327 change_detector
= hotkey_config_change
;
1328 mask
= hotkey_source_mask
& hotkey_mask
;
1329 mutex_unlock(&hotkey_thread_data_mutex
);
1330 hotkey_read_nvram(&s
[so
], mask
);
1332 while (!kthread_should_stop() && hotkey_poll_freq
) {
1334 t
= 1000/hotkey_poll_freq
;
1335 t
= msleep_interruptible(t
);
1336 if (unlikely(kthread_should_stop()))
1338 must_reset
= try_to_freeze();
1339 if (t
> 0 && !must_reset
)
1342 mutex_lock(&hotkey_thread_data_mutex
);
1343 if (must_reset
|| hotkey_config_change
!= change_detector
) {
1344 /* forget old state on thaw or config change */
1347 change_detector
= hotkey_config_change
;
1349 mask
= hotkey_source_mask
& hotkey_mask
;
1350 mutex_unlock(&hotkey_thread_data_mutex
);
1353 hotkey_read_nvram(&s
[si
], mask
);
1354 if (likely(si
!= so
)) {
1355 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
1365 mutex_unlock(&hotkey_thread_mutex
);
1369 static void hotkey_poll_stop_sync(void)
1371 if (tpacpi_hotkey_task
) {
1372 if (frozen(tpacpi_hotkey_task
) ||
1373 freezing(tpacpi_hotkey_task
))
1374 thaw_process(tpacpi_hotkey_task
);
1376 kthread_stop(tpacpi_hotkey_task
);
1377 tpacpi_hotkey_task
= NULL
;
1378 mutex_lock(&hotkey_thread_mutex
);
1379 /* at this point, the thread did exit */
1380 mutex_unlock(&hotkey_thread_mutex
);
1384 /* call with hotkey_mutex held */
1385 static void hotkey_poll_setup(int may_warn
)
1387 if ((hotkey_source_mask
& hotkey_mask
) != 0 &&
1388 hotkey_poll_freq
> 0 &&
1389 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1390 if (!tpacpi_hotkey_task
) {
1391 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1394 if (IS_ERR(tpacpi_hotkey_task
)) {
1395 tpacpi_hotkey_task
= NULL
;
1397 "could not create kernel thread "
1398 "for hotkey polling\n");
1402 hotkey_poll_stop_sync();
1404 hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1405 printk(TPACPI_NOTICE
1406 "hot keys 0x%08x require polling, "
1407 "which is currently disabled\n",
1408 hotkey_source_mask
);
1413 static void hotkey_poll_setup_safe(int may_warn
)
1415 mutex_lock(&hotkey_mutex
);
1416 hotkey_poll_setup(may_warn
);
1417 mutex_unlock(&hotkey_mutex
);
1420 static int hotkey_inputdev_open(struct input_dev
*dev
)
1422 switch (tpacpi_lifecycle
) {
1423 case TPACPI_LIFE_INIT
:
1425 * hotkey_init will call hotkey_poll_setup_safe
1426 * at the appropriate moment
1429 case TPACPI_LIFE_EXITING
:
1431 case TPACPI_LIFE_RUNNING
:
1432 hotkey_poll_setup_safe(0);
1436 /* Should only happen if tpacpi_lifecycle is corrupt */
1441 static void hotkey_inputdev_close(struct input_dev
*dev
)
1443 /* disable hotkey polling when possible */
1444 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
)
1445 hotkey_poll_setup_safe(0);
1447 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1449 /* sysfs hotkey enable ------------------------------------------------- */
1450 static ssize_t
hotkey_enable_show(struct device
*dev
,
1451 struct device_attribute
*attr
,
1456 res
= hotkey_status_get(&status
);
1460 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1463 static ssize_t
hotkey_enable_store(struct device
*dev
,
1464 struct device_attribute
*attr
,
1465 const char *buf
, size_t count
)
1470 if (parse_strtoul(buf
, 1, &t
))
1473 res
= hotkey_status_set(t
);
1475 return (res
) ? res
: count
;
1478 static struct device_attribute dev_attr_hotkey_enable
=
1479 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
1480 hotkey_enable_show
, hotkey_enable_store
);
1482 /* sysfs hotkey mask --------------------------------------------------- */
1483 static ssize_t
hotkey_mask_show(struct device
*dev
,
1484 struct device_attribute
*attr
,
1489 if (mutex_lock_interruptible(&hotkey_mutex
))
1490 return -ERESTARTSYS
;
1491 res
= hotkey_mask_get();
1492 mutex_unlock(&hotkey_mutex
);
1495 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
1498 static ssize_t
hotkey_mask_store(struct device
*dev
,
1499 struct device_attribute
*attr
,
1500 const char *buf
, size_t count
)
1505 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
1508 if (mutex_lock_interruptible(&hotkey_mutex
))
1509 return -ERESTARTSYS
;
1511 res
= hotkey_mask_set(t
);
1513 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1514 hotkey_poll_setup(1);
1517 mutex_unlock(&hotkey_mutex
);
1519 return (res
) ? res
: count
;
1522 static struct device_attribute dev_attr_hotkey_mask
=
1523 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
1524 hotkey_mask_show
, hotkey_mask_store
);
1526 /* sysfs hotkey bios_enabled ------------------------------------------- */
1527 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
1528 struct device_attribute
*attr
,
1531 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
1534 static struct device_attribute dev_attr_hotkey_bios_enabled
=
1535 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
1537 /* sysfs hotkey bios_mask ---------------------------------------------- */
1538 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
1539 struct device_attribute
*attr
,
1542 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
1545 static struct device_attribute dev_attr_hotkey_bios_mask
=
1546 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
1548 /* sysfs hotkey all_mask ----------------------------------------------- */
1549 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
1550 struct device_attribute
*attr
,
1553 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1554 hotkey_all_mask
| hotkey_source_mask
);
1557 static struct device_attribute dev_attr_hotkey_all_mask
=
1558 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
1560 /* sysfs hotkey recommended_mask --------------------------------------- */
1561 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
1562 struct device_attribute
*attr
,
1565 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1566 (hotkey_all_mask
| hotkey_source_mask
)
1567 & ~hotkey_reserved_mask
);
1570 static struct device_attribute dev_attr_hotkey_recommended_mask
=
1571 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
1572 hotkey_recommended_mask_show
, NULL
);
1574 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1576 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
1577 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
1578 struct device_attribute
*attr
,
1581 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
1584 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
1585 struct device_attribute
*attr
,
1586 const char *buf
, size_t count
)
1590 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
1591 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
1594 if (mutex_lock_interruptible(&hotkey_mutex
))
1595 return -ERESTARTSYS
;
1597 HOTKEY_CONFIG_CRITICAL_START
1598 hotkey_source_mask
= t
;
1599 HOTKEY_CONFIG_CRITICAL_END
1601 hotkey_poll_setup(1);
1603 mutex_unlock(&hotkey_mutex
);
1608 static struct device_attribute dev_attr_hotkey_source_mask
=
1609 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
1610 hotkey_source_mask_show
, hotkey_source_mask_store
);
1612 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
1613 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
1614 struct device_attribute
*attr
,
1617 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
1620 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
1621 struct device_attribute
*attr
,
1622 const char *buf
, size_t count
)
1626 if (parse_strtoul(buf
, 25, &t
))
1629 if (mutex_lock_interruptible(&hotkey_mutex
))
1630 return -ERESTARTSYS
;
1632 hotkey_poll_freq
= t
;
1634 hotkey_poll_setup(1);
1635 mutex_unlock(&hotkey_mutex
);
1640 static struct device_attribute dev_attr_hotkey_poll_freq
=
1641 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
1642 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
1644 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1646 /* sysfs hotkey radio_sw ----------------------------------------------- */
1647 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
1648 struct device_attribute
*attr
,
1652 res
= hotkey_get_wlsw(&s
);
1656 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1659 static struct device_attribute dev_attr_hotkey_radio_sw
=
1660 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
1662 /* sysfs hotkey report_mode -------------------------------------------- */
1663 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
1664 struct device_attribute
*attr
,
1667 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1668 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
1671 static struct device_attribute dev_attr_hotkey_report_mode
=
1672 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
1674 /* sysfs wakeup reason ------------------------------------------------- */
1675 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
1676 struct device_attribute
*attr
,
1679 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
1682 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
1683 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
1685 /* sysfs wakeup hotunplug_complete ------------------------------------- */
1686 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
1687 struct device_attribute
*attr
,
1690 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
1693 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
1694 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
1695 hotkey_wakeup_hotunplug_complete_show
, NULL
);
1697 /* --------------------------------------------------------------------- */
1699 static struct attribute
*hotkey_attributes
[] __initdata
= {
1700 &dev_attr_hotkey_enable
.attr
,
1701 &dev_attr_hotkey_bios_enabled
.attr
,
1702 &dev_attr_hotkey_report_mode
.attr
,
1703 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1704 &dev_attr_hotkey_mask
.attr
,
1705 &dev_attr_hotkey_all_mask
.attr
,
1706 &dev_attr_hotkey_recommended_mask
.attr
,
1707 &dev_attr_hotkey_source_mask
.attr
,
1708 &dev_attr_hotkey_poll_freq
.attr
,
1712 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
1713 &dev_attr_hotkey_bios_mask
.attr
,
1714 #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1715 &dev_attr_hotkey_mask
.attr
,
1716 &dev_attr_hotkey_all_mask
.attr
,
1717 &dev_attr_hotkey_recommended_mask
.attr
,
1719 &dev_attr_hotkey_wakeup_reason
.attr
,
1720 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
1723 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
1725 /* Requirements for changing the default keymaps:
1727 * 1. Many of the keys are mapped to KEY_RESERVED for very
1728 * good reasons. Do not change them unless you have deep
1729 * knowledge on the IBM and Lenovo ThinkPad firmware for
1730 * the various ThinkPad models. The driver behaves
1731 * differently for KEY_RESERVED: such keys have their
1732 * hot key mask *unset* in mask_recommended, and also
1733 * in the initial hot key mask programmed into the
1734 * firmware at driver load time, which means the firm-
1735 * ware may react very differently if you change them to
1738 * 2. You must be subscribed to the linux-thinkpad and
1739 * ibm-acpi-devel mailing lists, and you should read the
1740 * list archives since 2007 if you want to change the
1741 * keymaps. This requirement exists so that you will
1742 * know the past history of problems with the thinkpad-
1743 * acpi driver keymaps, and also that you will be
1744 * listening to any bug reports;
1746 * 3. Do not send thinkpad-acpi specific patches directly to
1747 * for merging, *ever*. Send them to the linux-acpi
1748 * mailinglist for comments. Merging is to be done only
1749 * through acpi-test and the ACPI maintainer.
1751 * If the above is too much to ask, don't change the keymap.
1752 * Ask the thinkpad-acpi maintainer to do it, instead.
1754 static u16 ibm_keycode_map
[] __initdata
= {
1755 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1756 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
1757 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1758 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1760 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
1761 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1762 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1763 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1765 /* brightness: firmware always reacts to them, unless
1766 * X.org did some tricks in the radeon BIOS scratch
1767 * registers of *some* models */
1768 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1769 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1771 /* Thinklight: firmware always react to it */
1772 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1774 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1775 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1777 /* Volume: firmware always react to it and reprograms
1778 * the built-in *extra* mixer. Never map it to control
1779 * another mixer by default. */
1780 KEY_RESERVED
, /* 0x14: VOLUME UP */
1781 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1782 KEY_RESERVED
, /* 0x16: MUTE */
1784 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1786 /* (assignments unknown, please report if found) */
1787 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1788 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1790 static u16 lenovo_keycode_map
[] __initdata
= {
1791 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1792 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
1793 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1794 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1796 /* Scan codes 0x0C to 0x1F: Other ACPI HKEY hot keys */
1797 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1798 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1799 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1801 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1802 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1804 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1806 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1807 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1809 /* Volume: z60/z61, T60 (BIOS version?): firmware always
1810 * react to it and reprograms the built-in *extra* mixer.
1811 * Never map it to control another mixer by default.
1813 * T60?, T61, R60?, R61: firmware and EC tries to send
1814 * these over the regular keyboard, so these are no-ops,
1815 * but there are still weird bugs re. MUTE, so do not
1816 * change unless you get test reports from all Lenovo
1817 * models. May cause the BIOS to interfere with the
1820 KEY_RESERVED
, /* 0x14: VOLUME UP */
1821 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1822 KEY_RESERVED
, /* 0x16: MUTE */
1824 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1826 /* (assignments unknown, please report if found) */
1827 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1828 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1831 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
1832 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
1833 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
1839 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
1841 BUG_ON(!tpacpi_inputdev
);
1842 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
1843 tpacpi_inputdev
->close
!= NULL
);
1845 TPACPI_ACPIHANDLE_INIT(hkey
);
1846 mutex_init(&hotkey_mutex
);
1848 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1849 mutex_init(&hotkey_thread_mutex
);
1850 mutex_init(&hotkey_thread_data_mutex
);
1853 /* hotkey not supported on 570 */
1854 tp_features
.hotkey
= hkey_handle
!= NULL
;
1856 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
1857 str_supported(tp_features
.hotkey
));
1859 if (tp_features
.hotkey
) {
1860 hotkey_dev_attributes
= create_attr_set(12, NULL
);
1861 if (!hotkey_dev_attributes
)
1863 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1865 ARRAY_SIZE(hotkey_attributes
));
1869 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1870 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
1871 for HKEY interface version 0x100 */
1872 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
1873 if ((hkeyv
>> 8) != 1) {
1874 printk(TPACPI_ERR
"unknown version of the "
1875 "HKEY interface: 0x%x\n", hkeyv
);
1876 printk(TPACPI_ERR
"please report this to %s\n",
1880 * MHKV 0x100 in A31, R40, R40e,
1881 * T4x, X31, and later
1883 tp_features
.hotkey_mask
= 1;
1887 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
1888 str_supported(tp_features
.hotkey_mask
));
1890 if (tp_features
.hotkey_mask
) {
1891 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
1894 "missing MHKA handler, "
1895 "please report this to %s\n",
1897 /* FN+F12, FN+F4, FN+F3 */
1898 hotkey_all_mask
= 0x080cU
;
1902 /* hotkey_source_mask *must* be zero for
1903 * the first hotkey_mask_get */
1904 res
= hotkey_status_get(&hotkey_orig_status
);
1905 if (!res
&& tp_features
.hotkey_mask
) {
1906 res
= hotkey_mask_get();
1907 hotkey_orig_mask
= hotkey_mask
;
1909 res
= add_many_to_attr_set(
1910 hotkey_dev_attributes
,
1911 hotkey_mask_attributes
,
1912 ARRAY_SIZE(hotkey_mask_attributes
));
1916 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1917 if (tp_features
.hotkey_mask
) {
1918 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
1921 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
;
1924 vdbg_printk(TPACPI_DBG_INIT
,
1925 "hotkey source mask 0x%08x, polling freq %d\n",
1926 hotkey_source_mask
, hotkey_poll_freq
);
1929 /* Not all thinkpads have a hardware radio switch */
1930 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
1931 tp_features
.hotkey_wlsw
= 1;
1933 "radio switch found; radios are %s\n",
1934 enabled(status
, 0));
1935 res
= add_to_attr_set(hotkey_dev_attributes
,
1936 &dev_attr_hotkey_radio_sw
.attr
);
1940 res
= register_attr_set_with_sysfs(
1941 hotkey_dev_attributes
,
1942 &tpacpi_pdev
->dev
.kobj
);
1946 /* Set up key map */
1948 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
1950 if (!hotkey_keycode_map
) {
1952 "failed to allocate memory for key map\n");
1956 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
1957 dbg_printk(TPACPI_DBG_INIT
,
1958 "using Lenovo default hot key map\n");
1959 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
1960 TPACPI_HOTKEY_MAP_SIZE
);
1962 dbg_printk(TPACPI_DBG_INIT
,
1963 "using IBM default hot key map\n");
1964 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
1965 TPACPI_HOTKEY_MAP_SIZE
);
1968 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
1969 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
1970 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
1971 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
1972 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
1973 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
1974 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
1975 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
1976 set_bit(hotkey_keycode_map
[i
],
1977 tpacpi_inputdev
->keybit
);
1979 if (i
< sizeof(hotkey_reserved_mask
)*8)
1980 hotkey_reserved_mask
|= 1 << i
;
1984 if (tp_features
.hotkey_wlsw
) {
1985 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
1986 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
1989 dbg_printk(TPACPI_DBG_INIT
,
1990 "enabling hot key handling\n");
1991 res
= hotkey_status_set(1);
1994 res
= hotkey_mask_set(((hotkey_all_mask
| hotkey_source_mask
)
1995 & ~hotkey_reserved_mask
)
1996 | hotkey_orig_mask
);
1997 if (res
< 0 && res
!= -ENXIO
)
2000 dbg_printk(TPACPI_DBG_INIT
,
2001 "legacy hot key reporting over procfs %s\n",
2002 (hotkey_report_mode
< 2) ?
2003 "enabled" : "disabled");
2005 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2006 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
2007 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
2009 hotkey_poll_setup_safe(1);
2013 return (tp_features
.hotkey
)? 0 : 1;
2016 static void hotkey_exit(void)
2018 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2019 hotkey_poll_stop_sync();
2022 if (tp_features
.hotkey
) {
2023 dbg_printk(TPACPI_DBG_EXIT
,
2024 "restoring original hot key mask\n");
2025 /* no short-circuit boolean operator below! */
2026 if ((hotkey_mask_set(hotkey_orig_mask
) |
2027 hotkey_status_set(hotkey_orig_status
)) != 0)
2029 "failed to restore hot key mask "
2030 "to BIOS defaults\n");
2033 if (hotkey_dev_attributes
) {
2034 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
2035 hotkey_dev_attributes
= NULL
;
2039 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
2042 unsigned int scancode
;
2047 if (event
!= 0x80) {
2049 "unknown HKEY notification event %d\n", event
);
2050 /* forward it to userspace, maybe it knows how to handle it */
2051 acpi_bus_generate_netlink_event(
2052 ibm
->acpi
->device
->pnp
.device_class
,
2053 ibm
->acpi
->device
->dev
.bus_id
,
2059 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
2060 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
2073 switch (hkey
>> 12) {
2075 /* 0x1000-0x1FFF: key presses */
2076 scancode
= hkey
& 0xfff;
2077 if (scancode
> 0 && scancode
< 0x21) {
2079 if (!(hotkey_source_mask
& (1 << scancode
))) {
2080 tpacpi_input_send_key(scancode
);
2092 case 0x2304: /* suspend, undock */
2093 case 0x2404: /* hibernation, undock */
2094 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
2097 case 0x2305: /* suspend, bay eject */
2098 case 0x2405: /* hibernation, bay eject */
2099 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
2105 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
2107 "woke up due to a hot-unplug "
2112 /* bay-related wakeups */
2113 if (hkey
== 0x3003) {
2114 hotkey_autosleep_ack
= 1;
2122 /* dock-related wakeups */
2123 if (hkey
== 0x4003) {
2124 hotkey_autosleep_ack
= 1;
2132 /* 0x5000-0x5FFF: human interface helpers */
2134 case 0x5010: /* Lenovo new BIOS: brightness changed */
2135 case 0x5009: /* X61t: swivel up (tablet mode) */
2136 case 0x500a: /* X61t: swivel down (normal mode) */
2137 case 0x500b: /* X61t: tablet pen inserted into bay */
2138 case 0x500c: /* X61t: tablet pen removed from bay */
2142 /* LID switch events. Do not propagate */
2150 /* 0x7000-0x7FFF: misc */
2151 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
2152 tpacpi_input_send_radiosw();
2156 /* fallthrough to default */
2161 printk(TPACPI_NOTICE
2162 "unhandled HKEY event 0x%04x\n", hkey
);
2166 if (!ignore_acpi_ev
&&
2167 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
2168 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
2172 /* netlink events */
2173 if (!ignore_acpi_ev
&& send_acpi_ev
) {
2174 acpi_bus_generate_netlink_event(
2175 ibm
->acpi
->device
->pnp
.device_class
,
2176 ibm
->acpi
->device
->dev
.bus_id
,
2182 static void hotkey_suspend(pm_message_t state
)
2184 /* Do these on suspend, we get the events on early resume! */
2185 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
2186 hotkey_autosleep_ack
= 0;
2189 static void hotkey_resume(void)
2191 if (hotkey_mask_get())
2193 "error while trying to read hot key mask "
2195 tpacpi_input_send_radiosw();
2196 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2197 hotkey_poll_setup_safe(0);
2201 /* procfs -------------------------------------------------------------- */
2202 static int hotkey_read(char *p
)
2207 if (!tp_features
.hotkey
) {
2208 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2212 if (mutex_lock_interruptible(&hotkey_mutex
))
2213 return -ERESTARTSYS
;
2214 res
= hotkey_status_get(&status
);
2216 res
= hotkey_mask_get();
2217 mutex_unlock(&hotkey_mutex
);
2221 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
2222 if (tp_features
.hotkey_mask
) {
2223 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
2224 len
+= sprintf(p
+ len
,
2225 "commands:\tenable, disable, reset, <mask>\n");
2227 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
2228 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
2234 static int hotkey_write(char *buf
)
2240 if (!tp_features
.hotkey
)
2243 if (mutex_lock_interruptible(&hotkey_mutex
))
2244 return -ERESTARTSYS
;
2250 while ((cmd
= next_cmd(&buf
))) {
2251 if (strlencmp(cmd
, "enable") == 0) {
2253 } else if (strlencmp(cmd
, "disable") == 0) {
2255 } else if (strlencmp(cmd
, "reset") == 0) {
2256 status
= hotkey_orig_status
;
2257 mask
= hotkey_orig_mask
;
2258 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
2260 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
2268 res
= hotkey_status_set(status
);
2270 if (!res
&& mask
!= hotkey_mask
)
2271 res
= hotkey_mask_set(mask
);
2274 mutex_unlock(&hotkey_mutex
);
2278 static const struct acpi_device_id ibm_htk_device_ids
[] = {
2279 {TPACPI_ACPI_HKEY_HID
, 0},
2283 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
2284 .hid
= ibm_htk_device_ids
,
2285 .notify
= hotkey_notify
,
2286 .handle
= &hkey_handle
,
2287 .type
= ACPI_DEVICE_NOTIFY
,
2290 static struct ibm_struct hotkey_driver_data
= {
2292 .read
= hotkey_read
,
2293 .write
= hotkey_write
,
2294 .exit
= hotkey_exit
,
2295 .resume
= hotkey_resume
,
2296 .suspend
= hotkey_suspend
,
2297 .acpi
= &ibm_hotkey_acpidriver
,
2300 /*************************************************************************
2301 * Bluetooth subdriver
2305 /* ACPI GBDC/SBDC bits */
2306 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
2307 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
2308 TP_ACPI_BLUETOOTH_UNK
= 0x04, /* unknown function */
2311 static int bluetooth_get_radiosw(void);
2312 static int bluetooth_set_radiosw(int radio_on
);
2314 /* sysfs bluetooth enable ---------------------------------------------- */
2315 static ssize_t
bluetooth_enable_show(struct device
*dev
,
2316 struct device_attribute
*attr
,
2321 status
= bluetooth_get_radiosw();
2325 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
2328 static ssize_t
bluetooth_enable_store(struct device
*dev
,
2329 struct device_attribute
*attr
,
2330 const char *buf
, size_t count
)
2335 if (parse_strtoul(buf
, 1, &t
))
2338 res
= bluetooth_set_radiosw(t
);
2340 return (res
) ? res
: count
;
2343 static struct device_attribute dev_attr_bluetooth_enable
=
2344 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
2345 bluetooth_enable_show
, bluetooth_enable_store
);
2347 /* --------------------------------------------------------------------- */
2349 static struct attribute
*bluetooth_attributes
[] = {
2350 &dev_attr_bluetooth_enable
.attr
,
2354 static const struct attribute_group bluetooth_attr_group
= {
2355 .attrs
= bluetooth_attributes
,
2358 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
2363 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
2365 TPACPI_ACPIHANDLE_INIT(hkey
);
2367 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2368 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
2369 tp_features
.bluetooth
= hkey_handle
&&
2370 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
2372 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
2373 str_supported(tp_features
.bluetooth
),
2376 if (tp_features
.bluetooth
) {
2377 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
2378 /* no bluetooth hardware present in system */
2379 tp_features
.bluetooth
= 0;
2380 dbg_printk(TPACPI_DBG_INIT
,
2381 "bluetooth hardware not installed\n");
2383 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2384 &bluetooth_attr_group
);
2390 return (tp_features
.bluetooth
)? 0 : 1;
2393 static void bluetooth_exit(void)
2395 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2396 &bluetooth_attr_group
);
2399 static int bluetooth_get_radiosw(void)
2403 if (!tp_features
.bluetooth
)
2406 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2409 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
2412 static int bluetooth_set_radiosw(int radio_on
)
2416 if (!tp_features
.bluetooth
)
2419 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2422 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
2424 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
2425 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
2431 /* procfs -------------------------------------------------------------- */
2432 static int bluetooth_read(char *p
)
2435 int status
= bluetooth_get_radiosw();
2437 if (!tp_features
.bluetooth
)
2438 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2440 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2441 (status
)? "enabled" : "disabled");
2442 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2448 static int bluetooth_write(char *buf
)
2452 if (!tp_features
.bluetooth
)
2455 while ((cmd
= next_cmd(&buf
))) {
2456 if (strlencmp(cmd
, "enable") == 0) {
2457 bluetooth_set_radiosw(1);
2458 } else if (strlencmp(cmd
, "disable") == 0) {
2459 bluetooth_set_radiosw(0);
2467 static struct ibm_struct bluetooth_driver_data
= {
2468 .name
= "bluetooth",
2469 .read
= bluetooth_read
,
2470 .write
= bluetooth_write
,
2471 .exit
= bluetooth_exit
,
2474 /*************************************************************************
2479 /* ACPI GWAN/SWAN bits */
2480 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
2481 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
2482 TP_ACPI_WANCARD_UNK
= 0x04, /* unknown function */
2485 static int wan_get_radiosw(void);
2486 static int wan_set_radiosw(int radio_on
);
2488 /* sysfs wan enable ---------------------------------------------------- */
2489 static ssize_t
wan_enable_show(struct device
*dev
,
2490 struct device_attribute
*attr
,
2495 status
= wan_get_radiosw();
2499 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
2502 static ssize_t
wan_enable_store(struct device
*dev
,
2503 struct device_attribute
*attr
,
2504 const char *buf
, size_t count
)
2509 if (parse_strtoul(buf
, 1, &t
))
2512 res
= wan_set_radiosw(t
);
2514 return (res
) ? res
: count
;
2517 static struct device_attribute dev_attr_wan_enable
=
2518 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
2519 wan_enable_show
, wan_enable_store
);
2521 /* --------------------------------------------------------------------- */
2523 static struct attribute
*wan_attributes
[] = {
2524 &dev_attr_wan_enable
.attr
,
2528 static const struct attribute_group wan_attr_group
= {
2529 .attrs
= wan_attributes
,
2532 static int __init
wan_init(struct ibm_init_struct
*iibm
)
2537 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
2539 TPACPI_ACPIHANDLE_INIT(hkey
);
2541 tp_features
.wan
= hkey_handle
&&
2542 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
2544 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
2545 str_supported(tp_features
.wan
),
2548 if (tp_features
.wan
) {
2549 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
2550 /* no wan hardware present in system */
2551 tp_features
.wan
= 0;
2552 dbg_printk(TPACPI_DBG_INIT
,
2553 "wan hardware not installed\n");
2555 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2562 return (tp_features
.wan
)? 0 : 1;
2565 static void wan_exit(void)
2567 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2571 static int wan_get_radiosw(void)
2575 if (!tp_features
.wan
)
2578 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2581 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
2584 static int wan_set_radiosw(int radio_on
)
2588 if (!tp_features
.wan
)
2591 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2594 status
|= TP_ACPI_WANCARD_RADIOSSW
;
2596 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
2597 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
2603 /* procfs -------------------------------------------------------------- */
2604 static int wan_read(char *p
)
2607 int status
= wan_get_radiosw();
2609 if (!tp_features
.wan
)
2610 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2612 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2613 (status
)? "enabled" : "disabled");
2614 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2620 static int wan_write(char *buf
)
2624 if (!tp_features
.wan
)
2627 while ((cmd
= next_cmd(&buf
))) {
2628 if (strlencmp(cmd
, "enable") == 0) {
2630 } else if (strlencmp(cmd
, "disable") == 0) {
2639 static struct ibm_struct wan_driver_data
= {
2644 .flags
.experimental
= 1,
2647 /*************************************************************************
2651 enum video_access_mode
{
2652 TPACPI_VIDEO_NONE
= 0,
2653 TPACPI_VIDEO_570
, /* 570 */
2654 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
2655 TPACPI_VIDEO_NEW
, /* all others */
2658 enum { /* video status flags, based on VIDEO_570 */
2659 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
2660 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
2661 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
2664 enum { /* TPACPI_VIDEO_570 constants */
2665 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
2666 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
2667 * video_status_flags */
2668 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
2669 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
2672 static enum video_access_mode video_supported
;
2673 static int video_orig_autosw
;
2675 static int video_autosw_get(void);
2676 static int video_autosw_set(int enable
);
2678 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
2679 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
2680 "\\_SB.PCI0.VID0", /* 770e */
2681 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
2682 "\\_SB.PCI0.AGP.VID", /* all others */
2685 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
2687 static int __init
video_init(struct ibm_init_struct
*iibm
)
2691 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
2693 TPACPI_ACPIHANDLE_INIT(vid
);
2694 TPACPI_ACPIHANDLE_INIT(vid2
);
2696 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
2697 /* G41, assume IVGA doesn't change */
2698 vid_handle
= vid2_handle
;
2701 /* video switching not supported on R30, R31 */
2702 video_supported
= TPACPI_VIDEO_NONE
;
2703 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
2705 video_supported
= TPACPI_VIDEO_570
;
2706 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
2707 /* 600e/x, 770e, 770x */
2708 video_supported
= TPACPI_VIDEO_770
;
2711 video_supported
= TPACPI_VIDEO_NEW
;
2713 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
2714 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
2717 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
2720 static void video_exit(void)
2722 dbg_printk(TPACPI_DBG_EXIT
,
2723 "restoring original video autoswitch mode\n");
2724 if (video_autosw_set(video_orig_autosw
))
2725 printk(TPACPI_ERR
"error while trying to restore original "
2726 "video autoswitch mode\n");
2729 static int video_outputsw_get(void)
2734 switch (video_supported
) {
2735 case TPACPI_VIDEO_570
:
2736 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
2737 TP_ACPI_VIDEO_570_PHSCMD
))
2739 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
2741 case TPACPI_VIDEO_770
:
2742 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2745 status
|= TP_ACPI_VIDEO_S_LCD
;
2746 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2749 status
|= TP_ACPI_VIDEO_S_CRT
;
2751 case TPACPI_VIDEO_NEW
:
2752 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
2753 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2756 status
|= TP_ACPI_VIDEO_S_CRT
;
2758 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
2759 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2762 status
|= TP_ACPI_VIDEO_S_LCD
;
2763 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
2766 status
|= TP_ACPI_VIDEO_S_DVI
;
2775 static int video_outputsw_set(int status
)
2780 switch (video_supported
) {
2781 case TPACPI_VIDEO_570
:
2782 res
= acpi_evalf(NULL
, NULL
,
2783 "\\_SB.PHS2", "vdd",
2784 TP_ACPI_VIDEO_570_PHS2CMD
,
2785 status
| TP_ACPI_VIDEO_570_PHS2SET
);
2787 case TPACPI_VIDEO_770
:
2788 autosw
= video_autosw_get();
2792 res
= video_autosw_set(1);
2795 res
= acpi_evalf(vid_handle
, NULL
,
2796 "ASWT", "vdd", status
* 0x100, 0);
2797 if (!autosw
&& video_autosw_set(autosw
)) {
2799 "video auto-switch left enabled due to error\n");
2803 case TPACPI_VIDEO_NEW
:
2804 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
2805 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
2811 return (res
)? 0 : -EIO
;
2814 static int video_autosw_get(void)
2818 switch (video_supported
) {
2819 case TPACPI_VIDEO_570
:
2820 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
2823 case TPACPI_VIDEO_770
:
2824 case TPACPI_VIDEO_NEW
:
2825 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
2835 static int video_autosw_set(int enable
)
2837 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
2842 static int video_outputsw_cycle(void)
2844 int autosw
= video_autosw_get();
2850 switch (video_supported
) {
2851 case TPACPI_VIDEO_570
:
2852 res
= video_autosw_set(1);
2855 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
2857 case TPACPI_VIDEO_770
:
2858 case TPACPI_VIDEO_NEW
:
2859 res
= video_autosw_set(1);
2862 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
2867 if (!autosw
&& video_autosw_set(autosw
)) {
2869 "video auto-switch left enabled due to error\n");
2873 return (res
)? 0 : -EIO
;
2876 static int video_expand_toggle(void)
2878 switch (video_supported
) {
2879 case TPACPI_VIDEO_570
:
2880 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
2882 case TPACPI_VIDEO_770
:
2883 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
2885 case TPACPI_VIDEO_NEW
:
2886 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
2894 static int video_read(char *p
)
2899 if (video_supported
== TPACPI_VIDEO_NONE
) {
2900 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2904 status
= video_outputsw_get();
2908 autosw
= video_autosw_get();
2912 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2913 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
2914 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
2915 if (video_supported
== TPACPI_VIDEO_NEW
)
2916 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
2917 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
2918 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
2919 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
2920 if (video_supported
== TPACPI_VIDEO_NEW
)
2921 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
2922 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
2923 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
2928 static int video_write(char *buf
)
2931 int enable
, disable
, status
;
2934 if (video_supported
== TPACPI_VIDEO_NONE
)
2940 while ((cmd
= next_cmd(&buf
))) {
2941 if (strlencmp(cmd
, "lcd_enable") == 0) {
2942 enable
|= TP_ACPI_VIDEO_S_LCD
;
2943 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
2944 disable
|= TP_ACPI_VIDEO_S_LCD
;
2945 } else if (strlencmp(cmd
, "crt_enable") == 0) {
2946 enable
|= TP_ACPI_VIDEO_S_CRT
;
2947 } else if (strlencmp(cmd
, "crt_disable") == 0) {
2948 disable
|= TP_ACPI_VIDEO_S_CRT
;
2949 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2950 strlencmp(cmd
, "dvi_enable") == 0) {
2951 enable
|= TP_ACPI_VIDEO_S_DVI
;
2952 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2953 strlencmp(cmd
, "dvi_disable") == 0) {
2954 disable
|= TP_ACPI_VIDEO_S_DVI
;
2955 } else if (strlencmp(cmd
, "auto_enable") == 0) {
2956 res
= video_autosw_set(1);
2959 } else if (strlencmp(cmd
, "auto_disable") == 0) {
2960 res
= video_autosw_set(0);
2963 } else if (strlencmp(cmd
, "video_switch") == 0) {
2964 res
= video_outputsw_cycle();
2967 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
2968 res
= video_expand_toggle();
2975 if (enable
|| disable
) {
2976 status
= video_outputsw_get();
2979 res
= video_outputsw_set((status
& ~disable
) | enable
);
2987 static struct ibm_struct video_driver_data
= {
2990 .write
= video_write
,
2994 /*************************************************************************
2995 * Light (thinklight) subdriver
2998 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
2999 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
3001 static int __init
light_init(struct ibm_init_struct
*iibm
)
3003 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
3005 TPACPI_ACPIHANDLE_INIT(ledb
);
3006 TPACPI_ACPIHANDLE_INIT(lght
);
3007 TPACPI_ACPIHANDLE_INIT(cmos
);
3009 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
3010 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
3012 if (tp_features
.light
)
3013 /* light status not supported on
3014 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
3015 tp_features
.light_status
=
3016 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
3018 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
3019 str_supported(tp_features
.light
));
3021 return (tp_features
.light
)? 0 : 1;
3024 static int light_read(char *p
)
3029 if (!tp_features
.light
) {
3030 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3031 } else if (!tp_features
.light_status
) {
3032 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
3033 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
3035 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
3037 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
3038 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
3044 static int light_write(char *buf
)
3046 int cmos_cmd
, lght_cmd
;
3050 if (!tp_features
.light
)
3053 while ((cmd
= next_cmd(&buf
))) {
3054 if (strlencmp(cmd
, "on") == 0) {
3057 } else if (strlencmp(cmd
, "off") == 0) {
3063 success
= cmos_handle
?
3064 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
3065 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
3073 static struct ibm_struct light_driver_data
= {
3076 .write
= light_write
,
3079 /*************************************************************************
3083 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3085 static void dock_notify(struct ibm_struct
*ibm
, u32 event
);
3086 static int dock_read(char *p
);
3087 static int dock_write(char *buf
);
3089 TPACPI_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
3090 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
3091 "\\_SB.PCI0.PCI1.DOCK", /* all others */
3092 "\\_SB.PCI.ISA.SLCE", /* 570 */
3093 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
3095 /* don't list other alternatives as we install a notify handler on the 570 */
3096 TPACPI_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
3098 static const struct acpi_device_id ibm_pci_device_ids
[] = {
3099 {PCI_ROOT_HID_STRING
, 0},
3103 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
3105 .notify
= dock_notify
,
3106 .handle
= &dock_handle
,
3107 .type
= ACPI_SYSTEM_NOTIFY
,
3110 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
3111 * We just use it to get notifications of dock hotplug
3112 * in very old thinkpads */
3113 .hid
= ibm_pci_device_ids
,
3114 .notify
= dock_notify
,
3115 .handle
= &pci_handle
,
3116 .type
= ACPI_SYSTEM_NOTIFY
,
3120 static struct ibm_struct dock_driver_data
[2] = {
3124 .write
= dock_write
,
3125 .acpi
= &ibm_dock_acpidriver
[0],
3129 .acpi
= &ibm_dock_acpidriver
[1],
3133 #define dock_docked() (_sta(dock_handle) & 1)
3135 static int __init
dock_init(struct ibm_init_struct
*iibm
)
3137 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
3139 TPACPI_ACPIHANDLE_INIT(dock
);
3141 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
3142 str_supported(dock_handle
!= NULL
));
3144 return (dock_handle
)? 0 : 1;
3147 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
3151 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
3153 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
3154 dock_driver_data
[0].flags
.acpi_notify_installed
) {
3155 TPACPI_ACPIHANDLE_INIT(pci
);
3156 dock2_needed
= (pci_handle
!= NULL
);
3157 vdbg_printk(TPACPI_DBG_INIT
,
3158 "dock PCI handler for the TP 570 is %s\n",
3159 str_supported(dock2_needed
));
3161 vdbg_printk(TPACPI_DBG_INIT
,
3162 "dock subdriver part 2 not required\n");
3166 return (dock2_needed
)? 0 : 1;
3169 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
3171 int docked
= dock_docked();
3172 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
3173 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
3176 if (event
== 1 && !pci
) /* 570 */
3177 data
= 1; /* button */
3178 else if (event
== 1 && pci
) /* 570 */
3179 data
= 3; /* dock */
3180 else if (event
== 3 && docked
)
3181 data
= 1; /* button */
3182 else if (event
== 3 && !docked
)
3183 data
= 2; /* undock */
3184 else if (event
== 0 && docked
)
3185 data
= 3; /* dock */
3187 printk(TPACPI_ERR
"unknown dock event %d, status %d\n",
3188 event
, _sta(dock_handle
));
3189 data
= 0; /* unknown */
3191 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
3192 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3193 ibm
->acpi
->device
->dev
.bus_id
,
3197 static int dock_read(char *p
)
3200 int docked
= dock_docked();
3203 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3205 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
3207 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
3208 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
3214 static int dock_write(char *buf
)
3221 while ((cmd
= next_cmd(&buf
))) {
3222 if (strlencmp(cmd
, "undock") == 0) {
3223 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
3224 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
3226 } else if (strlencmp(cmd
, "dock") == 0) {
3227 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
3236 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
3238 /*************************************************************************
3242 #ifdef CONFIG_THINKPAD_ACPI_BAY
3244 TPACPI_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
3245 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
3246 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
3247 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
3248 ); /* A21e, R30, R31 */
3249 TPACPI_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
3250 "_EJ0", /* all others */
3251 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
3252 TPACPI_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
3253 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
3255 TPACPI_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
3259 static int __init
bay_init(struct ibm_init_struct
*iibm
)
3261 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
3263 TPACPI_ACPIHANDLE_INIT(bay
);
3265 TPACPI_ACPIHANDLE_INIT(bay_ej
);
3266 TPACPI_ACPIHANDLE_INIT(bay2
);
3268 TPACPI_ACPIHANDLE_INIT(bay2_ej
);
3270 tp_features
.bay_status
= bay_handle
&&
3271 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
3272 tp_features
.bay_status2
= bay2_handle
&&
3273 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
3275 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
3276 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
3277 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
3278 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
3280 vdbg_printk(TPACPI_DBG_INIT
,
3281 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
3282 str_supported(tp_features
.bay_status
),
3283 str_supported(tp_features
.bay_eject
),
3284 str_supported(tp_features
.bay_status2
),
3285 str_supported(tp_features
.bay_eject2
));
3287 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
3288 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
3291 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
3293 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
3294 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3295 ibm
->acpi
->device
->dev
.bus_id
,
3299 #define bay_occupied(b) (_sta(b##_handle) & 1)
3301 static int bay_read(char *p
)
3304 int occupied
= bay_occupied(bay
);
3305 int occupied2
= bay_occupied(bay2
);
3308 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3309 tp_features
.bay_status
?
3310 (occupied
? "occupied" : "unoccupied") :
3312 if (tp_features
.bay_status2
)
3313 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
3314 "occupied" : "unoccupied");
3316 eject
= tp_features
.bay_eject
&& occupied
;
3317 eject2
= tp_features
.bay_eject2
&& occupied2
;
3319 if (eject
&& eject2
)
3320 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
3322 len
+= sprintf(p
+ len
, "commands:\teject\n");
3324 len
+= sprintf(p
+ len
, "commands:\teject2\n");
3329 static int bay_write(char *buf
)
3333 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
3336 while ((cmd
= next_cmd(&buf
))) {
3337 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
3338 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
3340 } else if (tp_features
.bay_eject2
&&
3341 strlencmp(cmd
, "eject2") == 0) {
3342 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
3351 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
3352 .notify
= bay_notify
,
3353 .handle
= &bay_handle
,
3354 .type
= ACPI_SYSTEM_NOTIFY
,
3357 static struct ibm_struct bay_driver_data
= {
3361 .acpi
= &ibm_bay_acpidriver
,
3364 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3366 /*************************************************************************
3370 /* sysfs cmos_command -------------------------------------------------- */
3371 static ssize_t
cmos_command_store(struct device
*dev
,
3372 struct device_attribute
*attr
,
3373 const char *buf
, size_t count
)
3375 unsigned long cmos_cmd
;
3378 if (parse_strtoul(buf
, 21, &cmos_cmd
))
3381 res
= issue_thinkpad_cmos_command(cmos_cmd
);
3382 return (res
)? res
: count
;
3385 static struct device_attribute dev_attr_cmos_command
=
3386 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
3388 /* --------------------------------------------------------------------- */
3390 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
3394 vdbg_printk(TPACPI_DBG_INIT
,
3395 "initializing cmos commands subdriver\n");
3397 TPACPI_ACPIHANDLE_INIT(cmos
);
3399 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
3400 str_supported(cmos_handle
!= NULL
));
3402 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
3406 return (cmos_handle
)? 0 : 1;
3409 static void cmos_exit(void)
3411 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
3414 static int cmos_read(char *p
)
3418 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3419 R30, R31, T20-22, X20-21 */
3421 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3423 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3424 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
3430 static int cmos_write(char *buf
)
3435 while ((cmd
= next_cmd(&buf
))) {
3436 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
3437 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
3442 res
= issue_thinkpad_cmos_command(cmos_cmd
);
3450 static struct ibm_struct cmos_driver_data
= {
3453 .write
= cmos_write
,
3457 /*************************************************************************
3461 enum led_access_mode
{
3462 TPACPI_LED_NONE
= 0,
3463 TPACPI_LED_570
, /* 570 */
3464 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3465 TPACPI_LED_NEW
, /* all others */
3468 enum { /* For TPACPI_LED_OLD */
3469 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
3470 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
3471 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
3474 static enum led_access_mode led_supported
;
3476 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
3477 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
3478 /* T20-22, X20-21 */
3479 "LED", /* all others */
3482 static int __init
led_init(struct ibm_init_struct
*iibm
)
3484 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
3486 TPACPI_ACPIHANDLE_INIT(led
);
3489 /* led not supported on R30, R31 */
3490 led_supported
= TPACPI_LED_NONE
;
3491 else if (strlencmp(led_path
, "SLED") == 0)
3493 led_supported
= TPACPI_LED_570
;
3494 else if (strlencmp(led_path
, "SYSL") == 0)
3495 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3496 led_supported
= TPACPI_LED_OLD
;
3499 led_supported
= TPACPI_LED_NEW
;
3501 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
3502 str_supported(led_supported
), led_supported
);
3504 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
3507 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
3509 static int led_read(char *p
)
3513 if (!led_supported
) {
3514 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3517 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3519 if (led_supported
== TPACPI_LED_570
) {
3522 for (i
= 0; i
< 8; i
++) {
3523 if (!acpi_evalf(ec_handle
,
3524 &status
, "GLED", "dd", 1 << i
))
3526 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
3527 i
, led_status(status
));
3531 len
+= sprintf(p
+ len
, "commands:\t"
3532 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
3537 /* off, on, blink */
3538 static const int led_sled_arg1
[] = { 0, 1, 3 };
3539 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
3540 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
3541 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
3543 static int led_write(char *buf
)
3551 while ((cmd
= next_cmd(&buf
))) {
3552 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
3555 if (strstr(cmd
, "off")) {
3557 } else if (strstr(cmd
, "on")) {
3559 } else if (strstr(cmd
, "blink")) {
3564 if (led_supported
== TPACPI_LED_570
) {
3567 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
3568 led
, led_sled_arg1
[ind
]))
3570 } else if (led_supported
== TPACPI_LED_OLD
) {
3571 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
3573 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
3575 ret
= ec_write(TPACPI_LED_EC_HLBL
,
3576 led
* led_exp_hlbl
[ind
]);
3578 ret
= ec_write(TPACPI_LED_EC_HLCL
,
3579 led
* led_exp_hlcl
[ind
]);
3584 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
3585 led
, led_led_arg1
[ind
]))
3593 static struct ibm_struct led_driver_data
= {
3599 /*************************************************************************
3603 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
3605 static int __init
beep_init(struct ibm_init_struct
*iibm
)
3607 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
3609 TPACPI_ACPIHANDLE_INIT(beep
);
3611 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
3612 str_supported(beep_handle
!= NULL
));
3614 return (beep_handle
)? 0 : 1;
3617 static int beep_read(char *p
)
3622 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3624 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3625 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
3631 static int beep_write(char *buf
)
3639 while ((cmd
= next_cmd(&buf
))) {
3640 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
3641 beep_cmd
>= 0 && beep_cmd
<= 17) {
3645 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
3652 static struct ibm_struct beep_driver_data
= {
3655 .write
= beep_write
,
3658 /*************************************************************************
3662 enum thermal_access_mode
{
3663 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
3664 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
3665 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
3666 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
3667 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
3670 enum { /* TPACPI_THERMAL_TPEC_* */
3671 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
3672 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
3673 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
3676 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
3677 struct ibm_thermal_sensors_struct
{
3678 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
3681 static enum thermal_access_mode thermal_read_mode
;
3683 /* idx is zero-based */
3684 static int thermal_get_sensor(int idx
, s32
*value
)
3690 t
= TP_EC_THERMAL_TMP0
;
3692 switch (thermal_read_mode
) {
3693 #if TPACPI_MAX_THERMAL_SENSORS >= 16
3694 case TPACPI_THERMAL_TPEC_16
:
3695 if (idx
>= 8 && idx
<= 15) {
3696 t
= TP_EC_THERMAL_TMP8
;
3701 case TPACPI_THERMAL_TPEC_8
:
3703 if (!acpi_ec_read(t
+ idx
, &tmp
))
3705 *value
= tmp
* 1000;
3710 case TPACPI_THERMAL_ACPI_UPDT
:
3712 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3713 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
3715 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3717 *value
= (t
- 2732) * 100;
3722 case TPACPI_THERMAL_ACPI_TMP07
:
3724 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3725 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3727 if (t
> 127 || t
< -127)
3728 t
= TP_EC_THERMAL_TMP_NA
;
3734 case TPACPI_THERMAL_NONE
:
3742 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
3753 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
3756 for (i
= 0 ; i
< n
; i
++) {
3757 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
3765 /* sysfs temp##_input -------------------------------------------------- */
3767 static ssize_t
thermal_temp_input_show(struct device
*dev
,
3768 struct device_attribute
*attr
,
3771 struct sensor_device_attribute
*sensor_attr
=
3772 to_sensor_dev_attr(attr
);
3773 int idx
= sensor_attr
->index
;
3777 res
= thermal_get_sensor(idx
, &value
);
3780 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
3783 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
3786 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
3787 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
3788 thermal_temp_input_show, NULL, _idxB)
3790 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
3791 THERMAL_SENSOR_ATTR_TEMP(1, 0),
3792 THERMAL_SENSOR_ATTR_TEMP(2, 1),
3793 THERMAL_SENSOR_ATTR_TEMP(3, 2),
3794 THERMAL_SENSOR_ATTR_TEMP(4, 3),
3795 THERMAL_SENSOR_ATTR_TEMP(5, 4),
3796 THERMAL_SENSOR_ATTR_TEMP(6, 5),
3797 THERMAL_SENSOR_ATTR_TEMP(7, 6),
3798 THERMAL_SENSOR_ATTR_TEMP(8, 7),
3799 THERMAL_SENSOR_ATTR_TEMP(9, 8),
3800 THERMAL_SENSOR_ATTR_TEMP(10, 9),
3801 THERMAL_SENSOR_ATTR_TEMP(11, 10),
3802 THERMAL_SENSOR_ATTR_TEMP(12, 11),
3803 THERMAL_SENSOR_ATTR_TEMP(13, 12),
3804 THERMAL_SENSOR_ATTR_TEMP(14, 13),
3805 THERMAL_SENSOR_ATTR_TEMP(15, 14),
3806 THERMAL_SENSOR_ATTR_TEMP(16, 15),
3809 #define THERMAL_ATTRS(X) \
3810 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
3812 static struct attribute
*thermal_temp_input_attr
[] = {
3832 static const struct attribute_group thermal_temp_input16_group
= {
3833 .attrs
= thermal_temp_input_attr
3836 static const struct attribute_group thermal_temp_input8_group
= {
3837 .attrs
= &thermal_temp_input_attr
[8]
3840 #undef THERMAL_SENSOR_ATTR_TEMP
3841 #undef THERMAL_ATTRS
3843 /* --------------------------------------------------------------------- */
3845 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
3852 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
3854 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
3856 if (thinkpad_id
.ec_model
) {
3858 * Direct EC access mode: sensors at registers
3859 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
3860 * non-implemented, thermal sensors return 0x80 when
3865 for (i
= 0; i
< 8; i
++) {
3866 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
3872 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
3880 /* This is sheer paranoia, but we handle it anyway */
3883 "ThinkPad ACPI EC access misbehaving, "
3884 "falling back to ACPI TMPx access "
3886 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
3889 "ThinkPad ACPI EC access misbehaving, "
3890 "disabling thermal sensors access\n");
3891 thermal_read_mode
= TPACPI_THERMAL_NONE
;
3896 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
3898 } else if (acpi_tmp7
) {
3899 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
3900 /* 600e/x, 770e, 770x */
3901 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
3903 /* Standard ACPI TMPx access, max 8 sensors */
3904 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
3907 /* temperatures not supported on 570, G4x, R30, R31, R32 */
3908 thermal_read_mode
= TPACPI_THERMAL_NONE
;
3911 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
3912 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
3915 switch (thermal_read_mode
) {
3916 case TPACPI_THERMAL_TPEC_16
:
3917 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3918 &thermal_temp_input16_group
);
3922 case TPACPI_THERMAL_TPEC_8
:
3923 case TPACPI_THERMAL_ACPI_TMP07
:
3924 case TPACPI_THERMAL_ACPI_UPDT
:
3925 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3926 &thermal_temp_input8_group
);
3930 case TPACPI_THERMAL_NONE
:
3938 static void thermal_exit(void)
3940 switch (thermal_read_mode
) {
3941 case TPACPI_THERMAL_TPEC_16
:
3942 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3943 &thermal_temp_input16_group
);
3945 case TPACPI_THERMAL_TPEC_8
:
3946 case TPACPI_THERMAL_ACPI_TMP07
:
3947 case TPACPI_THERMAL_ACPI_UPDT
:
3948 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3949 &thermal_temp_input16_group
);
3951 case TPACPI_THERMAL_NONE
:
3957 static int thermal_read(char *p
)
3961 struct ibm_thermal_sensors_struct t
;
3963 n
= thermal_get_sensors(&t
);
3964 if (unlikely(n
< 0))
3967 len
+= sprintf(p
+ len
, "temperatures:\t");
3970 for (i
= 0; i
< (n
- 1); i
++)
3971 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
3972 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
3974 len
+= sprintf(p
+ len
, "not supported\n");
3979 static struct ibm_struct thermal_driver_data
= {
3981 .read
= thermal_read
,
3982 .exit
= thermal_exit
,
3985 /*************************************************************************
3989 static u8 ecdump_regs
[256];
3991 static int ecdump_read(char *p
)
3997 len
+= sprintf(p
+ len
, "EC "
3998 " +00 +01 +02 +03 +04 +05 +06 +07"
3999 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
4000 for (i
= 0; i
< 256; i
+= 16) {
4001 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
4002 for (j
= 0; j
< 16; j
++) {
4003 if (!acpi_ec_read(i
+ j
, &v
))
4005 if (v
!= ecdump_regs
[i
+ j
])
4006 len
+= sprintf(p
+ len
, " *%02x", v
);
4008 len
+= sprintf(p
+ len
, " %02x", v
);
4009 ecdump_regs
[i
+ j
] = v
;
4011 len
+= sprintf(p
+ len
, "\n");
4016 /* These are way too dangerous to advertise openly... */
4018 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
4019 " (<offset> is 00-ff, <value> is 00-ff)\n");
4020 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
4021 " (<offset> is 00-ff, <value> is 0-255)\n");
4026 static int ecdump_write(char *buf
)
4031 while ((cmd
= next_cmd(&buf
))) {
4032 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
4034 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
4038 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
4039 if (!acpi_ec_write(i
, v
))
4048 static struct ibm_struct ecdump_driver_data
= {
4050 .read
= ecdump_read
,
4051 .write
= ecdump_write
,
4052 .flags
.experimental
= 1,
4055 /*************************************************************************
4056 * Backlight/brightness subdriver
4059 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
4061 static struct backlight_device
*ibm_backlight_device
;
4062 static int brightness_offset
= 0x31;
4063 static int brightness_mode
;
4064 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
4066 static struct mutex brightness_mutex
;
4069 * ThinkPads can read brightness from two places: EC 0x31, or
4070 * CMOS NVRAM byte 0x5E, bits 0-3.
4072 static int brightness_get(struct backlight_device
*bd
)
4074 u8 lec
= 0, lcmos
= 0, level
= 0;
4076 if (brightness_mode
& 1) {
4077 if (!acpi_ec_read(brightness_offset
, &lec
))
4079 lec
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
4082 if (brightness_mode
& 2) {
4083 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
4084 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
4085 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
4086 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
4090 if (brightness_mode
== 3 && lec
!= lcmos
) {
4092 "CMOS NVRAM (%u) and EC (%u) do not agree "
4093 "on display brightness level\n",
4094 (unsigned int) lcmos
,
4095 (unsigned int) lec
);
4102 /* May return EINTR which can always be mapped to ERESTARTSYS */
4103 static int brightness_set(int value
)
4105 int cmos_cmd
, inc
, i
, res
;
4108 if (value
> ((tp_features
.bright_16levels
)? 15 : 7))
4111 res
= mutex_lock_interruptible(&brightness_mutex
);
4115 current_value
= brightness_get(NULL
);
4116 if (current_value
< 0) {
4117 res
= current_value
;
4121 cmos_cmd
= value
> current_value
?
4122 TP_CMOS_BRIGHTNESS_UP
:
4123 TP_CMOS_BRIGHTNESS_DOWN
;
4124 inc
= (value
> current_value
)? 1 : -1;
4127 for (i
= current_value
; i
!= value
; i
+= inc
) {
4128 if ((brightness_mode
& 2) &&
4129 issue_thinkpad_cmos_command(cmos_cmd
)) {
4133 if ((brightness_mode
& 1) &&
4134 !acpi_ec_write(brightness_offset
, i
+ inc
)) {
4141 mutex_unlock(&brightness_mutex
);
4145 /* sysfs backlight class ----------------------------------------------- */
4147 static int brightness_update_status(struct backlight_device
*bd
)
4149 /* it is the backlight class's job (caller) to handle
4150 * EINTR and other errors properly */
4151 return brightness_set(
4152 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
4153 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
4154 bd
->props
.brightness
: 0);
4157 static struct backlight_ops ibm_backlight_data
= {
4158 .get_brightness
= brightness_get
,
4159 .update_status
= brightness_update_status
,
4162 /* --------------------------------------------------------------------- */
4164 static int __init
tpacpi_query_bcll_levels(acpi_handle handle
)
4166 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
4167 union acpi_object
*obj
;
4170 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
4171 obj
= (union acpi_object
*)buffer
.pointer
;
4172 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
4173 printk(TPACPI_ERR
"Unknown BCLL data, "
4174 "please report this to %s\n", TPACPI_MAIL
);
4177 rc
= obj
->package
.count
;
4183 kfree(buffer
.pointer
);
4187 static acpi_status __init
brightness_find_bcll(acpi_handle handle
, u32 lvl
,
4188 void *context
, void **rv
)
4190 char name
[ACPI_PATH_SEGMENT_LENGTH
];
4191 struct acpi_buffer buffer
= { sizeof(name
), &name
};
4193 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
4194 !strncmp("BCLL", name
, sizeof(name
) - 1)) {
4195 if (tpacpi_query_bcll_levels(handle
) == 16) {
4197 return AE_CTRL_TERMINATE
;
4206 static int __init
brightness_check_levels(void)
4209 void *found_node
= NULL
;
4212 TPACPI_ACPIHANDLE_INIT(vid
);
4217 /* Search for a BCLL package with 16 levels */
4218 status
= acpi_walk_namespace(ACPI_TYPE_PACKAGE
, vid_handle
, 3,
4219 brightness_find_bcll
, NULL
,
4222 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
4225 static acpi_status __init
brightness_find_bcl(acpi_handle handle
, u32 lvl
,
4226 void *context
, void **rv
)
4228 char name
[ACPI_PATH_SEGMENT_LENGTH
];
4229 struct acpi_buffer buffer
= { sizeof(name
), &name
};
4231 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
4232 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
4234 return AE_CTRL_TERMINATE
;
4240 static int __init
brightness_check_std_acpi_support(void)
4243 void *found_node
= NULL
;
4246 TPACPI_ACPIHANDLE_INIT(vid
);
4251 /* Search for a _BCL method, but don't execute it */
4252 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
4253 brightness_find_bcl
, NULL
, &found_node
);
4255 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
4258 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
4262 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
4264 mutex_init(&brightness_mutex
);
4266 if (!brightness_enable
) {
4267 dbg_printk(TPACPI_DBG_INIT
,
4268 "brightness support disabled by "
4269 "module parameter\n");
4271 } else if (brightness_enable
> 1) {
4272 if (brightness_check_std_acpi_support()) {
4273 printk(TPACPI_NOTICE
4274 "standard ACPI backlight interface "
4275 "available, not loading native one...\n");
4280 if (!brightness_mode
) {
4281 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
4282 brightness_mode
= 2;
4284 brightness_mode
= 3;
4286 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
4290 if (brightness_mode
> 3)
4293 tp_features
.bright_16levels
=
4294 thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
&&
4295 brightness_check_levels();
4297 b
= brightness_get(NULL
);
4301 if (tp_features
.bright_16levels
)
4303 "detected a 16-level brightness capable ThinkPad\n");
4305 ibm_backlight_device
= backlight_device_register(
4306 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
4307 &ibm_backlight_data
);
4308 if (IS_ERR(ibm_backlight_device
)) {
4309 printk(TPACPI_ERR
"Could not register backlight device\n");
4310 return PTR_ERR(ibm_backlight_device
);
4312 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
4314 ibm_backlight_device
->props
.max_brightness
=
4315 (tp_features
.bright_16levels
)? 15 : 7;
4316 ibm_backlight_device
->props
.brightness
= b
;
4317 backlight_update_status(ibm_backlight_device
);
4322 static void brightness_exit(void)
4324 if (ibm_backlight_device
) {
4325 vdbg_printk(TPACPI_DBG_EXIT
,
4326 "calling backlight_device_unregister()\n");
4327 backlight_device_unregister(ibm_backlight_device
);
4328 ibm_backlight_device
= NULL
;
4332 static int brightness_read(char *p
)
4337 level
= brightness_get(NULL
);
4339 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
4341 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
4342 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
4343 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
4344 " (<level> is 0-%d)\n",
4345 (tp_features
.bright_16levels
) ? 15 : 7);
4351 static int brightness_write(char *buf
)
4356 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
4358 level
= brightness_get(NULL
);
4362 while ((cmd
= next_cmd(&buf
))) {
4363 if (strlencmp(cmd
, "up") == 0) {
4364 if (level
< max_level
)
4366 } else if (strlencmp(cmd
, "down") == 0) {
4369 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
4370 level
>= 0 && level
<= max_level
) {
4377 * Now we know what the final level should be, so we try to set it.
4378 * Doing it this way makes the syscall restartable in case of EINTR
4380 rc
= brightness_set(level
);
4381 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
4384 static struct ibm_struct brightness_driver_data
= {
4385 .name
= "brightness",
4386 .read
= brightness_read
,
4387 .write
= brightness_write
,
4388 .exit
= brightness_exit
,
4391 /*************************************************************************
4395 static int volume_offset
= 0x30;
4397 static int volume_read(char *p
)
4402 if (!acpi_ec_read(volume_offset
, &level
)) {
4403 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
4405 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
4406 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
4407 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
4408 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
4409 " (<level> is 0-15)\n");
4415 static int volume_write(char *buf
)
4417 int cmos_cmd
, inc
, i
;
4419 int new_level
, new_mute
;
4422 while ((cmd
= next_cmd(&buf
))) {
4423 if (!acpi_ec_read(volume_offset
, &level
))
4425 new_mute
= mute
= level
& 0x40;
4426 new_level
= level
= level
& 0xf;
4428 if (strlencmp(cmd
, "up") == 0) {
4432 new_level
= level
== 15 ? 15 : level
+ 1;
4433 } else if (strlencmp(cmd
, "down") == 0) {
4437 new_level
= level
== 0 ? 0 : level
- 1;
4438 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
4439 new_level
>= 0 && new_level
<= 15) {
4441 } else if (strlencmp(cmd
, "mute") == 0) {
4446 if (new_level
!= level
) {
4447 /* mute doesn't change */
4449 cmos_cmd
= (new_level
> level
) ?
4450 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
4451 inc
= new_level
> level
? 1 : -1;
4453 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
4454 !acpi_ec_write(volume_offset
, level
)))
4457 for (i
= level
; i
!= new_level
; i
+= inc
)
4458 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
4459 !acpi_ec_write(volume_offset
, i
+ inc
))
4463 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
4464 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
4469 if (new_mute
!= mute
) {
4470 /* level doesn't change */
4472 cmos_cmd
= (new_mute
) ?
4473 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
4475 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
4476 !acpi_ec_write(volume_offset
, level
+ new_mute
))
4484 static struct ibm_struct volume_driver_data
= {
4486 .read
= volume_read
,
4487 .write
= volume_write
,
4490 /*************************************************************************
4497 * TPACPI_FAN_RD_ACPI_GFAN:
4498 * ACPI GFAN method: returns fan level
4500 * see TPACPI_FAN_WR_ACPI_SFAN
4501 * EC 0x2f (HFSP) not available if GFAN exists
4503 * TPACPI_FAN_WR_ACPI_SFAN:
4504 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
4506 * EC 0x2f (HFSP) might be available *for reading*, but do not use
4509 * TPACPI_FAN_WR_TPEC:
4510 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
4511 * Supported on almost all ThinkPads
4513 * Fan speed changes of any sort (including those caused by the
4514 * disengaged mode) are usually done slowly by the firmware as the
4515 * maximum ammount of fan duty cycle change per second seems to be
4518 * Reading is not available if GFAN exists.
4519 * Writing is not available if SFAN exists.
4522 * 7 automatic mode engaged;
4523 * (default operation mode of the ThinkPad)
4524 * fan level is ignored in this mode.
4525 * 6 full speed mode (takes precedence over bit 7);
4526 * not available on all thinkpads. May disable
4527 * the tachometer while the fan controller ramps up
4528 * the speed (which can take up to a few *minutes*).
4529 * Speeds up fan to 100% duty-cycle, which is far above
4530 * the standard RPM levels. It is not impossible that
4531 * it could cause hardware damage.
4532 * 5-3 unused in some models. Extra bits for fan level
4533 * in others, but still useless as all values above
4534 * 7 map to the same speed as level 7 in these models.
4535 * 2-0 fan level (0..7 usually)
4537 * 0x07 = max (set when temperatures critical)
4538 * Some ThinkPads may have other levels, see
4539 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
4541 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
4542 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
4543 * does so, its initial value is meaningless (0x07).
4545 * For firmware bugs, refer to:
4546 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
4550 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
4551 * Main fan tachometer reading (in RPM)
4553 * This register is present on all ThinkPads with a new-style EC, and
4554 * it is known not to be present on the A21m/e, and T22, as there is
4555 * something else in offset 0x84 according to the ACPI DSDT. Other
4556 * ThinkPads from this same time period (and earlier) probably lack the
4557 * tachometer as well.
4559 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
4560 * was never fixed by IBM to report the EC firmware version string
4561 * probably support the tachometer (like the early X models), so
4562 * detecting it is quite hard. We need more data to know for sure.
4564 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
4567 * FIRMWARE BUG: may go stale while the EC is switching to full speed
4570 * For firmware bugs, refer to:
4571 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
4573 * TPACPI_FAN_WR_ACPI_FANS:
4574 * ThinkPad X31, X40, X41. Not available in the X60.
4576 * FANS ACPI handle: takes three arguments: low speed, medium speed,
4577 * high speed. ACPI DSDT seems to map these three speeds to levels
4578 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
4579 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
4581 * The speeds are stored on handles
4582 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
4584 * There are three default speed sets, acessible as handles:
4585 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
4587 * ACPI DSDT switches which set is in use depending on various
4590 * TPACPI_FAN_WR_TPEC is also available and should be used to
4591 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
4592 * but the ACPI tables just mention level 7.
4595 enum { /* Fan control constants */
4596 fan_status_offset
= 0x2f, /* EC register 0x2f */
4597 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
4598 * 0x84 must be read before 0x85 */
4600 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
4601 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
4603 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
4606 enum fan_status_access_mode
{
4607 TPACPI_FAN_NONE
= 0, /* No fan status or control */
4608 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
4609 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
4612 enum fan_control_access_mode
{
4613 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
4614 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
4615 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
4616 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
4619 enum fan_control_commands
{
4620 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
4621 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
4622 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
4623 * and also watchdog cmd */
4626 static int fan_control_allowed
;
4628 static enum fan_status_access_mode fan_status_access_mode
;
4629 static enum fan_control_access_mode fan_control_access_mode
;
4630 static enum fan_control_commands fan_control_commands
;
4632 static u8 fan_control_initial_status
;
4633 static u8 fan_control_desired_level
;
4634 static int fan_watchdog_maxinterval
;
4636 static struct mutex fan_mutex
;
4638 static void fan_watchdog_fire(struct work_struct
*ignored
);
4639 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
4641 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
4642 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
4643 "\\FSPD", /* 600e/x, 770e, 770x */
4645 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
4646 "JFNS", /* 770x-JL */
4650 * Call with fan_mutex held
4652 static void fan_update_desired_level(u8 status
)
4655 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
4657 fan_control_desired_level
= 7;
4659 fan_control_desired_level
= status
;
4663 static int fan_get_status(u8
*status
)
4668 * Add TPACPI_FAN_RD_ACPI_FANS ? */
4670 switch (fan_status_access_mode
) {
4671 case TPACPI_FAN_RD_ACPI_GFAN
:
4672 /* 570, 600e/x, 770e, 770x */
4674 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
4682 case TPACPI_FAN_RD_TPEC
:
4683 /* all except 570, 600e/x, 770e, 770x */
4684 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
4699 static int fan_get_status_safe(u8
*status
)
4704 if (mutex_lock_interruptible(&fan_mutex
))
4705 return -ERESTARTSYS
;
4706 rc
= fan_get_status(&s
);
4708 fan_update_desired_level(s
);
4709 mutex_unlock(&fan_mutex
);
4717 static int fan_get_speed(unsigned int *speed
)
4721 switch (fan_status_access_mode
) {
4722 case TPACPI_FAN_RD_TPEC
:
4723 /* all except 570, 600e/x, 770e, 770x */
4724 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
4725 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
4729 *speed
= (hi
<< 8) | lo
;
4740 static int fan_set_level(int level
)
4742 if (!fan_control_allowed
)
4745 switch (fan_control_access_mode
) {
4746 case TPACPI_FAN_WR_ACPI_SFAN
:
4747 if (level
>= 0 && level
<= 7) {
4748 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
4754 case TPACPI_FAN_WR_ACPI_FANS
:
4755 case TPACPI_FAN_WR_TPEC
:
4756 if ((level
!= TP_EC_FAN_AUTO
) &&
4757 (level
!= TP_EC_FAN_FULLSPEED
) &&
4758 ((level
< 0) || (level
> 7)))
4761 /* safety net should the EC not support AUTO
4762 * or FULLSPEED mode bits and just ignore them */
4763 if (level
& TP_EC_FAN_FULLSPEED
)
4764 level
|= 7; /* safety min speed 7 */
4765 else if (level
& TP_EC_FAN_FULLSPEED
)
4766 level
|= 4; /* safety min speed 4 */
4768 if (!acpi_ec_write(fan_status_offset
, level
))
4771 tp_features
.fan_ctrl_status_undef
= 0;
4780 static int fan_set_level_safe(int level
)
4784 if (!fan_control_allowed
)
4787 if (mutex_lock_interruptible(&fan_mutex
))
4788 return -ERESTARTSYS
;
4790 if (level
== TPACPI_FAN_LAST_LEVEL
)
4791 level
= fan_control_desired_level
;
4793 rc
= fan_set_level(level
);
4795 fan_update_desired_level(level
);
4797 mutex_unlock(&fan_mutex
);
4801 static int fan_set_enable(void)
4806 if (!fan_control_allowed
)
4809 if (mutex_lock_interruptible(&fan_mutex
))
4810 return -ERESTARTSYS
;
4812 switch (fan_control_access_mode
) {
4813 case TPACPI_FAN_WR_ACPI_FANS
:
4814 case TPACPI_FAN_WR_TPEC
:
4815 rc
= fan_get_status(&s
);
4819 /* Don't go out of emergency fan mode */
4822 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
4825 if (!acpi_ec_write(fan_status_offset
, s
))
4828 tp_features
.fan_ctrl_status_undef
= 0;
4833 case TPACPI_FAN_WR_ACPI_SFAN
:
4834 rc
= fan_get_status(&s
);
4840 /* Set fan to at least level 4 */
4843 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
4853 mutex_unlock(&fan_mutex
);
4857 static int fan_set_disable(void)
4861 if (!fan_control_allowed
)
4864 if (mutex_lock_interruptible(&fan_mutex
))
4865 return -ERESTARTSYS
;
4868 switch (fan_control_access_mode
) {
4869 case TPACPI_FAN_WR_ACPI_FANS
:
4870 case TPACPI_FAN_WR_TPEC
:
4871 if (!acpi_ec_write(fan_status_offset
, 0x00))
4874 fan_control_desired_level
= 0;
4875 tp_features
.fan_ctrl_status_undef
= 0;
4879 case TPACPI_FAN_WR_ACPI_SFAN
:
4880 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
4883 fan_control_desired_level
= 0;
4891 mutex_unlock(&fan_mutex
);
4895 static int fan_set_speed(int speed
)
4899 if (!fan_control_allowed
)
4902 if (mutex_lock_interruptible(&fan_mutex
))
4903 return -ERESTARTSYS
;
4906 switch (fan_control_access_mode
) {
4907 case TPACPI_FAN_WR_ACPI_FANS
:
4908 if (speed
>= 0 && speed
<= 65535) {
4909 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
4910 speed
, speed
, speed
))
4920 mutex_unlock(&fan_mutex
);
4924 static void fan_watchdog_reset(void)
4926 static int fan_watchdog_active
;
4928 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
4931 if (fan_watchdog_active
)
4932 cancel_delayed_work(&fan_watchdog_task
);
4934 if (fan_watchdog_maxinterval
> 0 &&
4935 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
4936 fan_watchdog_active
= 1;
4937 if (!schedule_delayed_work(&fan_watchdog_task
,
4938 msecs_to_jiffies(fan_watchdog_maxinterval
4941 "failed to schedule the fan watchdog, "
4942 "watchdog will not trigger\n");
4945 fan_watchdog_active
= 0;
4948 static void fan_watchdog_fire(struct work_struct
*ignored
)
4952 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
4955 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
4956 rc
= fan_set_enable();
4958 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
4959 "will try again later...\n", -rc
);
4960 /* reschedule for later */
4961 fan_watchdog_reset();
4966 * SYSFS fan layout: hwmon compatible (device)
4969 * 0: "disengaged" mode
4971 * 2: native EC "auto" mode (recommended, hardware default)
4973 * pwm*: set speed in manual mode, ignored otherwise.
4974 * 0 is level 0; 255 is level 7. Intermediate points done with linear
4977 * fan*_input: tachometer reading, RPM
4980 * SYSFS fan layout: extensions
4982 * fan_watchdog (driver):
4983 * fan watchdog interval in seconds, 0 disables (default), max 120
4986 /* sysfs fan pwm1_enable ----------------------------------------------- */
4987 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
4988 struct device_attribute
*attr
,
4994 res
= fan_get_status_safe(&status
);
4998 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4999 if (status
!= fan_control_initial_status
) {
5000 tp_features
.fan_ctrl_status_undef
= 0;
5002 /* Return most likely status. In fact, it
5003 * might be the only possible status */
5004 status
= TP_EC_FAN_AUTO
;
5008 if (status
& TP_EC_FAN_FULLSPEED
) {
5010 } else if (status
& TP_EC_FAN_AUTO
) {
5015 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
5018 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
5019 struct device_attribute
*attr
,
5020 const char *buf
, size_t count
)
5025 if (parse_strtoul(buf
, 2, &t
))
5030 level
= TP_EC_FAN_FULLSPEED
;
5033 level
= TPACPI_FAN_LAST_LEVEL
;
5036 level
= TP_EC_FAN_AUTO
;
5039 /* reserved for software-controlled auto mode */
5045 res
= fan_set_level_safe(level
);
5051 fan_watchdog_reset();
5056 static struct device_attribute dev_attr_fan_pwm1_enable
=
5057 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
5058 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
5060 /* sysfs fan pwm1 ------------------------------------------------------ */
5061 static ssize_t
fan_pwm1_show(struct device
*dev
,
5062 struct device_attribute
*attr
,
5068 res
= fan_get_status_safe(&status
);
5072 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5073 if (status
!= fan_control_initial_status
) {
5074 tp_features
.fan_ctrl_status_undef
= 0;
5076 status
= TP_EC_FAN_AUTO
;
5081 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
5082 status
= fan_control_desired_level
;
5087 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
5090 static ssize_t
fan_pwm1_store(struct device
*dev
,
5091 struct device_attribute
*attr
,
5092 const char *buf
, size_t count
)
5096 u8 status
, newlevel
;
5098 if (parse_strtoul(buf
, 255, &s
))
5101 /* scale down from 0-255 to 0-7 */
5102 newlevel
= (s
>> 5) & 0x07;
5104 if (mutex_lock_interruptible(&fan_mutex
))
5105 return -ERESTARTSYS
;
5107 rc
= fan_get_status(&status
);
5108 if (!rc
&& (status
&
5109 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
5110 rc
= fan_set_level(newlevel
);
5114 fan_update_desired_level(newlevel
);
5115 fan_watchdog_reset();
5119 mutex_unlock(&fan_mutex
);
5120 return (rc
)? rc
: count
;
5123 static struct device_attribute dev_attr_fan_pwm1
=
5124 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
5125 fan_pwm1_show
, fan_pwm1_store
);
5127 /* sysfs fan fan1_input ------------------------------------------------ */
5128 static ssize_t
fan_fan1_input_show(struct device
*dev
,
5129 struct device_attribute
*attr
,
5135 res
= fan_get_speed(&speed
);
5139 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
5142 static struct device_attribute dev_attr_fan_fan1_input
=
5143 __ATTR(fan1_input
, S_IRUGO
,
5144 fan_fan1_input_show
, NULL
);
5146 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
5147 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
5150 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
5153 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
5154 const char *buf
, size_t count
)
5158 if (parse_strtoul(buf
, 120, &t
))
5161 if (!fan_control_allowed
)
5164 fan_watchdog_maxinterval
= t
;
5165 fan_watchdog_reset();
5170 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
5171 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
5173 /* --------------------------------------------------------------------- */
5174 static struct attribute
*fan_attributes
[] = {
5175 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
5176 &dev_attr_fan_fan1_input
.attr
,
5180 static const struct attribute_group fan_attr_group
= {
5181 .attrs
= fan_attributes
,
5184 static int __init
fan_init(struct ibm_init_struct
*iibm
)
5188 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
5190 mutex_init(&fan_mutex
);
5191 fan_status_access_mode
= TPACPI_FAN_NONE
;
5192 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
5193 fan_control_commands
= 0;
5194 fan_watchdog_maxinterval
= 0;
5195 tp_features
.fan_ctrl_status_undef
= 0;
5196 fan_control_desired_level
= 7;
5198 TPACPI_ACPIHANDLE_INIT(fans
);
5199 TPACPI_ACPIHANDLE_INIT(gfan
);
5200 TPACPI_ACPIHANDLE_INIT(sfan
);
5203 /* 570, 600e/x, 770e, 770x */
5204 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
5206 /* all other ThinkPads: note that even old-style
5207 * ThinkPad ECs supports the fan control register */
5208 if (likely(acpi_ec_read(fan_status_offset
,
5209 &fan_control_initial_status
))) {
5210 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
5212 /* In some ThinkPads, neither the EC nor the ACPI
5213 * DSDT initialize the fan status, and it ends up
5214 * being set to 0x07 when it *could* be either
5217 * Enable for TP-1Y (T43), TP-78 (R51e),
5218 * TP-76 (R52), TP-70 (T43, R52), which are known
5220 if (fan_control_initial_status
== 0x07) {
5221 switch (thinkpad_id
.ec_model
) {
5222 case 0x5931: /* TP-1Y */
5223 case 0x3837: /* TP-78 */
5224 case 0x3637: /* TP-76 */
5225 case 0x3037: /* TP-70 */
5226 printk(TPACPI_NOTICE
5227 "fan_init: initial fan status "
5228 "is unknown, assuming it is "
5230 tp_features
.fan_ctrl_status_undef
= 1;
5236 "ThinkPad ACPI EC access misbehaving, "
5237 "fan status and control unavailable\n");
5244 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
5245 fan_control_commands
|=
5246 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
5249 /* gfan without sfan means no fan control */
5250 /* all other models implement TP EC 0x2f control */
5254 fan_control_access_mode
=
5255 TPACPI_FAN_WR_ACPI_FANS
;
5256 fan_control_commands
|=
5257 TPACPI_FAN_CMD_SPEED
|
5258 TPACPI_FAN_CMD_LEVEL
|
5259 TPACPI_FAN_CMD_ENABLE
;
5261 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
5262 fan_control_commands
|=
5263 TPACPI_FAN_CMD_LEVEL
|
5264 TPACPI_FAN_CMD_ENABLE
;
5269 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
5270 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
5271 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
5272 fan_status_access_mode
, fan_control_access_mode
);
5274 /* fan control master switch */
5275 if (!fan_control_allowed
) {
5276 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
5277 fan_control_commands
= 0;
5278 dbg_printk(TPACPI_DBG_INIT
,
5279 "fan control features disabled by parameter\n");
5282 /* update fan_control_desired_level */
5283 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
5284 fan_get_status_safe(NULL
);
5286 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
5287 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
5288 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5291 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
5292 &driver_attr_fan_watchdog
);
5300 static void fan_exit(void)
5302 vdbg_printk(TPACPI_DBG_EXIT
,
5303 "cancelling any pending fan watchdog tasks\n");
5305 /* FIXME: can we really do this unconditionally? */
5306 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
5307 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
5308 &driver_attr_fan_watchdog
);
5310 cancel_delayed_work(&fan_watchdog_task
);
5311 flush_scheduled_work();
5314 static int fan_read(char *p
)
5319 unsigned int speed
= 0;
5321 switch (fan_status_access_mode
) {
5322 case TPACPI_FAN_RD_ACPI_GFAN
:
5323 /* 570, 600e/x, 770e, 770x */
5324 rc
= fan_get_status_safe(&status
);
5328 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
5330 (status
!= 0) ? "enabled" : "disabled", status
);
5333 case TPACPI_FAN_RD_TPEC
:
5334 /* all except 570, 600e/x, 770e, 770x */
5335 rc
= fan_get_status_safe(&status
);
5339 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5340 if (status
!= fan_control_initial_status
)
5341 tp_features
.fan_ctrl_status_undef
= 0;
5343 /* Return most likely status. In fact, it
5344 * might be the only possible status */
5345 status
= TP_EC_FAN_AUTO
;
5348 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
5349 (status
!= 0) ? "enabled" : "disabled");
5351 rc
= fan_get_speed(&speed
);
5355 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
5357 if (status
& TP_EC_FAN_FULLSPEED
)
5358 /* Disengaged mode takes precedence */
5359 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
5360 else if (status
& TP_EC_FAN_AUTO
)
5361 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
5363 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
5366 case TPACPI_FAN_NONE
:
5368 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5371 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
5372 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
5374 switch (fan_control_access_mode
) {
5375 case TPACPI_FAN_WR_ACPI_SFAN
:
5376 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
5380 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
5381 "auto, disengaged, full-speed)\n");
5386 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
5387 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
5388 "commands:\twatchdog <timeout> (<timeout> "
5389 "is 0 (off), 1-120 (seconds))\n");
5391 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
5392 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
5393 " (<speed> is 0-65535)\n");
5398 static int fan_write_cmd_level(const char *cmd
, int *rc
)
5402 if (strlencmp(cmd
, "level auto") == 0)
5403 level
= TP_EC_FAN_AUTO
;
5404 else if ((strlencmp(cmd
, "level disengaged") == 0) |
5405 (strlencmp(cmd
, "level full-speed") == 0))
5406 level
= TP_EC_FAN_FULLSPEED
;
5407 else if (sscanf(cmd
, "level %d", &level
) != 1)
5410 *rc
= fan_set_level_safe(level
);
5412 printk(TPACPI_ERR
"level command accepted for unsupported "
5413 "access mode %d", fan_control_access_mode
);
5418 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
5420 if (strlencmp(cmd
, "enable") != 0)
5423 *rc
= fan_set_enable();
5425 printk(TPACPI_ERR
"enable command accepted for unsupported "
5426 "access mode %d", fan_control_access_mode
);
5431 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
5433 if (strlencmp(cmd
, "disable") != 0)
5436 *rc
= fan_set_disable();
5438 printk(TPACPI_ERR
"disable command accepted for unsupported "
5439 "access mode %d", fan_control_access_mode
);
5444 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
5449 * Support speed <low> <medium> <high> ? */
5451 if (sscanf(cmd
, "speed %d", &speed
) != 1)
5454 *rc
= fan_set_speed(speed
);
5456 printk(TPACPI_ERR
"speed command accepted for unsupported "
5457 "access mode %d", fan_control_access_mode
);
5462 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
5466 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
5469 if (interval
< 0 || interval
> 120)
5472 fan_watchdog_maxinterval
= interval
;
5477 static int fan_write(char *buf
)
5482 while (!rc
&& (cmd
= next_cmd(&buf
))) {
5483 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
5484 fan_write_cmd_level(cmd
, &rc
)) &&
5485 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
5486 (fan_write_cmd_enable(cmd
, &rc
) ||
5487 fan_write_cmd_disable(cmd
, &rc
) ||
5488 fan_write_cmd_watchdog(cmd
, &rc
))) &&
5489 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
5490 fan_write_cmd_speed(cmd
, &rc
))
5494 fan_watchdog_reset();
5500 static struct ibm_struct fan_driver_data
= {
5507 /****************************************************************************
5508 ****************************************************************************
5512 ****************************************************************************
5513 ****************************************************************************/
5515 /* sysfs name ---------------------------------------------------------- */
5516 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
5517 struct device_attribute
*attr
,
5520 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
5523 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
5524 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
5526 /* --------------------------------------------------------------------- */
5529 static struct proc_dir_entry
*proc_dir
;
5532 * Module and infrastructure proble, init and exit handling
5535 static int force_load
;
5537 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
5538 static const char * __init
str_supported(int is_supported
)
5540 static char text_unsupported
[] __initdata
= "not supported";
5542 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
5544 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
5546 static void ibm_exit(struct ibm_struct
*ibm
)
5548 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
5550 list_del_init(&ibm
->all_drivers
);
5552 if (ibm
->flags
.acpi_notify_installed
) {
5553 dbg_printk(TPACPI_DBG_EXIT
,
5554 "%s: acpi_remove_notify_handler\n", ibm
->name
);
5556 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
5558 dispatch_acpi_notify
);
5559 ibm
->flags
.acpi_notify_installed
= 0;
5560 ibm
->flags
.acpi_notify_installed
= 0;
5563 if (ibm
->flags
.proc_created
) {
5564 dbg_printk(TPACPI_DBG_EXIT
,
5565 "%s: remove_proc_entry\n", ibm
->name
);
5566 remove_proc_entry(ibm
->name
, proc_dir
);
5567 ibm
->flags
.proc_created
= 0;
5570 if (ibm
->flags
.acpi_driver_registered
) {
5571 dbg_printk(TPACPI_DBG_EXIT
,
5572 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
5574 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
5575 kfree(ibm
->acpi
->driver
);
5576 ibm
->acpi
->driver
= NULL
;
5577 ibm
->flags
.acpi_driver_registered
= 0;
5580 if (ibm
->flags
.init_called
&& ibm
->exit
) {
5582 ibm
->flags
.init_called
= 0;
5585 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
5588 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
5591 struct ibm_struct
*ibm
= iibm
->data
;
5592 struct proc_dir_entry
*entry
;
5594 BUG_ON(ibm
== NULL
);
5596 INIT_LIST_HEAD(&ibm
->all_drivers
);
5598 if (ibm
->flags
.experimental
&& !experimental
)
5601 dbg_printk(TPACPI_DBG_INIT
,
5602 "probing for %s\n", ibm
->name
);
5605 ret
= iibm
->init(iibm
);
5607 return 0; /* probe failed */
5611 ibm
->flags
.init_called
= 1;
5615 if (ibm
->acpi
->hid
) {
5616 ret
= register_tpacpi_subdriver(ibm
);
5621 if (ibm
->acpi
->notify
) {
5622 ret
= setup_acpi_notify(ibm
);
5623 if (ret
== -ENODEV
) {
5624 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
5634 dbg_printk(TPACPI_DBG_INIT
,
5635 "%s installed\n", ibm
->name
);
5638 entry
= create_proc_entry(ibm
->name
,
5639 S_IFREG
| S_IRUGO
| S_IWUSR
,
5642 printk(TPACPI_ERR
"unable to create proc entry %s\n",
5647 entry
->owner
= THIS_MODULE
;
5649 entry
->read_proc
= &dispatch_procfs_read
;
5651 entry
->write_proc
= &dispatch_procfs_write
;
5652 ibm
->flags
.proc_created
= 1;
5655 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
5660 dbg_printk(TPACPI_DBG_INIT
,
5661 "%s: at error exit path with result %d\n",
5665 return (ret
< 0)? ret
: 0;
5670 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
5672 const struct dmi_device
*dev
= NULL
;
5673 char ec_fw_string
[18];
5678 memset(tp
, 0, sizeof(*tp
));
5680 if (dmi_name_in_vendors("IBM"))
5681 tp
->vendor
= PCI_VENDOR_ID_IBM
;
5682 else if (dmi_name_in_vendors("LENOVO"))
5683 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
5687 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
5689 if (!tp
->bios_version_str
)
5691 tp
->bios_model
= tp
->bios_version_str
[0]
5692 | (tp
->bios_version_str
[1] << 8);
5695 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
5696 * X32 or newer, all Z series; Some models must have an
5697 * up-to-date BIOS or they will not be detected.
5699 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
5701 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
5702 if (sscanf(dev
->name
,
5703 "IBM ThinkPad Embedded Controller -[%17c",
5704 ec_fw_string
) == 1) {
5705 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
5706 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
5708 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
5709 tp
->ec_model
= ec_fw_string
[0]
5710 | (ec_fw_string
[1] << 8);
5715 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
5717 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
5718 kfree(tp
->model_str
);
5719 tp
->model_str
= NULL
;
5723 static int __init
probe_for_thinkpad(void)
5731 * Non-ancient models have better DMI tagging, but very old models
5734 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
5736 /* ec is required because many other handles are relative to it */
5737 TPACPI_ACPIHANDLE_INIT(ec
);
5741 "Not yet supported ThinkPad detected!\n");
5746 * Risks a regression on very old machines, but reduces potential
5747 * false positives a damn great deal
5750 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
5752 if (!is_thinkpad
&& !force_load
)
5759 /* Module init, exit, parameters */
5761 static struct ibm_init_struct ibms_init
[] __initdata
= {
5763 .init
= thinkpad_acpi_driver_init
,
5764 .data
= &thinkpad_acpi_driver_data
,
5767 .init
= hotkey_init
,
5768 .data
= &hotkey_driver_data
,
5771 .init
= bluetooth_init
,
5772 .data
= &bluetooth_driver_data
,
5776 .data
= &wan_driver_data
,
5780 .data
= &video_driver_data
,
5784 .data
= &light_driver_data
,
5786 #ifdef CONFIG_THINKPAD_ACPI_DOCK
5789 .data
= &dock_driver_data
[0],
5793 .data
= &dock_driver_data
[1],
5796 #ifdef CONFIG_THINKPAD_ACPI_BAY
5799 .data
= &bay_driver_data
,
5804 .data
= &cmos_driver_data
,
5808 .data
= &led_driver_data
,
5812 .data
= &beep_driver_data
,
5815 .init
= thermal_init
,
5816 .data
= &thermal_driver_data
,
5819 .data
= &ecdump_driver_data
,
5822 .init
= brightness_init
,
5823 .data
= &brightness_driver_data
,
5826 .data
= &volume_driver_data
,
5830 .data
= &fan_driver_data
,
5834 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
5837 struct ibm_struct
*ibm
;
5839 if (!kp
|| !kp
->name
|| !val
)
5842 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
5843 ibm
= ibms_init
[i
].data
;
5844 WARN_ON(ibm
== NULL
);
5846 if (!ibm
|| !ibm
->name
)
5849 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
5850 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
5852 strcpy(ibms_init
[i
].param
, val
);
5853 strcat(ibms_init
[i
].param
, ",");
5861 module_param(experimental
, int, 0);
5862 MODULE_PARM_DESC(experimental
,
5863 "Enables experimental features when non-zero");
5865 module_param_named(debug
, dbg_level
, uint
, 0);
5866 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
5868 module_param(force_load
, bool, 0);
5869 MODULE_PARM_DESC(force_load
,
5870 "Attempts to load the driver even on a "
5871 "mis-identified ThinkPad when true");
5873 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
5874 MODULE_PARM_DESC(fan_control
,
5875 "Enables setting fan parameters features when true");
5877 module_param_named(brightness_mode
, brightness_mode
, int, 0);
5878 MODULE_PARM_DESC(brightness_mode
,
5879 "Selects brightness control strategy: "
5880 "0=auto, 1=EC, 2=CMOS, 3=both");
5882 module_param(brightness_enable
, uint
, 0);
5883 MODULE_PARM_DESC(brightness_enable
,
5884 "Enables backlight control when 1, disables when 0");
5886 module_param(hotkey_report_mode
, uint
, 0);
5887 MODULE_PARM_DESC(hotkey_report_mode
,
5888 "used for backwards compatibility with userspace, "
5889 "see documentation");
5891 #define TPACPI_PARAM(feature) \
5892 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
5893 MODULE_PARM_DESC(feature, "Simulates thinkpad-aci procfs command " \
5894 "at module load, see documentation")
5896 TPACPI_PARAM(hotkey
);
5897 TPACPI_PARAM(bluetooth
);
5898 TPACPI_PARAM(video
);
5899 TPACPI_PARAM(light
);
5900 #ifdef CONFIG_THINKPAD_ACPI_DOCK
5903 #ifdef CONFIG_THINKPAD_ACPI_BAY
5905 #endif /* CONFIG_THINKPAD_ACPI_BAY */
5909 TPACPI_PARAM(ecdump
);
5910 TPACPI_PARAM(brightness
);
5911 TPACPI_PARAM(volume
);
5914 static void thinkpad_acpi_module_exit(void)
5916 struct ibm_struct
*ibm
, *itmp
;
5918 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
5920 list_for_each_entry_safe_reverse(ibm
, itmp
,
5921 &tpacpi_all_drivers
,
5926 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
5928 if (tpacpi_inputdev
) {
5929 if (tp_features
.input_device_registered
)
5930 input_unregister_device(tpacpi_inputdev
);
5932 input_free_device(tpacpi_inputdev
);
5936 hwmon_device_unregister(tpacpi_hwmon
);
5938 if (tp_features
.sensors_pdev_attrs_registered
)
5939 device_remove_file(&tpacpi_sensors_pdev
->dev
,
5940 &dev_attr_thinkpad_acpi_pdev_name
);
5941 if (tpacpi_sensors_pdev
)
5942 platform_device_unregister(tpacpi_sensors_pdev
);
5944 platform_device_unregister(tpacpi_pdev
);
5946 if (tp_features
.sensors_pdrv_attrs_registered
)
5947 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
5948 if (tp_features
.platform_drv_attrs_registered
)
5949 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
5951 if (tp_features
.sensors_pdrv_registered
)
5952 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
5954 if (tp_features
.platform_drv_registered
)
5955 platform_driver_unregister(&tpacpi_pdriver
);
5958 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
5960 kfree(thinkpad_id
.bios_version_str
);
5961 kfree(thinkpad_id
.ec_version_str
);
5962 kfree(thinkpad_id
.model_str
);
5966 static int __init
thinkpad_acpi_module_init(void)
5970 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
5972 /* Parameter checking */
5973 if (hotkey_report_mode
> 2)
5976 /* Driver-level probe */
5978 get_thinkpad_model_data(&thinkpad_id
);
5979 ret
= probe_for_thinkpad();
5981 thinkpad_acpi_module_exit();
5985 /* Driver initialization */
5987 TPACPI_ACPIHANDLE_INIT(ecrd
);
5988 TPACPI_ACPIHANDLE_INIT(ecwr
);
5990 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
5993 "unable to create proc dir " TPACPI_PROC_DIR
);
5994 thinkpad_acpi_module_exit();
5997 proc_dir
->owner
= THIS_MODULE
;
5999 ret
= platform_driver_register(&tpacpi_pdriver
);
6002 "unable to register main platform driver\n");
6003 thinkpad_acpi_module_exit();
6006 tp_features
.platform_drv_registered
= 1;
6008 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
6011 "unable to register hwmon platform driver\n");
6012 thinkpad_acpi_module_exit();
6015 tp_features
.sensors_pdrv_registered
= 1;
6017 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
6019 tp_features
.platform_drv_attrs_registered
= 1;
6020 ret
= tpacpi_create_driver_attributes(
6021 &tpacpi_hwmon_pdriver
.driver
);
6025 "unable to create sysfs driver attributes\n");
6026 thinkpad_acpi_module_exit();
6029 tp_features
.sensors_pdrv_attrs_registered
= 1;
6032 /* Device initialization */
6033 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
6035 if (IS_ERR(tpacpi_pdev
)) {
6036 ret
= PTR_ERR(tpacpi_pdev
);
6038 printk(TPACPI_ERR
"unable to register platform device\n");
6039 thinkpad_acpi_module_exit();
6042 tpacpi_sensors_pdev
= platform_device_register_simple(
6043 TPACPI_HWMON_DRVR_NAME
,
6045 if (IS_ERR(tpacpi_sensors_pdev
)) {
6046 ret
= PTR_ERR(tpacpi_sensors_pdev
);
6047 tpacpi_sensors_pdev
= NULL
;
6049 "unable to register hwmon platform device\n");
6050 thinkpad_acpi_module_exit();
6053 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
6054 &dev_attr_thinkpad_acpi_pdev_name
);
6057 "unable to create sysfs hwmon device attributes\n");
6058 thinkpad_acpi_module_exit();
6061 tp_features
.sensors_pdev_attrs_registered
= 1;
6062 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
6063 if (IS_ERR(tpacpi_hwmon
)) {
6064 ret
= PTR_ERR(tpacpi_hwmon
);
6065 tpacpi_hwmon
= NULL
;
6066 printk(TPACPI_ERR
"unable to register hwmon device\n");
6067 thinkpad_acpi_module_exit();
6070 mutex_init(&tpacpi_inputdev_send_mutex
);
6071 tpacpi_inputdev
= input_allocate_device();
6072 if (!tpacpi_inputdev
) {
6073 printk(TPACPI_ERR
"unable to allocate input device\n");
6074 thinkpad_acpi_module_exit();
6077 /* Prepare input device, but don't register */
6078 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
6079 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
6080 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
6081 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
6082 thinkpad_id
.vendor
:
6084 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
6085 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
6087 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
6088 ret
= ibm_init(&ibms_init
[i
]);
6089 if (ret
>= 0 && *ibms_init
[i
].param
)
6090 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
6092 thinkpad_acpi_module_exit();
6096 ret
= input_register_device(tpacpi_inputdev
);
6098 printk(TPACPI_ERR
"unable to register input device\n");
6099 thinkpad_acpi_module_exit();
6102 tp_features
.input_device_registered
= 1;
6105 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
6109 /* Please remove this in year 2009 */
6110 MODULE_ALIAS("ibm_acpi");
6113 * DMI matching for module autoloading
6115 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
6116 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
6118 * Only models listed in thinkwiki will be supported, so add yours
6119 * if it is not there yet.
6121 #define IBM_BIOS_MODULE_ALIAS(__type) \
6122 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
6124 /* Non-ancient thinkpads */
6125 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
6126 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
6128 /* Ancient thinkpad BIOSes have to be identified by
6129 * BIOS type or model number, and there are far less
6130 * BIOS types than model numbers... */
6131 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
6132 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
6133 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
6135 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
6136 MODULE_DESCRIPTION(TPACPI_DESC
);
6137 MODULE_VERSION(TPACPI_VERSION
);
6138 MODULE_LICENSE("GPL");
6140 module_init(thinkpad_acpi_module_init
);
6141 module_exit(thinkpad_acpi_module_exit
);