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 IBM_VERSION "0.16"
25 #define TPACPI_SYSFS_VERSION 0x010000
29 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
32 * 2006-11-22 0.13 new maintainer
33 * changelog now lives in git commit history, and will
34 * not be updated further in-file.
36 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
37 * 2005-03-17 0.11 support for 600e, 770x
38 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
39 * support for 770e, G41
40 * G40 and G41 don't have a thinklight
41 * temperatures no longer experimental
42 * experimental brightness control
43 * experimental volume control
44 * experimental fan enable/disable
45 * 2005-01-16 0.10 fix module loading on R30, R31
46 * 2005-01-16 0.9 support for 570, R30, R31
47 * ultrabay support on A22p, A3x
48 * limit arg for cmos, led, beep, drop experimental status
49 * more capable led control on A21e, A22p, T20-22, X20
50 * experimental temperatures and fan speed
51 * experimental embedded controller register dump
52 * mark more functions as __init, drop incorrect __exit
54 * thanks to Henrik Brix Andersen <brix@gentoo.org>
55 * fix parameter passing on module loading
56 * thanks to Rusty Russell <rusty@rustcorp.com.au>
57 * thanks to Jim Radford <radford@blackbean.org>
58 * 2004-11-08 0.8 fix init error case, don't return from a macro
59 * thanks to Chris Wright <chrisw@osdl.org>
60 * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
61 * fix led control on A21e
62 * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
63 * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
64 * proc file format changed
65 * video_switch command
66 * experimental cmos control
67 * experimental led control
68 * experimental acpi sounds
69 * 2004-09-16 0.4 support for module parameters
70 * hotkey mask can be prefixed by 0x
71 * video output switching
72 * video expansion control
73 * ultrabay eject support
74 * removed lcd brightness/on/off control, didn't work
75 * 2004-08-17 0.3 support for R40
76 * lcd off, brightness control
78 * 2004-08-14 0.2 support for T series, X20
79 * bluetooth enable/disable
80 * hotkey events disabled by default
81 * removed fan control, currently useless
82 * 2004-08-09 0.1 initial release, support for X series
85 #include "thinkpad_acpi.h"
87 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
88 MODULE_DESCRIPTION(IBM_DESC
);
89 MODULE_VERSION(IBM_VERSION
);
90 MODULE_LICENSE("GPL");
92 /* Please remove this in year 2009 */
93 MODULE_ALIAS("ibm_acpi");
96 * DMI matching for module autoloading
98 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
99 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
101 * Only models listed in thinkwiki will be supported, so add yours
102 * if it is not there yet.
104 #define IBM_BIOS_MODULE_ALIAS(__type) \
105 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
107 /* Non-ancient thinkpads */
108 MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
109 MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
111 /* Ancient thinkpad BIOSes have to be identified by
112 * BIOS type or model number, and there are far less
113 * BIOS types than model numbers... */
114 IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
115 IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
116 IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
118 #define __unused __attribute__ ((unused))
121 TPACPI_LIFE_INIT
= 0,
126 /****************************************************************************
127 ****************************************************************************
129 * ACPI Helpers and device model
131 ****************************************************************************
132 ****************************************************************************/
134 /*************************************************************************
138 static acpi_handle root_handle
;
140 #define IBM_HANDLE(object, parent, paths...) \
141 static acpi_handle object##_handle; \
142 static acpi_handle *object##_parent = &parent##_handle; \
143 static char *object##_path; \
144 static char *object##_paths[] = { paths }
146 IBM_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
147 "\\_SB.PCI.ISA.EC", /* 570 */
148 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
149 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
150 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
151 "\\_SB.PCI0.ICH3.EC0", /* R31 */
152 "\\_SB.PCI0.LPC.EC", /* all others */
155 IBM_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
156 IBM_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
159 /*************************************************************************
163 IBM_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
164 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
165 "\\CMS", /* R40, R40e */
168 IBM_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
169 "^HKEY", /* R30, R31 */
170 "HKEY", /* all others */
174 /*************************************************************************
178 static int acpi_evalf(acpi_handle handle
,
179 void *res
, char *method
, char *fmt
, ...)
182 struct acpi_object_list params
;
183 union acpi_object in_objs
[IBM_MAX_ACPI_ARGS
];
184 struct acpi_buffer result
, *resultp
;
185 union acpi_object out_obj
;
193 printk(IBM_ERR
"acpi_evalf() called with empty format\n");
206 params
.pointer
= &in_objs
[0];
213 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
214 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
216 /* add more types as needed */
218 printk(IBM_ERR
"acpi_evalf() called "
219 "with invalid format character '%c'\n", c
);
225 if (res_type
!= 'v') {
226 result
.length
= sizeof(out_obj
);
227 result
.pointer
= &out_obj
;
232 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
237 *(int *)res
= out_obj
.integer
.value
;
238 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
241 success
= status
== AE_OK
;
243 /* add more types as needed */
245 printk(IBM_ERR
"acpi_evalf() called "
246 "with invalid format character '%c'\n", res_type
);
250 if (!success
&& !quiet
)
251 printk(IBM_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
252 method
, fmt0
, status
);
257 static void __unused
acpi_print_int(acpi_handle handle
, char *method
)
261 if (acpi_evalf(handle
, &i
, method
, "d"))
262 printk(IBM_INFO
"%s = 0x%x\n", method
, i
);
264 printk(IBM_ERR
"error calling %s\n", method
);
267 static int acpi_ec_read(int i
, u8
* p
)
272 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
276 if (ec_read(i
, p
) < 0)
283 static int acpi_ec_write(int i
, u8 v
)
286 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
289 if (ec_write(i
, v
) < 0)
296 static int _sta(acpi_handle handle
)
300 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
306 static int issue_thinkpad_cmos_command(int cmos_cmd
)
311 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
317 /*************************************************************************
321 static void drv_acpi_handle_init(char *name
,
322 acpi_handle
*handle
, acpi_handle parent
,
323 char **paths
, int num_paths
, char **path
)
328 vdbg_printk(TPACPI_DBG_INIT
, "trying to locate ACPI handle for %s\n",
331 for (i
= 0; i
< num_paths
; i
++) {
332 status
= acpi_get_handle(parent
, paths
[i
], handle
);
333 if (ACPI_SUCCESS(status
)) {
335 dbg_printk(TPACPI_DBG_INIT
,
336 "Found ACPI handle %s for %s\n",
342 vdbg_printk(TPACPI_DBG_INIT
, "ACPI handle for %s not found\n",
347 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
349 struct ibm_struct
*ibm
= data
;
351 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
354 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
357 ibm
->acpi
->notify(ibm
, event
);
360 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
367 if (!*ibm
->acpi
->handle
)
370 vdbg_printk(TPACPI_DBG_INIT
,
371 "setting up ACPI notify for %s\n", ibm
->name
);
373 rc
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
375 printk(IBM_ERR
"acpi_bus_get_device(%s) failed: %d\n",
380 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
381 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
382 IBM_ACPI_EVENT_PREFIX
,
385 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
386 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
387 if (ACPI_FAILURE(status
)) {
388 if (status
== AE_ALREADY_EXISTS
) {
389 printk(IBM_NOTICE
"another device driver is already handling %s events\n",
392 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
397 ibm
->flags
.acpi_notify_installed
= 1;
401 static int __init
tpacpi_device_add(struct acpi_device
*device
)
406 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
410 dbg_printk(TPACPI_DBG_INIT
,
411 "registering %s as an ACPI driver\n", ibm
->name
);
415 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
416 if (!ibm
->acpi
->driver
) {
417 printk(IBM_ERR
"kzalloc(ibm->driver) failed\n");
421 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
422 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
424 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
426 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
428 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
430 kfree(ibm
->acpi
->driver
);
431 ibm
->acpi
->driver
= NULL
;
433 ibm
->flags
.acpi_driver_registered
= 1;
439 /****************************************************************************
440 ****************************************************************************
444 ****************************************************************************
445 ****************************************************************************/
447 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
448 int count
, int *eof
, void *data
)
450 struct ibm_struct
*ibm
= data
;
453 if (!ibm
|| !ibm
->read
)
456 len
= ibm
->read(page
);
460 if (len
<= off
+ count
)
472 static int dispatch_procfs_write(struct file
*file
,
473 const char __user
* userbuf
,
474 unsigned long count
, void *data
)
476 struct ibm_struct
*ibm
= data
;
480 if (!ibm
|| !ibm
->write
)
483 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
487 if (copy_from_user(kernbuf
, userbuf
, count
)) {
493 strcat(kernbuf
, ",");
494 ret
= ibm
->write(kernbuf
);
503 static char *next_cmd(char **cmds
)
508 while ((end
= strchr(start
, ',')) && end
== start
)
520 /****************************************************************************
521 ****************************************************************************
523 * Device model: input, hwmon and platform
525 ****************************************************************************
526 ****************************************************************************/
528 static struct platform_device
*tpacpi_pdev
;
529 static struct class_device
*tpacpi_hwmon
;
530 static struct input_dev
*tpacpi_inputdev
;
531 static struct mutex tpacpi_inputdev_send_mutex
;
534 static int tpacpi_resume_handler(struct platform_device
*pdev
)
536 struct ibm_struct
*ibm
, *itmp
;
538 list_for_each_entry_safe(ibm
, itmp
,
548 static struct platform_driver tpacpi_pdriver
= {
550 .name
= IBM_DRVR_NAME
,
551 .owner
= THIS_MODULE
,
553 .resume
= tpacpi_resume_handler
,
557 /*************************************************************************
558 * thinkpad-acpi driver attributes
561 /* interface_version --------------------------------------------------- */
562 static ssize_t
tpacpi_driver_interface_version_show(
563 struct device_driver
*drv
,
566 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
569 static DRIVER_ATTR(interface_version
, S_IRUGO
,
570 tpacpi_driver_interface_version_show
, NULL
);
572 /* debug_level --------------------------------------------------------- */
573 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
576 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
579 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
580 const char *buf
, size_t count
)
584 if (parse_strtoul(buf
, 0xffff, &t
))
592 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
593 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
595 /* version ------------------------------------------------------------- */
596 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
599 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n", IBM_DESC
, IBM_VERSION
);
602 static DRIVER_ATTR(version
, S_IRUGO
,
603 tpacpi_driver_version_show
, NULL
);
605 /* --------------------------------------------------------------------- */
607 static struct driver_attribute
* tpacpi_driver_attributes
[] = {
608 &driver_attr_debug_level
, &driver_attr_version
,
609 &driver_attr_interface_version
,
612 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
618 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
619 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
626 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
630 for(i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
631 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
634 /*************************************************************************
635 * sysfs support helpers
638 struct attribute_set_obj
{
639 struct attribute_set s
;
641 } __attribute__((packed
));
643 static struct attribute_set
*create_attr_set(unsigned int max_members
,
646 struct attribute_set_obj
*sobj
;
648 if (max_members
== 0)
651 /* Allocates space for implicit NULL at the end too */
652 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
653 max_members
* sizeof(struct attribute
*),
657 sobj
->s
.max_members
= max_members
;
658 sobj
->s
.group
.attrs
= &sobj
->a
;
659 sobj
->s
.group
.name
= name
;
664 /* not multi-threaded safe, use it in a single thread per set */
665 static int add_to_attr_set(struct attribute_set
* s
, struct attribute
*attr
)
670 if (s
->members
>= s
->max_members
)
673 s
->group
.attrs
[s
->members
] = attr
;
679 static int add_many_to_attr_set(struct attribute_set
* s
,
680 struct attribute
**attr
,
685 for (i
= 0; i
< count
; i
++) {
686 res
= add_to_attr_set(s
, attr
[i
]);
694 static void delete_attr_set(struct attribute_set
* s
, struct kobject
*kobj
)
696 sysfs_remove_group(kobj
, &s
->group
);
700 static int parse_strtoul(const char *buf
,
701 unsigned long max
, unsigned long *value
)
705 *value
= simple_strtoul(buf
, &endp
, 0);
706 while (*endp
&& isspace(*endp
))
708 if (*endp
|| *value
> max
)
714 /****************************************************************************
715 ****************************************************************************
719 ****************************************************************************
720 ****************************************************************************/
722 /*************************************************************************
723 * thinkpad-acpi init subdriver
726 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
728 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
729 printk(IBM_INFO
"%s\n", IBM_URL
);
731 printk(IBM_INFO
"ThinkPad BIOS %s, EC %s\n",
732 (thinkpad_id
.bios_version_str
) ?
733 thinkpad_id
.bios_version_str
: "unknown",
734 (thinkpad_id
.ec_version_str
) ?
735 thinkpad_id
.ec_version_str
: "unknown");
737 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
738 printk(IBM_INFO
"%s %s\n",
739 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
740 "IBM" : ((thinkpad_id
.vendor
==
741 PCI_VENDOR_ID_LENOVO
) ?
742 "Lenovo" : "Unknown vendor"),
743 thinkpad_id
.model_str
);
748 static int thinkpad_acpi_driver_read(char *p
)
752 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
753 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
758 static struct ibm_struct thinkpad_acpi_driver_data
= {
760 .read
= thinkpad_acpi_driver_read
,
763 /*************************************************************************
767 enum { /* Keys available through NVRAM polling */
768 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb8000U
,
771 enum { /* Positions of some of the keys in hotkey masks */
772 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
773 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
774 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
775 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
776 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
777 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
778 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
779 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
780 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
781 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
782 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
785 enum { /* NVRAM to ACPI HKEY group map */
786 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
787 TP_ACPI_HKEY_ZOOM_MASK
|
788 TP_ACPI_HKEY_DISPSWTCH_MASK
|
789 TP_ACPI_HKEY_HIBERNATE_MASK
,
790 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
791 TP_ACPI_HKEY_BRGHTDWN_MASK
,
792 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
793 TP_ACPI_HKEY_VOLDWN_MASK
|
794 TP_ACPI_HKEY_MUTE_MASK
,
797 struct tp_nvram_state
{
798 u16 thinkpad_toggle
:1;
800 u16 display_toggle
:1;
801 u16 thinklight_toggle
:1;
802 u16 hibernate_toggle
:1;
803 u16 displayexp_toggle
:1;
805 u16 brightness_toggle
:1;
813 static int hotkey_orig_status
;
814 static u32 hotkey_orig_mask
;
815 static u32 hotkey_all_mask
;
816 static u32 hotkey_reserved_mask
;
818 static struct task_struct
*tpacpi_hotkey_task
;
819 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
820 static int hotkey_poll_freq
= 4; /* Hz */
821 static struct mutex hotkey_poll_mutex
;
822 static struct mutex thinkpad_nvram_mutex
;
823 static struct mutex hotkey_thread_mutex
;
825 static u16
*hotkey_keycode_map
;
827 static struct attribute_set
*hotkey_dev_attributes
;
829 static void tpacpi_input_send_key(unsigned int scancode
)
831 unsigned int keycode
;
833 keycode
= hotkey_keycode_map
[scancode
];
835 if (keycode
!= KEY_RESERVED
) {
836 mutex_lock(&tpacpi_inputdev_send_mutex
);
838 input_report_key(tpacpi_inputdev
, keycode
, 1);
839 if (keycode
== KEY_UNKNOWN
)
840 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
842 input_sync(tpacpi_inputdev
);
844 input_report_key(tpacpi_inputdev
, keycode
, 0);
845 if (keycode
== KEY_UNKNOWN
)
846 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
848 input_sync(tpacpi_inputdev
);
850 mutex_unlock(&tpacpi_inputdev_send_mutex
);
854 static int hotkey_get_wlsw(int *status
)
856 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
861 static void tpacpi_input_send_radiosw(void)
865 mutex_lock(&tpacpi_inputdev_send_mutex
);
867 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
868 input_report_switch(tpacpi_inputdev
,
870 input_sync(tpacpi_inputdev
);
873 mutex_unlock(&tpacpi_inputdev_send_mutex
);
876 static void hotkey_read_nvram(struct tp_nvram_state
*n
)
880 if (hotkey_source_mask
& TP_NVRAM_HKEY_GROUP_HK2
) {
881 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
882 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
883 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
884 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
885 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
887 if (hotkey_source_mask
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
888 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
889 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
891 if (hotkey_source_mask
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
892 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
893 n
->displayexp_toggle
=
894 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
896 if (hotkey_source_mask
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
897 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
898 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
899 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
900 n
->brightness_toggle
=
901 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
903 if (hotkey_source_mask
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
904 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
905 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
906 >> TP_NVRAM_POS_LEVEL_VOLUME
;
907 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
908 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
912 #define TPACPI_COMPARE_KEY(__scancode, __member) \
913 if (hotkey_source_mask & (1 << __scancode) && \
914 oldn->__member != newn->__member) \
915 tpacpi_input_send_key(__scancode);
917 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
918 struct tp_nvram_state
*newn
)
920 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
)
921 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
)
922 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
)
923 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
)
925 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
)
927 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
)
930 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
931 if (oldn
->mute
!= newn
->mute
) {
932 tpacpi_input_send_key(TP_ACPI_HOTKEYSCAN_MUTE
);
934 if (oldn
->volume_level
> newn
->volume_level
) {
935 tpacpi_input_send_key(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
936 } else if (oldn
->volume_level
< newn
->volume_level
) {
937 tpacpi_input_send_key(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
940 /* we could "else" here and issue mute regardless of a change
941 * in the mute bit (and therefore notify of multiple presses of
942 * the mute button), but that is *incorrect* semanthics for
943 * a thinkpad mixer, where "mute" always mutes, and a volume
948 /* handle brightness */
949 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
950 if (oldn
->brightness_level
< newn
->brightness_level
) {
951 tpacpi_input_send_key(TP_ACPI_HOTKEYSCAN_FNHOME
);
952 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
953 tpacpi_input_send_key(TP_ACPI_HOTKEYSCAN_FNEND
);
958 #undef TPACPI_COMPARE_KEY
960 static int hotkey_kthread(void *data
)
962 struct tp_nvram_state s
[2];
966 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
969 mutex_lock(&hotkey_thread_mutex
);
975 /* Initial state for compares */
976 hotkey_read_nvram(&s
[so
]);
978 while (!kthread_should_stop() && hotkey_poll_freq
) {
979 t
= msleep_interruptible(1000/hotkey_poll_freq
+ t
);
980 if (unlikely(kthread_should_stop()))
982 if (unlikely(try_to_freeze())) {
983 si
= so
; /* forget old state on thaw */
989 hotkey_read_nvram(&s
[si
]);
990 hotkey_compare_and_issue_event(&s
[so
], &s
[si
]);
995 mutex_unlock(&hotkey_thread_mutex
);
999 static void hotkey_poll_stop_sync(void)
1001 if (tpacpi_hotkey_task
) {
1002 kthread_stop(tpacpi_hotkey_task
);
1003 tpacpi_hotkey_task
= NULL
;
1004 mutex_lock(&hotkey_thread_mutex
);
1005 /* at this point, the thread did exit */
1006 mutex_unlock(&hotkey_thread_mutex
);
1010 /* call with hotkey_poll_mutex held */
1011 static void hotkey_poll_setup(int force
)
1014 hotkey_poll_stop_sync();
1016 if (hotkey_source_mask
!= 0 && hotkey_poll_freq
> 0 &&
1017 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1018 if (!tpacpi_hotkey_task
) {
1019 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1020 NULL
, IBM_FILE
"d");
1021 if (IS_ERR(tpacpi_hotkey_task
)) {
1022 tpacpi_hotkey_task
= NULL
;
1023 printk(IBM_ERR
"could not create kernel thread "
1024 "for hotkey polling\n");
1028 hotkey_poll_stop_sync();
1032 static int hotkey_poll_setup_safe(int force
)
1036 rc
= mutex_lock_interruptible(&hotkey_poll_mutex
);
1040 hotkey_poll_setup(force
);
1041 mutex_unlock(&hotkey_poll_mutex
);
1046 static void hotkey_warn_no_poll(void)
1048 if (hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1049 printk(IBM_NOTICE
"hot keys 0x%08x require polling, "
1050 "which is currently disabled\n",
1051 hotkey_source_mask
);
1056 static int hotkey_inputdev_open(struct input_dev
*dev
)
1058 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
1060 /* enable hotkey polling when required */
1061 return hotkey_poll_setup_safe(0);
1064 static void hotkey_inputdev_close(struct input_dev
*dev
)
1066 /* disable hotkey polling when possible */
1067 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
)
1068 hotkey_poll_setup_safe(0);
1071 /* sysfs hotkey enable ------------------------------------------------- */
1072 static ssize_t
hotkey_enable_show(struct device
*dev
,
1073 struct device_attribute
*attr
,
1079 res
= hotkey_get(&status
, &mask
);
1083 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1086 static ssize_t
hotkey_enable_store(struct device
*dev
,
1087 struct device_attribute
*attr
,
1088 const char *buf
, size_t count
)
1094 if (parse_strtoul(buf
, 1, &t
))
1097 res
= hotkey_get(&status
, &mask
);
1099 res
= hotkey_set(t
, mask
);
1101 return (res
) ? res
: count
;
1104 static struct device_attribute dev_attr_hotkey_enable
=
1105 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
1106 hotkey_enable_show
, hotkey_enable_store
);
1108 /* sysfs hotkey mask --------------------------------------------------- */
1109 static ssize_t
hotkey_mask_show(struct device
*dev
,
1110 struct device_attribute
*attr
,
1116 res
= hotkey_get(&status
, &mask
);
1120 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", mask
);
1123 static ssize_t
hotkey_mask_store(struct device
*dev
,
1124 struct device_attribute
*attr
,
1125 const char *buf
, size_t count
)
1131 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
1134 res
= hotkey_get(&status
, &mask
);
1136 hotkey_set(status
, t
);
1138 return (res
) ? res
: count
;
1141 static struct device_attribute dev_attr_hotkey_mask
=
1142 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
1143 hotkey_mask_show
, hotkey_mask_store
);
1145 /* sysfs hotkey bios_enabled ------------------------------------------- */
1146 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
1147 struct device_attribute
*attr
,
1150 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
1153 static struct device_attribute dev_attr_hotkey_bios_enabled
=
1154 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
1156 /* sysfs hotkey bios_mask ---------------------------------------------- */
1157 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
1158 struct device_attribute
*attr
,
1161 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
1164 static struct device_attribute dev_attr_hotkey_bios_mask
=
1165 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
1167 /* sysfs hotkey all_mask ----------------------------------------------- */
1168 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
1169 struct device_attribute
*attr
,
1172 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1173 hotkey_all_mask
| hotkey_source_mask
);
1176 static struct device_attribute dev_attr_hotkey_all_mask
=
1177 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
1179 /* sysfs hotkey recommended_mask --------------------------------------- */
1180 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
1181 struct device_attribute
*attr
,
1184 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1185 (hotkey_all_mask
| hotkey_source_mask
)
1186 & ~hotkey_reserved_mask
);
1189 static struct device_attribute dev_attr_hotkey_recommended_mask
=
1190 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
1191 hotkey_recommended_mask_show
, NULL
);
1193 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
1194 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
1195 struct device_attribute
*attr
,
1198 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
1201 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
1202 struct device_attribute
*attr
,
1203 const char *buf
, size_t count
)
1208 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
1209 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
1212 rc
= mutex_lock_interruptible(&hotkey_poll_mutex
);
1216 hotkey_source_mask
= t
;
1218 hotkey_poll_setup(1);
1219 hotkey_warn_no_poll();
1220 mutex_unlock(&hotkey_poll_mutex
);
1225 static struct device_attribute dev_attr_hotkey_source_mask
=
1226 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
1227 hotkey_source_mask_show
, hotkey_source_mask_store
);
1229 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
1230 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
1231 struct device_attribute
*attr
,
1234 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
1237 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
1238 struct device_attribute
*attr
,
1239 const char *buf
, size_t count
)
1244 if (parse_strtoul(buf
, 25, &t
))
1247 rc
= mutex_lock_interruptible(&hotkey_poll_mutex
);
1251 hotkey_poll_freq
= t
;
1253 hotkey_poll_setup(0);
1254 hotkey_warn_no_poll();
1255 mutex_unlock(&hotkey_poll_mutex
);
1260 static struct device_attribute dev_attr_hotkey_poll_freq
=
1261 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
1262 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
1264 /* sysfs hotkey radio_sw ----------------------------------------------- */
1265 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
1266 struct device_attribute
*attr
,
1270 res
= hotkey_get_wlsw(&s
);
1274 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1277 static struct device_attribute dev_attr_hotkey_radio_sw
=
1278 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
1280 /* sysfs hotkey report_mode -------------------------------------------- */
1281 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
1282 struct device_attribute
*attr
,
1285 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1286 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
1289 static struct device_attribute dev_attr_hotkey_report_mode
=
1290 __ATTR(hotkey_report_mode
, S_IRUGO
, hotkey_report_mode_show
, NULL
);
1292 /* --------------------------------------------------------------------- */
1294 static struct attribute
*hotkey_attributes
[] __initdata
= {
1295 &dev_attr_hotkey_enable
.attr
,
1296 &dev_attr_hotkey_report_mode
.attr
,
1299 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
1300 &dev_attr_hotkey_mask
.attr
,
1301 &dev_attr_hotkey_bios_enabled
.attr
,
1302 &dev_attr_hotkey_bios_mask
.attr
,
1303 &dev_attr_hotkey_all_mask
.attr
,
1304 &dev_attr_hotkey_recommended_mask
.attr
,
1305 &dev_attr_hotkey_source_mask
.attr
,
1306 &dev_attr_hotkey_poll_freq
.attr
,
1309 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
1312 static u16 ibm_keycode_map
[] __initdata
= {
1313 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1314 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
1315 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1316 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1317 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
1318 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1319 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1320 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1321 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1322 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
1323 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1324 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1325 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1326 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1327 KEY_RESERVED
, /* 0x14: VOLUME UP */
1328 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1329 KEY_RESERVED
, /* 0x16: MUTE */
1330 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1331 /* (assignments unknown, please report if found) */
1332 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1333 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1335 static u16 lenovo_keycode_map
[] __initdata
= {
1336 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1337 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
1338 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1339 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1340 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
1341 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1342 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1343 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1344 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
1345 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
1346 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
1347 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1348 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1349 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1350 KEY_RESERVED
, /* 0x14: VOLUME UP */
1351 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1352 KEY_RESERVED
, /* 0x16: MUTE */
1353 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1354 /* (assignments unknown, please report if found) */
1355 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1356 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1359 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
1360 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
1361 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
1367 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
1369 BUG_ON(!tpacpi_inputdev
);
1370 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
1371 tpacpi_inputdev
->close
!= NULL
);
1373 IBM_ACPIHANDLE_INIT(hkey
);
1374 mutex_init(&hotkey_mutex
);
1375 mutex_init(&hotkey_poll_mutex
);
1376 mutex_init(&hotkey_thread_mutex
);
1378 /* hotkey not supported on 570 */
1379 tp_features
.hotkey
= hkey_handle
!= NULL
;
1381 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
1382 str_supported(tp_features
.hotkey
));
1384 if (tp_features
.hotkey
) {
1385 hotkey_dev_attributes
= create_attr_set(10, NULL
);
1386 if (!hotkey_dev_attributes
)
1388 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1390 ARRAY_SIZE(hotkey_attributes
));
1394 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1395 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
1396 for HKEY interface version 0x100 */
1397 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
1398 if ((hkeyv
>> 8) != 1) {
1399 printk(IBM_ERR
"unknown version of the "
1400 "HKEY interface: 0x%x\n", hkeyv
);
1401 printk(IBM_ERR
"please report this to %s\n",
1405 * MHKV 0x100 in A31, R40, R40e,
1406 * T4x, X31, and later
1408 tp_features
.hotkey_mask
= 1;
1412 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
1413 str_supported(tp_features
.hotkey_mask
));
1415 if (tp_features
.hotkey_mask
) {
1416 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
1419 "missing MHKA handler, "
1420 "please report this to %s\n",
1422 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
1426 hotkey_source_mask
= TPACPI_HKEY_NVRAM_KNOWN_MASK
1429 vdbg_printk(TPACPI_DBG_INIT
,
1430 "hotkey source mask 0x%08x, polling freq %d\n",
1431 hotkey_source_mask
, hotkey_poll_freq
);
1433 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
1434 if (!res
&& tp_features
.hotkey_mask
) {
1435 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1436 hotkey_mask_attributes
,
1437 ARRAY_SIZE(hotkey_mask_attributes
));
1440 /* Not all thinkpads have a hardware radio switch */
1441 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
1442 tp_features
.hotkey_wlsw
= 1;
1444 "radio switch found; radios are %s\n",
1445 enabled(status
, 0));
1446 res
= add_to_attr_set(hotkey_dev_attributes
,
1447 &dev_attr_hotkey_radio_sw
.attr
);
1451 res
= register_attr_set_with_sysfs(
1452 hotkey_dev_attributes
,
1453 &tpacpi_pdev
->dev
.kobj
);
1457 /* Set up key map */
1459 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
1461 if (!hotkey_keycode_map
) {
1462 printk(IBM_ERR
"failed to allocate memory for key map\n");
1466 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
1467 dbg_printk(TPACPI_DBG_INIT
,
1468 "using Lenovo default hot key map\n");
1469 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
1470 TPACPI_HOTKEY_MAP_SIZE
);
1472 dbg_printk(TPACPI_DBG_INIT
,
1473 "using IBM default hot key map\n");
1474 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
1475 TPACPI_HOTKEY_MAP_SIZE
);
1478 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
1479 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
1480 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
1481 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
1482 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
1483 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
1484 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
1485 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
1486 set_bit(hotkey_keycode_map
[i
],
1487 tpacpi_inputdev
->keybit
);
1489 if (i
< sizeof(hotkey_reserved_mask
)*8)
1490 hotkey_reserved_mask
|= 1 << i
;
1493 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
1494 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
1496 if (tp_features
.hotkey_wlsw
) {
1497 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
1498 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
1501 dbg_printk(TPACPI_DBG_INIT
,
1502 "enabling hot key handling\n");
1503 res
= hotkey_set(1, ((hotkey_all_mask
| hotkey_source_mask
)
1504 & ~hotkey_reserved_mask
)
1505 | hotkey_orig_mask
);
1509 dbg_printk(TPACPI_DBG_INIT
,
1510 "legacy hot key reporting over procfs %s\n",
1511 (hotkey_report_mode
< 2) ?
1512 "enabled" : "disabled");
1514 mutex_lock(&hotkey_poll_mutex
);
1515 hotkey_poll_setup(0);
1516 hotkey_warn_no_poll();
1517 mutex_unlock(&hotkey_poll_mutex
);
1520 return (tp_features
.hotkey
)? 0 : 1;
1523 static void hotkey_exit(void)
1527 hotkey_poll_stop_sync();
1529 if (tp_features
.hotkey
) {
1530 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
1531 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
1533 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
1536 if (hotkey_dev_attributes
) {
1537 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
1538 hotkey_dev_attributes
= NULL
;
1542 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
1545 unsigned int scancode
;
1549 if (event
!= 0x80) {
1550 printk(IBM_ERR
"unknown hotkey notification event %d\n", event
);
1551 /* forward it to userspace, maybe it knows how to handle it */
1552 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
1553 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
1554 ibm
->acpi
->device
->dev
.bus_id
,
1560 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
1561 printk(IBM_ERR
"failed to retrieve hot key event\n");
1573 switch (hkey
>> 12) {
1575 /* 0x1000-0x1FFF: key presses */
1576 scancode
= hkey
& 0xfff;
1577 if (scancode
> 0 && scancode
< 0x21) {
1579 if (!(hotkey_source_mask
& (1 << scancode
))) {
1580 tpacpi_input_send_key(scancode
);
1584 "hotkey 0x%04x out of range for keyboard map\n",
1590 /* 0x5000-0x5FFF: LID */
1591 /* we don't handle it through this path, just
1592 * eat up known LID events */
1593 if (hkey
!= 0x5001 && hkey
!= 0x5002) {
1595 "unknown LID-related hotkey event: 0x%04x\n",
1603 /* 0x7000-0x7FFF: misc */
1604 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
1605 tpacpi_input_send_radiosw();
1608 /* fallthrough to default */
1610 /* case 2: dock-related */
1611 /* 0x2305 - T43 waking up due to bay lever eject while aslept */
1612 /* case 3: ultra-bay related. maybe bay in dock? */
1613 /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
1614 printk(IBM_NOTICE
"unhandled HKEY event 0x%04x\n", hkey
);
1619 if (!ignore_acpi_ev
&& (send_acpi_ev
|| hotkey_report_mode
< 2)) {
1620 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, hkey
);
1623 /* netlink events */
1624 if (!ignore_acpi_ev
&& send_acpi_ev
) {
1625 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
1626 ibm
->acpi
->device
->dev
.bus_id
,
1632 static void hotkey_resume(void)
1634 tpacpi_input_send_radiosw();
1635 hotkey_poll_setup_safe(1);
1639 * Call with hotkey_mutex held
1641 static int hotkey_get(int *status
, u32
*mask
)
1643 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1646 if (tp_features
.hotkey_mask
)
1647 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
1654 * Call with hotkey_mutex held
1656 static int hotkey_set(int status
, u32 mask
)
1660 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1663 if (tp_features
.hotkey_mask
)
1664 for (i
= 0; i
< 32; i
++) {
1665 int bit
= ((1 << i
) & mask
) != 0;
1666 if (!acpi_evalf(hkey_handle
,
1667 NULL
, "MHKM", "vdd", i
+ 1, bit
))
1674 /* procfs -------------------------------------------------------------- */
1675 static int hotkey_read(char *p
)
1681 if (!tp_features
.hotkey
) {
1682 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1686 res
= mutex_lock_interruptible(&hotkey_mutex
);
1689 res
= hotkey_get(&status
, &mask
);
1690 mutex_unlock(&hotkey_mutex
);
1694 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
1695 if (tp_features
.hotkey_mask
) {
1696 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", mask
);
1697 len
+= sprintf(p
+ len
,
1698 "commands:\tenable, disable, reset, <mask>\n");
1700 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
1701 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
1707 static int hotkey_write(char *buf
)
1714 if (!tp_features
.hotkey
)
1717 res
= mutex_lock_interruptible(&hotkey_mutex
);
1721 res
= hotkey_get(&status
, &mask
);
1726 while ((cmd
= next_cmd(&buf
))) {
1727 if (strlencmp(cmd
, "enable") == 0) {
1729 } else if (strlencmp(cmd
, "disable") == 0) {
1731 } else if (strlencmp(cmd
, "reset") == 0) {
1732 status
= hotkey_orig_status
;
1733 mask
= hotkey_orig_mask
;
1734 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
1736 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
1746 res
= hotkey_set(status
, mask
);
1749 mutex_unlock(&hotkey_mutex
);
1753 static const struct acpi_device_id ibm_htk_device_ids
[] = {
1758 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
1759 .hid
= ibm_htk_device_ids
,
1760 .notify
= hotkey_notify
,
1761 .handle
= &hkey_handle
,
1762 .type
= ACPI_DEVICE_NOTIFY
,
1765 static struct ibm_struct hotkey_driver_data
= {
1767 .read
= hotkey_read
,
1768 .write
= hotkey_write
,
1769 .exit
= hotkey_exit
,
1770 .resume
= hotkey_resume
,
1771 .acpi
= &ibm_hotkey_acpidriver
,
1774 /*************************************************************************
1775 * Bluetooth subdriver
1778 /* sysfs bluetooth enable ---------------------------------------------- */
1779 static ssize_t
bluetooth_enable_show(struct device
*dev
,
1780 struct device_attribute
*attr
,
1785 status
= bluetooth_get_radiosw();
1789 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1792 static ssize_t
bluetooth_enable_store(struct device
*dev
,
1793 struct device_attribute
*attr
,
1794 const char *buf
, size_t count
)
1799 if (parse_strtoul(buf
, 1, &t
))
1802 res
= bluetooth_set_radiosw(t
);
1804 return (res
) ? res
: count
;
1807 static struct device_attribute dev_attr_bluetooth_enable
=
1808 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
1809 bluetooth_enable_show
, bluetooth_enable_store
);
1811 /* --------------------------------------------------------------------- */
1813 static struct attribute
*bluetooth_attributes
[] = {
1814 &dev_attr_bluetooth_enable
.attr
,
1818 static const struct attribute_group bluetooth_attr_group
= {
1819 .attrs
= bluetooth_attributes
,
1822 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
1827 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
1829 IBM_ACPIHANDLE_INIT(hkey
);
1831 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1832 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1833 tp_features
.bluetooth
= hkey_handle
&&
1834 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
1836 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
1837 str_supported(tp_features
.bluetooth
),
1840 if (tp_features
.bluetooth
) {
1841 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
1842 /* no bluetooth hardware present in system */
1843 tp_features
.bluetooth
= 0;
1844 dbg_printk(TPACPI_DBG_INIT
,
1845 "bluetooth hardware not installed\n");
1847 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1848 &bluetooth_attr_group
);
1854 return (tp_features
.bluetooth
)? 0 : 1;
1857 static void bluetooth_exit(void)
1859 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1860 &bluetooth_attr_group
);
1863 static int bluetooth_get_radiosw(void)
1867 if (!tp_features
.bluetooth
)
1870 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1873 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
1876 static int bluetooth_set_radiosw(int radio_on
)
1880 if (!tp_features
.bluetooth
)
1883 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1886 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
1888 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
1889 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
1895 /* procfs -------------------------------------------------------------- */
1896 static int bluetooth_read(char *p
)
1899 int status
= bluetooth_get_radiosw();
1901 if (!tp_features
.bluetooth
)
1902 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1904 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1905 (status
)? "enabled" : "disabled");
1906 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1912 static int bluetooth_write(char *buf
)
1916 if (!tp_features
.bluetooth
)
1919 while ((cmd
= next_cmd(&buf
))) {
1920 if (strlencmp(cmd
, "enable") == 0) {
1921 bluetooth_set_radiosw(1);
1922 } else if (strlencmp(cmd
, "disable") == 0) {
1923 bluetooth_set_radiosw(0);
1931 static struct ibm_struct bluetooth_driver_data
= {
1932 .name
= "bluetooth",
1933 .read
= bluetooth_read
,
1934 .write
= bluetooth_write
,
1935 .exit
= bluetooth_exit
,
1938 /*************************************************************************
1942 /* sysfs wan enable ---------------------------------------------------- */
1943 static ssize_t
wan_enable_show(struct device
*dev
,
1944 struct device_attribute
*attr
,
1949 status
= wan_get_radiosw();
1953 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1956 static ssize_t
wan_enable_store(struct device
*dev
,
1957 struct device_attribute
*attr
,
1958 const char *buf
, size_t count
)
1963 if (parse_strtoul(buf
, 1, &t
))
1966 res
= wan_set_radiosw(t
);
1968 return (res
) ? res
: count
;
1971 static struct device_attribute dev_attr_wan_enable
=
1972 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
1973 wan_enable_show
, wan_enable_store
);
1975 /* --------------------------------------------------------------------- */
1977 static struct attribute
*wan_attributes
[] = {
1978 &dev_attr_wan_enable
.attr
,
1982 static const struct attribute_group wan_attr_group
= {
1983 .attrs
= wan_attributes
,
1986 static int __init
wan_init(struct ibm_init_struct
*iibm
)
1991 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
1993 IBM_ACPIHANDLE_INIT(hkey
);
1995 tp_features
.wan
= hkey_handle
&&
1996 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
1998 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
1999 str_supported(tp_features
.wan
),
2002 if (tp_features
.wan
) {
2003 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
2004 /* no wan hardware present in system */
2005 tp_features
.wan
= 0;
2006 dbg_printk(TPACPI_DBG_INIT
,
2007 "wan hardware not installed\n");
2009 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2016 return (tp_features
.wan
)? 0 : 1;
2019 static void wan_exit(void)
2021 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2025 static int wan_get_radiosw(void)
2029 if (!tp_features
.wan
)
2032 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2035 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
2038 static int wan_set_radiosw(int radio_on
)
2042 if (!tp_features
.wan
)
2045 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2048 status
|= TP_ACPI_WANCARD_RADIOSSW
;
2050 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
2051 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
2057 /* procfs -------------------------------------------------------------- */
2058 static int wan_read(char *p
)
2061 int status
= wan_get_radiosw();
2063 if (!tp_features
.wan
)
2064 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2066 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2067 (status
)? "enabled" : "disabled");
2068 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2074 static int wan_write(char *buf
)
2078 if (!tp_features
.wan
)
2081 while ((cmd
= next_cmd(&buf
))) {
2082 if (strlencmp(cmd
, "enable") == 0) {
2084 } else if (strlencmp(cmd
, "disable") == 0) {
2093 static struct ibm_struct wan_driver_data
= {
2098 .flags
.experimental
= 1,
2101 /*************************************************************************
2105 static enum video_access_mode video_supported
;
2106 static int video_orig_autosw
;
2108 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
2109 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
2110 "\\_SB.PCI0.VID0", /* 770e */
2111 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
2112 "\\_SB.PCI0.AGP.VID", /* all others */
2115 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
2117 static int __init
video_init(struct ibm_init_struct
*iibm
)
2121 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
2123 IBM_ACPIHANDLE_INIT(vid
);
2124 IBM_ACPIHANDLE_INIT(vid2
);
2126 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
2127 /* G41, assume IVGA doesn't change */
2128 vid_handle
= vid2_handle
;
2131 /* video switching not supported on R30, R31 */
2132 video_supported
= TPACPI_VIDEO_NONE
;
2133 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
2135 video_supported
= TPACPI_VIDEO_570
;
2136 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
2137 /* 600e/x, 770e, 770x */
2138 video_supported
= TPACPI_VIDEO_770
;
2141 video_supported
= TPACPI_VIDEO_NEW
;
2143 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
2144 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
2147 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
2150 static void video_exit(void)
2152 dbg_printk(TPACPI_DBG_EXIT
,
2153 "restoring original video autoswitch mode\n");
2154 if (video_autosw_set(video_orig_autosw
))
2155 printk(IBM_ERR
"error while trying to restore original "
2156 "video autoswitch mode\n");
2159 static int video_outputsw_get(void)
2164 switch (video_supported
) {
2165 case TPACPI_VIDEO_570
:
2166 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
2167 TP_ACPI_VIDEO_570_PHSCMD
))
2169 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
2171 case TPACPI_VIDEO_770
:
2172 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2175 status
|= TP_ACPI_VIDEO_S_LCD
;
2176 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2179 status
|= TP_ACPI_VIDEO_S_CRT
;
2181 case TPACPI_VIDEO_NEW
:
2182 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
2183 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2186 status
|= TP_ACPI_VIDEO_S_CRT
;
2188 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
2189 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2192 status
|= TP_ACPI_VIDEO_S_LCD
;
2193 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
2196 status
|= TP_ACPI_VIDEO_S_DVI
;
2205 static int video_outputsw_set(int status
)
2210 switch (video_supported
) {
2211 case TPACPI_VIDEO_570
:
2212 res
= acpi_evalf(NULL
, NULL
,
2213 "\\_SB.PHS2", "vdd",
2214 TP_ACPI_VIDEO_570_PHS2CMD
,
2215 status
| TP_ACPI_VIDEO_570_PHS2SET
);
2217 case TPACPI_VIDEO_770
:
2218 autosw
= video_autosw_get();
2222 res
= video_autosw_set(1);
2225 res
= acpi_evalf(vid_handle
, NULL
,
2226 "ASWT", "vdd", status
* 0x100, 0);
2227 if (!autosw
&& video_autosw_set(autosw
)) {
2228 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
2232 case TPACPI_VIDEO_NEW
:
2233 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
2234 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
2240 return (res
)? 0 : -EIO
;
2243 static int video_autosw_get(void)
2247 switch (video_supported
) {
2248 case TPACPI_VIDEO_570
:
2249 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
2252 case TPACPI_VIDEO_770
:
2253 case TPACPI_VIDEO_NEW
:
2254 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
2264 static int video_autosw_set(int enable
)
2266 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
2271 static int video_outputsw_cycle(void)
2273 int autosw
= video_autosw_get();
2279 switch (video_supported
) {
2280 case TPACPI_VIDEO_570
:
2281 res
= video_autosw_set(1);
2284 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
2286 case TPACPI_VIDEO_770
:
2287 case TPACPI_VIDEO_NEW
:
2288 res
= video_autosw_set(1);
2291 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
2296 if (!autosw
&& video_autosw_set(autosw
)) {
2297 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
2301 return (res
)? 0 : -EIO
;
2304 static int video_expand_toggle(void)
2306 switch (video_supported
) {
2307 case TPACPI_VIDEO_570
:
2308 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
2310 case TPACPI_VIDEO_770
:
2311 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
2313 case TPACPI_VIDEO_NEW
:
2314 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
2322 static int video_read(char *p
)
2327 if (video_supported
== TPACPI_VIDEO_NONE
) {
2328 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2332 status
= video_outputsw_get();
2336 autosw
= video_autosw_get();
2340 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2341 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
2342 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
2343 if (video_supported
== TPACPI_VIDEO_NEW
)
2344 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
2345 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
2346 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
2347 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
2348 if (video_supported
== TPACPI_VIDEO_NEW
)
2349 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
2350 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
2351 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
2356 static int video_write(char *buf
)
2359 int enable
, disable
, status
;
2362 if (video_supported
== TPACPI_VIDEO_NONE
)
2368 while ((cmd
= next_cmd(&buf
))) {
2369 if (strlencmp(cmd
, "lcd_enable") == 0) {
2370 enable
|= TP_ACPI_VIDEO_S_LCD
;
2371 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
2372 disable
|= TP_ACPI_VIDEO_S_LCD
;
2373 } else if (strlencmp(cmd
, "crt_enable") == 0) {
2374 enable
|= TP_ACPI_VIDEO_S_CRT
;
2375 } else if (strlencmp(cmd
, "crt_disable") == 0) {
2376 disable
|= TP_ACPI_VIDEO_S_CRT
;
2377 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2378 strlencmp(cmd
, "dvi_enable") == 0) {
2379 enable
|= TP_ACPI_VIDEO_S_DVI
;
2380 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2381 strlencmp(cmd
, "dvi_disable") == 0) {
2382 disable
|= TP_ACPI_VIDEO_S_DVI
;
2383 } else if (strlencmp(cmd
, "auto_enable") == 0) {
2384 res
= video_autosw_set(1);
2387 } else if (strlencmp(cmd
, "auto_disable") == 0) {
2388 res
= video_autosw_set(0);
2391 } else if (strlencmp(cmd
, "video_switch") == 0) {
2392 res
= video_outputsw_cycle();
2395 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
2396 res
= video_expand_toggle();
2403 if (enable
|| disable
) {
2404 status
= video_outputsw_get();
2407 res
= video_outputsw_set((status
& ~disable
) | enable
);
2415 static struct ibm_struct video_driver_data
= {
2418 .write
= video_write
,
2422 /*************************************************************************
2423 * Light (thinklight) subdriver
2426 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
2427 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
2429 static int __init
light_init(struct ibm_init_struct
*iibm
)
2431 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
2433 IBM_ACPIHANDLE_INIT(ledb
);
2434 IBM_ACPIHANDLE_INIT(lght
);
2435 IBM_ACPIHANDLE_INIT(cmos
);
2437 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
2438 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
2440 if (tp_features
.light
)
2441 /* light status not supported on
2442 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
2443 tp_features
.light_status
=
2444 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
2446 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
2447 str_supported(tp_features
.light
));
2449 return (tp_features
.light
)? 0 : 1;
2452 static int light_read(char *p
)
2457 if (!tp_features
.light
) {
2458 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2459 } else if (!tp_features
.light_status
) {
2460 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
2461 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2463 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
2465 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
2466 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2472 static int light_write(char *buf
)
2474 int cmos_cmd
, lght_cmd
;
2478 if (!tp_features
.light
)
2481 while ((cmd
= next_cmd(&buf
))) {
2482 if (strlencmp(cmd
, "on") == 0) {
2485 } else if (strlencmp(cmd
, "off") == 0) {
2491 success
= cmos_handle
?
2492 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
2493 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
2501 static struct ibm_struct light_driver_data
= {
2504 .write
= light_write
,
2507 /*************************************************************************
2511 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2513 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
2514 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
2515 "\\_SB.PCI0.PCI1.DOCK", /* all others */
2516 "\\_SB.PCI.ISA.SLCE", /* 570 */
2517 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
2519 /* don't list other alternatives as we install a notify handler on the 570 */
2520 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
2522 static const struct acpi_device_id ibm_pci_device_ids
[] = {
2523 {PCI_ROOT_HID_STRING
, 0},
2527 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
2529 .notify
= dock_notify
,
2530 .handle
= &dock_handle
,
2531 .type
= ACPI_SYSTEM_NOTIFY
,
2534 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
2535 * We just use it to get notifications of dock hotplug
2536 * in very old thinkpads */
2537 .hid
= ibm_pci_device_ids
,
2538 .notify
= dock_notify
,
2539 .handle
= &pci_handle
,
2540 .type
= ACPI_SYSTEM_NOTIFY
,
2544 static struct ibm_struct dock_driver_data
[2] = {
2548 .write
= dock_write
,
2549 .acpi
= &ibm_dock_acpidriver
[0],
2553 .acpi
= &ibm_dock_acpidriver
[1],
2557 #define dock_docked() (_sta(dock_handle) & 1)
2559 static int __init
dock_init(struct ibm_init_struct
*iibm
)
2561 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
2563 IBM_ACPIHANDLE_INIT(dock
);
2565 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
2566 str_supported(dock_handle
!= NULL
));
2568 return (dock_handle
)? 0 : 1;
2571 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
2575 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
2577 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
2578 dock_driver_data
[0].flags
.acpi_notify_installed
) {
2579 IBM_ACPIHANDLE_INIT(pci
);
2580 dock2_needed
= (pci_handle
!= NULL
);
2581 vdbg_printk(TPACPI_DBG_INIT
,
2582 "dock PCI handler for the TP 570 is %s\n",
2583 str_supported(dock2_needed
));
2585 vdbg_printk(TPACPI_DBG_INIT
,
2586 "dock subdriver part 2 not required\n");
2590 return (dock2_needed
)? 0 : 1;
2593 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
2595 int docked
= dock_docked();
2596 int pci
= ibm
->acpi
->hid
&& ibm
->acpi
->device
&&
2597 acpi_match_device_ids(ibm
->acpi
->device
, ibm_pci_device_ids
);
2600 if (event
== 1 && !pci
) /* 570 */
2601 data
= 1; /* button */
2602 else if (event
== 1 && pci
) /* 570 */
2603 data
= 3; /* dock */
2604 else if (event
== 3 && docked
)
2605 data
= 1; /* button */
2606 else if (event
== 3 && !docked
)
2607 data
= 2; /* undock */
2608 else if (event
== 0 && docked
)
2609 data
= 3; /* dock */
2611 printk(IBM_ERR
"unknown dock event %d, status %d\n",
2612 event
, _sta(dock_handle
));
2613 data
= 0; /* unknown */
2615 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, data
);
2616 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
2617 ibm
->acpi
->device
->dev
.bus_id
,
2621 static int dock_read(char *p
)
2624 int docked
= dock_docked();
2627 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2629 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
2631 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
2632 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
2638 static int dock_write(char *buf
)
2645 while ((cmd
= next_cmd(&buf
))) {
2646 if (strlencmp(cmd
, "undock") == 0) {
2647 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
2648 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
2650 } else if (strlencmp(cmd
, "dock") == 0) {
2651 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
2660 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
2662 /*************************************************************************
2666 #ifdef CONFIG_THINKPAD_ACPI_BAY
2667 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
2668 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
2669 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
2670 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
2671 ); /* A21e, R30, R31 */
2672 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
2673 "_EJ0", /* all others */
2674 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
2675 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
2676 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
2678 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
2682 static int __init
bay_init(struct ibm_init_struct
*iibm
)
2684 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
2686 IBM_ACPIHANDLE_INIT(bay
);
2688 IBM_ACPIHANDLE_INIT(bay_ej
);
2689 IBM_ACPIHANDLE_INIT(bay2
);
2691 IBM_ACPIHANDLE_INIT(bay2_ej
);
2693 tp_features
.bay_status
= bay_handle
&&
2694 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
2695 tp_features
.bay_status2
= bay2_handle
&&
2696 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
2698 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
2699 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
2700 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
2701 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
2703 vdbg_printk(TPACPI_DBG_INIT
,
2704 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
2705 str_supported(tp_features
.bay_status
),
2706 str_supported(tp_features
.bay_eject
),
2707 str_supported(tp_features
.bay_status2
),
2708 str_supported(tp_features
.bay_eject2
));
2710 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
2711 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
2714 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
2716 acpi_bus_generate_proc_event(ibm
->acpi
->device
, event
, 0);
2717 acpi_bus_generate_netlink_event(ibm
->acpi
->device
->pnp
.device_class
,
2718 ibm
->acpi
->device
->dev
.bus_id
,
2722 #define bay_occupied(b) (_sta(b##_handle) & 1)
2724 static int bay_read(char *p
)
2727 int occupied
= bay_occupied(bay
);
2728 int occupied2
= bay_occupied(bay2
);
2731 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2732 tp_features
.bay_status
?
2733 (occupied
? "occupied" : "unoccupied") :
2735 if (tp_features
.bay_status2
)
2736 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
2737 "occupied" : "unoccupied");
2739 eject
= tp_features
.bay_eject
&& occupied
;
2740 eject2
= tp_features
.bay_eject2
&& occupied2
;
2742 if (eject
&& eject2
)
2743 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
2745 len
+= sprintf(p
+ len
, "commands:\teject\n");
2747 len
+= sprintf(p
+ len
, "commands:\teject2\n");
2752 static int bay_write(char *buf
)
2756 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
2759 while ((cmd
= next_cmd(&buf
))) {
2760 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
2761 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
2763 } else if (tp_features
.bay_eject2
&&
2764 strlencmp(cmd
, "eject2") == 0) {
2765 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
2774 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
2775 .notify
= bay_notify
,
2776 .handle
= &bay_handle
,
2777 .type
= ACPI_SYSTEM_NOTIFY
,
2780 static struct ibm_struct bay_driver_data
= {
2784 .acpi
= &ibm_bay_acpidriver
,
2787 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2789 /*************************************************************************
2793 /* sysfs cmos_command -------------------------------------------------- */
2794 static ssize_t
cmos_command_store(struct device
*dev
,
2795 struct device_attribute
*attr
,
2796 const char *buf
, size_t count
)
2798 unsigned long cmos_cmd
;
2801 if (parse_strtoul(buf
, 21, &cmos_cmd
))
2804 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2805 return (res
)? res
: count
;
2808 static struct device_attribute dev_attr_cmos_command
=
2809 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
2811 /* --------------------------------------------------------------------- */
2813 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
2817 vdbg_printk(TPACPI_DBG_INIT
,
2818 "initializing cmos commands subdriver\n");
2820 IBM_ACPIHANDLE_INIT(cmos
);
2822 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
2823 str_supported(cmos_handle
!= NULL
));
2825 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2829 return (cmos_handle
)? 0 : 1;
2832 static void cmos_exit(void)
2834 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2837 static int cmos_read(char *p
)
2841 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2842 R30, R31, T20-22, X20-21 */
2844 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2846 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2847 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
2853 static int cmos_write(char *buf
)
2858 while ((cmd
= next_cmd(&buf
))) {
2859 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
2860 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
2865 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2873 static struct ibm_struct cmos_driver_data
= {
2876 .write
= cmos_write
,
2880 /*************************************************************************
2884 static enum led_access_mode led_supported
;
2886 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
2887 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2888 "LED", /* all others */
2891 static int __init
led_init(struct ibm_init_struct
*iibm
)
2893 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
2895 IBM_ACPIHANDLE_INIT(led
);
2898 /* led not supported on R30, R31 */
2899 led_supported
= TPACPI_LED_NONE
;
2900 else if (strlencmp(led_path
, "SLED") == 0)
2902 led_supported
= TPACPI_LED_570
;
2903 else if (strlencmp(led_path
, "SYSL") == 0)
2904 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2905 led_supported
= TPACPI_LED_OLD
;
2908 led_supported
= TPACPI_LED_NEW
;
2910 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
2911 str_supported(led_supported
), led_supported
);
2913 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
2916 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2918 static int led_read(char *p
)
2922 if (!led_supported
) {
2923 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2926 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2928 if (led_supported
== TPACPI_LED_570
) {
2931 for (i
= 0; i
< 8; i
++) {
2932 if (!acpi_evalf(ec_handle
,
2933 &status
, "GLED", "dd", 1 << i
))
2935 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
2936 i
, led_status(status
));
2940 len
+= sprintf(p
+ len
, "commands:\t"
2941 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2946 /* off, on, blink */
2947 static const int led_sled_arg1
[] = { 0, 1, 3 };
2948 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
2949 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
2950 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
2952 static int led_write(char *buf
)
2960 while ((cmd
= next_cmd(&buf
))) {
2961 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
2964 if (strstr(cmd
, "off")) {
2966 } else if (strstr(cmd
, "on")) {
2968 } else if (strstr(cmd
, "blink")) {
2973 if (led_supported
== TPACPI_LED_570
) {
2976 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2977 led
, led_sled_arg1
[ind
]))
2979 } else if (led_supported
== TPACPI_LED_OLD
) {
2980 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2982 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
2985 ec_write(TPACPI_LED_EC_HLBL
,
2986 led
* led_exp_hlbl
[ind
]);
2989 ec_write(TPACPI_LED_EC_HLCL
,
2990 led
* led_exp_hlcl
[ind
]);
2995 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2996 led
, led_led_arg1
[ind
]))
3004 static struct ibm_struct led_driver_data
= {
3010 /*************************************************************************
3014 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
3016 static int __init
beep_init(struct ibm_init_struct
*iibm
)
3018 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
3020 IBM_ACPIHANDLE_INIT(beep
);
3022 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
3023 str_supported(beep_handle
!= NULL
));
3025 return (beep_handle
)? 0 : 1;
3028 static int beep_read(char *p
)
3033 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3035 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3036 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
3042 static int beep_write(char *buf
)
3050 while ((cmd
= next_cmd(&buf
))) {
3051 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
3052 beep_cmd
>= 0 && beep_cmd
<= 17) {
3056 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
3063 static struct ibm_struct beep_driver_data
= {
3066 .write
= beep_write
,
3069 /*************************************************************************
3073 static enum thermal_access_mode thermal_read_mode
;
3075 /* sysfs temp##_input -------------------------------------------------- */
3077 static ssize_t
thermal_temp_input_show(struct device
*dev
,
3078 struct device_attribute
*attr
,
3081 struct sensor_device_attribute
*sensor_attr
=
3082 to_sensor_dev_attr(attr
);
3083 int idx
= sensor_attr
->index
;
3087 res
= thermal_get_sensor(idx
, &value
);
3090 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
3093 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
3096 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
3097 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
3099 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
3100 THERMAL_SENSOR_ATTR_TEMP(1, 0),
3101 THERMAL_SENSOR_ATTR_TEMP(2, 1),
3102 THERMAL_SENSOR_ATTR_TEMP(3, 2),
3103 THERMAL_SENSOR_ATTR_TEMP(4, 3),
3104 THERMAL_SENSOR_ATTR_TEMP(5, 4),
3105 THERMAL_SENSOR_ATTR_TEMP(6, 5),
3106 THERMAL_SENSOR_ATTR_TEMP(7, 6),
3107 THERMAL_SENSOR_ATTR_TEMP(8, 7),
3108 THERMAL_SENSOR_ATTR_TEMP(9, 8),
3109 THERMAL_SENSOR_ATTR_TEMP(10, 9),
3110 THERMAL_SENSOR_ATTR_TEMP(11, 10),
3111 THERMAL_SENSOR_ATTR_TEMP(12, 11),
3112 THERMAL_SENSOR_ATTR_TEMP(13, 12),
3113 THERMAL_SENSOR_ATTR_TEMP(14, 13),
3114 THERMAL_SENSOR_ATTR_TEMP(15, 14),
3115 THERMAL_SENSOR_ATTR_TEMP(16, 15),
3118 #define THERMAL_ATTRS(X) \
3119 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
3121 static struct attribute
*thermal_temp_input_attr
[] = {
3141 static const struct attribute_group thermal_temp_input16_group
= {
3142 .attrs
= thermal_temp_input_attr
3145 static const struct attribute_group thermal_temp_input8_group
= {
3146 .attrs
= &thermal_temp_input_attr
[8]
3149 #undef THERMAL_SENSOR_ATTR_TEMP
3150 #undef THERMAL_ATTRS
3152 /* --------------------------------------------------------------------- */
3154 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
3161 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
3163 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
3165 if (thinkpad_id
.ec_model
) {
3167 * Direct EC access mode: sensors at registers
3168 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
3169 * non-implemented, thermal sensors return 0x80 when
3174 for (i
= 0; i
< 8; i
++) {
3175 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
3181 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
3189 /* This is sheer paranoia, but we handle it anyway */
3192 "ThinkPad ACPI EC access misbehaving, "
3193 "falling back to ACPI TMPx access mode\n");
3194 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
3197 "ThinkPad ACPI EC access misbehaving, "
3198 "disabling thermal sensors access\n");
3199 thermal_read_mode
= TPACPI_THERMAL_NONE
;
3204 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
3206 } else if (acpi_tmp7
) {
3207 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
3208 /* 600e/x, 770e, 770x */
3209 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
3211 /* Standard ACPI TMPx access, max 8 sensors */
3212 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
3215 /* temperatures not supported on 570, G4x, R30, R31, R32 */
3216 thermal_read_mode
= TPACPI_THERMAL_NONE
;
3219 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
3220 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
3223 switch(thermal_read_mode
) {
3224 case TPACPI_THERMAL_TPEC_16
:
3225 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3226 &thermal_temp_input16_group
);
3230 case TPACPI_THERMAL_TPEC_8
:
3231 case TPACPI_THERMAL_ACPI_TMP07
:
3232 case TPACPI_THERMAL_ACPI_UPDT
:
3233 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3234 &thermal_temp_input8_group
);
3238 case TPACPI_THERMAL_NONE
:
3246 static void thermal_exit(void)
3248 switch(thermal_read_mode
) {
3249 case TPACPI_THERMAL_TPEC_16
:
3250 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3251 &thermal_temp_input16_group
);
3253 case TPACPI_THERMAL_TPEC_8
:
3254 case TPACPI_THERMAL_ACPI_TMP07
:
3255 case TPACPI_THERMAL_ACPI_UPDT
:
3256 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3257 &thermal_temp_input16_group
);
3259 case TPACPI_THERMAL_NONE
:
3265 /* idx is zero-based */
3266 static int thermal_get_sensor(int idx
, s32
*value
)
3272 t
= TP_EC_THERMAL_TMP0
;
3274 switch (thermal_read_mode
) {
3275 #if TPACPI_MAX_THERMAL_SENSORS >= 16
3276 case TPACPI_THERMAL_TPEC_16
:
3277 if (idx
>= 8 && idx
<= 15) {
3278 t
= TP_EC_THERMAL_TMP8
;
3283 case TPACPI_THERMAL_TPEC_8
:
3285 if (!acpi_ec_read(t
+ idx
, &tmp
))
3287 *value
= tmp
* 1000;
3292 case TPACPI_THERMAL_ACPI_UPDT
:
3294 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3295 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
3297 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3299 *value
= (t
- 2732) * 100;
3304 case TPACPI_THERMAL_ACPI_TMP07
:
3306 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3307 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3309 if (t
> 127 || t
< -127)
3310 t
= TP_EC_THERMAL_TMP_NA
;
3316 case TPACPI_THERMAL_NONE
:
3324 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
3335 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
3338 for(i
= 0 ; i
< n
; i
++) {
3339 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
3347 static int thermal_read(char *p
)
3351 struct ibm_thermal_sensors_struct t
;
3353 n
= thermal_get_sensors(&t
);
3354 if (unlikely(n
< 0))
3357 len
+= sprintf(p
+ len
, "temperatures:\t");
3360 for (i
= 0; i
< (n
- 1); i
++)
3361 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
3362 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
3364 len
+= sprintf(p
+ len
, "not supported\n");
3369 static struct ibm_struct thermal_driver_data
= {
3371 .read
= thermal_read
,
3372 .exit
= thermal_exit
,
3375 /*************************************************************************
3379 static u8 ecdump_regs
[256];
3381 static int ecdump_read(char *p
)
3387 len
+= sprintf(p
+ len
, "EC "
3388 " +00 +01 +02 +03 +04 +05 +06 +07"
3389 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
3390 for (i
= 0; i
< 256; i
+= 16) {
3391 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
3392 for (j
= 0; j
< 16; j
++) {
3393 if (!acpi_ec_read(i
+ j
, &v
))
3395 if (v
!= ecdump_regs
[i
+ j
])
3396 len
+= sprintf(p
+ len
, " *%02x", v
);
3398 len
+= sprintf(p
+ len
, " %02x", v
);
3399 ecdump_regs
[i
+ j
] = v
;
3401 len
+= sprintf(p
+ len
, "\n");
3406 /* These are way too dangerous to advertise openly... */
3408 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
3409 " (<offset> is 00-ff, <value> is 00-ff)\n");
3410 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
3411 " (<offset> is 00-ff, <value> is 0-255)\n");
3416 static int ecdump_write(char *buf
)
3421 while ((cmd
= next_cmd(&buf
))) {
3422 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
3424 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
3428 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
3429 if (!acpi_ec_write(i
, v
))
3438 static struct ibm_struct ecdump_driver_data
= {
3440 .read
= ecdump_read
,
3441 .write
= ecdump_write
,
3442 .flags
.experimental
= 1,
3445 /*************************************************************************
3446 * Backlight/brightness subdriver
3449 static struct backlight_device
*ibm_backlight_device
;
3451 static struct backlight_ops ibm_backlight_data
= {
3452 .get_brightness
= brightness_get
,
3453 .update_status
= brightness_update_status
,
3456 static struct mutex brightness_mutex
;
3458 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
3462 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
3464 mutex_init(&brightness_mutex
);
3466 if (!brightness_mode
) {
3467 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
3468 brightness_mode
= 2;
3470 brightness_mode
= 3;
3472 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
3476 if (brightness_mode
> 3)
3479 b
= brightness_get(NULL
);
3483 ibm_backlight_device
= backlight_device_register(
3484 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
3485 &ibm_backlight_data
);
3486 if (IS_ERR(ibm_backlight_device
)) {
3487 printk(IBM_ERR
"Could not register backlight device\n");
3488 return PTR_ERR(ibm_backlight_device
);
3490 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
3492 ibm_backlight_device
->props
.max_brightness
= 7;
3493 ibm_backlight_device
->props
.brightness
= b
;
3494 backlight_update_status(ibm_backlight_device
);
3499 static void brightness_exit(void)
3501 if (ibm_backlight_device
) {
3502 vdbg_printk(TPACPI_DBG_EXIT
,
3503 "calling backlight_device_unregister()\n");
3504 backlight_device_unregister(ibm_backlight_device
);
3505 ibm_backlight_device
= NULL
;
3509 static int brightness_update_status(struct backlight_device
*bd
)
3511 return brightness_set(
3512 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
3513 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
3514 bd
->props
.brightness
: 0);
3518 * ThinkPads can read brightness from two places: EC 0x31, or
3519 * CMOS NVRAM byte 0x5E, bits 0-3.
3521 static int brightness_get(struct backlight_device
*bd
)
3523 u8 lec
= 0, lcmos
= 0, level
= 0;
3525 if (brightness_mode
& 1) {
3526 if (!acpi_ec_read(brightness_offset
, &lec
))
3531 if (brightness_mode
& 2) {
3532 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
3533 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
3534 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
3538 if (brightness_mode
== 3 && lec
!= lcmos
) {
3540 "CMOS NVRAM (%u) and EC (%u) do not agree "
3541 "on display brightness level\n",
3542 (unsigned int) lcmos
,
3543 (unsigned int) lec
);
3550 static int brightness_set(int value
)
3552 int cmos_cmd
, inc
, i
, res
;
3558 res
= mutex_lock_interruptible(&brightness_mutex
);
3562 current_value
= brightness_get(NULL
);
3563 if (current_value
< 0) {
3564 res
= current_value
;
3568 cmos_cmd
= value
> current_value
?
3569 TP_CMOS_BRIGHTNESS_UP
:
3570 TP_CMOS_BRIGHTNESS_DOWN
;
3571 inc
= value
> current_value
? 1 : -1;
3574 for (i
= current_value
; i
!= value
; i
+= inc
) {
3575 if ((brightness_mode
& 2) &&
3576 issue_thinkpad_cmos_command(cmos_cmd
)) {
3580 if ((brightness_mode
& 1) &&
3581 !acpi_ec_write(brightness_offset
, i
+ inc
)) {
3588 mutex_unlock(&brightness_mutex
);
3592 static int brightness_read(char *p
)
3597 if ((level
= brightness_get(NULL
)) < 0) {
3598 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3600 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
3601 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
3602 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3603 " (<level> is 0-7)\n");
3609 static int brightness_write(char *buf
)
3615 while ((cmd
= next_cmd(&buf
))) {
3616 if ((level
= brightness_get(NULL
)) < 0)
3620 if (strlencmp(cmd
, "up") == 0) {
3621 new_level
= level
== 7 ? 7 : level
+ 1;
3622 } else if (strlencmp(cmd
, "down") == 0) {
3623 new_level
= level
== 0 ? 0 : level
- 1;
3624 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3625 new_level
>= 0 && new_level
<= 7) {
3630 brightness_set(new_level
);
3636 static struct ibm_struct brightness_driver_data
= {
3637 .name
= "brightness",
3638 .read
= brightness_read
,
3639 .write
= brightness_write
,
3640 .exit
= brightness_exit
,
3643 /*************************************************************************
3647 static int volume_read(char *p
)
3652 if (!acpi_ec_read(volume_offset
, &level
)) {
3653 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3655 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
3656 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
3657 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
3658 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3659 " (<level> is 0-15)\n");
3665 static int volume_write(char *buf
)
3667 int cmos_cmd
, inc
, i
;
3669 int new_level
, new_mute
;
3672 while ((cmd
= next_cmd(&buf
))) {
3673 if (!acpi_ec_read(volume_offset
, &level
))
3675 new_mute
= mute
= level
& 0x40;
3676 new_level
= level
= level
& 0xf;
3678 if (strlencmp(cmd
, "up") == 0) {
3682 new_level
= level
== 15 ? 15 : level
+ 1;
3683 } else if (strlencmp(cmd
, "down") == 0) {
3687 new_level
= level
== 0 ? 0 : level
- 1;
3688 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3689 new_level
>= 0 && new_level
<= 15) {
3691 } else if (strlencmp(cmd
, "mute") == 0) {
3696 if (new_level
!= level
) { /* mute doesn't change */
3697 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
3698 inc
= new_level
> level
? 1 : -1;
3700 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
3701 !acpi_ec_write(volume_offset
, level
)))
3704 for (i
= level
; i
!= new_level
; i
+= inc
)
3705 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3706 !acpi_ec_write(volume_offset
, i
+ inc
))
3709 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
3710 !acpi_ec_write(volume_offset
,
3715 if (new_mute
!= mute
) { /* level doesn't change */
3716 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
3718 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3719 !acpi_ec_write(volume_offset
, level
+ new_mute
))
3727 static struct ibm_struct volume_driver_data
= {
3729 .read
= volume_read
,
3730 .write
= volume_write
,
3733 /*************************************************************************
3740 * TPACPI_FAN_RD_ACPI_GFAN:
3741 * ACPI GFAN method: returns fan level
3743 * see TPACPI_FAN_WR_ACPI_SFAN
3744 * EC 0x2f (HFSP) not available if GFAN exists
3746 * TPACPI_FAN_WR_ACPI_SFAN:
3747 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
3749 * EC 0x2f (HFSP) might be available *for reading*, but do not use
3752 * TPACPI_FAN_WR_TPEC:
3753 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
3754 * Supported on almost all ThinkPads
3756 * Fan speed changes of any sort (including those caused by the
3757 * disengaged mode) are usually done slowly by the firmware as the
3758 * maximum ammount of fan duty cycle change per second seems to be
3761 * Reading is not available if GFAN exists.
3762 * Writing is not available if SFAN exists.
3765 * 7 automatic mode engaged;
3766 * (default operation mode of the ThinkPad)
3767 * fan level is ignored in this mode.
3768 * 6 full speed mode (takes precedence over bit 7);
3769 * not available on all thinkpads. May disable
3770 * the tachometer while the fan controller ramps up
3771 * the speed (which can take up to a few *minutes*).
3772 * Speeds up fan to 100% duty-cycle, which is far above
3773 * the standard RPM levels. It is not impossible that
3774 * it could cause hardware damage.
3775 * 5-3 unused in some models. Extra bits for fan level
3776 * in others, but still useless as all values above
3777 * 7 map to the same speed as level 7 in these models.
3778 * 2-0 fan level (0..7 usually)
3780 * 0x07 = max (set when temperatures critical)
3781 * Some ThinkPads may have other levels, see
3782 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
3784 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
3785 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
3786 * does so, its initial value is meaningless (0x07).
3788 * For firmware bugs, refer to:
3789 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3793 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
3794 * Main fan tachometer reading (in RPM)
3796 * This register is present on all ThinkPads with a new-style EC, and
3797 * it is known not to be present on the A21m/e, and T22, as there is
3798 * something else in offset 0x84 according to the ACPI DSDT. Other
3799 * ThinkPads from this same time period (and earlier) probably lack the
3800 * tachometer as well.
3802 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
3803 * was never fixed by IBM to report the EC firmware version string
3804 * probably support the tachometer (like the early X models), so
3805 * detecting it is quite hard. We need more data to know for sure.
3807 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
3810 * FIRMWARE BUG: may go stale while the EC is switching to full speed
3813 * For firmware bugs, refer to:
3814 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3816 * TPACPI_FAN_WR_ACPI_FANS:
3817 * ThinkPad X31, X40, X41. Not available in the X60.
3819 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3820 * high speed. ACPI DSDT seems to map these three speeds to levels
3821 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3822 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3824 * The speeds are stored on handles
3825 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3827 * There are three default speed sets, acessible as handles:
3828 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3830 * ACPI DSDT switches which set is in use depending on various
3833 * TPACPI_FAN_WR_TPEC is also available and should be used to
3834 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3835 * but the ACPI tables just mention level 7.
3838 static enum fan_status_access_mode fan_status_access_mode
;
3839 static enum fan_control_access_mode fan_control_access_mode
;
3840 static enum fan_control_commands fan_control_commands
;
3842 static u8 fan_control_initial_status
;
3843 static u8 fan_control_desired_level
;
3845 static void fan_watchdog_fire(struct work_struct
*ignored
);
3846 static int fan_watchdog_maxinterval
;
3847 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
3849 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
3850 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
3851 "\\FSPD", /* 600e/x, 770e, 770x */
3853 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
3854 "JFNS", /* 770x-JL */
3858 * SYSFS fan layout: hwmon compatible (device)
3861 * 0: "disengaged" mode
3863 * 2: native EC "auto" mode (recommended, hardware default)
3865 * pwm*: set speed in manual mode, ignored otherwise.
3866 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3869 * fan*_input: tachometer reading, RPM
3872 * SYSFS fan layout: extensions
3874 * fan_watchdog (driver):
3875 * fan watchdog interval in seconds, 0 disables (default), max 120
3878 /* sysfs fan pwm1_enable ----------------------------------------------- */
3879 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
3880 struct device_attribute
*attr
,
3886 res
= fan_get_status_safe(&status
);
3890 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3891 if (status
!= fan_control_initial_status
) {
3892 tp_features
.fan_ctrl_status_undef
= 0;
3894 /* Return most likely status. In fact, it
3895 * might be the only possible status */
3896 status
= TP_EC_FAN_AUTO
;
3900 if (status
& TP_EC_FAN_FULLSPEED
) {
3902 } else if (status
& TP_EC_FAN_AUTO
) {
3907 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
3910 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
3911 struct device_attribute
*attr
,
3912 const char *buf
, size_t count
)
3917 if (parse_strtoul(buf
, 2, &t
))
3922 level
= TP_EC_FAN_FULLSPEED
;
3925 level
= TPACPI_FAN_LAST_LEVEL
;
3928 level
= TP_EC_FAN_AUTO
;
3931 /* reserved for software-controlled auto mode */
3937 res
= fan_set_level_safe(level
);
3943 fan_watchdog_reset();
3948 static struct device_attribute dev_attr_fan_pwm1_enable
=
3949 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
3950 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
3952 /* sysfs fan pwm1 ------------------------------------------------------ */
3953 static ssize_t
fan_pwm1_show(struct device
*dev
,
3954 struct device_attribute
*attr
,
3960 res
= fan_get_status_safe(&status
);
3964 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3965 if (status
!= fan_control_initial_status
) {
3966 tp_features
.fan_ctrl_status_undef
= 0;
3968 status
= TP_EC_FAN_AUTO
;
3973 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
3974 status
= fan_control_desired_level
;
3979 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
3982 static ssize_t
fan_pwm1_store(struct device
*dev
,
3983 struct device_attribute
*attr
,
3984 const char *buf
, size_t count
)
3988 u8 status
, newlevel
;
3990 if (parse_strtoul(buf
, 255, &s
))
3993 /* scale down from 0-255 to 0-7 */
3994 newlevel
= (s
>> 5) & 0x07;
3996 rc
= mutex_lock_interruptible(&fan_mutex
);
4000 rc
= fan_get_status(&status
);
4001 if (!rc
&& (status
&
4002 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
4003 rc
= fan_set_level(newlevel
);
4007 fan_update_desired_level(newlevel
);
4008 fan_watchdog_reset();
4012 mutex_unlock(&fan_mutex
);
4013 return (rc
)? rc
: count
;
4016 static struct device_attribute dev_attr_fan_pwm1
=
4017 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
4018 fan_pwm1_show
, fan_pwm1_store
);
4020 /* sysfs fan fan1_input ------------------------------------------------ */
4021 static ssize_t
fan_fan1_input_show(struct device
*dev
,
4022 struct device_attribute
*attr
,
4028 res
= fan_get_speed(&speed
);
4032 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
4035 static struct device_attribute dev_attr_fan_fan1_input
=
4036 __ATTR(fan1_input
, S_IRUGO
,
4037 fan_fan1_input_show
, NULL
);
4039 /* sysfs fan fan_watchdog (driver) ------------------------------------- */
4040 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
4043 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
4046 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
4047 const char *buf
, size_t count
)
4051 if (parse_strtoul(buf
, 120, &t
))
4054 if (!fan_control_allowed
)
4057 fan_watchdog_maxinterval
= t
;
4058 fan_watchdog_reset();
4063 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
4064 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
4066 /* --------------------------------------------------------------------- */
4067 static struct attribute
*fan_attributes
[] = {
4068 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
4069 &dev_attr_fan_fan1_input
.attr
,
4073 static const struct attribute_group fan_attr_group
= {
4074 .attrs
= fan_attributes
,
4077 static int __init
fan_init(struct ibm_init_struct
*iibm
)
4081 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
4083 mutex_init(&fan_mutex
);
4084 fan_status_access_mode
= TPACPI_FAN_NONE
;
4085 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
4086 fan_control_commands
= 0;
4087 fan_watchdog_maxinterval
= 0;
4088 tp_features
.fan_ctrl_status_undef
= 0;
4089 fan_control_desired_level
= 7;
4091 IBM_ACPIHANDLE_INIT(fans
);
4092 IBM_ACPIHANDLE_INIT(gfan
);
4093 IBM_ACPIHANDLE_INIT(sfan
);
4096 /* 570, 600e/x, 770e, 770x */
4097 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
4099 /* all other ThinkPads: note that even old-style
4100 * ThinkPad ECs supports the fan control register */
4101 if (likely(acpi_ec_read(fan_status_offset
,
4102 &fan_control_initial_status
))) {
4103 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
4105 /* In some ThinkPads, neither the EC nor the ACPI
4106 * DSDT initialize the fan status, and it ends up
4107 * being set to 0x07 when it *could* be either
4110 * Enable for TP-1Y (T43), TP-78 (R51e),
4111 * TP-76 (R52), TP-70 (T43, R52), which are known
4113 if (fan_control_initial_status
== 0x07) {
4114 switch (thinkpad_id
.ec_model
) {
4115 case 0x5931: /* TP-1Y */
4116 case 0x3837: /* TP-78 */
4117 case 0x3637: /* TP-76 */
4118 case 0x3037: /* TP-70 */
4120 "fan_init: initial fan status is "
4121 "unknown, assuming it is in auto "
4123 tp_features
.fan_ctrl_status_undef
= 1;
4129 "ThinkPad ACPI EC access misbehaving, "
4130 "fan status and control unavailable\n");
4137 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
4138 fan_control_commands
|=
4139 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
4142 /* gfan without sfan means no fan control */
4143 /* all other models implement TP EC 0x2f control */
4147 fan_control_access_mode
=
4148 TPACPI_FAN_WR_ACPI_FANS
;
4149 fan_control_commands
|=
4150 TPACPI_FAN_CMD_SPEED
|
4151 TPACPI_FAN_CMD_LEVEL
|
4152 TPACPI_FAN_CMD_ENABLE
;
4154 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
4155 fan_control_commands
|=
4156 TPACPI_FAN_CMD_LEVEL
|
4157 TPACPI_FAN_CMD_ENABLE
;
4162 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
4163 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
4164 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
4165 fan_status_access_mode
, fan_control_access_mode
);
4167 /* fan control master switch */
4168 if (!fan_control_allowed
) {
4169 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
4170 fan_control_commands
= 0;
4171 dbg_printk(TPACPI_DBG_INIT
,
4172 "fan control features disabled by parameter\n");
4175 /* update fan_control_desired_level */
4176 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
4177 fan_get_status_safe(NULL
);
4179 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
4180 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
4181 rc
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4184 rc
= driver_create_file(&tpacpi_pdriver
.driver
,
4185 &driver_attr_fan_watchdog
);
4194 * Call with fan_mutex held
4196 static void fan_update_desired_level(u8 status
)
4199 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
4201 fan_control_desired_level
= 7;
4203 fan_control_desired_level
= status
;
4207 static int fan_get_status(u8
*status
)
4212 * Add TPACPI_FAN_RD_ACPI_FANS ? */
4214 switch (fan_status_access_mode
) {
4215 case TPACPI_FAN_RD_ACPI_GFAN
:
4216 /* 570, 600e/x, 770e, 770x */
4218 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
4226 case TPACPI_FAN_RD_TPEC
:
4227 /* all except 570, 600e/x, 770e, 770x */
4228 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
4243 static int fan_get_status_safe(u8
*status
)
4248 rc
= mutex_lock_interruptible(&fan_mutex
);
4251 rc
= fan_get_status(&s
);
4253 fan_update_desired_level(s
);
4254 mutex_unlock(&fan_mutex
);
4262 static void fan_exit(void)
4264 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
4266 /* FIXME: can we really do this unconditionally? */
4267 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
, &fan_attr_group
);
4268 driver_remove_file(&tpacpi_pdriver
.driver
, &driver_attr_fan_watchdog
);
4270 cancel_delayed_work(&fan_watchdog_task
);
4271 flush_scheduled_work();
4274 static int fan_get_speed(unsigned int *speed
)
4278 switch (fan_status_access_mode
) {
4279 case TPACPI_FAN_RD_TPEC
:
4280 /* all except 570, 600e/x, 770e, 770x */
4281 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
4282 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
4286 *speed
= (hi
<< 8) | lo
;
4297 static void fan_watchdog_fire(struct work_struct
*ignored
)
4301 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
4304 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
4305 rc
= fan_set_enable();
4307 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
4308 "will try again later...\n", -rc
);
4309 /* reschedule for later */
4310 fan_watchdog_reset();
4314 static void fan_watchdog_reset(void)
4316 static int fan_watchdog_active
;
4318 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
4321 if (fan_watchdog_active
)
4322 cancel_delayed_work(&fan_watchdog_task
);
4324 if (fan_watchdog_maxinterval
> 0 &&
4325 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
4326 fan_watchdog_active
= 1;
4327 if (!schedule_delayed_work(&fan_watchdog_task
,
4328 msecs_to_jiffies(fan_watchdog_maxinterval
4330 printk(IBM_ERR
"failed to schedule the fan watchdog, "
4331 "watchdog will not trigger\n");
4334 fan_watchdog_active
= 0;
4337 static int fan_set_level(int level
)
4339 if (!fan_control_allowed
)
4342 switch (fan_control_access_mode
) {
4343 case TPACPI_FAN_WR_ACPI_SFAN
:
4344 if (level
>= 0 && level
<= 7) {
4345 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
4351 case TPACPI_FAN_WR_ACPI_FANS
:
4352 case TPACPI_FAN_WR_TPEC
:
4353 if ((level
!= TP_EC_FAN_AUTO
) &&
4354 (level
!= TP_EC_FAN_FULLSPEED
) &&
4355 ((level
< 0) || (level
> 7)))
4358 /* safety net should the EC not support AUTO
4359 * or FULLSPEED mode bits and just ignore them */
4360 if (level
& TP_EC_FAN_FULLSPEED
)
4361 level
|= 7; /* safety min speed 7 */
4362 else if (level
& TP_EC_FAN_FULLSPEED
)
4363 level
|= 4; /* safety min speed 4 */
4365 if (!acpi_ec_write(fan_status_offset
, level
))
4368 tp_features
.fan_ctrl_status_undef
= 0;
4377 static int fan_set_level_safe(int level
)
4381 if (!fan_control_allowed
)
4384 rc
= mutex_lock_interruptible(&fan_mutex
);
4388 if (level
== TPACPI_FAN_LAST_LEVEL
)
4389 level
= fan_control_desired_level
;
4391 rc
= fan_set_level(level
);
4393 fan_update_desired_level(level
);
4395 mutex_unlock(&fan_mutex
);
4399 static int fan_set_enable(void)
4404 if (!fan_control_allowed
)
4407 rc
= mutex_lock_interruptible(&fan_mutex
);
4411 switch (fan_control_access_mode
) {
4412 case TPACPI_FAN_WR_ACPI_FANS
:
4413 case TPACPI_FAN_WR_TPEC
:
4414 rc
= fan_get_status(&s
);
4418 /* Don't go out of emergency fan mode */
4421 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
4424 if (!acpi_ec_write(fan_status_offset
, s
))
4427 tp_features
.fan_ctrl_status_undef
= 0;
4432 case TPACPI_FAN_WR_ACPI_SFAN
:
4433 rc
= fan_get_status(&s
);
4439 /* Set fan to at least level 4 */
4442 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
4452 mutex_unlock(&fan_mutex
);
4456 static int fan_set_disable(void)
4460 if (!fan_control_allowed
)
4463 rc
= mutex_lock_interruptible(&fan_mutex
);
4468 switch (fan_control_access_mode
) {
4469 case TPACPI_FAN_WR_ACPI_FANS
:
4470 case TPACPI_FAN_WR_TPEC
:
4471 if (!acpi_ec_write(fan_status_offset
, 0x00))
4474 fan_control_desired_level
= 0;
4475 tp_features
.fan_ctrl_status_undef
= 0;
4479 case TPACPI_FAN_WR_ACPI_SFAN
:
4480 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
4483 fan_control_desired_level
= 0;
4491 mutex_unlock(&fan_mutex
);
4495 static int fan_set_speed(int speed
)
4499 if (!fan_control_allowed
)
4502 rc
= mutex_lock_interruptible(&fan_mutex
);
4507 switch (fan_control_access_mode
) {
4508 case TPACPI_FAN_WR_ACPI_FANS
:
4509 if (speed
>= 0 && speed
<= 65535) {
4510 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
4511 speed
, speed
, speed
))
4521 mutex_unlock(&fan_mutex
);
4525 static int fan_read(char *p
)
4530 unsigned int speed
= 0;
4532 switch (fan_status_access_mode
) {
4533 case TPACPI_FAN_RD_ACPI_GFAN
:
4534 /* 570, 600e/x, 770e, 770x */
4535 if ((rc
= fan_get_status_safe(&status
)) < 0)
4538 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
4540 (status
!= 0) ? "enabled" : "disabled", status
);
4543 case TPACPI_FAN_RD_TPEC
:
4544 /* all except 570, 600e/x, 770e, 770x */
4545 if ((rc
= fan_get_status_safe(&status
)) < 0)
4548 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4549 if (status
!= fan_control_initial_status
)
4550 tp_features
.fan_ctrl_status_undef
= 0;
4552 /* Return most likely status. In fact, it
4553 * might be the only possible status */
4554 status
= TP_EC_FAN_AUTO
;
4557 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4558 (status
!= 0) ? "enabled" : "disabled");
4560 if ((rc
= fan_get_speed(&speed
)) < 0)
4563 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
4565 if (status
& TP_EC_FAN_FULLSPEED
)
4566 /* Disengaged mode takes precedence */
4567 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
4568 else if (status
& TP_EC_FAN_AUTO
)
4569 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
4571 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
4574 case TPACPI_FAN_NONE
:
4576 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4579 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
4580 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
4582 switch (fan_control_access_mode
) {
4583 case TPACPI_FAN_WR_ACPI_SFAN
:
4584 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
4588 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
4589 "auto, disengaged, full-speed)\n");
4594 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
4595 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
4596 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
4597 "1-120 (seconds))\n");
4599 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
4600 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
4601 " (<speed> is 0-65535)\n");
4606 static int fan_write_cmd_level(const char *cmd
, int *rc
)
4610 if (strlencmp(cmd
, "level auto") == 0)
4611 level
= TP_EC_FAN_AUTO
;
4612 else if ((strlencmp(cmd
, "level disengaged") == 0) |
4613 (strlencmp(cmd
, "level full-speed") == 0))
4614 level
= TP_EC_FAN_FULLSPEED
;
4615 else if (sscanf(cmd
, "level %d", &level
) != 1)
4618 if ((*rc
= fan_set_level_safe(level
)) == -ENXIO
)
4619 printk(IBM_ERR
"level command accepted for unsupported "
4620 "access mode %d", fan_control_access_mode
);
4625 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
4627 if (strlencmp(cmd
, "enable") != 0)
4630 if ((*rc
= fan_set_enable()) == -ENXIO
)
4631 printk(IBM_ERR
"enable command accepted for unsupported "
4632 "access mode %d", fan_control_access_mode
);
4637 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
4639 if (strlencmp(cmd
, "disable") != 0)
4642 if ((*rc
= fan_set_disable()) == -ENXIO
)
4643 printk(IBM_ERR
"disable command accepted for unsupported "
4644 "access mode %d", fan_control_access_mode
);
4649 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
4654 * Support speed <low> <medium> <high> ? */
4656 if (sscanf(cmd
, "speed %d", &speed
) != 1)
4659 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
4660 printk(IBM_ERR
"speed command accepted for unsupported "
4661 "access mode %d", fan_control_access_mode
);
4666 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
4670 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
4673 if (interval
< 0 || interval
> 120)
4676 fan_watchdog_maxinterval
= interval
;
4681 static int fan_write(char *buf
)
4686 while (!rc
&& (cmd
= next_cmd(&buf
))) {
4687 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
4688 fan_write_cmd_level(cmd
, &rc
)) &&
4689 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
4690 (fan_write_cmd_enable(cmd
, &rc
) ||
4691 fan_write_cmd_disable(cmd
, &rc
) ||
4692 fan_write_cmd_watchdog(cmd
, &rc
))) &&
4693 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
4694 fan_write_cmd_speed(cmd
, &rc
))
4698 fan_watchdog_reset();
4704 static struct ibm_struct fan_driver_data
= {
4711 /****************************************************************************
4712 ****************************************************************************
4716 ****************************************************************************
4717 ****************************************************************************/
4720 static struct proc_dir_entry
*proc_dir
;
4722 /* Subdriver registry */
4723 static LIST_HEAD(tpacpi_all_drivers
);
4727 * Module and infrastructure proble, init and exit handling
4730 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
4731 static const char * __init
str_supported(int is_supported
)
4733 static char text_unsupported
[] __initdata
= "not supported";
4735 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
4737 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
4739 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
4742 struct ibm_struct
*ibm
= iibm
->data
;
4743 struct proc_dir_entry
*entry
;
4745 BUG_ON(ibm
== NULL
);
4747 INIT_LIST_HEAD(&ibm
->all_drivers
);
4749 if (ibm
->flags
.experimental
&& !experimental
)
4752 dbg_printk(TPACPI_DBG_INIT
,
4753 "probing for %s\n", ibm
->name
);
4756 ret
= iibm
->init(iibm
);
4758 return 0; /* probe failed */
4762 ibm
->flags
.init_called
= 1;
4766 if (ibm
->acpi
->hid
) {
4767 ret
= register_tpacpi_subdriver(ibm
);
4772 if (ibm
->acpi
->notify
) {
4773 ret
= setup_acpi_notify(ibm
);
4774 if (ret
== -ENODEV
) {
4775 printk(IBM_NOTICE
"disabling subdriver %s\n",
4785 dbg_printk(TPACPI_DBG_INIT
,
4786 "%s installed\n", ibm
->name
);
4789 entry
= create_proc_entry(ibm
->name
,
4790 S_IFREG
| S_IRUGO
| S_IWUSR
,
4793 printk(IBM_ERR
"unable to create proc entry %s\n",
4798 entry
->owner
= THIS_MODULE
;
4800 entry
->read_proc
= &dispatch_procfs_read
;
4802 entry
->write_proc
= &dispatch_procfs_write
;
4803 ibm
->flags
.proc_created
= 1;
4806 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
4811 dbg_printk(TPACPI_DBG_INIT
,
4812 "%s: at error exit path with result %d\n",
4816 return (ret
< 0)? ret
: 0;
4819 static void ibm_exit(struct ibm_struct
*ibm
)
4821 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
4823 list_del_init(&ibm
->all_drivers
);
4825 if (ibm
->flags
.acpi_notify_installed
) {
4826 dbg_printk(TPACPI_DBG_EXIT
,
4827 "%s: acpi_remove_notify_handler\n", ibm
->name
);
4829 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
4831 dispatch_acpi_notify
);
4832 ibm
->flags
.acpi_notify_installed
= 0;
4833 ibm
->flags
.acpi_notify_installed
= 0;
4836 if (ibm
->flags
.proc_created
) {
4837 dbg_printk(TPACPI_DBG_EXIT
,
4838 "%s: remove_proc_entry\n", ibm
->name
);
4839 remove_proc_entry(ibm
->name
, proc_dir
);
4840 ibm
->flags
.proc_created
= 0;
4843 if (ibm
->flags
.acpi_driver_registered
) {
4844 dbg_printk(TPACPI_DBG_EXIT
,
4845 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
4847 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
4848 kfree(ibm
->acpi
->driver
);
4849 ibm
->acpi
->driver
= NULL
;
4850 ibm
->flags
.acpi_driver_registered
= 0;
4853 if (ibm
->flags
.init_called
&& ibm
->exit
) {
4855 ibm
->flags
.init_called
= 0;
4858 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
4863 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
4865 struct dmi_device
*dev
= NULL
;
4866 char ec_fw_string
[18];
4871 memset(tp
, 0, sizeof(*tp
));
4873 if (dmi_name_in_vendors("IBM"))
4874 tp
->vendor
= PCI_VENDOR_ID_IBM
;
4875 else if (dmi_name_in_vendors("LENOVO"))
4876 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
4880 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
4882 if (!tp
->bios_version_str
)
4884 tp
->bios_model
= tp
->bios_version_str
[0]
4885 | (tp
->bios_version_str
[1] << 8);
4888 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4889 * X32 or newer, all Z series; Some models must have an
4890 * up-to-date BIOS or they will not be detected.
4892 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4894 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
4895 if (sscanf(dev
->name
,
4896 "IBM ThinkPad Embedded Controller -[%17c",
4897 ec_fw_string
) == 1) {
4898 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
4899 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
4901 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
4902 tp
->ec_model
= ec_fw_string
[0]
4903 | (ec_fw_string
[1] << 8);
4908 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
4910 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
4911 kfree(tp
->model_str
);
4912 tp
->model_str
= NULL
;
4916 static int __init
probe_for_thinkpad(void)
4924 * Non-ancient models have better DMI tagging, but very old models
4927 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
4929 /* ec is required because many other handles are relative to it */
4930 IBM_ACPIHANDLE_INIT(ec
);
4934 "Not yet supported ThinkPad detected!\n");
4939 * Risks a regression on very old machines, but reduces potential
4940 * false positives a damn great deal
4943 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
4945 if (!is_thinkpad
&& !force_load
)
4952 /* Module init, exit, parameters */
4954 static struct ibm_init_struct ibms_init
[] __initdata
= {
4956 .init
= thinkpad_acpi_driver_init
,
4957 .data
= &thinkpad_acpi_driver_data
,
4960 .init
= hotkey_init
,
4961 .data
= &hotkey_driver_data
,
4964 .init
= bluetooth_init
,
4965 .data
= &bluetooth_driver_data
,
4969 .data
= &wan_driver_data
,
4973 .data
= &video_driver_data
,
4977 .data
= &light_driver_data
,
4979 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4982 .data
= &dock_driver_data
[0],
4986 .data
= &dock_driver_data
[1],
4989 #ifdef CONFIG_THINKPAD_ACPI_BAY
4992 .data
= &bay_driver_data
,
4997 .data
= &cmos_driver_data
,
5001 .data
= &led_driver_data
,
5005 .data
= &beep_driver_data
,
5008 .init
= thermal_init
,
5009 .data
= &thermal_driver_data
,
5012 .data
= &ecdump_driver_data
,
5015 .init
= brightness_init
,
5016 .data
= &brightness_driver_data
,
5019 .data
= &volume_driver_data
,
5023 .data
= &fan_driver_data
,
5027 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
5030 struct ibm_struct
*ibm
;
5032 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
5033 ibm
= ibms_init
[i
].data
;
5034 BUG_ON(ibm
== NULL
);
5036 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
5037 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
5039 strcpy(ibms_init
[i
].param
, val
);
5040 strcat(ibms_init
[i
].param
, ",");
5048 static int experimental
;
5049 module_param(experimental
, int, 0);
5051 static u32 dbg_level
;
5052 module_param_named(debug
, dbg_level
, uint
, 0);
5054 static int force_load
;
5055 module_param(force_load
, bool, 0);
5057 static int fan_control_allowed
;
5058 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
5060 static int brightness_mode
;
5061 module_param_named(brightness_mode
, brightness_mode
, int, 0);
5063 static unsigned int hotkey_report_mode
;
5064 module_param(hotkey_report_mode
, uint
, 0);
5066 #define IBM_PARAM(feature) \
5067 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
5070 IBM_PARAM(bluetooth
);
5073 #ifdef CONFIG_THINKPAD_ACPI_DOCK
5076 #ifdef CONFIG_THINKPAD_ACPI_BAY
5078 #endif /* CONFIG_THINKPAD_ACPI_BAY */
5083 IBM_PARAM(brightness
);
5087 static int __init
thinkpad_acpi_module_init(void)
5091 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
5093 /* Parameter checking */
5094 if (hotkey_report_mode
> 2)
5097 /* Driver-level probe */
5099 get_thinkpad_model_data(&thinkpad_id
);
5100 ret
= probe_for_thinkpad();
5102 thinkpad_acpi_module_exit();
5106 /* Driver initialization */
5108 IBM_ACPIHANDLE_INIT(ecrd
);
5109 IBM_ACPIHANDLE_INIT(ecwr
);
5111 mutex_init(&thinkpad_nvram_mutex
);
5113 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
5115 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
5116 thinkpad_acpi_module_exit();
5119 proc_dir
->owner
= THIS_MODULE
;
5121 ret
= platform_driver_register(&tpacpi_pdriver
);
5123 printk(IBM_ERR
"unable to register platform driver\n");
5124 thinkpad_acpi_module_exit();
5127 tp_features
.platform_drv_registered
= 1;
5129 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
5131 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
5132 thinkpad_acpi_module_exit();
5135 tp_features
.platform_drv_attrs_registered
= 1;
5138 /* Device initialization */
5139 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
5141 if (IS_ERR(tpacpi_pdev
)) {
5142 ret
= PTR_ERR(tpacpi_pdev
);
5144 printk(IBM_ERR
"unable to register platform device\n");
5145 thinkpad_acpi_module_exit();
5148 tpacpi_hwmon
= hwmon_device_register(&tpacpi_pdev
->dev
);
5149 if (IS_ERR(tpacpi_hwmon
)) {
5150 ret
= PTR_ERR(tpacpi_hwmon
);
5151 tpacpi_hwmon
= NULL
;
5152 printk(IBM_ERR
"unable to register hwmon device\n");
5153 thinkpad_acpi_module_exit();
5156 mutex_init(&tpacpi_inputdev_send_mutex
);
5157 tpacpi_inputdev
= input_allocate_device();
5158 if (!tpacpi_inputdev
) {
5159 printk(IBM_ERR
"unable to allocate input device\n");
5160 thinkpad_acpi_module_exit();
5163 /* Prepare input device, but don't register */
5164 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
5165 tpacpi_inputdev
->phys
= IBM_DRVR_NAME
"/input0";
5166 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
5167 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
5168 thinkpad_id
.vendor
:
5170 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
5171 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
5173 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
5174 ret
= ibm_init(&ibms_init
[i
]);
5175 if (ret
>= 0 && *ibms_init
[i
].param
)
5176 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
5178 thinkpad_acpi_module_exit();
5182 ret
= input_register_device(tpacpi_inputdev
);
5184 printk(IBM_ERR
"unable to register input device\n");
5185 thinkpad_acpi_module_exit();
5188 tp_features
.input_device_registered
= 1;
5191 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
5195 static void thinkpad_acpi_module_exit(void)
5197 struct ibm_struct
*ibm
, *itmp
;
5199 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
5201 list_for_each_entry_safe_reverse(ibm
, itmp
,
5202 &tpacpi_all_drivers
,
5207 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
5209 if (tpacpi_inputdev
) {
5210 if (tp_features
.input_device_registered
)
5211 input_unregister_device(tpacpi_inputdev
);
5213 input_free_device(tpacpi_inputdev
);
5217 hwmon_device_unregister(tpacpi_hwmon
);
5220 platform_device_unregister(tpacpi_pdev
);
5222 if (tp_features
.platform_drv_attrs_registered
)
5223 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
5225 if (tp_features
.platform_drv_registered
)
5226 platform_driver_unregister(&tpacpi_pdriver
);
5229 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
5231 kfree(thinkpad_id
.bios_version_str
);
5232 kfree(thinkpad_id
.ec_version_str
);
5233 kfree(thinkpad_id
.model_str
);
5236 module_init(thinkpad_acpi_module_init
);
5237 module_exit(thinkpad_acpi_module_exit
);