2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2007 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #define TPACPI_VERSION "0.18"
25 #define TPACPI_SYSFS_VERSION 0x020101
29 * 2007-10-20 changelog trimmed down
31 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
34 * 2006-11-22 0.13 new maintainer
35 * changelog now lives in git commit history, and will
36 * not be updated further in-file.
38 * 2005-03-17 0.11 support for 600e, 770x
39 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
41 * 2005-01-16 0.9 use MODULE_VERSION
42 * thanks to Henrik Brix Andersen <brix@gentoo.org>
43 * fix parameter passing on module loading
44 * thanks to Rusty Russell <rusty@rustcorp.com.au>
45 * thanks to Jim Radford <radford@blackbean.org>
46 * 2004-11-08 0.8 fix init error case, don't return from a macro
47 * thanks to Chris Wright <chrisw@osdl.org>
50 #include <linux/kernel.h>
51 #include <linux/module.h>
52 #include <linux/init.h>
53 #include <linux/types.h>
54 #include <linux/string.h>
55 #include <linux/list.h>
56 #include <linux/mutex.h>
57 #include <linux/kthread.h>
58 #include <linux/freezer.h>
59 #include <linux/delay.h>
61 #include <linux/nvram.h>
62 #include <linux/proc_fs.h>
63 #include <linux/sysfs.h>
64 #include <linux/backlight.h>
66 #include <linux/platform_device.h>
67 #include <linux/hwmon.h>
68 #include <linux/hwmon-sysfs.h>
69 #include <linux/input.h>
70 #include <asm/uaccess.h>
72 #include <linux/dmi.h>
73 #include <linux/jiffies.h>
74 #include <linux/workqueue.h>
76 #include <acpi/acpi_drivers.h>
77 #include <acpi/acnamesp.h>
79 #include <linux/pci_ids.h>
82 /* ThinkPad CMOS commands */
83 #define TP_CMOS_VOLUME_DOWN 0
84 #define TP_CMOS_VOLUME_UP 1
85 #define TP_CMOS_VOLUME_MUTE 2
86 #define TP_CMOS_BRIGHTNESS_UP 4
87 #define TP_CMOS_BRIGHTNESS_DOWN 5
91 TP_NVRAM_ADDR_HK2
= 0x57,
92 TP_NVRAM_ADDR_THINKLIGHT
= 0x58,
93 TP_NVRAM_ADDR_VIDEO
= 0x59,
94 TP_NVRAM_ADDR_BRIGHTNESS
= 0x5e,
95 TP_NVRAM_ADDR_MIXER
= 0x60,
100 TP_NVRAM_MASK_HKT_THINKPAD
= 0x08,
101 TP_NVRAM_MASK_HKT_ZOOM
= 0x20,
102 TP_NVRAM_MASK_HKT_DISPLAY
= 0x40,
103 TP_NVRAM_MASK_HKT_HIBERNATE
= 0x80,
104 TP_NVRAM_MASK_THINKLIGHT
= 0x10,
105 TP_NVRAM_MASK_HKT_DISPEXPND
= 0x30,
106 TP_NVRAM_MASK_HKT_BRIGHTNESS
= 0x20,
107 TP_NVRAM_MASK_LEVEL_BRIGHTNESS
= 0x0f,
108 TP_NVRAM_POS_LEVEL_BRIGHTNESS
= 0,
109 TP_NVRAM_MASK_MUTE
= 0x40,
110 TP_NVRAM_MASK_HKT_VOLUME
= 0x80,
111 TP_NVRAM_MASK_LEVEL_VOLUME
= 0x0f,
112 TP_NVRAM_POS_LEVEL_VOLUME
= 0,
116 #define TPACPI_ACPI_HKEY_HID "IBM0068"
119 #define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
120 #define TPACPI_HKEY_INPUT_VERSION 0x4101
123 /****************************************************************************
127 #define TPACPI_NAME "thinkpad"
128 #define TPACPI_DESC "ThinkPad ACPI Extras"
129 #define TPACPI_FILE TPACPI_NAME "_acpi"
130 #define TPACPI_URL "http://ibm-acpi.sf.net/"
131 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
133 #define TPACPI_PROC_DIR "ibm"
134 #define TPACPI_ACPI_EVENT_PREFIX "ibm"
135 #define TPACPI_DRVR_NAME TPACPI_FILE
136 #define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
138 #define TPACPI_MAX_ACPI_ARGS 3
141 #define TPACPI_LOG TPACPI_FILE ": "
142 #define TPACPI_ERR KERN_ERR TPACPI_LOG
143 #define TPACPI_NOTICE KERN_NOTICE TPACPI_LOG
144 #define TPACPI_INFO KERN_INFO TPACPI_LOG
145 #define TPACPI_DEBUG KERN_DEBUG TPACPI_LOG
147 #define TPACPI_DBG_ALL 0xffff
148 #define TPACPI_DBG_ALL 0xffff
149 #define TPACPI_DBG_INIT 0x0001
150 #define TPACPI_DBG_EXIT 0x0002
151 #define dbg_printk(a_dbg_level, format, arg...) \
152 do { if (dbg_level & a_dbg_level) \
153 printk(TPACPI_DEBUG "%s: " format, __func__ , ## arg); } while (0)
154 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
155 #define vdbg_printk(a_dbg_level, format, arg...) \
156 dbg_printk(a_dbg_level, format, ## arg)
157 static const char *str_supported(int is_supported
);
159 #define vdbg_printk(a_dbg_level, format, arg...)
162 #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
163 #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
164 #define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
167 /****************************************************************************
168 * Driver-wide structs and misc. variables
173 struct tp_acpi_drv_struct
{
174 const struct acpi_device_id
*hid
;
175 struct acpi_driver
*driver
;
177 void (*notify
) (struct ibm_struct
*, u32
);
180 struct acpi_device
*device
;
186 int (*read
) (char *);
187 int (*write
) (char *);
189 void (*resume
) (void);
191 struct list_head all_drivers
;
193 struct tp_acpi_drv_struct
*acpi
;
196 u8 acpi_driver_registered
:1;
197 u8 acpi_notify_installed
:1;
204 struct ibm_init_struct
{
207 int (*init
) (struct ibm_init_struct
*);
208 struct ibm_struct
*data
;
212 #ifdef CONFIG_THINKPAD_ACPI_BAY
224 u32 bright_16levels
:1;
226 u32 fan_ctrl_status_undef
:1;
227 u32 input_device_registered
:1;
228 u32 platform_drv_registered
:1;
229 u32 platform_drv_attrs_registered
:1;
230 u32 sensors_pdrv_registered
:1;
231 u32 sensors_pdrv_attrs_registered
:1;
232 u32 sensors_pdev_attrs_registered
:1;
233 u32 hotkey_poll_active
:1;
236 struct thinkpad_id_data
{
237 unsigned int vendor
; /* ThinkPad vendor:
238 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
240 char *bios_version_str
; /* Something like 1ZET51WW (1.03z) */
241 char *ec_version_str
; /* Something like 1ZHT51WW-1.04a */
243 u16 bios_model
; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */
248 static struct thinkpad_id_data thinkpad_id
;
251 TPACPI_LIFE_INIT
= 0,
256 static int experimental
;
257 static u32 dbg_level
;
259 /****************************************************************************
260 ****************************************************************************
262 * ACPI Helpers and device model
264 ****************************************************************************
265 ****************************************************************************/
267 /*************************************************************************
271 static acpi_handle root_handle
;
273 #define TPACPI_HANDLE(object, parent, paths...) \
274 static acpi_handle object##_handle; \
275 static acpi_handle *object##_parent = &parent##_handle; \
276 static char *object##_path; \
277 static char *object##_paths[] = { paths }
279 TPACPI_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
280 "\\_SB.PCI.ISA.EC", /* 570 */
281 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
282 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
283 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
284 "\\_SB.PCI0.ICH3.EC0", /* R31 */
285 "\\_SB.PCI0.LPC.EC", /* all others */
288 TPACPI_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
289 TPACPI_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
291 TPACPI_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
292 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
293 "\\CMS", /* R40, R40e */
296 TPACPI_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
297 "^HKEY", /* R30, R31 */
298 "HKEY", /* all others */
302 /*************************************************************************
306 static int acpi_evalf(acpi_handle handle
,
307 void *res
, char *method
, char *fmt
, ...)
310 struct acpi_object_list params
;
311 union acpi_object in_objs
[TPACPI_MAX_ACPI_ARGS
];
312 struct acpi_buffer result
, *resultp
;
313 union acpi_object out_obj
;
321 printk(TPACPI_ERR
"acpi_evalf() called with empty format\n");
334 params
.pointer
= &in_objs
[0];
341 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
342 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
344 /* add more types as needed */
346 printk(TPACPI_ERR
"acpi_evalf() called "
347 "with invalid format character '%c'\n", c
);
353 if (res_type
!= 'v') {
354 result
.length
= sizeof(out_obj
);
355 result
.pointer
= &out_obj
;
360 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
365 *(int *)res
= out_obj
.integer
.value
;
366 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
369 success
= status
== AE_OK
;
371 /* add more types as needed */
373 printk(TPACPI_ERR
"acpi_evalf() called "
374 "with invalid format character '%c'\n", res_type
);
378 if (!success
&& !quiet
)
379 printk(TPACPI_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
380 method
, fmt0
, status
);
385 static int acpi_ec_read(int i
, u8
* p
)
390 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
394 if (ec_read(i
, p
) < 0)
401 static int acpi_ec_write(int i
, u8 v
)
404 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
407 if (ec_write(i
, v
) < 0)
414 static int _sta(acpi_handle handle
)
418 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
424 static int issue_thinkpad_cmos_command(int cmos_cmd
)
429 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
435 /*************************************************************************
439 #define TPACPI_ACPIHANDLE_INIT(object) \
440 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
441 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
443 static void drv_acpi_handle_init(char *name
,
444 acpi_handle
*handle
, acpi_handle parent
,
445 char **paths
, int num_paths
, char **path
)
450 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
453 for (i
= 0; i
< num_paths
; i
++) {
454 status
= acpi_get_handle(parent
, paths
[i
], handle
);
455 if (ACPI_SUCCESS(status
)) {
457 dbg_printk(TPACPI_DBG_INIT
,
458 "Found ACPI handle %s for %s\n",
464 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
469 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
471 struct ibm_struct
*ibm
= data
;
473 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
476 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
479 ibm
->acpi
->notify(ibm
, event
);
482 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
489 if (!*ibm
->acpi
->handle
)
492 vdbg_printk(TPACPI_DBG_INIT
,
493 "setting up ACPI notify for %s\n", ibm
->name
);
495 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
497 printk(TPACPI_ERR
"acpi_bus_get_device(%s) failed: %d\n",
502 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
503 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
504 TPACPI_ACPI_EVENT_PREFIX
,
507 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
508 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
509 if (ACPI_FAILURE(status
)) {
510 if (status
== AE_ALREADY_EXISTS
) {
511 printk(TPACPI_NOTICE
"another device driver is already handling %s events\n",
514 printk(TPACPI_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
519 ibm
->flags
.acpi_notify_installed
= 1;
523 static int __init
tpacpi_device_add(struct acpi_device
*device
)
528 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
532 dbg_printk(TPACPI_DBG_INIT
,
533 "registering %s as an ACPI driver\n", ibm
->name
);
537 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
538 if (!ibm
->acpi
->driver
) {
539 printk(TPACPI_ERR
"kzalloc(ibm->driver) failed\n");
543 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", TPACPI_NAME
, ibm
->name
);
544 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
546 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
548 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
550 printk(TPACPI_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
552 kfree(ibm
->acpi
->driver
);
553 ibm
->acpi
->driver
= NULL
;
555 ibm
->flags
.acpi_driver_registered
= 1;
561 /****************************************************************************
562 ****************************************************************************
566 ****************************************************************************
567 ****************************************************************************/
569 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
570 int count
, int *eof
, void *data
)
572 struct ibm_struct
*ibm
= data
;
575 if (!ibm
|| !ibm
->read
)
578 len
= ibm
->read(page
);
582 if (len
<= off
+ count
)
594 static int dispatch_procfs_write(struct file
*file
,
595 const char __user
* userbuf
,
596 unsigned long count
, void *data
)
598 struct ibm_struct
*ibm
= data
;
602 if (!ibm
|| !ibm
->write
)
605 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
609 if (copy_from_user(kernbuf
, userbuf
, count
)) {
615 strcat(kernbuf
, ",");
616 ret
= ibm
->write(kernbuf
);
625 static char *next_cmd(char **cmds
)
630 while ((end
= strchr(start
, ',')) && end
== start
)
642 /****************************************************************************
643 ****************************************************************************
645 * Device model: input, hwmon and platform
647 ****************************************************************************
648 ****************************************************************************/
650 static struct platform_device
*tpacpi_pdev
;
651 static struct platform_device
*tpacpi_sensors_pdev
;
652 static struct device
*tpacpi_hwmon
;
653 static struct input_dev
*tpacpi_inputdev
;
654 static struct mutex tpacpi_inputdev_send_mutex
;
655 static LIST_HEAD(tpacpi_all_drivers
);
657 static int tpacpi_resume_handler(struct platform_device
*pdev
)
659 struct ibm_struct
*ibm
, *itmp
;
661 list_for_each_entry_safe(ibm
, itmp
,
671 static struct platform_driver tpacpi_pdriver
= {
673 .name
= TPACPI_DRVR_NAME
,
674 .owner
= THIS_MODULE
,
676 .resume
= tpacpi_resume_handler
,
679 static struct platform_driver tpacpi_hwmon_pdriver
= {
681 .name
= TPACPI_HWMON_DRVR_NAME
,
682 .owner
= THIS_MODULE
,
686 /*************************************************************************
687 * sysfs support helpers
690 struct attribute_set
{
691 unsigned int members
, max_members
;
692 struct attribute_group group
;
695 struct attribute_set_obj
{
696 struct attribute_set s
;
698 } __attribute__((packed
));
700 static struct attribute_set
*create_attr_set(unsigned int max_members
,
703 struct attribute_set_obj
*sobj
;
705 if (max_members
== 0)
708 /* Allocates space for implicit NULL at the end too */
709 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
710 max_members
* sizeof(struct attribute
*),
714 sobj
->s
.max_members
= max_members
;
715 sobj
->s
.group
.attrs
= &sobj
->a
;
716 sobj
->s
.group
.name
= name
;
721 #define destroy_attr_set(_set) \
724 /* not multi-threaded safe, use it in a single thread per set */
725 static int add_to_attr_set(struct attribute_set
* s
, struct attribute
*attr
)
730 if (s
->members
>= s
->max_members
)
733 s
->group
.attrs
[s
->members
] = attr
;
739 static int add_many_to_attr_set(struct attribute_set
* s
,
740 struct attribute
**attr
,
745 for (i
= 0; i
< count
; i
++) {
746 res
= add_to_attr_set(s
, attr
[i
]);
754 static void delete_attr_set(struct attribute_set
* s
, struct kobject
*kobj
)
756 sysfs_remove_group(kobj
, &s
->group
);
760 #define register_attr_set_with_sysfs(_attr_set, _kobj) \
761 sysfs_create_group(_kobj, &_attr_set->group)
763 static int parse_strtoul(const char *buf
,
764 unsigned long max
, unsigned long *value
)
768 while (*buf
&& isspace(*buf
))
770 *value
= simple_strtoul(buf
, &endp
, 0);
771 while (*endp
&& isspace(*endp
))
773 if (*endp
|| *value
> max
)
779 /*************************************************************************
780 * thinkpad-acpi driver attributes
783 /* interface_version --------------------------------------------------- */
784 static ssize_t
tpacpi_driver_interface_version_show(
785 struct device_driver
*drv
,
788 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
791 static DRIVER_ATTR(interface_version
, S_IRUGO
,
792 tpacpi_driver_interface_version_show
, NULL
);
794 /* debug_level --------------------------------------------------------- */
795 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
798 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
801 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
802 const char *buf
, size_t count
)
806 if (parse_strtoul(buf
, 0xffff, &t
))
814 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
815 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
817 /* version ------------------------------------------------------------- */
818 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
821 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
824 static DRIVER_ATTR(version
, S_IRUGO
,
825 tpacpi_driver_version_show
, NULL
);
827 /* --------------------------------------------------------------------- */
829 static struct driver_attribute
* tpacpi_driver_attributes
[] = {
830 &driver_attr_debug_level
, &driver_attr_version
,
831 &driver_attr_interface_version
,
834 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
840 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
841 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
848 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
852 for(i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
853 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
856 /****************************************************************************
857 ****************************************************************************
861 ****************************************************************************
862 ****************************************************************************/
864 /*************************************************************************
865 * thinkpad-acpi init subdriver
868 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
870 printk(TPACPI_INFO
"%s v%s\n", TPACPI_DESC
, TPACPI_VERSION
);
871 printk(TPACPI_INFO
"%s\n", TPACPI_URL
);
873 printk(TPACPI_INFO
"ThinkPad BIOS %s, EC %s\n",
874 (thinkpad_id
.bios_version_str
) ?
875 thinkpad_id
.bios_version_str
: "unknown",
876 (thinkpad_id
.ec_version_str
) ?
877 thinkpad_id
.ec_version_str
: "unknown");
879 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
880 printk(TPACPI_INFO
"%s %s\n",
881 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
882 "IBM" : ((thinkpad_id
.vendor
==
883 PCI_VENDOR_ID_LENOVO
) ?
884 "Lenovo" : "Unknown vendor"),
885 thinkpad_id
.model_str
);
890 static int thinkpad_acpi_driver_read(char *p
)
894 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", TPACPI_DESC
);
895 len
+= sprintf(p
+ len
, "version:\t%s\n", TPACPI_VERSION
);
900 static struct ibm_struct thinkpad_acpi_driver_data
= {
902 .read
= thinkpad_acpi_driver_read
,
905 /*************************************************************************
909 enum { /* hot key scan codes (derived from ACPI DSDT) */
910 TP_ACPI_HOTKEYSCAN_FNF1
= 0,
911 TP_ACPI_HOTKEYSCAN_FNF2
,
912 TP_ACPI_HOTKEYSCAN_FNF3
,
913 TP_ACPI_HOTKEYSCAN_FNF4
,
914 TP_ACPI_HOTKEYSCAN_FNF5
,
915 TP_ACPI_HOTKEYSCAN_FNF6
,
916 TP_ACPI_HOTKEYSCAN_FNF7
,
917 TP_ACPI_HOTKEYSCAN_FNF8
,
918 TP_ACPI_HOTKEYSCAN_FNF9
,
919 TP_ACPI_HOTKEYSCAN_FNF10
,
920 TP_ACPI_HOTKEYSCAN_FNF11
,
921 TP_ACPI_HOTKEYSCAN_FNF12
,
922 TP_ACPI_HOTKEYSCAN_FNBACKSPACE
,
923 TP_ACPI_HOTKEYSCAN_FNINSERT
,
924 TP_ACPI_HOTKEYSCAN_FNDELETE
,
925 TP_ACPI_HOTKEYSCAN_FNHOME
,
926 TP_ACPI_HOTKEYSCAN_FNEND
,
927 TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
928 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN
,
929 TP_ACPI_HOTKEYSCAN_FNSPACE
,
930 TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
931 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
932 TP_ACPI_HOTKEYSCAN_MUTE
,
933 TP_ACPI_HOTKEYSCAN_THINKPAD
,
936 enum { /* Keys available through NVRAM polling */
937 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb88c0U
,
938 TPACPI_HKEY_NVRAM_GOOD_MASK
= 0x00fb8000U
,
941 enum { /* Positions of some of the keys in hotkey masks */
942 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
943 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
944 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
945 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
946 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
947 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
948 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
949 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
950 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
951 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
952 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
955 enum { /* NVRAM to ACPI HKEY group map */
956 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
957 TP_ACPI_HKEY_ZOOM_MASK
|
958 TP_ACPI_HKEY_DISPSWTCH_MASK
|
959 TP_ACPI_HKEY_HIBERNATE_MASK
,
960 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
961 TP_ACPI_HKEY_BRGHTDWN_MASK
,
962 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
963 TP_ACPI_HKEY_VOLDWN_MASK
|
964 TP_ACPI_HKEY_MUTE_MASK
,
967 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
968 struct tp_nvram_state
{
969 u16 thinkpad_toggle
:1;
971 u16 display_toggle
:1;
972 u16 thinklight_toggle
:1;
973 u16 hibernate_toggle
:1;
974 u16 displayexp_toggle
:1;
976 u16 brightness_toggle
:1;
984 static struct task_struct
*tpacpi_hotkey_task
;
985 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
986 static int hotkey_poll_freq
= 10; /* Hz */
987 static struct mutex hotkey_thread_mutex
;
988 static struct mutex hotkey_thread_data_mutex
;
989 static unsigned int hotkey_config_change
;
991 #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
993 #define hotkey_source_mask 0U
995 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
997 static struct mutex hotkey_mutex
;
999 static int hotkey_orig_status
;
1000 static u32 hotkey_orig_mask
;
1001 static u32 hotkey_all_mask
;
1002 static u32 hotkey_reserved_mask
;
1003 static u32 hotkey_mask
;
1005 static unsigned int hotkey_report_mode
;
1007 static u16
*hotkey_keycode_map
;
1009 static struct attribute_set
*hotkey_dev_attributes
;
1011 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1012 #define HOTKEY_CONFIG_CRITICAL_START \
1013 mutex_lock(&hotkey_thread_data_mutex); \
1014 hotkey_config_change++;
1015 #define HOTKEY_CONFIG_CRITICAL_END \
1016 mutex_unlock(&hotkey_thread_data_mutex);
1018 #define HOTKEY_CONFIG_CRITICAL_START
1019 #define HOTKEY_CONFIG_CRITICAL_END
1020 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1022 static int hotkey_get_wlsw(int *status
)
1024 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
1030 * Call with hotkey_mutex held
1032 static int hotkey_mask_get(void)
1036 if (tp_features
.hotkey_mask
) {
1037 if (!acpi_evalf(hkey_handle
, &m
, "DHKN", "d"))
1040 hotkey_mask
= m
| (hotkey_source_mask
& hotkey_mask
);
1046 * Call with hotkey_mutex held
1048 static int hotkey_mask_set(u32 mask
)
1053 if (tp_features
.hotkey_mask
) {
1054 HOTKEY_CONFIG_CRITICAL_START
1055 for (i
= 0; i
< 32; i
++) {
1057 /* enable in firmware mask only keys not in NVRAM
1058 * mode, but enable the key in the cached hotkey_mask
1059 * regardless of mode, or the key will end up
1060 * disabled by hotkey_mask_get() */
1061 if (!acpi_evalf(hkey_handle
,
1062 NULL
, "MHKM", "vdd", i
+ 1,
1063 !!((mask
& ~hotkey_source_mask
) & m
))) {
1067 hotkey_mask
= (hotkey_mask
& ~m
) | (mask
& m
);
1070 HOTKEY_CONFIG_CRITICAL_END
1072 /* hotkey_mask_get must be called unconditionally below */
1073 if (!hotkey_mask_get() && !rc
&&
1074 (hotkey_mask
& ~hotkey_source_mask
) !=
1075 (mask
& ~hotkey_source_mask
)) {
1076 printk(TPACPI_NOTICE
1077 "requested hot key mask 0x%08x, but "
1078 "firmware forced it to 0x%08x\n",
1082 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1083 HOTKEY_CONFIG_CRITICAL_START
1084 hotkey_mask
= mask
& hotkey_source_mask
;
1085 HOTKEY_CONFIG_CRITICAL_END
1087 if (hotkey_mask
!= mask
) {
1088 printk(TPACPI_NOTICE
1089 "requested hot key mask 0x%08x, "
1090 "forced to 0x%08x (NVRAM poll mask is "
1091 "0x%08x): no firmware mask support\n",
1092 mask
, hotkey_mask
, hotkey_source_mask
);
1097 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1103 static int hotkey_status_get(int *status
)
1105 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1111 static int hotkey_status_set(int status
)
1113 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1119 static void tpacpi_input_send_radiosw(void)
1123 mutex_lock(&tpacpi_inputdev_send_mutex
);
1125 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
1126 input_report_switch(tpacpi_inputdev
,
1128 input_sync(tpacpi_inputdev
);
1131 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1134 static void tpacpi_input_send_key(unsigned int scancode
)
1136 unsigned int keycode
;
1138 keycode
= hotkey_keycode_map
[scancode
];
1140 if (keycode
!= KEY_RESERVED
) {
1141 mutex_lock(&tpacpi_inputdev_send_mutex
);
1143 input_report_key(tpacpi_inputdev
, keycode
, 1);
1144 if (keycode
== KEY_UNKNOWN
)
1145 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1147 input_sync(tpacpi_inputdev
);
1149 input_report_key(tpacpi_inputdev
, keycode
, 0);
1150 if (keycode
== KEY_UNKNOWN
)
1151 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1153 input_sync(tpacpi_inputdev
);
1155 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1159 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1160 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
;
1162 static void tpacpi_hotkey_send_key(unsigned int scancode
)
1164 tpacpi_input_send_key(scancode
);
1165 if (hotkey_report_mode
< 2) {
1166 acpi_bus_generate_proc_event(ibm_hotkey_acpidriver
.device
,
1167 0x80, 0x1001 + scancode
);
1171 static void hotkey_read_nvram(struct tp_nvram_state
*n
, u32 m
)
1175 if (m
& TP_NVRAM_HKEY_GROUP_HK2
) {
1176 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
1177 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
1178 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
1179 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
1180 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
1182 if (m
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
1183 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
1184 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
1186 if (m
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
1187 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
1188 n
->displayexp_toggle
=
1189 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
1191 if (m
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
1192 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
1193 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
1194 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
1195 n
->brightness_toggle
=
1196 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
1198 if (m
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
1199 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
1200 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
1201 >> TP_NVRAM_POS_LEVEL_VOLUME
;
1202 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
1203 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
1207 #define TPACPI_COMPARE_KEY(__scancode, __member) \
1208 do { if ((mask & (1 << __scancode)) && oldn->__member != newn->__member) \
1209 tpacpi_hotkey_send_key(__scancode); } while (0)
1211 #define TPACPI_MAY_SEND_KEY(__scancode) \
1212 do { if (mask & (1 << __scancode)) \
1213 tpacpi_hotkey_send_key(__scancode); } while (0)
1215 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
1216 struct tp_nvram_state
*newn
,
1219 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
);
1220 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
);
1221 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
);
1222 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
);
1224 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
);
1226 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
);
1229 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
1230 if (oldn
->mute
!= newn
->mute
) {
1231 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1233 if (oldn
->volume_level
> newn
->volume_level
) {
1234 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1235 } else if (oldn
->volume_level
< newn
->volume_level
) {
1236 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1237 } else if (oldn
->mute
== newn
->mute
) {
1238 /* repeated key presses that didn't change state */
1240 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE
);
1241 } else if (newn
->volume_level
!= 0) {
1242 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
1244 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
1249 /* handle brightness */
1250 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
1251 if (oldn
->brightness_level
< newn
->brightness_level
) {
1252 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1253 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
1254 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1256 /* repeated key presses that didn't change state */
1257 if (newn
->brightness_level
!= 0) {
1258 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME
);
1260 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND
);
1266 #undef TPACPI_COMPARE_KEY
1267 #undef TPACPI_MAY_SEND_KEY
1269 static int hotkey_kthread(void *data
)
1271 struct tp_nvram_state s
[2];
1273 unsigned int si
, so
;
1275 unsigned int change_detector
, must_reset
;
1277 mutex_lock(&hotkey_thread_mutex
);
1279 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
1288 /* Initial state for compares */
1289 mutex_lock(&hotkey_thread_data_mutex
);
1290 change_detector
= hotkey_config_change
;
1291 mask
= hotkey_source_mask
& hotkey_mask
;
1292 mutex_unlock(&hotkey_thread_data_mutex
);
1293 hotkey_read_nvram(&s
[so
], mask
);
1295 while (!kthread_should_stop() && hotkey_poll_freq
) {
1297 t
= 1000/hotkey_poll_freq
;
1298 t
= msleep_interruptible(t
);
1299 if (unlikely(kthread_should_stop()))
1301 must_reset
= try_to_freeze();
1302 if (t
> 0 && !must_reset
)
1305 mutex_lock(&hotkey_thread_data_mutex
);
1306 if (must_reset
|| hotkey_config_change
!= change_detector
) {
1307 /* forget old state on thaw or config change */
1310 change_detector
= hotkey_config_change
;
1312 mask
= hotkey_source_mask
& hotkey_mask
;
1313 mutex_unlock(&hotkey_thread_data_mutex
);
1316 hotkey_read_nvram(&s
[si
], mask
);
1317 if (likely(si
!= so
)) {
1318 hotkey_compare_and_issue_event(&s
[so
], &s
[si
],
1328 mutex_unlock(&hotkey_thread_mutex
);
1332 static void hotkey_poll_stop_sync(void)
1334 if (tpacpi_hotkey_task
) {
1335 if (frozen(tpacpi_hotkey_task
) ||
1336 freezing(tpacpi_hotkey_task
))
1337 thaw_process(tpacpi_hotkey_task
);
1339 kthread_stop(tpacpi_hotkey_task
);
1340 tpacpi_hotkey_task
= NULL
;
1341 mutex_lock(&hotkey_thread_mutex
);
1342 /* at this point, the thread did exit */
1343 mutex_unlock(&hotkey_thread_mutex
);
1347 /* call with hotkey_mutex held */
1348 static void hotkey_poll_setup(int may_warn
)
1350 if ((hotkey_source_mask
& hotkey_mask
) != 0 &&
1351 hotkey_poll_freq
> 0 &&
1352 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1353 if (!tpacpi_hotkey_task
) {
1354 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1355 NULL
, TPACPI_FILE
"d");
1356 if (IS_ERR(tpacpi_hotkey_task
)) {
1357 tpacpi_hotkey_task
= NULL
;
1358 printk(TPACPI_ERR
"could not create kernel thread "
1359 "for hotkey polling\n");
1363 hotkey_poll_stop_sync();
1365 hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1366 printk(TPACPI_NOTICE
"hot keys 0x%08x require polling, "
1367 "which is currently disabled\n",
1368 hotkey_source_mask
);
1373 static void hotkey_poll_setup_safe(int may_warn
)
1375 mutex_lock(&hotkey_mutex
);
1376 hotkey_poll_setup(may_warn
);
1377 mutex_unlock(&hotkey_mutex
);
1380 static int hotkey_inputdev_open(struct input_dev
*dev
)
1382 switch (tpacpi_lifecycle
) {
1383 case TPACPI_LIFE_INIT
:
1385 * hotkey_init will call hotkey_poll_setup_safe
1386 * at the appropriate moment
1389 case TPACPI_LIFE_EXITING
:
1391 case TPACPI_LIFE_RUNNING
:
1392 hotkey_poll_setup_safe(0);
1396 /* Should only happen if tpacpi_lifecycle is corrupt */
1401 static void hotkey_inputdev_close(struct input_dev
*dev
)
1403 /* disable hotkey polling when possible */
1404 if (tpacpi_lifecycle
== TPACPI_LIFE_RUNNING
)
1405 hotkey_poll_setup_safe(0);
1407 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1409 /* sysfs hotkey enable ------------------------------------------------- */
1410 static ssize_t
hotkey_enable_show(struct device
*dev
,
1411 struct device_attribute
*attr
,
1416 res
= hotkey_status_get(&status
);
1420 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1423 static ssize_t
hotkey_enable_store(struct device
*dev
,
1424 struct device_attribute
*attr
,
1425 const char *buf
, size_t count
)
1430 if (parse_strtoul(buf
, 1, &t
))
1433 res
= hotkey_status_set(t
);
1435 return (res
) ? res
: count
;
1438 static struct device_attribute dev_attr_hotkey_enable
=
1439 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
1440 hotkey_enable_show
, hotkey_enable_store
);
1442 /* sysfs hotkey mask --------------------------------------------------- */
1443 static ssize_t
hotkey_mask_show(struct device
*dev
,
1444 struct device_attribute
*attr
,
1449 if (mutex_lock_interruptible(&hotkey_mutex
))
1450 return -ERESTARTSYS
;
1451 res
= hotkey_mask_get();
1452 mutex_unlock(&hotkey_mutex
);
1455 res
: snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_mask
);
1458 static ssize_t
hotkey_mask_store(struct device
*dev
,
1459 struct device_attribute
*attr
,
1460 const char *buf
, size_t count
)
1465 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
1468 if (mutex_lock_interruptible(&hotkey_mutex
))
1469 return -ERESTARTSYS
;
1471 res
= hotkey_mask_set(t
);
1473 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1474 hotkey_poll_setup(1);
1477 mutex_unlock(&hotkey_mutex
);
1479 return (res
) ? res
: count
;
1482 static struct device_attribute dev_attr_hotkey_mask
=
1483 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
1484 hotkey_mask_show
, hotkey_mask_store
);
1486 /* sysfs hotkey bios_enabled ------------------------------------------- */
1487 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
1488 struct device_attribute
*attr
,
1491 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
1494 static struct device_attribute dev_attr_hotkey_bios_enabled
=
1495 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
1497 /* sysfs hotkey bios_mask ---------------------------------------------- */
1498 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
1499 struct device_attribute
*attr
,
1502 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
1505 static struct device_attribute dev_attr_hotkey_bios_mask
=
1506 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
1508 /* sysfs hotkey all_mask ----------------------------------------------- */
1509 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
1510 struct device_attribute
*attr
,
1513 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1514 hotkey_all_mask
| hotkey_source_mask
);
1517 static struct device_attribute dev_attr_hotkey_all_mask
=
1518 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
1520 /* sysfs hotkey recommended_mask --------------------------------------- */
1521 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
1522 struct device_attribute
*attr
,
1525 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1526 (hotkey_all_mask
| hotkey_source_mask
)
1527 & ~hotkey_reserved_mask
);
1530 static struct device_attribute dev_attr_hotkey_recommended_mask
=
1531 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
1532 hotkey_recommended_mask_show
, NULL
);
1534 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1536 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
1537 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
1538 struct device_attribute
*attr
,
1541 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
1544 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
1545 struct device_attribute
*attr
,
1546 const char *buf
, size_t count
)
1550 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
1551 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
1554 if (mutex_lock_interruptible(&hotkey_mutex
))
1555 return -ERESTARTSYS
;
1557 HOTKEY_CONFIG_CRITICAL_START
1558 hotkey_source_mask
= t
;
1559 HOTKEY_CONFIG_CRITICAL_END
1561 hotkey_poll_setup(1);
1563 mutex_unlock(&hotkey_mutex
);
1568 static struct device_attribute dev_attr_hotkey_source_mask
=
1569 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
1570 hotkey_source_mask_show
, hotkey_source_mask_store
);
1572 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
1573 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
1574 struct device_attribute
*attr
,
1577 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
1580 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
1581 struct device_attribute
*attr
,
1582 const char *buf
, size_t count
)
1586 if (parse_strtoul(buf
, 25, &t
))
1589 if (mutex_lock_interruptible(&hotkey_mutex
))
1590 return -ERESTARTSYS
;
1592 hotkey_poll_freq
= t
;
1594 hotkey_poll_setup(1);
1595 mutex_unlock(&hotkey_mutex
);
1600 static struct device_attribute dev_attr_hotkey_poll_freq
=
1601 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
1602 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
1604 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1606 /* sysfs hotkey radio_sw ----------------------------------------------- */
1607 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
1608 struct device_attribute
*attr
,
1612 res
= hotkey_get_wlsw(&s
);
1616 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1619 static struct device_attribute dev_attr_hotkey_radio_sw
=
1620 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
1622 /* sysfs hotkey report_mode -------------------------------------------- */
1623 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
1624 struct device_attribute
*attr
,
1627 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1628 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
1631 static struct device_attribute dev_attr_hotkey_report_mode
=
1632 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
1634 /* --------------------------------------------------------------------- */
1636 static struct attribute
*hotkey_attributes
[] __initdata
= {
1637 &dev_attr_hotkey_enable
.attr
,
1638 &dev_attr_hotkey_bios_enabled
.attr
,
1639 &dev_attr_hotkey_report_mode
.attr
,
1640 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1641 &dev_attr_hotkey_mask
.attr
,
1642 &dev_attr_hotkey_all_mask
.attr
,
1643 &dev_attr_hotkey_recommended_mask
.attr
,
1644 &dev_attr_hotkey_source_mask
.attr
,
1645 &dev_attr_hotkey_poll_freq
.attr
,
1649 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
1650 &dev_attr_hotkey_bios_mask
.attr
,
1651 #ifndef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1652 &dev_attr_hotkey_mask
.attr
,
1653 &dev_attr_hotkey_all_mask
.attr
,
1654 &dev_attr_hotkey_recommended_mask
.attr
,
1658 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
1661 /* Requirements for changing the default keymaps:
1663 * 1. Many of the keys are mapped to KEY_RESERVED for very
1664 * good reasons. Do not change them unless you have deep
1665 * knowledge on the IBM and Lenovo ThinkPad firmware for
1666 * the various ThinkPad models;
1668 * 2. You must be subscribed to the linux-thinkpad and
1669 * ibm-acpi-devel mailing lists, and you should read the
1670 * list archives since 2007. This requirement exists so
1671 * that you know the past history of problems with the
1672 * thinkpad-acpi driver keymaps, and also that you will
1673 * be listening to any bug reports;
1675 * 3. Do not send thinkpad-acpi specific patches directly to
1676 * Linus or to Andrew for merging. Send them to the
1677 * linux-acpi mailinglist, for comments. Merging is to
1678 * be done through acpi-test and the ACPI maintainer.
1680 * If the above is too much to ask, please consider sending a
1681 * simple email to the thinkpad-acpi maintainer describing the
1682 * changes you wanted to make and the rationale behind them,
1685 static u16 ibm_keycode_map
[] __initdata
= {
1686 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1687 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
1688 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1689 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1690 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
1691 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1692 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1693 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1694 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1695 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
1696 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1697 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1698 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1699 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1700 KEY_RESERVED
, /* 0x14: VOLUME UP */
1701 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1702 KEY_RESERVED
, /* 0x16: MUTE */
1703 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1704 /* (assignments unknown, please report if found) */
1705 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1706 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1708 static u16 lenovo_keycode_map
[] __initdata
= {
1709 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1710 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
1711 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1712 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1713 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
1714 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1715 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1716 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1717 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1718 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
1719 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1720 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1721 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1722 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1723 KEY_RESERVED
, /* 0x14: VOLUME UP */
1724 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1725 KEY_RESERVED
, /* 0x16: MUTE */
1726 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1727 /* (assignments unknown, please report if found) */
1728 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1729 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1732 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
1733 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
1734 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
1740 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
1742 BUG_ON(!tpacpi_inputdev
);
1743 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
1744 tpacpi_inputdev
->close
!= NULL
);
1746 TPACPI_ACPIHANDLE_INIT(hkey
);
1747 mutex_init(&hotkey_mutex
);
1749 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1750 mutex_init(&hotkey_thread_mutex
);
1751 mutex_init(&hotkey_thread_data_mutex
);
1754 /* hotkey not supported on 570 */
1755 tp_features
.hotkey
= hkey_handle
!= NULL
;
1757 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
1758 str_supported(tp_features
.hotkey
));
1760 if (tp_features
.hotkey
) {
1761 hotkey_dev_attributes
= create_attr_set(10, NULL
);
1762 if (!hotkey_dev_attributes
)
1764 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1766 ARRAY_SIZE(hotkey_attributes
));
1770 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1771 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
1772 for HKEY interface version 0x100 */
1773 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
1774 if ((hkeyv
>> 8) != 1) {
1775 printk(TPACPI_ERR
"unknown version of the "
1776 "HKEY interface: 0x%x\n", hkeyv
);
1777 printk(TPACPI_ERR
"please report this to %s\n",
1781 * MHKV 0x100 in A31, R40, R40e,
1782 * T4x, X31, and later
1784 tp_features
.hotkey_mask
= 1;
1788 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
1789 str_supported(tp_features
.hotkey_mask
));
1791 if (tp_features
.hotkey_mask
) {
1792 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
1795 "missing MHKA handler, "
1796 "please report this to %s\n",
1798 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
1802 /* hotkey_source_mask *must* be zero for
1803 * the first hotkey_mask_get */
1804 res
= hotkey_status_get(&hotkey_orig_status
);
1805 if (!res
&& tp_features
.hotkey_mask
) {
1806 res
= hotkey_mask_get();
1807 hotkey_orig_mask
= hotkey_mask
;
1809 res
= add_many_to_attr_set(
1810 hotkey_dev_attributes
,
1811 hotkey_mask_attributes
,
1812 ARRAY_SIZE(hotkey_mask_attributes
));
1816 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1817 if (tp_features
.hotkey_mask
) {
1818 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
1821 hotkey_source_mask
= TPACPI_HKEY_NVRAM_GOOD_MASK
;
1824 vdbg_printk(TPACPI_DBG_INIT
,
1825 "hotkey source mask 0x%08x, polling freq %d\n",
1826 hotkey_source_mask
, hotkey_poll_freq
);
1829 /* Not all thinkpads have a hardware radio switch */
1830 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
1831 tp_features
.hotkey_wlsw
= 1;
1833 "radio switch found; radios are %s\n",
1834 enabled(status
, 0));
1835 res
= add_to_attr_set(hotkey_dev_attributes
,
1836 &dev_attr_hotkey_radio_sw
.attr
);
1840 res
= register_attr_set_with_sysfs(
1841 hotkey_dev_attributes
,
1842 &tpacpi_pdev
->dev
.kobj
);
1846 /* Set up key map */
1848 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
1850 if (!hotkey_keycode_map
) {
1851 printk(TPACPI_ERR
"failed to allocate memory for key map\n");
1855 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
1856 dbg_printk(TPACPI_DBG_INIT
,
1857 "using Lenovo default hot key map\n");
1858 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
1859 TPACPI_HOTKEY_MAP_SIZE
);
1861 dbg_printk(TPACPI_DBG_INIT
,
1862 "using IBM default hot key map\n");
1863 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
1864 TPACPI_HOTKEY_MAP_SIZE
);
1867 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
1868 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
1869 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
1870 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
1871 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
1872 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
1873 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
1874 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
1875 set_bit(hotkey_keycode_map
[i
],
1876 tpacpi_inputdev
->keybit
);
1878 if (i
< sizeof(hotkey_reserved_mask
)*8)
1879 hotkey_reserved_mask
|= 1 << i
;
1883 if (tp_features
.hotkey_wlsw
) {
1884 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
1885 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
1888 dbg_printk(TPACPI_DBG_INIT
,
1889 "enabling hot key handling\n");
1890 res
= hotkey_status_set(1);
1893 res
= hotkey_mask_set(((hotkey_all_mask
| hotkey_source_mask
)
1894 & ~hotkey_reserved_mask
)
1895 | hotkey_orig_mask
);
1896 if (res
< 0 && res
!= -ENXIO
)
1899 dbg_printk(TPACPI_DBG_INIT
,
1900 "legacy hot key reporting over procfs %s\n",
1901 (hotkey_report_mode
< 2) ?
1902 "enabled" : "disabled");
1904 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1905 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
1906 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
1908 hotkey_poll_setup_safe(1);
1912 return (tp_features
.hotkey
)? 0 : 1;
1915 static void hotkey_exit(void)
1917 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
1918 hotkey_poll_stop_sync();
1921 if (tp_features
.hotkey
) {
1922 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hot key mask\n");
1923 /* no short-circuit boolean operator below! */
1924 if ((hotkey_mask_set(hotkey_orig_mask
) |
1925 hotkey_status_set(hotkey_orig_status
)) != 0)
1926 printk(TPACPI_ERR
"failed to restore hot key mask to BIOS defaults\n");
1929 if (hotkey_dev_attributes
) {
1930 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
1931 hotkey_dev_attributes
= NULL
;
1935 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
1938 unsigned int scancode
;
1942 if (event
!= 0x80) {
1943 printk(TPACPI_ERR
"unknown HKEY notification event %d\n", event
);
1944 /* forward it to userspace, maybe it knows how to handle it */
1945 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
1946 ibm
->acpi
->device
->dev
.bus_id
,
1952 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
1953 printk(TPACPI_ERR
"failed to retrieve HKEY event\n");
1965 switch (hkey
>> 12) {
1967 /* 0x1000-0x1FFF: key presses */
1968 scancode
= hkey
& 0xfff;
1969 if (scancode
> 0 && scancode
< 0x21) {
1971 if (!(hotkey_source_mask
& (1 << scancode
))) {
1972 tpacpi_input_send_key(scancode
);
1978 "hotkey 0x%04x out of range for keyboard map\n",
1984 /* 0x5000-0x5FFF: LID */
1985 /* we don't handle it through this path, just
1986 * eat up known LID events */
1987 if (hkey
!= 0x5001 && hkey
!= 0x5002) {
1989 "unknown LID-related HKEY event: 0x%04x\n",
1997 /* 0x7000-0x7FFF: misc */
1998 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
1999 tpacpi_input_send_radiosw();
2002 /* fallthrough to default */
2004 /* case 2: dock-related */
2005 /* 0x2305 - T43 waking up due to bay lever eject while aslept */
2006 /* case 3: ultra-bay related. maybe bay in dock? */
2007 /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
2008 printk(TPACPI_NOTICE
"unhandled HKEY event 0x%04x\n", hkey
);
2013 if (!ignore_acpi_ev
&& (send_acpi_ev
|| hotkey_report_mode
< 2)) {
2014 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, hkey
);
2017 /* netlink events */
2018 if (!ignore_acpi_ev
&& send_acpi_ev
) {
2019 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
2020 ibm
->acpi
->device
->dev
.bus_id
,
2026 static void hotkey_resume(void)
2028 if (hotkey_mask_get())
2029 printk(TPACPI_ERR
"error while trying to read hot key mask from firmware\n");
2030 tpacpi_input_send_radiosw();
2031 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
2032 hotkey_poll_setup_safe(0);
2036 /* procfs -------------------------------------------------------------- */
2037 static int hotkey_read(char *p
)
2042 if (!tp_features
.hotkey
) {
2043 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2047 if (mutex_lock_interruptible(&hotkey_mutex
))
2048 return -ERESTARTSYS
;
2049 res
= hotkey_status_get(&status
);
2051 res
= hotkey_mask_get();
2052 mutex_unlock(&hotkey_mutex
);
2056 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
2057 if (tp_features
.hotkey_mask
) {
2058 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", hotkey_mask
);
2059 len
+= sprintf(p
+ len
,
2060 "commands:\tenable, disable, reset, <mask>\n");
2062 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
2063 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
2069 static int hotkey_write(char *buf
)
2075 if (!tp_features
.hotkey
)
2078 if (mutex_lock_interruptible(&hotkey_mutex
))
2079 return -ERESTARTSYS
;
2085 while ((cmd
= next_cmd(&buf
))) {
2086 if (strlencmp(cmd
, "enable") == 0) {
2088 } else if (strlencmp(cmd
, "disable") == 0) {
2090 } else if (strlencmp(cmd
, "reset") == 0) {
2091 status
= hotkey_orig_status
;
2092 mask
= hotkey_orig_mask
;
2093 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
2095 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
2103 res
= hotkey_status_set(status
);
2105 if (!res
&& mask
!= hotkey_mask
)
2106 res
= hotkey_mask_set(mask
);
2109 mutex_unlock(&hotkey_mutex
);
2113 static const struct acpi_device_id ibm_htk_device_ids
[] = {
2114 {TPACPI_ACPI_HKEY_HID
, 0},
2118 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
2119 .hid
= ibm_htk_device_ids
,
2120 .notify
= hotkey_notify
,
2121 .handle
= &hkey_handle
,
2122 .type
= ACPI_DEVICE_NOTIFY
,
2125 static struct ibm_struct hotkey_driver_data
= {
2127 .read
= hotkey_read
,
2128 .write
= hotkey_write
,
2129 .exit
= hotkey_exit
,
2130 .resume
= hotkey_resume
,
2131 .acpi
= &ibm_hotkey_acpidriver
,
2134 /*************************************************************************
2135 * Bluetooth subdriver
2139 /* ACPI GBDC/SBDC bits */
2140 TP_ACPI_BLUETOOTH_HWPRESENT
= 0x01, /* Bluetooth hw available */
2141 TP_ACPI_BLUETOOTH_RADIOSSW
= 0x02, /* Bluetooth radio enabled */
2142 TP_ACPI_BLUETOOTH_UNK
= 0x04, /* unknown function */
2145 static int bluetooth_get_radiosw(void);
2146 static int bluetooth_set_radiosw(int radio_on
);
2148 /* sysfs bluetooth enable ---------------------------------------------- */
2149 static ssize_t
bluetooth_enable_show(struct device
*dev
,
2150 struct device_attribute
*attr
,
2155 status
= bluetooth_get_radiosw();
2159 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
2162 static ssize_t
bluetooth_enable_store(struct device
*dev
,
2163 struct device_attribute
*attr
,
2164 const char *buf
, size_t count
)
2169 if (parse_strtoul(buf
, 1, &t
))
2172 res
= bluetooth_set_radiosw(t
);
2174 return (res
) ? res
: count
;
2177 static struct device_attribute dev_attr_bluetooth_enable
=
2178 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
2179 bluetooth_enable_show
, bluetooth_enable_store
);
2181 /* --------------------------------------------------------------------- */
2183 static struct attribute
*bluetooth_attributes
[] = {
2184 &dev_attr_bluetooth_enable
.attr
,
2188 static const struct attribute_group bluetooth_attr_group
= {
2189 .attrs
= bluetooth_attributes
,
2192 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
2197 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
2199 TPACPI_ACPIHANDLE_INIT(hkey
);
2201 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2202 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
2203 tp_features
.bluetooth
= hkey_handle
&&
2204 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
2206 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
2207 str_supported(tp_features
.bluetooth
),
2210 if (tp_features
.bluetooth
) {
2211 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
2212 /* no bluetooth hardware present in system */
2213 tp_features
.bluetooth
= 0;
2214 dbg_printk(TPACPI_DBG_INIT
,
2215 "bluetooth hardware not installed\n");
2217 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2218 &bluetooth_attr_group
);
2224 return (tp_features
.bluetooth
)? 0 : 1;
2227 static void bluetooth_exit(void)
2229 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2230 &bluetooth_attr_group
);
2233 static int bluetooth_get_radiosw(void)
2237 if (!tp_features
.bluetooth
)
2240 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2243 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
2246 static int bluetooth_set_radiosw(int radio_on
)
2250 if (!tp_features
.bluetooth
)
2253 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
2256 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
2258 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
2259 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
2265 /* procfs -------------------------------------------------------------- */
2266 static int bluetooth_read(char *p
)
2269 int status
= bluetooth_get_radiosw();
2271 if (!tp_features
.bluetooth
)
2272 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2274 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2275 (status
)? "enabled" : "disabled");
2276 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2282 static int bluetooth_write(char *buf
)
2286 if (!tp_features
.bluetooth
)
2289 while ((cmd
= next_cmd(&buf
))) {
2290 if (strlencmp(cmd
, "enable") == 0) {
2291 bluetooth_set_radiosw(1);
2292 } else if (strlencmp(cmd
, "disable") == 0) {
2293 bluetooth_set_radiosw(0);
2301 static struct ibm_struct bluetooth_driver_data
= {
2302 .name
= "bluetooth",
2303 .read
= bluetooth_read
,
2304 .write
= bluetooth_write
,
2305 .exit
= bluetooth_exit
,
2308 /*************************************************************************
2313 /* ACPI GWAN/SWAN bits */
2314 TP_ACPI_WANCARD_HWPRESENT
= 0x01, /* Wan hw available */
2315 TP_ACPI_WANCARD_RADIOSSW
= 0x02, /* Wan radio enabled */
2316 TP_ACPI_WANCARD_UNK
= 0x04, /* unknown function */
2319 static int wan_get_radiosw(void);
2320 static int wan_set_radiosw(int radio_on
);
2322 /* sysfs wan enable ---------------------------------------------------- */
2323 static ssize_t
wan_enable_show(struct device
*dev
,
2324 struct device_attribute
*attr
,
2329 status
= wan_get_radiosw();
2333 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
2336 static ssize_t
wan_enable_store(struct device
*dev
,
2337 struct device_attribute
*attr
,
2338 const char *buf
, size_t count
)
2343 if (parse_strtoul(buf
, 1, &t
))
2346 res
= wan_set_radiosw(t
);
2348 return (res
) ? res
: count
;
2351 static struct device_attribute dev_attr_wan_enable
=
2352 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
2353 wan_enable_show
, wan_enable_store
);
2355 /* --------------------------------------------------------------------- */
2357 static struct attribute
*wan_attributes
[] = {
2358 &dev_attr_wan_enable
.attr
,
2362 static const struct attribute_group wan_attr_group
= {
2363 .attrs
= wan_attributes
,
2366 static int __init
wan_init(struct ibm_init_struct
*iibm
)
2371 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
2373 TPACPI_ACPIHANDLE_INIT(hkey
);
2375 tp_features
.wan
= hkey_handle
&&
2376 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
2378 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
2379 str_supported(tp_features
.wan
),
2382 if (tp_features
.wan
) {
2383 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
2384 /* no wan hardware present in system */
2385 tp_features
.wan
= 0;
2386 dbg_printk(TPACPI_DBG_INIT
,
2387 "wan hardware not installed\n");
2389 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2396 return (tp_features
.wan
)? 0 : 1;
2399 static void wan_exit(void)
2401 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2405 static int wan_get_radiosw(void)
2409 if (!tp_features
.wan
)
2412 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2415 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
2418 static int wan_set_radiosw(int radio_on
)
2422 if (!tp_features
.wan
)
2425 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2428 status
|= TP_ACPI_WANCARD_RADIOSSW
;
2430 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
2431 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
2437 /* procfs -------------------------------------------------------------- */
2438 static int wan_read(char *p
)
2441 int status
= wan_get_radiosw();
2443 if (!tp_features
.wan
)
2444 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2446 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2447 (status
)? "enabled" : "disabled");
2448 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2454 static int wan_write(char *buf
)
2458 if (!tp_features
.wan
)
2461 while ((cmd
= next_cmd(&buf
))) {
2462 if (strlencmp(cmd
, "enable") == 0) {
2464 } else if (strlencmp(cmd
, "disable") == 0) {
2473 static struct ibm_struct wan_driver_data
= {
2478 .flags
.experimental
= 1,
2481 /*************************************************************************
2485 enum video_access_mode
{
2486 TPACPI_VIDEO_NONE
= 0,
2487 TPACPI_VIDEO_570
, /* 570 */
2488 TPACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
2489 TPACPI_VIDEO_NEW
, /* all others */
2492 enum { /* video status flags, based on VIDEO_570 */
2493 TP_ACPI_VIDEO_S_LCD
= 0x01, /* LCD output enabled */
2494 TP_ACPI_VIDEO_S_CRT
= 0x02, /* CRT output enabled */
2495 TP_ACPI_VIDEO_S_DVI
= 0x08, /* DVI output enabled */
2498 enum { /* TPACPI_VIDEO_570 constants */
2499 TP_ACPI_VIDEO_570_PHSCMD
= 0x87, /* unknown magic constant :( */
2500 TP_ACPI_VIDEO_570_PHSMASK
= 0x03, /* PHS bits that map to
2501 * video_status_flags */
2502 TP_ACPI_VIDEO_570_PHS2CMD
= 0x8b, /* unknown magic constant :( */
2503 TP_ACPI_VIDEO_570_PHS2SET
= 0x80, /* unknown magic constant :( */
2506 static enum video_access_mode video_supported
;
2507 static int video_orig_autosw
;
2509 static int video_autosw_get(void);
2510 static int video_autosw_set(int enable
);
2512 TPACPI_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
2513 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
2514 "\\_SB.PCI0.VID0", /* 770e */
2515 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
2516 "\\_SB.PCI0.AGP.VID", /* all others */
2519 TPACPI_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
2521 static int __init
video_init(struct ibm_init_struct
*iibm
)
2525 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
2527 TPACPI_ACPIHANDLE_INIT(vid
);
2528 TPACPI_ACPIHANDLE_INIT(vid2
);
2530 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
2531 /* G41, assume IVGA doesn't change */
2532 vid_handle
= vid2_handle
;
2535 /* video switching not supported on R30, R31 */
2536 video_supported
= TPACPI_VIDEO_NONE
;
2537 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
2539 video_supported
= TPACPI_VIDEO_570
;
2540 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
2541 /* 600e/x, 770e, 770x */
2542 video_supported
= TPACPI_VIDEO_770
;
2545 video_supported
= TPACPI_VIDEO_NEW
;
2547 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
2548 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
2551 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
2554 static void video_exit(void)
2556 dbg_printk(TPACPI_DBG_EXIT
,
2557 "restoring original video autoswitch mode\n");
2558 if (video_autosw_set(video_orig_autosw
))
2559 printk(TPACPI_ERR
"error while trying to restore original "
2560 "video autoswitch mode\n");
2563 static int video_outputsw_get(void)
2568 switch (video_supported
) {
2569 case TPACPI_VIDEO_570
:
2570 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
2571 TP_ACPI_VIDEO_570_PHSCMD
))
2573 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
2575 case TPACPI_VIDEO_770
:
2576 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2579 status
|= TP_ACPI_VIDEO_S_LCD
;
2580 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2583 status
|= TP_ACPI_VIDEO_S_CRT
;
2585 case TPACPI_VIDEO_NEW
:
2586 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
2587 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2590 status
|= TP_ACPI_VIDEO_S_CRT
;
2592 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
2593 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2596 status
|= TP_ACPI_VIDEO_S_LCD
;
2597 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
2600 status
|= TP_ACPI_VIDEO_S_DVI
;
2609 static int video_outputsw_set(int status
)
2614 switch (video_supported
) {
2615 case TPACPI_VIDEO_570
:
2616 res
= acpi_evalf(NULL
, NULL
,
2617 "\\_SB.PHS2", "vdd",
2618 TP_ACPI_VIDEO_570_PHS2CMD
,
2619 status
| TP_ACPI_VIDEO_570_PHS2SET
);
2621 case TPACPI_VIDEO_770
:
2622 autosw
= video_autosw_get();
2626 res
= video_autosw_set(1);
2629 res
= acpi_evalf(vid_handle
, NULL
,
2630 "ASWT", "vdd", status
* 0x100, 0);
2631 if (!autosw
&& video_autosw_set(autosw
)) {
2632 printk(TPACPI_ERR
"video auto-switch left enabled due to error\n");
2636 case TPACPI_VIDEO_NEW
:
2637 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
2638 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
2644 return (res
)? 0 : -EIO
;
2647 static int video_autosw_get(void)
2651 switch (video_supported
) {
2652 case TPACPI_VIDEO_570
:
2653 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
2656 case TPACPI_VIDEO_770
:
2657 case TPACPI_VIDEO_NEW
:
2658 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
2668 static int video_autosw_set(int enable
)
2670 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
2675 static int video_outputsw_cycle(void)
2677 int autosw
= video_autosw_get();
2683 switch (video_supported
) {
2684 case TPACPI_VIDEO_570
:
2685 res
= video_autosw_set(1);
2688 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
2690 case TPACPI_VIDEO_770
:
2691 case TPACPI_VIDEO_NEW
:
2692 res
= video_autosw_set(1);
2695 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
2700 if (!autosw
&& video_autosw_set(autosw
)) {
2701 printk(TPACPI_ERR
"video auto-switch left enabled due to error\n");
2705 return (res
)? 0 : -EIO
;
2708 static int video_expand_toggle(void)
2710 switch (video_supported
) {
2711 case TPACPI_VIDEO_570
:
2712 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
2714 case TPACPI_VIDEO_770
:
2715 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
2717 case TPACPI_VIDEO_NEW
:
2718 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
2726 static int video_read(char *p
)
2731 if (video_supported
== TPACPI_VIDEO_NONE
) {
2732 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2736 status
= video_outputsw_get();
2740 autosw
= video_autosw_get();
2744 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2745 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
2746 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
2747 if (video_supported
== TPACPI_VIDEO_NEW
)
2748 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
2749 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
2750 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
2751 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
2752 if (video_supported
== TPACPI_VIDEO_NEW
)
2753 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
2754 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
2755 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
2760 static int video_write(char *buf
)
2763 int enable
, disable
, status
;
2766 if (video_supported
== TPACPI_VIDEO_NONE
)
2772 while ((cmd
= next_cmd(&buf
))) {
2773 if (strlencmp(cmd
, "lcd_enable") == 0) {
2774 enable
|= TP_ACPI_VIDEO_S_LCD
;
2775 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
2776 disable
|= TP_ACPI_VIDEO_S_LCD
;
2777 } else if (strlencmp(cmd
, "crt_enable") == 0) {
2778 enable
|= TP_ACPI_VIDEO_S_CRT
;
2779 } else if (strlencmp(cmd
, "crt_disable") == 0) {
2780 disable
|= TP_ACPI_VIDEO_S_CRT
;
2781 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2782 strlencmp(cmd
, "dvi_enable") == 0) {
2783 enable
|= TP_ACPI_VIDEO_S_DVI
;
2784 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2785 strlencmp(cmd
, "dvi_disable") == 0) {
2786 disable
|= TP_ACPI_VIDEO_S_DVI
;
2787 } else if (strlencmp(cmd
, "auto_enable") == 0) {
2788 res
= video_autosw_set(1);
2791 } else if (strlencmp(cmd
, "auto_disable") == 0) {
2792 res
= video_autosw_set(0);
2795 } else if (strlencmp(cmd
, "video_switch") == 0) {
2796 res
= video_outputsw_cycle();
2799 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
2800 res
= video_expand_toggle();
2807 if (enable
|| disable
) {
2808 status
= video_outputsw_get();
2811 res
= video_outputsw_set((status
& ~disable
) | enable
);
2819 static struct ibm_struct video_driver_data
= {
2822 .write
= video_write
,
2826 /*************************************************************************
2827 * Light (thinklight) subdriver
2830 TPACPI_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
2831 TPACPI_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
2833 static int __init
light_init(struct ibm_init_struct
*iibm
)
2835 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
2837 TPACPI_ACPIHANDLE_INIT(ledb
);
2838 TPACPI_ACPIHANDLE_INIT(lght
);
2839 TPACPI_ACPIHANDLE_INIT(cmos
);
2841 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
2842 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
2844 if (tp_features
.light
)
2845 /* light status not supported on
2846 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
2847 tp_features
.light_status
=
2848 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
2850 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
2851 str_supported(tp_features
.light
));
2853 return (tp_features
.light
)? 0 : 1;
2856 static int light_read(char *p
)
2861 if (!tp_features
.light
) {
2862 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2863 } else if (!tp_features
.light_status
) {
2864 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
2865 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2867 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
2869 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
2870 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2876 static int light_write(char *buf
)
2878 int cmos_cmd
, lght_cmd
;
2882 if (!tp_features
.light
)
2885 while ((cmd
= next_cmd(&buf
))) {
2886 if (strlencmp(cmd
, "on") == 0) {
2889 } else if (strlencmp(cmd
, "off") == 0) {
2895 success
= cmos_handle
?
2896 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
2897 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
2905 static struct ibm_struct light_driver_data
= {
2908 .write
= light_write
,
2911 /*************************************************************************
2915 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2917 static void dock_notify(struct ibm_struct
*ibm
, u32 event
);
2918 static int dock_read(char *p
);
2919 static int dock_write(char *buf
);
2921 TPACPI_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
2922 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
2923 "\\_SB.PCI0.PCI1.DOCK", /* all others */
2924 "\\_SB.PCI.ISA.SLCE", /* 570 */
2925 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
2927 /* don't list other alternatives as we install a notify handler on the 570 */
2928 TPACPI_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
2930 static const struct acpi_device_id ibm_pci_device_ids
[] = {
2931 {PCI_ROOT_HID_STRING
, 0},
2935 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
2937 .notify
= dock_notify
,
2938 .handle
= &dock_handle
,
2939 .type
= ACPI_SYSTEM_NOTIFY
,
2942 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
2943 * We just use it to get notifications of dock hotplug
2944 * in very old thinkpads */
2945 .hid
= ibm_pci_device_ids
,
2946 .notify
= dock_notify
,
2947 .handle
= &pci_handle
,
2948 .type
= ACPI_SYSTEM_NOTIFY
,
2952 static struct ibm_struct dock_driver_data
[2] = {
2956 .write
= dock_write
,
2957 .acpi
= &ibm_dock_acpidriver
[0],
2961 .acpi
= &ibm_dock_acpidriver
[1],
2965 #define dock_docked() (_sta(dock_handle) & 1)
2967 static int __init
dock_init(struct ibm_init_struct
*iibm
)
2969 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
2971 TPACPI_ACPIHANDLE_INIT(dock
);
2973 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
2974 str_supported(dock_handle
!= NULL
));
2976 return (dock_handle
)? 0 : 1;
2979 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
2983 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
2985 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
2986 dock_driver_data
[0].flags
.acpi_notify_installed
) {
2987 TPACPI_ACPIHANDLE_INIT(pci
);
2988 dock2_needed
= (pci_handle
!= NULL
);
2989 vdbg_printk(TPACPI_DBG_INIT
,
2990 "dock PCI handler for the TP 570 is %s\n",
2991 str_supported(dock2_needed
));
2993 vdbg_printk(TPACPI_DBG_INIT
,
2994 "dock subdriver part 2 not required\n");
2998 return (dock2_needed
)? 0 : 1;
3001 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
3003 int docked
= dock_docked();
3004 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
3005 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
3008 if (event
== 1 && !pci
) /* 570 */
3009 data
= 1; /* button */
3010 else if (event
== 1 && pci
) /* 570 */
3011 data
= 3; /* dock */
3012 else if (event
== 3 && docked
)
3013 data
= 1; /* button */
3014 else if (event
== 3 && !docked
)
3015 data
= 2; /* undock */
3016 else if (event
== 0 && docked
)
3017 data
= 3; /* dock */
3019 printk(TPACPI_ERR
"unknown dock event %d, status %d\n",
3020 event
, _sta(dock_handle
));
3021 data
= 0; /* unknown */
3023 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
3024 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3025 ibm
->acpi
->device
->dev
.bus_id
,
3029 static int dock_read(char *p
)
3032 int docked
= dock_docked();
3035 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3037 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
3039 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
3040 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
3046 static int dock_write(char *buf
)
3053 while ((cmd
= next_cmd(&buf
))) {
3054 if (strlencmp(cmd
, "undock") == 0) {
3055 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
3056 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
3058 } else if (strlencmp(cmd
, "dock") == 0) {
3059 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
3068 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
3070 /*************************************************************************
3074 #ifdef CONFIG_THINKPAD_ACPI_BAY
3076 TPACPI_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
3077 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
3078 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
3079 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
3080 ); /* A21e, R30, R31 */
3081 TPACPI_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
3082 "_EJ0", /* all others */
3083 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
3084 TPACPI_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
3085 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
3087 TPACPI_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
3091 static int __init
bay_init(struct ibm_init_struct
*iibm
)
3093 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
3095 TPACPI_ACPIHANDLE_INIT(bay
);
3097 TPACPI_ACPIHANDLE_INIT(bay_ej
);
3098 TPACPI_ACPIHANDLE_INIT(bay2
);
3100 TPACPI_ACPIHANDLE_INIT(bay2_ej
);
3102 tp_features
.bay_status
= bay_handle
&&
3103 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
3104 tp_features
.bay_status2
= bay2_handle
&&
3105 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
3107 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
3108 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
3109 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
3110 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
3112 vdbg_printk(TPACPI_DBG_INIT
,
3113 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
3114 str_supported(tp_features
.bay_status
),
3115 str_supported(tp_features
.bay_eject
),
3116 str_supported(tp_features
.bay_status2
),
3117 str_supported(tp_features
.bay_eject2
));
3119 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
3120 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
3123 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
3125 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
3126 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
3127 ibm
->acpi
->device
->dev
.bus_id
,
3131 #define bay_occupied(b) (_sta(b##_handle) & 1)
3133 static int bay_read(char *p
)
3136 int occupied
= bay_occupied(bay
);
3137 int occupied2
= bay_occupied(bay2
);
3140 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
3141 tp_features
.bay_status
?
3142 (occupied
? "occupied" : "unoccupied") :
3144 if (tp_features
.bay_status2
)
3145 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
3146 "occupied" : "unoccupied");
3148 eject
= tp_features
.bay_eject
&& occupied
;
3149 eject2
= tp_features
.bay_eject2
&& occupied2
;
3151 if (eject
&& eject2
)
3152 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
3154 len
+= sprintf(p
+ len
, "commands:\teject\n");
3156 len
+= sprintf(p
+ len
, "commands:\teject2\n");
3161 static int bay_write(char *buf
)
3165 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
3168 while ((cmd
= next_cmd(&buf
))) {
3169 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
3170 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
3172 } else if (tp_features
.bay_eject2
&&
3173 strlencmp(cmd
, "eject2") == 0) {
3174 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
3183 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
3184 .notify
= bay_notify
,
3185 .handle
= &bay_handle
,
3186 .type
= ACPI_SYSTEM_NOTIFY
,
3189 static struct ibm_struct bay_driver_data
= {
3193 .acpi
= &ibm_bay_acpidriver
,
3196 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3198 /*************************************************************************
3202 /* sysfs cmos_command -------------------------------------------------- */
3203 static ssize_t
cmos_command_store(struct device
*dev
,
3204 struct device_attribute
*attr
,
3205 const char *buf
, size_t count
)
3207 unsigned long cmos_cmd
;
3210 if (parse_strtoul(buf
, 21, &cmos_cmd
))
3213 res
= issue_thinkpad_cmos_command(cmos_cmd
);
3214 return (res
)? res
: count
;
3217 static struct device_attribute dev_attr_cmos_command
=
3218 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
3220 /* --------------------------------------------------------------------- */
3222 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
3226 vdbg_printk(TPACPI_DBG_INIT
,
3227 "initializing cmos commands subdriver\n");
3229 TPACPI_ACPIHANDLE_INIT(cmos
);
3231 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
3232 str_supported(cmos_handle
!= NULL
));
3234 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
3238 return (cmos_handle
)? 0 : 1;
3241 static void cmos_exit(void)
3243 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
3246 static int cmos_read(char *p
)
3250 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
3251 R30, R31, T20-22, X20-21 */
3253 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3255 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3256 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
3262 static int cmos_write(char *buf
)
3267 while ((cmd
= next_cmd(&buf
))) {
3268 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
3269 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
3274 res
= issue_thinkpad_cmos_command(cmos_cmd
);
3282 static struct ibm_struct cmos_driver_data
= {
3285 .write
= cmos_write
,
3289 /*************************************************************************
3293 enum led_access_mode
{
3294 TPACPI_LED_NONE
= 0,
3295 TPACPI_LED_570
, /* 570 */
3296 TPACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3297 TPACPI_LED_NEW
, /* all others */
3300 enum { /* For TPACPI_LED_OLD */
3301 TPACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
3302 TPACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
3303 TPACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
3306 static enum led_access_mode led_supported
;
3308 TPACPI_HANDLE(led
, ec
, "SLED", /* 570 */
3309 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3310 "LED", /* all others */
3313 static int __init
led_init(struct ibm_init_struct
*iibm
)
3315 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
3317 TPACPI_ACPIHANDLE_INIT(led
);
3320 /* led not supported on R30, R31 */
3321 led_supported
= TPACPI_LED_NONE
;
3322 else if (strlencmp(led_path
, "SLED") == 0)
3324 led_supported
= TPACPI_LED_570
;
3325 else if (strlencmp(led_path
, "SYSL") == 0)
3326 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3327 led_supported
= TPACPI_LED_OLD
;
3330 led_supported
= TPACPI_LED_NEW
;
3332 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
3333 str_supported(led_supported
), led_supported
);
3335 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
3338 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
3340 static int led_read(char *p
)
3344 if (!led_supported
) {
3345 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3348 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3350 if (led_supported
== TPACPI_LED_570
) {
3353 for (i
= 0; i
< 8; i
++) {
3354 if (!acpi_evalf(ec_handle
,
3355 &status
, "GLED", "dd", 1 << i
))
3357 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
3358 i
, led_status(status
));
3362 len
+= sprintf(p
+ len
, "commands:\t"
3363 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
3368 /* off, on, blink */
3369 static const int led_sled_arg1
[] = { 0, 1, 3 };
3370 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
3371 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
3372 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
3374 static int led_write(char *buf
)
3382 while ((cmd
= next_cmd(&buf
))) {
3383 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
3386 if (strstr(cmd
, "off")) {
3388 } else if (strstr(cmd
, "on")) {
3390 } else if (strstr(cmd
, "blink")) {
3395 if (led_supported
== TPACPI_LED_570
) {
3398 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
3399 led
, led_sled_arg1
[ind
]))
3401 } else if (led_supported
== TPACPI_LED_OLD
) {
3402 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
3404 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
3407 ec_write(TPACPI_LED_EC_HLBL
,
3408 led
* led_exp_hlbl
[ind
]);
3411 ec_write(TPACPI_LED_EC_HLCL
,
3412 led
* led_exp_hlcl
[ind
]);
3417 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
3418 led
, led_led_arg1
[ind
]))
3426 static struct ibm_struct led_driver_data
= {
3432 /*************************************************************************
3436 TPACPI_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
3438 static int __init
beep_init(struct ibm_init_struct
*iibm
)
3440 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
3442 TPACPI_ACPIHANDLE_INIT(beep
);
3444 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
3445 str_supported(beep_handle
!= NULL
));
3447 return (beep_handle
)? 0 : 1;
3450 static int beep_read(char *p
)
3455 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3457 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3458 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
3464 static int beep_write(char *buf
)
3472 while ((cmd
= next_cmd(&buf
))) {
3473 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
3474 beep_cmd
>= 0 && beep_cmd
<= 17) {
3478 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
3485 static struct ibm_struct beep_driver_data
= {
3488 .write
= beep_write
,
3491 /*************************************************************************
3495 enum thermal_access_mode
{
3496 TPACPI_THERMAL_NONE
= 0, /* No thermal support */
3497 TPACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
3498 TPACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
3499 TPACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
3500 TPACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
3503 enum { /* TPACPI_THERMAL_TPEC_* */
3504 TP_EC_THERMAL_TMP0
= 0x78, /* ACPI EC regs TMP 0..7 */
3505 TP_EC_THERMAL_TMP8
= 0xC0, /* ACPI EC regs TMP 8..15 */
3506 TP_EC_THERMAL_TMP_NA
= -128, /* ACPI EC sensor not available */
3509 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
3510 struct ibm_thermal_sensors_struct
{
3511 s32 temp
[TPACPI_MAX_THERMAL_SENSORS
];
3514 static enum thermal_access_mode thermal_read_mode
;
3516 /* idx is zero-based */
3517 static int thermal_get_sensor(int idx
, s32
*value
)
3523 t
= TP_EC_THERMAL_TMP0
;
3525 switch (thermal_read_mode
) {
3526 #if TPACPI_MAX_THERMAL_SENSORS >= 16
3527 case TPACPI_THERMAL_TPEC_16
:
3528 if (idx
>= 8 && idx
<= 15) {
3529 t
= TP_EC_THERMAL_TMP8
;
3534 case TPACPI_THERMAL_TPEC_8
:
3536 if (!acpi_ec_read(t
+ idx
, &tmp
))
3538 *value
= tmp
* 1000;
3543 case TPACPI_THERMAL_ACPI_UPDT
:
3545 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3546 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
3548 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3550 *value
= (t
- 2732) * 100;
3555 case TPACPI_THERMAL_ACPI_TMP07
:
3557 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3558 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3560 if (t
> 127 || t
< -127)
3561 t
= TP_EC_THERMAL_TMP_NA
;
3567 case TPACPI_THERMAL_NONE
:
3575 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
3586 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
3589 for(i
= 0 ; i
< n
; i
++) {
3590 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
3598 /* sysfs temp##_input -------------------------------------------------- */
3600 static ssize_t
thermal_temp_input_show(struct device
*dev
,
3601 struct device_attribute
*attr
,
3604 struct sensor_device_attribute
*sensor_attr
=
3605 to_sensor_dev_attr(attr
);
3606 int idx
= sensor_attr
->index
;
3610 res
= thermal_get_sensor(idx
, &value
);
3613 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
3616 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
3619 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
3620 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
3622 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
3623 THERMAL_SENSOR_ATTR_TEMP(1, 0),
3624 THERMAL_SENSOR_ATTR_TEMP(2, 1),
3625 THERMAL_SENSOR_ATTR_TEMP(3, 2),
3626 THERMAL_SENSOR_ATTR_TEMP(4, 3),
3627 THERMAL_SENSOR_ATTR_TEMP(5, 4),
3628 THERMAL_SENSOR_ATTR_TEMP(6, 5),
3629 THERMAL_SENSOR_ATTR_TEMP(7, 6),
3630 THERMAL_SENSOR_ATTR_TEMP(8, 7),
3631 THERMAL_SENSOR_ATTR_TEMP(9, 8),
3632 THERMAL_SENSOR_ATTR_TEMP(10, 9),
3633 THERMAL_SENSOR_ATTR_TEMP(11, 10),
3634 THERMAL_SENSOR_ATTR_TEMP(12, 11),
3635 THERMAL_SENSOR_ATTR_TEMP(13, 12),
3636 THERMAL_SENSOR_ATTR_TEMP(14, 13),
3637 THERMAL_SENSOR_ATTR_TEMP(15, 14),
3638 THERMAL_SENSOR_ATTR_TEMP(16, 15),
3641 #define THERMAL_ATTRS(X) \
3642 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
3644 static struct attribute
*thermal_temp_input_attr
[] = {
3664 static const struct attribute_group thermal_temp_input16_group
= {
3665 .attrs
= thermal_temp_input_attr
3668 static const struct attribute_group thermal_temp_input8_group
= {
3669 .attrs
= &thermal_temp_input_attr
[8]
3672 #undef THERMAL_SENSOR_ATTR_TEMP
3673 #undef THERMAL_ATTRS
3675 /* --------------------------------------------------------------------- */
3677 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
3684 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
3686 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
3688 if (thinkpad_id
.ec_model
) {
3690 * Direct EC access mode: sensors at registers
3691 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
3692 * non-implemented, thermal sensors return 0x80 when
3697 for (i
= 0; i
< 8; i
++) {
3698 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
3704 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
3712 /* This is sheer paranoia, but we handle it anyway */
3715 "ThinkPad ACPI EC access misbehaving, "
3716 "falling back to ACPI TMPx access mode\n");
3717 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
3720 "ThinkPad ACPI EC access misbehaving, "
3721 "disabling thermal sensors access\n");
3722 thermal_read_mode
= TPACPI_THERMAL_NONE
;
3727 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
3729 } else if (acpi_tmp7
) {
3730 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
3731 /* 600e/x, 770e, 770x */
3732 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
3734 /* Standard ACPI TMPx access, max 8 sensors */
3735 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
3738 /* temperatures not supported on 570, G4x, R30, R31, R32 */
3739 thermal_read_mode
= TPACPI_THERMAL_NONE
;
3742 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
3743 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
3746 switch(thermal_read_mode
) {
3747 case TPACPI_THERMAL_TPEC_16
:
3748 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3749 &thermal_temp_input16_group
);
3753 case TPACPI_THERMAL_TPEC_8
:
3754 case TPACPI_THERMAL_ACPI_TMP07
:
3755 case TPACPI_THERMAL_ACPI_UPDT
:
3756 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3757 &thermal_temp_input8_group
);
3761 case TPACPI_THERMAL_NONE
:
3769 static void thermal_exit(void)
3771 switch(thermal_read_mode
) {
3772 case TPACPI_THERMAL_TPEC_16
:
3773 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3774 &thermal_temp_input16_group
);
3776 case TPACPI_THERMAL_TPEC_8
:
3777 case TPACPI_THERMAL_ACPI_TMP07
:
3778 case TPACPI_THERMAL_ACPI_UPDT
:
3779 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3780 &thermal_temp_input16_group
);
3782 case TPACPI_THERMAL_NONE
:
3788 static int thermal_read(char *p
)
3792 struct ibm_thermal_sensors_struct t
;
3794 n
= thermal_get_sensors(&t
);
3795 if (unlikely(n
< 0))
3798 len
+= sprintf(p
+ len
, "temperatures:\t");
3801 for (i
= 0; i
< (n
- 1); i
++)
3802 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
3803 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
3805 len
+= sprintf(p
+ len
, "not supported\n");
3810 static struct ibm_struct thermal_driver_data
= {
3812 .read
= thermal_read
,
3813 .exit
= thermal_exit
,
3816 /*************************************************************************
3820 static u8 ecdump_regs
[256];
3822 static int ecdump_read(char *p
)
3828 len
+= sprintf(p
+ len
, "EC "
3829 " +00 +01 +02 +03 +04 +05 +06 +07"
3830 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
3831 for (i
= 0; i
< 256; i
+= 16) {
3832 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
3833 for (j
= 0; j
< 16; j
++) {
3834 if (!acpi_ec_read(i
+ j
, &v
))
3836 if (v
!= ecdump_regs
[i
+ j
])
3837 len
+= sprintf(p
+ len
, " *%02x", v
);
3839 len
+= sprintf(p
+ len
, " %02x", v
);
3840 ecdump_regs
[i
+ j
] = v
;
3842 len
+= sprintf(p
+ len
, "\n");
3847 /* These are way too dangerous to advertise openly... */
3849 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
3850 " (<offset> is 00-ff, <value> is 00-ff)\n");
3851 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
3852 " (<offset> is 00-ff, <value> is 0-255)\n");
3857 static int ecdump_write(char *buf
)
3862 while ((cmd
= next_cmd(&buf
))) {
3863 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
3865 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
3869 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
3870 if (!acpi_ec_write(i
, v
))
3879 static struct ibm_struct ecdump_driver_data
= {
3881 .read
= ecdump_read
,
3882 .write
= ecdump_write
,
3883 .flags
.experimental
= 1,
3886 /*************************************************************************
3887 * Backlight/brightness subdriver
3890 #define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
3892 static struct backlight_device
*ibm_backlight_device
;
3893 static int brightness_offset
= 0x31;
3894 static int brightness_mode
;
3895 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
3897 static struct mutex brightness_mutex
;
3900 * ThinkPads can read brightness from two places: EC 0x31, or
3901 * CMOS NVRAM byte 0x5E, bits 0-3.
3903 static int brightness_get(struct backlight_device
*bd
)
3905 u8 lec
= 0, lcmos
= 0, level
= 0;
3907 if (brightness_mode
& 1) {
3908 if (!acpi_ec_read(brightness_offset
, &lec
))
3910 lec
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
3913 if (brightness_mode
& 2) {
3914 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
3915 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
3916 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
3917 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
3921 if (brightness_mode
== 3 && lec
!= lcmos
) {
3923 "CMOS NVRAM (%u) and EC (%u) do not agree "
3924 "on display brightness level\n",
3925 (unsigned int) lcmos
,
3926 (unsigned int) lec
);
3933 /* May return EINTR which can always be mapped to ERESTARTSYS */
3934 static int brightness_set(int value
)
3936 int cmos_cmd
, inc
, i
, res
;
3939 if (value
> ((tp_features
.bright_16levels
)? 15 : 7))
3942 res
= mutex_lock_interruptible(&brightness_mutex
);
3946 current_value
= brightness_get(NULL
);
3947 if (current_value
< 0) {
3948 res
= current_value
;
3952 cmos_cmd
= value
> current_value
?
3953 TP_CMOS_BRIGHTNESS_UP
:
3954 TP_CMOS_BRIGHTNESS_DOWN
;
3955 inc
= (value
> current_value
)? 1 : -1;
3958 for (i
= current_value
; i
!= value
; i
+= inc
) {
3959 if ((brightness_mode
& 2) &&
3960 issue_thinkpad_cmos_command(cmos_cmd
)) {
3964 if ((brightness_mode
& 1) &&
3965 !acpi_ec_write(brightness_offset
, i
+ inc
)) {
3972 mutex_unlock(&brightness_mutex
);
3976 /* sysfs backlight class ----------------------------------------------- */
3978 static int brightness_update_status(struct backlight_device
*bd
)
3980 /* it is the backlight class's job (caller) to handle
3981 * EINTR and other errors properly */
3982 return brightness_set(
3983 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
3984 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
3985 bd
->props
.brightness
: 0);
3988 static struct backlight_ops ibm_backlight_data
= {
3989 .get_brightness
= brightness_get
,
3990 .update_status
= brightness_update_status
,
3993 /* --------------------------------------------------------------------- */
3995 static int __init
tpacpi_query_bcll_levels(acpi_handle handle
)
3997 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
3998 union acpi_object
*obj
;
4001 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
4002 obj
= (union acpi_object
*)buffer
.pointer
;
4003 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
4004 printk(TPACPI_ERR
"Unknown BCLL data, "
4005 "please report this to %s\n", TPACPI_MAIL
);
4008 rc
= obj
->package
.count
;
4014 kfree(buffer
.pointer
);
4018 static acpi_status __init
brightness_find_bcll(acpi_handle handle
, u32 lvl
,
4019 void *context
, void **rv
)
4021 char name
[ACPI_PATH_SEGMENT_LENGTH
];
4022 struct acpi_buffer buffer
= { sizeof(name
), &name
};
4024 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
4025 !strncmp("BCLL", name
, sizeof(name
) - 1)) {
4026 if (tpacpi_query_bcll_levels(handle
) == 16) {
4028 return AE_CTRL_TERMINATE
;
4037 static int __init
brightness_check_levels(void)
4040 void *found_node
= NULL
;
4043 TPACPI_ACPIHANDLE_INIT(vid
);
4048 /* Search for a BCLL package with 16 levels */
4049 status
= acpi_walk_namespace(ACPI_TYPE_PACKAGE
, vid_handle
, 3,
4050 brightness_find_bcll
, NULL
, &found_node
);
4052 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
4055 static acpi_status __init
brightness_find_bcl(acpi_handle handle
, u32 lvl
,
4056 void *context
, void **rv
)
4058 char name
[ACPI_PATH_SEGMENT_LENGTH
];
4059 struct acpi_buffer buffer
= { sizeof(name
), &name
};
4061 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
4062 !strncmp("_BCL", name
, sizeof(name
) - 1)) {
4064 return AE_CTRL_TERMINATE
;
4070 static int __init
brightness_check_std_acpi_support(void)
4073 void *found_node
= NULL
;
4076 TPACPI_ACPIHANDLE_INIT(vid
);
4081 /* Search for a _BCL method, but don't execute it */
4082 status
= acpi_walk_namespace(ACPI_TYPE_METHOD
, vid_handle
, 3,
4083 brightness_find_bcl
, NULL
, &found_node
);
4085 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
4088 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
4092 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
4094 mutex_init(&brightness_mutex
);
4096 if (!brightness_enable
) {
4097 dbg_printk(TPACPI_DBG_INIT
,
4098 "brightness support disabled by module parameter\n");
4100 } else if (brightness_enable
> 1) {
4101 if (brightness_check_std_acpi_support()) {
4102 printk(TPACPI_NOTICE
4103 "standard ACPI backlight interface available, not loading native one...\n");
4108 if (!brightness_mode
) {
4109 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
4110 brightness_mode
= 2;
4112 brightness_mode
= 3;
4114 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
4118 if (brightness_mode
> 3)
4121 tp_features
.bright_16levels
=
4122 thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
&&
4123 brightness_check_levels();
4125 b
= brightness_get(NULL
);
4129 if (tp_features
.bright_16levels
)
4130 printk(TPACPI_INFO
"detected a 16-level brightness capable ThinkPad\n");
4132 ibm_backlight_device
= backlight_device_register(
4133 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
4134 &ibm_backlight_data
);
4135 if (IS_ERR(ibm_backlight_device
)) {
4136 printk(TPACPI_ERR
"Could not register backlight device\n");
4137 return PTR_ERR(ibm_backlight_device
);
4139 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
4141 ibm_backlight_device
->props
.max_brightness
=
4142 (tp_features
.bright_16levels
)? 15 : 7;
4143 ibm_backlight_device
->props
.brightness
= b
;
4144 backlight_update_status(ibm_backlight_device
);
4149 static void brightness_exit(void)
4151 if (ibm_backlight_device
) {
4152 vdbg_printk(TPACPI_DBG_EXIT
,
4153 "calling backlight_device_unregister()\n");
4154 backlight_device_unregister(ibm_backlight_device
);
4155 ibm_backlight_device
= NULL
;
4159 static int brightness_read(char *p
)
4164 if ((level
= brightness_get(NULL
)) < 0) {
4165 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
4167 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
4168 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
4169 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
4170 " (<level> is 0-%d)\n",
4171 (tp_features
.bright_16levels
) ? 15 : 7);
4177 static int brightness_write(char *buf
)
4182 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
4184 level
= brightness_get(NULL
);
4188 while ((cmd
= next_cmd(&buf
))) {
4189 if (strlencmp(cmd
, "up") == 0) {
4190 if (level
< max_level
)
4192 } else if (strlencmp(cmd
, "down") == 0) {
4195 } else if (sscanf(cmd
, "level %d", &level
) == 1 &&
4196 level
>= 0 && level
<= max_level
) {
4203 * Now we know what the final level should be, so we try to set it.
4204 * Doing it this way makes the syscall restartable in case of EINTR
4206 rc
= brightness_set(level
);
4207 return (rc
== -EINTR
)? ERESTARTSYS
: rc
;
4210 static struct ibm_struct brightness_driver_data
= {
4211 .name
= "brightness",
4212 .read
= brightness_read
,
4213 .write
= brightness_write
,
4214 .exit
= brightness_exit
,
4217 /*************************************************************************
4221 static int volume_offset
= 0x30;
4223 static int volume_read(char *p
)
4228 if (!acpi_ec_read(volume_offset
, &level
)) {
4229 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
4231 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
4232 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
4233 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
4234 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
4235 " (<level> is 0-15)\n");
4241 static int volume_write(char *buf
)
4243 int cmos_cmd
, inc
, i
;
4245 int new_level
, new_mute
;
4248 while ((cmd
= next_cmd(&buf
))) {
4249 if (!acpi_ec_read(volume_offset
, &level
))
4251 new_mute
= mute
= level
& 0x40;
4252 new_level
= level
= level
& 0xf;
4254 if (strlencmp(cmd
, "up") == 0) {
4258 new_level
= level
== 15 ? 15 : level
+ 1;
4259 } else if (strlencmp(cmd
, "down") == 0) {
4263 new_level
= level
== 0 ? 0 : level
- 1;
4264 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
4265 new_level
>= 0 && new_level
<= 15) {
4267 } else if (strlencmp(cmd
, "mute") == 0) {
4272 if (new_level
!= level
) { /* mute doesn't change */
4273 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
4274 inc
= new_level
> level
? 1 : -1;
4276 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
4277 !acpi_ec_write(volume_offset
, level
)))
4280 for (i
= level
; i
!= new_level
; i
+= inc
)
4281 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
4282 !acpi_ec_write(volume_offset
, i
+ inc
))
4285 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
4286 !acpi_ec_write(volume_offset
,
4291 if (new_mute
!= mute
) { /* level doesn't change */
4292 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
4294 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
4295 !acpi_ec_write(volume_offset
, level
+ new_mute
))
4303 static struct ibm_struct volume_driver_data
= {
4305 .read
= volume_read
,
4306 .write
= volume_write
,
4309 /*************************************************************************
4316 * TPACPI_FAN_RD_ACPI_GFAN:
4317 * ACPI GFAN method: returns fan level
4319 * see TPACPI_FAN_WR_ACPI_SFAN
4320 * EC 0x2f (HFSP) not available if GFAN exists
4322 * TPACPI_FAN_WR_ACPI_SFAN:
4323 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
4325 * EC 0x2f (HFSP) might be available *for reading*, but do not use
4328 * TPACPI_FAN_WR_TPEC:
4329 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
4330 * Supported on almost all ThinkPads
4332 * Fan speed changes of any sort (including those caused by the
4333 * disengaged mode) are usually done slowly by the firmware as the
4334 * maximum ammount of fan duty cycle change per second seems to be
4337 * Reading is not available if GFAN exists.
4338 * Writing is not available if SFAN exists.
4341 * 7 automatic mode engaged;
4342 * (default operation mode of the ThinkPad)
4343 * fan level is ignored in this mode.
4344 * 6 full speed mode (takes precedence over bit 7);
4345 * not available on all thinkpads. May disable
4346 * the tachometer while the fan controller ramps up
4347 * the speed (which can take up to a few *minutes*).
4348 * Speeds up fan to 100% duty-cycle, which is far above
4349 * the standard RPM levels. It is not impossible that
4350 * it could cause hardware damage.
4351 * 5-3 unused in some models. Extra bits for fan level
4352 * in others, but still useless as all values above
4353 * 7 map to the same speed as level 7 in these models.
4354 * 2-0 fan level (0..7 usually)
4356 * 0x07 = max (set when temperatures critical)
4357 * Some ThinkPads may have other levels, see
4358 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
4360 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
4361 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
4362 * does so, its initial value is meaningless (0x07).
4364 * For firmware bugs, refer to:
4365 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
4369 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
4370 * Main fan tachometer reading (in RPM)
4372 * This register is present on all ThinkPads with a new-style EC, and
4373 * it is known not to be present on the A21m/e, and T22, as there is
4374 * something else in offset 0x84 according to the ACPI DSDT. Other
4375 * ThinkPads from this same time period (and earlier) probably lack the
4376 * tachometer as well.
4378 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
4379 * was never fixed by IBM to report the EC firmware version string
4380 * probably support the tachometer (like the early X models), so
4381 * detecting it is quite hard. We need more data to know for sure.
4383 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
4386 * FIRMWARE BUG: may go stale while the EC is switching to full speed
4389 * For firmware bugs, refer to:
4390 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
4392 * TPACPI_FAN_WR_ACPI_FANS:
4393 * ThinkPad X31, X40, X41. Not available in the X60.
4395 * FANS ACPI handle: takes three arguments: low speed, medium speed,
4396 * high speed. ACPI DSDT seems to map these three speeds to levels
4397 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
4398 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
4400 * The speeds are stored on handles
4401 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
4403 * There are three default speed sets, acessible as handles:
4404 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
4406 * ACPI DSDT switches which set is in use depending on various
4409 * TPACPI_FAN_WR_TPEC is also available and should be used to
4410 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
4411 * but the ACPI tables just mention level 7.
4414 enum { /* Fan control constants */
4415 fan_status_offset
= 0x2f, /* EC register 0x2f */
4416 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
4417 * 0x84 must be read before 0x85 */
4419 TP_EC_FAN_FULLSPEED
= 0x40, /* EC fan mode: full speed */
4420 TP_EC_FAN_AUTO
= 0x80, /* EC fan mode: auto fan control */
4422 TPACPI_FAN_LAST_LEVEL
= 0x100, /* Use cached last-seen fan level */
4425 enum fan_status_access_mode
{
4426 TPACPI_FAN_NONE
= 0, /* No fan status or control */
4427 TPACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
4428 TPACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
4431 enum fan_control_access_mode
{
4432 TPACPI_FAN_WR_NONE
= 0, /* No fan control */
4433 TPACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
4434 TPACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
4435 TPACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
4438 enum fan_control_commands
{
4439 TPACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
4440 TPACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
4441 TPACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
4442 * and also watchdog cmd */
4445 static int fan_control_allowed
;
4447 static enum fan_status_access_mode fan_status_access_mode
;
4448 static enum fan_control_access_mode fan_control_access_mode
;
4449 static enum fan_control_commands fan_control_commands
;
4451 static u8 fan_control_initial_status
;
4452 static u8 fan_control_desired_level
;
4453 static int fan_watchdog_maxinterval
;
4455 static struct mutex fan_mutex
;
4457 static void fan_watchdog_fire(struct work_struct
*ignored
);
4458 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
4460 TPACPI_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
4461 TPACPI_HANDLE(gfan
, ec
, "GFAN", /* 570 */
4462 "\\FSPD", /* 600e/x, 770e, 770x */
4464 TPACPI_HANDLE(sfan
, ec
, "SFAN", /* 570 */
4465 "JFNS", /* 770x-JL */
4469 * Call with fan_mutex held
4471 static void fan_update_desired_level(u8 status
)
4474 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
4476 fan_control_desired_level
= 7;
4478 fan_control_desired_level
= status
;
4482 static int fan_get_status(u8
*status
)
4487 * Add TPACPI_FAN_RD_ACPI_FANS ? */
4489 switch (fan_status_access_mode
) {
4490 case TPACPI_FAN_RD_ACPI_GFAN
:
4491 /* 570, 600e/x, 770e, 770x */
4493 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
4501 case TPACPI_FAN_RD_TPEC
:
4502 /* all except 570, 600e/x, 770e, 770x */
4503 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
4518 static int fan_get_status_safe(u8
*status
)
4523 if (mutex_lock_interruptible(&fan_mutex
))
4524 return -ERESTARTSYS
;
4525 rc
= fan_get_status(&s
);
4527 fan_update_desired_level(s
);
4528 mutex_unlock(&fan_mutex
);
4536 static int fan_get_speed(unsigned int *speed
)
4540 switch (fan_status_access_mode
) {
4541 case TPACPI_FAN_RD_TPEC
:
4542 /* all except 570, 600e/x, 770e, 770x */
4543 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
4544 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
4548 *speed
= (hi
<< 8) | lo
;
4559 static int fan_set_level(int level
)
4561 if (!fan_control_allowed
)
4564 switch (fan_control_access_mode
) {
4565 case TPACPI_FAN_WR_ACPI_SFAN
:
4566 if (level
>= 0 && level
<= 7) {
4567 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
4573 case TPACPI_FAN_WR_ACPI_FANS
:
4574 case TPACPI_FAN_WR_TPEC
:
4575 if ((level
!= TP_EC_FAN_AUTO
) &&
4576 (level
!= TP_EC_FAN_FULLSPEED
) &&
4577 ((level
< 0) || (level
> 7)))
4580 /* safety net should the EC not support AUTO
4581 * or FULLSPEED mode bits and just ignore them */
4582 if (level
& TP_EC_FAN_FULLSPEED
)
4583 level
|= 7; /* safety min speed 7 */
4584 else if (level
& TP_EC_FAN_FULLSPEED
)
4585 level
|= 4; /* safety min speed 4 */
4587 if (!acpi_ec_write(fan_status_offset
, level
))
4590 tp_features
.fan_ctrl_status_undef
= 0;
4599 static int fan_set_level_safe(int level
)
4603 if (!fan_control_allowed
)
4606 if (mutex_lock_interruptible(&fan_mutex
))
4607 return -ERESTARTSYS
;
4609 if (level
== TPACPI_FAN_LAST_LEVEL
)
4610 level
= fan_control_desired_level
;
4612 rc
= fan_set_level(level
);
4614 fan_update_desired_level(level
);
4616 mutex_unlock(&fan_mutex
);
4620 static int fan_set_enable(void)
4625 if (!fan_control_allowed
)
4628 if (mutex_lock_interruptible(&fan_mutex
))
4629 return -ERESTARTSYS
;
4631 switch (fan_control_access_mode
) {
4632 case TPACPI_FAN_WR_ACPI_FANS
:
4633 case TPACPI_FAN_WR_TPEC
:
4634 rc
= fan_get_status(&s
);
4638 /* Don't go out of emergency fan mode */
4641 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
4644 if (!acpi_ec_write(fan_status_offset
, s
))
4647 tp_features
.fan_ctrl_status_undef
= 0;
4652 case TPACPI_FAN_WR_ACPI_SFAN
:
4653 rc
= fan_get_status(&s
);
4659 /* Set fan to at least level 4 */
4662 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
4672 mutex_unlock(&fan_mutex
);
4676 static int fan_set_disable(void)
4680 if (!fan_control_allowed
)
4683 if (mutex_lock_interruptible(&fan_mutex
))
4684 return -ERESTARTSYS
;
4687 switch (fan_control_access_mode
) {
4688 case TPACPI_FAN_WR_ACPI_FANS
:
4689 case TPACPI_FAN_WR_TPEC
:
4690 if (!acpi_ec_write(fan_status_offset
, 0x00))
4693 fan_control_desired_level
= 0;
4694 tp_features
.fan_ctrl_status_undef
= 0;
4698 case TPACPI_FAN_WR_ACPI_SFAN
:
4699 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
4702 fan_control_desired_level
= 0;
4710 mutex_unlock(&fan_mutex
);
4714 static int fan_set_speed(int speed
)
4718 if (!fan_control_allowed
)
4721 if (mutex_lock_interruptible(&fan_mutex
))
4722 return -ERESTARTSYS
;
4725 switch (fan_control_access_mode
) {
4726 case TPACPI_FAN_WR_ACPI_FANS
:
4727 if (speed
>= 0 && speed
<= 65535) {
4728 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
4729 speed
, speed
, speed
))
4739 mutex_unlock(&fan_mutex
);
4743 static void fan_watchdog_reset(void)
4745 static int fan_watchdog_active
;
4747 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
4750 if (fan_watchdog_active
)
4751 cancel_delayed_work(&fan_watchdog_task
);
4753 if (fan_watchdog_maxinterval
> 0 &&
4754 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
4755 fan_watchdog_active
= 1;
4756 if (!schedule_delayed_work(&fan_watchdog_task
,
4757 msecs_to_jiffies(fan_watchdog_maxinterval
4759 printk(TPACPI_ERR
"failed to schedule the fan watchdog, "
4760 "watchdog will not trigger\n");
4763 fan_watchdog_active
= 0;
4766 static void fan_watchdog_fire(struct work_struct
*ignored
)
4770 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
4773 printk(TPACPI_NOTICE
"fan watchdog: enabling fan\n");
4774 rc
= fan_set_enable();
4776 printk(TPACPI_ERR
"fan watchdog: error %d while enabling fan, "
4777 "will try again later...\n", -rc
);
4778 /* reschedule for later */
4779 fan_watchdog_reset();
4784 * SYSFS fan layout: hwmon compatible (device)
4787 * 0: "disengaged" mode
4789 * 2: native EC "auto" mode (recommended, hardware default)
4791 * pwm*: set speed in manual mode, ignored otherwise.
4792 * 0 is level 0; 255 is level 7. Intermediate points done with linear
4795 * fan*_input: tachometer reading, RPM
4798 * SYSFS fan layout: extensions
4800 * fan_watchdog (driver):
4801 * fan watchdog interval in seconds, 0 disables (default), max 120
4804 /* sysfs fan pwm1_enable ----------------------------------------------- */
4805 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
4806 struct device_attribute
*attr
,
4812 res
= fan_get_status_safe(&status
);
4816 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4817 if (status
!= fan_control_initial_status
) {
4818 tp_features
.fan_ctrl_status_undef
= 0;
4820 /* Return most likely status. In fact, it
4821 * might be the only possible status */
4822 status
= TP_EC_FAN_AUTO
;
4826 if (status
& TP_EC_FAN_FULLSPEED
) {
4828 } else if (status
& TP_EC_FAN_AUTO
) {
4833 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
4836 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
4837 struct device_attribute
*attr
,
4838 const char *buf
, size_t count
)
4843 if (parse_strtoul(buf
, 2, &t
))
4848 level
= TP_EC_FAN_FULLSPEED
;
4851 level
= TPACPI_FAN_LAST_LEVEL
;
4854 level
= TP_EC_FAN_AUTO
;
4857 /* reserved for software-controlled auto mode */
4863 res
= fan_set_level_safe(level
);
4869 fan_watchdog_reset();
4874 static struct device_attribute dev_attr_fan_pwm1_enable
=
4875 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
4876 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
4878 /* sysfs fan pwm1 ------------------------------------------------------ */
4879 static ssize_t
fan_pwm1_show(struct device
*dev
,
4880 struct device_attribute
*attr
,
4886 res
= fan_get_status_safe(&status
);
4890 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4891 if (status
!= fan_control_initial_status
) {
4892 tp_features
.fan_ctrl_status_undef
= 0;
4894 status
= TP_EC_FAN_AUTO
;
4899 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
4900 status
= fan_control_desired_level
;
4905 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
4908 static ssize_t
fan_pwm1_store(struct device
*dev
,
4909 struct device_attribute
*attr
,
4910 const char *buf
, size_t count
)
4914 u8 status
, newlevel
;
4916 if (parse_strtoul(buf
, 255, &s
))
4919 /* scale down from 0-255 to 0-7 */
4920 newlevel
= (s
>> 5) & 0x07;
4922 if (mutex_lock_interruptible(&fan_mutex
))
4923 return -ERESTARTSYS
;
4925 rc
= fan_get_status(&status
);
4926 if (!rc
&& (status
&
4927 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
4928 rc
= fan_set_level(newlevel
);
4932 fan_update_desired_level(newlevel
);
4933 fan_watchdog_reset();
4937 mutex_unlock(&fan_mutex
);
4938 return (rc
)? rc
: count
;
4941 static struct device_attribute dev_attr_fan_pwm1
=
4942 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
4943 fan_pwm1_show
, fan_pwm1_store
);
4945 /* sysfs fan fan1_input ------------------------------------------------ */
4946 static ssize_t
fan_fan1_input_show(struct device
*dev
,
4947 struct device_attribute
*attr
,
4953 res
= fan_get_speed(&speed
);
4957 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
4960 static struct device_attribute dev_attr_fan_fan1_input
=
4961 __ATTR(fan1_input
, S_IRUGO
,
4962 fan_fan1_input_show
, NULL
);
4964 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
4965 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
4968 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
4971 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
4972 const char *buf
, size_t count
)
4976 if (parse_strtoul(buf
, 120, &t
))
4979 if (!fan_control_allowed
)
4982 fan_watchdog_maxinterval
= t
;
4983 fan_watchdog_reset();
4988 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
4989 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
4991 /* --------------------------------------------------------------------- */
4992 static struct attribute
*fan_attributes
[] = {
4993 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
4994 &dev_attr_fan_fan1_input
.attr
,
4998 static const struct attribute_group fan_attr_group
= {
4999 .attrs
= fan_attributes
,
5002 static int __init
fan_init(struct ibm_init_struct
*iibm
)
5006 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
5008 mutex_init(&fan_mutex
);
5009 fan_status_access_mode
= TPACPI_FAN_NONE
;
5010 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
5011 fan_control_commands
= 0;
5012 fan_watchdog_maxinterval
= 0;
5013 tp_features
.fan_ctrl_status_undef
= 0;
5014 fan_control_desired_level
= 7;
5016 TPACPI_ACPIHANDLE_INIT(fans
);
5017 TPACPI_ACPIHANDLE_INIT(gfan
);
5018 TPACPI_ACPIHANDLE_INIT(sfan
);
5021 /* 570, 600e/x, 770e, 770x */
5022 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
5024 /* all other ThinkPads: note that even old-style
5025 * ThinkPad ECs supports the fan control register */
5026 if (likely(acpi_ec_read(fan_status_offset
,
5027 &fan_control_initial_status
))) {
5028 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
5030 /* In some ThinkPads, neither the EC nor the ACPI
5031 * DSDT initialize the fan status, and it ends up
5032 * being set to 0x07 when it *could* be either
5035 * Enable for TP-1Y (T43), TP-78 (R51e),
5036 * TP-76 (R52), TP-70 (T43, R52), which are known
5038 if (fan_control_initial_status
== 0x07) {
5039 switch (thinkpad_id
.ec_model
) {
5040 case 0x5931: /* TP-1Y */
5041 case 0x3837: /* TP-78 */
5042 case 0x3637: /* TP-76 */
5043 case 0x3037: /* TP-70 */
5044 printk(TPACPI_NOTICE
5045 "fan_init: initial fan status is "
5046 "unknown, assuming it is in auto "
5048 tp_features
.fan_ctrl_status_undef
= 1;
5054 "ThinkPad ACPI EC access misbehaving, "
5055 "fan status and control unavailable\n");
5062 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
5063 fan_control_commands
|=
5064 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
5067 /* gfan without sfan means no fan control */
5068 /* all other models implement TP EC 0x2f control */
5072 fan_control_access_mode
=
5073 TPACPI_FAN_WR_ACPI_FANS
;
5074 fan_control_commands
|=
5075 TPACPI_FAN_CMD_SPEED
|
5076 TPACPI_FAN_CMD_LEVEL
|
5077 TPACPI_FAN_CMD_ENABLE
;
5079 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
5080 fan_control_commands
|=
5081 TPACPI_FAN_CMD_LEVEL
|
5082 TPACPI_FAN_CMD_ENABLE
;
5087 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
5088 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
5089 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
5090 fan_status_access_mode
, fan_control_access_mode
);
5092 /* fan control master switch */
5093 if (!fan_control_allowed
) {
5094 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
5095 fan_control_commands
= 0;
5096 dbg_printk(TPACPI_DBG_INIT
,
5097 "fan control features disabled by parameter\n");
5100 /* update fan_control_desired_level */
5101 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
5102 fan_get_status_safe(NULL
);
5104 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
5105 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
5106 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
5109 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
5110 &driver_attr_fan_watchdog
);
5118 static void fan_exit(void)
5120 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
5122 /* FIXME: can we really do this unconditionally? */
5123 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
5124 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
, &driver_attr_fan_watchdog
);
5126 cancel_delayed_work(&fan_watchdog_task
);
5127 flush_scheduled_work();
5130 static int fan_read(char *p
)
5135 unsigned int speed
= 0;
5137 switch (fan_status_access_mode
) {
5138 case TPACPI_FAN_RD_ACPI_GFAN
:
5139 /* 570, 600e/x, 770e, 770x */
5140 if ((rc
= fan_get_status_safe(&status
)) < 0)
5143 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
5145 (status
!= 0) ? "enabled" : "disabled", status
);
5148 case TPACPI_FAN_RD_TPEC
:
5149 /* all except 570, 600e/x, 770e, 770x */
5150 if ((rc
= fan_get_status_safe(&status
)) < 0)
5153 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
5154 if (status
!= fan_control_initial_status
)
5155 tp_features
.fan_ctrl_status_undef
= 0;
5157 /* Return most likely status. In fact, it
5158 * might be the only possible status */
5159 status
= TP_EC_FAN_AUTO
;
5162 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
5163 (status
!= 0) ? "enabled" : "disabled");
5165 if ((rc
= fan_get_speed(&speed
)) < 0)
5168 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
5170 if (status
& TP_EC_FAN_FULLSPEED
)
5171 /* Disengaged mode takes precedence */
5172 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
5173 else if (status
& TP_EC_FAN_AUTO
)
5174 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
5176 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
5179 case TPACPI_FAN_NONE
:
5181 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
5184 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
5185 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
5187 switch (fan_control_access_mode
) {
5188 case TPACPI_FAN_WR_ACPI_SFAN
:
5189 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
5193 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
5194 "auto, disengaged, full-speed)\n");
5199 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
5200 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
5201 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
5202 "1-120 (seconds))\n");
5204 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
5205 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
5206 " (<speed> is 0-65535)\n");
5211 static int fan_write_cmd_level(const char *cmd
, int *rc
)
5215 if (strlencmp(cmd
, "level auto") == 0)
5216 level
= TP_EC_FAN_AUTO
;
5217 else if ((strlencmp(cmd
, "level disengaged") == 0) |
5218 (strlencmp(cmd
, "level full-speed") == 0))
5219 level
= TP_EC_FAN_FULLSPEED
;
5220 else if (sscanf(cmd
, "level %d", &level
) != 1)
5223 if ((*rc
= fan_set_level_safe(level
)) == -ENXIO
)
5224 printk(TPACPI_ERR
"level command accepted for unsupported "
5225 "access mode %d", fan_control_access_mode
);
5230 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
5232 if (strlencmp(cmd
, "enable") != 0)
5235 if ((*rc
= fan_set_enable()) == -ENXIO
)
5236 printk(TPACPI_ERR
"enable command accepted for unsupported "
5237 "access mode %d", fan_control_access_mode
);
5242 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
5244 if (strlencmp(cmd
, "disable") != 0)
5247 if ((*rc
= fan_set_disable()) == -ENXIO
)
5248 printk(TPACPI_ERR
"disable command accepted for unsupported "
5249 "access mode %d", fan_control_access_mode
);
5254 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
5259 * Support speed <low> <medium> <high> ? */
5261 if (sscanf(cmd
, "speed %d", &speed
) != 1)
5264 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
5265 printk(TPACPI_ERR
"speed command accepted for unsupported "
5266 "access mode %d", fan_control_access_mode
);
5271 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
5275 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
5278 if (interval
< 0 || interval
> 120)
5281 fan_watchdog_maxinterval
= interval
;
5286 static int fan_write(char *buf
)
5291 while (!rc
&& (cmd
= next_cmd(&buf
))) {
5292 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
5293 fan_write_cmd_level(cmd
, &rc
)) &&
5294 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
5295 (fan_write_cmd_enable(cmd
, &rc
) ||
5296 fan_write_cmd_disable(cmd
, &rc
) ||
5297 fan_write_cmd_watchdog(cmd
, &rc
))) &&
5298 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
5299 fan_write_cmd_speed(cmd
, &rc
))
5303 fan_watchdog_reset();
5309 static struct ibm_struct fan_driver_data
= {
5316 /****************************************************************************
5317 ****************************************************************************
5321 ****************************************************************************
5322 ****************************************************************************/
5324 /* sysfs name ---------------------------------------------------------- */
5325 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
5326 struct device_attribute
*attr
,
5329 return snprintf(buf
, PAGE_SIZE
, "%s\n", TPACPI_NAME
);
5332 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
5333 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
5335 /* --------------------------------------------------------------------- */
5338 static struct proc_dir_entry
*proc_dir
;
5341 * Module and infrastructure proble, init and exit handling
5344 static int force_load
;
5346 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
5347 static const char * __init
str_supported(int is_supported
)
5349 static char text_unsupported
[] __initdata
= "not supported";
5351 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
5353 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
5355 static void ibm_exit(struct ibm_struct
*ibm
)
5357 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
5359 list_del_init(&ibm
->all_drivers
);
5361 if (ibm
->flags
.acpi_notify_installed
) {
5362 dbg_printk(TPACPI_DBG_EXIT
,
5363 "%s: acpi_remove_notify_handler\n", ibm
->name
);
5365 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
5367 dispatch_acpi_notify
);
5368 ibm
->flags
.acpi_notify_installed
= 0;
5369 ibm
->flags
.acpi_notify_installed
= 0;
5372 if (ibm
->flags
.proc_created
) {
5373 dbg_printk(TPACPI_DBG_EXIT
,
5374 "%s: remove_proc_entry\n", ibm
->name
);
5375 remove_proc_entry(ibm
->name
, proc_dir
);
5376 ibm
->flags
.proc_created
= 0;
5379 if (ibm
->flags
.acpi_driver_registered
) {
5380 dbg_printk(TPACPI_DBG_EXIT
,
5381 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
5383 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
5384 kfree(ibm
->acpi
->driver
);
5385 ibm
->acpi
->driver
= NULL
;
5386 ibm
->flags
.acpi_driver_registered
= 0;
5389 if (ibm
->flags
.init_called
&& ibm
->exit
) {
5391 ibm
->flags
.init_called
= 0;
5394 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
5397 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
5400 struct ibm_struct
*ibm
= iibm
->data
;
5401 struct proc_dir_entry
*entry
;
5403 BUG_ON(ibm
== NULL
);
5405 INIT_LIST_HEAD(&ibm
->all_drivers
);
5407 if (ibm
->flags
.experimental
&& !experimental
)
5410 dbg_printk(TPACPI_DBG_INIT
,
5411 "probing for %s\n", ibm
->name
);
5414 ret
= iibm
->init(iibm
);
5416 return 0; /* probe failed */
5420 ibm
->flags
.init_called
= 1;
5424 if (ibm
->acpi
->hid
) {
5425 ret
= register_tpacpi_subdriver(ibm
);
5430 if (ibm
->acpi
->notify
) {
5431 ret
= setup_acpi_notify(ibm
);
5432 if (ret
== -ENODEV
) {
5433 printk(TPACPI_NOTICE
"disabling subdriver %s\n",
5443 dbg_printk(TPACPI_DBG_INIT
,
5444 "%s installed\n", ibm
->name
);
5447 entry
= create_proc_entry(ibm
->name
,
5448 S_IFREG
| S_IRUGO
| S_IWUSR
,
5451 printk(TPACPI_ERR
"unable to create proc entry %s\n",
5456 entry
->owner
= THIS_MODULE
;
5458 entry
->read_proc
= &dispatch_procfs_read
;
5460 entry
->write_proc
= &dispatch_procfs_write
;
5461 ibm
->flags
.proc_created
= 1;
5464 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
5469 dbg_printk(TPACPI_DBG_INIT
,
5470 "%s: at error exit path with result %d\n",
5474 return (ret
< 0)? ret
: 0;
5479 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
5481 const struct dmi_device
*dev
= NULL
;
5482 char ec_fw_string
[18];
5487 memset(tp
, 0, sizeof(*tp
));
5489 if (dmi_name_in_vendors("IBM"))
5490 tp
->vendor
= PCI_VENDOR_ID_IBM
;
5491 else if (dmi_name_in_vendors("LENOVO"))
5492 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
5496 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
5498 if (!tp
->bios_version_str
)
5500 tp
->bios_model
= tp
->bios_version_str
[0]
5501 | (tp
->bios_version_str
[1] << 8);
5504 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
5505 * X32 or newer, all Z series; Some models must have an
5506 * up-to-date BIOS or they will not be detected.
5508 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
5510 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
5511 if (sscanf(dev
->name
,
5512 "IBM ThinkPad Embedded Controller -[%17c",
5513 ec_fw_string
) == 1) {
5514 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
5515 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
5517 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
5518 tp
->ec_model
= ec_fw_string
[0]
5519 | (ec_fw_string
[1] << 8);
5524 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
5526 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
5527 kfree(tp
->model_str
);
5528 tp
->model_str
= NULL
;
5532 static int __init
probe_for_thinkpad(void)
5540 * Non-ancient models have better DMI tagging, but very old models
5543 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
5545 /* ec is required because many other handles are relative to it */
5546 TPACPI_ACPIHANDLE_INIT(ec
);
5550 "Not yet supported ThinkPad detected!\n");
5555 * Risks a regression on very old machines, but reduces potential
5556 * false positives a damn great deal
5559 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
5561 if (!is_thinkpad
&& !force_load
)
5568 /* Module init, exit, parameters */
5570 static struct ibm_init_struct ibms_init
[] __initdata
= {
5572 .init
= thinkpad_acpi_driver_init
,
5573 .data
= &thinkpad_acpi_driver_data
,
5576 .init
= hotkey_init
,
5577 .data
= &hotkey_driver_data
,
5580 .init
= bluetooth_init
,
5581 .data
= &bluetooth_driver_data
,
5585 .data
= &wan_driver_data
,
5589 .data
= &video_driver_data
,
5593 .data
= &light_driver_data
,
5595 #ifdef CONFIG_THINKPAD_ACPI_DOCK
5598 .data
= &dock_driver_data
[0],
5602 .data
= &dock_driver_data
[1],
5605 #ifdef CONFIG_THINKPAD_ACPI_BAY
5608 .data
= &bay_driver_data
,
5613 .data
= &cmos_driver_data
,
5617 .data
= &led_driver_data
,
5621 .data
= &beep_driver_data
,
5624 .init
= thermal_init
,
5625 .data
= &thermal_driver_data
,
5628 .data
= &ecdump_driver_data
,
5631 .init
= brightness_init
,
5632 .data
= &brightness_driver_data
,
5635 .data
= &volume_driver_data
,
5639 .data
= &fan_driver_data
,
5643 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
5646 struct ibm_struct
*ibm
;
5648 if (!kp
|| !kp
->name
|| !val
)
5651 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
5652 ibm
= ibms_init
[i
].data
;
5653 WARN_ON(ibm
== NULL
);
5655 if (!ibm
|| !ibm
->name
)
5658 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
5659 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
5661 strcpy(ibms_init
[i
].param
, val
);
5662 strcat(ibms_init
[i
].param
, ",");
5670 module_param(experimental
, int, 0);
5671 MODULE_PARM_DESC(experimental
,
5672 "Enables experimental features when non-zero");
5674 module_param_named(debug
, dbg_level
, uint
, 0);
5675 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
5677 module_param(force_load
, bool, 0);
5678 MODULE_PARM_DESC(force_load
,
5679 "Attempts to load the driver even on a "
5680 "mis-identified ThinkPad when true");
5682 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
5683 MODULE_PARM_DESC(fan_control
,
5684 "Enables setting fan parameters features when true");
5686 module_param_named(brightness_mode
, brightness_mode
, int, 0);
5687 MODULE_PARM_DESC(brightness_mode
,
5688 "Selects brightness control strategy: "
5689 "0=auto, 1=EC, 2=CMOS, 3=both");
5691 module_param(brightness_enable
, uint
, 0);
5692 MODULE_PARM_DESC(brightness_enable
,
5693 "Enables backlight control when 1, disables when 0");
5695 module_param(hotkey_report_mode
, uint
, 0);
5696 MODULE_PARM_DESC(hotkey_report_mode
,
5697 "used for backwards compatibility with userspace, "
5698 "see documentation");
5700 #define TPACPI_PARAM(feature) \
5701 module_param_call(feature, set_ibm_param, NULL, NULL, 0); \
5702 MODULE_PARM_DESC(feature, "Simulates thinkpad-aci procfs command " \
5703 "at module load, see documentation")
5705 TPACPI_PARAM(hotkey
);
5706 TPACPI_PARAM(bluetooth
);
5707 TPACPI_PARAM(video
);
5708 TPACPI_PARAM(light
);
5709 #ifdef CONFIG_THINKPAD_ACPI_DOCK
5712 #ifdef CONFIG_THINKPAD_ACPI_BAY
5714 #endif /* CONFIG_THINKPAD_ACPI_BAY */
5718 TPACPI_PARAM(ecdump
);
5719 TPACPI_PARAM(brightness
);
5720 TPACPI_PARAM(volume
);
5723 static void thinkpad_acpi_module_exit(void)
5725 struct ibm_struct
*ibm
, *itmp
;
5727 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
5729 list_for_each_entry_safe_reverse(ibm
, itmp
,
5730 &tpacpi_all_drivers
,
5735 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
5737 if (tpacpi_inputdev
) {
5738 if (tp_features
.input_device_registered
)
5739 input_unregister_device(tpacpi_inputdev
);
5741 input_free_device(tpacpi_inputdev
);
5745 hwmon_device_unregister(tpacpi_hwmon
);
5747 if (tp_features
.sensors_pdev_attrs_registered
)
5748 device_remove_file(&tpacpi_sensors_pdev
->dev
,
5749 &dev_attr_thinkpad_acpi_pdev_name
);
5750 if (tpacpi_sensors_pdev
)
5751 platform_device_unregister(tpacpi_sensors_pdev
);
5753 platform_device_unregister(tpacpi_pdev
);
5755 if (tp_features
.sensors_pdrv_attrs_registered
)
5756 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
5757 if (tp_features
.platform_drv_attrs_registered
)
5758 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
5760 if (tp_features
.sensors_pdrv_registered
)
5761 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
5763 if (tp_features
.platform_drv_registered
)
5764 platform_driver_unregister(&tpacpi_pdriver
);
5767 remove_proc_entry(TPACPI_PROC_DIR
, acpi_root_dir
);
5769 kfree(thinkpad_id
.bios_version_str
);
5770 kfree(thinkpad_id
.ec_version_str
);
5771 kfree(thinkpad_id
.model_str
);
5775 static int __init
thinkpad_acpi_module_init(void)
5779 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
5781 /* Parameter checking */
5782 if (hotkey_report_mode
> 2)
5785 /* Driver-level probe */
5787 get_thinkpad_model_data(&thinkpad_id
);
5788 ret
= probe_for_thinkpad();
5790 thinkpad_acpi_module_exit();
5794 /* Driver initialization */
5796 TPACPI_ACPIHANDLE_INIT(ecrd
);
5797 TPACPI_ACPIHANDLE_INIT(ecwr
);
5799 proc_dir
= proc_mkdir(TPACPI_PROC_DIR
, acpi_root_dir
);
5801 printk(TPACPI_ERR
"unable to create proc dir " TPACPI_PROC_DIR
);
5802 thinkpad_acpi_module_exit();
5805 proc_dir
->owner
= THIS_MODULE
;
5807 ret
= platform_driver_register(&tpacpi_pdriver
);
5809 printk(TPACPI_ERR
"unable to register main platform driver\n");
5810 thinkpad_acpi_module_exit();
5813 tp_features
.platform_drv_registered
= 1;
5815 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
5817 printk(TPACPI_ERR
"unable to register hwmon platform driver\n");
5818 thinkpad_acpi_module_exit();
5821 tp_features
.sensors_pdrv_registered
= 1;
5823 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
5825 tp_features
.platform_drv_attrs_registered
= 1;
5826 ret
= tpacpi_create_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
5829 printk(TPACPI_ERR
"unable to create sysfs driver attributes\n");
5830 thinkpad_acpi_module_exit();
5833 tp_features
.sensors_pdrv_attrs_registered
= 1;
5836 /* Device initialization */
5837 tpacpi_pdev
= platform_device_register_simple(TPACPI_DRVR_NAME
, -1,
5839 if (IS_ERR(tpacpi_pdev
)) {
5840 ret
= PTR_ERR(tpacpi_pdev
);
5842 printk(TPACPI_ERR
"unable to register platform device\n");
5843 thinkpad_acpi_module_exit();
5846 tpacpi_sensors_pdev
= platform_device_register_simple(
5847 TPACPI_HWMON_DRVR_NAME
,
5849 if (IS_ERR(tpacpi_sensors_pdev
)) {
5850 ret
= PTR_ERR(tpacpi_sensors_pdev
);
5851 tpacpi_sensors_pdev
= NULL
;
5852 printk(TPACPI_ERR
"unable to register hwmon platform device\n");
5853 thinkpad_acpi_module_exit();
5856 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
5857 &dev_attr_thinkpad_acpi_pdev_name
);
5860 "unable to create sysfs hwmon device attributes\n");
5861 thinkpad_acpi_module_exit();
5864 tp_features
.sensors_pdev_attrs_registered
= 1;
5865 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
5866 if (IS_ERR(tpacpi_hwmon
)) {
5867 ret
= PTR_ERR(tpacpi_hwmon
);
5868 tpacpi_hwmon
= NULL
;
5869 printk(TPACPI_ERR
"unable to register hwmon device\n");
5870 thinkpad_acpi_module_exit();
5873 mutex_init(&tpacpi_inputdev_send_mutex
);
5874 tpacpi_inputdev
= input_allocate_device();
5875 if (!tpacpi_inputdev
) {
5876 printk(TPACPI_ERR
"unable to allocate input device\n");
5877 thinkpad_acpi_module_exit();
5880 /* Prepare input device, but don't register */
5881 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
5882 tpacpi_inputdev
->phys
= TPACPI_DRVR_NAME
"/input0";
5883 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
5884 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
5885 thinkpad_id
.vendor
:
5887 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
5888 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
5890 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
5891 ret
= ibm_init(&ibms_init
[i
]);
5892 if (ret
>= 0 && *ibms_init
[i
].param
)
5893 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
5895 thinkpad_acpi_module_exit();
5899 ret
= input_register_device(tpacpi_inputdev
);
5901 printk(TPACPI_ERR
"unable to register input device\n");
5902 thinkpad_acpi_module_exit();
5905 tp_features
.input_device_registered
= 1;
5908 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
5912 /* Please remove this in year 2009 */
5913 MODULE_ALIAS("ibm_acpi");
5916 * DMI matching for module autoloading
5918 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
5919 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
5921 * Only models listed in thinkwiki will be supported, so add yours
5922 * if it is not there yet.
5924 #define IBM_BIOS_MODULE_ALIAS(__type) \
5925 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
5927 /* Non-ancient thinkpads */
5928 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
5929 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
5931 /* Ancient thinkpad BIOSes have to be identified by
5932 * BIOS type or model number, and there are far less
5933 * BIOS types than model numbers... */
5934 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
5935 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
5936 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
5938 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
5939 MODULE_DESCRIPTION(TPACPI_DESC
);
5940 MODULE_VERSION(TPACPI_VERSION
);
5941 MODULE_LICENSE("GPL");
5943 module_init(thinkpad_acpi_module_init
);
5944 module_exit(thinkpad_acpi_module_exit
);