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-20071112"
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
{
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 hotkey_report_mode_locked
:1;
231 u32 platform_drv_registered
:1;
232 u32 platform_drv_attrs_registered
:1;
233 u32 sensors_pdrv_registered
:1;
234 u32 sensors_pdrv_attrs_registered
:1;
235 u32 sensors_pdev_attrs_registered
:1;
236 u32 hotkey_poll_active
:1;
239 struct thinkpad_id_data
{
240 unsigned int vendor
; /* ThinkPad vendor:
241 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
243 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
244 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
246 u16 bios_model
; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */
251 static struct thinkpad_id_data thinkpad_id
;
254 TPACPI_LIFE_INIT
= 0,
259 static int experimental
;
260 static u32 dbg_level
;
262 /****************************************************************************
263 ****************************************************************************
265 * ACPI Helpers and device model
267 ****************************************************************************
268 ****************************************************************************/
270 /*************************************************************************
274 static acpi_handle root_handle
;
276 #define TPACPI_HANDLE(object, parent, paths...) \
277 static acpi_handle object##_handle; \
278 static acpi_handle *object##_parent = &parent##_handle; \
279 static char *object##_path; \
280 static char *object##_paths[] = { paths }
282 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
283 "\\_SB.PCI.ISA.EC", /* 570 */
284 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
285 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
286 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
287 "\\_SB.PCI0.ICH3.EC0", /* R31 */
288 "\\_SB.PCI0.LPC.EC", /* all others */
291 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
292 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
294 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, */
296 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
297 "\\CMS", /* R40, R40e */
300 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
301 "^HKEY", /* R30, R31 */
302 "HKEY", /* all others */
306 /*************************************************************************
310 static int acpi_evalf(acpi_handle handle
,
311 void *res
, char *method
, char *fmt
, ...)
314 struct acpi_object_list params
;
315 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
316 struct acpi_buffer result
, *resultp
;
317 union acpi_object out_obj
;
325 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
338 params
.pointer
= &in_objs
[0];
345 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
346 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
348 /* add more types as needed */
350 printk(TPACPI_ERR
"acpi_evalf() called "
351 "with invalid format character '%c'\n", c
);
357 if (res_type
!= 'v') {
358 result
.length
= sizeof(out_obj
);
359 result
.pointer
= &out_obj
;
364 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
369 *(int *)res
= out_obj
.integer
.value
;
370 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
373 success
= status
== AE_OK
;
375 /* add more types as needed */
377 printk(TPACPI_ERR
"acpi_evalf() called "
378 "with invalid format character '%c'\n", res_type
);
382 if (!success
&& !quiet
)
383 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
384 method
, fmt0
, status
);
389 static int acpi_ec_read(int i
, u8
*p
)
394 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
398 if (ec_read(i
, p
) < 0)
405 static int acpi_ec_write(int i
, u8 v
)
408 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
411 if (ec_write(i
, v
) < 0)
418 static int _sta(acpi_handle handle
)
422 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
428 static int issue_thinkpad_cmos_command(int cmos_cmd
)
433 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
439 /*************************************************************************
443 #define TPACPI_ACPIHANDLE_INIT(object) \
444 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
445 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
447 static void drv_acpi_handle_init(char *name
,
448 acpi_handle
*handle
, acpi_handle parent
,
449 char **paths
, int num_paths
, char **path
)
454 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
457 for (i
= 0; i
< num_paths
; i
++) {
458 status
= acpi_get_handle(parent
, paths
[i
], handle
);
459 if (ACPI_SUCCESS(status
)) {
461 dbg_printk(TPACPI_DBG_INIT
,
462 "Found ACPI handle %s for %s\n",
468 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
473 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
475 struct ibm_struct
*ibm
= data
;
477 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
480 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
483 ibm
->acpi
->notify(ibm
, event
);
486 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
493 if (!*ibm
->acpi
->handle
)
496 vdbg_printk(TPACPI_DBG_INIT
,
497 "setting up ACPI notify for %s\n", ibm
->name
);
499 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
501 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
506 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
507 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
508 TPACPI_ACPI_EVENT_PREFIX
,
511 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
512 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
513 if (ACPI_FAILURE(status
)) {
514 if (status
== AE_ALREADY_EXISTS
) {
516 "another device driver is already "
517 "handling %s events\n", ibm
->name
);
520 "acpi_install_notify_handler(%s) failed: %d\n",
525 ibm
->flags
.acpi_notify_installed
= 1;
529 static int __init
tpacpi_device_add(struct acpi_device
*device
)
534 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
538 dbg_printk(TPACPI_DBG_INIT
,
539 "registering %s as an ACPI driver\n", ibm
->name
);
543 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
544 if (!ibm
->acpi
->driver
) {
545 printk(TPACPI_ERR
"kzalloc(ibm->driver) failed\n");
549 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
550 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 class_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_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
)
1303 /* Initial state for compares */
1304 mutex_lock(&hotkey_thread_data_mutex
);
1305 change_detector
= hotkey_config_change
;
1306 mask
= hotkey_source_mask
& hotkey_mask
;
1307 mutex_unlock(&hotkey_thread_data_mutex
);
1308 hotkey_read_nvram(&s
[so
], mask
);
1310 while (!kthread_should_stop() && hotkey_poll_freq
) {
1312 t
= 1000/hotkey_poll_freq
;
1313 t
= msleep_interruptible(t
);
1314 if (unlikely(kthread_should_stop()))
1316 must_reset
= try_to_freeze();
1317 if (t
> 0 && !must_reset
)
1320 mutex_lock(&hotkey_thread_data_mutex
);
1321 if (must_reset
|| hotkey_config_change
!= change_detector
) {
1322 /* forget old state on thaw or config change */
1325 change_detector
= hotkey_config_change
;
1327 mask
= hotkey_source_mask
& hotkey_mask
;
1328 mutex_unlock(&hotkey_thread_data_mutex
);
1330 hotkey_read_nvram(&s
[si
], mask
);
1331 hotkey_compare_and_issue_event(&s
[so
], &s
[si
], mask
);
1338 mutex_unlock(&hotkey_thread_mutex
);
1342 static void hotkey_poll_stop_sync(void)
1344 if (tpacpi_hotkey_task
) {
1345 if (frozen(tpacpi_hotkey_task
) ||
1346 freezing(tpacpi_hotkey_task
))
1347 thaw_process(tpacpi_hotkey_task
);
1349 kthread_stop(tpacpi_hotkey_task
);
1350 tpacpi_hotkey_task
= NULL
;
1351 mutex_lock(&hotkey_thread_mutex
);
1352 /* at this point, the thread did exit */
1353 mutex_unlock(&hotkey_thread_mutex
);
1357 /* call with hotkey_mutex held */
1358 static void hotkey_poll_setup(int may_warn
)
1360 if ((hotkey_source_mask
& hotkey_mask
) != 0 &&
1361 hotkey_poll_freq
> 0 &&
1362 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1363 if (!tpacpi_hotkey_task
) {
1364 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1367 if (IS_ERR(tpacpi_hotkey_task
)) {
1368 tpacpi_hotkey_task
= NULL
;
1370 "could not create kernel thread "
1371 "for hotkey polling\n");
1375 hotkey_poll_stop_sync();
1377 hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1378 printk(TPACPI_NOTICE
1379 "hot keys 0x%08x require polling, "
1380 "which is currently disabled\n",
1381 hotkey_source_mask
);
1386 static void hotkey_poll_setup_safe(int may_warn
)
1388 mutex_lock(&hotkey_mutex
);
1389 hotkey_poll_setup(may_warn
);
1390 mutex_unlock(&hotkey_mutex
);
1393 static int hotkey_inputdev_open(struct input_dev
*dev
)
1395 switch (tpacpi_lifecycle
) {
1396 case TPACPI_LIFE_INIT
:
1398 * hotkey_init will call hotkey_poll_setup_safe
1399 * at the appropriate moment
1402 case TPACPI_LIFE_EXITING
:
1404 case TPACPI_LIFE_RUNNING
:
1405 hotkey_poll_setup_safe(0);
1409 /* Should only happen if tpacpi_lifecycle is corrupt */
1414 static void hotkey_inputdev_close(struct input_dev
*dev
)
1416 /* disable hotkey polling when possible */
1417 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
)
1418 hotkey_poll_setup_safe(0);
1420 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1422 /* sysfs hotkey enable ------------------------------------------------- */
1423 static ssize_t
hotkey_enable_show(struct device
*dev
,
1424 struct device_attribute
*attr
,
1429 res
= hotkey_status_get(&status
);
1433 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1436 static ssize_t
hotkey_enable_store(struct device
*dev
,
1437 struct device_attribute
*attr
,
1438 const char *buf
, size_t count
)
1443 if (parse_strtoul(buf
, 1, &t
))
1446 res
= hotkey_status_set(t
);
1448 return (res
) ? res
: count
;
1451 static struct device_attribute dev_attr_hotkey_enable
=
1452 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
1453 hotkey_enable_show
, hotkey_enable_store
);
1455 /* sysfs hotkey mask --------------------------------------------------- */
1456 static ssize_t
hotkey_mask_show(struct device
*dev
,
1457 struct device_attribute
*attr
,
1462 if (mutex_lock_interruptible(&hotkey_mutex
))
1463 return -ERESTARTSYS
;
1464 res
= hotkey_mask_get();
1465 mutex_unlock(&hotkey_mutex
);
1468 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
1471 static ssize_t
hotkey_mask_store(struct device
*dev
,
1472 struct device_attribute
*attr
,
1473 const char *buf
, size_t count
)
1478 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
1481 if (mutex_lock_interruptible(&hotkey_mutex
))
1482 return -ERESTARTSYS
;
1484 res
= hotkey_mask_set(t
);
1486 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1487 hotkey_poll_setup(1);
1490 mutex_unlock(&hotkey_mutex
);
1492 return (res
) ? res
: count
;
1495 static struct device_attribute dev_attr_hotkey_mask
=
1496 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
1497 hotkey_mask_show
, hotkey_mask_store
);
1499 /* sysfs hotkey bios_enabled ------------------------------------------- */
1500 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
1501 struct device_attribute
*attr
,
1504 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
1507 static struct device_attribute dev_attr_hotkey_bios_enabled
=
1508 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
1510 /* sysfs hotkey bios_mask ---------------------------------------------- */
1511 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
1512 struct device_attribute
*attr
,
1515 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
1518 static struct device_attribute dev_attr_hotkey_bios_mask
=
1519 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
1521 /* sysfs hotkey all_mask ----------------------------------------------- */
1522 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
1523 struct device_attribute
*attr
,
1526 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1527 hotkey_all_mask
| hotkey_source_mask
);
1530 static struct device_attribute dev_attr_hotkey_all_mask
=
1531 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
1533 /* sysfs hotkey recommended_mask --------------------------------------- */
1534 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
1535 struct device_attribute
*attr
,
1538 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1539 (hotkey_all_mask
| hotkey_source_mask
)
1540 & ~hotkey_reserved_mask
);
1543 static struct device_attribute dev_attr_hotkey_recommended_mask
=
1544 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
1545 hotkey_recommended_mask_show
, NULL
);
1547 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1549 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
1550 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
1551 struct device_attribute
*attr
,
1554 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
1557 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
1558 struct device_attribute
*attr
,
1559 const char *buf
, size_t count
)
1563 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
1564 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
1567 if (mutex_lock_interruptible(&hotkey_mutex
))
1568 return -ERESTARTSYS
;
1570 HOTKEY_CONFIG_CRITICAL_START
1571 hotkey_source_mask
= t
;
1572 HOTKEY_CONFIG_CRITICAL_END
1574 hotkey_poll_setup(1);
1576 mutex_unlock(&hotkey_mutex
);
1581 static struct device_attribute dev_attr_hotkey_source_mask
=
1582 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
1583 hotkey_source_mask_show
, hotkey_source_mask_store
);
1585 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
1586 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
1587 struct device_attribute
*attr
,
1590 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
1593 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
1594 struct device_attribute
*attr
,
1595 const char *buf
, size_t count
)
1599 if (parse_strtoul(buf
, 25, &t
))
1602 if (mutex_lock_interruptible(&hotkey_mutex
))
1603 return -ERESTARTSYS
;
1605 hotkey_poll_freq
= t
;
1607 hotkey_poll_setup(1);
1608 mutex_unlock(&hotkey_mutex
);
1613 static struct device_attribute dev_attr_hotkey_poll_freq
=
1614 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
1615 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
1617 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1619 /* sysfs hotkey radio_sw ----------------------------------------------- */
1620 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
1621 struct device_attribute
*attr
,
1625 res
= hotkey_get_wlsw(&s
);
1629 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1632 static struct device_attribute dev_attr_hotkey_radio_sw
=
1633 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
1635 /* sysfs hotkey report_mode -------------------------------------------- */
1636 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
1637 struct device_attribute
*attr
,
1640 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1641 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
1644 static ssize_t
hotkey_report_mode_store(struct device
*dev
,
1645 struct device_attribute
*attr
,
1646 const char *buf
, size_t count
)
1651 if (parse_strtoul(buf
, 2, &t
) || (t
< 1))
1654 if (t
!= hotkey_report_mode
) {
1655 if (tp_features
.hotkey_report_mode_locked
)
1657 hotkey_report_mode
= t
;
1658 printk(TPACPI_NOTICE
"hot key report mode set to %d\n",
1659 hotkey_report_mode
);
1662 return (res
) ? res
: count
;
1665 static struct device_attribute dev_attr_hotkey_report_mode
=
1666 __ATTR(hotkey_report_mode
, S_IWUSR
| S_IRUGO
,
1667 hotkey_report_mode_show
, hotkey_report_mode_store
);
1669 /* sysfs wakeup reason ------------------------------------------------- */
1670 static ssize_t
hotkey_wakeup_reason_show(struct device
*dev
,
1671 struct device_attribute
*attr
,
1674 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_wakeup_reason
);
1677 static struct device_attribute dev_attr_hotkey_wakeup_reason
=
1678 __ATTR(wakeup_reason
, S_IRUGO
, hotkey_wakeup_reason_show
, NULL
);
1680 /* sysfs wakeup hotunplug_complete ------------------------------------- */
1681 static ssize_t
hotkey_wakeup_hotunplug_complete_show(struct device
*dev
,
1682 struct device_attribute
*attr
,
1685 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_autosleep_ack
);
1688 static struct device_attribute dev_attr_hotkey_wakeup_hotunplug_complete
=
1689 __ATTR(wakeup_hotunplug_complete
, S_IRUGO
,
1690 hotkey_wakeup_hotunplug_complete_show
, NULL
);
1692 /* --------------------------------------------------------------------- */
1694 static struct attribute
*hotkey_attributes
[] __initdata
= {
1695 &dev_attr_hotkey_enable
.attr
,
1696 &dev_attr_hotkey_report_mode
.attr
,
1699 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
1700 &dev_attr_hotkey_mask
.attr
,
1701 &dev_attr_hotkey_bios_enabled
.attr
,
1702 &dev_attr_hotkey_bios_mask
.attr
,
1703 &dev_attr_hotkey_all_mask
.attr
,
1704 &dev_attr_hotkey_recommended_mask
.attr
,
1705 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1706 &dev_attr_hotkey_source_mask
.attr
,
1707 &dev_attr_hotkey_poll_freq
.attr
,
1709 &dev_attr_hotkey_wakeup_reason
.attr
,
1710 &dev_attr_hotkey_wakeup_hotunplug_complete
.attr
,
1713 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
1716 static u16 ibm_keycode_map
[] __initdata
= {
1717 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1718 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
1719 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1720 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1721 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
1722 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1723 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1724 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1725 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1726 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
1727 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1728 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1729 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1730 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1731 KEY_RESERVED
, /* 0x14: VOLUME UP */
1732 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1733 KEY_RESERVED
, /* 0x16: MUTE */
1734 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1735 /* (assignments unknown, please report if found) */
1736 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1737 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1739 static u16 lenovo_keycode_map
[] __initdata
= {
1740 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1741 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
1742 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1743 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1744 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
1745 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1746 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1747 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1748 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
1749 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
1750 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
1751 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1752 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1753 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1754 KEY_RESERVED
, /* 0x14: VOLUME UP */
1755 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1756 KEY_RESERVED
, /* 0x16: MUTE */
1757 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1758 /* (assignments unknown, please report if found) */
1759 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1760 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1763 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
1764 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
1765 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
1771 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
1773 BUG_ON(!tpacpi_inputdev
);
1774 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
1775 tpacpi_inputdev
->close
!= NULL
);
1777 TPACPI_ACPIHANDLE_INIT(hkey
);
1778 mutex_init(&hotkey_mutex
);
1780 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1781 mutex_init(&hotkey_thread_mutex
);
1782 mutex_init(&hotkey_thread_data_mutex
);
1785 /* hotkey not supported on 570 */
1786 tp_features
.hotkey
= hkey_handle
!= NULL
;
1788 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
1789 str_supported(tp_features
.hotkey
));
1791 if (tp_features
.hotkey
) {
1792 hotkey_dev_attributes
= create_attr_set(12, NULL
);
1793 if (!hotkey_dev_attributes
)
1795 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1797 ARRAY_SIZE(hotkey_attributes
));
1801 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1802 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
1803 for HKEY interface version 0x100 */
1804 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
1805 if ((hkeyv
>> 8) != 1) {
1806 printk(TPACPI_ERR
"unknown version of the "
1807 "HKEY interface: 0x%x\n", hkeyv
);
1808 printk(TPACPI_ERR
"please report this to %s\n",
1812 * MHKV 0x100 in A31, R40, R40e,
1813 * T4x, X31, and later
1815 tp_features
.hotkey_mask
= 1;
1819 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
1820 str_supported(tp_features
.hotkey_mask
));
1822 if (tp_features
.hotkey_mask
) {
1823 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
1826 "missing MHKA handler, "
1827 "please report this to %s\n",
1829 /* FN+F12, FN+F4, FN+F3 */
1830 hotkey_all_mask
= 0x080cU
;
1834 /* hotkey_source_mask *must* be zero for
1835 * the first hotkey_mask_get */
1836 res
= hotkey_status_get(&hotkey_orig_status
);
1837 if (!res
&& tp_features
.hotkey_mask
) {
1838 res
= hotkey_mask_get();
1839 hotkey_orig_mask
= hotkey_mask
;
1841 res
= add_many_to_attr_set(
1842 hotkey_dev_attributes
,
1843 hotkey_mask_attributes
,
1844 ARRAY_SIZE(hotkey_mask_attributes
));
1848 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1849 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
1852 vdbg_printk(TPACPI_DBG_INIT
,
1853 "hotkey source mask 0x%08x, polling freq %d\n",
1854 hotkey_source_mask
, hotkey_poll_freq
);
1857 /* Not all thinkpads have a hardware radio switch */
1858 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
1859 tp_features
.hotkey_wlsw
= 1;
1861 "radio switch found; radios are %s\n",
1862 enabled(status
, 0));
1863 res
= add_to_attr_set(hotkey_dev_attributes
,
1864 &dev_attr_hotkey_radio_sw
.attr
);
1868 res
= register_attr_set_with_sysfs(
1869 hotkey_dev_attributes
,
1870 &tpacpi_pdev
->dev
.kobj
);
1874 /* Set up key map */
1876 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
1878 if (!hotkey_keycode_map
) {
1880 "failed to allocate memory for key map\n");
1884 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
1885 dbg_printk(TPACPI_DBG_INIT
,
1886 "using Lenovo default hot key map\n");
1887 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
1888 TPACPI_HOTKEY_MAP_SIZE
);
1890 dbg_printk(TPACPI_DBG_INIT
,
1891 "using IBM default hot key map\n");
1892 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
1893 TPACPI_HOTKEY_MAP_SIZE
);
1896 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
1897 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
1898 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
1899 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
1900 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
1901 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
1902 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
1903 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
1904 set_bit(hotkey_keycode_map
[i
],
1905 tpacpi_inputdev
->keybit
);
1907 if (i
< sizeof(hotkey_reserved_mask
)*8)
1908 hotkey_reserved_mask
|= 1 << i
;
1912 if (tp_features
.hotkey_wlsw
) {
1913 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
1914 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
1917 dbg_printk(TPACPI_DBG_INIT
,
1918 "enabling hot key handling\n");
1919 res
= hotkey_status_set(1);
1922 res
= hotkey_mask_set(((hotkey_all_mask
| hotkey_source_mask
)
1923 & ~hotkey_reserved_mask
)
1924 | hotkey_orig_mask
);
1928 if (hotkey_report_mode
> 0) {
1929 tp_features
.hotkey_report_mode_locked
= 1;
1931 hotkey_report_mode
= 1;
1932 vdbg_printk(TPACPI_DBG_INIT
,
1933 "hot key reporting mode can be "
1934 "changed at runtime\n");
1937 dbg_printk(TPACPI_DBG_INIT
,
1938 "legacy hot key reporting over procfs %s\n",
1939 (hotkey_report_mode
< 2) ?
1940 "enabled" : "disabled");
1942 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1943 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
1944 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
1946 hotkey_poll_setup_safe(1);
1950 return (tp_features
.hotkey
)? 0 : 1;
1953 static void hotkey_exit(void)
1955 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1956 hotkey_poll_stop_sync();
1959 if (tp_features
.hotkey
) {
1960 dbg_printk(TPACPI_DBG_EXIT
,
1961 "restoring original hot key mask\n");
1962 /* no short-circuit boolean operator below! */
1963 if ((hotkey_mask_set(hotkey_orig_mask
) |
1964 hotkey_status_set(hotkey_orig_status
)) != 0)
1966 "failed to restore hot key mask "
1967 "to BIOS defaults\n");
1970 if (hotkey_dev_attributes
) {
1971 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
1972 hotkey_dev_attributes
= NULL
;
1976 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
1979 unsigned int scancode
;
1984 if (event
!= 0x80) {
1986 "unknown HKEY notification event %d\n", event
);
1987 /* forward it to userspace, maybe it knows how to handle it */
1988 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
1994 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
1995 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
2008 switch (hkey
>> 12) {
2010 /* 0x1000-0x1FFF: key presses */
2011 scancode
= hkey
& 0xfff;
2012 if (scancode
> 0 && scancode
< 0x21) {
2014 if (!(hotkey_source_mask
& (1 << scancode
))) {
2015 tpacpi_input_send_key(scancode
);
2027 case 0x2304: /* suspend, undock */
2028 case 0x2404: /* hibernation, undock */
2029 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_UNDOCK
;
2032 case 0x2305: /* suspend, bay eject */
2033 case 0x2405: /* hibernation, bay eject */
2034 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_BAYEJ
;
2040 if (hotkey_wakeup_reason
!= TP_ACPI_WAKEUP_NONE
) {
2042 "woke up due to a hot-unplug "
2047 /* bay-related wakeups */
2048 if (hkey
== 0x3003) {
2049 hotkey_autosleep_ack
= 1;
2057 /* dock-related wakeups */
2058 if (hkey
== 0x4003) {
2059 hotkey_autosleep_ack
= 1;
2067 /* 0x5000-0x5FFF: On screen display helpers */
2070 /* Lenovo Vista BIOS: brightness changed */
2074 /* LID switch events. Do not propagate */
2082 /* 0x7000-0x7FFF: misc */
2083 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
2084 tpacpi_input_send_radiosw();
2088 /* fallthrough to default */
2093 printk(TPACPI_NOTICE
2094 "unhandled HKEY event 0x%04x\n", hkey
);
2097 if (!ignore_acpi_ev
&&
2098 (send_acpi_ev
|| hotkey_report_mode
< 2)) {
2099 acpi_bus_generate_event(ibm
->acpi
->device
, event
, hkey
);
2104 static void hotkey_suspend(pm_message_t state
)
2106 /* Do these on suspend, we get the events on early resume! */
2107 hotkey_wakeup_reason
= TP_ACPI_WAKEUP_NONE
;
2108 hotkey_autosleep_ack
= 0;
2111 static void hotkey_resume(void)
2113 if (hotkey_mask_get())
2115 "error while trying to read hot key mask "
2117 tpacpi_input_send_radiosw();
2118 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2119 hotkey_poll_setup_safe(0);
2123 /* procfs -------------------------------------------------------------- */
2124 static int hotkey_read(char *p
)
2129 if (!tp_features
.hotkey
) {
2130 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2134 if (mutex_lock_interruptible(&hotkey_mutex
))
2135 return -ERESTARTSYS
;
2136 res
= hotkey_status_get(&status
);
2138 res
= hotkey_mask_get();
2139 mutex_unlock(&hotkey_mutex
);
2143 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
2144 if (tp_features
.hotkey_mask
) {
2145 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
2146 len
+= sprintf(p
+ len
,
2147 "commands:\tenable, disable, reset, <mask>\n");
2149 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
2150 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
2156 static int hotkey_write(char *buf
)
2162 if (!tp_features
.hotkey
)
2165 if (mutex_lock_interruptible(&hotkey_mutex
))
2166 return -ERESTARTSYS
;
2172 while ((cmd
= next_cmd(&buf
))) {
2173 if (strlencmp(cmd
, "enable") == 0) {
2175 } else if (strlencmp(cmd
, "disable") == 0) {
2177 } else if (strlencmp(cmd
, "reset") == 0) {
2178 status
= hotkey_orig_status
;
2179 mask
= hotkey_orig_mask
;
2180 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
2182 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
2190 res
= hotkey_status_set(status
);
2192 if (!res
&& mask
!= hotkey_mask
)
2193 res
= hotkey_mask_set(mask
);
2196 mutex_unlock(&hotkey_mutex
);
2200 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
2201 .hid
= TPACPI_ACPI_HKEY_HID
,
2202 .notify
= hotkey_notify
,
2203 .handle
= &hkey_handle
,
2204 .type
= ACPI_DEVICE_NOTIFY
,
2207 static struct ibm_struct hotkey_driver_data
= {
2209 .read
= hotkey_read
,
2210 .write
= hotkey_write
,
2211 .exit
= hotkey_exit
,
2212 .resume
= hotkey_resume
,
2213 .suspend
= hotkey_suspend
,
2214 .acpi
= &ibm_hotkey_acpidriver
,
2217 /*************************************************************************
2218 * Bluetooth subdriver
2222 /* ACPI GBDC/SBDC bits */
2223 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
2224 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
2225 TP_ACPI_BLUETOOTH_UNK
= 0x04, /* unknown function */
2228 static int bluetooth_get_radiosw(void);
2229 static int bluetooth_set_radiosw(int radio_on
);
2231 /* sysfs bluetooth enable ---------------------------------------------- */
2232 static ssize_t
bluetooth_enable_show(struct device
*dev
,
2233 struct device_attribute
*attr
,
2238 status
= bluetooth_get_radiosw();
2242 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
2245 static ssize_t
bluetooth_enable_store(struct device
*dev
,
2246 struct device_attribute
*attr
,
2247 const char *buf
, size_t count
)
2252 if (parse_strtoul(buf
, 1, &t
))
2255 res
= bluetooth_set_radiosw(t
);
2257 return (res
) ? res
: count
;
2260 static struct device_attribute dev_attr_bluetooth_enable
=
2261 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
2262 bluetooth_enable_show
, bluetooth_enable_store
);
2264 /* --------------------------------------------------------------------- */
2266 static struct attribute
*bluetooth_attributes
[] = {
2267 &dev_attr_bluetooth_enable
.attr
,
2271 static const struct attribute_group bluetooth_attr_group
= {
2272 .attrs
= bluetooth_attributes
,
2275 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
2280 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
2282 TPACPI_ACPIHANDLE_INIT(hkey
);
2284 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2285 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
2286 tp_features
.bluetooth
= hkey_handle
&&
2287 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
2289 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
2290 str_supported(tp_features
.bluetooth
),
2293 if (tp_features
.bluetooth
) {
2294 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
2295 /* no bluetooth hardware present in system */
2296 tp_features
.bluetooth
= 0;
2297 dbg_printk(TPACPI_DBG_INIT
,
2298 "bluetooth hardware not installed\n");
2300 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2301 &bluetooth_attr_group
);
2307 return (tp_features
.bluetooth
)? 0 : 1;
2310 static void bluetooth_exit(void)
2312 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2313 &bluetooth_attr_group
);
2316 static int bluetooth_get_radiosw(void)
2320 if (!tp_features
.bluetooth
)
2323 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2326 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
2329 static int bluetooth_set_radiosw(int radio_on
)
2333 if (!tp_features
.bluetooth
)
2336 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2339 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
2341 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
2342 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
2348 /* procfs -------------------------------------------------------------- */
2349 static int bluetooth_read(char *p
)
2352 int status
= bluetooth_get_radiosw();
2354 if (!tp_features
.bluetooth
)
2355 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2357 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2358 (status
)? "enabled" : "disabled");
2359 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2365 static int bluetooth_write(char *buf
)
2369 if (!tp_features
.bluetooth
)
2372 while ((cmd
= next_cmd(&buf
))) {
2373 if (strlencmp(cmd
, "enable") == 0) {
2374 bluetooth_set_radiosw(1);
2375 } else if (strlencmp(cmd
, "disable") == 0) {
2376 bluetooth_set_radiosw(0);
2384 static struct ibm_struct bluetooth_driver_data
= {
2385 .name
= "bluetooth",
2386 .read
= bluetooth_read
,
2387 .write
= bluetooth_write
,
2388 .exit
= bluetooth_exit
,
2391 /*************************************************************************
2396 /* ACPI GWAN/SWAN bits */
2397 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
2398 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
2399 TP_ACPI_WANCARD_UNK
= 0x04, /* unknown function */
2402 static int wan_get_radiosw(void);
2403 static int wan_set_radiosw(int radio_on
);
2405 /* sysfs wan enable ---------------------------------------------------- */
2406 static ssize_t
wan_enable_show(struct device
*dev
,
2407 struct device_attribute
*attr
,
2412 status
= wan_get_radiosw();
2416 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
2419 static ssize_t
wan_enable_store(struct device
*dev
,
2420 struct device_attribute
*attr
,
2421 const char *buf
, size_t count
)
2426 if (parse_strtoul(buf
, 1, &t
))
2429 res
= wan_set_radiosw(t
);
2431 return (res
) ? res
: count
;
2434 static struct device_attribute dev_attr_wan_enable
=
2435 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
2436 wan_enable_show
, wan_enable_store
);
2438 /* --------------------------------------------------------------------- */
2440 static struct attribute
*wan_attributes
[] = {
2441 &dev_attr_wan_enable
.attr
,
2445 static const struct attribute_group wan_attr_group
= {
2446 .attrs
= wan_attributes
,
2449 static int __init
wan_init(struct ibm_init_struct
*iibm
)
2454 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
2456 TPACPI_ACPIHANDLE_INIT(hkey
);
2458 tp_features
.wan
= hkey_handle
&&
2459 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
2461 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
2462 str_supported(tp_features
.wan
),
2465 if (tp_features
.wan
) {
2466 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
2467 /* no wan hardware present in system */
2468 tp_features
.wan
= 0;
2469 dbg_printk(TPACPI_DBG_INIT
,
2470 "wan hardware not installed\n");
2472 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2479 return (tp_features
.wan
)? 0 : 1;
2482 static void wan_exit(void)
2484 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2488 static int wan_get_radiosw(void)
2492 if (!tp_features
.wan
)
2495 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2498 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
2501 static int wan_set_radiosw(int radio_on
)
2505 if (!tp_features
.wan
)
2508 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2511 status
|= TP_ACPI_WANCARD_RADIOSSW
;
2513 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
2514 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
2520 /* procfs -------------------------------------------------------------- */
2521 static int wan_read(char *p
)
2524 int status
= wan_get_radiosw();
2526 if (!tp_features
.wan
)
2527 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2529 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2530 (status
)? "enabled" : "disabled");
2531 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2537 static int wan_write(char *buf
)
2541 if (!tp_features
.wan
)
2544 while ((cmd
= next_cmd(&buf
))) {
2545 if (strlencmp(cmd
, "enable") == 0) {
2547 } else if (strlencmp(cmd
, "disable") == 0) {
2556 static struct ibm_struct wan_driver_data
= {
2561 .flags
.experimental
= 1,
2564 /*************************************************************************
2568 enum video_access_mode
{
2569 TPACPI_VIDEO_NONE
= 0,
2570 TPACPI_VIDEO_570
, /* 570 */
2571 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
2572 TPACPI_VIDEO_NEW
, /* all others */
2575 enum { /* video status flags, based on VIDEO_570 */
2576 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
2577 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
2578 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
2581 enum { /* TPACPI_VIDEO_570 constants */
2582 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
2583 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
2584 * video_status_flags */
2585 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
2586 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
2589 static enum video_access_mode video_supported
;
2590 static int video_orig_autosw
;
2592 static int video_autosw_get(void);
2593 static int video_autosw_set(int enable
);
2595 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
2596 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
2597 "\\_SB.PCI0.VID0", /* 770e */
2598 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
2599 "\\_SB.PCI0.AGP.VID", /* all others */
2602 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
2604 static int __init
video_init(struct ibm_init_struct
*iibm
)
2608 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
2610 TPACPI_ACPIHANDLE_INIT(vid
);
2611 TPACPI_ACPIHANDLE_INIT(vid2
);
2613 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
2614 /* G41, assume IVGA doesn't change */
2615 vid_handle
= vid2_handle
;
2618 /* video switching not supported on R30, R31 */
2619 video_supported
= TPACPI_VIDEO_NONE
;
2620 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
2622 video_supported
= TPACPI_VIDEO_570
;
2623 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
2624 /* 600e/x, 770e, 770x */
2625 video_supported
= TPACPI_VIDEO_770
;
2628 video_supported
= TPACPI_VIDEO_NEW
;
2630 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
2631 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
2634 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
2637 static void video_exit(void)
2639 dbg_printk(TPACPI_DBG_EXIT
,
2640 "restoring original video autoswitch mode\n");
2641 if (video_autosw_set(video_orig_autosw
))
2642 printk(TPACPI_ERR
"error while trying to restore original "
2643 "video autoswitch mode\n");
2646 static int video_outputsw_get(void)
2651 switch (video_supported
) {
2652 case TPACPI_VIDEO_570
:
2653 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
2654 TP_ACPI_VIDEO_570_PHSCMD
))
2656 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
2658 case TPACPI_VIDEO_770
:
2659 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2662 status
|= TP_ACPI_VIDEO_S_LCD
;
2663 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2666 status
|= TP_ACPI_VIDEO_S_CRT
;
2668 case TPACPI_VIDEO_NEW
:
2669 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
2670 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2673 status
|= TP_ACPI_VIDEO_S_CRT
;
2675 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
2676 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2679 status
|= TP_ACPI_VIDEO_S_LCD
;
2680 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
2683 status
|= TP_ACPI_VIDEO_S_DVI
;
2692 static int video_outputsw_set(int status
)
2697 switch (video_supported
) {
2698 case TPACPI_VIDEO_570
:
2699 res
= acpi_evalf(NULL
, NULL
,
2700 "\\_SB.PHS2", "vdd",
2701 TP_ACPI_VIDEO_570_PHS2CMD
,
2702 status
| TP_ACPI_VIDEO_570_PHS2SET
);
2704 case TPACPI_VIDEO_770
:
2705 autosw
= video_autosw_get();
2709 res
= video_autosw_set(1);
2712 res
= acpi_evalf(vid_handle
, NULL
,
2713 "ASWT", "vdd", status
* 0x100, 0);
2714 if (!autosw
&& video_autosw_set(autosw
)) {
2716 "video auto-switch left enabled due to error\n");
2720 case TPACPI_VIDEO_NEW
:
2721 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
2722 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
2728 return (res
)? 0 : -EIO
;
2731 static int video_autosw_get(void)
2735 switch (video_supported
) {
2736 case TPACPI_VIDEO_570
:
2737 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
2740 case TPACPI_VIDEO_770
:
2741 case TPACPI_VIDEO_NEW
:
2742 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
2752 static int video_autosw_set(int enable
)
2754 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
2759 static int video_outputsw_cycle(void)
2761 int autosw
= video_autosw_get();
2767 switch (video_supported
) {
2768 case TPACPI_VIDEO_570
:
2769 res
= video_autosw_set(1);
2772 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
2774 case TPACPI_VIDEO_770
:
2775 case TPACPI_VIDEO_NEW
:
2776 res
= video_autosw_set(1);
2779 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
2784 if (!autosw
&& video_autosw_set(autosw
)) {
2786 "video auto-switch left enabled due to error\n");
2790 return (res
)? 0 : -EIO
;
2793 static int video_expand_toggle(void)
2795 switch (video_supported
) {
2796 case TPACPI_VIDEO_570
:
2797 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
2799 case TPACPI_VIDEO_770
:
2800 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
2802 case TPACPI_VIDEO_NEW
:
2803 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
2811 static int video_read(char *p
)
2816 if (video_supported
== TPACPI_VIDEO_NONE
) {
2817 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2821 status
= video_outputsw_get();
2825 autosw
= video_autosw_get();
2829 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2830 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
2831 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
2832 if (video_supported
== TPACPI_VIDEO_NEW
)
2833 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
2834 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
2835 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
2836 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
2837 if (video_supported
== TPACPI_VIDEO_NEW
)
2838 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
2839 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
2840 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
2845 static int video_write(char *buf
)
2848 int enable
, disable
, status
;
2851 if (video_supported
== TPACPI_VIDEO_NONE
)
2857 while ((cmd
= next_cmd(&buf
))) {
2858 if (strlencmp(cmd
, "lcd_enable") == 0) {
2859 enable
|= TP_ACPI_VIDEO_S_LCD
;
2860 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
2861 disable
|= TP_ACPI_VIDEO_S_LCD
;
2862 } else if (strlencmp(cmd
, "crt_enable") == 0) {
2863 enable
|= TP_ACPI_VIDEO_S_CRT
;
2864 } else if (strlencmp(cmd
, "crt_disable") == 0) {
2865 disable
|= TP_ACPI_VIDEO_S_CRT
;
2866 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2867 strlencmp(cmd
, "dvi_enable") == 0) {
2868 enable
|= TP_ACPI_VIDEO_S_DVI
;
2869 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2870 strlencmp(cmd
, "dvi_disable") == 0) {
2871 disable
|= TP_ACPI_VIDEO_S_DVI
;
2872 } else if (strlencmp(cmd
, "auto_enable") == 0) {
2873 res
= video_autosw_set(1);
2876 } else if (strlencmp(cmd
, "auto_disable") == 0) {
2877 res
= video_autosw_set(0);
2880 } else if (strlencmp(cmd
, "video_switch") == 0) {
2881 res
= video_outputsw_cycle();
2884 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
2885 res
= video_expand_toggle();
2892 if (enable
|| disable
) {
2893 status
= video_outputsw_get();
2896 res
= video_outputsw_set((status
& ~disable
) | enable
);
2904 static struct ibm_struct video_driver_data
= {
2907 .write
= video_write
,
2911 /*************************************************************************
2912 * Light (thinklight) subdriver
2915 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
2916 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
2918 static int __init
light_init(struct ibm_init_struct
*iibm
)
2920 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
2922 TPACPI_ACPIHANDLE_INIT(ledb
);
2923 TPACPI_ACPIHANDLE_INIT(lght
);
2924 TPACPI_ACPIHANDLE_INIT(cmos
);
2926 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
2927 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
2929 if (tp_features
.light
)
2930 /* light status not supported on
2931 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
2932 tp_features
.light_status
=
2933 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
2935 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
2936 str_supported(tp_features
.light
));
2938 return (tp_features
.light
)? 0 : 1;
2941 static int light_read(char *p
)
2946 if (!tp_features
.light
) {
2947 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2948 } else if (!tp_features
.light_status
) {
2949 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
2950 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2952 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
2954 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
2955 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2961 static int light_write(char *buf
)
2963 int cmos_cmd
, lght_cmd
;
2967 if (!tp_features
.light
)
2970 while ((cmd
= next_cmd(&buf
))) {
2971 if (strlencmp(cmd
, "on") == 0) {
2974 } else if (strlencmp(cmd
, "off") == 0) {
2980 success
= cmos_handle
?
2981 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
2982 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
2990 static struct ibm_struct light_driver_data
= {
2993 .write
= light_write
,
2996 /*************************************************************************
3000 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3002 static void dock_notify(struct ibm_struct
*ibm
, u32 event
);
3003 static int dock_read(char *p
);
3004 static int dock_write(char *buf
);
3006 TPACPI_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
3007 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
3008 "\\_SB.PCI0.PCI1.DOCK", /* all others */
3009 "\\_SB.PCI.ISA.SLCE", /* 570 */
3010 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
3012 /* don't list other alternatives as we install a notify handler on the 570 */
3013 TPACPI_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
3015 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
3017 .notify
= dock_notify
,
3018 .handle
= &dock_handle
,
3019 .type
= ACPI_SYSTEM_NOTIFY
,
3022 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
3023 * We just use it to get notifications of dock hotplug
3024 * in very old thinkpads */
3025 .hid
= PCI_ROOT_HID_STRING
,
3026 .notify
= dock_notify
,
3027 .handle
= &pci_handle
,
3028 .type
= ACPI_SYSTEM_NOTIFY
,
3032 static struct ibm_struct dock_driver_data
[2] = {
3036 .write
= dock_write
,
3037 .acpi
= &ibm_dock_acpidriver
[0],
3041 .acpi
= &ibm_dock_acpidriver
[1],
3045 #define dock_docked() (_sta(dock_handle) & 1)
3047 static int __init
dock_init(struct ibm_init_struct
*iibm
)
3049 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
3051 TPACPI_ACPIHANDLE_INIT(dock
);
3053 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
3054 str_supported(dock_handle
!= NULL
));
3056 return (dock_handle
)? 0 : 1;
3059 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
3063 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
3065 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
3066 dock_driver_data
[0].flags
.acpi_notify_installed
) {
3067 TPACPI_ACPIHANDLE_INIT(pci
);
3068 dock2_needed
= (pci_handle
!= NULL
);
3069 vdbg_printk(TPACPI_DBG_INIT
,
3070 "dock PCI handler for the TP 570 is %s\n",
3071 str_supported(dock2_needed
));
3073 vdbg_printk(TPACPI_DBG_INIT
,
3074 "dock subdriver part 2 not required\n");
3078 return (dock2_needed
)? 0 : 1;
3081 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
3083 int docked
= dock_docked();
3084 int pci
= ibm
->acpi
->hid
&& strstr(ibm
->acpi
->hid
, PCI_ROOT_HID_STRING
);
3086 if (event
== 1 && !pci
) /* 570 */
3087 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
3088 else if (event
== 1 && pci
) /* 570 */
3089 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
3090 else if (event
== 3 && docked
)
3091 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
3092 else if (event
== 3 && !docked
)
3093 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 2); /* undock */
3094 else if (event
== 0 && docked
)
3095 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
3097 printk(TPACPI_ERR
"unknown dock event %d, status %d\n",
3098 event
, _sta(dock_handle
));
3099 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0); /* unknown */
3103 static int dock_read(char *p
)
3106 int docked
= dock_docked();
3109 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3111 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
3113 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
3114 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
3120 static int dock_write(char *buf
)
3127 while ((cmd
= next_cmd(&buf
))) {
3128 if (strlencmp(cmd
, "undock") == 0) {
3129 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
3130 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
3132 } else if (strlencmp(cmd
, "dock") == 0) {
3133 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
3142 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
3144 /*************************************************************************
3148 #ifdef CONFIG_THINKPAD_ACPI_BAY
3150 TPACPI_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
3151 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
3152 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
3153 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
3154 ); /* A21e, R30, R31 */
3155 TPACPI_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
3156 "_EJ0", /* all others */
3157 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
3158 TPACPI_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
3159 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
3161 TPACPI_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
3165 static int __init
bay_init(struct ibm_init_struct
*iibm
)
3167 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
3169 TPACPI_ACPIHANDLE_INIT(bay
);
3171 TPACPI_ACPIHANDLE_INIT(bay_ej
);
3172 TPACPI_ACPIHANDLE_INIT(bay2
);
3174 TPACPI_ACPIHANDLE_INIT(bay2_ej
);
3176 tp_features
.bay_status
= bay_handle
&&
3177 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
3178 tp_features
.bay_status2
= bay2_handle
&&
3179 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
3181 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
3182 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
3183 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
3184 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
3186 vdbg_printk(TPACPI_DBG_INIT
,
3187 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
3188 str_supported(tp_features
.bay_status
),
3189 str_supported(tp_features
.bay_eject
),
3190 str_supported(tp_features
.bay_status2
),
3191 str_supported(tp_features
.bay_eject2
));
3193 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
3194 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
3197 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
3199 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
3202 #define bay_occupied(b) (_sta(b##_handle) & 1)
3204 static int bay_read(char *p
)
3207 int occupied
= bay_occupied(bay
);
3208 int occupied2
= bay_occupied(bay2
);
3211 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3212 tp_features
.bay_status
?
3213 (occupied
? "occupied" : "unoccupied") :
3215 if (tp_features
.bay_status2
)
3216 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
3217 "occupied" : "unoccupied");
3219 eject
= tp_features
.bay_eject
&& occupied
;
3220 eject2
= tp_features
.bay_eject2
&& occupied2
;
3222 if (eject
&& eject2
)
3223 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
3225 len
+= sprintf(p
+ len
, "commands:\teject\n");
3227 len
+= sprintf(p
+ len
, "commands:\teject2\n");
3232 static int bay_write(char *buf
)
3236 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
3239 while ((cmd
= next_cmd(&buf
))) {
3240 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
3241 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
3243 } else if (tp_features
.bay_eject2
&&
3244 strlencmp(cmd
, "eject2") == 0) {
3245 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
3254 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
3255 .notify
= bay_notify
,
3256 .handle
= &bay_handle
,
3257 .type
= ACPI_SYSTEM_NOTIFY
,
3260 static struct ibm_struct bay_driver_data
= {
3264 .acpi
= &ibm_bay_acpidriver
,
3267 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3269 /*************************************************************************
3273 /* sysfs cmos_command -------------------------------------------------- */
3274 static ssize_t
cmos_command_store(struct device
*dev
,
3275 struct device_attribute
*attr
,
3276 const char *buf
, size_t count
)
3278 unsigned long cmos_cmd
;
3281 if (parse_strtoul(buf
, 21, &cmos_cmd
))
3284 res
= issue_thinkpad_cmos_command(cmos_cmd
);
3285 return (res
)? res
: count
;
3288 static struct device_attribute dev_attr_cmos_command
=
3289 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
3291 /* --------------------------------------------------------------------- */
3293 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
3297 vdbg_printk(TPACPI_DBG_INIT
,
3298 "initializing cmos commands subdriver\n");
3300 TPACPI_ACPIHANDLE_INIT(cmos
);
3302 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
3303 str_supported(cmos_handle
!= NULL
));
3305 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
3309 return (cmos_handle
)? 0 : 1;
3312 static void cmos_exit(void)
3314 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
3317 static int cmos_read(char *p
)
3321 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3322 R30, R31, T20-22, X20-21 */
3324 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3326 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3327 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
3333 static int cmos_write(char *buf
)
3338 while ((cmd
= next_cmd(&buf
))) {
3339 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
3340 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
3345 res
= issue_thinkpad_cmos_command(cmos_cmd
);
3353 static struct ibm_struct cmos_driver_data
= {
3356 .write
= cmos_write
,
3360 /*************************************************************************
3364 enum led_access_mode
{
3365 TPACPI_LED_NONE
= 0,
3366 TPACPI_LED_570
, /* 570 */
3367 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3368 TPACPI_LED_NEW
, /* all others */
3371 enum { /* For TPACPI_LED_OLD */
3372 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
3373 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
3374 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
3377 static enum led_access_mode led_supported
;
3379 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
3380 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, */
3381 /* T20-22, X20-21 */
3382 "LED", /* all others */
3385 static int __init
led_init(struct ibm_init_struct
*iibm
)
3387 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
3389 TPACPI_ACPIHANDLE_INIT(led
);
3392 /* led not supported on R30, R31 */
3393 led_supported
= TPACPI_LED_NONE
;
3394 else if (strlencmp(led_path
, "SLED") == 0)
3396 led_supported
= TPACPI_LED_570
;
3397 else if (strlencmp(led_path
, "SYSL") == 0)
3398 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3399 led_supported
= TPACPI_LED_OLD
;
3402 led_supported
= TPACPI_LED_NEW
;
3404 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
3405 str_supported(led_supported
), led_supported
);
3407 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
3410 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
3412 static int led_read(char *p
)
3416 if (!led_supported
) {
3417 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3420 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3422 if (led_supported
== TPACPI_LED_570
) {
3425 for (i
= 0; i
< 8; i
++) {
3426 if (!acpi_evalf(ec_handle
,
3427 &status
, "GLED", "dd", 1 << i
))
3429 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
3430 i
, led_status(status
));
3434 len
+= sprintf(p
+ len
, "commands:\t"
3435 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
3440 /* off, on, blink */
3441 static const int led_sled_arg1
[] = { 0, 1, 3 };
3442 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
3443 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
3444 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
3446 static int led_write(char *buf
)
3454 while ((cmd
= next_cmd(&buf
))) {
3455 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
3458 if (strstr(cmd
, "off")) {
3460 } else if (strstr(cmd
, "on")) {
3462 } else if (strstr(cmd
, "blink")) {
3467 if (led_supported
== TPACPI_LED_570
) {
3470 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
3471 led
, led_sled_arg1
[ind
]))
3473 } else if (led_supported
== TPACPI_LED_OLD
) {
3474 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
3476 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
3478 ret
= ec_write(TPACPI_LED_EC_HLBL
,
3479 led
* led_exp_hlbl
[ind
]);
3481 ret
= ec_write(TPACPI_LED_EC_HLCL
,
3482 led
* led_exp_hlcl
[ind
]);
3487 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
3488 led
, led_led_arg1
[ind
]))
3496 static struct ibm_struct led_driver_data
= {
3502 /*************************************************************************
3506 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
3508 static int __init
beep_init(struct ibm_init_struct
*iibm
)
3510 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
3512 TPACPI_ACPIHANDLE_INIT(beep
);
3514 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
3515 str_supported(beep_handle
!= NULL
));
3517 return (beep_handle
)? 0 : 1;
3520 static int beep_read(char *p
)
3525 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3527 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3528 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
3534 static int beep_write(char *buf
)
3542 while ((cmd
= next_cmd(&buf
))) {
3543 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
3544 beep_cmd
>= 0 && beep_cmd
<= 17) {
3548 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
3555 static struct ibm_struct beep_driver_data
= {
3558 .write
= beep_write
,
3561 /*************************************************************************
3565 enum thermal_access_mode
{
3566 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
3567 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
3568 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
3569 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
3570 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
3573 enum { /* TPACPI_THERMAL_TPEC_* */
3574 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
3575 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
3576 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
3579 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
3580 struct ibm_thermal_sensors_struct
{
3581 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
3584 static enum thermal_access_mode thermal_read_mode
;
3586 /* idx is zero-based */
3587 static int thermal_get_sensor(int idx
, s32
*value
)
3593 t
= TP_EC_THERMAL_TMP0
;
3595 switch (thermal_read_mode
) {
3596 #if TPACPI_MAX_THERMAL_SENSORS >= 16
3597 case TPACPI_THERMAL_TPEC_16
:
3598 if (idx
>= 8 && idx
<= 15) {
3599 t
= TP_EC_THERMAL_TMP8
;
3604 case TPACPI_THERMAL_TPEC_8
:
3606 if (!acpi_ec_read(t
+ idx
, &tmp
))
3608 *value
= tmp
* 1000;
3613 case TPACPI_THERMAL_ACPI_UPDT
:
3615 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3616 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
3618 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3620 *value
= (t
- 2732) * 100;
3625 case TPACPI_THERMAL_ACPI_TMP07
:
3627 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3628 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3630 if (t
> 127 || t
< -127)
3631 t
= TP_EC_THERMAL_TMP_NA
;
3637 case TPACPI_THERMAL_NONE
:
3645 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
3656 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
3659 for (i
= 0 ; i
< n
; i
++) {
3660 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
3668 /* sysfs temp##_input -------------------------------------------------- */
3670 static ssize_t
thermal_temp_input_show(struct device
*dev
,
3671 struct device_attribute
*attr
,
3674 struct sensor_device_attribute
*sensor_attr
=
3675 to_sensor_dev_attr(attr
);
3676 int idx
= sensor_attr
->index
;
3680 res
= thermal_get_sensor(idx
, &value
);
3683 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
3686 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
3689 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
3690 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, \
3691 thermal_temp_input_show, NULL, _idxB)
3693 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
3694 THERMAL_SENSOR_ATTR_TEMP(1, 0),
3695 THERMAL_SENSOR_ATTR_TEMP(2, 1),
3696 THERMAL_SENSOR_ATTR_TEMP(3, 2),
3697 THERMAL_SENSOR_ATTR_TEMP(4, 3),
3698 THERMAL_SENSOR_ATTR_TEMP(5, 4),
3699 THERMAL_SENSOR_ATTR_TEMP(6, 5),
3700 THERMAL_SENSOR_ATTR_TEMP(7, 6),
3701 THERMAL_SENSOR_ATTR_TEMP(8, 7),
3702 THERMAL_SENSOR_ATTR_TEMP(9, 8),
3703 THERMAL_SENSOR_ATTR_TEMP(10, 9),
3704 THERMAL_SENSOR_ATTR_TEMP(11, 10),
3705 THERMAL_SENSOR_ATTR_TEMP(12, 11),
3706 THERMAL_SENSOR_ATTR_TEMP(13, 12),
3707 THERMAL_SENSOR_ATTR_TEMP(14, 13),
3708 THERMAL_SENSOR_ATTR_TEMP(15, 14),
3709 THERMAL_SENSOR_ATTR_TEMP(16, 15),
3712 #define THERMAL_ATTRS(X) \
3713 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
3715 static struct attribute
*thermal_temp_input_attr
[] = {
3735 static const struct attribute_group thermal_temp_input16_group
= {
3736 .attrs
= thermal_temp_input_attr
3739 static const struct attribute_group thermal_temp_input8_group
= {
3740 .attrs
= &thermal_temp_input_attr
[8]
3743 #undef THERMAL_SENSOR_ATTR_TEMP
3744 #undef THERMAL_ATTRS
3746 /* --------------------------------------------------------------------- */
3748 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
3755 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
3757 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
3759 if (thinkpad_id
.ec_model
) {
3761 * Direct EC access mode: sensors at registers
3762 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
3763 * non-implemented, thermal sensors return 0x80 when
3768 for (i
= 0; i
< 8; i
++) {
3769 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
3775 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
3783 /* This is sheer paranoia, but we handle it anyway */
3786 "ThinkPad ACPI EC access misbehaving, "
3787 "falling back to ACPI TMPx access "
3789 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
3792 "ThinkPad ACPI EC access misbehaving, "
3793 "disabling thermal sensors access\n");
3794 thermal_read_mode
= TPACPI_THERMAL_NONE
;
3799 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
3801 } else if (acpi_tmp7
) {
3802 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
3803 /* 600e/x, 770e, 770x */
3804 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
3806 /* Standard ACPI TMPx access, max 8 sensors */
3807 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
3810 /* temperatures not supported on 570, G4x, R30, R31, R32 */
3811 thermal_read_mode
= TPACPI_THERMAL_NONE
;
3814 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
3815 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
3818 switch (thermal_read_mode
) {
3819 case TPACPI_THERMAL_TPEC_16
:
3820 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3821 &thermal_temp_input16_group
);
3825 case TPACPI_THERMAL_TPEC_8
:
3826 case TPACPI_THERMAL_ACPI_TMP07
:
3827 case TPACPI_THERMAL_ACPI_UPDT
:
3828 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3829 &thermal_temp_input8_group
);
3833 case TPACPI_THERMAL_NONE
:
3841 static void thermal_exit(void)
3843 switch (thermal_read_mode
) {
3844 case TPACPI_THERMAL_TPEC_16
:
3845 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3846 &thermal_temp_input16_group
);
3848 case TPACPI_THERMAL_TPEC_8
:
3849 case TPACPI_THERMAL_ACPI_TMP07
:
3850 case TPACPI_THERMAL_ACPI_UPDT
:
3851 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3852 &thermal_temp_input16_group
);
3854 case TPACPI_THERMAL_NONE
:
3860 static int thermal_read(char *p
)
3864 struct ibm_thermal_sensors_struct t
;
3866 n
= thermal_get_sensors(&t
);
3867 if (unlikely(n
< 0))
3870 len
+= sprintf(p
+ len
, "temperatures:\t");
3873 for (i
= 0; i
< (n
- 1); i
++)
3874 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
3875 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
3877 len
+= sprintf(p
+ len
, "not supported\n");
3882 static struct ibm_struct thermal_driver_data
= {
3884 .read
= thermal_read
,
3885 .exit
= thermal_exit
,
3888 /*************************************************************************
3892 static u8 ecdump_regs
[256];
3894 static int ecdump_read(char *p
)
3900 len
+= sprintf(p
+ len
, "EC "
3901 " +00 +01 +02 +03 +04 +05 +06 +07"
3902 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
3903 for (i
= 0; i
< 256; i
+= 16) {
3904 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
3905 for (j
= 0; j
< 16; j
++) {
3906 if (!acpi_ec_read(i
+ j
, &v
))
3908 if (v
!= ecdump_regs
[i
+ j
])
3909 len
+= sprintf(p
+ len
, " *%02x", v
);
3911 len
+= sprintf(p
+ len
, " %02x", v
);
3912 ecdump_regs
[i
+ j
] = v
;
3914 len
+= sprintf(p
+ len
, "\n");
3919 /* These are way too dangerous to advertise openly... */
3921 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
3922 " (<offset> is 00-ff, <value> is 00-ff)\n");
3923 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
3924 " (<offset> is 00-ff, <value> is 0-255)\n");
3929 static int ecdump_write(char *buf
)
3934 while ((cmd
= next_cmd(&buf
))) {
3935 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
3937 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
3941 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
3942 if (!acpi_ec_write(i
, v
))
3951 static struct ibm_struct ecdump_driver_data
= {
3953 .read
= ecdump_read
,
3954 .write
= ecdump_write
,
3955 .flags
.experimental
= 1,
3958 /*************************************************************************
3959 * Backlight/brightness subdriver
3962 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
3964 static struct backlight_device
*ibm_backlight_device
;
3965 static int brightness_offset
= 0x31;
3966 static int brightness_mode
;
3967 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
3969 static struct mutex brightness_mutex
;
3972 * ThinkPads can read brightness from two places: EC 0x31, or
3973 * CMOS NVRAM byte 0x5E, bits 0-3.
3975 static int brightness_get(struct backlight_device
*bd
)
3977 u8 lec
= 0, lcmos
= 0, level
= 0;
3979 if (brightness_mode
& 1) {
3980 if (!acpi_ec_read(brightness_offset
, &lec
))
3982 lec
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
3985 if (brightness_mode
& 2) {
3986 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
3987 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
3988 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
3989 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
3993 if (brightness_mode
== 3 && lec
!= lcmos
) {
3995 "CMOS NVRAM (%u) and EC (%u) do not agree "
3996 "on display brightness level\n",
3997 (unsigned int) lcmos
,
3998 (unsigned int) lec
);
4005 /* May return EINTR which can always be mapped to ERESTARTSYS */
4006 static int brightness_set(int value
)
4008 int cmos_cmd
, inc
, i
, res
;
4011 if (value
> ((tp_features
.bright_16levels
)? 15 : 7))
4014 res
= mutex_lock_interruptible(&brightness_mutex
);
4018 current_value
= brightness_get(NULL
);
4019 if (current_value
< 0) {
4020 res
= current_value
;
4024 cmos_cmd
= value
> current_value
?
4025 TP_CMOS_BRIGHTNESS_UP
:
4026 TP_CMOS_BRIGHTNESS_DOWN
;
4027 inc
= (value
> current_value
)? 1 : -1;
4030 for (i
= current_value
; i
!= value
; i
+= inc
) {
4031 if ((brightness_mode
& 2) &&
4032 issue_thinkpad_cmos_command(cmos_cmd
)) {
4036 if ((brightness_mode
& 1) &&
4037 !acpi_ec_write(brightness_offset
, i
+ inc
)) {
4044 mutex_unlock(&brightness_mutex
);
4048 /* sysfs backlight class ----------------------------------------------- */
4050 static int brightness_update_status(struct backlight_device
*bd
)
4052 /* it is the backlight class's job (caller) to handle
4053 * EINTR and other errors properly */
4054 return brightness_set(
4055 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
4056 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
4057 bd
->props
.brightness
: 0);
4060 static struct backlight_ops ibm_backlight_data
= {
4061 .get_brightness
= brightness_get
,
4062 .update_status
= brightness_update_status
,
4065 /* --------------------------------------------------------------------- */
4067 static int __init
tpacpi_query_bcll_levels(acpi_handle handle
)
4069 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
4070 union acpi_object
*obj
;
4073 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
4074 obj
= (union acpi_object
*)buffer
.pointer
;
4075 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
4076 printk(TPACPI_ERR
"Unknown BCLL data, "
4077 "please report this to %s\n", TPACPI_MAIL
);
4080 rc
= obj
->package
.count
;
4086 kfree(buffer
.pointer
);
4090 static acpi_status __init
brightness_find_bcll(acpi_handle handle
, u32 lvl
,
4091 void *context
, void **rv
)
4093 char name
[ACPI_PATH_SEGMENT_LENGTH
];
4094 struct acpi_buffer buffer
= { sizeof(name
), &name
};
4096 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
4097 !strncmp("BCLL", name
, sizeof(name
) - 1)) {
4098 if (tpacpi_query_bcll_levels(handle
) == 16) {
4100 return AE_CTRL_TERMINATE
;
4109 static int __init
brightness_check_levels(void)
4112 void *found_node
= NULL
;
4115 TPACPI_ACPIHANDLE_INIT(vid
);
4120 /* Search for a BCLL package with 16 levels */
4121 status
= acpi_walk_namespace(ACPI_TYPE_PACKAGE
, vid_handle
, 3,
4122 brightness_find_bcll
, NULL
,
4125 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
4128 static acpi_status __init
brightness_find_bcl(acpi_handle handle
, u32 lvl
,
4129 void *context
, void **rv
)
4131 char name
[ACPI_PATH_SEGMENT_LENGTH
];
4132 struct acpi_buffer buffer
= { sizeof(name
), &name
};
4134 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
4135 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
4137 return AE_CTRL_TERMINATE
;
4143 static int __init
brightness_check_std_acpi_support(void)
4146 void *found_node
= NULL
;
4149 TPACPI_ACPIHANDLE_INIT(vid
);
4154 /* Search for a _BCL method, but don't execute it */
4155 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
4156 brightness_find_bcl
, NULL
, &found_node
);
4158 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
4161 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
4165 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
4167 mutex_init(&brightness_mutex
);
4169 if (!brightness_enable
) {
4170 dbg_printk(TPACPI_DBG_INIT
,
4171 "brightness support disabled by module parameter\n");
4173 } else if (brightness_enable
> 1) {
4174 if (brightness_check_std_acpi_support()) {
4175 printk(TPACPI_NOTICE
4176 "standard ACPI backlight interface "
4177 "available, not loading native one...\n");
4182 if (!brightness_mode
) {
4183 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
4184 brightness_mode
= 2;
4186 brightness_mode
= 3;
4188 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
4192 if (brightness_mode
> 3)
4195 tp_features
.bright_16levels
=
4196 thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
&&
4197 brightness_check_levels();
4199 b
= brightness_get(NULL
);
4203 if (tp_features
.bright_16levels
)
4205 "detected a 16-level brightness capable ThinkPad\n");
4207 ibm_backlight_device
= backlight_device_register(
4208 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
4209 &ibm_backlight_data
);
4210 if (IS_ERR(ibm_backlight_device
)) {
4211 printk(TPACPI_ERR
"Could not register backlight device\n");
4212 return PTR_ERR(ibm_backlight_device
);
4214 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
4216 ibm_backlight_device
->props
.max_brightness
=
4217 (tp_features
.bright_16levels
)? 15 : 7;
4218 ibm_backlight_device
->props
.brightness
= b
;
4219 backlight_update_status(ibm_backlight_device
);
4224 static void brightness_exit(void)
4226 if (ibm_backlight_device
) {
4227 vdbg_printk(TPACPI_DBG_EXIT
,
4228 "calling backlight_device_unregister()\n");
4229 backlight_device_unregister(ibm_backlight_device
);
4230 ibm_backlight_device
= NULL
;
4234 static int brightness_read(char *p
)
4239 level
= brightness_get(NULL
);
4241 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
4243 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
4244 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
4245 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
4246 " (<level> is 0-%d)\n",
4247 (tp_features
.bright_16levels
) ? 15 : 7);
4253 static int brightness_write(char *buf
)
4258 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
4260 level
= brightness_get(NULL
);
4264 while ((cmd
= next_cmd(&buf
))) {
4265 if (strlencmp(cmd
, "up") == 0) {
4266 if (level
< max_level
)
4268 } else if (strlencmp(cmd
, "down") == 0) {
4271 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
4272 level
>= 0 && level
<= max_level
) {
4279 * Now we know what the final level should be, so we try to set it.
4280 * Doing it this way makes the syscall restartable in case of EINTR
4282 rc
= brightness_set(level
);
4283 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
4286 static struct ibm_struct brightness_driver_data
= {
4287 .name
= "brightness",
4288 .read
= brightness_read
,
4289 .write
= brightness_write
,
4290 .exit
= brightness_exit
,
4293 /*************************************************************************
4297 static int volume_offset
= 0x30;
4299 static int volume_read(char *p
)
4304 if (!acpi_ec_read(volume_offset
, &level
)) {
4305 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
4307 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
4308 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
4309 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
4310 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
4311 " (<level> is 0-15)\n");
4317 static int volume_write(char *buf
)
4319 int cmos_cmd
, inc
, i
;
4321 int new_level
, new_mute
;
4324 while ((cmd
= next_cmd(&buf
))) {
4325 if (!acpi_ec_read(volume_offset
, &level
))
4327 new_mute
= mute
= level
& 0x40;
4328 new_level
= level
= level
& 0xf;
4330 if (strlencmp(cmd
, "up") == 0) {
4334 new_level
= level
== 15 ? 15 : level
+ 1;
4335 } else if (strlencmp(cmd
, "down") == 0) {
4339 new_level
= level
== 0 ? 0 : level
- 1;
4340 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
4341 new_level
>= 0 && new_level
<= 15) {
4343 } else if (strlencmp(cmd
, "mute") == 0) {
4348 if (new_level
!= level
) { /* mute doesn't change */
4349 cmos_cmd
= (new_level
> level
) ?
4350 TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
4351 inc
= new_level
> level
? 1 : -1;
4353 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
4354 !acpi_ec_write(volume_offset
, level
)))
4357 for (i
= level
; i
!= new_level
; i
+= inc
)
4358 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
4359 !acpi_ec_write(volume_offset
, i
+ inc
))
4363 (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
4364 !acpi_ec_write(volume_offset
, new_level
+ mute
))) {
4369 if (new_mute
!= mute
) { /* level doesn't change */
4370 cmos_cmd
= (new_mute
) ?
4371 TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
4373 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
4374 !acpi_ec_write(volume_offset
, level
+ new_mute
))
4382 static struct ibm_struct volume_driver_data
= {
4384 .read
= volume_read
,
4385 .write
= volume_write
,
4388 /*************************************************************************
4395 * TPACPI_FAN_RD_ACPI_GFAN:
4396 * ACPI GFAN method: returns fan level
4398 * see TPACPI_FAN_WR_ACPI_SFAN
4399 * EC 0x2f (HFSP) not available if GFAN exists
4401 * TPACPI_FAN_WR_ACPI_SFAN:
4402 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
4404 * EC 0x2f (HFSP) might be available *for reading*, but do not use
4407 * TPACPI_FAN_WR_TPEC:
4408 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
4409 * Supported on almost all ThinkPads
4411 * Fan speed changes of any sort (including those caused by the
4412 * disengaged mode) are usually done slowly by the firmware as the
4413 * maximum ammount of fan duty cycle change per second seems to be
4416 * Reading is not available if GFAN exists.
4417 * Writing is not available if SFAN exists.
4420 * 7 automatic mode engaged;
4421 * (default operation mode of the ThinkPad)
4422 * fan level is ignored in this mode.
4423 * 6 full speed mode (takes precedence over bit 7);
4424 * not available on all thinkpads. May disable
4425 * the tachometer while the fan controller ramps up
4426 * the speed (which can take up to a few *minutes*).
4427 * Speeds up fan to 100% duty-cycle, which is far above
4428 * the standard RPM levels. It is not impossible that
4429 * it could cause hardware damage.
4430 * 5-3 unused in some models. Extra bits for fan level
4431 * in others, but still useless as all values above
4432 * 7 map to the same speed as level 7 in these models.
4433 * 2-0 fan level (0..7 usually)
4435 * 0x07 = max (set when temperatures critical)
4436 * Some ThinkPads may have other levels, see
4437 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
4439 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
4440 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
4441 * does so, its initial value is meaningless (0x07).
4443 * For firmware bugs, refer to:
4444 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
4448 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
4449 * Main fan tachometer reading (in RPM)
4451 * This register is present on all ThinkPads with a new-style EC, and
4452 * it is known not to be present on the A21m/e, and T22, as there is
4453 * something else in offset 0x84 according to the ACPI DSDT. Other
4454 * ThinkPads from this same time period (and earlier) probably lack the
4455 * tachometer as well.
4457 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
4458 * was never fixed by IBM to report the EC firmware version string
4459 * probably support the tachometer (like the early X models), so
4460 * detecting it is quite hard. We need more data to know for sure.
4462 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
4465 * FIRMWARE BUG: may go stale while the EC is switching to full speed
4468 * For firmware bugs, refer to:
4469 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
4471 * TPACPI_FAN_WR_ACPI_FANS:
4472 * ThinkPad X31, X40, X41. Not available in the X60.
4474 * FANS ACPI handle: takes three arguments: low speed, medium speed,
4475 * high speed. ACPI DSDT seems to map these three speeds to levels
4476 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
4477 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
4479 * The speeds are stored on handles
4480 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
4482 * There are three default speed sets, acessible as handles:
4483 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
4485 * ACPI DSDT switches which set is in use depending on various
4488 * TPACPI_FAN_WR_TPEC is also available and should be used to
4489 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
4490 * but the ACPI tables just mention level 7.
4493 enum { /* Fan control constants */
4494 fan_status_offset
= 0x2f, /* EC register 0x2f */
4495 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
4496 * 0x84 must be read before 0x85 */
4498 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
4499 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
4501 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
4504 enum fan_status_access_mode
{
4505 TPACPI_FAN_NONE
= 0, /* No fan status or control */
4506 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
4507 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
4510 enum fan_control_access_mode
{
4511 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
4512 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
4513 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
4514 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
4517 enum fan_control_commands
{
4518 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
4519 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
4520 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
4521 * and also watchdog cmd */
4524 static int fan_control_allowed
;
4526 static enum fan_status_access_mode fan_status_access_mode
;
4527 static enum fan_control_access_mode fan_control_access_mode
;
4528 static enum fan_control_commands fan_control_commands
;
4530 static u8 fan_control_initial_status
;
4531 static u8 fan_control_desired_level
;
4532 static int fan_watchdog_maxinterval
;
4534 static struct mutex fan_mutex
;
4536 static void fan_watchdog_fire(struct work_struct
*ignored
);
4537 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
4539 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
4540 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
4541 "\\FSPD", /* 600e/x, 770e, 770x */
4543 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
4544 "JFNS", /* 770x-JL */
4548 * Call with fan_mutex held
4550 static void fan_update_desired_level(u8 status
)
4553 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
4555 fan_control_desired_level
= 7;
4557 fan_control_desired_level
= status
;
4561 static int fan_get_status(u8
*status
)
4566 * Add TPACPI_FAN_RD_ACPI_FANS ? */
4568 switch (fan_status_access_mode
) {
4569 case TPACPI_FAN_RD_ACPI_GFAN
:
4570 /* 570, 600e/x, 770e, 770x */
4572 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
4580 case TPACPI_FAN_RD_TPEC
:
4581 /* all except 570, 600e/x, 770e, 770x */
4582 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
4597 static int fan_get_status_safe(u8
*status
)
4602 if (mutex_lock_interruptible(&fan_mutex
))
4603 return -ERESTARTSYS
;
4604 rc
= fan_get_status(&s
);
4606 fan_update_desired_level(s
);
4607 mutex_unlock(&fan_mutex
);
4615 static int fan_get_speed(unsigned int *speed
)
4619 switch (fan_status_access_mode
) {
4620 case TPACPI_FAN_RD_TPEC
:
4621 /* all except 570, 600e/x, 770e, 770x */
4622 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
4623 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
4627 *speed
= (hi
<< 8) | lo
;
4638 static int fan_set_level(int level
)
4640 if (!fan_control_allowed
)
4643 switch (fan_control_access_mode
) {
4644 case TPACPI_FAN_WR_ACPI_SFAN
:
4645 if (level
>= 0 && level
<= 7) {
4646 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
4652 case TPACPI_FAN_WR_ACPI_FANS
:
4653 case TPACPI_FAN_WR_TPEC
:
4654 if ((level
!= TP_EC_FAN_AUTO
) &&
4655 (level
!= TP_EC_FAN_FULLSPEED
) &&
4656 ((level
< 0) || (level
> 7)))
4659 /* safety net should the EC not support AUTO
4660 * or FULLSPEED mode bits and just ignore them */
4661 if (level
& TP_EC_FAN_FULLSPEED
)
4662 level
|= 7; /* safety min speed 7 */
4663 else if (level
& TP_EC_FAN_FULLSPEED
)
4664 level
|= 4; /* safety min speed 4 */
4666 if (!acpi_ec_write(fan_status_offset
, level
))
4669 tp_features
.fan_ctrl_status_undef
= 0;
4678 static int fan_set_level_safe(int level
)
4682 if (!fan_control_allowed
)
4685 if (mutex_lock_interruptible(&fan_mutex
))
4686 return -ERESTARTSYS
;
4688 if (level
== TPACPI_FAN_LAST_LEVEL
)
4689 level
= fan_control_desired_level
;
4691 rc
= fan_set_level(level
);
4693 fan_update_desired_level(level
);
4695 mutex_unlock(&fan_mutex
);
4699 static int fan_set_enable(void)
4704 if (!fan_control_allowed
)
4707 if (mutex_lock_interruptible(&fan_mutex
))
4708 return -ERESTARTSYS
;
4710 switch (fan_control_access_mode
) {
4711 case TPACPI_FAN_WR_ACPI_FANS
:
4712 case TPACPI_FAN_WR_TPEC
:
4713 rc
= fan_get_status(&s
);
4717 /* Don't go out of emergency fan mode */
4720 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
4723 if (!acpi_ec_write(fan_status_offset
, s
))
4726 tp_features
.fan_ctrl_status_undef
= 0;
4731 case TPACPI_FAN_WR_ACPI_SFAN
:
4732 rc
= fan_get_status(&s
);
4738 /* Set fan to at least level 4 */
4741 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
4751 mutex_unlock(&fan_mutex
);
4755 static int fan_set_disable(void)
4759 if (!fan_control_allowed
)
4762 if (mutex_lock_interruptible(&fan_mutex
))
4763 return -ERESTARTSYS
;
4766 switch (fan_control_access_mode
) {
4767 case TPACPI_FAN_WR_ACPI_FANS
:
4768 case TPACPI_FAN_WR_TPEC
:
4769 if (!acpi_ec_write(fan_status_offset
, 0x00))
4772 fan_control_desired_level
= 0;
4773 tp_features
.fan_ctrl_status_undef
= 0;
4777 case TPACPI_FAN_WR_ACPI_SFAN
:
4778 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
4781 fan_control_desired_level
= 0;
4789 mutex_unlock(&fan_mutex
);
4793 static int fan_set_speed(int speed
)
4797 if (!fan_control_allowed
)
4800 if (mutex_lock_interruptible(&fan_mutex
))
4801 return -ERESTARTSYS
;
4804 switch (fan_control_access_mode
) {
4805 case TPACPI_FAN_WR_ACPI_FANS
:
4806 if (speed
>= 0 && speed
<= 65535) {
4807 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
4808 speed
, speed
, speed
))
4818 mutex_unlock(&fan_mutex
);
4822 static void fan_watchdog_reset(void)
4824 static int fan_watchdog_active
;
4826 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
4829 if (fan_watchdog_active
)
4830 cancel_delayed_work(&fan_watchdog_task
);
4832 if (fan_watchdog_maxinterval
> 0 &&
4833 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
4834 fan_watchdog_active
= 1;
4835 if (!schedule_delayed_work(&fan_watchdog_task
,
4836 msecs_to_jiffies(fan_watchdog_maxinterval
4839 "failed to schedule the fan watchdog, "
4840 "watchdog will not trigger\n");
4843 fan_watchdog_active
= 0;
4846 static void fan_watchdog_fire(struct work_struct
*ignored
)
4850 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
4853 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
4854 rc
= fan_set_enable();
4856 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
4857 "will try again later...\n", -rc
);
4858 /* reschedule for later */
4859 fan_watchdog_reset();
4864 * SYSFS fan layout: hwmon compatible (device)
4867 * 0: "disengaged" mode
4869 * 2: native EC "auto" mode (recommended, hardware default)
4871 * pwm*: set speed in manual mode, ignored otherwise.
4872 * 0 is level 0; 255 is level 7. Intermediate points done with linear
4875 * fan*_input: tachometer reading, RPM
4878 * SYSFS fan layout: extensions
4880 * fan_watchdog (driver):
4881 * fan watchdog interval in seconds, 0 disables (default), max 120
4884 /* sysfs fan pwm1_enable ----------------------------------------------- */
4885 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
4886 struct device_attribute
*attr
,
4892 res
= fan_get_status_safe(&status
);
4896 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4897 if (status
!= fan_control_initial_status
) {
4898 tp_features
.fan_ctrl_status_undef
= 0;
4900 /* Return most likely status. In fact, it
4901 * might be the only possible status */
4902 status
= TP_EC_FAN_AUTO
;
4906 if (status
& TP_EC_FAN_FULLSPEED
) {
4908 } else if (status
& TP_EC_FAN_AUTO
) {
4913 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
4916 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
4917 struct device_attribute
*attr
,
4918 const char *buf
, size_t count
)
4923 if (parse_strtoul(buf
, 2, &t
))
4928 level
= TP_EC_FAN_FULLSPEED
;
4931 level
= TPACPI_FAN_LAST_LEVEL
;
4934 level
= TP_EC_FAN_AUTO
;
4937 /* reserved for software-controlled auto mode */
4943 res
= fan_set_level_safe(level
);
4949 fan_watchdog_reset();
4954 static struct device_attribute dev_attr_fan_pwm1_enable
=
4955 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
4956 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
4958 /* sysfs fan pwm1 ------------------------------------------------------ */
4959 static ssize_t
fan_pwm1_show(struct device
*dev
,
4960 struct device_attribute
*attr
,
4966 res
= fan_get_status_safe(&status
);
4970 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4971 if (status
!= fan_control_initial_status
) {
4972 tp_features
.fan_ctrl_status_undef
= 0;
4974 status
= TP_EC_FAN_AUTO
;
4979 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
4980 status
= fan_control_desired_level
;
4985 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
4988 static ssize_t
fan_pwm1_store(struct device
*dev
,
4989 struct device_attribute
*attr
,
4990 const char *buf
, size_t count
)
4994 u8 status
, newlevel
;
4996 if (parse_strtoul(buf
, 255, &s
))
4999 /* scale down from 0-255 to 0-7 */
5000 newlevel
= (s
>> 5) & 0x07;
5002 if (mutex_lock_interruptible(&fan_mutex
))
5003 return -ERESTARTSYS
;
5005 rc
= fan_get_status(&status
);
5006 if (!rc
&& (status
&
5007 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
5008 rc
= fan_set_level(newlevel
);
5012 fan_update_desired_level(newlevel
);
5013 fan_watchdog_reset();
5017 mutex_unlock(&fan_mutex
);
5018 return (rc
)? rc
: count
;
5021 static struct device_attribute dev_attr_fan_pwm1
=
5022 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
5023 fan_pwm1_show
, fan_pwm1_store
);
5025 /* sysfs fan fan1_input ------------------------------------------------ */
5026 static ssize_t
fan_fan1_input_show(struct device
*dev
,
5027 struct device_attribute
*attr
,
5033 res
= fan_get_speed(&speed
);
5037 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
5040 static struct device_attribute dev_attr_fan_fan1_input
=
5041 __ATTR(fan1_input
, S_IRUGO
,
5042 fan_fan1_input_show
, NULL
);
5044 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
5045 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
5048 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
5051 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
5052 const char *buf
, size_t count
)
5056 if (parse_strtoul(buf
, 120, &t
))
5059 if (!fan_control_allowed
)
5062 fan_watchdog_maxinterval
= t
;
5063 fan_watchdog_reset();
5068 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
5069 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
5071 /* --------------------------------------------------------------------- */
5072 static struct attribute
*fan_attributes
[] = {
5073 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
5074 &dev_attr_fan_fan1_input
.attr
,
5078 static const struct attribute_group fan_attr_group
= {
5079 .attrs
= fan_attributes
,
5082 static int __init
fan_init(struct ibm_init_struct
*iibm
)
5086 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
5088 mutex_init(&fan_mutex
);
5089 fan_status_access_mode
= TPACPI_FAN_NONE
;
5090 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
5091 fan_control_commands
= 0;
5092 fan_watchdog_maxinterval
= 0;
5093 tp_features
.fan_ctrl_status_undef
= 0;
5094 fan_control_desired_level
= 7;
5096 TPACPI_ACPIHANDLE_INIT(fans
);
5097 TPACPI_ACPIHANDLE_INIT(gfan
);
5098 TPACPI_ACPIHANDLE_INIT(sfan
);
5101 /* 570, 600e/x, 770e, 770x */
5102 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
5104 /* all other ThinkPads: note that even old-style
5105 * ThinkPad ECs supports the fan control register */
5106 if (likely(acpi_ec_read(fan_status_offset
,
5107 &fan_control_initial_status
))) {
5108 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
5110 /* In some ThinkPads, neither the EC nor the ACPI
5111 * DSDT initialize the fan status, and it ends up
5112 * being set to 0x07 when it *could* be either
5115 * Enable for TP-1Y (T43), TP-78 (R51e),
5116 * TP-76 (R52), TP-70 (T43, R52), which are known
5118 if (fan_control_initial_status
== 0x07) {
5119 switch (thinkpad_id
.ec_model
) {
5120 case 0x5931: /* TP-1Y */
5121 case 0x3837: /* TP-78 */
5122 case 0x3637: /* TP-76 */
5123 case 0x3037: /* TP-70 */
5124 printk(TPACPI_NOTICE
5125 "fan_init: initial fan status "
5126 "is unknown, assuming it is "
5128 tp_features
.fan_ctrl_status_undef
= 1;
5134 "ThinkPad ACPI EC access misbehaving, "
5135 "fan status and control unavailable\n");
5142 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
5143 fan_control_commands
|=
5144 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
5147 /* gfan without sfan means no fan control */
5148 /* all other models implement TP EC 0x2f control */
5152 fan_control_access_mode
=
5153 TPACPI_FAN_WR_ACPI_FANS
;
5154 fan_control_commands
|=
5155 TPACPI_FAN_CMD_SPEED
|
5156 TPACPI_FAN_CMD_LEVEL
|
5157 TPACPI_FAN_CMD_ENABLE
;
5159 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
5160 fan_control_commands
|=
5161 TPACPI_FAN_CMD_LEVEL
|
5162 TPACPI_FAN_CMD_ENABLE
;
5167 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
5168 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
5169 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
5170 fan_status_access_mode
, fan_control_access_mode
);
5172 /* fan control master switch */
5173 if (!fan_control_allowed
) {
5174 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
5175 fan_control_commands
= 0;
5176 dbg_printk(TPACPI_DBG_INIT
,
5177 "fan control features disabled by parameter\n");
5180 /* update fan_control_desired_level */
5181 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
5182 fan_get_status_safe(NULL
);
5184 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
5185 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
5186 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5189 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
5190 &driver_attr_fan_watchdog
);
5198 static void fan_exit(void)
5200 vdbg_printk(TPACPI_DBG_EXIT
,
5201 "cancelling any pending fan watchdog tasks\n");
5203 /* FIXME: can we really do this unconditionally? */
5204 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
5205 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
,
5206 &driver_attr_fan_watchdog
);
5208 cancel_delayed_work(&fan_watchdog_task
);
5209 flush_scheduled_work();
5212 static int fan_read(char *p
)
5217 unsigned int speed
= 0;
5219 switch (fan_status_access_mode
) {
5220 case TPACPI_FAN_RD_ACPI_GFAN
:
5221 /* 570, 600e/x, 770e, 770x */
5222 rc
= fan_get_status_safe(&status
);
5226 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
5228 (status
!= 0) ? "enabled" : "disabled", status
);
5231 case TPACPI_FAN_RD_TPEC
:
5232 /* all except 570, 600e/x, 770e, 770x */
5233 rc
= fan_get_status_safe(&status
);
5237 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5238 if (status
!= fan_control_initial_status
)
5239 tp_features
.fan_ctrl_status_undef
= 0;
5241 /* Return most likely status. In fact, it
5242 * might be the only possible status */
5243 status
= TP_EC_FAN_AUTO
;
5246 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
5247 (status
!= 0) ? "enabled" : "disabled");
5249 rc
= fan_get_speed(&speed
);
5253 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
5255 if (status
& TP_EC_FAN_FULLSPEED
)
5256 /* Disengaged mode takes precedence */
5257 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
5258 else if (status
& TP_EC_FAN_AUTO
)
5259 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
5261 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
5264 case TPACPI_FAN_NONE
:
5266 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5269 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
5270 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
5272 switch (fan_control_access_mode
) {
5273 case TPACPI_FAN_WR_ACPI_SFAN
:
5274 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
5278 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
5279 "auto, disengaged, full-speed)\n");
5284 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
5285 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
5286 "commands:\twatchdog <timeout> (<timeout> "
5287 "is 0 (off), 1-120 (seconds))\n");
5289 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
5290 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
5291 " (<speed> is 0-65535)\n");
5296 static int fan_write_cmd_level(const char *cmd
, int *rc
)
5300 if (strlencmp(cmd
, "level auto") == 0)
5301 level
= TP_EC_FAN_AUTO
;
5302 else if ((strlencmp(cmd
, "level disengaged") == 0) |
5303 (strlencmp(cmd
, "level full-speed") == 0))
5304 level
= TP_EC_FAN_FULLSPEED
;
5305 else if (sscanf(cmd
, "level %d", &level
) != 1)
5308 *rc
= fan_set_level_safe(level
);
5310 printk(TPACPI_ERR
"level command accepted for unsupported "
5311 "access mode %d", fan_control_access_mode
);
5316 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
5318 if (strlencmp(cmd
, "enable") != 0)
5321 *rc
= fan_set_enable();
5323 printk(TPACPI_ERR
"enable command accepted for unsupported "
5324 "access mode %d", fan_control_access_mode
);
5329 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
5331 if (strlencmp(cmd
, "disable") != 0)
5334 *rc
= fan_set_disable();
5336 printk(TPACPI_ERR
"disable command accepted for unsupported "
5337 "access mode %d", fan_control_access_mode
);
5342 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
5347 * Support speed <low> <medium> <high> ? */
5349 if (sscanf(cmd
, "speed %d", &speed
) != 1)
5352 *rc
= fan_set_speed(speed
);
5354 printk(TPACPI_ERR
"speed command accepted for unsupported "
5355 "access mode %d", fan_control_access_mode
);
5360 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
5364 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
5367 if (interval
< 0 || interval
> 120)
5370 fan_watchdog_maxinterval
= interval
;
5375 static int fan_write(char *buf
)
5380 while (!rc
&& (cmd
= next_cmd(&buf
))) {
5381 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
5382 fan_write_cmd_level(cmd
, &rc
)) &&
5383 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
5384 (fan_write_cmd_enable(cmd
, &rc
) ||
5385 fan_write_cmd_disable(cmd
, &rc
) ||
5386 fan_write_cmd_watchdog(cmd
, &rc
))) &&
5387 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
5388 fan_write_cmd_speed(cmd
, &rc
))
5392 fan_watchdog_reset();
5398 static struct ibm_struct fan_driver_data
= {
5405 /****************************************************************************
5406 ****************************************************************************
5410 ****************************************************************************
5411 ****************************************************************************/
5413 /* sysfs name ---------------------------------------------------------- */
5414 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
5415 struct device_attribute
*attr
,
5418 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
5421 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
5422 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
5424 /* --------------------------------------------------------------------- */
5427 static struct proc_dir_entry
*proc_dir
;
5430 * Module and infrastructure proble, init and exit handling
5433 static int force_load
;
5435 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
5436 static const char * __init
str_supported(int is_supported
)
5438 static char text_unsupported
[] __initdata
= "not supported";
5440 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
5442 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
5444 static void ibm_exit(struct ibm_struct
*ibm
)
5446 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
5448 list_del_init(&ibm
->all_drivers
);
5450 if (ibm
->flags
.acpi_notify_installed
) {
5451 dbg_printk(TPACPI_DBG_EXIT
,
5452 "%s: acpi_remove_notify_handler\n", ibm
->name
);
5454 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
5456 dispatch_acpi_notify
);
5457 ibm
->flags
.acpi_notify_installed
= 0;
5458 ibm
->flags
.acpi_notify_installed
= 0;
5461 if (ibm
->flags
.proc_created
) {
5462 dbg_printk(TPACPI_DBG_EXIT
,
5463 "%s: remove_proc_entry\n", ibm
->name
);
5464 remove_proc_entry(ibm
->name
, proc_dir
);
5465 ibm
->flags
.proc_created
= 0;
5468 if (ibm
->flags
.acpi_driver_registered
) {
5469 dbg_printk(TPACPI_DBG_EXIT
,
5470 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
5472 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
5473 kfree(ibm
->acpi
->driver
);
5474 ibm
->acpi
->driver
= NULL
;
5475 ibm
->flags
.acpi_driver_registered
= 0;
5478 if (ibm
->flags
.init_called
&& ibm
->exit
) {
5480 ibm
->flags
.init_called
= 0;
5483 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
5486 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
5489 struct ibm_struct
*ibm
= iibm
->data
;
5490 struct proc_dir_entry
*entry
;
5492 BUG_ON(ibm
== NULL
);
5494 INIT_LIST_HEAD(&ibm
->all_drivers
);
5496 if (ibm
->flags
.experimental
&& !experimental
)
5499 dbg_printk(TPACPI_DBG_INIT
,
5500 "probing for %s\n", ibm
->name
);
5503 ret
= iibm
->init(iibm
);
5505 return 0; /* probe failed */
5509 ibm
->flags
.init_called
= 1;
5513 if (ibm
->acpi
->hid
) {
5514 ret
= register_tpacpi_subdriver(ibm
);
5519 if (ibm
->acpi
->notify
) {
5520 ret
= setup_acpi_notify(ibm
);
5521 if (ret
== -ENODEV
) {
5522 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
5532 dbg_printk(TPACPI_DBG_INIT
,
5533 "%s installed\n", ibm
->name
);
5536 entry
= create_proc_entry(ibm
->name
,
5537 S_IFREG
| S_IRUGO
| S_IWUSR
,
5540 printk(TPACPI_ERR
"unable to create proc entry %s\n",
5545 entry
->owner
= THIS_MODULE
;
5547 entry
->read_proc
= &dispatch_procfs_read
;
5549 entry
->write_proc
= &dispatch_procfs_write
;
5550 ibm
->flags
.proc_created
= 1;
5553 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
5558 dbg_printk(TPACPI_DBG_INIT
,
5559 "%s: at error exit path with result %d\n",
5563 return (ret
< 0)? ret
: 0;
5568 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
5570 struct dmi_device
*dev
= NULL
;
5571 char ec_fw_string
[18];
5576 memset(tp
, 0, sizeof(*tp
));
5578 if (dmi_name_in_vendors("IBM"))
5579 tp
->vendor
= PCI_VENDOR_ID_IBM
;
5580 else if (dmi_name_in_vendors("LENOVO"))
5581 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
5585 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
5587 if (!tp
->bios_version_str
)
5589 tp
->bios_model
= tp
->bios_version_str
[0]
5590 | (tp
->bios_version_str
[1] << 8);
5593 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
5594 * X32 or newer, all Z series; Some models must have an
5595 * up-to-date BIOS or they will not be detected.
5597 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
5599 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
5600 if (sscanf(dev
->name
,
5601 "IBM ThinkPad Embedded Controller -[%17c",
5602 ec_fw_string
) == 1) {
5603 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
5604 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
5606 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
5607 tp
->ec_model
= ec_fw_string
[0]
5608 | (ec_fw_string
[1] << 8);
5613 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
5615 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
5616 kfree(tp
->model_str
);
5617 tp
->model_str
= NULL
;
5621 static int __init
probe_for_thinkpad(void)
5629 * Non-ancient models have better DMI tagging, but very old models
5632 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
5634 /* ec is required because many other handles are relative to it */
5635 TPACPI_ACPIHANDLE_INIT(ec
);
5639 "Not yet supported ThinkPad detected!\n");
5644 * Risks a regression on very old machines, but reduces potential
5645 * false positives a damn great deal
5648 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
5650 if (!is_thinkpad
&& !force_load
)
5657 /* Module init, exit, parameters */
5659 static struct ibm_init_struct ibms_init
[] __initdata
= {
5661 .init
= thinkpad_acpi_driver_init
,
5662 .data
= &thinkpad_acpi_driver_data
,
5665 .init
= hotkey_init
,
5666 .data
= &hotkey_driver_data
,
5669 .init
= bluetooth_init
,
5670 .data
= &bluetooth_driver_data
,
5674 .data
= &wan_driver_data
,
5678 .data
= &video_driver_data
,
5682 .data
= &light_driver_data
,
5684 #ifdef CONFIG_THINKPAD_ACPI_DOCK
5687 .data
= &dock_driver_data
[0],
5691 .data
= &dock_driver_data
[1],
5694 #ifdef CONFIG_THINKPAD_ACPI_BAY
5697 .data
= &bay_driver_data
,
5702 .data
= &cmos_driver_data
,
5706 .data
= &led_driver_data
,
5710 .data
= &beep_driver_data
,
5713 .init
= thermal_init
,
5714 .data
= &thermal_driver_data
,
5717 .data
= &ecdump_driver_data
,
5720 .init
= brightness_init
,
5721 .data
= &brightness_driver_data
,
5724 .data
= &volume_driver_data
,
5728 .data
= &fan_driver_data
,
5732 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
5735 struct ibm_struct
*ibm
;
5737 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
5738 ibm
= ibms_init
[i
].data
;
5739 BUG_ON(ibm
== NULL
);
5741 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
5742 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
5744 strcpy(ibms_init
[i
].param
, val
);
5745 strcat(ibms_init
[i
].param
, ",");
5753 module_param(experimental
, int, 0);
5754 MODULE_PARM_DESC(experimental
,
5755 "Enables experimental features when non-zero");
5757 module_param_named(debug
, dbg_level
, uint
, 0);
5758 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
5760 module_param(force_load
, bool, 0);
5761 MODULE_PARM_DESC(force_load
,
5762 "Attempts to load the driver even on a "
5763 "mis-identified ThinkPad when true");
5765 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
5766 MODULE_PARM_DESC(fan_control
,
5767 "Enables setting fan parameters features when true");
5769 module_param_named(brightness_mode
, brightness_mode
, int, 0);
5770 MODULE_PARM_DESC(brightness_mode
,
5771 "Selects brightness control strategy: "
5772 "0=auto, 1=EC, 2=CMOS, 3=both");
5774 module_param(brightness_enable
, uint
, 0);
5775 MODULE_PARM_DESC(brightness_enable
,
5776 "Enables backlight control when 1, disables when 0");
5778 module_param(hotkey_report_mode
, uint
, 0);
5779 MODULE_PARM_DESC(hotkey_report_mode
,
5780 "used for backwards compatibility with userspace, "
5781 "see documentation");
5783 #define TPACPI_PARAM(feature) \
5784 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
5785 MODULE_PARM_DESC(feature, "Simulates thinkpad-aci procfs command " \
5786 "at module load, see documentation")
5788 TPACPI_PARAM(hotkey
);
5789 TPACPI_PARAM(bluetooth
);
5790 TPACPI_PARAM(video
);
5791 TPACPI_PARAM(light
);
5792 #ifdef CONFIG_THINKPAD_ACPI_DOCK
5795 #ifdef CONFIG_THINKPAD_ACPI_BAY
5797 #endif /* CONFIG_THINKPAD_ACPI_BAY */
5801 TPACPI_PARAM(ecdump
);
5802 TPACPI_PARAM(brightness
);
5803 TPACPI_PARAM(volume
);
5806 static void thinkpad_acpi_module_exit(void)
5808 struct ibm_struct
*ibm
, *itmp
;
5810 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
5812 list_for_each_entry_safe_reverse(ibm
, itmp
,
5813 &tpacpi_all_drivers
,
5818 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
5820 if (tpacpi_inputdev
) {
5821 if (tp_features
.input_device_registered
)
5822 input_unregister_device(tpacpi_inputdev
);
5824 input_free_device(tpacpi_inputdev
);
5828 hwmon_device_unregister(tpacpi_hwmon
);
5830 if (tp_features
.sensors_pdev_attrs_registered
)
5831 device_remove_file(&tpacpi_sensors_pdev
->dev
,
5832 &dev_attr_thinkpad_acpi_pdev_name
);
5833 if (tpacpi_sensors_pdev
)
5834 platform_device_unregister(tpacpi_sensors_pdev
);
5836 platform_device_unregister(tpacpi_pdev
);
5838 if (tp_features
.sensors_pdrv_attrs_registered
)
5839 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
5840 if (tp_features
.platform_drv_attrs_registered
)
5841 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
5843 if (tp_features
.sensors_pdrv_registered
)
5844 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
5846 if (tp_features
.platform_drv_registered
)
5847 platform_driver_unregister(&tpacpi_pdriver
);
5850 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
5852 kfree(thinkpad_id
.bios_version_str
);
5853 kfree(thinkpad_id
.ec_version_str
);
5854 kfree(thinkpad_id
.model_str
);
5858 static int __init
thinkpad_acpi_module_init(void)
5862 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
5864 /* Parameter checking */
5865 if (hotkey_report_mode
> 2)
5868 /* Driver-level probe */
5870 get_thinkpad_model_data(&thinkpad_id
);
5871 ret
= probe_for_thinkpad();
5873 thinkpad_acpi_module_exit();
5877 /* Driver initialization */
5879 TPACPI_ACPIHANDLE_INIT(ecrd
);
5880 TPACPI_ACPIHANDLE_INIT(ecwr
);
5882 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
5885 "unable to create proc dir " TPACPI_PROC_DIR
);
5886 thinkpad_acpi_module_exit();
5889 proc_dir
->owner
= THIS_MODULE
;
5891 ret
= platform_driver_register(&tpacpi_pdriver
);
5894 "unable to register main platform driver\n");
5895 thinkpad_acpi_module_exit();
5898 tp_features
.platform_drv_registered
= 1;
5900 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
5903 "unable to register hwmon platform driver\n");
5904 thinkpad_acpi_module_exit();
5907 tp_features
.sensors_pdrv_registered
= 1;
5909 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
5911 tp_features
.platform_drv_attrs_registered
= 1;
5912 ret
= tpacpi_create_driver_attributes(
5913 &tpacpi_hwmon_pdriver
.driver
);
5917 "unable to create sysfs driver attributes\n");
5918 thinkpad_acpi_module_exit();
5921 tp_features
.sensors_pdrv_attrs_registered
= 1;
5924 /* Device initialization */
5925 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
5927 if (IS_ERR(tpacpi_pdev
)) {
5928 ret
= PTR_ERR(tpacpi_pdev
);
5930 printk(TPACPI_ERR
"unable to register platform device\n");
5931 thinkpad_acpi_module_exit();
5934 tpacpi_sensors_pdev
= platform_device_register_simple(
5935 TPACPI_HWMON_DRVR_NAME
,
5937 if (IS_ERR(tpacpi_sensors_pdev
)) {
5938 ret
= PTR_ERR(tpacpi_sensors_pdev
);
5939 tpacpi_sensors_pdev
= NULL
;
5941 "unable to register hwmon platform device\n");
5942 thinkpad_acpi_module_exit();
5945 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
5946 &dev_attr_thinkpad_acpi_pdev_name
);
5949 "unable to create sysfs hwmon device attributes\n");
5950 thinkpad_acpi_module_exit();
5953 tp_features
.sensors_pdev_attrs_registered
= 1;
5954 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
5955 if (IS_ERR(tpacpi_hwmon
)) {
5956 ret
= PTR_ERR(tpacpi_hwmon
);
5957 tpacpi_hwmon
= NULL
;
5958 printk(TPACPI_ERR
"unable to register hwmon device\n");
5959 thinkpad_acpi_module_exit();
5962 mutex_init(&tpacpi_inputdev_send_mutex
);
5963 tpacpi_inputdev
= input_allocate_device();
5964 if (!tpacpi_inputdev
) {
5965 printk(TPACPI_ERR
"unable to allocate input device\n");
5966 thinkpad_acpi_module_exit();
5969 /* Prepare input device, but don't register */
5970 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
5971 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
5972 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
5973 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
5974 thinkpad_id
.vendor
:
5976 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
5977 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
5979 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
5980 ret
= ibm_init(&ibms_init
[i
]);
5981 if (ret
>= 0 && *ibms_init
[i
].param
)
5982 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
5984 thinkpad_acpi_module_exit();
5988 ret
= input_register_device(tpacpi_inputdev
);
5990 printk(TPACPI_ERR
"unable to register input device\n");
5991 thinkpad_acpi_module_exit();
5994 tp_features
.input_device_registered
= 1;
5997 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
6001 /* Please remove this in year 2009 */
6002 MODULE_ALIAS("ibm_acpi");
6005 * DMI matching for module autoloading
6007 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
6008 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
6010 * Only models listed in thinkwiki will be supported, so add yours
6011 * if it is not there yet.
6013 #define IBM_BIOS_MODULE_ALIAS(__type) \
6014 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
6016 /* Non-ancient thinkpads */
6017 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
6018 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
6020 /* Ancient thinkpad BIOSes have to be identified by
6021 * BIOS type or model number, and there are far less
6022 * BIOS types than model numbers... */
6023 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
6024 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
6025 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
6027 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
6028 MODULE_DESCRIPTION(TPACPI_DESC
);
6029 MODULE_VERSION(TPACPI_VERSION
);
6030 MODULE_LICENSE("GPL");
6032 module_init(thinkpad_acpi_module_init
);
6033 module_exit(thinkpad_acpi_module_exit
);