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 0x020100
29 * 2007-10-20 changelog trimmed down
31 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
34 * 2006-11-22 0.13 new maintainer
35 * changelog now lives in git commit history, and will
36 * not be updated further in-file.
38 * 2005-03-17 0.11 support for 600e, 770x
39 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
41 * 2005-01-16 0.9 use MODULE_VERSION
42 * thanks to Henrik Brix Andersen <brix@gentoo.org>
43 * fix parameter passing on module loading
44 * thanks to Rusty Russell <rusty@rustcorp.com.au>
45 * thanks to Jim Radford <radford@blackbean.org>
46 * 2004-11-08 0.8 fix init error case, don't return from a macro
47 * thanks to Chris Wright <chrisw@osdl.org>
50 #include <linux/kernel.h>
51 #include <linux/module.h>
52 #include <linux/init.h>
53 #include <linux/types.h>
54 #include <linux/string.h>
55 #include <linux/list.h>
56 #include <linux/mutex.h>
57 #include <linux/kthread.h>
58 #include <linux/freezer.h>
59 #include <linux/delay.h>
61 #include <linux/nvram.h>
62 #include <linux/proc_fs.h>
63 #include <linux/sysfs.h>
64 #include <linux/backlight.h>
66 #include <linux/platform_device.h>
67 #include <linux/hwmon.h>
68 #include <linux/hwmon-sysfs.h>
69 #include <linux/input.h>
70 #include <asm/uaccess.h>
72 #include <linux/dmi.h>
73 #include <linux/jiffies.h>
74 #include <linux/workqueue.h>
76 #include <acpi/acpi_drivers.h>
77 #include <acpi/acnamesp.h>
79 #include <linux/pci_ids.h>
82 /* ThinkPad CMOS commands */
83 #define TP_CMOS_VOLUME_DOWN 0
84 #define TP_CMOS_VOLUME_UP 1
85 #define TP_CMOS_VOLUME_MUTE 2
86 #define TP_CMOS_BRIGHTNESS_UP 4
87 #define TP_CMOS_BRIGHTNESS_DOWN 5
91 TP_NVRAM_ADDR_HK2
= 0x57,
92 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
93 TP_NVRAM_ADDR_VIDEO
= 0x59,
94 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
95 TP_NVRAM_ADDR_MIXER
= 0x60,
100 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
101 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
102 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
103 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
104 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
105 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
106 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
107 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
108 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
109 TP_NVRAM_MASK_MUTE
= 0x40,
110 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
111 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
112 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
116 #define TPACPI_ACPI_HKEY_HID "IBM0068"
119 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
120 #define TPACPI_HKEY_INPUT_VERSION 0x4101
123 /****************************************************************************
127 #define TPACPI_NAME "thinkpad"
128 #define TPACPI_DESC "ThinkPad ACPI Extras"
129 #define TPACPI_FILE TPACPI_NAME "_acpi"
130 #define TPACPI_URL "http://ibm-acpi.sf.net/"
131 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
133 #define TPACPI_PROC_DIR "ibm"
134 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
135 #define TPACPI_DRVR_NAME TPACPI_FILE
136 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
138 #define TPACPI_MAX_ACPI_ARGS 3
141 #define TPACPI_LOG TPACPI_FILE ": "
142 #define TPACPI_ERR KERN_ERR TPACPI_LOG
143 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
144 #define TPACPI_INFO KERN_INFO TPACPI_LOG
145 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
147 #define TPACPI_DBG_ALL 0xffff
148 #define TPACPI_DBG_ALL 0xffff
149 #define TPACPI_DBG_INIT 0x0001
150 #define TPACPI_DBG_EXIT 0x0002
151 #define dbg_printk(a_dbg_level, format, arg...) \
152 do { if (dbg_level & a_dbg_level) \
153 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); \
155 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
156 #define vdbg_printk(a_dbg_level, format, arg...) \
157 dbg_printk(a_dbg_level, format, ## arg)
158 static const char *str_supported(int is_supported
);
160 #define vdbg_printk(a_dbg_level, format, arg...)
163 #define onoff(status, bit) ((status) & (1 << (bit)) ? "on" : "off")
164 #define enabled(status, bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
165 #define strlencmp(a, b) (strncmp((a), (b), strlen(b)))
168 /****************************************************************************
169 * Driver-wide structs and misc. variables
174 struct tp_acpi_drv_struct
{
175 const struct acpi_device_id
*hid
;
176 struct acpi_driver
*driver
;
178 void (*notify
) (struct ibm_struct
*, u32
);
181 struct acpi_device
*device
;
187 int (*read
) (char *);
188 int (*write
) (char *);
190 void (*resume
) (void);
191 void (*suspend
) (pm_message_t state
);
193 struct list_head all_drivers
;
195 struct tp_acpi_drv_struct
*acpi
;
198 u8 acpi_driver_registered
:1;
199 u8 acpi_notify_installed
:1;
206 struct ibm_init_struct
{
209 int (*init
) (struct ibm_init_struct
*);
210 struct ibm_struct
*data
;
214 #ifdef CONFIG_THINKPAD_ACPI_BAY
226 u32 bright_16levels
:1;
228 u32 fan_ctrl_status_undef
:1;
229 u32 input_device_registered
:1;
230 u32 platform_drv_registered
:1;
231 u32 platform_drv_attrs_registered
:1;
232 u32 sensors_pdrv_registered
:1;
233 u32 sensors_pdrv_attrs_registered
:1;
234 u32 sensors_pdev_attrs_registered
:1;
235 u32 hotkey_poll_active
:1;
238 struct thinkpad_id_data
{
239 unsigned int vendor
; /* ThinkPad vendor:
240 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
242 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
243 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
245 u16 bios_model
; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */
250 static struct thinkpad_id_data thinkpad_id
;
253 TPACPI_LIFE_INIT
= 0,
258 static int experimental
;
259 static u32 dbg_level
;
261 /****************************************************************************
262 ****************************************************************************
264 * ACPI Helpers and device model
266 ****************************************************************************
267 ****************************************************************************/
269 /*************************************************************************
273 static acpi_handle root_handle
;
275 #define TPACPI_HANDLE(object, parent, paths...) \
276 static acpi_handle object##_handle; \
277 static acpi_handle *object##_parent = &parent##_handle; \
278 static char *object##_path; \
279 static char *object##_paths[] = { paths }
281 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
282 "\\_SB.PCI.ISA.EC", /* 570 */
283 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
284 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
285 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
286 "\\_SB.PCI0.ICH3.EC0", /* R31 */
287 "\\_SB.PCI0.LPC.EC", /* all others */
290 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
291 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
293 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
295 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
296 "\\CMS", /* R40, R40e */
299 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
300 "^HKEY", /* R30, R31 */
301 "HKEY", /* all others */
305 /*************************************************************************
309 static int acpi_evalf(acpi_handle handle
,
310 void *res
, char *method
, char *fmt
, ...)
313 struct acpi_object_list params
;
314 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
315 struct acpi_buffer result
, *resultp
;
316 union acpi_object out_obj
;
324 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
337 params
.pointer
= &in_objs
[0];
344 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
345 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
347 /* add more types as needed */
349 printk(TPACPI_ERR
"acpi_evalf() called "
350 "with invalid format character '%c'\n", c
);
356 if (res_type
!= 'v') {
357 result
.length
= sizeof(out_obj
);
358 result
.pointer
= &out_obj
;
363 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
368 *(int *)res
= out_obj
.integer
.value
;
369 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
372 success
= status
== AE_OK
;
374 /* add more types as needed */
376 printk(TPACPI_ERR
"acpi_evalf() called "
377 "with invalid format character '%c'\n", res_type
);
381 if (!success
&& !quiet
)
382 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
383 method
, fmt0
, status
);
388 static int acpi_ec_read(int i
, u8
*p
)
393 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
397 if (ec_read(i
, p
) < 0)
404 static int acpi_ec_write(int i
, u8 v
)
407 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
410 if (ec_write(i
, v
) < 0)
417 static int _sta(acpi_handle handle
)
421 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
427 static int issue_thinkpad_cmos_command(int cmos_cmd
)
432 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
438 /*************************************************************************
442 #define TPACPI_ACPIHANDLE_INIT(object) \
443 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
444 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
446 static void drv_acpi_handle_init(char *name
,
447 acpi_handle
*handle
, acpi_handle parent
,
448 char **paths
, int num_paths
, char **path
)
453 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
456 for (i
= 0; i
< num_paths
; i
++) {
457 status
= acpi_get_handle(parent
, paths
[i
], handle
);
458 if (ACPI_SUCCESS(status
)) {
460 dbg_printk(TPACPI_DBG_INIT
,
461 "Found ACPI handle %s for %s\n",
467 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
472 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
474 struct ibm_struct
*ibm
= data
;
476 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
479 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
482 ibm
->acpi
->notify(ibm
, event
);
485 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
492 if (!*ibm
->acpi
->handle
)
495 vdbg_printk(TPACPI_DBG_INIT
,
496 "setting up ACPI notify for %s\n", ibm
->name
);
498 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
500 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
505 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
506 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
507 TPACPI_ACPI_EVENT_PREFIX
,
510 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
511 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
512 if (ACPI_FAILURE(status
)) {
513 if (status
== AE_ALREADY_EXISTS
) {
515 "another device driver is already "
516 "handling %s events\n", ibm
->name
);
519 "acpi_install_notify_handler(%s) failed: %d\n",
524 ibm
->flags
.acpi_notify_installed
= 1;
528 static int __init
tpacpi_device_add(struct acpi_device
*device
)
533 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
537 dbg_printk(TPACPI_DBG_INIT
,
538 "registering %s as an ACPI driver\n", ibm
->name
);
542 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
543 if (!ibm
->acpi
->driver
) {
544 printk(TPACPI_ERR
"kzalloc(ibm->driver) failed\n");
548 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
549 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
551 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
553 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
555 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
557 kfree(ibm
->acpi
->driver
);
558 ibm
->acpi
->driver
= NULL
;
560 ibm
->flags
.acpi_driver_registered
= 1;
566 /****************************************************************************
567 ****************************************************************************
571 ****************************************************************************
572 ****************************************************************************/
574 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
575 int count
, int *eof
, void *data
)
577 struct ibm_struct
*ibm
= data
;
580 if (!ibm
|| !ibm
->read
)
583 len
= ibm
->read(page
);
587 if (len
<= off
+ count
)
599 static int dispatch_procfs_write(struct file
*file
,
600 const char __user
*userbuf
,
601 unsigned long count
, void *data
)
603 struct ibm_struct
*ibm
= data
;
607 if (!ibm
|| !ibm
->write
)
610 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
614 if (copy_from_user(kernbuf
, userbuf
, count
)) {
620 strcat(kernbuf
, ",");
621 ret
= ibm
->write(kernbuf
);
630 static char *next_cmd(char **cmds
)
635 while ((end
= strchr(start
, ',')) && end
== start
)
647 /****************************************************************************
648 ****************************************************************************
650 * Device model: input, hwmon and platform
652 ****************************************************************************
653 ****************************************************************************/
655 static struct platform_device
*tpacpi_pdev
;
656 static struct platform_device
*tpacpi_sensors_pdev
;
657 static struct device
*tpacpi_hwmon
;
658 static struct input_dev
*tpacpi_inputdev
;
659 static struct mutex tpacpi_inputdev_send_mutex
;
660 static LIST_HEAD(tpacpi_all_drivers
);
662 static int tpacpi_suspend_handler(struct platform_device
*pdev
,
665 struct ibm_struct
*ibm
, *itmp
;
667 list_for_each_entry_safe(ibm
, itmp
,
671 (ibm
->suspend
)(state
);
677 static int tpacpi_resume_handler(struct platform_device
*pdev
)
679 struct ibm_struct
*ibm
, *itmp
;
681 list_for_each_entry_safe(ibm
, itmp
,
691 static struct platform_driver tpacpi_pdriver
= {
693 .name
= TPACPI_DRVR_NAME
,
694 .owner
= THIS_MODULE
,
696 .suspend
= tpacpi_suspend_handler
,
697 .resume
= tpacpi_resume_handler
,
700 static struct platform_driver tpacpi_hwmon_pdriver
= {
702 .name
= TPACPI_HWMON_DRVR_NAME
,
703 .owner
= THIS_MODULE
,
707 /*************************************************************************
708 * sysfs support helpers
711 struct attribute_set
{
712 unsigned int members
, max_members
;
713 struct attribute_group group
;
716 struct attribute_set_obj
{
717 struct attribute_set s
;
719 } __attribute__((packed
));
721 static struct attribute_set
*create_attr_set(unsigned int max_members
,
724 struct attribute_set_obj
*sobj
;
726 if (max_members
== 0)
729 /* Allocates space for implicit NULL at the end too */
730 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
731 max_members
* sizeof(struct attribute
*),
735 sobj
->s
.max_members
= max_members
;
736 sobj
->s
.group
.attrs
= &sobj
->a
;
737 sobj
->s
.group
.name
= name
;
742 #define destroy_attr_set(_set) \
745 /* not multi-threaded safe, use it in a single thread per set */
746 static int add_to_attr_set(struct attribute_set
*s
, struct attribute
*attr
)
751 if (s
->members
>= s
->max_members
)
754 s
->group
.attrs
[s
->members
] = attr
;
760 static int add_many_to_attr_set(struct attribute_set
*s
,
761 struct attribute
**attr
,
766 for (i
= 0; i
< count
; i
++) {
767 res
= add_to_attr_set(s
, attr
[i
]);
775 static void delete_attr_set(struct attribute_set
*s
, struct kobject
*kobj
)
777 sysfs_remove_group(kobj
, &s
->group
);
781 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
782 sysfs_create_group(_kobj, &_attr_set->group)
784 static int parse_strtoul(const char *buf
,
785 unsigned long max
, unsigned long *value
)
789 while (*buf
&& isspace(*buf
))
791 *value
= simple_strtoul(buf
, &endp
, 0);
792 while (*endp
&& isspace(*endp
))
794 if (*endp
|| *value
> max
)
800 /*************************************************************************
801 * thinkpad-acpi driver attributes
804 /* interface_version --------------------------------------------------- */
805 static ssize_t
tpacpi_driver_interface_version_show(
806 struct device_driver
*drv
,
809 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
812 static DRIVER_ATTR(interface_version
, S_IRUGO
,
813 tpacpi_driver_interface_version_show
, NULL
);
815 /* debug_level --------------------------------------------------------- */
816 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
819 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
822 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
823 const char *buf
, size_t count
)
827 if (parse_strtoul(buf
, 0xffff, &t
))
835 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
836 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
838 /* version ------------------------------------------------------------- */
839 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
842 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n",
843 TPACPI_DESC
, TPACPI_VERSION
);
846 static DRIVER_ATTR(version
, S_IRUGO
,
847 tpacpi_driver_version_show
, NULL
);
849 /* --------------------------------------------------------------------- */
851 static struct driver_attribute
*tpacpi_driver_attributes
[] = {
852 &driver_attr_debug_level
, &driver_attr_version
,
853 &driver_attr_interface_version
,
856 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
862 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
863 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
870 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
874 for (i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
875 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
878 /****************************************************************************
879 ****************************************************************************
883 ****************************************************************************
884 ****************************************************************************/
886 /*************************************************************************
887 * thinkpad-acpi init subdriver
890 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
892 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
893 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
895 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
896 (thinkpad_id
.bios_version_str
) ?
897 thinkpad_id
.bios_version_str
: "unknown",
898 (thinkpad_id
.ec_version_str
) ?
899 thinkpad_id
.ec_version_str
: "unknown");
901 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
902 printk(TPACPI_INFO
"%s %s\n",
903 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
904 "IBM" : ((thinkpad_id
.vendor
==
905 PCI_VENDOR_ID_LENOVO
) ?
906 "Lenovo" : "Unknown vendor"),
907 thinkpad_id
.model_str
);
912 static int thinkpad_acpi_driver_read(char *p
)
916 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
917 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
922 static struct ibm_struct thinkpad_acpi_driver_data
= {
924 .read
= thinkpad_acpi_driver_read
,
927 /*************************************************************************
931 enum { /* hot key scan codes (derived from ACPI DSDT) */
932 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
933 TP_ACPI_HOTKEYSCAN_FNF2
,
934 TP_ACPI_HOTKEYSCAN_FNF3
,
935 TP_ACPI_HOTKEYSCAN_FNF4
,
936 TP_ACPI_HOTKEYSCAN_FNF5
,
937 TP_ACPI_HOTKEYSCAN_FNF6
,
938 TP_ACPI_HOTKEYSCAN_FNF7
,
939 TP_ACPI_HOTKEYSCAN_FNF8
,
940 TP_ACPI_HOTKEYSCAN_FNF9
,
941 TP_ACPI_HOTKEYSCAN_FNF10
,
942 TP_ACPI_HOTKEYSCAN_FNF11
,
943 TP_ACPI_HOTKEYSCAN_FNF12
,
944 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
945 TP_ACPI_HOTKEYSCAN_FNINSERT
,
946 TP_ACPI_HOTKEYSCAN_FNDELETE
,
947 TP_ACPI_HOTKEYSCAN_FNHOME
,
948 TP_ACPI_HOTKEYSCAN_FNEND
,
949 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
950 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
951 TP_ACPI_HOTKEYSCAN_FNSPACE
,
952 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
953 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
954 TP_ACPI_HOTKEYSCAN_MUTE
,
955 TP_ACPI_HOTKEYSCAN_THINKPAD
,
958 enum { /* Keys available through NVRAM polling */
959 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
960 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
963 enum { /* Positions of some of the keys in hotkey masks */
964 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
965 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
966 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
967 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
968 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
969 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
970 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
971 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
972 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
973 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
974 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
977 enum { /* NVRAM to ACPI HKEY group map */
978 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
979 TP_ACPI_HKEY_ZOOM_MASK
|
980 TP_ACPI_HKEY_DISPSWTCH_MASK
|
981 TP_ACPI_HKEY_HIBERNATE_MASK
,
982 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
983 TP_ACPI_HKEY_BRGHTDWN_MASK
,
984 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
985 TP_ACPI_HKEY_VOLDWN_MASK
|
986 TP_ACPI_HKEY_MUTE_MASK
,
989 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
990 struct tp_nvram_state
{
991 u16 thinkpad_toggle
:1;
993 u16 display_toggle
:1;
994 u16 thinklight_toggle
:1;
995 u16 hibernate_toggle
:1;
996 u16 displayexp_toggle
:1;
998 u16 brightness_toggle
:1;
1002 u8 brightness_level
;
1006 static struct task_struct
*tpacpi_hotkey_task
;
1007 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
1008 static int hotkey_poll_freq
= 10; /* Hz */
1009 static struct mutex hotkey_thread_mutex
;
1010 static struct mutex hotkey_thread_data_mutex
;
1011 static unsigned int hotkey_config_change
;
1013 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1015 #define hotkey_source_mask 0U
1017 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1019 static struct mutex hotkey_mutex
;
1021 static enum { /* Reasons for waking up */
1022 TP_ACPI_WAKEUP_NONE
= 0, /* None or unknown */
1023 TP_ACPI_WAKEUP_BAYEJ
, /* Bay ejection request */
1024 TP_ACPI_WAKEUP_UNDOCK
, /* Undock request */
1025 } hotkey_wakeup_reason
;
1027 static int hotkey_autosleep_ack
;
1029 static int hotkey_orig_status
;
1030 static u32 hotkey_orig_mask
;
1031 static u32 hotkey_all_mask
;
1032 static u32 hotkey_reserved_mask
;
1033 static u32 hotkey_mask
;
1035 static unsigned int hotkey_report_mode
;
1037 static u16
*hotkey_keycode_map
;
1039 static struct attribute_set
*hotkey_dev_attributes
;
1041 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1042 #define HOTKEY_CONFIG_CRITICAL_START \
1044 mutex_lock(&hotkey_thread_data_mutex); \
1045 hotkey_config_change++; \
1047 #define HOTKEY_CONFIG_CRITICAL_END \
1048 mutex_unlock(&hotkey_thread_data_mutex);
1050 #define HOTKEY_CONFIG_CRITICAL_START
1051 #define HOTKEY_CONFIG_CRITICAL_END
1052 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1054 static int hotkey_get_wlsw(int *status
)
1056 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1062 * Call with hotkey_mutex held
1064 static int hotkey_mask_get(void)
1068 if (tp_features
.hotkey_mask
) {
1069 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1071 hotkey_mask
= m
| (hotkey_source_mask
& hotkey_mask
);
1078 * Call with hotkey_mutex held
1080 static int hotkey_mask_set(u32 mask
)
1085 if (tp_features
.hotkey_mask
) {
1086 HOTKEY_CONFIG_CRITICAL_START
1087 for (i
= 0; i
< 32; i
++) {
1089 if (!acpi_evalf(hkey_handle
,
1090 NULL
, "MHKM", "vdd", i
+ 1,
1095 hotkey_mask
= (hotkey_mask
& ~m
) | (mask
& m
);
1098 HOTKEY_CONFIG_CRITICAL_END
1100 /* hotkey_mask_get must be called unconditionally below */
1101 if (!hotkey_mask_get() && !rc
&&
1102 (hotkey_mask
& ~hotkey_source_mask
) !=
1103 (mask
& ~hotkey_source_mask
)) {
1104 printk(TPACPI_NOTICE
1105 "requested hot key mask 0x%08x, but "
1106 "firmware forced it to 0x%08x\n",
1114 static int hotkey_status_get(int *status
)
1116 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1122 static int hotkey_status_set(int status
)
1124 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1130 static void tpacpi_input_send_radiosw(void)
1134 mutex_lock(&tpacpi_inputdev_send_mutex
);
1136 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
1137 input_report_switch(tpacpi_inputdev
,
1139 input_sync(tpacpi_inputdev
);
1142 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1145 static void tpacpi_input_send_key(unsigned int scancode
)
1147 unsigned int keycode
;
1149 keycode
= hotkey_keycode_map
[scancode
];
1151 if (keycode
!= KEY_RESERVED
) {
1152 mutex_lock(&tpacpi_inputdev_send_mutex
);
1154 input_report_key(tpacpi_inputdev
, keycode
, 1);
1155 if (keycode
== KEY_UNKNOWN
)
1156 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1158 input_sync(tpacpi_inputdev
);
1160 input_report_key(tpacpi_inputdev
, keycode
, 0);
1161 if (keycode
== KEY_UNKNOWN
)
1162 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1164 input_sync(tpacpi_inputdev
);
1166 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1170 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1171 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
1173 static void tpacpi_hotkey_send_key(unsigned int scancode
)
1175 tpacpi_input_send_key(scancode
);
1176 if (hotkey_report_mode
< 2) {
1177 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
1178 0x80, 0x1001 + scancode
);
1182 static void hotkey_read_nvram(struct tp_nvram_state
*n
, u32 m
)
1186 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
1187 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
1188 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
1189 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
1190 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
1191 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
1193 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
1194 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
1195 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
1197 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
1198 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
1199 n
->displayexp_toggle
=
1200 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
1202 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
1203 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
1204 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
1205 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
1206 n
->brightness_toggle
=
1207 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
1209 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
1210 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
1211 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
1212 >> TP_NVRAM_POS_LEVEL_VOLUME
;
1213 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
1214 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
1218 #define TPACPI_COMPARE_KEY(__scancode, __member) \
1220 if ((mask & (1 << __scancode)) && \
1221 oldn->__member != newn->__member) \
1222 tpacpi_hotkey_send_key(__scancode); \
1225 #define TPACPI_MAY_SEND_KEY(__scancode) \
1226 do { if (mask & (1 << __scancode)) \
1227 tpacpi_hotkey_send_key(__scancode); } while (0)
1229 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
1230 struct tp_nvram_state
*newn
,
1236 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
1237 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
1238 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
1239 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
1241 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
1243 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
1246 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
1247 if (oldn
->mute
!= newn
->mute
) {
1248 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1250 if (oldn
->volume_level
> newn
->volume_level
) {
1251 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1252 } else if (oldn
->volume_level
< newn
->volume_level
) {
1253 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1254 } else if (oldn
->mute
== newn
->mute
) {
1255 /* repeated key presses that didn't change state */
1257 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1258 } else if (newn
->volume_level
!= 0) {
1259 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1261 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1266 /* handle brightness */
1267 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
1268 if (oldn
->brightness_level
< newn
->brightness_level
) {
1269 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1270 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
1271 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1273 /* repeated key presses that didn't change state */
1274 if (newn
->brightness_level
!= 0) {
1275 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1277 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1283 #undef TPACPI_COMPARE_KEY
1284 #undef TPACPI_MAY_SEND_KEY
1286 static int hotkey_kthread(void *data
)
1288 struct tp_nvram_state s
[2];
1290 unsigned int si
, so
;
1292 unsigned int change_detector
, must_reset
;
1294 mutex_lock(&hotkey_thread_mutex
);
1296 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
1305 /* Initial state for compares */
1306 mutex_lock(&hotkey_thread_data_mutex
);
1307 change_detector
= hotkey_config_change
;
1308 mask
= hotkey_source_mask
& hotkey_mask
;
1309 mutex_unlock(&hotkey_thread_data_mutex
);
1310 hotkey_read_nvram(&s
[so
], mask
);
1312 while (!kthread_should_stop() && hotkey_poll_freq
) {
1314 t
= 1000/hotkey_poll_freq
;
1315 t
= msleep_interruptible(t
);
1316 if (unlikely(kthread_should_stop()))
1318 must_reset
= try_to_freeze();
1319 if (t
> 0 && !must_reset
)
1322 mutex_lock(&hotkey_thread_data_mutex
);
1323 if (must_reset
|| hotkey_config_change
!= change_detector
) {
1324 /* forget old state on thaw or config change */
1327 change_detector
= hotkey_config_change
;
1329 mask
= hotkey_source_mask
& hotkey_mask
;
1330 mutex_unlock(&hotkey_thread_data_mutex
);
1332 hotkey_read_nvram(&s
[si
], mask
);
1333 hotkey_compare_and_issue_event(&s
[so
], &s
[si
], mask
);
1340 mutex_unlock(&hotkey_thread_mutex
);
1344 static void hotkey_poll_stop_sync(void)
1346 if (tpacpi_hotkey_task
) {
1347 if (frozen(tpacpi_hotkey_task
) ||
1348 freezing(tpacpi_hotkey_task
))
1349 thaw_process(tpacpi_hotkey_task
);
1351 kthread_stop(tpacpi_hotkey_task
);
1352 tpacpi_hotkey_task
= NULL
;
1353 mutex_lock(&hotkey_thread_mutex
);
1354 /* at this point, the thread did exit */
1355 mutex_unlock(&hotkey_thread_mutex
);
1359 /* call with hotkey_mutex held */
1360 static void hotkey_poll_setup(int may_warn
)
1362 if ((hotkey_source_mask
& hotkey_mask
) != 0 &&
1363 hotkey_poll_freq
> 0 &&
1364 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1365 if (!tpacpi_hotkey_task
) {
1366 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1369 if (IS_ERR(tpacpi_hotkey_task
)) {
1370 tpacpi_hotkey_task
= NULL
;
1372 "could not create kernel thread "
1373 "for hotkey polling\n");
1377 hotkey_poll_stop_sync();
1379 hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1380 printk(TPACPI_NOTICE
1381 "hot keys 0x%08x require polling, "
1382 "which is currently disabled\n",
1383 hotkey_source_mask
);
1388 static void hotkey_poll_setup_safe(int may_warn
)
1390 mutex_lock(&hotkey_mutex
);
1391 hotkey_poll_setup(may_warn
);
1392 mutex_unlock(&hotkey_mutex
);
1395 static int hotkey_inputdev_open(struct input_dev
*dev
)
1397 switch (tpacpi_lifecycle
) {
1398 case TPACPI_LIFE_INIT
:
1400 * hotkey_init will call hotkey_poll_setup_safe
1401 * at the appropriate moment
1404 case TPACPI_LIFE_EXITING
:
1406 case TPACPI_LIFE_RUNNING
:
1407 hotkey_poll_setup_safe(0);
1411 /* Should only happen if tpacpi_lifecycle is corrupt */
1416 static void hotkey_inputdev_close(struct input_dev
*dev
)
1418 /* disable hotkey polling when possible */
1419 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
)
1420 hotkey_poll_setup_safe(0);
1422 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1424 /* sysfs hotkey enable ------------------------------------------------- */
1425 static ssize_t
hotkey_enable_show(struct device
*dev
,
1426 struct device_attribute
*attr
,
1431 res
= hotkey_status_get(&status
);
1435 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1438 static ssize_t
hotkey_enable_store(struct device
*dev
,
1439 struct device_attribute
*attr
,
1440 const char *buf
, size_t count
)
1445 if (parse_strtoul(buf
, 1, &t
))
1448 res
= hotkey_status_set(t
);
1450 return (res
) ? res
: count
;
1453 static struct device_attribute dev_attr_hotkey_enable
=
1454 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
1455 hotkey_enable_show
, hotkey_enable_store
);
1457 /* sysfs hotkey mask --------------------------------------------------- */
1458 static ssize_t
hotkey_mask_show(struct device
*dev
,
1459 struct device_attribute
*attr
,
1464 if (mutex_lock_interruptible(&hotkey_mutex
))
1465 return -ERESTARTSYS
;
1466 res
= hotkey_mask_get();
1467 mutex_unlock(&hotkey_mutex
);
1470 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
1473 static ssize_t
hotkey_mask_store(struct device
*dev
,
1474 struct device_attribute
*attr
,
1475 const char *buf
, size_t count
)
1480 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
1483 if (mutex_lock_interruptible(&hotkey_mutex
))
1484 return -ERESTARTSYS
;
1486 res
= hotkey_mask_set(t
);
1488 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1489 hotkey_poll_setup(1);
1492 mutex_unlock(&hotkey_mutex
);
1494 return (res
) ? res
: count
;
1497 static struct device_attribute dev_attr_hotkey_mask
=
1498 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
1499 hotkey_mask_show
, hotkey_mask_store
);
1501 /* sysfs hotkey bios_enabled ------------------------------------------- */
1502 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
1503 struct device_attribute
*attr
,
1506 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
1509 static struct device_attribute dev_attr_hotkey_bios_enabled
=
1510 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
1512 /* sysfs hotkey bios_mask ---------------------------------------------- */
1513 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
1514 struct device_attribute
*attr
,
1517 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
1520 static struct device_attribute dev_attr_hotkey_bios_mask
=
1521 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
1523 /* sysfs hotkey all_mask ----------------------------------------------- */
1524 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
1525 struct device_attribute
*attr
,
1528 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1529 hotkey_all_mask
| hotkey_source_mask
);
1532 static struct device_attribute dev_attr_hotkey_all_mask
=
1533 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
1535 /* sysfs hotkey recommended_mask --------------------------------------- */
1536 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
1537 struct device_attribute
*attr
,
1540 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1541 (hotkey_all_mask
| hotkey_source_mask
)
1542 & ~hotkey_reserved_mask
);
1545 static struct device_attribute dev_attr_hotkey_recommended_mask
=
1546 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
1547 hotkey_recommended_mask_show
, NULL
);
1549 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1551 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
1552 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
1553 struct device_attribute
*attr
,
1556 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
1559 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
1560 struct device_attribute
*attr
,
1561 const char *buf
, size_t count
)
1565 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
1566 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
1569 if (mutex_lock_interruptible(&hotkey_mutex
))
1570 return -ERESTARTSYS
;
1572 HOTKEY_CONFIG_CRITICAL_START
1573 hotkey_source_mask
= t
;
1574 HOTKEY_CONFIG_CRITICAL_END
1576 hotkey_poll_setup(1);
1578 mutex_unlock(&hotkey_mutex
);
1583 static struct device_attribute dev_attr_hotkey_source_mask
=
1584 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
1585 hotkey_source_mask_show
, hotkey_source_mask_store
);
1587 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
1588 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
1589 struct device_attribute
*attr
,
1592 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
1595 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
1596 struct device_attribute
*attr
,
1597 const char *buf
, size_t count
)
1601 if (parse_strtoul(buf
, 25, &t
))
1604 if (mutex_lock_interruptible(&hotkey_mutex
))
1605 return -ERESTARTSYS
;
1607 hotkey_poll_freq
= t
;
1609 hotkey_poll_setup(1);
1610 mutex_unlock(&hotkey_mutex
);
1615 static struct device_attribute dev_attr_hotkey_poll_freq
=
1616 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
1617 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
1619 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1621 /* sysfs hotkey radio_sw ----------------------------------------------- */
1622 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
1623 struct device_attribute
*attr
,
1627 res
= hotkey_get_wlsw(&s
);
1631 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1634 static struct device_attribute dev_attr_hotkey_radio_sw
=
1635 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
1637 /* sysfs hotkey report_mode -------------------------------------------- */
1638 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
1639 struct device_attribute
*attr
,
1642 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1643 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
1646 static struct device_attribute dev_attr_hotkey_report_mode
=
1647 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
1649 /* sysfs wakeup reason ------------------------------------------------- */
1650 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
1651 struct device_attribute
*attr
,
1654 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
1657 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
1658 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
1660 /* sysfs wakeup hotunplug_complete ------------------------------------- */
1661 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
1662 struct device_attribute
*attr
,
1665 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
1668 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
1669 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
1670 hotkey_wakeup_hotunplug_complete_show
, NULL
);
1672 /* --------------------------------------------------------------------- */
1674 static struct attribute
*hotkey_attributes
[] __initdata
= {
1675 &dev_attr_hotkey_enable
.attr
,
1676 &dev_attr_hotkey_report_mode
.attr
,
1679 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
1680 &dev_attr_hotkey_mask
.attr
,
1681 &dev_attr_hotkey_bios_enabled
.attr
,
1682 &dev_attr_hotkey_bios_mask
.attr
,
1683 &dev_attr_hotkey_all_mask
.attr
,
1684 &dev_attr_hotkey_recommended_mask
.attr
,
1685 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1686 &dev_attr_hotkey_source_mask
.attr
,
1687 &dev_attr_hotkey_poll_freq
.attr
,
1689 &dev_attr_hotkey_wakeup_reason
.attr
,
1690 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
1693 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
1696 static u16 ibm_keycode_map
[] __initdata
= {
1697 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1698 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
1699 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1700 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1701 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
1702 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1703 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1704 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1705 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1706 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
1707 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1708 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1709 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1710 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1711 KEY_RESERVED
, /* 0x14: VOLUME UP */
1712 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1713 KEY_RESERVED
, /* 0x16: MUTE */
1714 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1715 /* (assignments unknown, please report if found) */
1716 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1717 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1719 static u16 lenovo_keycode_map
[] __initdata
= {
1720 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1721 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
1722 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1723 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1724 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
1725 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1726 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1727 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1728 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
1729 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
1730 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
1731 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1732 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1733 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1734 KEY_RESERVED
, /* 0x14: VOLUME UP */
1735 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1736 KEY_RESERVED
, /* 0x16: MUTE */
1737 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1738 /* (assignments unknown, please report if found) */
1739 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1740 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1743 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
1744 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
1745 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
1751 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
1753 BUG_ON(!tpacpi_inputdev
);
1754 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
1755 tpacpi_inputdev
->close
!= NULL
);
1757 TPACPI_ACPIHANDLE_INIT(hkey
);
1758 mutex_init(&hotkey_mutex
);
1760 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1761 mutex_init(&hotkey_thread_mutex
);
1762 mutex_init(&hotkey_thread_data_mutex
);
1765 /* hotkey not supported on 570 */
1766 tp_features
.hotkey
= hkey_handle
!= NULL
;
1768 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
1769 str_supported(tp_features
.hotkey
));
1771 if (tp_features
.hotkey
) {
1772 hotkey_dev_attributes
= create_attr_set(12, NULL
);
1773 if (!hotkey_dev_attributes
)
1775 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1777 ARRAY_SIZE(hotkey_attributes
));
1781 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1782 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
1783 for HKEY interface version 0x100 */
1784 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
1785 if ((hkeyv
>> 8) != 1) {
1786 printk(TPACPI_ERR
"unknown version of the "
1787 "HKEY interface: 0x%x\n", hkeyv
);
1788 printk(TPACPI_ERR
"please report this to %s\n",
1792 * MHKV 0x100 in A31, R40, R40e,
1793 * T4x, X31, and later
1795 tp_features
.hotkey_mask
= 1;
1799 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
1800 str_supported(tp_features
.hotkey_mask
));
1802 if (tp_features
.hotkey_mask
) {
1803 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
1806 "missing MHKA handler, "
1807 "please report this to %s\n",
1809 /* FN+F12, FN+F4, FN+F3 */
1810 hotkey_all_mask
= 0x080cU
;
1814 /* hotkey_source_mask *must* be zero for
1815 * the first hotkey_mask_get */
1816 res
= hotkey_status_get(&hotkey_orig_status
);
1817 if (!res
&& tp_features
.hotkey_mask
) {
1818 res
= hotkey_mask_get();
1819 hotkey_orig_mask
= hotkey_mask
;
1821 res
= add_many_to_attr_set(
1822 hotkey_dev_attributes
,
1823 hotkey_mask_attributes
,
1824 ARRAY_SIZE(hotkey_mask_attributes
));
1828 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1829 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
1832 vdbg_printk(TPACPI_DBG_INIT
,
1833 "hotkey source mask 0x%08x, polling freq %d\n",
1834 hotkey_source_mask
, hotkey_poll_freq
);
1837 /* Not all thinkpads have a hardware radio switch */
1838 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
1839 tp_features
.hotkey_wlsw
= 1;
1841 "radio switch found; radios are %s\n",
1842 enabled(status
, 0));
1843 res
= add_to_attr_set(hotkey_dev_attributes
,
1844 &dev_attr_hotkey_radio_sw
.attr
);
1848 res
= register_attr_set_with_sysfs(
1849 hotkey_dev_attributes
,
1850 &tpacpi_pdev
->dev
.kobj
);
1854 /* Set up key map */
1856 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
1858 if (!hotkey_keycode_map
) {
1860 "failed to allocate memory for key map\n");
1864 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
1865 dbg_printk(TPACPI_DBG_INIT
,
1866 "using Lenovo default hot key map\n");
1867 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
1868 TPACPI_HOTKEY_MAP_SIZE
);
1870 dbg_printk(TPACPI_DBG_INIT
,
1871 "using IBM default hot key map\n");
1872 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
1873 TPACPI_HOTKEY_MAP_SIZE
);
1876 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
1877 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
1878 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
1879 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
1880 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
1881 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
1882 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
1883 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
1884 set_bit(hotkey_keycode_map
[i
],
1885 tpacpi_inputdev
->keybit
);
1887 if (i
< sizeof(hotkey_reserved_mask
)*8)
1888 hotkey_reserved_mask
|= 1 << i
;
1892 if (tp_features
.hotkey_wlsw
) {
1893 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
1894 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
1897 dbg_printk(TPACPI_DBG_INIT
,
1898 "enabling hot key handling\n");
1899 res
= hotkey_status_set(1);
1902 res
= hotkey_mask_set(((hotkey_all_mask
| hotkey_source_mask
)
1903 & ~hotkey_reserved_mask
)
1904 | hotkey_orig_mask
);
1908 dbg_printk(TPACPI_DBG_INIT
,
1909 "legacy hot key reporting over procfs %s\n",
1910 (hotkey_report_mode
< 2) ?
1911 "enabled" : "disabled");
1913 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1914 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
1915 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
1917 hotkey_poll_setup_safe(1);
1921 return (tp_features
.hotkey
)? 0 : 1;
1924 static void hotkey_exit(void)
1926 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1927 hotkey_poll_stop_sync();
1930 if (tp_features
.hotkey
) {
1931 dbg_printk(TPACPI_DBG_EXIT
,
1932 "restoring original hot key mask\n");
1933 /* no short-circuit boolean operator below! */
1934 if ((hotkey_mask_set(hotkey_orig_mask
) |
1935 hotkey_status_set(hotkey_orig_status
)) != 0)
1937 "failed to restore hot key mask "
1938 "to BIOS defaults\n");
1941 if (hotkey_dev_attributes
) {
1942 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
1943 hotkey_dev_attributes
= NULL
;
1947 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
1950 unsigned int scancode
;
1955 if (event
!= 0x80) {
1957 "unknown HKEY notification event %d\n", event
);
1958 /* forward it to userspace, maybe it knows how to handle it */
1959 acpi_bus_generate_netlink_event(
1960 ibm
->acpi
->device
->pnp
.device_class
,
1961 ibm
->acpi
->device
->dev
.bus_id
,
1967 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
1968 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
1981 switch (hkey
>> 12) {
1983 /* 0x1000-0x1FFF: key presses */
1984 scancode
= hkey
& 0xfff;
1985 if (scancode
> 0 && scancode
< 0x21) {
1987 if (!(hotkey_source_mask
& (1 << scancode
))) {
1988 tpacpi_input_send_key(scancode
);
2000 case 0x2304: /* suspend, undock */
2001 case 0x2404: /* hibernation, undock */
2002 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
2005 case 0x2305: /* suspend, bay eject */
2006 case 0x2405: /* hibernation, bay eject */
2007 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
2013 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
2015 "woke up due to a hot-unplug "
2020 /* bay-related wakeups */
2021 if (hkey
== 0x3003) {
2022 hotkey_autosleep_ack
= 1;
2030 /* dock-related wakeups */
2031 if (hkey
== 0x4003) {
2032 hotkey_autosleep_ack
= 1;
2040 /* 0x5000-0x5FFF: On screen display helpers */
2043 /* Lenovo Vista BIOS: brightness changed */
2047 /* LID switch events. Do not propagate */
2055 /* 0x7000-0x7FFF: misc */
2056 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
2057 tpacpi_input_send_radiosw();
2061 /* fallthrough to default */
2066 printk(TPACPI_NOTICE
2067 "unhandled HKEY event 0x%04x\n", hkey
);
2071 if (!ignore_acpi_ev
&&
2072 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
2073 acpi_bus_generate_proc_event(ibm
->acpi
->device
,
2077 /* netlink events */
2078 if (!ignore_acpi_ev
&& send_acpi_ev
) {
2079 acpi_bus_generate_netlink_event(
2080 ibm
->acpi
->device
->pnp
.device_class
,
2081 ibm
->acpi
->device
->dev
.bus_id
,
2087 static void hotkey_suspend(pm_message_t state
)
2089 /* Do these on suspend, we get the events on early resume! */
2090 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
2091 hotkey_autosleep_ack
= 0;
2094 static void hotkey_resume(void)
2096 if (hotkey_mask_get())
2098 "error while trying to read hot key mask "
2100 tpacpi_input_send_radiosw();
2101 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2102 hotkey_poll_setup_safe(0);
2106 /* procfs -------------------------------------------------------------- */
2107 static int hotkey_read(char *p
)
2112 if (!tp_features
.hotkey
) {
2113 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2117 if (mutex_lock_interruptible(&hotkey_mutex
))
2118 return -ERESTARTSYS
;
2119 res
= hotkey_status_get(&status
);
2121 res
= hotkey_mask_get();
2122 mutex_unlock(&hotkey_mutex
);
2126 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
2127 if (tp_features
.hotkey_mask
) {
2128 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
2129 len
+= sprintf(p
+ len
,
2130 "commands:\tenable, disable, reset, <mask>\n");
2132 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
2133 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
2139 static int hotkey_write(char *buf
)
2145 if (!tp_features
.hotkey
)
2148 if (mutex_lock_interruptible(&hotkey_mutex
))
2149 return -ERESTARTSYS
;
2155 while ((cmd
= next_cmd(&buf
))) {
2156 if (strlencmp(cmd
, "enable") == 0) {
2158 } else if (strlencmp(cmd
, "disable") == 0) {
2160 } else if (strlencmp(cmd
, "reset") == 0) {
2161 status
= hotkey_orig_status
;
2162 mask
= hotkey_orig_mask
;
2163 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
2165 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
2173 res
= hotkey_status_set(status
);
2175 if (!res
&& mask
!= hotkey_mask
)
2176 res
= hotkey_mask_set(mask
);
2179 mutex_unlock(&hotkey_mutex
);
2183 static const struct acpi_device_id ibm_htk_device_ids
[] = {
2184 {TPACPI_ACPI_HKEY_HID
, 0},
2188 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
2189 .hid
= ibm_htk_device_ids
,
2190 .notify
= hotkey_notify
,
2191 .handle
= &hkey_handle
,
2192 .type
= ACPI_DEVICE_NOTIFY
,
2195 static struct ibm_struct hotkey_driver_data
= {
2197 .read
= hotkey_read
,
2198 .write
= hotkey_write
,
2199 .exit
= hotkey_exit
,
2200 .resume
= hotkey_resume
,
2201 .suspend
= hotkey_suspend
,
2202 .acpi
= &ibm_hotkey_acpidriver
,
2205 /*************************************************************************
2206 * Bluetooth subdriver
2210 /* ACPI GBDC/SBDC bits */
2211 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
2212 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
2213 TP_ACPI_BLUETOOTH_UNK
= 0x04, /* unknown function */
2216 static int bluetooth_get_radiosw(void);
2217 static int bluetooth_set_radiosw(int radio_on
);
2219 /* sysfs bluetooth enable ---------------------------------------------- */
2220 static ssize_t
bluetooth_enable_show(struct device
*dev
,
2221 struct device_attribute
*attr
,
2226 status
= bluetooth_get_radiosw();
2230 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
2233 static ssize_t
bluetooth_enable_store(struct device
*dev
,
2234 struct device_attribute
*attr
,
2235 const char *buf
, size_t count
)
2240 if (parse_strtoul(buf
, 1, &t
))
2243 res
= bluetooth_set_radiosw(t
);
2245 return (res
) ? res
: count
;
2248 static struct device_attribute dev_attr_bluetooth_enable
=
2249 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
2250 bluetooth_enable_show
, bluetooth_enable_store
);
2252 /* --------------------------------------------------------------------- */
2254 static struct attribute
*bluetooth_attributes
[] = {
2255 &dev_attr_bluetooth_enable
.attr
,
2259 static const struct attribute_group bluetooth_attr_group
= {
2260 .attrs
= bluetooth_attributes
,
2263 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
2268 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
2270 TPACPI_ACPIHANDLE_INIT(hkey
);
2272 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2273 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
2274 tp_features
.bluetooth
= hkey_handle
&&
2275 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
2277 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
2278 str_supported(tp_features
.bluetooth
),
2281 if (tp_features
.bluetooth
) {
2282 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
2283 /* no bluetooth hardware present in system */
2284 tp_features
.bluetooth
= 0;
2285 dbg_printk(TPACPI_DBG_INIT
,
2286 "bluetooth hardware not installed\n");
2288 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2289 &bluetooth_attr_group
);
2295 return (tp_features
.bluetooth
)? 0 : 1;
2298 static void bluetooth_exit(void)
2300 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2301 &bluetooth_attr_group
);
2304 static int bluetooth_get_radiosw(void)
2308 if (!tp_features
.bluetooth
)
2311 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2314 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
2317 static int bluetooth_set_radiosw(int radio_on
)
2321 if (!tp_features
.bluetooth
)
2324 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2327 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
2329 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
2330 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
2336 /* procfs -------------------------------------------------------------- */
2337 static int bluetooth_read(char *p
)
2340 int status
= bluetooth_get_radiosw();
2342 if (!tp_features
.bluetooth
)
2343 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2345 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2346 (status
)? "enabled" : "disabled");
2347 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2353 static int bluetooth_write(char *buf
)
2357 if (!tp_features
.bluetooth
)
2360 while ((cmd
= next_cmd(&buf
))) {
2361 if (strlencmp(cmd
, "enable") == 0) {
2362 bluetooth_set_radiosw(1);
2363 } else if (strlencmp(cmd
, "disable") == 0) {
2364 bluetooth_set_radiosw(0);
2372 static struct ibm_struct bluetooth_driver_data
= {
2373 .name
= "bluetooth",
2374 .read
= bluetooth_read
,
2375 .write
= bluetooth_write
,
2376 .exit
= bluetooth_exit
,
2379 /*************************************************************************
2384 /* ACPI GWAN/SWAN bits */
2385 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
2386 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
2387 TP_ACPI_WANCARD_UNK
= 0x04, /* unknown function */
2390 static int wan_get_radiosw(void);
2391 static int wan_set_radiosw(int radio_on
);
2393 /* sysfs wan enable ---------------------------------------------------- */
2394 static ssize_t
wan_enable_show(struct device
*dev
,
2395 struct device_attribute
*attr
,
2400 status
= wan_get_radiosw();
2404 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
2407 static ssize_t
wan_enable_store(struct device
*dev
,
2408 struct device_attribute
*attr
,
2409 const char *buf
, size_t count
)
2414 if (parse_strtoul(buf
, 1, &t
))
2417 res
= wan_set_radiosw(t
);
2419 return (res
) ? res
: count
;
2422 static struct device_attribute dev_attr_wan_enable
=
2423 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
2424 wan_enable_show
, wan_enable_store
);
2426 /* --------------------------------------------------------------------- */
2428 static struct attribute
*wan_attributes
[] = {
2429 &dev_attr_wan_enable
.attr
,
2433 static const struct attribute_group wan_attr_group
= {
2434 .attrs
= wan_attributes
,
2437 static int __init
wan_init(struct ibm_init_struct
*iibm
)
2442 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
2444 TPACPI_ACPIHANDLE_INIT(hkey
);
2446 tp_features
.wan
= hkey_handle
&&
2447 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
2449 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
2450 str_supported(tp_features
.wan
),
2453 if (tp_features
.wan
) {
2454 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
2455 /* no wan hardware present in system */
2456 tp_features
.wan
= 0;
2457 dbg_printk(TPACPI_DBG_INIT
,
2458 "wan hardware not installed\n");
2460 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2467 return (tp_features
.wan
)? 0 : 1;
2470 static void wan_exit(void)
2472 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2476 static int wan_get_radiosw(void)
2480 if (!tp_features
.wan
)
2483 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2486 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
2489 static int wan_set_radiosw(int radio_on
)
2493 if (!tp_features
.wan
)
2496 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2499 status
|= TP_ACPI_WANCARD_RADIOSSW
;
2501 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
2502 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
2508 /* procfs -------------------------------------------------------------- */
2509 static int wan_read(char *p
)
2512 int status
= wan_get_radiosw();
2514 if (!tp_features
.wan
)
2515 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2517 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2518 (status
)? "enabled" : "disabled");
2519 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2525 static int wan_write(char *buf
)
2529 if (!tp_features
.wan
)
2532 while ((cmd
= next_cmd(&buf
))) {
2533 if (strlencmp(cmd
, "enable") == 0) {
2535 } else if (strlencmp(cmd
, "disable") == 0) {
2544 static struct ibm_struct wan_driver_data
= {
2549 .flags
.experimental
= 1,
2552 /*************************************************************************
2556 enum video_access_mode
{
2557 TPACPI_VIDEO_NONE
= 0,
2558 TPACPI_VIDEO_570
, /* 570 */
2559 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
2560 TPACPI_VIDEO_NEW
, /* all others */
2563 enum { /* video status flags, based on VIDEO_570 */
2564 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
2565 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
2566 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
2569 enum { /* TPACPI_VIDEO_570 constants */
2570 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
2571 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
2572 * video_status_flags */
2573 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
2574 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
2577 static enum video_access_mode video_supported
;
2578 static int video_orig_autosw
;
2580 static int video_autosw_get(void);
2581 static int video_autosw_set(int enable
);
2583 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
2584 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
2585 "\\_SB.PCI0.VID0", /* 770e */
2586 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
2587 "\\_SB.PCI0.AGP.VID", /* all others */
2590 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
2592 static int __init
video_init(struct ibm_init_struct
*iibm
)
2596 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
2598 TPACPI_ACPIHANDLE_INIT(vid
);
2599 TPACPI_ACPIHANDLE_INIT(vid2
);
2601 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
2602 /* G41, assume IVGA doesn't change */
2603 vid_handle
= vid2_handle
;
2606 /* video switching not supported on R30, R31 */
2607 video_supported
= TPACPI_VIDEO_NONE
;
2608 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
2610 video_supported
= TPACPI_VIDEO_570
;
2611 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
2612 /* 600e/x, 770e, 770x */
2613 video_supported
= TPACPI_VIDEO_770
;
2616 video_supported
= TPACPI_VIDEO_NEW
;
2618 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
2619 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
2622 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
2625 static void video_exit(void)
2627 dbg_printk(TPACPI_DBG_EXIT
,
2628 "restoring original video autoswitch mode\n");
2629 if (video_autosw_set(video_orig_autosw
))
2630 printk(TPACPI_ERR
"error while trying to restore original "
2631 "video autoswitch mode\n");
2634 static int video_outputsw_get(void)
2639 switch (video_supported
) {
2640 case TPACPI_VIDEO_570
:
2641 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
2642 TP_ACPI_VIDEO_570_PHSCMD
))
2644 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
2646 case TPACPI_VIDEO_770
:
2647 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2650 status
|= TP_ACPI_VIDEO_S_LCD
;
2651 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2654 status
|= TP_ACPI_VIDEO_S_CRT
;
2656 case TPACPI_VIDEO_NEW
:
2657 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
2658 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2661 status
|= TP_ACPI_VIDEO_S_CRT
;
2663 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
2664 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2667 status
|= TP_ACPI_VIDEO_S_LCD
;
2668 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
2671 status
|= TP_ACPI_VIDEO_S_DVI
;
2680 static int video_outputsw_set(int status
)
2685 switch (video_supported
) {
2686 case TPACPI_VIDEO_570
:
2687 res
= acpi_evalf(NULL
, NULL
,
2688 "\\_SB.PHS2", "vdd",
2689 TP_ACPI_VIDEO_570_PHS2CMD
,
2690 status
| TP_ACPI_VIDEO_570_PHS2SET
);
2692 case TPACPI_VIDEO_770
:
2693 autosw
= video_autosw_get();
2697 res
= video_autosw_set(1);
2700 res
= acpi_evalf(vid_handle
, NULL
,
2701 "ASWT", "vdd", status
* 0x100, 0);
2702 if (!autosw
&& video_autosw_set(autosw
)) {
2704 "video auto-switch left enabled due to error\n");
2708 case TPACPI_VIDEO_NEW
:
2709 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
2710 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
2716 return (res
)? 0 : -EIO
;
2719 static int video_autosw_get(void)
2723 switch (video_supported
) {
2724 case TPACPI_VIDEO_570
:
2725 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
2728 case TPACPI_VIDEO_770
:
2729 case TPACPI_VIDEO_NEW
:
2730 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
2740 static int video_autosw_set(int enable
)
2742 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
2747 static int video_outputsw_cycle(void)
2749 int autosw
= video_autosw_get();
2755 switch (video_supported
) {
2756 case TPACPI_VIDEO_570
:
2757 res
= video_autosw_set(1);
2760 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
2762 case TPACPI_VIDEO_770
:
2763 case TPACPI_VIDEO_NEW
:
2764 res
= video_autosw_set(1);
2767 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
2772 if (!autosw
&& video_autosw_set(autosw
)) {
2774 "video auto-switch left enabled due to error\n");
2778 return (res
)? 0 : -EIO
;
2781 static int video_expand_toggle(void)
2783 switch (video_supported
) {
2784 case TPACPI_VIDEO_570
:
2785 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
2787 case TPACPI_VIDEO_770
:
2788 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
2790 case TPACPI_VIDEO_NEW
:
2791 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
2799 static int video_read(char *p
)
2804 if (video_supported
== TPACPI_VIDEO_NONE
) {
2805 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2809 status
= video_outputsw_get();
2813 autosw
= video_autosw_get();
2817 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2818 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
2819 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
2820 if (video_supported
== TPACPI_VIDEO_NEW
)
2821 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
2822 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
2823 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
2824 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
2825 if (video_supported
== TPACPI_VIDEO_NEW
)
2826 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
2827 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
2828 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
2833 static int video_write(char *buf
)
2836 int enable
, disable
, status
;
2839 if (video_supported
== TPACPI_VIDEO_NONE
)
2845 while ((cmd
= next_cmd(&buf
))) {
2846 if (strlencmp(cmd
, "lcd_enable") == 0) {
2847 enable
|= TP_ACPI_VIDEO_S_LCD
;
2848 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
2849 disable
|= TP_ACPI_VIDEO_S_LCD
;
2850 } else if (strlencmp(cmd
, "crt_enable") == 0) {
2851 enable
|= TP_ACPI_VIDEO_S_CRT
;
2852 } else if (strlencmp(cmd
, "crt_disable") == 0) {
2853 disable
|= TP_ACPI_VIDEO_S_CRT
;
2854 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2855 strlencmp(cmd
, "dvi_enable") == 0) {
2856 enable
|= TP_ACPI_VIDEO_S_DVI
;
2857 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2858 strlencmp(cmd
, "dvi_disable") == 0) {
2859 disable
|= TP_ACPI_VIDEO_S_DVI
;
2860 } else if (strlencmp(cmd
, "auto_enable") == 0) {
2861 res
= video_autosw_set(1);
2864 } else if (strlencmp(cmd
, "auto_disable") == 0) {
2865 res
= video_autosw_set(0);
2868 } else if (strlencmp(cmd
, "video_switch") == 0) {
2869 res
= video_outputsw_cycle();
2872 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
2873 res
= video_expand_toggle();
2880 if (enable
|| disable
) {
2881 status
= video_outputsw_get();
2884 res
= video_outputsw_set((status
& ~disable
) | enable
);
2892 static struct ibm_struct video_driver_data
= {
2895 .write
= video_write
,
2899 /*************************************************************************
2900 * Light (thinklight) subdriver
2903 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
2904 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
2906 static int __init
light_init(struct ibm_init_struct
*iibm
)
2908 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
2910 TPACPI_ACPIHANDLE_INIT(ledb
);
2911 TPACPI_ACPIHANDLE_INIT(lght
);
2912 TPACPI_ACPIHANDLE_INIT(cmos
);
2914 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
2915 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
2917 if (tp_features
.light
)
2918 /* light status not supported on
2919 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
2920 tp_features
.light_status
=
2921 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
2923 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
2924 str_supported(tp_features
.light
));
2926 return (tp_features
.light
)? 0 : 1;
2929 static int light_read(char *p
)
2934 if (!tp_features
.light
) {
2935 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2936 } else if (!tp_features
.light_status
) {
2937 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
2938 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2940 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
2942 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
2943 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2949 static int light_write(char *buf
)
2951 int cmos_cmd
, lght_cmd
;
2955 if (!tp_features
.light
)
2958 while ((cmd
= next_cmd(&buf
))) {
2959 if (strlencmp(cmd
, "on") == 0) {
2962 } else if (strlencmp(cmd
, "off") == 0) {
2968 success
= cmos_handle
?
2969 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
2970 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
2978 static struct ibm_struct light_driver_data
= {
2981 .write
= light_write
,
2984 /*************************************************************************
2988 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2990 static void dock_notify(struct ibm_struct
*ibm
, u32 event
);
2991 static int dock_read(char *p
);
2992 static int dock_write(char *buf
);
2994 TPACPI_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
2995 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
2996 "\\_SB.PCI0.PCI1.DOCK", /* all others */
2997 "\\_SB.PCI.ISA.SLCE", /* 570 */
2998 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
3000 /* don't list other alternatives as we install a notify handler on the 570 */
3001 TPACPI_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
3003 static const struct acpi_device_id ibm_pci_device_ids
[] = {
3004 {PCI_ROOT_HID_STRING
, 0},
3008 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
3010 .notify
= dock_notify
,
3011 .handle
= &dock_handle
,
3012 .type
= ACPI_SYSTEM_NOTIFY
,
3015 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
3016 * We just use it to get notifications of dock hotplug
3017 * in very old thinkpads */
3018 .hid
= ibm_pci_device_ids
,
3019 .notify
= dock_notify
,
3020 .handle
= &pci_handle
,
3021 .type
= ACPI_SYSTEM_NOTIFY
,
3025 static struct ibm_struct dock_driver_data
[2] = {
3029 .write
= dock_write
,
3030 .acpi
= &ibm_dock_acpidriver
[0],
3034 .acpi
= &ibm_dock_acpidriver
[1],
3038 #define dock_docked() (_sta(dock_handle) & 1)
3040 static int __init
dock_init(struct ibm_init_struct
*iibm
)
3042 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
3044 TPACPI_ACPIHANDLE_INIT(dock
);
3046 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
3047 str_supported(dock_handle
!= NULL
));
3049 return (dock_handle
)? 0 : 1;
3052 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
3056 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
3058 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
3059 dock_driver_data
[0].flags
.acpi_notify_installed
) {
3060 TPACPI_ACPIHANDLE_INIT(pci
);
3061 dock2_needed
= (pci_handle
!= NULL
);
3062 vdbg_printk(TPACPI_DBG_INIT
,
3063 "dock PCI handler for the TP 570 is %s\n",
3064 str_supported(dock2_needed
));
3066 vdbg_printk(TPACPI_DBG_INIT
,
3067 "dock subdriver part 2 not required\n");
3071 return (dock2_needed
)? 0 : 1;
3074 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
3076 int docked
= dock_docked();
3077 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
3078 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
3081 if (event
== 1 && !pci
) /* 570 */
3082 data
= 1; /* button */
3083 else if (event
== 1 && pci
) /* 570 */
3084 data
= 3; /* dock */
3085 else if (event
== 3 && docked
)
3086 data
= 1; /* button */
3087 else if (event
== 3 && !docked
)
3088 data
= 2; /* undock */
3089 else if (event
== 0 && docked
)
3090 data
= 3; /* dock */
3092 printk(TPACPI_ERR
"unknown dock event %d, status %d\n",
3093 event
, _sta(dock_handle
));
3094 data
= 0; /* unknown */
3096 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
3097 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3098 ibm
->acpi
->device
->dev
.bus_id
,
3102 static int dock_read(char *p
)
3105 int docked
= dock_docked();
3108 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3110 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
3112 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
3113 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
3119 static int dock_write(char *buf
)
3126 while ((cmd
= next_cmd(&buf
))) {
3127 if (strlencmp(cmd
, "undock") == 0) {
3128 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
3129 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
3131 } else if (strlencmp(cmd
, "dock") == 0) {
3132 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
3141 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
3143 /*************************************************************************
3147 #ifdef CONFIG_THINKPAD_ACPI_BAY
3149 TPACPI_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
3150 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
3151 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
3152 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
3153 ); /* A21e, R30, R31 */
3154 TPACPI_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
3155 "_EJ0", /* all others */
3156 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
3157 TPACPI_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
3158 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
3160 TPACPI_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
3164 static int __init
bay_init(struct ibm_init_struct
*iibm
)
3166 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
3168 TPACPI_ACPIHANDLE_INIT(bay
);
3170 TPACPI_ACPIHANDLE_INIT(bay_ej
);
3171 TPACPI_ACPIHANDLE_INIT(bay2
);
3173 TPACPI_ACPIHANDLE_INIT(bay2_ej
);
3175 tp_features
.bay_status
= bay_handle
&&
3176 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
3177 tp_features
.bay_status2
= bay2_handle
&&
3178 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
3180 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
3181 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
3182 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
3183 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
3185 vdbg_printk(TPACPI_DBG_INIT
,
3186 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
3187 str_supported(tp_features
.bay_status
),
3188 str_supported(tp_features
.bay_eject
),
3189 str_supported(tp_features
.bay_status2
),
3190 str_supported(tp_features
.bay_eject2
));
3192 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
3193 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
3196 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
3198 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
3199 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3200 ibm
->acpi
->device
->dev
.bus_id
,
3204 #define bay_occupied(b) (_sta(b##_handle) & 1)
3206 static int bay_read(char *p
)
3209 int occupied
= bay_occupied(bay
);
3210 int occupied2
= bay_occupied(bay2
);
3213 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3214 tp_features
.bay_status
?
3215 (occupied
? "occupied" : "unoccupied") :
3217 if (tp_features
.bay_status2
)
3218 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
3219 "occupied" : "unoccupied");
3221 eject
= tp_features
.bay_eject
&& occupied
;
3222 eject2
= tp_features
.bay_eject2
&& occupied2
;
3224 if (eject
&& eject2
)
3225 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
3227 len
+= sprintf(p
+ len
, "commands:\teject\n");
3229 len
+= sprintf(p
+ len
, "commands:\teject2\n");
3234 static int bay_write(char *buf
)
3238 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
3241 while ((cmd
= next_cmd(&buf
))) {
3242 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
3243 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
3245 } else if (tp_features
.bay_eject2
&&
3246 strlencmp(cmd
, "eject2") == 0) {
3247 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
3256 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
3257 .notify
= bay_notify
,
3258 .handle
= &bay_handle
,
3259 .type
= ACPI_SYSTEM_NOTIFY
,
3262 static struct ibm_struct bay_driver_data
= {
3266 .acpi
= &ibm_bay_acpidriver
,
3269 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3271 /*************************************************************************
3275 /* sysfs cmos_command -------------------------------------------------- */
3276 static ssize_t
cmos_command_store(struct device
*dev
,
3277 struct device_attribute
*attr
,
3278 const char *buf
, size_t count
)
3280 unsigned long cmos_cmd
;
3283 if (parse_strtoul(buf
, 21, &cmos_cmd
))
3286 res
= issue_thinkpad_cmos_command(cmos_cmd
);
3287 return (res
)? res
: count
;
3290 static struct device_attribute dev_attr_cmos_command
=
3291 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
3293 /* --------------------------------------------------------------------- */
3295 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
3299 vdbg_printk(TPACPI_DBG_INIT
,
3300 "initializing cmos commands subdriver\n");
3302 TPACPI_ACPIHANDLE_INIT(cmos
);
3304 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
3305 str_supported(cmos_handle
!= NULL
));
3307 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
3311 return (cmos_handle
)? 0 : 1;
3314 static void cmos_exit(void)
3316 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
3319 static int cmos_read(char *p
)
3323 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3324 R30, R31, T20-22, X20-21 */
3326 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3328 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3329 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
3335 static int cmos_write(char *buf
)
3340 while ((cmd
= next_cmd(&buf
))) {
3341 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
3342 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
3347 res
= issue_thinkpad_cmos_command(cmos_cmd
);
3355 static struct ibm_struct cmos_driver_data
= {
3358 .write
= cmos_write
,
3362 /*************************************************************************
3366 enum led_access_mode
{
3367 TPACPI_LED_NONE
= 0,
3368 TPACPI_LED_570
, /* 570 */
3369 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3370 TPACPI_LED_NEW
, /* all others */
3373 enum { /* For TPACPI_LED_OLD */
3374 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
3375 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
3376 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
3379 static enum led_access_mode led_supported
;
3381 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
3382 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
3383 /* T20-22, X20-21 */
3384 "LED", /* all others */
3387 static int __init
led_init(struct ibm_init_struct
*iibm
)
3389 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
3391 TPACPI_ACPIHANDLE_INIT(led
);
3394 /* led not supported on R30, R31 */
3395 led_supported
= TPACPI_LED_NONE
;
3396 else if (strlencmp(led_path
, "SLED") == 0)
3398 led_supported
= TPACPI_LED_570
;
3399 else if (strlencmp(led_path
, "SYSL") == 0)
3400 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3401 led_supported
= TPACPI_LED_OLD
;
3404 led_supported
= TPACPI_LED_NEW
;
3406 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
3407 str_supported(led_supported
), led_supported
);
3409 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
3412 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
3414 static int led_read(char *p
)
3418 if (!led_supported
) {
3419 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3422 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3424 if (led_supported
== TPACPI_LED_570
) {
3427 for (i
= 0; i
< 8; i
++) {
3428 if (!acpi_evalf(ec_handle
,
3429 &status
, "GLED", "dd", 1 << i
))
3431 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
3432 i
, led_status(status
));
3436 len
+= sprintf(p
+ len
, "commands:\t"
3437 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
3442 /* off, on, blink */
3443 static const int led_sled_arg1
[] = { 0, 1, 3 };
3444 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
3445 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
3446 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
3448 static int led_write(char *buf
)
3456 while ((cmd
= next_cmd(&buf
))) {
3457 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
3460 if (strstr(cmd
, "off")) {
3462 } else if (strstr(cmd
, "on")) {
3464 } else if (strstr(cmd
, "blink")) {
3469 if (led_supported
== TPACPI_LED_570
) {
3472 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
3473 led
, led_sled_arg1
[ind
]))
3475 } else if (led_supported
== TPACPI_LED_OLD
) {
3476 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
3478 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
3480 ret
= ec_write(TPACPI_LED_EC_HLBL
,
3481 led
* led_exp_hlbl
[ind
]);
3483 ret
= ec_write(TPACPI_LED_EC_HLCL
,
3484 led
* led_exp_hlcl
[ind
]);
3489 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
3490 led
, led_led_arg1
[ind
]))
3498 static struct ibm_struct led_driver_data
= {
3504 /*************************************************************************
3508 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
3510 static int __init
beep_init(struct ibm_init_struct
*iibm
)
3512 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
3514 TPACPI_ACPIHANDLE_INIT(beep
);
3516 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
3517 str_supported(beep_handle
!= NULL
));
3519 return (beep_handle
)? 0 : 1;
3522 static int beep_read(char *p
)
3527 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3529 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3530 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
3536 static int beep_write(char *buf
)
3544 while ((cmd
= next_cmd(&buf
))) {
3545 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
3546 beep_cmd
>= 0 && beep_cmd
<= 17) {
3550 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
3557 static struct ibm_struct beep_driver_data
= {
3560 .write
= beep_write
,
3563 /*************************************************************************
3567 enum thermal_access_mode
{
3568 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
3569 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
3570 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
3571 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
3572 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
3575 enum { /* TPACPI_THERMAL_TPEC_* */
3576 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
3577 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
3578 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
3581 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
3582 struct ibm_thermal_sensors_struct
{
3583 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
3586 static enum thermal_access_mode thermal_read_mode
;
3588 /* idx is zero-based */
3589 static int thermal_get_sensor(int idx
, s32
*value
)
3595 t
= TP_EC_THERMAL_TMP0
;
3597 switch (thermal_read_mode
) {
3598 #if TPACPI_MAX_THERMAL_SENSORS >= 16
3599 case TPACPI_THERMAL_TPEC_16
:
3600 if (idx
>= 8 && idx
<= 15) {
3601 t
= TP_EC_THERMAL_TMP8
;
3606 case TPACPI_THERMAL_TPEC_8
:
3608 if (!acpi_ec_read(t
+ idx
, &tmp
))
3610 *value
= tmp
* 1000;
3615 case TPACPI_THERMAL_ACPI_UPDT
:
3617 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3618 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
3620 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3622 *value
= (t
- 2732) * 100;
3627 case TPACPI_THERMAL_ACPI_TMP07
:
3629 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3630 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3632 if (t
> 127 || t
< -127)
3633 t
= TP_EC_THERMAL_TMP_NA
;
3639 case TPACPI_THERMAL_NONE
:
3647 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
3658 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
3661 for (i
= 0 ; i
< n
; i
++) {
3662 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
3670 /* sysfs temp##_input -------------------------------------------------- */
3672 static ssize_t
thermal_temp_input_show(struct device
*dev
,
3673 struct device_attribute
*attr
,
3676 struct sensor_device_attribute
*sensor_attr
=
3677 to_sensor_dev_attr(attr
);
3678 int idx
= sensor_attr
->index
;
3682 res
= thermal_get_sensor(idx
, &value
);
3685 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
3688 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
3691 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
3692 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
3693 thermal_temp_input_show, NULL, _idxB)
3695 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
3696 THERMAL_SENSOR_ATTR_TEMP(1, 0),
3697 THERMAL_SENSOR_ATTR_TEMP(2, 1),
3698 THERMAL_SENSOR_ATTR_TEMP(3, 2),
3699 THERMAL_SENSOR_ATTR_TEMP(4, 3),
3700 THERMAL_SENSOR_ATTR_TEMP(5, 4),
3701 THERMAL_SENSOR_ATTR_TEMP(6, 5),
3702 THERMAL_SENSOR_ATTR_TEMP(7, 6),
3703 THERMAL_SENSOR_ATTR_TEMP(8, 7),
3704 THERMAL_SENSOR_ATTR_TEMP(9, 8),
3705 THERMAL_SENSOR_ATTR_TEMP(10, 9),
3706 THERMAL_SENSOR_ATTR_TEMP(11, 10),
3707 THERMAL_SENSOR_ATTR_TEMP(12, 11),
3708 THERMAL_SENSOR_ATTR_TEMP(13, 12),
3709 THERMAL_SENSOR_ATTR_TEMP(14, 13),
3710 THERMAL_SENSOR_ATTR_TEMP(15, 14),
3711 THERMAL_SENSOR_ATTR_TEMP(16, 15),
3714 #define THERMAL_ATTRS(X) \
3715 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
3717 static struct attribute
*thermal_temp_input_attr
[] = {
3737 static const struct attribute_group thermal_temp_input16_group
= {
3738 .attrs
= thermal_temp_input_attr
3741 static const struct attribute_group thermal_temp_input8_group
= {
3742 .attrs
= &thermal_temp_input_attr
[8]
3745 #undef THERMAL_SENSOR_ATTR_TEMP
3746 #undef THERMAL_ATTRS
3748 /* --------------------------------------------------------------------- */
3750 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
3757 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
3759 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
3761 if (thinkpad_id
.ec_model
) {
3763 * Direct EC access mode: sensors at registers
3764 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
3765 * non-implemented, thermal sensors return 0x80 when
3770 for (i
= 0; i
< 8; i
++) {
3771 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
3777 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
3785 /* This is sheer paranoia, but we handle it anyway */
3788 "ThinkPad ACPI EC access misbehaving, "
3789 "falling back to ACPI TMPx access "
3791 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
3794 "ThinkPad ACPI EC access misbehaving, "
3795 "disabling thermal sensors access\n");
3796 thermal_read_mode
= TPACPI_THERMAL_NONE
;
3801 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
3803 } else if (acpi_tmp7
) {
3804 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
3805 /* 600e/x, 770e, 770x */
3806 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
3808 /* Standard ACPI TMPx access, max 8 sensors */
3809 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
3812 /* temperatures not supported on 570, G4x, R30, R31, R32 */
3813 thermal_read_mode
= TPACPI_THERMAL_NONE
;
3816 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
3817 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
3820 switch (thermal_read_mode
) {
3821 case TPACPI_THERMAL_TPEC_16
:
3822 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3823 &thermal_temp_input16_group
);
3827 case TPACPI_THERMAL_TPEC_8
:
3828 case TPACPI_THERMAL_ACPI_TMP07
:
3829 case TPACPI_THERMAL_ACPI_UPDT
:
3830 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3831 &thermal_temp_input8_group
);
3835 case TPACPI_THERMAL_NONE
:
3843 static void thermal_exit(void)
3845 switch (thermal_read_mode
) {
3846 case TPACPI_THERMAL_TPEC_16
:
3847 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3848 &thermal_temp_input16_group
);
3850 case TPACPI_THERMAL_TPEC_8
:
3851 case TPACPI_THERMAL_ACPI_TMP07
:
3852 case TPACPI_THERMAL_ACPI_UPDT
:
3853 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3854 &thermal_temp_input16_group
);
3856 case TPACPI_THERMAL_NONE
:
3862 static int thermal_read(char *p
)
3866 struct ibm_thermal_sensors_struct t
;
3868 n
= thermal_get_sensors(&t
);
3869 if (unlikely(n
< 0))
3872 len
+= sprintf(p
+ len
, "temperatures:\t");
3875 for (i
= 0; i
< (n
- 1); i
++)
3876 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
3877 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
3879 len
+= sprintf(p
+ len
, "not supported\n");
3884 static struct ibm_struct thermal_driver_data
= {
3886 .read
= thermal_read
,
3887 .exit
= thermal_exit
,
3890 /*************************************************************************
3894 static u8 ecdump_regs
[256];
3896 static int ecdump_read(char *p
)
3902 len
+= sprintf(p
+ len
, "EC "
3903 " +00 +01 +02 +03 +04 +05 +06 +07"
3904 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
3905 for (i
= 0; i
< 256; i
+= 16) {
3906 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
3907 for (j
= 0; j
< 16; j
++) {
3908 if (!acpi_ec_read(i
+ j
, &v
))
3910 if (v
!= ecdump_regs
[i
+ j
])
3911 len
+= sprintf(p
+ len
, " *%02x", v
);
3913 len
+= sprintf(p
+ len
, " %02x", v
);
3914 ecdump_regs
[i
+ j
] = v
;
3916 len
+= sprintf(p
+ len
, "\n");
3921 /* These are way too dangerous to advertise openly... */
3923 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
3924 " (<offset> is 00-ff, <value> is 00-ff)\n");
3925 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
3926 " (<offset> is 00-ff, <value> is 0-255)\n");
3931 static int ecdump_write(char *buf
)
3936 while ((cmd
= next_cmd(&buf
))) {
3937 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
3939 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
3943 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
3944 if (!acpi_ec_write(i
, v
))
3953 static struct ibm_struct ecdump_driver_data
= {
3955 .read
= ecdump_read
,
3956 .write
= ecdump_write
,
3957 .flags
.experimental
= 1,
3960 /*************************************************************************
3961 * Backlight/brightness subdriver
3964 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
3966 static struct backlight_device
*ibm_backlight_device
;
3967 static int brightness_offset
= 0x31;
3968 static int brightness_mode
;
3969 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
3971 static struct mutex brightness_mutex
;
3974 * ThinkPads can read brightness from two places: EC 0x31, or
3975 * CMOS NVRAM byte 0x5E, bits 0-3.
3977 static int brightness_get(struct backlight_device
*bd
)
3979 u8 lec
= 0, lcmos
= 0, level
= 0;
3981 if (brightness_mode
& 1) {
3982 if (!acpi_ec_read(brightness_offset
, &lec
))
3984 lec
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
3987 if (brightness_mode
& 2) {
3988 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
3989 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
3990 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
3991 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
3995 if (brightness_mode
== 3 && lec
!= lcmos
) {
3997 "CMOS NVRAM (%u) and EC (%u) do not agree "
3998 "on display brightness level\n",
3999 (unsigned int) lcmos
,
4000 (unsigned int) lec
);
4007 /* May return EINTR which can always be mapped to ERESTARTSYS */
4008 static int brightness_set(int value
)
4010 int cmos_cmd
, inc
, i
, res
;
4013 if (value
> ((tp_features
.bright_16levels
)? 15 : 7))
4016 res
= mutex_lock_interruptible(&brightness_mutex
);
4020 current_value
= brightness_get(NULL
);
4021 if (current_value
< 0) {
4022 res
= current_value
;
4026 cmos_cmd
= value
> current_value
?
4027 TP_CMOS_BRIGHTNESS_UP
:
4028 TP_CMOS_BRIGHTNESS_DOWN
;
4029 inc
= (value
> current_value
)? 1 : -1;
4032 for (i
= current_value
; i
!= value
; i
+= inc
) {
4033 if ((brightness_mode
& 2) &&
4034 issue_thinkpad_cmos_command(cmos_cmd
)) {
4038 if ((brightness_mode
& 1) &&
4039 !acpi_ec_write(brightness_offset
, i
+ inc
)) {
4046 mutex_unlock(&brightness_mutex
);
4050 /* sysfs backlight class ----------------------------------------------- */
4052 static int brightness_update_status(struct backlight_device
*bd
)
4054 /* it is the backlight class's job (caller) to handle
4055 * EINTR and other errors properly */
4056 return brightness_set(
4057 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
4058 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
4059 bd
->props
.brightness
: 0);
4062 static struct backlight_ops ibm_backlight_data
= {
4063 .get_brightness
= brightness_get
,
4064 .update_status
= brightness_update_status
,
4067 /* --------------------------------------------------------------------- */
4069 static int __init
tpacpi_query_bcll_levels(acpi_handle handle
)
4071 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
4072 union acpi_object
*obj
;
4075 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
4076 obj
= (union acpi_object
*)buffer
.pointer
;
4077 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
4078 printk(TPACPI_ERR
"Unknown BCLL data, "
4079 "please report this to %s\n", TPACPI_MAIL
);
4082 rc
= obj
->package
.count
;
4088 kfree(buffer
.pointer
);
4092 static acpi_status __init
brightness_find_bcll(acpi_handle handle
, u32 lvl
,
4093 void *context
, void **rv
)
4095 char name
[ACPI_PATH_SEGMENT_LENGTH
];
4096 struct acpi_buffer buffer
= { sizeof(name
), &name
};
4098 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
4099 !strncmp("BCLL", name
, sizeof(name
) - 1)) {
4100 if (tpacpi_query_bcll_levels(handle
) == 16) {
4102 return AE_CTRL_TERMINATE
;
4111 static int __init
brightness_check_levels(void)
4114 void *found_node
= NULL
;
4117 TPACPI_ACPIHANDLE_INIT(vid
);
4122 /* Search for a BCLL package with 16 levels */
4123 status
= acpi_walk_namespace(ACPI_TYPE_PACKAGE
, vid_handle
, 3,
4124 brightness_find_bcll
, NULL
,
4127 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
4130 static acpi_status __init
brightness_find_bcl(acpi_handle handle
, u32 lvl
,
4131 void *context
, void **rv
)
4133 char name
[ACPI_PATH_SEGMENT_LENGTH
];
4134 struct acpi_buffer buffer
= { sizeof(name
), &name
};
4136 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
4137 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
4139 return AE_CTRL_TERMINATE
;
4145 static int __init
brightness_check_std_acpi_support(void)
4148 void *found_node
= NULL
;
4151 TPACPI_ACPIHANDLE_INIT(vid
);
4156 /* Search for a _BCL method, but don't execute it */
4157 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
4158 brightness_find_bcl
, NULL
, &found_node
);
4160 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
4163 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
4167 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
4169 mutex_init(&brightness_mutex
);
4171 if (!brightness_enable
) {
4172 dbg_printk(TPACPI_DBG_INIT
,
4173 "brightness support disabled by module parameter\n");
4175 } else if (brightness_enable
> 1) {
4176 if (brightness_check_std_acpi_support()) {
4177 printk(TPACPI_NOTICE
4178 "standard ACPI backlight interface "
4179 "available, not loading native one...\n");
4184 if (!brightness_mode
) {
4185 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
4186 brightness_mode
= 2;
4188 brightness_mode
= 3;
4190 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
4194 if (brightness_mode
> 3)
4197 tp_features
.bright_16levels
=
4198 thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
&&
4199 brightness_check_levels();
4201 b
= brightness_get(NULL
);
4205 if (tp_features
.bright_16levels
)
4207 "detected a 16-level brightness capable ThinkPad\n");
4209 ibm_backlight_device
= backlight_device_register(
4210 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
4211 &ibm_backlight_data
);
4212 if (IS_ERR(ibm_backlight_device
)) {
4213 printk(TPACPI_ERR
"Could not register backlight device\n");
4214 return PTR_ERR(ibm_backlight_device
);
4216 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
4218 ibm_backlight_device
->props
.max_brightness
=
4219 (tp_features
.bright_16levels
)? 15 : 7;
4220 ibm_backlight_device
->props
.brightness
= b
;
4221 backlight_update_status(ibm_backlight_device
);
4226 static void brightness_exit(void)
4228 if (ibm_backlight_device
) {
4229 vdbg_printk(TPACPI_DBG_EXIT
,
4230 "calling backlight_device_unregister()\n");
4231 backlight_device_unregister(ibm_backlight_device
);
4232 ibm_backlight_device
= NULL
;
4236 static int brightness_read(char *p
)
4241 level
= brightness_get(NULL
);
4243 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
4245 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
4246 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
4247 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
4248 " (<level> is 0-%d)\n",
4249 (tp_features
.bright_16levels
) ? 15 : 7);
4255 static int brightness_write(char *buf
)
4260 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
4262 level
= brightness_get(NULL
);
4266 while ((cmd
= next_cmd(&buf
))) {
4267 if (strlencmp(cmd
, "up") == 0) {
4268 if (level
< max_level
)
4270 } else if (strlencmp(cmd
, "down") == 0) {
4273 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
4274 level
>= 0 && level
<= max_level
) {
4281 * Now we know what the final level should be, so we try to set it.
4282 * Doing it this way makes the syscall restartable in case of EINTR
4284 rc
= brightness_set(level
);
4285 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
4288 static struct ibm_struct brightness_driver_data
= {
4289 .name
= "brightness",
4290 .read
= brightness_read
,
4291 .write
= brightness_write
,
4292 .exit
= brightness_exit
,
4295 /*************************************************************************
4299 static int volume_offset
= 0x30;
4301 static int volume_read(char *p
)
4306 if (!acpi_ec_read(volume_offset
, &level
)) {
4307 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
4309 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
4310 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
4311 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
4312 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
4313 " (<level> is 0-15)\n");
4319 static int volume_write(char *buf
)
4321 int cmos_cmd
, inc
, i
;
4323 int new_level
, new_mute
;
4326 while ((cmd
= next_cmd(&buf
))) {
4327 if (!acpi_ec_read(volume_offset
, &level
))
4329 new_mute
= mute
= level
& 0x40;
4330 new_level
= level
= level
& 0xf;
4332 if (strlencmp(cmd
, "up") == 0) {
4336 new_level
= level
== 15 ? 15 : level
+ 1;
4337 } else if (strlencmp(cmd
, "down") == 0) {
4341 new_level
= level
== 0 ? 0 : level
- 1;
4342 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
4343 new_level
>= 0 && new_level
<= 15) {
4345 } else if (strlencmp(cmd
, "mute") == 0) {
4350 if (new_level
!= level
) { /* mute doesn't change */
4351 cmos_cmd
= (new_level
> level
) ?
4352 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
4353 inc
= new_level
> level
? 1 : -1;
4355 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
4356 !acpi_ec_write(volume_offset
, level
)))
4359 for (i
= level
; i
!= new_level
; i
+= inc
)
4360 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
4361 !acpi_ec_write(volume_offset
, i
+ inc
))
4365 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
4366 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
4371 if (new_mute
!= mute
) { /* level doesn't change */
4372 cmos_cmd
= (new_mute
) ?
4373 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
4375 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
4376 !acpi_ec_write(volume_offset
, level
+ new_mute
))
4384 static struct ibm_struct volume_driver_data
= {
4386 .read
= volume_read
,
4387 .write
= volume_write
,
4390 /*************************************************************************
4397 * TPACPI_FAN_RD_ACPI_GFAN:
4398 * ACPI GFAN method: returns fan level
4400 * see TPACPI_FAN_WR_ACPI_SFAN
4401 * EC 0x2f (HFSP) not available if GFAN exists
4403 * TPACPI_FAN_WR_ACPI_SFAN:
4404 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
4406 * EC 0x2f (HFSP) might be available *for reading*, but do not use
4409 * TPACPI_FAN_WR_TPEC:
4410 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
4411 * Supported on almost all ThinkPads
4413 * Fan speed changes of any sort (including those caused by the
4414 * disengaged mode) are usually done slowly by the firmware as the
4415 * maximum ammount of fan duty cycle change per second seems to be
4418 * Reading is not available if GFAN exists.
4419 * Writing is not available if SFAN exists.
4422 * 7 automatic mode engaged;
4423 * (default operation mode of the ThinkPad)
4424 * fan level is ignored in this mode.
4425 * 6 full speed mode (takes precedence over bit 7);
4426 * not available on all thinkpads. May disable
4427 * the tachometer while the fan controller ramps up
4428 * the speed (which can take up to a few *minutes*).
4429 * Speeds up fan to 100% duty-cycle, which is far above
4430 * the standard RPM levels. It is not impossible that
4431 * it could cause hardware damage.
4432 * 5-3 unused in some models. Extra bits for fan level
4433 * in others, but still useless as all values above
4434 * 7 map to the same speed as level 7 in these models.
4435 * 2-0 fan level (0..7 usually)
4437 * 0x07 = max (set when temperatures critical)
4438 * Some ThinkPads may have other levels, see
4439 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
4441 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
4442 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
4443 * does so, its initial value is meaningless (0x07).
4445 * For firmware bugs, refer to:
4446 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
4450 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
4451 * Main fan tachometer reading (in RPM)
4453 * This register is present on all ThinkPads with a new-style EC, and
4454 * it is known not to be present on the A21m/e, and T22, as there is
4455 * something else in offset 0x84 according to the ACPI DSDT. Other
4456 * ThinkPads from this same time period (and earlier) probably lack the
4457 * tachometer as well.
4459 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
4460 * was never fixed by IBM to report the EC firmware version string
4461 * probably support the tachometer (like the early X models), so
4462 * detecting it is quite hard. We need more data to know for sure.
4464 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
4467 * FIRMWARE BUG: may go stale while the EC is switching to full speed
4470 * For firmware bugs, refer to:
4471 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
4473 * TPACPI_FAN_WR_ACPI_FANS:
4474 * ThinkPad X31, X40, X41. Not available in the X60.
4476 * FANS ACPI handle: takes three arguments: low speed, medium speed,
4477 * high speed. ACPI DSDT seems to map these three speeds to levels
4478 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
4479 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
4481 * The speeds are stored on handles
4482 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
4484 * There are three default speed sets, acessible as handles:
4485 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
4487 * ACPI DSDT switches which set is in use depending on various
4490 * TPACPI_FAN_WR_TPEC is also available and should be used to
4491 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
4492 * but the ACPI tables just mention level 7.
4495 enum { /* Fan control constants */
4496 fan_status_offset
= 0x2f, /* EC register 0x2f */
4497 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
4498 * 0x84 must be read before 0x85 */
4500 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
4501 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
4503 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
4506 enum fan_status_access_mode
{
4507 TPACPI_FAN_NONE
= 0, /* No fan status or control */
4508 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
4509 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
4512 enum fan_control_access_mode
{
4513 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
4514 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
4515 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
4516 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
4519 enum fan_control_commands
{
4520 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
4521 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
4522 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
4523 * and also watchdog cmd */
4526 static int fan_control_allowed
;
4528 static enum fan_status_access_mode fan_status_access_mode
;
4529 static enum fan_control_access_mode fan_control_access_mode
;
4530 static enum fan_control_commands fan_control_commands
;
4532 static u8 fan_control_initial_status
;
4533 static u8 fan_control_desired_level
;
4534 static int fan_watchdog_maxinterval
;
4536 static struct mutex fan_mutex
;
4538 static void fan_watchdog_fire(struct work_struct
*ignored
);
4539 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
4541 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
4542 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
4543 "\\FSPD", /* 600e/x, 770e, 770x */
4545 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
4546 "JFNS", /* 770x-JL */
4550 * Call with fan_mutex held
4552 static void fan_update_desired_level(u8 status
)
4555 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
4557 fan_control_desired_level
= 7;
4559 fan_control_desired_level
= status
;
4563 static int fan_get_status(u8
*status
)
4568 * Add TPACPI_FAN_RD_ACPI_FANS ? */
4570 switch (fan_status_access_mode
) {
4571 case TPACPI_FAN_RD_ACPI_GFAN
:
4572 /* 570, 600e/x, 770e, 770x */
4574 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
4582 case TPACPI_FAN_RD_TPEC
:
4583 /* all except 570, 600e/x, 770e, 770x */
4584 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
4599 static int fan_get_status_safe(u8
*status
)
4604 if (mutex_lock_interruptible(&fan_mutex
))
4605 return -ERESTARTSYS
;
4606 rc
= fan_get_status(&s
);
4608 fan_update_desired_level(s
);
4609 mutex_unlock(&fan_mutex
);
4617 static int fan_get_speed(unsigned int *speed
)
4621 switch (fan_status_access_mode
) {
4622 case TPACPI_FAN_RD_TPEC
:
4623 /* all except 570, 600e/x, 770e, 770x */
4624 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
4625 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
4629 *speed
= (hi
<< 8) | lo
;
4640 static int fan_set_level(int level
)
4642 if (!fan_control_allowed
)
4645 switch (fan_control_access_mode
) {
4646 case TPACPI_FAN_WR_ACPI_SFAN
:
4647 if (level
>= 0 && level
<= 7) {
4648 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
4654 case TPACPI_FAN_WR_ACPI_FANS
:
4655 case TPACPI_FAN_WR_TPEC
:
4656 if ((level
!= TP_EC_FAN_AUTO
) &&
4657 (level
!= TP_EC_FAN_FULLSPEED
) &&
4658 ((level
< 0) || (level
> 7)))
4661 /* safety net should the EC not support AUTO
4662 * or FULLSPEED mode bits and just ignore them */
4663 if (level
& TP_EC_FAN_FULLSPEED
)
4664 level
|= 7; /* safety min speed 7 */
4665 else if (level
& TP_EC_FAN_FULLSPEED
)
4666 level
|= 4; /* safety min speed 4 */
4668 if (!acpi_ec_write(fan_status_offset
, level
))
4671 tp_features
.fan_ctrl_status_undef
= 0;
4680 static int fan_set_level_safe(int level
)
4684 if (!fan_control_allowed
)
4687 if (mutex_lock_interruptible(&fan_mutex
))
4688 return -ERESTARTSYS
;
4690 if (level
== TPACPI_FAN_LAST_LEVEL
)
4691 level
= fan_control_desired_level
;
4693 rc
= fan_set_level(level
);
4695 fan_update_desired_level(level
);
4697 mutex_unlock(&fan_mutex
);
4701 static int fan_set_enable(void)
4706 if (!fan_control_allowed
)
4709 if (mutex_lock_interruptible(&fan_mutex
))
4710 return -ERESTARTSYS
;
4712 switch (fan_control_access_mode
) {
4713 case TPACPI_FAN_WR_ACPI_FANS
:
4714 case TPACPI_FAN_WR_TPEC
:
4715 rc
= fan_get_status(&s
);
4719 /* Don't go out of emergency fan mode */
4722 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
4725 if (!acpi_ec_write(fan_status_offset
, s
))
4728 tp_features
.fan_ctrl_status_undef
= 0;
4733 case TPACPI_FAN_WR_ACPI_SFAN
:
4734 rc
= fan_get_status(&s
);
4740 /* Set fan to at least level 4 */
4743 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
4753 mutex_unlock(&fan_mutex
);
4757 static int fan_set_disable(void)
4761 if (!fan_control_allowed
)
4764 if (mutex_lock_interruptible(&fan_mutex
))
4765 return -ERESTARTSYS
;
4768 switch (fan_control_access_mode
) {
4769 case TPACPI_FAN_WR_ACPI_FANS
:
4770 case TPACPI_FAN_WR_TPEC
:
4771 if (!acpi_ec_write(fan_status_offset
, 0x00))
4774 fan_control_desired_level
= 0;
4775 tp_features
.fan_ctrl_status_undef
= 0;
4779 case TPACPI_FAN_WR_ACPI_SFAN
:
4780 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
4783 fan_control_desired_level
= 0;
4791 mutex_unlock(&fan_mutex
);
4795 static int fan_set_speed(int speed
)
4799 if (!fan_control_allowed
)
4802 if (mutex_lock_interruptible(&fan_mutex
))
4803 return -ERESTARTSYS
;
4806 switch (fan_control_access_mode
) {
4807 case TPACPI_FAN_WR_ACPI_FANS
:
4808 if (speed
>= 0 && speed
<= 65535) {
4809 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
4810 speed
, speed
, speed
))
4820 mutex_unlock(&fan_mutex
);
4824 static void fan_watchdog_reset(void)
4826 static int fan_watchdog_active
;
4828 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
4831 if (fan_watchdog_active
)
4832 cancel_delayed_work(&fan_watchdog_task
);
4834 if (fan_watchdog_maxinterval
> 0 &&
4835 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
4836 fan_watchdog_active
= 1;
4837 if (!schedule_delayed_work(&fan_watchdog_task
,
4838 msecs_to_jiffies(fan_watchdog_maxinterval
4841 "failed to schedule the fan watchdog, "
4842 "watchdog will not trigger\n");
4845 fan_watchdog_active
= 0;
4848 static void fan_watchdog_fire(struct work_struct
*ignored
)
4852 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
4855 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
4856 rc
= fan_set_enable();
4858 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
4859 "will try again later...\n", -rc
);
4860 /* reschedule for later */
4861 fan_watchdog_reset();
4866 * SYSFS fan layout: hwmon compatible (device)
4869 * 0: "disengaged" mode
4871 * 2: native EC "auto" mode (recommended, hardware default)
4873 * pwm*: set speed in manual mode, ignored otherwise.
4874 * 0 is level 0; 255 is level 7. Intermediate points done with linear
4877 * fan*_input: tachometer reading, RPM
4880 * SYSFS fan layout: extensions
4882 * fan_watchdog (driver):
4883 * fan watchdog interval in seconds, 0 disables (default), max 120
4886 /* sysfs fan pwm1_enable ----------------------------------------------- */
4887 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
4888 struct device_attribute
*attr
,
4894 res
= fan_get_status_safe(&status
);
4898 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4899 if (status
!= fan_control_initial_status
) {
4900 tp_features
.fan_ctrl_status_undef
= 0;
4902 /* Return most likely status. In fact, it
4903 * might be the only possible status */
4904 status
= TP_EC_FAN_AUTO
;
4908 if (status
& TP_EC_FAN_FULLSPEED
) {
4910 } else if (status
& TP_EC_FAN_AUTO
) {
4915 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
4918 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
4919 struct device_attribute
*attr
,
4920 const char *buf
, size_t count
)
4925 if (parse_strtoul(buf
, 2, &t
))
4930 level
= TP_EC_FAN_FULLSPEED
;
4933 level
= TPACPI_FAN_LAST_LEVEL
;
4936 level
= TP_EC_FAN_AUTO
;
4939 /* reserved for software-controlled auto mode */
4945 res
= fan_set_level_safe(level
);
4951 fan_watchdog_reset();
4956 static struct device_attribute dev_attr_fan_pwm1_enable
=
4957 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
4958 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
4960 /* sysfs fan pwm1 ------------------------------------------------------ */
4961 static ssize_t
fan_pwm1_show(struct device
*dev
,
4962 struct device_attribute
*attr
,
4968 res
= fan_get_status_safe(&status
);
4972 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4973 if (status
!= fan_control_initial_status
) {
4974 tp_features
.fan_ctrl_status_undef
= 0;
4976 status
= TP_EC_FAN_AUTO
;
4981 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
4982 status
= fan_control_desired_level
;
4987 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
4990 static ssize_t
fan_pwm1_store(struct device
*dev
,
4991 struct device_attribute
*attr
,
4992 const char *buf
, size_t count
)
4996 u8 status
, newlevel
;
4998 if (parse_strtoul(buf
, 255, &s
))
5001 /* scale down from 0-255 to 0-7 */
5002 newlevel
= (s
>> 5) & 0x07;
5004 if (mutex_lock_interruptible(&fan_mutex
))
5005 return -ERESTARTSYS
;
5007 rc
= fan_get_status(&status
);
5008 if (!rc
&& (status
&
5009 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
5010 rc
= fan_set_level(newlevel
);
5014 fan_update_desired_level(newlevel
);
5015 fan_watchdog_reset();
5019 mutex_unlock(&fan_mutex
);
5020 return (rc
)? rc
: count
;
5023 static struct device_attribute dev_attr_fan_pwm1
=
5024 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
5025 fan_pwm1_show
, fan_pwm1_store
);
5027 /* sysfs fan fan1_input ------------------------------------------------ */
5028 static ssize_t
fan_fan1_input_show(struct device
*dev
,
5029 struct device_attribute
*attr
,
5035 res
= fan_get_speed(&speed
);
5039 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
5042 static struct device_attribute dev_attr_fan_fan1_input
=
5043 __ATTR(fan1_input
, S_IRUGO
,
5044 fan_fan1_input_show
, NULL
);
5046 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
5047 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
5050 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
5053 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
5054 const char *buf
, size_t count
)
5058 if (parse_strtoul(buf
, 120, &t
))
5061 if (!fan_control_allowed
)
5064 fan_watchdog_maxinterval
= t
;
5065 fan_watchdog_reset();
5070 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
5071 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
5073 /* --------------------------------------------------------------------- */
5074 static struct attribute
*fan_attributes
[] = {
5075 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
5076 &dev_attr_fan_fan1_input
.attr
,
5080 static const struct attribute_group fan_attr_group
= {
5081 .attrs
= fan_attributes
,
5084 static int __init
fan_init(struct ibm_init_struct
*iibm
)
5088 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
5090 mutex_init(&fan_mutex
);
5091 fan_status_access_mode
= TPACPI_FAN_NONE
;
5092 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
5093 fan_control_commands
= 0;
5094 fan_watchdog_maxinterval
= 0;
5095 tp_features
.fan_ctrl_status_undef
= 0;
5096 fan_control_desired_level
= 7;
5098 TPACPI_ACPIHANDLE_INIT(fans
);
5099 TPACPI_ACPIHANDLE_INIT(gfan
);
5100 TPACPI_ACPIHANDLE_INIT(sfan
);
5103 /* 570, 600e/x, 770e, 770x */
5104 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
5106 /* all other ThinkPads: note that even old-style
5107 * ThinkPad ECs supports the fan control register */
5108 if (likely(acpi_ec_read(fan_status_offset
,
5109 &fan_control_initial_status
))) {
5110 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
5112 /* In some ThinkPads, neither the EC nor the ACPI
5113 * DSDT initialize the fan status, and it ends up
5114 * being set to 0x07 when it *could* be either
5117 * Enable for TP-1Y (T43), TP-78 (R51e),
5118 * TP-76 (R52), TP-70 (T43, R52), which are known
5120 if (fan_control_initial_status
== 0x07) {
5121 switch (thinkpad_id
.ec_model
) {
5122 case 0x5931: /* TP-1Y */
5123 case 0x3837: /* TP-78 */
5124 case 0x3637: /* TP-76 */
5125 case 0x3037: /* TP-70 */
5126 printk(TPACPI_NOTICE
5127 "fan_init: initial fan status "
5128 "is unknown, assuming it is "
5130 tp_features
.fan_ctrl_status_undef
= 1;
5136 "ThinkPad ACPI EC access misbehaving, "
5137 "fan status and control unavailable\n");
5144 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
5145 fan_control_commands
|=
5146 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
5149 /* gfan without sfan means no fan control */
5150 /* all other models implement TP EC 0x2f control */
5154 fan_control_access_mode
=
5155 TPACPI_FAN_WR_ACPI_FANS
;
5156 fan_control_commands
|=
5157 TPACPI_FAN_CMD_SPEED
|
5158 TPACPI_FAN_CMD_LEVEL
|
5159 TPACPI_FAN_CMD_ENABLE
;
5161 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
5162 fan_control_commands
|=
5163 TPACPI_FAN_CMD_LEVEL
|
5164 TPACPI_FAN_CMD_ENABLE
;
5169 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
5170 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
5171 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
5172 fan_status_access_mode
, fan_control_access_mode
);
5174 /* fan control master switch */
5175 if (!fan_control_allowed
) {
5176 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
5177 fan_control_commands
= 0;
5178 dbg_printk(TPACPI_DBG_INIT
,
5179 "fan control features disabled by parameter\n");
5182 /* update fan_control_desired_level */
5183 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
5184 fan_get_status_safe(NULL
);
5186 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
5187 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
5188 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5191 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
5192 &driver_attr_fan_watchdog
);
5200 static void fan_exit(void)
5202 vdbg_printk(TPACPI_DBG_EXIT
,
5203 "cancelling any pending fan watchdog tasks\n");
5205 /* FIXME: can we really do this unconditionally? */
5206 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
5207 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
5208 &driver_attr_fan_watchdog
);
5210 cancel_delayed_work(&fan_watchdog_task
);
5211 flush_scheduled_work();
5214 static int fan_read(char *p
)
5219 unsigned int speed
= 0;
5221 switch (fan_status_access_mode
) {
5222 case TPACPI_FAN_RD_ACPI_GFAN
:
5223 /* 570, 600e/x, 770e, 770x */
5224 rc
= fan_get_status_safe(&status
);
5228 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
5230 (status
!= 0) ? "enabled" : "disabled", status
);
5233 case TPACPI_FAN_RD_TPEC
:
5234 /* all except 570, 600e/x, 770e, 770x */
5235 rc
= fan_get_status_safe(&status
);
5239 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5240 if (status
!= fan_control_initial_status
)
5241 tp_features
.fan_ctrl_status_undef
= 0;
5243 /* Return most likely status. In fact, it
5244 * might be the only possible status */
5245 status
= TP_EC_FAN_AUTO
;
5248 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
5249 (status
!= 0) ? "enabled" : "disabled");
5251 rc
= fan_get_speed(&speed
);
5255 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
5257 if (status
& TP_EC_FAN_FULLSPEED
)
5258 /* Disengaged mode takes precedence */
5259 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
5260 else if (status
& TP_EC_FAN_AUTO
)
5261 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
5263 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
5266 case TPACPI_FAN_NONE
:
5268 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5271 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
5272 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
5274 switch (fan_control_access_mode
) {
5275 case TPACPI_FAN_WR_ACPI_SFAN
:
5276 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
5280 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
5281 "auto, disengaged, full-speed)\n");
5286 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
5287 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
5288 "commands:\twatchdog <timeout> (<timeout> "
5289 "is 0 (off), 1-120 (seconds))\n");
5291 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
5292 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
5293 " (<speed> is 0-65535)\n");
5298 static int fan_write_cmd_level(const char *cmd
, int *rc
)
5302 if (strlencmp(cmd
, "level auto") == 0)
5303 level
= TP_EC_FAN_AUTO
;
5304 else if ((strlencmp(cmd
, "level disengaged") == 0) |
5305 (strlencmp(cmd
, "level full-speed") == 0))
5306 level
= TP_EC_FAN_FULLSPEED
;
5307 else if (sscanf(cmd
, "level %d", &level
) != 1)
5310 *rc
= fan_set_level_safe(level
);
5312 printk(TPACPI_ERR
"level command accepted for unsupported "
5313 "access mode %d", fan_control_access_mode
);
5318 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
5320 if (strlencmp(cmd
, "enable") != 0)
5323 *rc
= fan_set_enable();
5325 printk(TPACPI_ERR
"enable command accepted for unsupported "
5326 "access mode %d", fan_control_access_mode
);
5331 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
5333 if (strlencmp(cmd
, "disable") != 0)
5336 *rc
= fan_set_disable();
5338 printk(TPACPI_ERR
"disable command accepted for unsupported "
5339 "access mode %d", fan_control_access_mode
);
5344 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
5349 * Support speed <low> <medium> <high> ? */
5351 if (sscanf(cmd
, "speed %d", &speed
) != 1)
5354 *rc
= fan_set_speed(speed
);
5356 printk(TPACPI_ERR
"speed command accepted for unsupported "
5357 "access mode %d", fan_control_access_mode
);
5362 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
5366 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
5369 if (interval
< 0 || interval
> 120)
5372 fan_watchdog_maxinterval
= interval
;
5377 static int fan_write(char *buf
)
5382 while (!rc
&& (cmd
= next_cmd(&buf
))) {
5383 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
5384 fan_write_cmd_level(cmd
, &rc
)) &&
5385 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
5386 (fan_write_cmd_enable(cmd
, &rc
) ||
5387 fan_write_cmd_disable(cmd
, &rc
) ||
5388 fan_write_cmd_watchdog(cmd
, &rc
))) &&
5389 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
5390 fan_write_cmd_speed(cmd
, &rc
))
5394 fan_watchdog_reset();
5400 static struct ibm_struct fan_driver_data
= {
5407 /****************************************************************************
5408 ****************************************************************************
5412 ****************************************************************************
5413 ****************************************************************************/
5415 /* sysfs name ---------------------------------------------------------- */
5416 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
5417 struct device_attribute
*attr
,
5420 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
5423 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
5424 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
5426 /* --------------------------------------------------------------------- */
5429 static struct proc_dir_entry
*proc_dir
;
5432 * Module and infrastructure proble, init and exit handling
5435 static int force_load
;
5437 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
5438 static const char * __init
str_supported(int is_supported
)
5440 static char text_unsupported
[] __initdata
= "not supported";
5442 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
5444 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
5446 static void ibm_exit(struct ibm_struct
*ibm
)
5448 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
5450 list_del_init(&ibm
->all_drivers
);
5452 if (ibm
->flags
.acpi_notify_installed
) {
5453 dbg_printk(TPACPI_DBG_EXIT
,
5454 "%s: acpi_remove_notify_handler\n", ibm
->name
);
5456 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
5458 dispatch_acpi_notify
);
5459 ibm
->flags
.acpi_notify_installed
= 0;
5460 ibm
->flags
.acpi_notify_installed
= 0;
5463 if (ibm
->flags
.proc_created
) {
5464 dbg_printk(TPACPI_DBG_EXIT
,
5465 "%s: remove_proc_entry\n", ibm
->name
);
5466 remove_proc_entry(ibm
->name
, proc_dir
);
5467 ibm
->flags
.proc_created
= 0;
5470 if (ibm
->flags
.acpi_driver_registered
) {
5471 dbg_printk(TPACPI_DBG_EXIT
,
5472 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
5474 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
5475 kfree(ibm
->acpi
->driver
);
5476 ibm
->acpi
->driver
= NULL
;
5477 ibm
->flags
.acpi_driver_registered
= 0;
5480 if (ibm
->flags
.init_called
&& ibm
->exit
) {
5482 ibm
->flags
.init_called
= 0;
5485 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
5488 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
5491 struct ibm_struct
*ibm
= iibm
->data
;
5492 struct proc_dir_entry
*entry
;
5494 BUG_ON(ibm
== NULL
);
5496 INIT_LIST_HEAD(&ibm
->all_drivers
);
5498 if (ibm
->flags
.experimental
&& !experimental
)
5501 dbg_printk(TPACPI_DBG_INIT
,
5502 "probing for %s\n", ibm
->name
);
5505 ret
= iibm
->init(iibm
);
5507 return 0; /* probe failed */
5511 ibm
->flags
.init_called
= 1;
5515 if (ibm
->acpi
->hid
) {
5516 ret
= register_tpacpi_subdriver(ibm
);
5521 if (ibm
->acpi
->notify
) {
5522 ret
= setup_acpi_notify(ibm
);
5523 if (ret
== -ENODEV
) {
5524 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
5534 dbg_printk(TPACPI_DBG_INIT
,
5535 "%s installed\n", ibm
->name
);
5538 entry
= create_proc_entry(ibm
->name
,
5539 S_IFREG
| S_IRUGO
| S_IWUSR
,
5542 printk(TPACPI_ERR
"unable to create proc entry %s\n",
5547 entry
->owner
= THIS_MODULE
;
5549 entry
->read_proc
= &dispatch_procfs_read
;
5551 entry
->write_proc
= &dispatch_procfs_write
;
5552 ibm
->flags
.proc_created
= 1;
5555 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
5560 dbg_printk(TPACPI_DBG_INIT
,
5561 "%s: at error exit path with result %d\n",
5565 return (ret
< 0)? ret
: 0;
5570 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
5572 const struct dmi_device
*dev
= NULL
;
5573 char ec_fw_string
[18];
5578 memset(tp
, 0, sizeof(*tp
));
5580 if (dmi_name_in_vendors("IBM"))
5581 tp
->vendor
= PCI_VENDOR_ID_IBM
;
5582 else if (dmi_name_in_vendors("LENOVO"))
5583 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
5587 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
5589 if (!tp
->bios_version_str
)
5591 tp
->bios_model
= tp
->bios_version_str
[0]
5592 | (tp
->bios_version_str
[1] << 8);
5595 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
5596 * X32 or newer, all Z series; Some models must have an
5597 * up-to-date BIOS or they will not be detected.
5599 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
5601 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
5602 if (sscanf(dev
->name
,
5603 "IBM ThinkPad Embedded Controller -[%17c",
5604 ec_fw_string
) == 1) {
5605 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
5606 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
5608 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
5609 tp
->ec_model
= ec_fw_string
[0]
5610 | (ec_fw_string
[1] << 8);
5615 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
5617 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
5618 kfree(tp
->model_str
);
5619 tp
->model_str
= NULL
;
5623 static int __init
probe_for_thinkpad(void)
5631 * Non-ancient models have better DMI tagging, but very old models
5634 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
5636 /* ec is required because many other handles are relative to it */
5637 TPACPI_ACPIHANDLE_INIT(ec
);
5641 "Not yet supported ThinkPad detected!\n");
5646 * Risks a regression on very old machines, but reduces potential
5647 * false positives a damn great deal
5650 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
5652 if (!is_thinkpad
&& !force_load
)
5659 /* Module init, exit, parameters */
5661 static struct ibm_init_struct ibms_init
[] __initdata
= {
5663 .init
= thinkpad_acpi_driver_init
,
5664 .data
= &thinkpad_acpi_driver_data
,
5667 .init
= hotkey_init
,
5668 .data
= &hotkey_driver_data
,
5671 .init
= bluetooth_init
,
5672 .data
= &bluetooth_driver_data
,
5676 .data
= &wan_driver_data
,
5680 .data
= &video_driver_data
,
5684 .data
= &light_driver_data
,
5686 #ifdef CONFIG_THINKPAD_ACPI_DOCK
5689 .data
= &dock_driver_data
[0],
5693 .data
= &dock_driver_data
[1],
5696 #ifdef CONFIG_THINKPAD_ACPI_BAY
5699 .data
= &bay_driver_data
,
5704 .data
= &cmos_driver_data
,
5708 .data
= &led_driver_data
,
5712 .data
= &beep_driver_data
,
5715 .init
= thermal_init
,
5716 .data
= &thermal_driver_data
,
5719 .data
= &ecdump_driver_data
,
5722 .init
= brightness_init
,
5723 .data
= &brightness_driver_data
,
5726 .data
= &volume_driver_data
,
5730 .data
= &fan_driver_data
,
5734 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
5737 struct ibm_struct
*ibm
;
5739 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
5740 ibm
= ibms_init
[i
].data
;
5741 BUG_ON(ibm
== NULL
);
5743 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
5744 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
5746 strcpy(ibms_init
[i
].param
, val
);
5747 strcat(ibms_init
[i
].param
, ",");
5755 module_param(experimental
, int, 0);
5756 MODULE_PARM_DESC(experimental
,
5757 "Enables experimental features when non-zero");
5759 module_param_named(debug
, dbg_level
, uint
, 0);
5760 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
5762 module_param(force_load
, bool, 0);
5763 MODULE_PARM_DESC(force_load
,
5764 "Attempts to load the driver even on a "
5765 "mis-identified ThinkPad when true");
5767 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
5768 MODULE_PARM_DESC(fan_control
,
5769 "Enables setting fan parameters features when true");
5771 module_param_named(brightness_mode
, brightness_mode
, int, 0);
5772 MODULE_PARM_DESC(brightness_mode
,
5773 "Selects brightness control strategy: "
5774 "0=auto, 1=EC, 2=CMOS, 3=both");
5776 module_param(brightness_enable
, uint
, 0);
5777 MODULE_PARM_DESC(brightness_enable
,
5778 "Enables backlight control when 1, disables when 0");
5780 module_param(hotkey_report_mode
, uint
, 0);
5781 MODULE_PARM_DESC(hotkey_report_mode
,
5782 "used for backwards compatibility with userspace, "
5783 "see documentation");
5785 #define TPACPI_PARAM(feature) \
5786 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
5787 MODULE_PARM_DESC(feature, "Simulates thinkpad-aci procfs command " \
5788 "at module load, see documentation")
5790 TPACPI_PARAM(hotkey
);
5791 TPACPI_PARAM(bluetooth
);
5792 TPACPI_PARAM(video
);
5793 TPACPI_PARAM(light
);
5794 #ifdef CONFIG_THINKPAD_ACPI_DOCK
5797 #ifdef CONFIG_THINKPAD_ACPI_BAY
5799 #endif /* CONFIG_THINKPAD_ACPI_BAY */
5803 TPACPI_PARAM(ecdump
);
5804 TPACPI_PARAM(brightness
);
5805 TPACPI_PARAM(volume
);
5808 static void thinkpad_acpi_module_exit(void)
5810 struct ibm_struct
*ibm
, *itmp
;
5812 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
5814 list_for_each_entry_safe_reverse(ibm
, itmp
,
5815 &tpacpi_all_drivers
,
5820 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
5822 if (tpacpi_inputdev
) {
5823 if (tp_features
.input_device_registered
)
5824 input_unregister_device(tpacpi_inputdev
);
5826 input_free_device(tpacpi_inputdev
);
5830 hwmon_device_unregister(tpacpi_hwmon
);
5832 if (tp_features
.sensors_pdev_attrs_registered
)
5833 device_remove_file(&tpacpi_sensors_pdev
->dev
,
5834 &dev_attr_thinkpad_acpi_pdev_name
);
5835 if (tpacpi_sensors_pdev
)
5836 platform_device_unregister(tpacpi_sensors_pdev
);
5838 platform_device_unregister(tpacpi_pdev
);
5840 if (tp_features
.sensors_pdrv_attrs_registered
)
5841 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
5842 if (tp_features
.platform_drv_attrs_registered
)
5843 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
5845 if (tp_features
.sensors_pdrv_registered
)
5846 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
5848 if (tp_features
.platform_drv_registered
)
5849 platform_driver_unregister(&tpacpi_pdriver
);
5852 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
5854 kfree(thinkpad_id
.bios_version_str
);
5855 kfree(thinkpad_id
.ec_version_str
);
5856 kfree(thinkpad_id
.model_str
);
5860 static int __init
thinkpad_acpi_module_init(void)
5864 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
5866 /* Parameter checking */
5867 if (hotkey_report_mode
> 2)
5870 /* Driver-level probe */
5872 get_thinkpad_model_data(&thinkpad_id
);
5873 ret
= probe_for_thinkpad();
5875 thinkpad_acpi_module_exit();
5879 /* Driver initialization */
5881 TPACPI_ACPIHANDLE_INIT(ecrd
);
5882 TPACPI_ACPIHANDLE_INIT(ecwr
);
5884 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
5887 "unable to create proc dir " TPACPI_PROC_DIR
);
5888 thinkpad_acpi_module_exit();
5891 proc_dir
->owner
= THIS_MODULE
;
5893 ret
= platform_driver_register(&tpacpi_pdriver
);
5896 "unable to register main platform driver\n");
5897 thinkpad_acpi_module_exit();
5900 tp_features
.platform_drv_registered
= 1;
5902 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
5905 "unable to register hwmon platform driver\n");
5906 thinkpad_acpi_module_exit();
5909 tp_features
.sensors_pdrv_registered
= 1;
5911 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
5913 tp_features
.platform_drv_attrs_registered
= 1;
5914 ret
= tpacpi_create_driver_attributes(
5915 &tpacpi_hwmon_pdriver
.driver
);
5919 "unable to create sysfs driver attributes\n");
5920 thinkpad_acpi_module_exit();
5923 tp_features
.sensors_pdrv_attrs_registered
= 1;
5926 /* Device initialization */
5927 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
5929 if (IS_ERR(tpacpi_pdev
)) {
5930 ret
= PTR_ERR(tpacpi_pdev
);
5932 printk(TPACPI_ERR
"unable to register platform device\n");
5933 thinkpad_acpi_module_exit();
5936 tpacpi_sensors_pdev
= platform_device_register_simple(
5937 TPACPI_HWMON_DRVR_NAME
,
5939 if (IS_ERR(tpacpi_sensors_pdev
)) {
5940 ret
= PTR_ERR(tpacpi_sensors_pdev
);
5941 tpacpi_sensors_pdev
= NULL
;
5943 "unable to register hwmon platform device\n");
5944 thinkpad_acpi_module_exit();
5947 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
5948 &dev_attr_thinkpad_acpi_pdev_name
);
5951 "unable to create sysfs hwmon device attributes\n");
5952 thinkpad_acpi_module_exit();
5955 tp_features
.sensors_pdev_attrs_registered
= 1;
5956 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
5957 if (IS_ERR(tpacpi_hwmon
)) {
5958 ret
= PTR_ERR(tpacpi_hwmon
);
5959 tpacpi_hwmon
= NULL
;
5960 printk(TPACPI_ERR
"unable to register hwmon device\n");
5961 thinkpad_acpi_module_exit();
5964 mutex_init(&tpacpi_inputdev_send_mutex
);
5965 tpacpi_inputdev
= input_allocate_device();
5966 if (!tpacpi_inputdev
) {
5967 printk(TPACPI_ERR
"unable to allocate input device\n");
5968 thinkpad_acpi_module_exit();
5971 /* Prepare input device, but don't register */
5972 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
5973 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
5974 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
5975 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
5976 thinkpad_id
.vendor
:
5978 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
5979 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
5981 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
5982 ret
= ibm_init(&ibms_init
[i
]);
5983 if (ret
>= 0 && *ibms_init
[i
].param
)
5984 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
5986 thinkpad_acpi_module_exit();
5990 ret
= input_register_device(tpacpi_inputdev
);
5992 printk(TPACPI_ERR
"unable to register input device\n");
5993 thinkpad_acpi_module_exit();
5996 tp_features
.input_device_registered
= 1;
5999 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
6003 /* Please remove this in year 2009 */
6004 MODULE_ALIAS("ibm_acpi");
6007 * DMI matching for module autoloading
6009 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
6010 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
6012 * Only models listed in thinkwiki will be supported, so add yours
6013 * if it is not there yet.
6015 #define IBM_BIOS_MODULE_ALIAS(__type) \
6016 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
6018 /* Non-ancient thinkpads */
6019 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
6020 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
6022 /* Ancient thinkpad BIOSes have to be identified by
6023 * BIOS type or model number, and there are far less
6024 * BIOS types than model numbers... */
6025 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
6026 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
6027 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
6029 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
6030 MODULE_DESCRIPTION(TPACPI_DESC
);
6031 MODULE_VERSION(TPACPI_VERSION
);
6032 MODULE_LICENSE("GPL");
6034 module_init(thinkpad_acpi_module_init
);
6035 module_exit(thinkpad_acpi_module_exit
);