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-20070916"
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
;
423 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
425 rc
= acpi_bus_register_driver(ibm
->acpi
->driver
);
427 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
429 kfree(ibm
->acpi
->driver
);
430 ibm
->acpi
->driver
= NULL
;
432 ibm
->flags
.acpi_driver_registered
= 1;
438 /****************************************************************************
439 ****************************************************************************
443 ****************************************************************************
444 ****************************************************************************/
446 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
447 int count
, int *eof
, void *data
)
449 struct ibm_struct
*ibm
= data
;
452 if (!ibm
|| !ibm
->read
)
455 len
= ibm
->read(page
);
459 if (len
<= off
+ count
)
471 static int dispatch_procfs_write(struct file
*file
,
472 const char __user
* userbuf
,
473 unsigned long count
, void *data
)
475 struct ibm_struct
*ibm
= data
;
479 if (!ibm
|| !ibm
->write
)
482 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
486 if (copy_from_user(kernbuf
, userbuf
, count
)) {
492 strcat(kernbuf
, ",");
493 ret
= ibm
->write(kernbuf
);
502 static char *next_cmd(char **cmds
)
507 while ((end
= strchr(start
, ',')) && end
== start
)
519 /****************************************************************************
520 ****************************************************************************
522 * Device model: input, hwmon and platform
524 ****************************************************************************
525 ****************************************************************************/
527 static struct platform_device
*tpacpi_pdev
;
528 static struct class_device
*tpacpi_hwmon
;
529 static struct input_dev
*tpacpi_inputdev
;
530 static struct mutex tpacpi_inputdev_send_mutex
;
533 static int tpacpi_resume_handler(struct platform_device
*pdev
)
535 struct ibm_struct
*ibm
, *itmp
;
537 list_for_each_entry_safe(ibm
, itmp
,
547 static struct platform_driver tpacpi_pdriver
= {
549 .name
= IBM_DRVR_NAME
,
550 .owner
= THIS_MODULE
,
552 .resume
= tpacpi_resume_handler
,
556 /*************************************************************************
557 * thinkpad-acpi driver attributes
560 /* interface_version --------------------------------------------------- */
561 static ssize_t
tpacpi_driver_interface_version_show(
562 struct device_driver
*drv
,
565 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
568 static DRIVER_ATTR(interface_version
, S_IRUGO
,
569 tpacpi_driver_interface_version_show
, NULL
);
571 /* debug_level --------------------------------------------------------- */
572 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
575 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
578 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
579 const char *buf
, size_t count
)
583 if (parse_strtoul(buf
, 0xffff, &t
))
591 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
592 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
594 /* version ------------------------------------------------------------- */
595 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
598 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n", IBM_DESC
, IBM_VERSION
);
601 static DRIVER_ATTR(version
, S_IRUGO
,
602 tpacpi_driver_version_show
, NULL
);
604 /* --------------------------------------------------------------------- */
606 static struct driver_attribute
* tpacpi_driver_attributes
[] = {
607 &driver_attr_debug_level
, &driver_attr_version
,
608 &driver_attr_interface_version
,
611 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
617 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
618 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
625 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
629 for(i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
630 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
633 /*************************************************************************
634 * sysfs support helpers
637 struct attribute_set_obj
{
638 struct attribute_set s
;
640 } __attribute__((packed
));
642 static struct attribute_set
*create_attr_set(unsigned int max_members
,
645 struct attribute_set_obj
*sobj
;
647 if (max_members
== 0)
650 /* Allocates space for implicit NULL at the end too */
651 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
652 max_members
* sizeof(struct attribute
*),
656 sobj
->s
.max_members
= max_members
;
657 sobj
->s
.group
.attrs
= &sobj
->a
;
658 sobj
->s
.group
.name
= name
;
663 /* not multi-threaded safe, use it in a single thread per set */
664 static int add_to_attr_set(struct attribute_set
* s
, struct attribute
*attr
)
669 if (s
->members
>= s
->max_members
)
672 s
->group
.attrs
[s
->members
] = attr
;
678 static int add_many_to_attr_set(struct attribute_set
* s
,
679 struct attribute
**attr
,
684 for (i
= 0; i
< count
; i
++) {
685 res
= add_to_attr_set(s
, attr
[i
]);
693 static void delete_attr_set(struct attribute_set
* s
, struct kobject
*kobj
)
695 sysfs_remove_group(kobj
, &s
->group
);
699 static int parse_strtoul(const char *buf
,
700 unsigned long max
, unsigned long *value
)
704 *value
= simple_strtoul(buf
, &endp
, 0);
705 while (*endp
&& isspace(*endp
))
707 if (*endp
|| *value
> max
)
713 /****************************************************************************
714 ****************************************************************************
718 ****************************************************************************
719 ****************************************************************************/
721 /*************************************************************************
722 * thinkpad-acpi init subdriver
725 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
727 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
728 printk(IBM_INFO
"%s\n", IBM_URL
);
730 printk(IBM_INFO
"ThinkPad BIOS %s, EC %s\n",
731 (thinkpad_id
.bios_version_str
) ?
732 thinkpad_id
.bios_version_str
: "unknown",
733 (thinkpad_id
.ec_version_str
) ?
734 thinkpad_id
.ec_version_str
: "unknown");
736 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
737 printk(IBM_INFO
"%s %s\n",
738 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
739 "IBM" : ((thinkpad_id
.vendor
==
740 PCI_VENDOR_ID_LENOVO
) ?
741 "Lenovo" : "Unknown vendor"),
742 thinkpad_id
.model_str
);
747 static int thinkpad_acpi_driver_read(char *p
)
751 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
752 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
757 static struct ibm_struct thinkpad_acpi_driver_data
= {
759 .read
= thinkpad_acpi_driver_read
,
762 /*************************************************************************
766 enum { /* Keys available through NVRAM polling */
767 TPACPI_HKEY_NVRAM_KNOWN_MASK
= 0x00fb8000U
,
770 enum { /* Positions of some of the keys in hotkey masks */
771 TP_ACPI_HKEY_DISPSWTCH_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF7
,
772 TP_ACPI_HKEY_DISPXPAND_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF8
,
773 TP_ACPI_HKEY_HIBERNATE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNF12
,
774 TP_ACPI_HKEY_BRGHTUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNHOME
,
775 TP_ACPI_HKEY_BRGHTDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNEND
,
776 TP_ACPI_HKEY_THNKLGHT_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNPAGEUP
,
777 TP_ACPI_HKEY_ZOOM_MASK
= 1 << TP_ACPI_HOTKEYSCAN_FNSPACE
,
778 TP_ACPI_HKEY_VOLUP_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEUP
,
779 TP_ACPI_HKEY_VOLDWN_MASK
= 1 << TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
,
780 TP_ACPI_HKEY_MUTE_MASK
= 1 << TP_ACPI_HOTKEYSCAN_MUTE
,
781 TP_ACPI_HKEY_THINKPAD_MASK
= 1 << TP_ACPI_HOTKEYSCAN_THINKPAD
,
784 enum { /* NVRAM to ACPI HKEY group map */
785 TP_NVRAM_HKEY_GROUP_HK2
= TP_ACPI_HKEY_THINKPAD_MASK
|
786 TP_ACPI_HKEY_ZOOM_MASK
|
787 TP_ACPI_HKEY_DISPSWTCH_MASK
|
788 TP_ACPI_HKEY_HIBERNATE_MASK
,
789 TP_NVRAM_HKEY_GROUP_BRIGHTNESS
= TP_ACPI_HKEY_BRGHTUP_MASK
|
790 TP_ACPI_HKEY_BRGHTDWN_MASK
,
791 TP_NVRAM_HKEY_GROUP_VOLUME
= TP_ACPI_HKEY_VOLUP_MASK
|
792 TP_ACPI_HKEY_VOLDWN_MASK
|
793 TP_ACPI_HKEY_MUTE_MASK
,
796 struct tp_nvram_state
{
797 u16 thinkpad_toggle
:1;
799 u16 display_toggle
:1;
800 u16 thinklight_toggle
:1;
801 u16 hibernate_toggle
:1;
802 u16 displayexp_toggle
:1;
804 u16 brightness_toggle
:1;
812 static int hotkey_orig_status
;
813 static u32 hotkey_orig_mask
;
814 static u32 hotkey_all_mask
;
815 static u32 hotkey_reserved_mask
;
817 static struct task_struct
*tpacpi_hotkey_task
;
818 static u32 hotkey_source_mask
; /* bit mask 0=ACPI,1=NVRAM */
819 static int hotkey_poll_freq
= 4; /* Hz */
820 static struct mutex hotkey_poll_mutex
;
821 static struct mutex thinkpad_nvram_mutex
;
822 static struct mutex hotkey_thread_mutex
;
824 static u16
*hotkey_keycode_map
;
826 static struct attribute_set
*hotkey_dev_attributes
;
828 static void tpacpi_input_send_key(unsigned int scancode
)
830 unsigned int keycode
;
832 keycode
= hotkey_keycode_map
[scancode
];
834 if (keycode
!= KEY_RESERVED
) {
835 mutex_lock(&tpacpi_inputdev_send_mutex
);
837 input_report_key(tpacpi_inputdev
, keycode
, 1);
838 if (keycode
== KEY_UNKNOWN
)
839 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
841 input_sync(tpacpi_inputdev
);
843 input_report_key(tpacpi_inputdev
, keycode
, 0);
844 if (keycode
== KEY_UNKNOWN
)
845 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
847 input_sync(tpacpi_inputdev
);
849 mutex_unlock(&tpacpi_inputdev_send_mutex
);
853 static int hotkey_get_wlsw(int *status
)
855 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
860 static void tpacpi_input_send_radiosw(void)
864 mutex_lock(&tpacpi_inputdev_send_mutex
);
866 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
867 input_report_switch(tpacpi_inputdev
,
869 input_sync(tpacpi_inputdev
);
872 mutex_unlock(&tpacpi_inputdev_send_mutex
);
875 static void hotkey_read_nvram(struct tp_nvram_state
*n
)
879 if (hotkey_source_mask
& TP_NVRAM_HKEY_GROUP_HK2
) {
880 d
= nvram_read_byte(TP_NVRAM_ADDR_HK2
);
881 n
->thinkpad_toggle
= !!(d
& TP_NVRAM_MASK_HKT_THINKPAD
);
882 n
->zoom_toggle
= !!(d
& TP_NVRAM_MASK_HKT_ZOOM
);
883 n
->display_toggle
= !!(d
& TP_NVRAM_MASK_HKT_DISPLAY
);
884 n
->hibernate_toggle
= !!(d
& TP_NVRAM_MASK_HKT_HIBERNATE
);
886 if (hotkey_source_mask
& TP_ACPI_HKEY_THNKLGHT_MASK
) {
887 d
= nvram_read_byte(TP_NVRAM_ADDR_THINKLIGHT
);
888 n
->thinklight_toggle
= !!(d
& TP_NVRAM_MASK_THINKLIGHT
);
890 if (hotkey_source_mask
& TP_ACPI_HKEY_DISPXPAND_MASK
) {
891 d
= nvram_read_byte(TP_NVRAM_ADDR_VIDEO
);
892 n
->displayexp_toggle
=
893 !!(d
& TP_NVRAM_MASK_HKT_DISPEXPND
);
895 if (hotkey_source_mask
& TP_NVRAM_HKEY_GROUP_BRIGHTNESS
) {
896 d
= nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
);
897 n
->brightness_level
= (d
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
898 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
899 n
->brightness_toggle
=
900 !!(d
& TP_NVRAM_MASK_HKT_BRIGHTNESS
);
902 if (hotkey_source_mask
& TP_NVRAM_HKEY_GROUP_VOLUME
) {
903 d
= nvram_read_byte(TP_NVRAM_ADDR_MIXER
);
904 n
->volume_level
= (d
& TP_NVRAM_MASK_LEVEL_VOLUME
)
905 >> TP_NVRAM_POS_LEVEL_VOLUME
;
906 n
->mute
= !!(d
& TP_NVRAM_MASK_MUTE
);
907 n
->volume_toggle
= !!(d
& TP_NVRAM_MASK_HKT_VOLUME
);
911 #define TPACPI_COMPARE_KEY(__scancode, __member) \
912 if (hotkey_source_mask & (1 << __scancode) && \
913 oldn->__member != newn->__member) \
914 tpacpi_input_send_key(__scancode);
916 static void hotkey_compare_and_issue_event(struct tp_nvram_state
*oldn
,
917 struct tp_nvram_state
*newn
)
919 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD
, thinkpad_toggle
)
920 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE
, zoom_toggle
)
921 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7
, display_toggle
)
922 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF12
, hibernate_toggle
)
924 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNPAGEUP
, thinklight_toggle
)
926 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF8
, displayexp_toggle
)
929 if (oldn
->volume_toggle
!= newn
->volume_toggle
) {
930 if (oldn
->mute
!= newn
->mute
) {
931 tpacpi_input_send_key(TP_ACPI_HOTKEYSCAN_MUTE
);
933 if (oldn
->volume_level
> newn
->volume_level
) {
934 tpacpi_input_send_key(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN
);
935 } else if (oldn
->volume_level
< newn
->volume_level
) {
936 tpacpi_input_send_key(TP_ACPI_HOTKEYSCAN_VOLUMEUP
);
939 /* we could "else" here and issue mute regardless of a change
940 * in the mute bit (and therefore notify of multiple presses of
941 * the mute button), but that is *incorrect* semanthics for
942 * a thinkpad mixer, where "mute" always mutes, and a volume
947 /* handle brightness */
948 if (oldn
->brightness_toggle
!= newn
->brightness_toggle
) {
949 if (oldn
->brightness_level
< newn
->brightness_level
) {
950 tpacpi_input_send_key(TP_ACPI_HOTKEYSCAN_FNHOME
);
951 } else if (oldn
->brightness_level
> newn
->brightness_level
) {
952 tpacpi_input_send_key(TP_ACPI_HOTKEYSCAN_FNEND
);
957 #undef TPACPI_COMPARE_KEY
959 static int hotkey_kthread(void *data
)
961 struct tp_nvram_state s
[2];
965 if (tpacpi_lifecycle
== TPACPI_LIFE_EXITING
)
968 mutex_lock(&hotkey_thread_mutex
);
974 /* Initial state for compares */
975 hotkey_read_nvram(&s
[so
]);
977 while (!kthread_should_stop() && hotkey_poll_freq
) {
978 t
= msleep_interruptible(1000/hotkey_poll_freq
+ t
);
979 if (unlikely(kthread_should_stop()))
981 if (unlikely(try_to_freeze())) {
982 si
= so
; /* forget old state on thaw */
988 hotkey_read_nvram(&s
[si
]);
989 hotkey_compare_and_issue_event(&s
[so
], &s
[si
]);
994 mutex_unlock(&hotkey_thread_mutex
);
998 static void hotkey_poll_stop_sync(void)
1000 if (tpacpi_hotkey_task
) {
1001 kthread_stop(tpacpi_hotkey_task
);
1002 tpacpi_hotkey_task
= NULL
;
1003 mutex_lock(&hotkey_thread_mutex
);
1004 /* at this point, the thread did exit */
1005 mutex_unlock(&hotkey_thread_mutex
);
1009 /* call with hotkey_poll_mutex held */
1010 static void hotkey_poll_setup(int force
)
1013 hotkey_poll_stop_sync();
1015 if (hotkey_source_mask
!= 0 && hotkey_poll_freq
> 0 &&
1016 (tpacpi_inputdev
->users
> 0 || hotkey_report_mode
< 2)) {
1017 if (!tpacpi_hotkey_task
) {
1018 tpacpi_hotkey_task
= kthread_run(hotkey_kthread
,
1019 NULL
, IBM_FILE
"d");
1020 if (IS_ERR(tpacpi_hotkey_task
)) {
1021 tpacpi_hotkey_task
= NULL
;
1022 printk(IBM_ERR
"could not create kernel thread "
1023 "for hotkey polling\n");
1027 hotkey_poll_stop_sync();
1031 static int hotkey_poll_setup_safe(int force
)
1035 rc
= mutex_lock_interruptible(&hotkey_poll_mutex
);
1039 hotkey_poll_setup(force
);
1040 mutex_unlock(&hotkey_poll_mutex
);
1045 static void hotkey_warn_no_poll(void)
1047 if (hotkey_source_mask
!= 0 && hotkey_poll_freq
== 0) {
1048 printk(IBM_NOTICE
"hot keys 0x%08x require polling, "
1049 "which is currently disabled\n",
1050 hotkey_source_mask
);
1055 static int hotkey_inputdev_open(struct input_dev
*dev
)
1057 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
1059 /* enable hotkey polling when required */
1060 return hotkey_poll_setup_safe(0);
1063 static void hotkey_inputdev_close(struct input_dev
*dev
)
1065 /* disable hotkey polling when possible */
1066 if (tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
)
1067 hotkey_poll_setup_safe(0);
1070 /* sysfs hotkey enable ------------------------------------------------- */
1071 static ssize_t
hotkey_enable_show(struct device
*dev
,
1072 struct device_attribute
*attr
,
1078 res
= hotkey_get(&status
, &mask
);
1082 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
1085 static ssize_t
hotkey_enable_store(struct device
*dev
,
1086 struct device_attribute
*attr
,
1087 const char *buf
, size_t count
)
1093 if (parse_strtoul(buf
, 1, &t
))
1096 res
= hotkey_get(&status
, &mask
);
1098 res
= hotkey_set(t
, mask
);
1100 return (res
) ? res
: count
;
1103 static struct device_attribute dev_attr_hotkey_enable
=
1104 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
1105 hotkey_enable_show
, hotkey_enable_store
);
1107 /* sysfs hotkey mask --------------------------------------------------- */
1108 static ssize_t
hotkey_mask_show(struct device
*dev
,
1109 struct device_attribute
*attr
,
1115 res
= hotkey_get(&status
, &mask
);
1119 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", mask
);
1122 static ssize_t
hotkey_mask_store(struct device
*dev
,
1123 struct device_attribute
*attr
,
1124 const char *buf
, size_t count
)
1130 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
1133 res
= hotkey_get(&status
, &mask
);
1135 hotkey_set(status
, t
);
1137 return (res
) ? res
: count
;
1140 static struct device_attribute dev_attr_hotkey_mask
=
1141 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
1142 hotkey_mask_show
, hotkey_mask_store
);
1144 /* sysfs hotkey bios_enabled ------------------------------------------- */
1145 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
1146 struct device_attribute
*attr
,
1149 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
1152 static struct device_attribute dev_attr_hotkey_bios_enabled
=
1153 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
1155 /* sysfs hotkey bios_mask ---------------------------------------------- */
1156 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
1157 struct device_attribute
*attr
,
1160 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
1163 static struct device_attribute dev_attr_hotkey_bios_mask
=
1164 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
1166 /* sysfs hotkey all_mask ----------------------------------------------- */
1167 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
1168 struct device_attribute
*attr
,
1171 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1172 hotkey_all_mask
| hotkey_source_mask
);
1175 static struct device_attribute dev_attr_hotkey_all_mask
=
1176 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
1178 /* sysfs hotkey recommended_mask --------------------------------------- */
1179 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
1180 struct device_attribute
*attr
,
1183 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
1184 (hotkey_all_mask
| hotkey_source_mask
)
1185 & ~hotkey_reserved_mask
);
1188 static struct device_attribute dev_attr_hotkey_recommended_mask
=
1189 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
1190 hotkey_recommended_mask_show
, NULL
);
1192 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
1193 static ssize_t
hotkey_source_mask_show(struct device
*dev
,
1194 struct device_attribute
*attr
,
1197 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_source_mask
);
1200 static ssize_t
hotkey_source_mask_store(struct device
*dev
,
1201 struct device_attribute
*attr
,
1202 const char *buf
, size_t count
)
1207 if (parse_strtoul(buf
, 0xffffffffUL
, &t
) ||
1208 ((t
& ~TPACPI_HKEY_NVRAM_KNOWN_MASK
) != 0))
1211 rc
= mutex_lock_interruptible(&hotkey_poll_mutex
);
1215 hotkey_source_mask
= t
;
1217 hotkey_poll_setup(1);
1218 hotkey_warn_no_poll();
1219 mutex_unlock(&hotkey_poll_mutex
);
1224 static struct device_attribute dev_attr_hotkey_source_mask
=
1225 __ATTR(hotkey_source_mask
, S_IWUSR
| S_IRUGO
,
1226 hotkey_source_mask_show
, hotkey_source_mask_store
);
1228 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
1229 static ssize_t
hotkey_poll_freq_show(struct device
*dev
,
1230 struct device_attribute
*attr
,
1233 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_poll_freq
);
1236 static ssize_t
hotkey_poll_freq_store(struct device
*dev
,
1237 struct device_attribute
*attr
,
1238 const char *buf
, size_t count
)
1243 if (parse_strtoul(buf
, 25, &t
))
1246 rc
= mutex_lock_interruptible(&hotkey_poll_mutex
);
1250 hotkey_poll_freq
= t
;
1252 hotkey_poll_setup(0);
1253 hotkey_warn_no_poll();
1254 mutex_unlock(&hotkey_poll_mutex
);
1259 static struct device_attribute dev_attr_hotkey_poll_freq
=
1260 __ATTR(hotkey_poll_freq
, S_IWUSR
| S_IRUGO
,
1261 hotkey_poll_freq_show
, hotkey_poll_freq_store
);
1263 /* sysfs hotkey radio_sw ----------------------------------------------- */
1264 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
1265 struct device_attribute
*attr
,
1269 res
= hotkey_get_wlsw(&s
);
1273 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
1276 static struct device_attribute dev_attr_hotkey_radio_sw
=
1277 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
1279 /* sysfs hotkey report_mode -------------------------------------------- */
1280 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
1281 struct device_attribute
*attr
,
1284 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1285 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
1288 static ssize_t
hotkey_report_mode_store(struct device
*dev
,
1289 struct device_attribute
*attr
,
1290 const char *buf
, size_t count
)
1295 if (parse_strtoul(buf
, 2, &t
) || (t
< 1))
1298 if (t
!= hotkey_report_mode
) {
1299 if (tp_features
.hotkey_report_mode_locked
)
1301 hotkey_report_mode
= t
;
1302 printk(IBM_NOTICE
"hot key report mode set to %d\n",
1303 hotkey_report_mode
);
1306 return (res
) ? res
: count
;
1309 static struct device_attribute dev_attr_hotkey_report_mode
=
1310 __ATTR(hotkey_report_mode
, S_IWUSR
| S_IRUGO
,
1311 hotkey_report_mode_show
, hotkey_report_mode_store
);
1313 /* --------------------------------------------------------------------- */
1315 static struct attribute
*hotkey_attributes
[] __initdata
= {
1316 &dev_attr_hotkey_enable
.attr
,
1317 &dev_attr_hotkey_report_mode
.attr
,
1320 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
1321 &dev_attr_hotkey_mask
.attr
,
1322 &dev_attr_hotkey_bios_enabled
.attr
,
1323 &dev_attr_hotkey_bios_mask
.attr
,
1324 &dev_attr_hotkey_all_mask
.attr
,
1325 &dev_attr_hotkey_recommended_mask
.attr
,
1326 &dev_attr_hotkey_source_mask
.attr
,
1327 &dev_attr_hotkey_poll_freq
.attr
,
1330 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
1333 static u16 ibm_keycode_map
[] __initdata
= {
1334 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1335 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
1336 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1337 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1338 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
1339 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1340 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1341 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1342 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
1343 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
1344 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
1345 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1346 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1347 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1348 KEY_RESERVED
, /* 0x14: VOLUME UP */
1349 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1350 KEY_RESERVED
, /* 0x16: MUTE */
1351 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1352 /* (assignments unknown, please report if found) */
1353 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1354 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1356 static u16 lenovo_keycode_map
[] __initdata
= {
1357 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1358 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
1359 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1360 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1361 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
1362 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1363 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1364 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1365 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
1366 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
1367 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
1368 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1369 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1370 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1371 KEY_RESERVED
, /* 0x14: VOLUME UP */
1372 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1373 KEY_RESERVED
, /* 0x16: MUTE */
1374 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1375 /* (assignments unknown, please report if found) */
1376 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1377 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1380 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
1381 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
1382 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
1388 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
1390 BUG_ON(!tpacpi_inputdev
);
1391 BUG_ON(tpacpi_inputdev
->open
!= NULL
||
1392 tpacpi_inputdev
->close
!= NULL
);
1394 IBM_ACPIHANDLE_INIT(hkey
);
1395 mutex_init(&hotkey_mutex
);
1396 mutex_init(&hotkey_poll_mutex
);
1397 mutex_init(&hotkey_thread_mutex
);
1399 /* hotkey not supported on 570 */
1400 tp_features
.hotkey
= hkey_handle
!= NULL
;
1402 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
1403 str_supported(tp_features
.hotkey
));
1405 if (tp_features
.hotkey
) {
1406 hotkey_dev_attributes
= create_attr_set(10, NULL
);
1407 if (!hotkey_dev_attributes
)
1409 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1411 ARRAY_SIZE(hotkey_attributes
));
1415 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1416 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
1417 for HKEY interface version 0x100 */
1418 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
1419 if ((hkeyv
>> 8) != 1) {
1420 printk(IBM_ERR
"unknown version of the "
1421 "HKEY interface: 0x%x\n", hkeyv
);
1422 printk(IBM_ERR
"please report this to %s\n",
1426 * MHKV 0x100 in A31, R40, R40e,
1427 * T4x, X31, and later
1429 tp_features
.hotkey_mask
= 1;
1433 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
1434 str_supported(tp_features
.hotkey_mask
));
1436 if (tp_features
.hotkey_mask
) {
1437 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
1440 "missing MHKA handler, "
1441 "please report this to %s\n",
1443 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
1447 hotkey_source_mask
= TPACPI_HKEY_NVRAM_KNOWN_MASK
1450 vdbg_printk(TPACPI_DBG_INIT
,
1451 "hotkey source mask 0x%08x, polling freq %d\n",
1452 hotkey_source_mask
, hotkey_poll_freq
);
1454 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
1455 if (!res
&& tp_features
.hotkey_mask
) {
1456 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1457 hotkey_mask_attributes
,
1458 ARRAY_SIZE(hotkey_mask_attributes
));
1461 /* Not all thinkpads have a hardware radio switch */
1462 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
1463 tp_features
.hotkey_wlsw
= 1;
1465 "radio switch found; radios are %s\n",
1466 enabled(status
, 0));
1467 res
= add_to_attr_set(hotkey_dev_attributes
,
1468 &dev_attr_hotkey_radio_sw
.attr
);
1472 res
= register_attr_set_with_sysfs(
1473 hotkey_dev_attributes
,
1474 &tpacpi_pdev
->dev
.kobj
);
1478 /* Set up key map */
1480 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
1482 if (!hotkey_keycode_map
) {
1483 printk(IBM_ERR
"failed to allocate memory for key map\n");
1487 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
1488 dbg_printk(TPACPI_DBG_INIT
,
1489 "using Lenovo default hot key map\n");
1490 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
1491 TPACPI_HOTKEY_MAP_SIZE
);
1493 dbg_printk(TPACPI_DBG_INIT
,
1494 "using IBM default hot key map\n");
1495 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
1496 TPACPI_HOTKEY_MAP_SIZE
);
1499 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
1500 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
1501 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
1502 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
1503 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
1504 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
1505 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
1506 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
1507 set_bit(hotkey_keycode_map
[i
],
1508 tpacpi_inputdev
->keybit
);
1510 if (i
< sizeof(hotkey_reserved_mask
)*8)
1511 hotkey_reserved_mask
|= 1 << i
;
1514 tpacpi_inputdev
->open
= &hotkey_inputdev_open
;
1515 tpacpi_inputdev
->close
= &hotkey_inputdev_close
;
1517 if (tp_features
.hotkey_wlsw
) {
1518 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
1519 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
1522 dbg_printk(TPACPI_DBG_INIT
,
1523 "enabling hot key handling\n");
1524 res
= hotkey_set(1, ((hotkey_all_mask
| hotkey_source_mask
)
1525 & ~hotkey_reserved_mask
)
1526 | hotkey_orig_mask
);
1530 if (hotkey_report_mode
> 0) {
1531 tp_features
.hotkey_report_mode_locked
= 1;
1533 hotkey_report_mode
= 1;
1534 vdbg_printk(TPACPI_DBG_INIT
,
1535 "hot key reporting mode can be "
1536 "changed at runtime\n");
1539 dbg_printk(TPACPI_DBG_INIT
,
1540 "legacy hot key reporting over procfs %s\n",
1541 (hotkey_report_mode
< 2) ?
1542 "enabled" : "disabled");
1544 mutex_lock(&hotkey_poll_mutex
);
1545 hotkey_poll_setup(0);
1546 hotkey_warn_no_poll();
1547 mutex_unlock(&hotkey_poll_mutex
);
1550 return (tp_features
.hotkey
)? 0 : 1;
1553 static void hotkey_exit(void)
1557 hotkey_poll_stop_sync();
1559 if (tp_features
.hotkey
) {
1560 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
1561 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
1563 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
1566 if (hotkey_dev_attributes
) {
1567 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
1568 hotkey_dev_attributes
= NULL
;
1572 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
1575 unsigned int scancode
;
1579 if (event
!= 0x80) {
1580 printk(IBM_ERR
"unknown hotkey notification event %d\n", event
);
1581 /* forward it to userspace, maybe it knows how to handle it */
1582 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
1588 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
1589 printk(IBM_ERR
"failed to retrieve hot key event\n");
1601 switch (hkey
>> 12) {
1603 /* 0x1000-0x1FFF: key presses */
1604 scancode
= hkey
& 0xfff;
1605 if (scancode
> 0 && scancode
< 0x21) {
1607 if (!(hotkey_source_mask
& (1 << scancode
))) {
1608 tpacpi_input_send_key(scancode
);
1612 "hotkey 0x%04x out of range for keyboard map\n",
1618 /* 0x5000-0x5FFF: LID */
1619 /* we don't handle it through this path, just
1620 * eat up known LID events */
1621 if (hkey
!= 0x5001 && hkey
!= 0x5002) {
1623 "unknown LID-related hotkey event: 0x%04x\n",
1631 /* 0x7000-0x7FFF: misc */
1632 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
1633 tpacpi_input_send_radiosw();
1636 /* fallthrough to default */
1638 /* case 2: dock-related */
1639 /* 0x2305 - T43 waking up due to bay lever eject while aslept */
1640 /* case 3: ultra-bay related. maybe bay in dock? */
1641 /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
1642 printk(IBM_NOTICE
"unhandled HKEY event 0x%04x\n", hkey
);
1646 if (!ignore_acpi_ev
&& (send_acpi_ev
|| hotkey_report_mode
< 2)) {
1647 acpi_bus_generate_event(ibm
->acpi
->device
, event
, hkey
);
1652 static void hotkey_resume(void)
1654 tpacpi_input_send_radiosw();
1655 hotkey_poll_setup_safe(1);
1659 * Call with hotkey_mutex held
1661 static int hotkey_get(int *status
, u32
*mask
)
1663 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1666 if (tp_features
.hotkey_mask
)
1667 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
1674 * Call with hotkey_mutex held
1676 static int hotkey_set(int status
, u32 mask
)
1680 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1683 if (tp_features
.hotkey_mask
)
1684 for (i
= 0; i
< 32; i
++) {
1685 int bit
= ((1 << i
) & mask
) != 0;
1686 if (!acpi_evalf(hkey_handle
,
1687 NULL
, "MHKM", "vdd", i
+ 1, bit
))
1694 /* procfs -------------------------------------------------------------- */
1695 static int hotkey_read(char *p
)
1701 if (!tp_features
.hotkey
) {
1702 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1706 res
= mutex_lock_interruptible(&hotkey_mutex
);
1709 res
= hotkey_get(&status
, &mask
);
1710 mutex_unlock(&hotkey_mutex
);
1714 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
1715 if (tp_features
.hotkey_mask
) {
1716 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", mask
);
1717 len
+= sprintf(p
+ len
,
1718 "commands:\tenable, disable, reset, <mask>\n");
1720 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
1721 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
1727 static int hotkey_write(char *buf
)
1734 if (!tp_features
.hotkey
)
1737 res
= mutex_lock_interruptible(&hotkey_mutex
);
1741 res
= hotkey_get(&status
, &mask
);
1746 while ((cmd
= next_cmd(&buf
))) {
1747 if (strlencmp(cmd
, "enable") == 0) {
1749 } else if (strlencmp(cmd
, "disable") == 0) {
1751 } else if (strlencmp(cmd
, "reset") == 0) {
1752 status
= hotkey_orig_status
;
1753 mask
= hotkey_orig_mask
;
1754 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
1756 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
1766 res
= hotkey_set(status
, mask
);
1769 mutex_unlock(&hotkey_mutex
);
1773 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
1774 .hid
= IBM_HKEY_HID
,
1775 .notify
= hotkey_notify
,
1776 .handle
= &hkey_handle
,
1777 .type
= ACPI_DEVICE_NOTIFY
,
1780 static struct ibm_struct hotkey_driver_data
= {
1782 .read
= hotkey_read
,
1783 .write
= hotkey_write
,
1784 .exit
= hotkey_exit
,
1785 .resume
= hotkey_resume
,
1786 .acpi
= &ibm_hotkey_acpidriver
,
1789 /*************************************************************************
1790 * Bluetooth subdriver
1793 /* sysfs bluetooth enable ---------------------------------------------- */
1794 static ssize_t
bluetooth_enable_show(struct device
*dev
,
1795 struct device_attribute
*attr
,
1800 status
= bluetooth_get_radiosw();
1804 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1807 static ssize_t
bluetooth_enable_store(struct device
*dev
,
1808 struct device_attribute
*attr
,
1809 const char *buf
, size_t count
)
1814 if (parse_strtoul(buf
, 1, &t
))
1817 res
= bluetooth_set_radiosw(t
);
1819 return (res
) ? res
: count
;
1822 static struct device_attribute dev_attr_bluetooth_enable
=
1823 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
1824 bluetooth_enable_show
, bluetooth_enable_store
);
1826 /* --------------------------------------------------------------------- */
1828 static struct attribute
*bluetooth_attributes
[] = {
1829 &dev_attr_bluetooth_enable
.attr
,
1833 static const struct attribute_group bluetooth_attr_group
= {
1834 .attrs
= bluetooth_attributes
,
1837 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
1842 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
1844 IBM_ACPIHANDLE_INIT(hkey
);
1846 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1847 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1848 tp_features
.bluetooth
= hkey_handle
&&
1849 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
1851 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
1852 str_supported(tp_features
.bluetooth
),
1855 if (tp_features
.bluetooth
) {
1856 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
1857 /* no bluetooth hardware present in system */
1858 tp_features
.bluetooth
= 0;
1859 dbg_printk(TPACPI_DBG_INIT
,
1860 "bluetooth hardware not installed\n");
1862 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1863 &bluetooth_attr_group
);
1869 return (tp_features
.bluetooth
)? 0 : 1;
1872 static void bluetooth_exit(void)
1874 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1875 &bluetooth_attr_group
);
1878 static int bluetooth_get_radiosw(void)
1882 if (!tp_features
.bluetooth
)
1885 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1888 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
1891 static int bluetooth_set_radiosw(int radio_on
)
1895 if (!tp_features
.bluetooth
)
1898 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1901 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
1903 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
1904 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
1910 /* procfs -------------------------------------------------------------- */
1911 static int bluetooth_read(char *p
)
1914 int status
= bluetooth_get_radiosw();
1916 if (!tp_features
.bluetooth
)
1917 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1919 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1920 (status
)? "enabled" : "disabled");
1921 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1927 static int bluetooth_write(char *buf
)
1931 if (!tp_features
.bluetooth
)
1934 while ((cmd
= next_cmd(&buf
))) {
1935 if (strlencmp(cmd
, "enable") == 0) {
1936 bluetooth_set_radiosw(1);
1937 } else if (strlencmp(cmd
, "disable") == 0) {
1938 bluetooth_set_radiosw(0);
1946 static struct ibm_struct bluetooth_driver_data
= {
1947 .name
= "bluetooth",
1948 .read
= bluetooth_read
,
1949 .write
= bluetooth_write
,
1950 .exit
= bluetooth_exit
,
1953 /*************************************************************************
1957 /* sysfs wan enable ---------------------------------------------------- */
1958 static ssize_t
wan_enable_show(struct device
*dev
,
1959 struct device_attribute
*attr
,
1964 status
= wan_get_radiosw();
1968 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1971 static ssize_t
wan_enable_store(struct device
*dev
,
1972 struct device_attribute
*attr
,
1973 const char *buf
, size_t count
)
1978 if (parse_strtoul(buf
, 1, &t
))
1981 res
= wan_set_radiosw(t
);
1983 return (res
) ? res
: count
;
1986 static struct device_attribute dev_attr_wan_enable
=
1987 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
1988 wan_enable_show
, wan_enable_store
);
1990 /* --------------------------------------------------------------------- */
1992 static struct attribute
*wan_attributes
[] = {
1993 &dev_attr_wan_enable
.attr
,
1997 static const struct attribute_group wan_attr_group
= {
1998 .attrs
= wan_attributes
,
2001 static int __init
wan_init(struct ibm_init_struct
*iibm
)
2006 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
2008 IBM_ACPIHANDLE_INIT(hkey
);
2010 tp_features
.wan
= hkey_handle
&&
2011 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
2013 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
2014 str_supported(tp_features
.wan
),
2017 if (tp_features
.wan
) {
2018 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
2019 /* no wan hardware present in system */
2020 tp_features
.wan
= 0;
2021 dbg_printk(TPACPI_DBG_INIT
,
2022 "wan hardware not installed\n");
2024 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
2031 return (tp_features
.wan
)? 0 : 1;
2034 static void wan_exit(void)
2036 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
2040 static int wan_get_radiosw(void)
2044 if (!tp_features
.wan
)
2047 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2050 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
2053 static int wan_set_radiosw(int radio_on
)
2057 if (!tp_features
.wan
)
2060 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
2063 status
|= TP_ACPI_WANCARD_RADIOSSW
;
2065 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
2066 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
2072 /* procfs -------------------------------------------------------------- */
2073 static int wan_read(char *p
)
2076 int status
= wan_get_radiosw();
2078 if (!tp_features
.wan
)
2079 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2081 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2082 (status
)? "enabled" : "disabled");
2083 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
2089 static int wan_write(char *buf
)
2093 if (!tp_features
.wan
)
2096 while ((cmd
= next_cmd(&buf
))) {
2097 if (strlencmp(cmd
, "enable") == 0) {
2099 } else if (strlencmp(cmd
, "disable") == 0) {
2108 static struct ibm_struct wan_driver_data
= {
2113 .flags
.experimental
= 1,
2116 /*************************************************************************
2120 static enum video_access_mode video_supported
;
2121 static int video_orig_autosw
;
2123 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
2124 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
2125 "\\_SB.PCI0.VID0", /* 770e */
2126 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
2127 "\\_SB.PCI0.AGP.VID", /* all others */
2130 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
2132 static int __init
video_init(struct ibm_init_struct
*iibm
)
2136 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
2138 IBM_ACPIHANDLE_INIT(vid
);
2139 IBM_ACPIHANDLE_INIT(vid2
);
2141 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
2142 /* G41, assume IVGA doesn't change */
2143 vid_handle
= vid2_handle
;
2146 /* video switching not supported on R30, R31 */
2147 video_supported
= TPACPI_VIDEO_NONE
;
2148 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
2150 video_supported
= TPACPI_VIDEO_570
;
2151 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
2152 /* 600e/x, 770e, 770x */
2153 video_supported
= TPACPI_VIDEO_770
;
2156 video_supported
= TPACPI_VIDEO_NEW
;
2158 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
2159 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
2162 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
2165 static void video_exit(void)
2167 dbg_printk(TPACPI_DBG_EXIT
,
2168 "restoring original video autoswitch mode\n");
2169 if (video_autosw_set(video_orig_autosw
))
2170 printk(IBM_ERR
"error while trying to restore original "
2171 "video autoswitch mode\n");
2174 static int video_outputsw_get(void)
2179 switch (video_supported
) {
2180 case TPACPI_VIDEO_570
:
2181 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
2182 TP_ACPI_VIDEO_570_PHSCMD
))
2184 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
2186 case TPACPI_VIDEO_770
:
2187 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2190 status
|= TP_ACPI_VIDEO_S_LCD
;
2191 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2194 status
|= TP_ACPI_VIDEO_S_CRT
;
2196 case TPACPI_VIDEO_NEW
:
2197 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
2198 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
2201 status
|= TP_ACPI_VIDEO_S_CRT
;
2203 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
2204 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
2207 status
|= TP_ACPI_VIDEO_S_LCD
;
2208 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
2211 status
|= TP_ACPI_VIDEO_S_DVI
;
2220 static int video_outputsw_set(int status
)
2225 switch (video_supported
) {
2226 case TPACPI_VIDEO_570
:
2227 res
= acpi_evalf(NULL
, NULL
,
2228 "\\_SB.PHS2", "vdd",
2229 TP_ACPI_VIDEO_570_PHS2CMD
,
2230 status
| TP_ACPI_VIDEO_570_PHS2SET
);
2232 case TPACPI_VIDEO_770
:
2233 autosw
= video_autosw_get();
2237 res
= video_autosw_set(1);
2240 res
= acpi_evalf(vid_handle
, NULL
,
2241 "ASWT", "vdd", status
* 0x100, 0);
2242 if (!autosw
&& video_autosw_set(autosw
)) {
2243 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
2247 case TPACPI_VIDEO_NEW
:
2248 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
2249 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
2255 return (res
)? 0 : -EIO
;
2258 static int video_autosw_get(void)
2262 switch (video_supported
) {
2263 case TPACPI_VIDEO_570
:
2264 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
2267 case TPACPI_VIDEO_770
:
2268 case TPACPI_VIDEO_NEW
:
2269 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
2279 static int video_autosw_set(int enable
)
2281 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
2286 static int video_outputsw_cycle(void)
2288 int autosw
= video_autosw_get();
2294 switch (video_supported
) {
2295 case TPACPI_VIDEO_570
:
2296 res
= video_autosw_set(1);
2299 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
2301 case TPACPI_VIDEO_770
:
2302 case TPACPI_VIDEO_NEW
:
2303 res
= video_autosw_set(1);
2306 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
2311 if (!autosw
&& video_autosw_set(autosw
)) {
2312 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
2316 return (res
)? 0 : -EIO
;
2319 static int video_expand_toggle(void)
2321 switch (video_supported
) {
2322 case TPACPI_VIDEO_570
:
2323 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
2325 case TPACPI_VIDEO_770
:
2326 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
2328 case TPACPI_VIDEO_NEW
:
2329 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
2337 static int video_read(char *p
)
2342 if (video_supported
== TPACPI_VIDEO_NONE
) {
2343 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2347 status
= video_outputsw_get();
2351 autosw
= video_autosw_get();
2355 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2356 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
2357 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
2358 if (video_supported
== TPACPI_VIDEO_NEW
)
2359 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
2360 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
2361 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
2362 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
2363 if (video_supported
== TPACPI_VIDEO_NEW
)
2364 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
2365 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
2366 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
2371 static int video_write(char *buf
)
2374 int enable
, disable
, status
;
2377 if (video_supported
== TPACPI_VIDEO_NONE
)
2383 while ((cmd
= next_cmd(&buf
))) {
2384 if (strlencmp(cmd
, "lcd_enable") == 0) {
2385 enable
|= TP_ACPI_VIDEO_S_LCD
;
2386 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
2387 disable
|= TP_ACPI_VIDEO_S_LCD
;
2388 } else if (strlencmp(cmd
, "crt_enable") == 0) {
2389 enable
|= TP_ACPI_VIDEO_S_CRT
;
2390 } else if (strlencmp(cmd
, "crt_disable") == 0) {
2391 disable
|= TP_ACPI_VIDEO_S_CRT
;
2392 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2393 strlencmp(cmd
, "dvi_enable") == 0) {
2394 enable
|= TP_ACPI_VIDEO_S_DVI
;
2395 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2396 strlencmp(cmd
, "dvi_disable") == 0) {
2397 disable
|= TP_ACPI_VIDEO_S_DVI
;
2398 } else if (strlencmp(cmd
, "auto_enable") == 0) {
2399 res
= video_autosw_set(1);
2402 } else if (strlencmp(cmd
, "auto_disable") == 0) {
2403 res
= video_autosw_set(0);
2406 } else if (strlencmp(cmd
, "video_switch") == 0) {
2407 res
= video_outputsw_cycle();
2410 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
2411 res
= video_expand_toggle();
2418 if (enable
|| disable
) {
2419 status
= video_outputsw_get();
2422 res
= video_outputsw_set((status
& ~disable
) | enable
);
2430 static struct ibm_struct video_driver_data
= {
2433 .write
= video_write
,
2437 /*************************************************************************
2438 * Light (thinklight) subdriver
2441 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
2442 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
2444 static int __init
light_init(struct ibm_init_struct
*iibm
)
2446 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
2448 IBM_ACPIHANDLE_INIT(ledb
);
2449 IBM_ACPIHANDLE_INIT(lght
);
2450 IBM_ACPIHANDLE_INIT(cmos
);
2452 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
2453 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
2455 if (tp_features
.light
)
2456 /* light status not supported on
2457 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
2458 tp_features
.light_status
=
2459 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
2461 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
2462 str_supported(tp_features
.light
));
2464 return (tp_features
.light
)? 0 : 1;
2467 static int light_read(char *p
)
2472 if (!tp_features
.light
) {
2473 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2474 } else if (!tp_features
.light_status
) {
2475 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
2476 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2478 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
2480 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
2481 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2487 static int light_write(char *buf
)
2489 int cmos_cmd
, lght_cmd
;
2493 if (!tp_features
.light
)
2496 while ((cmd
= next_cmd(&buf
))) {
2497 if (strlencmp(cmd
, "on") == 0) {
2500 } else if (strlencmp(cmd
, "off") == 0) {
2506 success
= cmos_handle
?
2507 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
2508 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
2516 static struct ibm_struct light_driver_data
= {
2519 .write
= light_write
,
2522 /*************************************************************************
2526 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2528 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
2529 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
2530 "\\_SB.PCI0.PCI1.DOCK", /* all others */
2531 "\\_SB.PCI.ISA.SLCE", /* 570 */
2532 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
2534 /* don't list other alternatives as we install a notify handler on the 570 */
2535 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
2537 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
2539 .notify
= dock_notify
,
2540 .handle
= &dock_handle
,
2541 .type
= ACPI_SYSTEM_NOTIFY
,
2544 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
2545 * We just use it to get notifications of dock hotplug
2546 * in very old thinkpads */
2547 .hid
= PCI_ROOT_HID_STRING
,
2548 .notify
= dock_notify
,
2549 .handle
= &pci_handle
,
2550 .type
= ACPI_SYSTEM_NOTIFY
,
2554 static struct ibm_struct dock_driver_data
[2] = {
2558 .write
= dock_write
,
2559 .acpi
= &ibm_dock_acpidriver
[0],
2563 .acpi
= &ibm_dock_acpidriver
[1],
2567 #define dock_docked() (_sta(dock_handle) & 1)
2569 static int __init
dock_init(struct ibm_init_struct
*iibm
)
2571 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
2573 IBM_ACPIHANDLE_INIT(dock
);
2575 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
2576 str_supported(dock_handle
!= NULL
));
2578 return (dock_handle
)? 0 : 1;
2581 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
2585 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
2587 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
2588 dock_driver_data
[0].flags
.acpi_notify_installed
) {
2589 IBM_ACPIHANDLE_INIT(pci
);
2590 dock2_needed
= (pci_handle
!= NULL
);
2591 vdbg_printk(TPACPI_DBG_INIT
,
2592 "dock PCI handler for the TP 570 is %s\n",
2593 str_supported(dock2_needed
));
2595 vdbg_printk(TPACPI_DBG_INIT
,
2596 "dock subdriver part 2 not required\n");
2600 return (dock2_needed
)? 0 : 1;
2603 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
2605 int docked
= dock_docked();
2606 int pci
= ibm
->acpi
->hid
&& strstr(ibm
->acpi
->hid
, PCI_ROOT_HID_STRING
);
2608 if (event
== 1 && !pci
) /* 570 */
2609 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
2610 else if (event
== 1 && pci
) /* 570 */
2611 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
2612 else if (event
== 3 && docked
)
2613 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
2614 else if (event
== 3 && !docked
)
2615 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 2); /* undock */
2616 else if (event
== 0 && docked
)
2617 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
2619 printk(IBM_ERR
"unknown dock event %d, status %d\n",
2620 event
, _sta(dock_handle
));
2621 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0); /* unknown */
2625 static int dock_read(char *p
)
2628 int docked
= dock_docked();
2631 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2633 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
2635 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
2636 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
2642 static int dock_write(char *buf
)
2649 while ((cmd
= next_cmd(&buf
))) {
2650 if (strlencmp(cmd
, "undock") == 0) {
2651 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
2652 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
2654 } else if (strlencmp(cmd
, "dock") == 0) {
2655 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
2664 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
2666 /*************************************************************************
2670 #ifdef CONFIG_THINKPAD_ACPI_BAY
2671 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
2672 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
2673 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
2674 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
2675 ); /* A21e, R30, R31 */
2676 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
2677 "_EJ0", /* all others */
2678 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
2679 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
2680 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
2682 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
2686 static int __init
bay_init(struct ibm_init_struct
*iibm
)
2688 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
2690 IBM_ACPIHANDLE_INIT(bay
);
2692 IBM_ACPIHANDLE_INIT(bay_ej
);
2693 IBM_ACPIHANDLE_INIT(bay2
);
2695 IBM_ACPIHANDLE_INIT(bay2_ej
);
2697 tp_features
.bay_status
= bay_handle
&&
2698 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
2699 tp_features
.bay_status2
= bay2_handle
&&
2700 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
2702 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
2703 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
2704 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
2705 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
2707 vdbg_printk(TPACPI_DBG_INIT
,
2708 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
2709 str_supported(tp_features
.bay_status
),
2710 str_supported(tp_features
.bay_eject
),
2711 str_supported(tp_features
.bay_status2
),
2712 str_supported(tp_features
.bay_eject2
));
2714 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
2715 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
2718 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
2720 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
2723 #define bay_occupied(b) (_sta(b##_handle) & 1)
2725 static int bay_read(char *p
)
2728 int occupied
= bay_occupied(bay
);
2729 int occupied2
= bay_occupied(bay2
);
2732 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2733 tp_features
.bay_status
?
2734 (occupied
? "occupied" : "unoccupied") :
2736 if (tp_features
.bay_status2
)
2737 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
2738 "occupied" : "unoccupied");
2740 eject
= tp_features
.bay_eject
&& occupied
;
2741 eject2
= tp_features
.bay_eject2
&& occupied2
;
2743 if (eject
&& eject2
)
2744 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
2746 len
+= sprintf(p
+ len
, "commands:\teject\n");
2748 len
+= sprintf(p
+ len
, "commands:\teject2\n");
2753 static int bay_write(char *buf
)
2757 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
2760 while ((cmd
= next_cmd(&buf
))) {
2761 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
2762 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
2764 } else if (tp_features
.bay_eject2
&&
2765 strlencmp(cmd
, "eject2") == 0) {
2766 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
2775 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
2776 .notify
= bay_notify
,
2777 .handle
= &bay_handle
,
2778 .type
= ACPI_SYSTEM_NOTIFY
,
2781 static struct ibm_struct bay_driver_data
= {
2785 .acpi
= &ibm_bay_acpidriver
,
2788 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2790 /*************************************************************************
2794 /* sysfs cmos_command -------------------------------------------------- */
2795 static ssize_t
cmos_command_store(struct device
*dev
,
2796 struct device_attribute
*attr
,
2797 const char *buf
, size_t count
)
2799 unsigned long cmos_cmd
;
2802 if (parse_strtoul(buf
, 21, &cmos_cmd
))
2805 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2806 return (res
)? res
: count
;
2809 static struct device_attribute dev_attr_cmos_command
=
2810 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
2812 /* --------------------------------------------------------------------- */
2814 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
2818 vdbg_printk(TPACPI_DBG_INIT
,
2819 "initializing cmos commands subdriver\n");
2821 IBM_ACPIHANDLE_INIT(cmos
);
2823 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
2824 str_supported(cmos_handle
!= NULL
));
2826 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2830 return (cmos_handle
)? 0 : 1;
2833 static void cmos_exit(void)
2835 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2838 static int cmos_read(char *p
)
2842 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2843 R30, R31, T20-22, X20-21 */
2845 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2847 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2848 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
2854 static int cmos_write(char *buf
)
2859 while ((cmd
= next_cmd(&buf
))) {
2860 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
2861 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
2866 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2874 static struct ibm_struct cmos_driver_data
= {
2877 .write
= cmos_write
,
2881 /*************************************************************************
2885 static enum led_access_mode led_supported
;
2887 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
2888 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2889 "LED", /* all others */
2892 static int __init
led_init(struct ibm_init_struct
*iibm
)
2894 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
2896 IBM_ACPIHANDLE_INIT(led
);
2899 /* led not supported on R30, R31 */
2900 led_supported
= TPACPI_LED_NONE
;
2901 else if (strlencmp(led_path
, "SLED") == 0)
2903 led_supported
= TPACPI_LED_570
;
2904 else if (strlencmp(led_path
, "SYSL") == 0)
2905 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2906 led_supported
= TPACPI_LED_OLD
;
2909 led_supported
= TPACPI_LED_NEW
;
2911 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
2912 str_supported(led_supported
), led_supported
);
2914 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
2917 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2919 static int led_read(char *p
)
2923 if (!led_supported
) {
2924 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2927 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2929 if (led_supported
== TPACPI_LED_570
) {
2932 for (i
= 0; i
< 8; i
++) {
2933 if (!acpi_evalf(ec_handle
,
2934 &status
, "GLED", "dd", 1 << i
))
2936 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
2937 i
, led_status(status
));
2941 len
+= sprintf(p
+ len
, "commands:\t"
2942 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2947 /* off, on, blink */
2948 static const int led_sled_arg1
[] = { 0, 1, 3 };
2949 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
2950 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
2951 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
2953 static int led_write(char *buf
)
2961 while ((cmd
= next_cmd(&buf
))) {
2962 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
2965 if (strstr(cmd
, "off")) {
2967 } else if (strstr(cmd
, "on")) {
2969 } else if (strstr(cmd
, "blink")) {
2974 if (led_supported
== TPACPI_LED_570
) {
2977 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2978 led
, led_sled_arg1
[ind
]))
2980 } else if (led_supported
== TPACPI_LED_OLD
) {
2981 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2983 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
2986 ec_write(TPACPI_LED_EC_HLBL
,
2987 led
* led_exp_hlbl
[ind
]);
2990 ec_write(TPACPI_LED_EC_HLCL
,
2991 led
* led_exp_hlcl
[ind
]);
2996 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2997 led
, led_led_arg1
[ind
]))
3005 static struct ibm_struct led_driver_data
= {
3011 /*************************************************************************
3015 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
3017 static int __init
beep_init(struct ibm_init_struct
*iibm
)
3019 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
3021 IBM_ACPIHANDLE_INIT(beep
);
3023 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
3024 str_supported(beep_handle
!= NULL
));
3026 return (beep_handle
)? 0 : 1;
3029 static int beep_read(char *p
)
3034 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
3036 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
3037 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
3043 static int beep_write(char *buf
)
3051 while ((cmd
= next_cmd(&buf
))) {
3052 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
3053 beep_cmd
>= 0 && beep_cmd
<= 17) {
3057 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
3064 static struct ibm_struct beep_driver_data
= {
3067 .write
= beep_write
,
3070 /*************************************************************************
3074 static enum thermal_access_mode thermal_read_mode
;
3076 /* sysfs temp##_input -------------------------------------------------- */
3078 static ssize_t
thermal_temp_input_show(struct device
*dev
,
3079 struct device_attribute
*attr
,
3082 struct sensor_device_attribute
*sensor_attr
=
3083 to_sensor_dev_attr(attr
);
3084 int idx
= sensor_attr
->index
;
3088 res
= thermal_get_sensor(idx
, &value
);
3091 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
3094 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
3097 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
3098 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
3100 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
3101 THERMAL_SENSOR_ATTR_TEMP(1, 0),
3102 THERMAL_SENSOR_ATTR_TEMP(2, 1),
3103 THERMAL_SENSOR_ATTR_TEMP(3, 2),
3104 THERMAL_SENSOR_ATTR_TEMP(4, 3),
3105 THERMAL_SENSOR_ATTR_TEMP(5, 4),
3106 THERMAL_SENSOR_ATTR_TEMP(6, 5),
3107 THERMAL_SENSOR_ATTR_TEMP(7, 6),
3108 THERMAL_SENSOR_ATTR_TEMP(8, 7),
3109 THERMAL_SENSOR_ATTR_TEMP(9, 8),
3110 THERMAL_SENSOR_ATTR_TEMP(10, 9),
3111 THERMAL_SENSOR_ATTR_TEMP(11, 10),
3112 THERMAL_SENSOR_ATTR_TEMP(12, 11),
3113 THERMAL_SENSOR_ATTR_TEMP(13, 12),
3114 THERMAL_SENSOR_ATTR_TEMP(14, 13),
3115 THERMAL_SENSOR_ATTR_TEMP(15, 14),
3116 THERMAL_SENSOR_ATTR_TEMP(16, 15),
3119 #define THERMAL_ATTRS(X) \
3120 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
3122 static struct attribute
*thermal_temp_input_attr
[] = {
3142 static const struct attribute_group thermal_temp_input16_group
= {
3143 .attrs
= thermal_temp_input_attr
3146 static const struct attribute_group thermal_temp_input8_group
= {
3147 .attrs
= &thermal_temp_input_attr
[8]
3150 #undef THERMAL_SENSOR_ATTR_TEMP
3151 #undef THERMAL_ATTRS
3153 /* --------------------------------------------------------------------- */
3155 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
3162 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
3164 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
3166 if (thinkpad_id
.ec_model
) {
3168 * Direct EC access mode: sensors at registers
3169 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
3170 * non-implemented, thermal sensors return 0x80 when
3175 for (i
= 0; i
< 8; i
++) {
3176 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
3182 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
3190 /* This is sheer paranoia, but we handle it anyway */
3193 "ThinkPad ACPI EC access misbehaving, "
3194 "falling back to ACPI TMPx access mode\n");
3195 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
3198 "ThinkPad ACPI EC access misbehaving, "
3199 "disabling thermal sensors access\n");
3200 thermal_read_mode
= TPACPI_THERMAL_NONE
;
3205 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
3207 } else if (acpi_tmp7
) {
3208 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
3209 /* 600e/x, 770e, 770x */
3210 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
3212 /* Standard ACPI TMPx access, max 8 sensors */
3213 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
3216 /* temperatures not supported on 570, G4x, R30, R31, R32 */
3217 thermal_read_mode
= TPACPI_THERMAL_NONE
;
3220 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
3221 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
3224 switch(thermal_read_mode
) {
3225 case TPACPI_THERMAL_TPEC_16
:
3226 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3227 &thermal_temp_input16_group
);
3231 case TPACPI_THERMAL_TPEC_8
:
3232 case TPACPI_THERMAL_ACPI_TMP07
:
3233 case TPACPI_THERMAL_ACPI_UPDT
:
3234 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
3235 &thermal_temp_input8_group
);
3239 case TPACPI_THERMAL_NONE
:
3247 static void thermal_exit(void)
3249 switch(thermal_read_mode
) {
3250 case TPACPI_THERMAL_TPEC_16
:
3251 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3252 &thermal_temp_input16_group
);
3254 case TPACPI_THERMAL_TPEC_8
:
3255 case TPACPI_THERMAL_ACPI_TMP07
:
3256 case TPACPI_THERMAL_ACPI_UPDT
:
3257 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
3258 &thermal_temp_input16_group
);
3260 case TPACPI_THERMAL_NONE
:
3266 /* idx is zero-based */
3267 static int thermal_get_sensor(int idx
, s32
*value
)
3273 t
= TP_EC_THERMAL_TMP0
;
3275 switch (thermal_read_mode
) {
3276 #if TPACPI_MAX_THERMAL_SENSORS >= 16
3277 case TPACPI_THERMAL_TPEC_16
:
3278 if (idx
>= 8 && idx
<= 15) {
3279 t
= TP_EC_THERMAL_TMP8
;
3284 case TPACPI_THERMAL_TPEC_8
:
3286 if (!acpi_ec_read(t
+ idx
, &tmp
))
3288 *value
= tmp
* 1000;
3293 case TPACPI_THERMAL_ACPI_UPDT
:
3295 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3296 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
3298 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3300 *value
= (t
- 2732) * 100;
3305 case TPACPI_THERMAL_ACPI_TMP07
:
3307 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
3308 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
3310 if (t
> 127 || t
< -127)
3311 t
= TP_EC_THERMAL_TMP_NA
;
3317 case TPACPI_THERMAL_NONE
:
3325 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
3336 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
3339 for(i
= 0 ; i
< n
; i
++) {
3340 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
3348 static int thermal_read(char *p
)
3352 struct ibm_thermal_sensors_struct t
;
3354 n
= thermal_get_sensors(&t
);
3355 if (unlikely(n
< 0))
3358 len
+= sprintf(p
+ len
, "temperatures:\t");
3361 for (i
= 0; i
< (n
- 1); i
++)
3362 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
3363 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
3365 len
+= sprintf(p
+ len
, "not supported\n");
3370 static struct ibm_struct thermal_driver_data
= {
3372 .read
= thermal_read
,
3373 .exit
= thermal_exit
,
3376 /*************************************************************************
3380 static u8 ecdump_regs
[256];
3382 static int ecdump_read(char *p
)
3388 len
+= sprintf(p
+ len
, "EC "
3389 " +00 +01 +02 +03 +04 +05 +06 +07"
3390 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
3391 for (i
= 0; i
< 256; i
+= 16) {
3392 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
3393 for (j
= 0; j
< 16; j
++) {
3394 if (!acpi_ec_read(i
+ j
, &v
))
3396 if (v
!= ecdump_regs
[i
+ j
])
3397 len
+= sprintf(p
+ len
, " *%02x", v
);
3399 len
+= sprintf(p
+ len
, " %02x", v
);
3400 ecdump_regs
[i
+ j
] = v
;
3402 len
+= sprintf(p
+ len
, "\n");
3407 /* These are way too dangerous to advertise openly... */
3409 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
3410 " (<offset> is 00-ff, <value> is 00-ff)\n");
3411 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
3412 " (<offset> is 00-ff, <value> is 0-255)\n");
3417 static int ecdump_write(char *buf
)
3422 while ((cmd
= next_cmd(&buf
))) {
3423 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
3425 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
3429 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
3430 if (!acpi_ec_write(i
, v
))
3439 static struct ibm_struct ecdump_driver_data
= {
3441 .read
= ecdump_read
,
3442 .write
= ecdump_write
,
3443 .flags
.experimental
= 1,
3446 /*************************************************************************
3447 * Backlight/brightness subdriver
3450 static struct backlight_device
*ibm_backlight_device
;
3452 static struct backlight_properties ibm_backlight_data
= {
3453 .owner
= THIS_MODULE
,
3454 .get_brightness
= brightness_get
,
3455 .update_status
= brightness_update_status
,
3456 .max_brightness
= 7,
3459 static struct mutex brightness_mutex
;
3461 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
3465 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
3467 mutex_init(&brightness_mutex
);
3469 if (!brightness_mode
) {
3470 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
3471 brightness_mode
= 2;
3473 brightness_mode
= 3;
3475 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
3479 if (brightness_mode
> 3)
3482 b
= brightness_get(NULL
);
3486 ibm_backlight_device
= backlight_device_register(
3487 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
3488 &ibm_backlight_data
);
3489 if (IS_ERR(ibm_backlight_device
)) {
3490 printk(IBM_ERR
"Could not register backlight device\n");
3491 return PTR_ERR(ibm_backlight_device
);
3493 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
3495 ibm_backlight_device
->props
->brightness
= b
;
3496 brightness_update_status(ibm_backlight_device
);
3501 static void brightness_exit(void)
3503 if (ibm_backlight_device
) {
3504 vdbg_printk(TPACPI_DBG_EXIT
,
3505 "calling backlight_device_unregister()\n");
3506 backlight_device_unregister(ibm_backlight_device
);
3507 ibm_backlight_device
= NULL
;
3511 static int brightness_update_status(struct backlight_device
*bd
)
3513 return brightness_set(
3514 (bd
->props
->fb_blank
== FB_BLANK_UNBLANK
&&
3515 bd
->props
->power
== FB_BLANK_UNBLANK
) ?
3516 bd
->props
->brightness
: 0);
3520 * ThinkPads can read brightness from two places: EC 0x31, or
3521 * CMOS NVRAM byte 0x5E, bits 0-3.
3523 static int brightness_get(struct backlight_device
*bd
)
3525 u8 lec
= 0, lcmos
= 0, level
= 0;
3527 if (brightness_mode
& 1) {
3528 if (!acpi_ec_read(brightness_offset
, &lec
))
3533 if (brightness_mode
& 2) {
3534 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
3535 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
3536 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
3540 if (brightness_mode
== 3 && lec
!= lcmos
) {
3542 "CMOS NVRAM (%u) and EC (%u) do not agree "
3543 "on display brightness level\n",
3544 (unsigned int) lcmos
,
3545 (unsigned int) lec
);
3552 static int brightness_set(int value
)
3554 int cmos_cmd
, inc
, i
, res
;
3560 res
= mutex_lock_interruptible(&brightness_mutex
);
3564 current_value
= brightness_get(NULL
);
3565 if (current_value
< 0) {
3566 res
= current_value
;
3570 cmos_cmd
= value
> current_value
?
3571 TP_CMOS_BRIGHTNESS_UP
:
3572 TP_CMOS_BRIGHTNESS_DOWN
;
3573 inc
= value
> current_value
? 1 : -1;
3576 for (i
= current_value
; i
!= value
; i
+= inc
) {
3577 if ((brightness_mode
& 2) &&
3578 issue_thinkpad_cmos_command(cmos_cmd
)) {
3582 if ((brightness_mode
& 1) &&
3583 !acpi_ec_write(brightness_offset
, i
+ inc
)) {
3590 mutex_unlock(&brightness_mutex
);
3594 static int brightness_read(char *p
)
3599 if ((level
= brightness_get(NULL
)) < 0) {
3600 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3602 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
3603 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
3604 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3605 " (<level> is 0-7)\n");
3611 static int brightness_write(char *buf
)
3617 while ((cmd
= next_cmd(&buf
))) {
3618 if ((level
= brightness_get(NULL
)) < 0)
3622 if (strlencmp(cmd
, "up") == 0) {
3623 new_level
= level
== 7 ? 7 : level
+ 1;
3624 } else if (strlencmp(cmd
, "down") == 0) {
3625 new_level
= level
== 0 ? 0 : level
- 1;
3626 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3627 new_level
>= 0 && new_level
<= 7) {
3632 brightness_set(new_level
);
3638 static struct ibm_struct brightness_driver_data
= {
3639 .name
= "brightness",
3640 .read
= brightness_read
,
3641 .write
= brightness_write
,
3642 .exit
= brightness_exit
,
3645 /*************************************************************************
3649 static int volume_read(char *p
)
3654 if (!acpi_ec_read(volume_offset
, &level
)) {
3655 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3657 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
3658 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
3659 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
3660 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3661 " (<level> is 0-15)\n");
3667 static int volume_write(char *buf
)
3669 int cmos_cmd
, inc
, i
;
3671 int new_level
, new_mute
;
3674 while ((cmd
= next_cmd(&buf
))) {
3675 if (!acpi_ec_read(volume_offset
, &level
))
3677 new_mute
= mute
= level
& 0x40;
3678 new_level
= level
= level
& 0xf;
3680 if (strlencmp(cmd
, "up") == 0) {
3684 new_level
= level
== 15 ? 15 : level
+ 1;
3685 } else if (strlencmp(cmd
, "down") == 0) {
3689 new_level
= level
== 0 ? 0 : level
- 1;
3690 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3691 new_level
>= 0 && new_level
<= 15) {
3693 } else if (strlencmp(cmd
, "mute") == 0) {
3698 if (new_level
!= level
) { /* mute doesn't change */
3699 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
3700 inc
= new_level
> level
? 1 : -1;
3702 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
3703 !acpi_ec_write(volume_offset
, level
)))
3706 for (i
= level
; i
!= new_level
; i
+= inc
)
3707 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3708 !acpi_ec_write(volume_offset
, i
+ inc
))
3711 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
3712 !acpi_ec_write(volume_offset
,
3717 if (new_mute
!= mute
) { /* level doesn't change */
3718 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
3720 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3721 !acpi_ec_write(volume_offset
, level
+ new_mute
))
3729 static struct ibm_struct volume_driver_data
= {
3731 .read
= volume_read
,
3732 .write
= volume_write
,
3735 /*************************************************************************
3742 * TPACPI_FAN_RD_ACPI_GFAN:
3743 * ACPI GFAN method: returns fan level
3745 * see TPACPI_FAN_WR_ACPI_SFAN
3746 * EC 0x2f (HFSP) not available if GFAN exists
3748 * TPACPI_FAN_WR_ACPI_SFAN:
3749 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
3751 * EC 0x2f (HFSP) might be available *for reading*, but do not use
3754 * TPACPI_FAN_WR_TPEC:
3755 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
3756 * Supported on almost all ThinkPads
3758 * Fan speed changes of any sort (including those caused by the
3759 * disengaged mode) are usually done slowly by the firmware as the
3760 * maximum ammount of fan duty cycle change per second seems to be
3763 * Reading is not available if GFAN exists.
3764 * Writing is not available if SFAN exists.
3767 * 7 automatic mode engaged;
3768 * (default operation mode of the ThinkPad)
3769 * fan level is ignored in this mode.
3770 * 6 full speed mode (takes precedence over bit 7);
3771 * not available on all thinkpads. May disable
3772 * the tachometer while the fan controller ramps up
3773 * the speed (which can take up to a few *minutes*).
3774 * Speeds up fan to 100% duty-cycle, which is far above
3775 * the standard RPM levels. It is not impossible that
3776 * it could cause hardware damage.
3777 * 5-3 unused in some models. Extra bits for fan level
3778 * in others, but still useless as all values above
3779 * 7 map to the same speed as level 7 in these models.
3780 * 2-0 fan level (0..7 usually)
3782 * 0x07 = max (set when temperatures critical)
3783 * Some ThinkPads may have other levels, see
3784 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
3786 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
3787 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
3788 * does so, its initial value is meaningless (0x07).
3790 * For firmware bugs, refer to:
3791 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3795 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
3796 * Main fan tachometer reading (in RPM)
3798 * This register is present on all ThinkPads with a new-style EC, and
3799 * it is known not to be present on the A21m/e, and T22, as there is
3800 * something else in offset 0x84 according to the ACPI DSDT. Other
3801 * ThinkPads from this same time period (and earlier) probably lack the
3802 * tachometer as well.
3804 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
3805 * was never fixed by IBM to report the EC firmware version string
3806 * probably support the tachometer (like the early X models), so
3807 * detecting it is quite hard. We need more data to know for sure.
3809 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
3812 * FIRMWARE BUG: may go stale while the EC is switching to full speed
3815 * For firmware bugs, refer to:
3816 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3818 * TPACPI_FAN_WR_ACPI_FANS:
3819 * ThinkPad X31, X40, X41. Not available in the X60.
3821 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3822 * high speed. ACPI DSDT seems to map these three speeds to levels
3823 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3824 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3826 * The speeds are stored on handles
3827 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3829 * There are three default speed sets, acessible as handles:
3830 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3832 * ACPI DSDT switches which set is in use depending on various
3835 * TPACPI_FAN_WR_TPEC is also available and should be used to
3836 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3837 * but the ACPI tables just mention level 7.
3840 static enum fan_status_access_mode fan_status_access_mode
;
3841 static enum fan_control_access_mode fan_control_access_mode
;
3842 static enum fan_control_commands fan_control_commands
;
3844 static u8 fan_control_initial_status
;
3845 static u8 fan_control_desired_level
;
3847 static void fan_watchdog_fire(struct work_struct
*ignored
);
3848 static int fan_watchdog_maxinterval
;
3849 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
3851 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
3852 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
3853 "\\FSPD", /* 600e/x, 770e, 770x */
3855 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
3856 "JFNS", /* 770x-JL */
3860 * SYSFS fan layout: hwmon compatible (device)
3863 * 0: "disengaged" mode
3865 * 2: native EC "auto" mode (recommended, hardware default)
3867 * pwm*: set speed in manual mode, ignored otherwise.
3868 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3871 * fan*_input: tachometer reading, RPM
3874 * SYSFS fan layout: extensions
3876 * fan_watchdog (driver):
3877 * fan watchdog interval in seconds, 0 disables (default), max 120
3880 /* sysfs fan pwm1_enable ----------------------------------------------- */
3881 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
3882 struct device_attribute
*attr
,
3888 res
= fan_get_status_safe(&status
);
3892 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3893 if (status
!= fan_control_initial_status
) {
3894 tp_features
.fan_ctrl_status_undef
= 0;
3896 /* Return most likely status. In fact, it
3897 * might be the only possible status */
3898 status
= TP_EC_FAN_AUTO
;
3902 if (status
& TP_EC_FAN_FULLSPEED
) {
3904 } else if (status
& TP_EC_FAN_AUTO
) {
3909 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
3912 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
3913 struct device_attribute
*attr
,
3914 const char *buf
, size_t count
)
3919 if (parse_strtoul(buf
, 2, &t
))
3924 level
= TP_EC_FAN_FULLSPEED
;
3927 level
= TPACPI_FAN_LAST_LEVEL
;
3930 level
= TP_EC_FAN_AUTO
;
3933 /* reserved for software-controlled auto mode */
3939 res
= fan_set_level_safe(level
);
3945 fan_watchdog_reset();
3950 static struct device_attribute dev_attr_fan_pwm1_enable
=
3951 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
3952 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
3954 /* sysfs fan pwm1 ------------------------------------------------------ */
3955 static ssize_t
fan_pwm1_show(struct device
*dev
,
3956 struct device_attribute
*attr
,
3962 res
= fan_get_status_safe(&status
);
3966 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3967 if (status
!= fan_control_initial_status
) {
3968 tp_features
.fan_ctrl_status_undef
= 0;
3970 status
= TP_EC_FAN_AUTO
;
3975 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
3976 status
= fan_control_desired_level
;
3981 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
3984 static ssize_t
fan_pwm1_store(struct device
*dev
,
3985 struct device_attribute
*attr
,
3986 const char *buf
, size_t count
)
3990 u8 status
, newlevel
;
3992 if (parse_strtoul(buf
, 255, &s
))
3995 /* scale down from 0-255 to 0-7 */
3996 newlevel
= (s
>> 5) & 0x07;
3998 rc
= mutex_lock_interruptible(&fan_mutex
);
4002 rc
= fan_get_status(&status
);
4003 if (!rc
&& (status
&
4004 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
4005 rc
= fan_set_level(newlevel
);
4009 fan_update_desired_level(newlevel
);
4010 fan_watchdog_reset();
4014 mutex_unlock(&fan_mutex
);
4015 return (rc
)? rc
: count
;
4018 static struct device_attribute dev_attr_fan_pwm1
=
4019 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
4020 fan_pwm1_show
, fan_pwm1_store
);
4022 /* sysfs fan fan1_input ------------------------------------------------ */
4023 static ssize_t
fan_fan1_input_show(struct device
*dev
,
4024 struct device_attribute
*attr
,
4030 res
= fan_get_speed(&speed
);
4034 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
4037 static struct device_attribute dev_attr_fan_fan1_input
=
4038 __ATTR(fan1_input
, S_IRUGO
,
4039 fan_fan1_input_show
, NULL
);
4041 /* sysfs fan fan_watchdog (driver) ------------------------------------- */
4042 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
4045 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
4048 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
4049 const char *buf
, size_t count
)
4053 if (parse_strtoul(buf
, 120, &t
))
4056 if (!fan_control_allowed
)
4059 fan_watchdog_maxinterval
= t
;
4060 fan_watchdog_reset();
4065 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
4066 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
4068 /* --------------------------------------------------------------------- */
4069 static struct attribute
*fan_attributes
[] = {
4070 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
4071 &dev_attr_fan_fan1_input
.attr
,
4075 static const struct attribute_group fan_attr_group
= {
4076 .attrs
= fan_attributes
,
4079 static int __init
fan_init(struct ibm_init_struct
*iibm
)
4083 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
4085 mutex_init(&fan_mutex
);
4086 fan_status_access_mode
= TPACPI_FAN_NONE
;
4087 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
4088 fan_control_commands
= 0;
4089 fan_watchdog_maxinterval
= 0;
4090 tp_features
.fan_ctrl_status_undef
= 0;
4091 fan_control_desired_level
= 7;
4093 IBM_ACPIHANDLE_INIT(fans
);
4094 IBM_ACPIHANDLE_INIT(gfan
);
4095 IBM_ACPIHANDLE_INIT(sfan
);
4098 /* 570, 600e/x, 770e, 770x */
4099 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
4101 /* all other ThinkPads: note that even old-style
4102 * ThinkPad ECs supports the fan control register */
4103 if (likely(acpi_ec_read(fan_status_offset
,
4104 &fan_control_initial_status
))) {
4105 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
4107 /* In some ThinkPads, neither the EC nor the ACPI
4108 * DSDT initialize the fan status, and it ends up
4109 * being set to 0x07 when it *could* be either
4112 * Enable for TP-1Y (T43), TP-78 (R51e),
4113 * TP-76 (R52), TP-70 (T43, R52), which are known
4115 if (fan_control_initial_status
== 0x07) {
4116 switch (thinkpad_id
.ec_model
) {
4117 case 0x5931: /* TP-1Y */
4118 case 0x3837: /* TP-78 */
4119 case 0x3637: /* TP-76 */
4120 case 0x3037: /* TP-70 */
4122 "fan_init: initial fan status is "
4123 "unknown, assuming it is in auto "
4125 tp_features
.fan_ctrl_status_undef
= 1;
4131 "ThinkPad ACPI EC access misbehaving, "
4132 "fan status and control unavailable\n");
4139 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
4140 fan_control_commands
|=
4141 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
4144 /* gfan without sfan means no fan control */
4145 /* all other models implement TP EC 0x2f control */
4149 fan_control_access_mode
=
4150 TPACPI_FAN_WR_ACPI_FANS
;
4151 fan_control_commands
|=
4152 TPACPI_FAN_CMD_SPEED
|
4153 TPACPI_FAN_CMD_LEVEL
|
4154 TPACPI_FAN_CMD_ENABLE
;
4156 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
4157 fan_control_commands
|=
4158 TPACPI_FAN_CMD_LEVEL
|
4159 TPACPI_FAN_CMD_ENABLE
;
4164 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
4165 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
4166 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
4167 fan_status_access_mode
, fan_control_access_mode
);
4169 /* fan control master switch */
4170 if (!fan_control_allowed
) {
4171 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
4172 fan_control_commands
= 0;
4173 dbg_printk(TPACPI_DBG_INIT
,
4174 "fan control features disabled by parameter\n");
4177 /* update fan_control_desired_level */
4178 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
4179 fan_get_status_safe(NULL
);
4181 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
4182 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
4183 rc
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
4186 rc
= driver_create_file(&tpacpi_pdriver
.driver
,
4187 &driver_attr_fan_watchdog
);
4196 * Call with fan_mutex held
4198 static void fan_update_desired_level(u8 status
)
4201 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
4203 fan_control_desired_level
= 7;
4205 fan_control_desired_level
= status
;
4209 static int fan_get_status(u8
*status
)
4214 * Add TPACPI_FAN_RD_ACPI_FANS ? */
4216 switch (fan_status_access_mode
) {
4217 case TPACPI_FAN_RD_ACPI_GFAN
:
4218 /* 570, 600e/x, 770e, 770x */
4220 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
4228 case TPACPI_FAN_RD_TPEC
:
4229 /* all except 570, 600e/x, 770e, 770x */
4230 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
4245 static int fan_get_status_safe(u8
*status
)
4250 rc
= mutex_lock_interruptible(&fan_mutex
);
4253 rc
= fan_get_status(&s
);
4255 fan_update_desired_level(s
);
4256 mutex_unlock(&fan_mutex
);
4264 static void fan_exit(void)
4266 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
4268 /* FIXME: can we really do this unconditionally? */
4269 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
, &fan_attr_group
);
4270 driver_remove_file(&tpacpi_pdriver
.driver
, &driver_attr_fan_watchdog
);
4272 cancel_delayed_work(&fan_watchdog_task
);
4273 flush_scheduled_work();
4276 static int fan_get_speed(unsigned int *speed
)
4280 switch (fan_status_access_mode
) {
4281 case TPACPI_FAN_RD_TPEC
:
4282 /* all except 570, 600e/x, 770e, 770x */
4283 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
4284 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
4288 *speed
= (hi
<< 8) | lo
;
4299 static void fan_watchdog_fire(struct work_struct
*ignored
)
4303 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
4306 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
4307 rc
= fan_set_enable();
4309 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
4310 "will try again later...\n", -rc
);
4311 /* reschedule for later */
4312 fan_watchdog_reset();
4316 static void fan_watchdog_reset(void)
4318 static int fan_watchdog_active
;
4320 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
4323 if (fan_watchdog_active
)
4324 cancel_delayed_work(&fan_watchdog_task
);
4326 if (fan_watchdog_maxinterval
> 0 &&
4327 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
4328 fan_watchdog_active
= 1;
4329 if (!schedule_delayed_work(&fan_watchdog_task
,
4330 msecs_to_jiffies(fan_watchdog_maxinterval
4332 printk(IBM_ERR
"failed to schedule the fan watchdog, "
4333 "watchdog will not trigger\n");
4336 fan_watchdog_active
= 0;
4339 static int fan_set_level(int level
)
4341 if (!fan_control_allowed
)
4344 switch (fan_control_access_mode
) {
4345 case TPACPI_FAN_WR_ACPI_SFAN
:
4346 if (level
>= 0 && level
<= 7) {
4347 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
4353 case TPACPI_FAN_WR_ACPI_FANS
:
4354 case TPACPI_FAN_WR_TPEC
:
4355 if ((level
!= TP_EC_FAN_AUTO
) &&
4356 (level
!= TP_EC_FAN_FULLSPEED
) &&
4357 ((level
< 0) || (level
> 7)))
4360 /* safety net should the EC not support AUTO
4361 * or FULLSPEED mode bits and just ignore them */
4362 if (level
& TP_EC_FAN_FULLSPEED
)
4363 level
|= 7; /* safety min speed 7 */
4364 else if (level
& TP_EC_FAN_FULLSPEED
)
4365 level
|= 4; /* safety min speed 4 */
4367 if (!acpi_ec_write(fan_status_offset
, level
))
4370 tp_features
.fan_ctrl_status_undef
= 0;
4379 static int fan_set_level_safe(int level
)
4383 if (!fan_control_allowed
)
4386 rc
= mutex_lock_interruptible(&fan_mutex
);
4390 if (level
== TPACPI_FAN_LAST_LEVEL
)
4391 level
= fan_control_desired_level
;
4393 rc
= fan_set_level(level
);
4395 fan_update_desired_level(level
);
4397 mutex_unlock(&fan_mutex
);
4401 static int fan_set_enable(void)
4406 if (!fan_control_allowed
)
4409 rc
= mutex_lock_interruptible(&fan_mutex
);
4413 switch (fan_control_access_mode
) {
4414 case TPACPI_FAN_WR_ACPI_FANS
:
4415 case TPACPI_FAN_WR_TPEC
:
4416 rc
= fan_get_status(&s
);
4420 /* Don't go out of emergency fan mode */
4423 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
4426 if (!acpi_ec_write(fan_status_offset
, s
))
4429 tp_features
.fan_ctrl_status_undef
= 0;
4434 case TPACPI_FAN_WR_ACPI_SFAN
:
4435 rc
= fan_get_status(&s
);
4441 /* Set fan to at least level 4 */
4444 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
4454 mutex_unlock(&fan_mutex
);
4458 static int fan_set_disable(void)
4462 if (!fan_control_allowed
)
4465 rc
= mutex_lock_interruptible(&fan_mutex
);
4470 switch (fan_control_access_mode
) {
4471 case TPACPI_FAN_WR_ACPI_FANS
:
4472 case TPACPI_FAN_WR_TPEC
:
4473 if (!acpi_ec_write(fan_status_offset
, 0x00))
4476 fan_control_desired_level
= 0;
4477 tp_features
.fan_ctrl_status_undef
= 0;
4481 case TPACPI_FAN_WR_ACPI_SFAN
:
4482 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
4485 fan_control_desired_level
= 0;
4493 mutex_unlock(&fan_mutex
);
4497 static int fan_set_speed(int speed
)
4501 if (!fan_control_allowed
)
4504 rc
= mutex_lock_interruptible(&fan_mutex
);
4509 switch (fan_control_access_mode
) {
4510 case TPACPI_FAN_WR_ACPI_FANS
:
4511 if (speed
>= 0 && speed
<= 65535) {
4512 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
4513 speed
, speed
, speed
))
4523 mutex_unlock(&fan_mutex
);
4527 static int fan_read(char *p
)
4532 unsigned int speed
= 0;
4534 switch (fan_status_access_mode
) {
4535 case TPACPI_FAN_RD_ACPI_GFAN
:
4536 /* 570, 600e/x, 770e, 770x */
4537 if ((rc
= fan_get_status_safe(&status
)) < 0)
4540 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
4542 (status
!= 0) ? "enabled" : "disabled", status
);
4545 case TPACPI_FAN_RD_TPEC
:
4546 /* all except 570, 600e/x, 770e, 770x */
4547 if ((rc
= fan_get_status_safe(&status
)) < 0)
4550 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4551 if (status
!= fan_control_initial_status
)
4552 tp_features
.fan_ctrl_status_undef
= 0;
4554 /* Return most likely status. In fact, it
4555 * might be the only possible status */
4556 status
= TP_EC_FAN_AUTO
;
4559 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4560 (status
!= 0) ? "enabled" : "disabled");
4562 if ((rc
= fan_get_speed(&speed
)) < 0)
4565 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
4567 if (status
& TP_EC_FAN_FULLSPEED
)
4568 /* Disengaged mode takes precedence */
4569 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
4570 else if (status
& TP_EC_FAN_AUTO
)
4571 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
4573 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
4576 case TPACPI_FAN_NONE
:
4578 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4581 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
4582 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
4584 switch (fan_control_access_mode
) {
4585 case TPACPI_FAN_WR_ACPI_SFAN
:
4586 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
4590 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
4591 "auto, disengaged, full-speed)\n");
4596 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
4597 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
4598 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
4599 "1-120 (seconds))\n");
4601 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
4602 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
4603 " (<speed> is 0-65535)\n");
4608 static int fan_write_cmd_level(const char *cmd
, int *rc
)
4612 if (strlencmp(cmd
, "level auto") == 0)
4613 level
= TP_EC_FAN_AUTO
;
4614 else if ((strlencmp(cmd
, "level disengaged") == 0) |
4615 (strlencmp(cmd
, "level full-speed") == 0))
4616 level
= TP_EC_FAN_FULLSPEED
;
4617 else if (sscanf(cmd
, "level %d", &level
) != 1)
4620 if ((*rc
= fan_set_level_safe(level
)) == -ENXIO
)
4621 printk(IBM_ERR
"level command accepted for unsupported "
4622 "access mode %d", fan_control_access_mode
);
4627 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
4629 if (strlencmp(cmd
, "enable") != 0)
4632 if ((*rc
= fan_set_enable()) == -ENXIO
)
4633 printk(IBM_ERR
"enable command accepted for unsupported "
4634 "access mode %d", fan_control_access_mode
);
4639 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
4641 if (strlencmp(cmd
, "disable") != 0)
4644 if ((*rc
= fan_set_disable()) == -ENXIO
)
4645 printk(IBM_ERR
"disable command accepted for unsupported "
4646 "access mode %d", fan_control_access_mode
);
4651 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
4656 * Support speed <low> <medium> <high> ? */
4658 if (sscanf(cmd
, "speed %d", &speed
) != 1)
4661 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
4662 printk(IBM_ERR
"speed command accepted for unsupported "
4663 "access mode %d", fan_control_access_mode
);
4668 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
4672 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
4675 if (interval
< 0 || interval
> 120)
4678 fan_watchdog_maxinterval
= interval
;
4683 static int fan_write(char *buf
)
4688 while (!rc
&& (cmd
= next_cmd(&buf
))) {
4689 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
4690 fan_write_cmd_level(cmd
, &rc
)) &&
4691 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
4692 (fan_write_cmd_enable(cmd
, &rc
) ||
4693 fan_write_cmd_disable(cmd
, &rc
) ||
4694 fan_write_cmd_watchdog(cmd
, &rc
))) &&
4695 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
4696 fan_write_cmd_speed(cmd
, &rc
))
4700 fan_watchdog_reset();
4706 static struct ibm_struct fan_driver_data
= {
4713 /****************************************************************************
4714 ****************************************************************************
4718 ****************************************************************************
4719 ****************************************************************************/
4722 static struct proc_dir_entry
*proc_dir
;
4724 /* Subdriver registry */
4725 static LIST_HEAD(tpacpi_all_drivers
);
4729 * Module and infrastructure proble, init and exit handling
4732 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
4733 static const char * __init
str_supported(int is_supported
)
4735 static char text_unsupported
[] __initdata
= "not supported";
4737 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
4739 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
4741 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
4744 struct ibm_struct
*ibm
= iibm
->data
;
4745 struct proc_dir_entry
*entry
;
4747 BUG_ON(ibm
== NULL
);
4749 INIT_LIST_HEAD(&ibm
->all_drivers
);
4751 if (ibm
->flags
.experimental
&& !experimental
)
4754 dbg_printk(TPACPI_DBG_INIT
,
4755 "probing for %s\n", ibm
->name
);
4758 ret
= iibm
->init(iibm
);
4760 return 0; /* probe failed */
4764 ibm
->flags
.init_called
= 1;
4768 if (ibm
->acpi
->hid
) {
4769 ret
= register_tpacpi_subdriver(ibm
);
4774 if (ibm
->acpi
->notify
) {
4775 ret
= setup_acpi_notify(ibm
);
4776 if (ret
== -ENODEV
) {
4777 printk(IBM_NOTICE
"disabling subdriver %s\n",
4787 dbg_printk(TPACPI_DBG_INIT
,
4788 "%s installed\n", ibm
->name
);
4791 entry
= create_proc_entry(ibm
->name
,
4792 S_IFREG
| S_IRUGO
| S_IWUSR
,
4795 printk(IBM_ERR
"unable to create proc entry %s\n",
4800 entry
->owner
= THIS_MODULE
;
4802 entry
->read_proc
= &dispatch_procfs_read
;
4804 entry
->write_proc
= &dispatch_procfs_write
;
4805 ibm
->flags
.proc_created
= 1;
4808 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
4813 dbg_printk(TPACPI_DBG_INIT
,
4814 "%s: at error exit path with result %d\n",
4818 return (ret
< 0)? ret
: 0;
4821 static void ibm_exit(struct ibm_struct
*ibm
)
4823 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
4825 list_del_init(&ibm
->all_drivers
);
4827 if (ibm
->flags
.acpi_notify_installed
) {
4828 dbg_printk(TPACPI_DBG_EXIT
,
4829 "%s: acpi_remove_notify_handler\n", ibm
->name
);
4831 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
4833 dispatch_acpi_notify
);
4834 ibm
->flags
.acpi_notify_installed
= 0;
4835 ibm
->flags
.acpi_notify_installed
= 0;
4838 if (ibm
->flags
.proc_created
) {
4839 dbg_printk(TPACPI_DBG_EXIT
,
4840 "%s: remove_proc_entry\n", ibm
->name
);
4841 remove_proc_entry(ibm
->name
, proc_dir
);
4842 ibm
->flags
.proc_created
= 0;
4845 if (ibm
->flags
.acpi_driver_registered
) {
4846 dbg_printk(TPACPI_DBG_EXIT
,
4847 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
4849 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
4850 kfree(ibm
->acpi
->driver
);
4851 ibm
->acpi
->driver
= NULL
;
4852 ibm
->flags
.acpi_driver_registered
= 0;
4855 if (ibm
->flags
.init_called
&& ibm
->exit
) {
4857 ibm
->flags
.init_called
= 0;
4860 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
4865 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
4867 struct dmi_device
*dev
= NULL
;
4868 char ec_fw_string
[18];
4873 memset(tp
, 0, sizeof(*tp
));
4875 if (dmi_name_in_vendors("IBM"))
4876 tp
->vendor
= PCI_VENDOR_ID_IBM
;
4877 else if (dmi_name_in_vendors("LENOVO"))
4878 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
4882 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
4884 if (!tp
->bios_version_str
)
4886 tp
->bios_model
= tp
->bios_version_str
[0]
4887 | (tp
->bios_version_str
[1] << 8);
4890 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4891 * X32 or newer, all Z series; Some models must have an
4892 * up-to-date BIOS or they will not be detected.
4894 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4896 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
4897 if (sscanf(dev
->name
,
4898 "IBM ThinkPad Embedded Controller -[%17c",
4899 ec_fw_string
) == 1) {
4900 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
4901 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
4903 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
4904 tp
->ec_model
= ec_fw_string
[0]
4905 | (ec_fw_string
[1] << 8);
4910 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
4912 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
4913 kfree(tp
->model_str
);
4914 tp
->model_str
= NULL
;
4918 static int __init
probe_for_thinkpad(void)
4926 * Non-ancient models have better DMI tagging, but very old models
4929 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
4931 /* ec is required because many other handles are relative to it */
4932 IBM_ACPIHANDLE_INIT(ec
);
4936 "Not yet supported ThinkPad detected!\n");
4941 * Risks a regression on very old machines, but reduces potential
4942 * false positives a damn great deal
4945 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
4947 if (!is_thinkpad
&& !force_load
)
4954 /* Module init, exit, parameters */
4956 static struct ibm_init_struct ibms_init
[] __initdata
= {
4958 .init
= thinkpad_acpi_driver_init
,
4959 .data
= &thinkpad_acpi_driver_data
,
4962 .init
= hotkey_init
,
4963 .data
= &hotkey_driver_data
,
4966 .init
= bluetooth_init
,
4967 .data
= &bluetooth_driver_data
,
4971 .data
= &wan_driver_data
,
4975 .data
= &video_driver_data
,
4979 .data
= &light_driver_data
,
4981 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4984 .data
= &dock_driver_data
[0],
4988 .data
= &dock_driver_data
[1],
4991 #ifdef CONFIG_THINKPAD_ACPI_BAY
4994 .data
= &bay_driver_data
,
4999 .data
= &cmos_driver_data
,
5003 .data
= &led_driver_data
,
5007 .data
= &beep_driver_data
,
5010 .init
= thermal_init
,
5011 .data
= &thermal_driver_data
,
5014 .data
= &ecdump_driver_data
,
5017 .init
= brightness_init
,
5018 .data
= &brightness_driver_data
,
5021 .data
= &volume_driver_data
,
5025 .data
= &fan_driver_data
,
5029 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
5032 struct ibm_struct
*ibm
;
5034 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
5035 ibm
= ibms_init
[i
].data
;
5036 BUG_ON(ibm
== NULL
);
5038 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
5039 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
5041 strcpy(ibms_init
[i
].param
, val
);
5042 strcat(ibms_init
[i
].param
, ",");
5050 static int experimental
;
5051 module_param(experimental
, int, 0);
5053 static u32 dbg_level
;
5054 module_param_named(debug
, dbg_level
, uint
, 0);
5056 static int force_load
;
5057 module_param(force_load
, bool, 0);
5059 static int fan_control_allowed
;
5060 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
5062 static int brightness_mode
;
5063 module_param_named(brightness_mode
, brightness_mode
, int, 0);
5065 static unsigned int hotkey_report_mode
;
5066 module_param(hotkey_report_mode
, uint
, 0);
5068 #define IBM_PARAM(feature) \
5069 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
5072 IBM_PARAM(bluetooth
);
5075 #ifdef CONFIG_THINKPAD_ACPI_DOCK
5078 #ifdef CONFIG_THINKPAD_ACPI_BAY
5080 #endif /* CONFIG_THINKPAD_ACPI_BAY */
5085 IBM_PARAM(brightness
);
5089 static int __init
thinkpad_acpi_module_init(void)
5093 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
5095 /* Parameter checking */
5096 if (hotkey_report_mode
> 2)
5099 /* Driver-level probe */
5101 get_thinkpad_model_data(&thinkpad_id
);
5102 ret
= probe_for_thinkpad();
5104 thinkpad_acpi_module_exit();
5108 /* Driver initialization */
5110 IBM_ACPIHANDLE_INIT(ecrd
);
5111 IBM_ACPIHANDLE_INIT(ecwr
);
5113 mutex_init(&thinkpad_nvram_mutex
);
5115 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
5117 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
5118 thinkpad_acpi_module_exit();
5121 proc_dir
->owner
= THIS_MODULE
;
5123 ret
= platform_driver_register(&tpacpi_pdriver
);
5125 printk(IBM_ERR
"unable to register platform driver\n");
5126 thinkpad_acpi_module_exit();
5129 tp_features
.platform_drv_registered
= 1;
5131 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
5133 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
5134 thinkpad_acpi_module_exit();
5137 tp_features
.platform_drv_attrs_registered
= 1;
5140 /* Device initialization */
5141 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
5143 if (IS_ERR(tpacpi_pdev
)) {
5144 ret
= PTR_ERR(tpacpi_pdev
);
5146 printk(IBM_ERR
"unable to register platform device\n");
5147 thinkpad_acpi_module_exit();
5150 tpacpi_hwmon
= hwmon_device_register(&tpacpi_pdev
->dev
);
5151 if (IS_ERR(tpacpi_hwmon
)) {
5152 ret
= PTR_ERR(tpacpi_hwmon
);
5153 tpacpi_hwmon
= NULL
;
5154 printk(IBM_ERR
"unable to register hwmon device\n");
5155 thinkpad_acpi_module_exit();
5158 mutex_init(&tpacpi_inputdev_send_mutex
);
5159 tpacpi_inputdev
= input_allocate_device();
5160 if (!tpacpi_inputdev
) {
5161 printk(IBM_ERR
"unable to allocate input device\n");
5162 thinkpad_acpi_module_exit();
5165 /* Prepare input device, but don't register */
5166 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
5167 tpacpi_inputdev
->phys
= IBM_DRVR_NAME
"/input0";
5168 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
5169 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
5170 thinkpad_id
.vendor
:
5172 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
5173 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
5175 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
5176 ret
= ibm_init(&ibms_init
[i
]);
5177 if (ret
>= 0 && *ibms_init
[i
].param
)
5178 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
5180 thinkpad_acpi_module_exit();
5184 ret
= input_register_device(tpacpi_inputdev
);
5186 printk(IBM_ERR
"unable to register input device\n");
5187 thinkpad_acpi_module_exit();
5190 tp_features
.input_device_registered
= 1;
5193 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
5197 static void thinkpad_acpi_module_exit(void)
5199 struct ibm_struct
*ibm
, *itmp
;
5201 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
5203 list_for_each_entry_safe_reverse(ibm
, itmp
,
5204 &tpacpi_all_drivers
,
5209 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
5211 if (tpacpi_inputdev
) {
5212 if (tp_features
.input_device_registered
)
5213 input_unregister_device(tpacpi_inputdev
);
5215 input_free_device(tpacpi_inputdev
);
5219 hwmon_device_unregister(tpacpi_hwmon
);
5222 platform_device_unregister(tpacpi_pdev
);
5224 if (tp_features
.platform_drv_attrs_registered
)
5225 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
5227 if (tp_features
.platform_drv_registered
)
5228 platform_driver_unregister(&tpacpi_pdriver
);
5231 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
5233 kfree(thinkpad_id
.bios_version_str
);
5234 kfree(thinkpad_id
.ec_version_str
);
5235 kfree(thinkpad_id
.model_str
);
5238 module_init(thinkpad_acpi_module_init
);
5239 module_exit(thinkpad_acpi_module_exit
);