2 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2007 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #define IBM_VERSION "0.16"
25 #define TPACPI_SYSFS_VERSION 0x020000
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 platform_device
*tpacpi_sensors_pdev
;
529 static struct class_device
*tpacpi_hwmon
;
530 static struct input_dev
*tpacpi_inputdev
;
531 static struct mutex tpacpi_inputdev_send_mutex
;
534 static int tpacpi_resume_handler(struct platform_device
*pdev
)
536 struct ibm_struct
*ibm
, *itmp
;
538 list_for_each_entry_safe(ibm
, itmp
,
548 static struct platform_driver tpacpi_pdriver
= {
550 .name
= IBM_DRVR_NAME
,
551 .owner
= THIS_MODULE
,
553 .resume
= tpacpi_resume_handler
,
556 static struct platform_driver tpacpi_hwmon_pdriver
= {
558 .name
= IBM_HWMON_DRVR_NAME
,
559 .owner
= THIS_MODULE
,
563 /*************************************************************************
564 * thinkpad-acpi driver attributes
567 /* interface_version --------------------------------------------------- */
568 static ssize_t
tpacpi_driver_interface_version_show(
569 struct device_driver
*drv
,
572 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
575 static DRIVER_ATTR(interface_version
, S_IRUGO
,
576 tpacpi_driver_interface_version_show
, NULL
);
578 /* debug_level --------------------------------------------------------- */
579 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
582 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
585 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
586 const char *buf
, size_t count
)
590 if (parse_strtoul(buf
, 0xffff, &t
))
598 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
599 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
601 /* version ------------------------------------------------------------- */
602 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
605 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n", IBM_DESC
, IBM_VERSION
);
608 static DRIVER_ATTR(version
, S_IRUGO
,
609 tpacpi_driver_version_show
, NULL
);
611 /* --------------------------------------------------------------------- */
613 static struct driver_attribute
* tpacpi_driver_attributes
[] = {
614 &driver_attr_debug_level
, &driver_attr_version
,
615 &driver_attr_interface_version
,
618 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
624 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
625 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
632 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
636 for(i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
637 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
640 /*************************************************************************
641 * sysfs support helpers
644 struct attribute_set_obj
{
645 struct attribute_set s
;
647 } __attribute__((packed
));
649 static struct attribute_set
*create_attr_set(unsigned int max_members
,
652 struct attribute_set_obj
*sobj
;
654 if (max_members
== 0)
657 /* Allocates space for implicit NULL at the end too */
658 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
659 max_members
* sizeof(struct attribute
*),
663 sobj
->s
.max_members
= max_members
;
664 sobj
->s
.group
.attrs
= &sobj
->a
;
665 sobj
->s
.group
.name
= name
;
670 /* not multi-threaded safe, use it in a single thread per set */
671 static int add_to_attr_set(struct attribute_set
* s
, struct attribute
*attr
)
676 if (s
->members
>= s
->max_members
)
679 s
->group
.attrs
[s
->members
] = attr
;
685 static int add_many_to_attr_set(struct attribute_set
* s
,
686 struct attribute
**attr
,
691 for (i
= 0; i
< count
; i
++) {
692 res
= add_to_attr_set(s
, attr
[i
]);
700 static void delete_attr_set(struct attribute_set
* s
, struct kobject
*kobj
)
702 sysfs_remove_group(kobj
, &s
->group
);
706 static int parse_strtoul(const char *buf
,
707 unsigned long max
, unsigned long *value
)
711 while (*buf
&& isspace(*buf
))
713 *value
= simple_strtoul(buf
, &endp
, 0);
714 while (*endp
&& isspace(*endp
))
716 if (*endp
|| *value
> max
)
722 /****************************************************************************
723 ****************************************************************************
727 ****************************************************************************
728 ****************************************************************************/
730 /*************************************************************************
731 * thinkpad-acpi init subdriver
734 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
736 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
737 printk(IBM_INFO
"%s\n", IBM_URL
);
739 printk(IBM_INFO
"ThinkPad BIOS %s, EC %s\n",
740 (thinkpad_id
.bios_version_str
) ?
741 thinkpad_id
.bios_version_str
: "unknown",
742 (thinkpad_id
.ec_version_str
) ?
743 thinkpad_id
.ec_version_str
: "unknown");
745 if (thinkpad_id
.vendor
&& thinkpad_id
.model_str
)
746 printk(IBM_INFO
"%s %s\n",
747 (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
) ?
748 "IBM" : ((thinkpad_id
.vendor
==
749 PCI_VENDOR_ID_LENOVO
) ?
750 "Lenovo" : "Unknown vendor"),
751 thinkpad_id
.model_str
);
756 static int thinkpad_acpi_driver_read(char *p
)
760 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
761 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
766 static struct ibm_struct thinkpad_acpi_driver_data
= {
768 .read
= thinkpad_acpi_driver_read
,
771 /*************************************************************************
775 static int hotkey_orig_status
;
776 static u32 hotkey_orig_mask
;
777 static u32 hotkey_all_mask
;
778 static u32 hotkey_reserved_mask
;
780 static u16
*hotkey_keycode_map
;
782 static struct attribute_set
*hotkey_dev_attributes
;
784 static int hotkey_get_wlsw(int *status
)
786 if (!acpi_evalf(hkey_handle
, status
, "WLSW", "d"))
791 /* sysfs hotkey enable ------------------------------------------------- */
792 static ssize_t
hotkey_enable_show(struct device
*dev
,
793 struct device_attribute
*attr
,
799 res
= hotkey_get(&status
, &mask
);
803 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
);
806 static ssize_t
hotkey_enable_store(struct device
*dev
,
807 struct device_attribute
*attr
,
808 const char *buf
, size_t count
)
814 if (parse_strtoul(buf
, 1, &t
))
817 res
= hotkey_get(&status
, &mask
);
819 res
= hotkey_set(t
, mask
);
821 return (res
) ? res
: count
;
824 static struct device_attribute dev_attr_hotkey_enable
=
825 __ATTR(hotkey_enable
, S_IWUSR
| S_IRUGO
,
826 hotkey_enable_show
, hotkey_enable_store
);
828 /* sysfs hotkey mask --------------------------------------------------- */
829 static ssize_t
hotkey_mask_show(struct device
*dev
,
830 struct device_attribute
*attr
,
836 res
= hotkey_get(&status
, &mask
);
840 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", mask
);
843 static ssize_t
hotkey_mask_store(struct device
*dev
,
844 struct device_attribute
*attr
,
845 const char *buf
, size_t count
)
851 if (parse_strtoul(buf
, 0xffffffffUL
, &t
))
854 res
= hotkey_get(&status
, &mask
);
856 hotkey_set(status
, t
);
858 return (res
) ? res
: count
;
861 static struct device_attribute dev_attr_hotkey_mask
=
862 __ATTR(hotkey_mask
, S_IWUSR
| S_IRUGO
,
863 hotkey_mask_show
, hotkey_mask_store
);
865 /* sysfs hotkey bios_enabled ------------------------------------------- */
866 static ssize_t
hotkey_bios_enabled_show(struct device
*dev
,
867 struct device_attribute
*attr
,
870 return snprintf(buf
, PAGE_SIZE
, "%d\n", hotkey_orig_status
);
873 static struct device_attribute dev_attr_hotkey_bios_enabled
=
874 __ATTR(hotkey_bios_enabled
, S_IRUGO
, hotkey_bios_enabled_show
, NULL
);
876 /* sysfs hotkey bios_mask ---------------------------------------------- */
877 static ssize_t
hotkey_bios_mask_show(struct device
*dev
,
878 struct device_attribute
*attr
,
881 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_orig_mask
);
884 static struct device_attribute dev_attr_hotkey_bios_mask
=
885 __ATTR(hotkey_bios_mask
, S_IRUGO
, hotkey_bios_mask_show
, NULL
);
887 /* sysfs hotkey all_mask ----------------------------------------------- */
888 static ssize_t
hotkey_all_mask_show(struct device
*dev
,
889 struct device_attribute
*attr
,
892 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", hotkey_all_mask
);
895 static struct device_attribute dev_attr_hotkey_all_mask
=
896 __ATTR(hotkey_all_mask
, S_IRUGO
, hotkey_all_mask_show
, NULL
);
898 /* sysfs hotkey recommended_mask --------------------------------------- */
899 static ssize_t
hotkey_recommended_mask_show(struct device
*dev
,
900 struct device_attribute
*attr
,
903 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n",
904 hotkey_all_mask
& ~hotkey_reserved_mask
);
907 static struct device_attribute dev_attr_hotkey_recommended_mask
=
908 __ATTR(hotkey_recommended_mask
, S_IRUGO
,
909 hotkey_recommended_mask_show
, NULL
);
911 /* sysfs hotkey radio_sw ----------------------------------------------- */
912 static ssize_t
hotkey_radio_sw_show(struct device
*dev
,
913 struct device_attribute
*attr
,
917 res
= hotkey_get_wlsw(&s
);
921 return snprintf(buf
, PAGE_SIZE
, "%d\n", !!s
);
924 static struct device_attribute dev_attr_hotkey_radio_sw
=
925 __ATTR(hotkey_radio_sw
, S_IRUGO
, hotkey_radio_sw_show
, NULL
);
927 /* sysfs hotkey report_mode -------------------------------------------- */
928 static ssize_t
hotkey_report_mode_show(struct device
*dev
,
929 struct device_attribute
*attr
,
932 return snprintf(buf
, PAGE_SIZE
, "%d\n",
933 (hotkey_report_mode
!= 0) ? hotkey_report_mode
: 1);
936 static ssize_t
hotkey_report_mode_store(struct device
*dev
,
937 struct device_attribute
*attr
,
938 const char *buf
, size_t count
)
943 if (parse_strtoul(buf
, 2, &t
) || (t
< 1))
946 if (t
!= hotkey_report_mode
) {
947 if (tp_features
.hotkey_report_mode_locked
)
949 hotkey_report_mode
= t
;
950 printk(IBM_NOTICE
"hot key report mode set to %d\n",
954 return (res
) ? res
: count
;
957 static struct device_attribute dev_attr_hotkey_report_mode
=
958 __ATTR(hotkey_report_mode
, S_IWUSR
| S_IRUGO
,
959 hotkey_report_mode_show
, hotkey_report_mode_store
);
961 /* --------------------------------------------------------------------- */
963 static struct attribute
*hotkey_attributes
[] __initdata
= {
964 &dev_attr_hotkey_enable
.attr
,
965 &dev_attr_hotkey_report_mode
.attr
,
968 static struct attribute
*hotkey_mask_attributes
[] __initdata
= {
969 &dev_attr_hotkey_mask
.attr
,
970 &dev_attr_hotkey_bios_enabled
.attr
,
971 &dev_attr_hotkey_bios_mask
.attr
,
972 &dev_attr_hotkey_all_mask
.attr
,
973 &dev_attr_hotkey_recommended_mask
.attr
,
976 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
979 static u16 ibm_keycode_map
[] __initdata
= {
980 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
981 KEY_FN_F1
, KEY_FN_F2
, KEY_COFFEE
, KEY_SLEEP
,
982 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
983 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
984 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
985 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
986 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
987 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
988 KEY_RESERVED
, /* 0x0F: FN+HOME (brightness up) */
989 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
990 KEY_RESERVED
, /* 0x10: FN+END (brightness down) */
991 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
992 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
993 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
994 KEY_RESERVED
, /* 0x14: VOLUME UP */
995 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
996 KEY_RESERVED
, /* 0x16: MUTE */
997 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
998 /* (assignments unknown, please report if found) */
999 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1000 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1002 static u16 lenovo_keycode_map
[] __initdata
= {
1003 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
1004 KEY_FN_F1
, KEY_COFFEE
, KEY_BATTERY
, KEY_SLEEP
,
1005 KEY_WLAN
, KEY_FN_F6
, KEY_SWITCHVIDEOMODE
, KEY_FN_F8
,
1006 KEY_FN_F9
, KEY_FN_F10
, KEY_FN_F11
, KEY_SUSPEND
,
1007 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
1008 KEY_UNKNOWN
, /* 0x0C: FN+BACKSPACE */
1009 KEY_UNKNOWN
, /* 0x0D: FN+INSERT */
1010 KEY_UNKNOWN
, /* 0x0E: FN+DELETE */
1011 KEY_BRIGHTNESSUP
, /* 0x0F: FN+HOME (brightness up) */
1012 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
1013 KEY_BRIGHTNESSDOWN
, /* 0x10: FN+END (brightness down) */
1014 KEY_RESERVED
, /* 0x11: FN+PGUP (thinklight toggle) */
1015 KEY_UNKNOWN
, /* 0x12: FN+PGDOWN */
1016 KEY_ZOOM
, /* 0x13: FN+SPACE (zoom) */
1017 KEY_RESERVED
, /* 0x14: VOLUME UP */
1018 KEY_RESERVED
, /* 0x15: VOLUME DOWN */
1019 KEY_RESERVED
, /* 0x16: MUTE */
1020 KEY_VENDOR
, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1021 /* (assignments unknown, please report if found) */
1022 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1023 KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
, KEY_UNKNOWN
,
1026 #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
1027 #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
1028 #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
1034 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
1036 BUG_ON(!tpacpi_inputdev
);
1038 IBM_ACPIHANDLE_INIT(hkey
);
1039 mutex_init(&hotkey_mutex
);
1041 /* hotkey not supported on 570 */
1042 tp_features
.hotkey
= hkey_handle
!= NULL
;
1044 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
1045 str_supported(tp_features
.hotkey
));
1047 if (tp_features
.hotkey
) {
1048 hotkey_dev_attributes
= create_attr_set(8, NULL
);
1049 if (!hotkey_dev_attributes
)
1051 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1053 ARRAY_SIZE(hotkey_attributes
));
1057 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1058 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking
1059 for HKEY interface version 0x100 */
1060 if (acpi_evalf(hkey_handle
, &hkeyv
, "MHKV", "qd")) {
1061 if ((hkeyv
>> 8) != 1) {
1062 printk(IBM_ERR
"unknown version of the "
1063 "HKEY interface: 0x%x\n", hkeyv
);
1064 printk(IBM_ERR
"please report this to %s\n",
1068 * MHKV 0x100 in A31, R40, R40e,
1069 * T4x, X31, and later
1071 tp_features
.hotkey_mask
= 1;
1075 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
1076 str_supported(tp_features
.hotkey_mask
));
1078 if (tp_features
.hotkey_mask
) {
1079 if (!acpi_evalf(hkey_handle
, &hotkey_all_mask
,
1082 "missing MHKA handler, "
1083 "please report this to %s\n",
1085 hotkey_all_mask
= 0x080cU
; /* FN+F12, FN+F4, FN+F3 */
1089 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
1090 if (!res
&& tp_features
.hotkey_mask
) {
1091 res
= add_many_to_attr_set(hotkey_dev_attributes
,
1092 hotkey_mask_attributes
,
1093 ARRAY_SIZE(hotkey_mask_attributes
));
1096 /* Not all thinkpads have a hardware radio switch */
1097 if (!res
&& acpi_evalf(hkey_handle
, &status
, "WLSW", "qd")) {
1098 tp_features
.hotkey_wlsw
= 1;
1100 "radio switch found; radios are %s\n",
1101 enabled(status
, 0));
1102 res
= add_to_attr_set(hotkey_dev_attributes
,
1103 &dev_attr_hotkey_radio_sw
.attr
);
1107 res
= register_attr_set_with_sysfs(
1108 hotkey_dev_attributes
,
1109 &tpacpi_pdev
->dev
.kobj
);
1113 /* Set up key map */
1115 hotkey_keycode_map
= kmalloc(TPACPI_HOTKEY_MAP_SIZE
,
1117 if (!hotkey_keycode_map
) {
1118 printk(IBM_ERR
"failed to allocate memory for key map\n");
1122 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
) {
1123 dbg_printk(TPACPI_DBG_INIT
,
1124 "using Lenovo default hot key map\n");
1125 memcpy(hotkey_keycode_map
, &lenovo_keycode_map
,
1126 TPACPI_HOTKEY_MAP_SIZE
);
1128 dbg_printk(TPACPI_DBG_INIT
,
1129 "using IBM default hot key map\n");
1130 memcpy(hotkey_keycode_map
, &ibm_keycode_map
,
1131 TPACPI_HOTKEY_MAP_SIZE
);
1134 set_bit(EV_KEY
, tpacpi_inputdev
->evbit
);
1135 set_bit(EV_MSC
, tpacpi_inputdev
->evbit
);
1136 set_bit(MSC_SCAN
, tpacpi_inputdev
->mscbit
);
1137 tpacpi_inputdev
->keycodesize
= TPACPI_HOTKEY_MAP_TYPESIZE
;
1138 tpacpi_inputdev
->keycodemax
= TPACPI_HOTKEY_MAP_LEN
;
1139 tpacpi_inputdev
->keycode
= hotkey_keycode_map
;
1140 for (i
= 0; i
< TPACPI_HOTKEY_MAP_LEN
; i
++) {
1141 if (hotkey_keycode_map
[i
] != KEY_RESERVED
) {
1142 set_bit(hotkey_keycode_map
[i
],
1143 tpacpi_inputdev
->keybit
);
1145 if (i
< sizeof(hotkey_reserved_mask
)*8)
1146 hotkey_reserved_mask
|= 1 << i
;
1150 if (tp_features
.hotkey_wlsw
) {
1151 set_bit(EV_SW
, tpacpi_inputdev
->evbit
);
1152 set_bit(SW_RADIO
, tpacpi_inputdev
->swbit
);
1155 dbg_printk(TPACPI_DBG_INIT
,
1156 "enabling hot key handling\n");
1157 res
= hotkey_set(1, (hotkey_all_mask
& ~hotkey_reserved_mask
)
1158 | hotkey_orig_mask
);
1162 if (hotkey_report_mode
> 0) {
1163 tp_features
.hotkey_report_mode_locked
= 1;
1165 hotkey_report_mode
= 1;
1166 vdbg_printk(TPACPI_DBG_INIT
,
1167 "hot key reporting mode can be "
1168 "changed at runtime\n");
1171 dbg_printk(TPACPI_DBG_INIT
,
1172 "legacy hot key reporting over procfs %s\n",
1173 (hotkey_report_mode
< 2) ?
1174 "enabled" : "disabled");
1177 return (tp_features
.hotkey
)? 0 : 1;
1180 static void hotkey_exit(void)
1184 if (tp_features
.hotkey
) {
1185 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
1186 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
1188 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
1191 if (hotkey_dev_attributes
) {
1192 delete_attr_set(hotkey_dev_attributes
, &tpacpi_pdev
->dev
.kobj
);
1193 hotkey_dev_attributes
= NULL
;
1197 static void tpacpi_input_send_key(unsigned int scancode
,
1198 unsigned int keycode
)
1200 if (keycode
!= KEY_RESERVED
) {
1201 mutex_lock(&tpacpi_inputdev_send_mutex
);
1203 input_report_key(tpacpi_inputdev
, keycode
, 1);
1204 if (keycode
== KEY_UNKNOWN
)
1205 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1207 input_sync(tpacpi_inputdev
);
1209 input_report_key(tpacpi_inputdev
, keycode
, 0);
1210 if (keycode
== KEY_UNKNOWN
)
1211 input_event(tpacpi_inputdev
, EV_MSC
, MSC_SCAN
,
1213 input_sync(tpacpi_inputdev
);
1215 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1219 static void tpacpi_input_send_radiosw(void)
1223 mutex_lock(&tpacpi_inputdev_send_mutex
);
1225 if (tp_features
.hotkey_wlsw
&& !hotkey_get_wlsw(&wlsw
)) {
1226 input_report_switch(tpacpi_inputdev
,
1228 input_sync(tpacpi_inputdev
);
1231 mutex_unlock(&tpacpi_inputdev_send_mutex
);
1234 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
1237 unsigned int keycode
, scancode
;
1241 if (event
!= 0x80) {
1242 printk(IBM_ERR
"unknown HKEY notification event %d\n", event
);
1243 /* forward it to userspace, maybe it knows how to handle it */
1244 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
1250 if (!acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d")) {
1251 printk(IBM_ERR
"failed to retrieve HKEY event\n");
1263 switch (hkey
>> 12) {
1265 /* 0x1000-0x1FFF: key presses */
1266 scancode
= hkey
& 0xfff;
1267 if (scancode
> 0 && scancode
< 0x21) {
1269 keycode
= hotkey_keycode_map
[scancode
];
1270 tpacpi_input_send_key(scancode
, keycode
);
1273 "hotkey 0x%04x out of range for keyboard map\n",
1279 /* 0x5000-0x5FFF: LID */
1280 /* we don't handle it through this path, just
1281 * eat up known LID events */
1282 if (hkey
!= 0x5001 && hkey
!= 0x5002) {
1284 "unknown LID-related HKEY event: 0x%04x\n",
1292 /* 0x7000-0x7FFF: misc */
1293 if (tp_features
.hotkey_wlsw
&& hkey
== 0x7000) {
1294 tpacpi_input_send_radiosw();
1297 /* fallthrough to default */
1299 /* case 2: dock-related */
1300 /* 0x2305 - T43 waking up due to bay lever eject while aslept */
1301 /* case 3: ultra-bay related. maybe bay in dock? */
1302 /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
1303 printk(IBM_NOTICE
"unhandled HKEY event 0x%04x\n", hkey
);
1307 if (!ignore_acpi_ev
&& (send_acpi_ev
|| hotkey_report_mode
< 2)) {
1308 acpi_bus_generate_event(ibm
->acpi
->device
, event
, hkey
);
1313 static void hotkey_resume(void)
1315 tpacpi_input_send_radiosw();
1319 * Call with hotkey_mutex held
1321 static int hotkey_get(int *status
, u32
*mask
)
1323 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
1326 if (tp_features
.hotkey_mask
)
1327 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
1334 * Call with hotkey_mutex held
1336 static int hotkey_set(int status
, u32 mask
)
1340 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
1343 if (tp_features
.hotkey_mask
)
1344 for (i
= 0; i
< 32; i
++) {
1345 int bit
= ((1 << i
) & mask
) != 0;
1346 if (!acpi_evalf(hkey_handle
,
1347 NULL
, "MHKM", "vdd", i
+ 1, bit
))
1354 /* procfs -------------------------------------------------------------- */
1355 static int hotkey_read(char *p
)
1361 if (!tp_features
.hotkey
) {
1362 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1366 res
= mutex_lock_interruptible(&hotkey_mutex
);
1369 res
= hotkey_get(&status
, &mask
);
1370 mutex_unlock(&hotkey_mutex
);
1374 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
1375 if (tp_features
.hotkey_mask
) {
1376 len
+= sprintf(p
+ len
, "mask:\t\t0x%08x\n", mask
);
1377 len
+= sprintf(p
+ len
,
1378 "commands:\tenable, disable, reset, <mask>\n");
1380 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
1381 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
1387 static int hotkey_write(char *buf
)
1394 if (!tp_features
.hotkey
)
1397 res
= mutex_lock_interruptible(&hotkey_mutex
);
1401 res
= hotkey_get(&status
, &mask
);
1406 while ((cmd
= next_cmd(&buf
))) {
1407 if (strlencmp(cmd
, "enable") == 0) {
1409 } else if (strlencmp(cmd
, "disable") == 0) {
1411 } else if (strlencmp(cmd
, "reset") == 0) {
1412 status
= hotkey_orig_status
;
1413 mask
= hotkey_orig_mask
;
1414 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
1416 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
1426 res
= hotkey_set(status
, mask
);
1429 mutex_unlock(&hotkey_mutex
);
1433 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
1434 .hid
= IBM_HKEY_HID
,
1435 .notify
= hotkey_notify
,
1436 .handle
= &hkey_handle
,
1437 .type
= ACPI_DEVICE_NOTIFY
,
1440 static struct ibm_struct hotkey_driver_data
= {
1442 .read
= hotkey_read
,
1443 .write
= hotkey_write
,
1444 .exit
= hotkey_exit
,
1445 .resume
= hotkey_resume
,
1446 .acpi
= &ibm_hotkey_acpidriver
,
1449 /*************************************************************************
1450 * Bluetooth subdriver
1453 /* sysfs bluetooth enable ---------------------------------------------- */
1454 static ssize_t
bluetooth_enable_show(struct device
*dev
,
1455 struct device_attribute
*attr
,
1460 status
= bluetooth_get_radiosw();
1464 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1467 static ssize_t
bluetooth_enable_store(struct device
*dev
,
1468 struct device_attribute
*attr
,
1469 const char *buf
, size_t count
)
1474 if (parse_strtoul(buf
, 1, &t
))
1477 res
= bluetooth_set_radiosw(t
);
1479 return (res
) ? res
: count
;
1482 static struct device_attribute dev_attr_bluetooth_enable
=
1483 __ATTR(bluetooth_enable
, S_IWUSR
| S_IRUGO
,
1484 bluetooth_enable_show
, bluetooth_enable_store
);
1486 /* --------------------------------------------------------------------- */
1488 static struct attribute
*bluetooth_attributes
[] = {
1489 &dev_attr_bluetooth_enable
.attr
,
1493 static const struct attribute_group bluetooth_attr_group
= {
1494 .attrs
= bluetooth_attributes
,
1497 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
1502 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
1504 IBM_ACPIHANDLE_INIT(hkey
);
1506 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1507 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
1508 tp_features
.bluetooth
= hkey_handle
&&
1509 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
1511 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
1512 str_supported(tp_features
.bluetooth
),
1515 if (tp_features
.bluetooth
) {
1516 if (!(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
1517 /* no bluetooth hardware present in system */
1518 tp_features
.bluetooth
= 0;
1519 dbg_printk(TPACPI_DBG_INIT
,
1520 "bluetooth hardware not installed\n");
1522 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1523 &bluetooth_attr_group
);
1529 return (tp_features
.bluetooth
)? 0 : 1;
1532 static void bluetooth_exit(void)
1534 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1535 &bluetooth_attr_group
);
1538 static int bluetooth_get_radiosw(void)
1542 if (!tp_features
.bluetooth
)
1545 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1548 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
1551 static int bluetooth_set_radiosw(int radio_on
)
1555 if (!tp_features
.bluetooth
)
1558 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
1561 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
1563 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
1564 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
1570 /* procfs -------------------------------------------------------------- */
1571 static int bluetooth_read(char *p
)
1574 int status
= bluetooth_get_radiosw();
1576 if (!tp_features
.bluetooth
)
1577 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1579 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1580 (status
)? "enabled" : "disabled");
1581 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1587 static int bluetooth_write(char *buf
)
1591 if (!tp_features
.bluetooth
)
1594 while ((cmd
= next_cmd(&buf
))) {
1595 if (strlencmp(cmd
, "enable") == 0) {
1596 bluetooth_set_radiosw(1);
1597 } else if (strlencmp(cmd
, "disable") == 0) {
1598 bluetooth_set_radiosw(0);
1606 static struct ibm_struct bluetooth_driver_data
= {
1607 .name
= "bluetooth",
1608 .read
= bluetooth_read
,
1609 .write
= bluetooth_write
,
1610 .exit
= bluetooth_exit
,
1613 /*************************************************************************
1617 /* sysfs wan enable ---------------------------------------------------- */
1618 static ssize_t
wan_enable_show(struct device
*dev
,
1619 struct device_attribute
*attr
,
1624 status
= wan_get_radiosw();
1628 return snprintf(buf
, PAGE_SIZE
, "%d\n", status
? 1 : 0);
1631 static ssize_t
wan_enable_store(struct device
*dev
,
1632 struct device_attribute
*attr
,
1633 const char *buf
, size_t count
)
1638 if (parse_strtoul(buf
, 1, &t
))
1641 res
= wan_set_radiosw(t
);
1643 return (res
) ? res
: count
;
1646 static struct device_attribute dev_attr_wan_enable
=
1647 __ATTR(wwan_enable
, S_IWUSR
| S_IRUGO
,
1648 wan_enable_show
, wan_enable_store
);
1650 /* --------------------------------------------------------------------- */
1652 static struct attribute
*wan_attributes
[] = {
1653 &dev_attr_wan_enable
.attr
,
1657 static const struct attribute_group wan_attr_group
= {
1658 .attrs
= wan_attributes
,
1661 static int __init
wan_init(struct ibm_init_struct
*iibm
)
1666 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
1668 IBM_ACPIHANDLE_INIT(hkey
);
1670 tp_features
.wan
= hkey_handle
&&
1671 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
1673 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
1674 str_supported(tp_features
.wan
),
1677 if (tp_features
.wan
) {
1678 if (!(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
1679 /* no wan hardware present in system */
1680 tp_features
.wan
= 0;
1681 dbg_printk(TPACPI_DBG_INIT
,
1682 "wan hardware not installed\n");
1684 res
= sysfs_create_group(&tpacpi_pdev
->dev
.kobj
,
1691 return (tp_features
.wan
)? 0 : 1;
1694 static void wan_exit(void)
1696 sysfs_remove_group(&tpacpi_pdev
->dev
.kobj
,
1700 static int wan_get_radiosw(void)
1704 if (!tp_features
.wan
)
1707 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1710 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
1713 static int wan_set_radiosw(int radio_on
)
1717 if (!tp_features
.wan
)
1720 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1723 status
|= TP_ACPI_WANCARD_RADIOSSW
;
1725 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
1726 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
1732 /* procfs -------------------------------------------------------------- */
1733 static int wan_read(char *p
)
1736 int status
= wan_get_radiosw();
1738 if (!tp_features
.wan
)
1739 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1741 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1742 (status
)? "enabled" : "disabled");
1743 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1749 static int wan_write(char *buf
)
1753 if (!tp_features
.wan
)
1756 while ((cmd
= next_cmd(&buf
))) {
1757 if (strlencmp(cmd
, "enable") == 0) {
1759 } else if (strlencmp(cmd
, "disable") == 0) {
1768 static struct ibm_struct wan_driver_data
= {
1773 .flags
.experimental
= 1,
1776 /*************************************************************************
1780 static enum video_access_mode video_supported
;
1781 static int video_orig_autosw
;
1783 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
1784 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1785 "\\_SB.PCI0.VID0", /* 770e */
1786 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1787 "\\_SB.PCI0.AGP.VID", /* all others */
1790 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1792 static int __init
video_init(struct ibm_init_struct
*iibm
)
1796 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
1798 IBM_ACPIHANDLE_INIT(vid
);
1799 IBM_ACPIHANDLE_INIT(vid2
);
1801 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
1802 /* G41, assume IVGA doesn't change */
1803 vid_handle
= vid2_handle
;
1806 /* video switching not supported on R30, R31 */
1807 video_supported
= TPACPI_VIDEO_NONE
;
1808 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
1810 video_supported
= TPACPI_VIDEO_570
;
1811 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
1812 /* 600e/x, 770e, 770x */
1813 video_supported
= TPACPI_VIDEO_770
;
1816 video_supported
= TPACPI_VIDEO_NEW
;
1818 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
1819 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
1822 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
1825 static void video_exit(void)
1827 dbg_printk(TPACPI_DBG_EXIT
,
1828 "restoring original video autoswitch mode\n");
1829 if (video_autosw_set(video_orig_autosw
))
1830 printk(IBM_ERR
"error while trying to restore original "
1831 "video autoswitch mode\n");
1834 static int video_outputsw_get(void)
1839 switch (video_supported
) {
1840 case TPACPI_VIDEO_570
:
1841 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
1842 TP_ACPI_VIDEO_570_PHSCMD
))
1844 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
1846 case TPACPI_VIDEO_770
:
1847 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1850 status
|= TP_ACPI_VIDEO_S_LCD
;
1851 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1854 status
|= TP_ACPI_VIDEO_S_CRT
;
1856 case TPACPI_VIDEO_NEW
:
1857 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
1858 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1861 status
|= TP_ACPI_VIDEO_S_CRT
;
1863 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
1864 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1867 status
|= TP_ACPI_VIDEO_S_LCD
;
1868 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
1871 status
|= TP_ACPI_VIDEO_S_DVI
;
1880 static int video_outputsw_set(int status
)
1885 switch (video_supported
) {
1886 case TPACPI_VIDEO_570
:
1887 res
= acpi_evalf(NULL
, NULL
,
1888 "\\_SB.PHS2", "vdd",
1889 TP_ACPI_VIDEO_570_PHS2CMD
,
1890 status
| TP_ACPI_VIDEO_570_PHS2SET
);
1892 case TPACPI_VIDEO_770
:
1893 autosw
= video_autosw_get();
1897 res
= video_autosw_set(1);
1900 res
= acpi_evalf(vid_handle
, NULL
,
1901 "ASWT", "vdd", status
* 0x100, 0);
1902 if (!autosw
&& video_autosw_set(autosw
)) {
1903 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1907 case TPACPI_VIDEO_NEW
:
1908 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
1909 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
1915 return (res
)? 0 : -EIO
;
1918 static int video_autosw_get(void)
1922 switch (video_supported
) {
1923 case TPACPI_VIDEO_570
:
1924 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
1927 case TPACPI_VIDEO_770
:
1928 case TPACPI_VIDEO_NEW
:
1929 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
1939 static int video_autosw_set(int enable
)
1941 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
1946 static int video_outputsw_cycle(void)
1948 int autosw
= video_autosw_get();
1954 switch (video_supported
) {
1955 case TPACPI_VIDEO_570
:
1956 res
= video_autosw_set(1);
1959 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
1961 case TPACPI_VIDEO_770
:
1962 case TPACPI_VIDEO_NEW
:
1963 res
= video_autosw_set(1);
1966 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
1971 if (!autosw
&& video_autosw_set(autosw
)) {
1972 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1976 return (res
)? 0 : -EIO
;
1979 static int video_expand_toggle(void)
1981 switch (video_supported
) {
1982 case TPACPI_VIDEO_570
:
1983 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
1985 case TPACPI_VIDEO_770
:
1986 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
1988 case TPACPI_VIDEO_NEW
:
1989 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
1997 static int video_read(char *p
)
2002 if (video_supported
== TPACPI_VIDEO_NONE
) {
2003 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2007 status
= video_outputsw_get();
2011 autosw
= video_autosw_get();
2015 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2016 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
2017 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
2018 if (video_supported
== TPACPI_VIDEO_NEW
)
2019 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
2020 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
2021 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
2022 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
2023 if (video_supported
== TPACPI_VIDEO_NEW
)
2024 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
2025 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
2026 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
2031 static int video_write(char *buf
)
2034 int enable
, disable
, status
;
2037 if (video_supported
== TPACPI_VIDEO_NONE
)
2043 while ((cmd
= next_cmd(&buf
))) {
2044 if (strlencmp(cmd
, "lcd_enable") == 0) {
2045 enable
|= TP_ACPI_VIDEO_S_LCD
;
2046 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
2047 disable
|= TP_ACPI_VIDEO_S_LCD
;
2048 } else if (strlencmp(cmd
, "crt_enable") == 0) {
2049 enable
|= TP_ACPI_VIDEO_S_CRT
;
2050 } else if (strlencmp(cmd
, "crt_disable") == 0) {
2051 disable
|= TP_ACPI_VIDEO_S_CRT
;
2052 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2053 strlencmp(cmd
, "dvi_enable") == 0) {
2054 enable
|= TP_ACPI_VIDEO_S_DVI
;
2055 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
2056 strlencmp(cmd
, "dvi_disable") == 0) {
2057 disable
|= TP_ACPI_VIDEO_S_DVI
;
2058 } else if (strlencmp(cmd
, "auto_enable") == 0) {
2059 res
= video_autosw_set(1);
2062 } else if (strlencmp(cmd
, "auto_disable") == 0) {
2063 res
= video_autosw_set(0);
2066 } else if (strlencmp(cmd
, "video_switch") == 0) {
2067 res
= video_outputsw_cycle();
2070 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
2071 res
= video_expand_toggle();
2078 if (enable
|| disable
) {
2079 status
= video_outputsw_get();
2082 res
= video_outputsw_set((status
& ~disable
) | enable
);
2090 static struct ibm_struct video_driver_data
= {
2093 .write
= video_write
,
2097 /*************************************************************************
2098 * Light (thinklight) subdriver
2101 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
2102 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
2104 static int __init
light_init(struct ibm_init_struct
*iibm
)
2106 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
2108 IBM_ACPIHANDLE_INIT(ledb
);
2109 IBM_ACPIHANDLE_INIT(lght
);
2110 IBM_ACPIHANDLE_INIT(cmos
);
2112 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
2113 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
2115 if (tp_features
.light
)
2116 /* light status not supported on
2117 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
2118 tp_features
.light_status
=
2119 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
2121 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
2122 str_supported(tp_features
.light
));
2124 return (tp_features
.light
)? 0 : 1;
2127 static int light_read(char *p
)
2132 if (!tp_features
.light
) {
2133 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2134 } else if (!tp_features
.light_status
) {
2135 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
2136 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2138 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
2140 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
2141 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
2147 static int light_write(char *buf
)
2149 int cmos_cmd
, lght_cmd
;
2153 if (!tp_features
.light
)
2156 while ((cmd
= next_cmd(&buf
))) {
2157 if (strlencmp(cmd
, "on") == 0) {
2160 } else if (strlencmp(cmd
, "off") == 0) {
2166 success
= cmos_handle
?
2167 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
2168 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
2176 static struct ibm_struct light_driver_data
= {
2179 .write
= light_write
,
2182 /*************************************************************************
2186 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2188 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
2189 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
2190 "\\_SB.PCI0.PCI1.DOCK", /* all others */
2191 "\\_SB.PCI.ISA.SLCE", /* 570 */
2192 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
2194 /* don't list other alternatives as we install a notify handler on the 570 */
2195 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
2197 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
2199 .notify
= dock_notify
,
2200 .handle
= &dock_handle
,
2201 .type
= ACPI_SYSTEM_NOTIFY
,
2204 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
2205 * We just use it to get notifications of dock hotplug
2206 * in very old thinkpads */
2207 .hid
= PCI_ROOT_HID_STRING
,
2208 .notify
= dock_notify
,
2209 .handle
= &pci_handle
,
2210 .type
= ACPI_SYSTEM_NOTIFY
,
2214 static struct ibm_struct dock_driver_data
[2] = {
2218 .write
= dock_write
,
2219 .acpi
= &ibm_dock_acpidriver
[0],
2223 .acpi
= &ibm_dock_acpidriver
[1],
2227 #define dock_docked() (_sta(dock_handle) & 1)
2229 static int __init
dock_init(struct ibm_init_struct
*iibm
)
2231 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
2233 IBM_ACPIHANDLE_INIT(dock
);
2235 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
2236 str_supported(dock_handle
!= NULL
));
2238 return (dock_handle
)? 0 : 1;
2241 static int __init
dock_init2(struct ibm_init_struct
*iibm
)
2245 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver part 2\n");
2247 if (dock_driver_data
[0].flags
.acpi_driver_registered
&&
2248 dock_driver_data
[0].flags
.acpi_notify_installed
) {
2249 IBM_ACPIHANDLE_INIT(pci
);
2250 dock2_needed
= (pci_handle
!= NULL
);
2251 vdbg_printk(TPACPI_DBG_INIT
,
2252 "dock PCI handler for the TP 570 is %s\n",
2253 str_supported(dock2_needed
));
2255 vdbg_printk(TPACPI_DBG_INIT
,
2256 "dock subdriver part 2 not required\n");
2260 return (dock2_needed
)? 0 : 1;
2263 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
2265 int docked
= dock_docked();
2266 int pci
= ibm
->acpi
->hid
&& strstr(ibm
->acpi
->hid
, PCI_ROOT_HID_STRING
);
2268 if (event
== 1 && !pci
) /* 570 */
2269 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
2270 else if (event
== 1 && pci
) /* 570 */
2271 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
2272 else if (event
== 3 && docked
)
2273 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
2274 else if (event
== 3 && !docked
)
2275 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 2); /* undock */
2276 else if (event
== 0 && docked
)
2277 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
2279 printk(IBM_ERR
"unknown dock event %d, status %d\n",
2280 event
, _sta(dock_handle
));
2281 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0); /* unknown */
2285 static int dock_read(char *p
)
2288 int docked
= dock_docked();
2291 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2293 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
2295 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
2296 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
2302 static int dock_write(char *buf
)
2309 while ((cmd
= next_cmd(&buf
))) {
2310 if (strlencmp(cmd
, "undock") == 0) {
2311 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
2312 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
2314 } else if (strlencmp(cmd
, "dock") == 0) {
2315 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
2324 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
2326 /*************************************************************************
2330 #ifdef CONFIG_THINKPAD_ACPI_BAY
2331 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
2332 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
2333 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
2334 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
2335 ); /* A21e, R30, R31 */
2336 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
2337 "_EJ0", /* all others */
2338 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
2339 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
2340 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
2342 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
2346 static int __init
bay_init(struct ibm_init_struct
*iibm
)
2348 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
2350 IBM_ACPIHANDLE_INIT(bay
);
2352 IBM_ACPIHANDLE_INIT(bay_ej
);
2353 IBM_ACPIHANDLE_INIT(bay2
);
2355 IBM_ACPIHANDLE_INIT(bay2_ej
);
2357 tp_features
.bay_status
= bay_handle
&&
2358 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
2359 tp_features
.bay_status2
= bay2_handle
&&
2360 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
2362 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
2363 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
2364 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
2365 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
2367 vdbg_printk(TPACPI_DBG_INIT
,
2368 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
2369 str_supported(tp_features
.bay_status
),
2370 str_supported(tp_features
.bay_eject
),
2371 str_supported(tp_features
.bay_status2
),
2372 str_supported(tp_features
.bay_eject2
));
2374 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
2375 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
2378 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
2380 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
2383 #define bay_occupied(b) (_sta(b##_handle) & 1)
2385 static int bay_read(char *p
)
2388 int occupied
= bay_occupied(bay
);
2389 int occupied2
= bay_occupied(bay2
);
2392 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2393 tp_features
.bay_status
?
2394 (occupied
? "occupied" : "unoccupied") :
2396 if (tp_features
.bay_status2
)
2397 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
2398 "occupied" : "unoccupied");
2400 eject
= tp_features
.bay_eject
&& occupied
;
2401 eject2
= tp_features
.bay_eject2
&& occupied2
;
2403 if (eject
&& eject2
)
2404 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
2406 len
+= sprintf(p
+ len
, "commands:\teject\n");
2408 len
+= sprintf(p
+ len
, "commands:\teject2\n");
2413 static int bay_write(char *buf
)
2417 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
2420 while ((cmd
= next_cmd(&buf
))) {
2421 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
2422 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
2424 } else if (tp_features
.bay_eject2
&&
2425 strlencmp(cmd
, "eject2") == 0) {
2426 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
2435 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
2436 .notify
= bay_notify
,
2437 .handle
= &bay_handle
,
2438 .type
= ACPI_SYSTEM_NOTIFY
,
2441 static struct ibm_struct bay_driver_data
= {
2445 .acpi
= &ibm_bay_acpidriver
,
2448 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2450 /*************************************************************************
2454 /* sysfs cmos_command -------------------------------------------------- */
2455 static ssize_t
cmos_command_store(struct device
*dev
,
2456 struct device_attribute
*attr
,
2457 const char *buf
, size_t count
)
2459 unsigned long cmos_cmd
;
2462 if (parse_strtoul(buf
, 21, &cmos_cmd
))
2465 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2466 return (res
)? res
: count
;
2469 static struct device_attribute dev_attr_cmos_command
=
2470 __ATTR(cmos_command
, S_IWUSR
, NULL
, cmos_command_store
);
2472 /* --------------------------------------------------------------------- */
2474 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
2478 vdbg_printk(TPACPI_DBG_INIT
,
2479 "initializing cmos commands subdriver\n");
2481 IBM_ACPIHANDLE_INIT(cmos
);
2483 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
2484 str_supported(cmos_handle
!= NULL
));
2486 res
= device_create_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2490 return (cmos_handle
)? 0 : 1;
2493 static void cmos_exit(void)
2495 device_remove_file(&tpacpi_pdev
->dev
, &dev_attr_cmos_command
);
2498 static int cmos_read(char *p
)
2502 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
2503 R30, R31, T20-22, X20-21 */
2505 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2507 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2508 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
2514 static int cmos_write(char *buf
)
2519 while ((cmd
= next_cmd(&buf
))) {
2520 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
2521 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
2526 res
= issue_thinkpad_cmos_command(cmos_cmd
);
2534 static struct ibm_struct cmos_driver_data
= {
2537 .write
= cmos_write
,
2541 /*************************************************************************
2545 static enum led_access_mode led_supported
;
2547 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
2548 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2549 "LED", /* all others */
2552 static int __init
led_init(struct ibm_init_struct
*iibm
)
2554 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
2556 IBM_ACPIHANDLE_INIT(led
);
2559 /* led not supported on R30, R31 */
2560 led_supported
= TPACPI_LED_NONE
;
2561 else if (strlencmp(led_path
, "SLED") == 0)
2563 led_supported
= TPACPI_LED_570
;
2564 else if (strlencmp(led_path
, "SYSL") == 0)
2565 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
2566 led_supported
= TPACPI_LED_OLD
;
2569 led_supported
= TPACPI_LED_NEW
;
2571 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
2572 str_supported(led_supported
), led_supported
);
2574 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
2577 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
2579 static int led_read(char *p
)
2583 if (!led_supported
) {
2584 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2587 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2589 if (led_supported
== TPACPI_LED_570
) {
2592 for (i
= 0; i
< 8; i
++) {
2593 if (!acpi_evalf(ec_handle
,
2594 &status
, "GLED", "dd", 1 << i
))
2596 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
2597 i
, led_status(status
));
2601 len
+= sprintf(p
+ len
, "commands:\t"
2602 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
2607 /* off, on, blink */
2608 static const int led_sled_arg1
[] = { 0, 1, 3 };
2609 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
2610 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
2611 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
2613 static int led_write(char *buf
)
2621 while ((cmd
= next_cmd(&buf
))) {
2622 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
2625 if (strstr(cmd
, "off")) {
2627 } else if (strstr(cmd
, "on")) {
2629 } else if (strstr(cmd
, "blink")) {
2634 if (led_supported
== TPACPI_LED_570
) {
2637 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2638 led
, led_sled_arg1
[ind
]))
2640 } else if (led_supported
== TPACPI_LED_OLD
) {
2641 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
2643 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
2646 ec_write(TPACPI_LED_EC_HLBL
,
2647 led
* led_exp_hlbl
[ind
]);
2650 ec_write(TPACPI_LED_EC_HLCL
,
2651 led
* led_exp_hlcl
[ind
]);
2656 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
2657 led
, led_led_arg1
[ind
]))
2665 static struct ibm_struct led_driver_data
= {
2671 /*************************************************************************
2675 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
2677 static int __init
beep_init(struct ibm_init_struct
*iibm
)
2679 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
2681 IBM_ACPIHANDLE_INIT(beep
);
2683 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
2684 str_supported(beep_handle
!= NULL
));
2686 return (beep_handle
)? 0 : 1;
2689 static int beep_read(char *p
)
2694 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2696 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
2697 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
2703 static int beep_write(char *buf
)
2711 while ((cmd
= next_cmd(&buf
))) {
2712 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
2713 beep_cmd
>= 0 && beep_cmd
<= 17) {
2717 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
2724 static struct ibm_struct beep_driver_data
= {
2727 .write
= beep_write
,
2730 /*************************************************************************
2734 static enum thermal_access_mode thermal_read_mode
;
2736 /* sysfs temp##_input -------------------------------------------------- */
2738 static ssize_t
thermal_temp_input_show(struct device
*dev
,
2739 struct device_attribute
*attr
,
2742 struct sensor_device_attribute
*sensor_attr
=
2743 to_sensor_dev_attr(attr
);
2744 int idx
= sensor_attr
->index
;
2748 res
= thermal_get_sensor(idx
, &value
);
2751 if (value
== TP_EC_THERMAL_TMP_NA
* 1000)
2754 return snprintf(buf
, PAGE_SIZE
, "%d\n", value
);
2757 #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \
2758 SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB)
2760 static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input
[] = {
2761 THERMAL_SENSOR_ATTR_TEMP(1, 0),
2762 THERMAL_SENSOR_ATTR_TEMP(2, 1),
2763 THERMAL_SENSOR_ATTR_TEMP(3, 2),
2764 THERMAL_SENSOR_ATTR_TEMP(4, 3),
2765 THERMAL_SENSOR_ATTR_TEMP(5, 4),
2766 THERMAL_SENSOR_ATTR_TEMP(6, 5),
2767 THERMAL_SENSOR_ATTR_TEMP(7, 6),
2768 THERMAL_SENSOR_ATTR_TEMP(8, 7),
2769 THERMAL_SENSOR_ATTR_TEMP(9, 8),
2770 THERMAL_SENSOR_ATTR_TEMP(10, 9),
2771 THERMAL_SENSOR_ATTR_TEMP(11, 10),
2772 THERMAL_SENSOR_ATTR_TEMP(12, 11),
2773 THERMAL_SENSOR_ATTR_TEMP(13, 12),
2774 THERMAL_SENSOR_ATTR_TEMP(14, 13),
2775 THERMAL_SENSOR_ATTR_TEMP(15, 14),
2776 THERMAL_SENSOR_ATTR_TEMP(16, 15),
2779 #define THERMAL_ATTRS(X) \
2780 &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr
2782 static struct attribute
*thermal_temp_input_attr
[] = {
2802 static const struct attribute_group thermal_temp_input16_group
= {
2803 .attrs
= thermal_temp_input_attr
2806 static const struct attribute_group thermal_temp_input8_group
= {
2807 .attrs
= &thermal_temp_input_attr
[8]
2810 #undef THERMAL_SENSOR_ATTR_TEMP
2811 #undef THERMAL_ATTRS
2813 /* --------------------------------------------------------------------- */
2815 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
2822 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
2824 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
2826 if (thinkpad_id
.ec_model
) {
2828 * Direct EC access mode: sensors at registers
2829 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
2830 * non-implemented, thermal sensors return 0x80 when
2835 for (i
= 0; i
< 8; i
++) {
2836 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
2842 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
2850 /* This is sheer paranoia, but we handle it anyway */
2853 "ThinkPad ACPI EC access misbehaving, "
2854 "falling back to ACPI TMPx access mode\n");
2855 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2858 "ThinkPad ACPI EC access misbehaving, "
2859 "disabling thermal sensors access\n");
2860 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2865 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
2867 } else if (acpi_tmp7
) {
2868 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
2869 /* 600e/x, 770e, 770x */
2870 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
2872 /* Standard ACPI TMPx access, max 8 sensors */
2873 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2876 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2877 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2880 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
2881 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
2884 switch(thermal_read_mode
) {
2885 case TPACPI_THERMAL_TPEC_16
:
2886 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
2887 &thermal_temp_input16_group
);
2891 case TPACPI_THERMAL_TPEC_8
:
2892 case TPACPI_THERMAL_ACPI_TMP07
:
2893 case TPACPI_THERMAL_ACPI_UPDT
:
2894 res
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
2895 &thermal_temp_input8_group
);
2899 case TPACPI_THERMAL_NONE
:
2907 static void thermal_exit(void)
2909 switch(thermal_read_mode
) {
2910 case TPACPI_THERMAL_TPEC_16
:
2911 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
2912 &thermal_temp_input16_group
);
2914 case TPACPI_THERMAL_TPEC_8
:
2915 case TPACPI_THERMAL_ACPI_TMP07
:
2916 case TPACPI_THERMAL_ACPI_UPDT
:
2917 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
,
2918 &thermal_temp_input16_group
);
2920 case TPACPI_THERMAL_NONE
:
2926 /* idx is zero-based */
2927 static int thermal_get_sensor(int idx
, s32
*value
)
2933 t
= TP_EC_THERMAL_TMP0
;
2935 switch (thermal_read_mode
) {
2936 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2937 case TPACPI_THERMAL_TPEC_16
:
2938 if (idx
>= 8 && idx
<= 15) {
2939 t
= TP_EC_THERMAL_TMP8
;
2944 case TPACPI_THERMAL_TPEC_8
:
2946 if (!acpi_ec_read(t
+ idx
, &tmp
))
2948 *value
= tmp
* 1000;
2953 case TPACPI_THERMAL_ACPI_UPDT
:
2955 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2956 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
2958 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2960 *value
= (t
- 2732) * 100;
2965 case TPACPI_THERMAL_ACPI_TMP07
:
2967 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2968 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2970 if (t
> 127 || t
< -127)
2971 t
= TP_EC_THERMAL_TMP_NA
;
2977 case TPACPI_THERMAL_NONE
:
2985 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
2996 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
2999 for(i
= 0 ; i
< n
; i
++) {
3000 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
3008 static int thermal_read(char *p
)
3012 struct ibm_thermal_sensors_struct t
;
3014 n
= thermal_get_sensors(&t
);
3015 if (unlikely(n
< 0))
3018 len
+= sprintf(p
+ len
, "temperatures:\t");
3021 for (i
= 0; i
< (n
- 1); i
++)
3022 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
3023 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
3025 len
+= sprintf(p
+ len
, "not supported\n");
3030 static struct ibm_struct thermal_driver_data
= {
3032 .read
= thermal_read
,
3033 .exit
= thermal_exit
,
3036 /*************************************************************************
3040 static u8 ecdump_regs
[256];
3042 static int ecdump_read(char *p
)
3048 len
+= sprintf(p
+ len
, "EC "
3049 " +00 +01 +02 +03 +04 +05 +06 +07"
3050 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
3051 for (i
= 0; i
< 256; i
+= 16) {
3052 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
3053 for (j
= 0; j
< 16; j
++) {
3054 if (!acpi_ec_read(i
+ j
, &v
))
3056 if (v
!= ecdump_regs
[i
+ j
])
3057 len
+= sprintf(p
+ len
, " *%02x", v
);
3059 len
+= sprintf(p
+ len
, " %02x", v
);
3060 ecdump_regs
[i
+ j
] = v
;
3062 len
+= sprintf(p
+ len
, "\n");
3067 /* These are way too dangerous to advertise openly... */
3069 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
3070 " (<offset> is 00-ff, <value> is 00-ff)\n");
3071 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
3072 " (<offset> is 00-ff, <value> is 0-255)\n");
3077 static int ecdump_write(char *buf
)
3082 while ((cmd
= next_cmd(&buf
))) {
3083 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
3085 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
3089 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
3090 if (!acpi_ec_write(i
, v
))
3099 static struct ibm_struct ecdump_driver_data
= {
3101 .read
= ecdump_read
,
3102 .write
= ecdump_write
,
3103 .flags
.experimental
= 1,
3106 /*************************************************************************
3107 * Backlight/brightness subdriver
3110 static struct backlight_device
*ibm_backlight_device
;
3112 static struct backlight_ops ibm_backlight_data
= {
3113 .get_brightness
= brightness_get
,
3114 .update_status
= brightness_update_status
,
3117 static struct mutex brightness_mutex
;
3119 static int __init
tpacpi_query_bcll_levels(acpi_handle handle
)
3121 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
3122 union acpi_object
*obj
;
3125 if (ACPI_SUCCESS(acpi_evaluate_object(handle
, NULL
, NULL
, &buffer
))) {
3126 obj
= (union acpi_object
*)buffer
.pointer
;
3127 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
3128 printk(IBM_ERR
"Unknown BCLL data, "
3129 "please report this to %s\n", IBM_MAIL
);
3132 rc
= obj
->package
.count
;
3138 kfree(buffer
.pointer
);
3142 static acpi_status __init
brightness_find_bcll(acpi_handle handle
, u32 lvl
,
3143 void *context
, void **rv
)
3145 char name
[ACPI_PATH_SEGMENT_LENGTH
];
3146 struct acpi_buffer buffer
= { sizeof(name
), &name
};
3148 if (ACPI_SUCCESS(acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
)) &&
3149 !strncmp("BCLL", name
, sizeof(name
) - 1)) {
3150 if (tpacpi_query_bcll_levels(handle
) == 16) {
3152 return AE_CTRL_TERMINATE
;
3161 static int __init
brightness_check_levels(void)
3164 void *found_node
= NULL
;
3167 IBM_ACPIHANDLE_INIT(vid
);
3172 /* Search for a BCLL package with 16 levels */
3173 status
= acpi_walk_namespace(ACPI_TYPE_PACKAGE
, vid_handle
, 3,
3174 brightness_find_bcll
, NULL
, &found_node
);
3176 return (ACPI_SUCCESS(status
) && found_node
!= NULL
);
3179 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
3183 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
3185 mutex_init(&brightness_mutex
);
3187 if (!brightness_enable
) {
3188 dbg_printk(TPACPI_DBG_INIT
,
3189 "brightness support disabled by module parameter\n");
3193 if (!brightness_mode
) {
3194 if (thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
)
3195 brightness_mode
= 2;
3197 brightness_mode
= 3;
3199 dbg_printk(TPACPI_DBG_INIT
, "selected brightness_mode=%d\n",
3203 if (brightness_mode
> 3)
3206 tp_features
.bright_16levels
=
3207 thinkpad_id
.vendor
== PCI_VENDOR_ID_LENOVO
&&
3208 brightness_check_levels();
3210 b
= brightness_get(NULL
);
3214 if (tp_features
.bright_16levels
)
3215 printk(IBM_INFO
"detected a 16-level brightness capable ThinkPad\n");
3217 ibm_backlight_device
= backlight_device_register(
3218 TPACPI_BACKLIGHT_DEV_NAME
, NULL
, NULL
,
3219 &ibm_backlight_data
);
3220 if (IS_ERR(ibm_backlight_device
)) {
3221 printk(IBM_ERR
"Could not register backlight device\n");
3222 return PTR_ERR(ibm_backlight_device
);
3224 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
3226 ibm_backlight_device
->props
.max_brightness
=
3227 (tp_features
.bright_16levels
)? 15 : 7;
3228 ibm_backlight_device
->props
.brightness
= b
;
3229 backlight_update_status(ibm_backlight_device
);
3234 static void brightness_exit(void)
3236 if (ibm_backlight_device
) {
3237 vdbg_printk(TPACPI_DBG_EXIT
,
3238 "calling backlight_device_unregister()\n");
3239 backlight_device_unregister(ibm_backlight_device
);
3240 ibm_backlight_device
= NULL
;
3244 static int brightness_update_status(struct backlight_device
*bd
)
3246 return brightness_set(
3247 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
3248 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
3249 bd
->props
.brightness
: 0);
3253 * ThinkPads can read brightness from two places: EC 0x31, or
3254 * CMOS NVRAM byte 0x5E, bits 0-3.
3256 static int brightness_get(struct backlight_device
*bd
)
3258 u8 lec
= 0, lcmos
= 0, level
= 0;
3260 if (brightness_mode
& 1) {
3261 if (!acpi_ec_read(brightness_offset
, &lec
))
3263 lec
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
3266 if (brightness_mode
& 2) {
3267 lcmos
= (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS
)
3268 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS
)
3269 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS
;
3270 lcmos
&= (tp_features
.bright_16levels
)? 0x0f : 0x07;
3274 if (brightness_mode
== 3 && lec
!= lcmos
) {
3276 "CMOS NVRAM (%u) and EC (%u) do not agree "
3277 "on display brightness level\n",
3278 (unsigned int) lcmos
,
3279 (unsigned int) lec
);
3286 static int brightness_set(int value
)
3288 int cmos_cmd
, inc
, i
, res
;
3291 if (value
> ((tp_features
.bright_16levels
)? 15 : 7))
3294 res
= mutex_lock_interruptible(&brightness_mutex
);
3298 current_value
= brightness_get(NULL
);
3299 if (current_value
< 0) {
3300 res
= current_value
;
3304 cmos_cmd
= value
> current_value
?
3305 TP_CMOS_BRIGHTNESS_UP
:
3306 TP_CMOS_BRIGHTNESS_DOWN
;
3307 inc
= (value
> current_value
)? 1 : -1;
3310 for (i
= current_value
; i
!= value
; i
+= inc
) {
3311 if ((brightness_mode
& 2) &&
3312 issue_thinkpad_cmos_command(cmos_cmd
)) {
3316 if ((brightness_mode
& 1) &&
3317 !acpi_ec_write(brightness_offset
, i
+ inc
)) {
3324 mutex_unlock(&brightness_mutex
);
3328 static int brightness_read(char *p
)
3333 if ((level
= brightness_get(NULL
)) < 0) {
3334 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3336 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
);
3337 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
3338 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3339 " (<level> is 0-%d)\n",
3340 (tp_features
.bright_16levels
) ? 15 : 7);
3346 static int brightness_write(char *buf
)
3351 int max_level
= (tp_features
.bright_16levels
) ? 15 : 7;
3353 while ((cmd
= next_cmd(&buf
))) {
3354 if ((level
= brightness_get(NULL
)) < 0)
3357 if (strlencmp(cmd
, "up") == 0) {
3358 new_level
= level
== (max_level
)?
3359 max_level
: level
+ 1;
3360 } else if (strlencmp(cmd
, "down") == 0) {
3361 new_level
= level
== 0? 0 : level
- 1;
3362 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3363 new_level
>= 0 && new_level
<= max_level
) {
3368 brightness_set(new_level
);
3374 static struct ibm_struct brightness_driver_data
= {
3375 .name
= "brightness",
3376 .read
= brightness_read
,
3377 .write
= brightness_write
,
3378 .exit
= brightness_exit
,
3381 /*************************************************************************
3385 static int volume_read(char *p
)
3390 if (!acpi_ec_read(volume_offset
, &level
)) {
3391 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
3393 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
3394 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
3395 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
3396 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
3397 " (<level> is 0-15)\n");
3403 static int volume_write(char *buf
)
3405 int cmos_cmd
, inc
, i
;
3407 int new_level
, new_mute
;
3410 while ((cmd
= next_cmd(&buf
))) {
3411 if (!acpi_ec_read(volume_offset
, &level
))
3413 new_mute
= mute
= level
& 0x40;
3414 new_level
= level
= level
& 0xf;
3416 if (strlencmp(cmd
, "up") == 0) {
3420 new_level
= level
== 15 ? 15 : level
+ 1;
3421 } else if (strlencmp(cmd
, "down") == 0) {
3425 new_level
= level
== 0 ? 0 : level
- 1;
3426 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
3427 new_level
>= 0 && new_level
<= 15) {
3429 } else if (strlencmp(cmd
, "mute") == 0) {
3434 if (new_level
!= level
) { /* mute doesn't change */
3435 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
3436 inc
= new_level
> level
? 1 : -1;
3438 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
3439 !acpi_ec_write(volume_offset
, level
)))
3442 for (i
= level
; i
!= new_level
; i
+= inc
)
3443 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3444 !acpi_ec_write(volume_offset
, i
+ inc
))
3447 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
3448 !acpi_ec_write(volume_offset
,
3453 if (new_mute
!= mute
) { /* level doesn't change */
3454 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
3456 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
3457 !acpi_ec_write(volume_offset
, level
+ new_mute
))
3465 static struct ibm_struct volume_driver_data
= {
3467 .read
= volume_read
,
3468 .write
= volume_write
,
3471 /*************************************************************************
3478 * TPACPI_FAN_RD_ACPI_GFAN:
3479 * ACPI GFAN method: returns fan level
3481 * see TPACPI_FAN_WR_ACPI_SFAN
3482 * EC 0x2f (HFSP) not available if GFAN exists
3484 * TPACPI_FAN_WR_ACPI_SFAN:
3485 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
3487 * EC 0x2f (HFSP) might be available *for reading*, but do not use
3490 * TPACPI_FAN_WR_TPEC:
3491 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
3492 * Supported on almost all ThinkPads
3494 * Fan speed changes of any sort (including those caused by the
3495 * disengaged mode) are usually done slowly by the firmware as the
3496 * maximum ammount of fan duty cycle change per second seems to be
3499 * Reading is not available if GFAN exists.
3500 * Writing is not available if SFAN exists.
3503 * 7 automatic mode engaged;
3504 * (default operation mode of the ThinkPad)
3505 * fan level is ignored in this mode.
3506 * 6 full speed mode (takes precedence over bit 7);
3507 * not available on all thinkpads. May disable
3508 * the tachometer while the fan controller ramps up
3509 * the speed (which can take up to a few *minutes*).
3510 * Speeds up fan to 100% duty-cycle, which is far above
3511 * the standard RPM levels. It is not impossible that
3512 * it could cause hardware damage.
3513 * 5-3 unused in some models. Extra bits for fan level
3514 * in others, but still useless as all values above
3515 * 7 map to the same speed as level 7 in these models.
3516 * 2-0 fan level (0..7 usually)
3518 * 0x07 = max (set when temperatures critical)
3519 * Some ThinkPads may have other levels, see
3520 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
3522 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
3523 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
3524 * does so, its initial value is meaningless (0x07).
3526 * For firmware bugs, refer to:
3527 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3531 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
3532 * Main fan tachometer reading (in RPM)
3534 * This register is present on all ThinkPads with a new-style EC, and
3535 * it is known not to be present on the A21m/e, and T22, as there is
3536 * something else in offset 0x84 according to the ACPI DSDT. Other
3537 * ThinkPads from this same time period (and earlier) probably lack the
3538 * tachometer as well.
3540 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
3541 * was never fixed by IBM to report the EC firmware version string
3542 * probably support the tachometer (like the early X models), so
3543 * detecting it is quite hard. We need more data to know for sure.
3545 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
3548 * FIRMWARE BUG: may go stale while the EC is switching to full speed
3551 * For firmware bugs, refer to:
3552 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
3554 * TPACPI_FAN_WR_ACPI_FANS:
3555 * ThinkPad X31, X40, X41. Not available in the X60.
3557 * FANS ACPI handle: takes three arguments: low speed, medium speed,
3558 * high speed. ACPI DSDT seems to map these three speeds to levels
3559 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
3560 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
3562 * The speeds are stored on handles
3563 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
3565 * There are three default speed sets, acessible as handles:
3566 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
3568 * ACPI DSDT switches which set is in use depending on various
3571 * TPACPI_FAN_WR_TPEC is also available and should be used to
3572 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
3573 * but the ACPI tables just mention level 7.
3576 static enum fan_status_access_mode fan_status_access_mode
;
3577 static enum fan_control_access_mode fan_control_access_mode
;
3578 static enum fan_control_commands fan_control_commands
;
3580 static u8 fan_control_initial_status
;
3581 static u8 fan_control_desired_level
;
3583 static void fan_watchdog_fire(struct work_struct
*ignored
);
3584 static int fan_watchdog_maxinterval
;
3585 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
3587 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
3588 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
3589 "\\FSPD", /* 600e/x, 770e, 770x */
3591 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
3592 "JFNS", /* 770x-JL */
3596 * SYSFS fan layout: hwmon compatible (device)
3599 * 0: "disengaged" mode
3601 * 2: native EC "auto" mode (recommended, hardware default)
3603 * pwm*: set speed in manual mode, ignored otherwise.
3604 * 0 is level 0; 255 is level 7. Intermediate points done with linear
3607 * fan*_input: tachometer reading, RPM
3610 * SYSFS fan layout: extensions
3612 * fan_watchdog (driver):
3613 * fan watchdog interval in seconds, 0 disables (default), max 120
3616 /* sysfs fan pwm1_enable ----------------------------------------------- */
3617 static ssize_t
fan_pwm1_enable_show(struct device
*dev
,
3618 struct device_attribute
*attr
,
3624 res
= fan_get_status_safe(&status
);
3628 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3629 if (status
!= fan_control_initial_status
) {
3630 tp_features
.fan_ctrl_status_undef
= 0;
3632 /* Return most likely status. In fact, it
3633 * might be the only possible status */
3634 status
= TP_EC_FAN_AUTO
;
3638 if (status
& TP_EC_FAN_FULLSPEED
) {
3640 } else if (status
& TP_EC_FAN_AUTO
) {
3645 return snprintf(buf
, PAGE_SIZE
, "%d\n", mode
);
3648 static ssize_t
fan_pwm1_enable_store(struct device
*dev
,
3649 struct device_attribute
*attr
,
3650 const char *buf
, size_t count
)
3655 if (parse_strtoul(buf
, 2, &t
))
3660 level
= TP_EC_FAN_FULLSPEED
;
3663 level
= TPACPI_FAN_LAST_LEVEL
;
3666 level
= TP_EC_FAN_AUTO
;
3669 /* reserved for software-controlled auto mode */
3675 res
= fan_set_level_safe(level
);
3681 fan_watchdog_reset();
3686 static struct device_attribute dev_attr_fan_pwm1_enable
=
3687 __ATTR(pwm1_enable
, S_IWUSR
| S_IRUGO
,
3688 fan_pwm1_enable_show
, fan_pwm1_enable_store
);
3690 /* sysfs fan pwm1 ------------------------------------------------------ */
3691 static ssize_t
fan_pwm1_show(struct device
*dev
,
3692 struct device_attribute
*attr
,
3698 res
= fan_get_status_safe(&status
);
3702 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
3703 if (status
!= fan_control_initial_status
) {
3704 tp_features
.fan_ctrl_status_undef
= 0;
3706 status
= TP_EC_FAN_AUTO
;
3711 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) != 0)
3712 status
= fan_control_desired_level
;
3717 return snprintf(buf
, PAGE_SIZE
, "%u\n", (status
* 255) / 7);
3720 static ssize_t
fan_pwm1_store(struct device
*dev
,
3721 struct device_attribute
*attr
,
3722 const char *buf
, size_t count
)
3726 u8 status
, newlevel
;
3728 if (parse_strtoul(buf
, 255, &s
))
3731 /* scale down from 0-255 to 0-7 */
3732 newlevel
= (s
>> 5) & 0x07;
3734 rc
= mutex_lock_interruptible(&fan_mutex
);
3738 rc
= fan_get_status(&status
);
3739 if (!rc
&& (status
&
3740 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3741 rc
= fan_set_level(newlevel
);
3745 fan_update_desired_level(newlevel
);
3746 fan_watchdog_reset();
3750 mutex_unlock(&fan_mutex
);
3751 return (rc
)? rc
: count
;
3754 static struct device_attribute dev_attr_fan_pwm1
=
3755 __ATTR(pwm1
, S_IWUSR
| S_IRUGO
,
3756 fan_pwm1_show
, fan_pwm1_store
);
3758 /* sysfs fan fan1_input ------------------------------------------------ */
3759 static ssize_t
fan_fan1_input_show(struct device
*dev
,
3760 struct device_attribute
*attr
,
3766 res
= fan_get_speed(&speed
);
3770 return snprintf(buf
, PAGE_SIZE
, "%u\n", speed
);
3773 static struct device_attribute dev_attr_fan_fan1_input
=
3774 __ATTR(fan1_input
, S_IRUGO
,
3775 fan_fan1_input_show
, NULL
);
3777 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
3778 static ssize_t
fan_fan_watchdog_show(struct device_driver
*drv
,
3781 return snprintf(buf
, PAGE_SIZE
, "%u\n", fan_watchdog_maxinterval
);
3784 static ssize_t
fan_fan_watchdog_store(struct device_driver
*drv
,
3785 const char *buf
, size_t count
)
3789 if (parse_strtoul(buf
, 120, &t
))
3792 if (!fan_control_allowed
)
3795 fan_watchdog_maxinterval
= t
;
3796 fan_watchdog_reset();
3801 static DRIVER_ATTR(fan_watchdog
, S_IWUSR
| S_IRUGO
,
3802 fan_fan_watchdog_show
, fan_fan_watchdog_store
);
3804 /* --------------------------------------------------------------------- */
3805 static struct attribute
*fan_attributes
[] = {
3806 &dev_attr_fan_pwm1_enable
.attr
, &dev_attr_fan_pwm1
.attr
,
3807 &dev_attr_fan_fan1_input
.attr
,
3811 static const struct attribute_group fan_attr_group
= {
3812 .attrs
= fan_attributes
,
3815 static int __init
fan_init(struct ibm_init_struct
*iibm
)
3819 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
3821 mutex_init(&fan_mutex
);
3822 fan_status_access_mode
= TPACPI_FAN_NONE
;
3823 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3824 fan_control_commands
= 0;
3825 fan_watchdog_maxinterval
= 0;
3826 tp_features
.fan_ctrl_status_undef
= 0;
3827 fan_control_desired_level
= 7;
3829 IBM_ACPIHANDLE_INIT(fans
);
3830 IBM_ACPIHANDLE_INIT(gfan
);
3831 IBM_ACPIHANDLE_INIT(sfan
);
3834 /* 570, 600e/x, 770e, 770x */
3835 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
3837 /* all other ThinkPads: note that even old-style
3838 * ThinkPad ECs supports the fan control register */
3839 if (likely(acpi_ec_read(fan_status_offset
,
3840 &fan_control_initial_status
))) {
3841 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
3843 /* In some ThinkPads, neither the EC nor the ACPI
3844 * DSDT initialize the fan status, and it ends up
3845 * being set to 0x07 when it *could* be either
3848 * Enable for TP-1Y (T43), TP-78 (R51e),
3849 * TP-76 (R52), TP-70 (T43, R52), which are known
3851 if (fan_control_initial_status
== 0x07) {
3852 switch (thinkpad_id
.ec_model
) {
3853 case 0x5931: /* TP-1Y */
3854 case 0x3837: /* TP-78 */
3855 case 0x3637: /* TP-76 */
3856 case 0x3037: /* TP-70 */
3858 "fan_init: initial fan status is "
3859 "unknown, assuming it is in auto "
3861 tp_features
.fan_ctrl_status_undef
= 1;
3867 "ThinkPad ACPI EC access misbehaving, "
3868 "fan status and control unavailable\n");
3875 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
3876 fan_control_commands
|=
3877 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
3880 /* gfan without sfan means no fan control */
3881 /* all other models implement TP EC 0x2f control */
3885 fan_control_access_mode
=
3886 TPACPI_FAN_WR_ACPI_FANS
;
3887 fan_control_commands
|=
3888 TPACPI_FAN_CMD_SPEED
|
3889 TPACPI_FAN_CMD_LEVEL
|
3890 TPACPI_FAN_CMD_ENABLE
;
3892 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
3893 fan_control_commands
|=
3894 TPACPI_FAN_CMD_LEVEL
|
3895 TPACPI_FAN_CMD_ENABLE
;
3900 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
3901 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
3902 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
3903 fan_status_access_mode
, fan_control_access_mode
);
3905 /* fan control master switch */
3906 if (!fan_control_allowed
) {
3907 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
3908 fan_control_commands
= 0;
3909 dbg_printk(TPACPI_DBG_INIT
,
3910 "fan control features disabled by parameter\n");
3913 /* update fan_control_desired_level */
3914 if (fan_status_access_mode
!= TPACPI_FAN_NONE
)
3915 fan_get_status_safe(NULL
);
3917 if (fan_status_access_mode
!= TPACPI_FAN_NONE
||
3918 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
) {
3919 rc
= sysfs_create_group(&tpacpi_sensors_pdev
->dev
.kobj
,
3922 rc
= driver_create_file(&tpacpi_hwmon_pdriver
.driver
,
3923 &driver_attr_fan_watchdog
);
3932 * Call with fan_mutex held
3934 static void fan_update_desired_level(u8 status
)
3937 (TP_EC_FAN_AUTO
| TP_EC_FAN_FULLSPEED
)) == 0) {
3939 fan_control_desired_level
= 7;
3941 fan_control_desired_level
= status
;
3945 static int fan_get_status(u8
*status
)
3950 * Add TPACPI_FAN_RD_ACPI_FANS ? */
3952 switch (fan_status_access_mode
) {
3953 case TPACPI_FAN_RD_ACPI_GFAN
:
3954 /* 570, 600e/x, 770e, 770x */
3956 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
3964 case TPACPI_FAN_RD_TPEC
:
3965 /* all except 570, 600e/x, 770e, 770x */
3966 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
3981 static int fan_get_status_safe(u8
*status
)
3986 rc
= mutex_lock_interruptible(&fan_mutex
);
3989 rc
= fan_get_status(&s
);
3991 fan_update_desired_level(s
);
3992 mutex_unlock(&fan_mutex
);
4000 static void fan_exit(void)
4002 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
4004 /* FIXME: can we really do this unconditionally? */
4005 sysfs_remove_group(&tpacpi_sensors_pdev
->dev
.kobj
, &fan_attr_group
);
4006 driver_remove_file(&tpacpi_hwmon_pdriver
.driver
, &driver_attr_fan_watchdog
);
4008 cancel_delayed_work(&fan_watchdog_task
);
4009 flush_scheduled_work();
4012 static int fan_get_speed(unsigned int *speed
)
4016 switch (fan_status_access_mode
) {
4017 case TPACPI_FAN_RD_TPEC
:
4018 /* all except 570, 600e/x, 770e, 770x */
4019 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
4020 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
4024 *speed
= (hi
<< 8) | lo
;
4035 static void fan_watchdog_fire(struct work_struct
*ignored
)
4039 if (tpacpi_lifecycle
!= TPACPI_LIFE_RUNNING
)
4042 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
4043 rc
= fan_set_enable();
4045 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
4046 "will try again later...\n", -rc
);
4047 /* reschedule for later */
4048 fan_watchdog_reset();
4052 static void fan_watchdog_reset(void)
4054 static int fan_watchdog_active
;
4056 if (fan_control_access_mode
== TPACPI_FAN_WR_NONE
)
4059 if (fan_watchdog_active
)
4060 cancel_delayed_work(&fan_watchdog_task
);
4062 if (fan_watchdog_maxinterval
> 0 &&
4063 tpacpi_lifecycle
!= TPACPI_LIFE_EXITING
) {
4064 fan_watchdog_active
= 1;
4065 if (!schedule_delayed_work(&fan_watchdog_task
,
4066 msecs_to_jiffies(fan_watchdog_maxinterval
4068 printk(IBM_ERR
"failed to schedule the fan watchdog, "
4069 "watchdog will not trigger\n");
4072 fan_watchdog_active
= 0;
4075 static int fan_set_level(int level
)
4077 if (!fan_control_allowed
)
4080 switch (fan_control_access_mode
) {
4081 case TPACPI_FAN_WR_ACPI_SFAN
:
4082 if (level
>= 0 && level
<= 7) {
4083 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
4089 case TPACPI_FAN_WR_ACPI_FANS
:
4090 case TPACPI_FAN_WR_TPEC
:
4091 if ((level
!= TP_EC_FAN_AUTO
) &&
4092 (level
!= TP_EC_FAN_FULLSPEED
) &&
4093 ((level
< 0) || (level
> 7)))
4096 /* safety net should the EC not support AUTO
4097 * or FULLSPEED mode bits and just ignore them */
4098 if (level
& TP_EC_FAN_FULLSPEED
)
4099 level
|= 7; /* safety min speed 7 */
4100 else if (level
& TP_EC_FAN_FULLSPEED
)
4101 level
|= 4; /* safety min speed 4 */
4103 if (!acpi_ec_write(fan_status_offset
, level
))
4106 tp_features
.fan_ctrl_status_undef
= 0;
4115 static int fan_set_level_safe(int level
)
4119 if (!fan_control_allowed
)
4122 rc
= mutex_lock_interruptible(&fan_mutex
);
4126 if (level
== TPACPI_FAN_LAST_LEVEL
)
4127 level
= fan_control_desired_level
;
4129 rc
= fan_set_level(level
);
4131 fan_update_desired_level(level
);
4133 mutex_unlock(&fan_mutex
);
4137 static int fan_set_enable(void)
4142 if (!fan_control_allowed
)
4145 rc
= mutex_lock_interruptible(&fan_mutex
);
4149 switch (fan_control_access_mode
) {
4150 case TPACPI_FAN_WR_ACPI_FANS
:
4151 case TPACPI_FAN_WR_TPEC
:
4152 rc
= fan_get_status(&s
);
4156 /* Don't go out of emergency fan mode */
4159 s
|= TP_EC_FAN_AUTO
| 4; /* min fan speed 4 */
4162 if (!acpi_ec_write(fan_status_offset
, s
))
4165 tp_features
.fan_ctrl_status_undef
= 0;
4170 case TPACPI_FAN_WR_ACPI_SFAN
:
4171 rc
= fan_get_status(&s
);
4177 /* Set fan to at least level 4 */
4180 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
4190 mutex_unlock(&fan_mutex
);
4194 static int fan_set_disable(void)
4198 if (!fan_control_allowed
)
4201 rc
= mutex_lock_interruptible(&fan_mutex
);
4206 switch (fan_control_access_mode
) {
4207 case TPACPI_FAN_WR_ACPI_FANS
:
4208 case TPACPI_FAN_WR_TPEC
:
4209 if (!acpi_ec_write(fan_status_offset
, 0x00))
4212 fan_control_desired_level
= 0;
4213 tp_features
.fan_ctrl_status_undef
= 0;
4217 case TPACPI_FAN_WR_ACPI_SFAN
:
4218 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
4221 fan_control_desired_level
= 0;
4229 mutex_unlock(&fan_mutex
);
4233 static int fan_set_speed(int speed
)
4237 if (!fan_control_allowed
)
4240 rc
= mutex_lock_interruptible(&fan_mutex
);
4245 switch (fan_control_access_mode
) {
4246 case TPACPI_FAN_WR_ACPI_FANS
:
4247 if (speed
>= 0 && speed
<= 65535) {
4248 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
4249 speed
, speed
, speed
))
4259 mutex_unlock(&fan_mutex
);
4263 static int fan_read(char *p
)
4268 unsigned int speed
= 0;
4270 switch (fan_status_access_mode
) {
4271 case TPACPI_FAN_RD_ACPI_GFAN
:
4272 /* 570, 600e/x, 770e, 770x */
4273 if ((rc
= fan_get_status_safe(&status
)) < 0)
4276 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
4278 (status
!= 0) ? "enabled" : "disabled", status
);
4281 case TPACPI_FAN_RD_TPEC
:
4282 /* all except 570, 600e/x, 770e, 770x */
4283 if ((rc
= fan_get_status_safe(&status
)) < 0)
4286 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
4287 if (status
!= fan_control_initial_status
)
4288 tp_features
.fan_ctrl_status_undef
= 0;
4290 /* Return most likely status. In fact, it
4291 * might be the only possible status */
4292 status
= TP_EC_FAN_AUTO
;
4295 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
4296 (status
!= 0) ? "enabled" : "disabled");
4298 if ((rc
= fan_get_speed(&speed
)) < 0)
4301 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
4303 if (status
& TP_EC_FAN_FULLSPEED
)
4304 /* Disengaged mode takes precedence */
4305 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
4306 else if (status
& TP_EC_FAN_AUTO
)
4307 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
4309 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
4312 case TPACPI_FAN_NONE
:
4314 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
4317 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
4318 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
4320 switch (fan_control_access_mode
) {
4321 case TPACPI_FAN_WR_ACPI_SFAN
:
4322 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
4326 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
4327 "auto, disengaged, full-speed)\n");
4332 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
4333 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
4334 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
4335 "1-120 (seconds))\n");
4337 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
4338 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
4339 " (<speed> is 0-65535)\n");
4344 static int fan_write_cmd_level(const char *cmd
, int *rc
)
4348 if (strlencmp(cmd
, "level auto") == 0)
4349 level
= TP_EC_FAN_AUTO
;
4350 else if ((strlencmp(cmd
, "level disengaged") == 0) |
4351 (strlencmp(cmd
, "level full-speed") == 0))
4352 level
= TP_EC_FAN_FULLSPEED
;
4353 else if (sscanf(cmd
, "level %d", &level
) != 1)
4356 if ((*rc
= fan_set_level_safe(level
)) == -ENXIO
)
4357 printk(IBM_ERR
"level command accepted for unsupported "
4358 "access mode %d", fan_control_access_mode
);
4363 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
4365 if (strlencmp(cmd
, "enable") != 0)
4368 if ((*rc
= fan_set_enable()) == -ENXIO
)
4369 printk(IBM_ERR
"enable command accepted for unsupported "
4370 "access mode %d", fan_control_access_mode
);
4375 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
4377 if (strlencmp(cmd
, "disable") != 0)
4380 if ((*rc
= fan_set_disable()) == -ENXIO
)
4381 printk(IBM_ERR
"disable command accepted for unsupported "
4382 "access mode %d", fan_control_access_mode
);
4387 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
4392 * Support speed <low> <medium> <high> ? */
4394 if (sscanf(cmd
, "speed %d", &speed
) != 1)
4397 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
4398 printk(IBM_ERR
"speed command accepted for unsupported "
4399 "access mode %d", fan_control_access_mode
);
4404 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
4408 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
4411 if (interval
< 0 || interval
> 120)
4414 fan_watchdog_maxinterval
= interval
;
4419 static int fan_write(char *buf
)
4424 while (!rc
&& (cmd
= next_cmd(&buf
))) {
4425 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
4426 fan_write_cmd_level(cmd
, &rc
)) &&
4427 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
4428 (fan_write_cmd_enable(cmd
, &rc
) ||
4429 fan_write_cmd_disable(cmd
, &rc
) ||
4430 fan_write_cmd_watchdog(cmd
, &rc
))) &&
4431 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
4432 fan_write_cmd_speed(cmd
, &rc
))
4436 fan_watchdog_reset();
4442 static struct ibm_struct fan_driver_data
= {
4449 /****************************************************************************
4450 ****************************************************************************
4454 ****************************************************************************
4455 ****************************************************************************/
4457 /* sysfs name ---------------------------------------------------------- */
4458 static ssize_t
thinkpad_acpi_pdev_name_show(struct device
*dev
,
4459 struct device_attribute
*attr
,
4462 return snprintf(buf
, PAGE_SIZE
, "%s\n", IBM_NAME
);
4465 static struct device_attribute dev_attr_thinkpad_acpi_pdev_name
=
4466 __ATTR(name
, S_IRUGO
, thinkpad_acpi_pdev_name_show
, NULL
);
4468 /* --------------------------------------------------------------------- */
4471 static struct proc_dir_entry
*proc_dir
;
4473 /* Subdriver registry */
4474 static LIST_HEAD(tpacpi_all_drivers
);
4478 * Module and infrastructure proble, init and exit handling
4481 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
4482 static const char * __init
str_supported(int is_supported
)
4484 static char text_unsupported
[] __initdata
= "not supported";
4486 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
4488 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
4490 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
4493 struct ibm_struct
*ibm
= iibm
->data
;
4494 struct proc_dir_entry
*entry
;
4496 BUG_ON(ibm
== NULL
);
4498 INIT_LIST_HEAD(&ibm
->all_drivers
);
4500 if (ibm
->flags
.experimental
&& !experimental
)
4503 dbg_printk(TPACPI_DBG_INIT
,
4504 "probing for %s\n", ibm
->name
);
4507 ret
= iibm
->init(iibm
);
4509 return 0; /* probe failed */
4513 ibm
->flags
.init_called
= 1;
4517 if (ibm
->acpi
->hid
) {
4518 ret
= register_tpacpi_subdriver(ibm
);
4523 if (ibm
->acpi
->notify
) {
4524 ret
= setup_acpi_notify(ibm
);
4525 if (ret
== -ENODEV
) {
4526 printk(IBM_NOTICE
"disabling subdriver %s\n",
4536 dbg_printk(TPACPI_DBG_INIT
,
4537 "%s installed\n", ibm
->name
);
4540 entry
= create_proc_entry(ibm
->name
,
4541 S_IFREG
| S_IRUGO
| S_IWUSR
,
4544 printk(IBM_ERR
"unable to create proc entry %s\n",
4549 entry
->owner
= THIS_MODULE
;
4551 entry
->read_proc
= &dispatch_procfs_read
;
4553 entry
->write_proc
= &dispatch_procfs_write
;
4554 ibm
->flags
.proc_created
= 1;
4557 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
4562 dbg_printk(TPACPI_DBG_INIT
,
4563 "%s: at error exit path with result %d\n",
4567 return (ret
< 0)? ret
: 0;
4570 static void ibm_exit(struct ibm_struct
*ibm
)
4572 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
4574 list_del_init(&ibm
->all_drivers
);
4576 if (ibm
->flags
.acpi_notify_installed
) {
4577 dbg_printk(TPACPI_DBG_EXIT
,
4578 "%s: acpi_remove_notify_handler\n", ibm
->name
);
4580 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
4582 dispatch_acpi_notify
);
4583 ibm
->flags
.acpi_notify_installed
= 0;
4584 ibm
->flags
.acpi_notify_installed
= 0;
4587 if (ibm
->flags
.proc_created
) {
4588 dbg_printk(TPACPI_DBG_EXIT
,
4589 "%s: remove_proc_entry\n", ibm
->name
);
4590 remove_proc_entry(ibm
->name
, proc_dir
);
4591 ibm
->flags
.proc_created
= 0;
4594 if (ibm
->flags
.acpi_driver_registered
) {
4595 dbg_printk(TPACPI_DBG_EXIT
,
4596 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
4598 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
4599 kfree(ibm
->acpi
->driver
);
4600 ibm
->acpi
->driver
= NULL
;
4601 ibm
->flags
.acpi_driver_registered
= 0;
4604 if (ibm
->flags
.init_called
&& ibm
->exit
) {
4606 ibm
->flags
.init_called
= 0;
4609 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
4614 static void __init
get_thinkpad_model_data(struct thinkpad_id_data
*tp
)
4616 struct dmi_device
*dev
= NULL
;
4617 char ec_fw_string
[18];
4622 memset(tp
, 0, sizeof(*tp
));
4624 if (dmi_name_in_vendors("IBM"))
4625 tp
->vendor
= PCI_VENDOR_ID_IBM
;
4626 else if (dmi_name_in_vendors("LENOVO"))
4627 tp
->vendor
= PCI_VENDOR_ID_LENOVO
;
4631 tp
->bios_version_str
= kstrdup(dmi_get_system_info(DMI_BIOS_VERSION
),
4633 if (!tp
->bios_version_str
)
4635 tp
->bios_model
= tp
->bios_version_str
[0]
4636 | (tp
->bios_version_str
[1] << 8);
4639 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4640 * X32 or newer, all Z series; Some models must have an
4641 * up-to-date BIOS or they will not be detected.
4643 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
4645 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
4646 if (sscanf(dev
->name
,
4647 "IBM ThinkPad Embedded Controller -[%17c",
4648 ec_fw_string
) == 1) {
4649 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
4650 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
4652 tp
->ec_version_str
= kstrdup(ec_fw_string
, GFP_KERNEL
);
4653 tp
->ec_model
= ec_fw_string
[0]
4654 | (ec_fw_string
[1] << 8);
4659 tp
->model_str
= kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION
),
4661 if (strnicmp(tp
->model_str
, "ThinkPad", 8) != 0) {
4662 kfree(tp
->model_str
);
4663 tp
->model_str
= NULL
;
4667 static int __init
probe_for_thinkpad(void)
4675 * Non-ancient models have better DMI tagging, but very old models
4678 is_thinkpad
= (thinkpad_id
.model_str
!= NULL
);
4680 /* ec is required because many other handles are relative to it */
4681 IBM_ACPIHANDLE_INIT(ec
);
4685 "Not yet supported ThinkPad detected!\n");
4690 * Risks a regression on very old machines, but reduces potential
4691 * false positives a damn great deal
4694 is_thinkpad
= (thinkpad_id
.vendor
== PCI_VENDOR_ID_IBM
);
4696 if (!is_thinkpad
&& !force_load
)
4703 /* Module init, exit, parameters */
4705 static struct ibm_init_struct ibms_init
[] __initdata
= {
4707 .init
= thinkpad_acpi_driver_init
,
4708 .data
= &thinkpad_acpi_driver_data
,
4711 .init
= hotkey_init
,
4712 .data
= &hotkey_driver_data
,
4715 .init
= bluetooth_init
,
4716 .data
= &bluetooth_driver_data
,
4720 .data
= &wan_driver_data
,
4724 .data
= &video_driver_data
,
4728 .data
= &light_driver_data
,
4730 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4733 .data
= &dock_driver_data
[0],
4737 .data
= &dock_driver_data
[1],
4740 #ifdef CONFIG_THINKPAD_ACPI_BAY
4743 .data
= &bay_driver_data
,
4748 .data
= &cmos_driver_data
,
4752 .data
= &led_driver_data
,
4756 .data
= &beep_driver_data
,
4759 .init
= thermal_init
,
4760 .data
= &thermal_driver_data
,
4763 .data
= &ecdump_driver_data
,
4766 .init
= brightness_init
,
4767 .data
= &brightness_driver_data
,
4770 .data
= &volume_driver_data
,
4774 .data
= &fan_driver_data
,
4778 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
4781 struct ibm_struct
*ibm
;
4783 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4784 ibm
= ibms_init
[i
].data
;
4785 BUG_ON(ibm
== NULL
);
4787 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
4788 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
4790 strcpy(ibms_init
[i
].param
, val
);
4791 strcat(ibms_init
[i
].param
, ",");
4799 static int experimental
;
4800 module_param(experimental
, int, 0);
4802 static u32 dbg_level
;
4803 module_param_named(debug
, dbg_level
, uint
, 0);
4805 static int force_load
;
4806 module_param(force_load
, bool, 0);
4808 static int fan_control_allowed
;
4809 module_param_named(fan_control
, fan_control_allowed
, bool, 0);
4811 static int brightness_mode
;
4812 module_param_named(brightness_mode
, brightness_mode
, int, 0);
4814 static unsigned int brightness_enable
= 2; /* 2 = auto, 0 = no, 1 = yes */
4815 module_param(brightness_enable
, uint
, 0);
4817 static unsigned int hotkey_report_mode
;
4818 module_param(hotkey_report_mode
, uint
, 0);
4820 #define IBM_PARAM(feature) \
4821 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
4824 IBM_PARAM(bluetooth
);
4827 #ifdef CONFIG_THINKPAD_ACPI_DOCK
4830 #ifdef CONFIG_THINKPAD_ACPI_BAY
4832 #endif /* CONFIG_THINKPAD_ACPI_BAY */
4837 IBM_PARAM(brightness
);
4841 static int __init
thinkpad_acpi_module_init(void)
4845 tpacpi_lifecycle
= TPACPI_LIFE_INIT
;
4847 /* Parameter checking */
4848 if (hotkey_report_mode
> 2)
4851 /* Driver-level probe */
4853 get_thinkpad_model_data(&thinkpad_id
);
4854 ret
= probe_for_thinkpad();
4856 thinkpad_acpi_module_exit();
4860 /* Driver initialization */
4862 IBM_ACPIHANDLE_INIT(ecrd
);
4863 IBM_ACPIHANDLE_INIT(ecwr
);
4865 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
4867 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
4868 thinkpad_acpi_module_exit();
4871 proc_dir
->owner
= THIS_MODULE
;
4873 ret
= platform_driver_register(&tpacpi_pdriver
);
4875 printk(IBM_ERR
"unable to register main platform driver\n");
4876 thinkpad_acpi_module_exit();
4879 tp_features
.platform_drv_registered
= 1;
4881 ret
= platform_driver_register(&tpacpi_hwmon_pdriver
);
4883 printk(IBM_ERR
"unable to register hwmon platform driver\n");
4884 thinkpad_acpi_module_exit();
4887 tp_features
.sensors_pdrv_registered
= 1;
4889 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
4891 tp_features
.platform_drv_attrs_registered
= 1;
4892 ret
= tpacpi_create_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
4895 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
4896 thinkpad_acpi_module_exit();
4899 tp_features
.sensors_pdrv_attrs_registered
= 1;
4902 /* Device initialization */
4903 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
4905 if (IS_ERR(tpacpi_pdev
)) {
4906 ret
= PTR_ERR(tpacpi_pdev
);
4908 printk(IBM_ERR
"unable to register platform device\n");
4909 thinkpad_acpi_module_exit();
4912 tpacpi_sensors_pdev
= platform_device_register_simple(
4913 IBM_HWMON_DRVR_NAME
,
4915 if (IS_ERR(tpacpi_sensors_pdev
)) {
4916 ret
= PTR_ERR(tpacpi_sensors_pdev
);
4917 tpacpi_sensors_pdev
= NULL
;
4918 printk(IBM_ERR
"unable to register hwmon platform device\n");
4919 thinkpad_acpi_module_exit();
4922 ret
= device_create_file(&tpacpi_sensors_pdev
->dev
,
4923 &dev_attr_thinkpad_acpi_pdev_name
);
4926 "unable to create sysfs hwmon device attributes\n");
4927 thinkpad_acpi_module_exit();
4930 tp_features
.sensors_pdev_attrs_registered
= 1;
4931 tpacpi_hwmon
= hwmon_device_register(&tpacpi_sensors_pdev
->dev
);
4932 if (IS_ERR(tpacpi_hwmon
)) {
4933 ret
= PTR_ERR(tpacpi_hwmon
);
4934 tpacpi_hwmon
= NULL
;
4935 printk(IBM_ERR
"unable to register hwmon device\n");
4936 thinkpad_acpi_module_exit();
4939 mutex_init(&tpacpi_inputdev_send_mutex
);
4940 tpacpi_inputdev
= input_allocate_device();
4941 if (!tpacpi_inputdev
) {
4942 printk(IBM_ERR
"unable to allocate input device\n");
4943 thinkpad_acpi_module_exit();
4946 /* Prepare input device, but don't register */
4947 tpacpi_inputdev
->name
= "ThinkPad Extra Buttons";
4948 tpacpi_inputdev
->phys
= IBM_DRVR_NAME
"/input0";
4949 tpacpi_inputdev
->id
.bustype
= BUS_HOST
;
4950 tpacpi_inputdev
->id
.vendor
= (thinkpad_id
.vendor
) ?
4951 thinkpad_id
.vendor
:
4953 tpacpi_inputdev
->id
.product
= TPACPI_HKEY_INPUT_PRODUCT
;
4954 tpacpi_inputdev
->id
.version
= TPACPI_HKEY_INPUT_VERSION
;
4956 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
4957 ret
= ibm_init(&ibms_init
[i
]);
4958 if (ret
>= 0 && *ibms_init
[i
].param
)
4959 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
4961 thinkpad_acpi_module_exit();
4965 ret
= input_register_device(tpacpi_inputdev
);
4967 printk(IBM_ERR
"unable to register input device\n");
4968 thinkpad_acpi_module_exit();
4971 tp_features
.input_device_registered
= 1;
4974 tpacpi_lifecycle
= TPACPI_LIFE_RUNNING
;
4978 static void thinkpad_acpi_module_exit(void)
4980 struct ibm_struct
*ibm
, *itmp
;
4982 tpacpi_lifecycle
= TPACPI_LIFE_EXITING
;
4984 list_for_each_entry_safe_reverse(ibm
, itmp
,
4985 &tpacpi_all_drivers
,
4990 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
4992 if (tpacpi_inputdev
) {
4993 if (tp_features
.input_device_registered
)
4994 input_unregister_device(tpacpi_inputdev
);
4996 input_free_device(tpacpi_inputdev
);
5000 hwmon_device_unregister(tpacpi_hwmon
);
5002 if (tp_features
.sensors_pdev_attrs_registered
)
5003 device_remove_file(&tpacpi_sensors_pdev
->dev
,
5004 &dev_attr_thinkpad_acpi_pdev_name
);
5005 if (tpacpi_sensors_pdev
)
5006 platform_device_unregister(tpacpi_sensors_pdev
);
5008 platform_device_unregister(tpacpi_pdev
);
5010 if (tp_features
.sensors_pdrv_attrs_registered
)
5011 tpacpi_remove_driver_attributes(&tpacpi_hwmon_pdriver
.driver
);
5012 if (tp_features
.platform_drv_attrs_registered
)
5013 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
5015 if (tp_features
.sensors_pdrv_registered
)
5016 platform_driver_unregister(&tpacpi_hwmon_pdriver
);
5018 if (tp_features
.platform_drv_registered
)
5019 platform_driver_unregister(&tpacpi_pdriver
);
5022 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
5024 kfree(thinkpad_id
.bios_version_str
);
5025 kfree(thinkpad_id
.ec_version_str
);
5026 kfree(thinkpad_id
.model_str
);
5029 module_init(thinkpad_acpi_module_init
);
5030 module_exit(thinkpad_acpi_module_exit
);