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.14"
25 #define TPACPI_SYSFS_VERSION 0x000100
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");
95 #define __unused __attribute__ ((unused))
97 /****************************************************************************
98 ****************************************************************************
100 * ACPI Helpers and device model
102 ****************************************************************************
103 ****************************************************************************/
105 /*************************************************************************
109 static acpi_handle root_handle
= NULL
;
111 #define IBM_HANDLE(object, parent, paths...) \
112 static acpi_handle object##_handle; \
113 static acpi_handle *object##_parent = &parent##_handle; \
114 static char *object##_path; \
115 static char *object##_paths[] = { paths }
117 IBM_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
118 "\\_SB.PCI.ISA.EC", /* 570 */
119 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
120 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
121 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
122 "\\_SB.PCI0.ICH3.EC0", /* R31 */
123 "\\_SB.PCI0.LPC.EC", /* all others */
126 IBM_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
127 IBM_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
130 /*************************************************************************
134 IBM_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
135 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
136 "\\CMS", /* R40, R40e */
139 IBM_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
140 "^HKEY", /* R30, R31 */
141 "HKEY", /* all others */
145 /*************************************************************************
149 static int acpi_evalf(acpi_handle handle
,
150 void *res
, char *method
, char *fmt
, ...)
153 struct acpi_object_list params
;
154 union acpi_object in_objs
[IBM_MAX_ACPI_ARGS
];
155 struct acpi_buffer result
, *resultp
;
156 union acpi_object out_obj
;
164 printk(IBM_ERR
"acpi_evalf() called with empty format\n");
177 params
.pointer
= &in_objs
[0];
184 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
185 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
187 /* add more types as needed */
189 printk(IBM_ERR
"acpi_evalf() called "
190 "with invalid format character '%c'\n", c
);
196 if (res_type
!= 'v') {
197 result
.length
= sizeof(out_obj
);
198 result
.pointer
= &out_obj
;
203 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
208 *(int *)res
= out_obj
.integer
.value
;
209 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
212 success
= status
== AE_OK
;
214 /* add more types as needed */
216 printk(IBM_ERR
"acpi_evalf() called "
217 "with invalid format character '%c'\n", res_type
);
221 if (!success
&& !quiet
)
222 printk(IBM_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
223 method
, fmt0
, status
);
228 static void __unused
acpi_print_int(acpi_handle handle
, char *method
)
232 if (acpi_evalf(handle
, &i
, method
, "d"))
233 printk(IBM_INFO
"%s = 0x%x\n", method
, i
);
235 printk(IBM_ERR
"error calling %s\n", method
);
238 static int acpi_ec_read(int i
, u8
* p
)
243 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
247 if (ec_read(i
, p
) < 0)
254 static int acpi_ec_write(int i
, u8 v
)
257 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
260 if (ec_write(i
, v
) < 0)
267 static int _sta(acpi_handle handle
)
271 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
277 static int issue_thinkpad_cmos_command(int cmos_cmd
)
282 if (!acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
))
288 /*************************************************************************
292 static void drv_acpi_handle_init(char *name
,
293 acpi_handle
*handle
, acpi_handle parent
,
294 char **paths
, int num_paths
, char **path
)
299 for (i
= 0; i
< num_paths
; i
++) {
300 status
= acpi_get_handle(parent
, paths
[i
], handle
);
301 if (ACPI_SUCCESS(status
)) {
310 static void dispatch_acpi_notify(acpi_handle handle
, u32 event
, void *data
)
312 struct ibm_struct
*ibm
= data
;
314 if (!ibm
|| !ibm
->acpi
|| !ibm
->acpi
->notify
)
317 ibm
->acpi
->notify(ibm
, event
);
320 static int __init
setup_acpi_notify(struct ibm_struct
*ibm
)
327 if (!*ibm
->acpi
->handle
)
330 dbg_printk(TPACPI_DBG_INIT
,
331 "setting up ACPI notify for %s\n", ibm
->name
);
333 ret
= acpi_bus_get_device(*ibm
->acpi
->handle
, &ibm
->acpi
->device
);
335 printk(IBM_ERR
"%s device not present\n", ibm
->name
);
339 acpi_driver_data(ibm
->acpi
->device
) = ibm
;
340 sprintf(acpi_device_class(ibm
->acpi
->device
), "%s/%s",
341 IBM_ACPI_EVENT_PREFIX
,
344 status
= acpi_install_notify_handler(*ibm
->acpi
->handle
,
345 ibm
->acpi
->type
, dispatch_acpi_notify
, ibm
);
346 if (ACPI_FAILURE(status
)) {
347 if (status
== AE_ALREADY_EXISTS
) {
348 printk(IBM_NOTICE
"another device driver is already handling %s events\n",
351 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
356 ibm
->flags
.acpi_notify_installed
= 1;
360 static int __init
tpacpi_device_add(struct acpi_device
*device
)
365 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
369 dbg_printk(TPACPI_DBG_INIT
,
370 "registering %s as an ACPI driver\n", ibm
->name
);
374 ibm
->acpi
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
375 if (!ibm
->acpi
->driver
) {
376 printk(IBM_ERR
"kzalloc(ibm->driver) failed\n");
380 sprintf(ibm
->acpi
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
381 ibm
->acpi
->driver
->ids
= ibm
->acpi
->hid
;
382 ibm
->acpi
->driver
->ops
.add
= &tpacpi_device_add
;
384 ret
= acpi_bus_register_driver(ibm
->acpi
->driver
);
386 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
387 ibm
->acpi
->hid
, ret
);
388 kfree(ibm
->acpi
->driver
);
389 ibm
->acpi
->driver
= NULL
;
391 ibm
->flags
.acpi_driver_registered
= 1;
397 /****************************************************************************
398 ****************************************************************************
402 ****************************************************************************
403 ****************************************************************************/
405 static int dispatch_procfs_read(char *page
, char **start
, off_t off
,
406 int count
, int *eof
, void *data
)
408 struct ibm_struct
*ibm
= data
;
411 if (!ibm
|| !ibm
->read
)
414 len
= ibm
->read(page
);
418 if (len
<= off
+ count
)
430 static int dispatch_procfs_write(struct file
*file
,
431 const char __user
* userbuf
,
432 unsigned long count
, void *data
)
434 struct ibm_struct
*ibm
= data
;
438 if (!ibm
|| !ibm
->write
)
441 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
445 if (copy_from_user(kernbuf
, userbuf
, count
)) {
451 strcat(kernbuf
, ",");
452 ret
= ibm
->write(kernbuf
);
461 static char *next_cmd(char **cmds
)
466 while ((end
= strchr(start
, ',')) && end
== start
)
478 /****************************************************************************
479 ****************************************************************************
481 * Device model: hwmon and platform
483 ****************************************************************************
484 ****************************************************************************/
486 static struct platform_device
*tpacpi_pdev
= NULL
;
487 static struct class_device
*tpacpi_hwmon
= NULL
;
489 static struct platform_driver tpacpi_pdriver
= {
491 .name
= IBM_DRVR_NAME
,
492 .owner
= THIS_MODULE
,
497 /*************************************************************************
498 * thinkpad-acpi driver attributes
501 /* interface_version --------------------------------------------------- */
502 static ssize_t
tpacpi_driver_interface_version_show(
503 struct device_driver
*drv
,
506 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", TPACPI_SYSFS_VERSION
);
509 static DRIVER_ATTR(interface_version
, S_IRUGO
,
510 tpacpi_driver_interface_version_show
, NULL
);
512 /* debug_level --------------------------------------------------------- */
513 static ssize_t
tpacpi_driver_debug_show(struct device_driver
*drv
,
516 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n", dbg_level
);
519 static ssize_t
tpacpi_driver_debug_store(struct device_driver
*drv
,
520 const char *buf
, size_t count
)
524 if (parse_strtoul(buf
, 0xffff, &t
))
532 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
533 tpacpi_driver_debug_show
, tpacpi_driver_debug_store
);
535 /* version ------------------------------------------------------------- */
536 static ssize_t
tpacpi_driver_version_show(struct device_driver
*drv
,
539 return snprintf(buf
, PAGE_SIZE
, "%s v%s\n", IBM_DESC
, IBM_VERSION
);
542 static DRIVER_ATTR(version
, S_IRUGO
,
543 tpacpi_driver_version_show
, NULL
);
545 /* --------------------------------------------------------------------- */
547 static struct driver_attribute
* tpacpi_driver_attributes
[] = {
548 &driver_attr_debug_level
, &driver_attr_version
,
549 &driver_attr_interface_version
,
552 static int __init
tpacpi_create_driver_attributes(struct device_driver
*drv
)
558 while (!res
&& i
< ARRAY_SIZE(tpacpi_driver_attributes
)) {
559 res
= driver_create_file(drv
, tpacpi_driver_attributes
[i
]);
566 static void tpacpi_remove_driver_attributes(struct device_driver
*drv
)
570 for(i
= 0; i
< ARRAY_SIZE(tpacpi_driver_attributes
); i
++)
571 driver_remove_file(drv
, tpacpi_driver_attributes
[i
]);
574 /*************************************************************************
575 * sysfs support helpers
578 struct attribute_set_obj
{
579 struct attribute_set s
;
581 } __attribute__((packed
));
583 static struct attribute_set
*create_attr_set(unsigned int max_members
,
586 struct attribute_set_obj
*sobj
;
588 if (max_members
== 0)
591 /* Allocates space for implicit NULL at the end too */
592 sobj
= kzalloc(sizeof(struct attribute_set_obj
) +
593 max_members
* sizeof(struct attribute
*),
597 sobj
->s
.max_members
= max_members
;
598 sobj
->s
.group
.attrs
= &sobj
->a
;
599 sobj
->s
.group
.name
= name
;
604 /* not multi-threaded safe, use it in a single thread per set */
605 static int add_to_attr_set(struct attribute_set
* s
, struct attribute
*attr
)
610 if (s
->members
>= s
->max_members
)
613 s
->group
.attrs
[s
->members
] = attr
;
619 static int add_many_to_attr_set(struct attribute_set
* s
,
620 struct attribute
**attr
,
625 for (i
= 0; i
< count
; i
++) {
626 res
= add_to_attr_set(s
, attr
[i
]);
634 static void delete_attr_set(struct attribute_set
* s
, struct kobject
*kobj
)
636 sysfs_remove_group(kobj
, &s
->group
);
640 static int parse_strtoul(const char *buf
,
641 unsigned long max
, unsigned long *value
)
645 *value
= simple_strtoul(buf
, &endp
, 0);
646 while (*endp
&& isspace(*endp
))
648 if (*endp
|| *value
> max
)
654 /****************************************************************************
655 ****************************************************************************
659 ****************************************************************************
660 ****************************************************************************/
662 /*************************************************************************
663 * thinkpad-acpi init subdriver
666 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
668 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
669 printk(IBM_INFO
"%s\n", IBM_URL
);
671 if (ibm_thinkpad_ec_found
)
672 printk(IBM_INFO
"ThinkPad EC firmware %s\n",
673 ibm_thinkpad_ec_found
);
678 static int thinkpad_acpi_driver_read(char *p
)
682 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
683 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
688 static struct ibm_struct thinkpad_acpi_driver_data
= {
690 .read
= thinkpad_acpi_driver_read
,
693 /*************************************************************************
697 static int hotkey_orig_status
;
698 static int hotkey_orig_mask
;
700 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
704 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
706 IBM_ACPIHANDLE_INIT(hkey
);
708 /* hotkey not supported on 570 */
709 tp_features
.hotkey
= hkey_handle
!= NULL
;
711 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
712 str_supported(tp_features
.hotkey
));
714 if (tp_features
.hotkey
) {
715 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
716 A30, R30, R31, T20-22, X20-21, X22-24 */
717 tp_features
.hotkey_mask
=
718 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
720 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
721 str_supported(tp_features
.hotkey_mask
));
723 res
= hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
);
728 return (tp_features
.hotkey
)? 0 : 1;
731 static void hotkey_exit(void)
735 if (tp_features
.hotkey
) {
736 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
737 res
= hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
739 printk(IBM_ERR
"failed to restore hotkey to BIOS defaults\n");
743 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
747 if (acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d"))
748 acpi_bus_generate_event(ibm
->acpi
->device
, event
, hkey
);
750 printk(IBM_ERR
"unknown hotkey event %d\n", event
);
751 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
755 static int hotkey_get(int *status
, int *mask
)
757 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
760 if (tp_features
.hotkey_mask
)
761 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
767 static int hotkey_set(int status
, int mask
)
771 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
774 if (tp_features
.hotkey_mask
)
775 for (i
= 0; i
< 32; i
++) {
776 int bit
= ((1 << i
) & mask
) != 0;
777 if (!acpi_evalf(hkey_handle
,
778 NULL
, "MHKM", "vdd", i
+ 1, bit
))
785 static int hotkey_read(char *p
)
787 int res
, status
, mask
;
790 if (!tp_features
.hotkey
) {
791 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
795 res
= hotkey_get(&status
, &mask
);
799 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
800 if (tp_features
.hotkey_mask
) {
801 len
+= sprintf(p
+ len
, "mask:\t\t0x%04x\n", mask
);
802 len
+= sprintf(p
+ len
,
803 "commands:\tenable, disable, reset, <mask>\n");
805 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
806 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
812 static int hotkey_write(char *buf
)
814 int res
, status
, mask
;
818 if (!tp_features
.hotkey
)
821 res
= hotkey_get(&status
, &mask
);
825 while ((cmd
= next_cmd(&buf
))) {
826 if (strlencmp(cmd
, "enable") == 0) {
828 } else if (strlencmp(cmd
, "disable") == 0) {
830 } else if (strlencmp(cmd
, "reset") == 0) {
831 status
= hotkey_orig_status
;
832 mask
= hotkey_orig_mask
;
833 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
835 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
843 res
= hotkey_set(status
, mask
);
851 static struct tp_acpi_drv_struct ibm_hotkey_acpidriver
= {
853 .notify
= hotkey_notify
,
854 .handle
= &hkey_handle
,
855 .type
= ACPI_DEVICE_NOTIFY
,
858 static struct ibm_struct hotkey_driver_data
= {
861 .write
= hotkey_write
,
863 .acpi
= &ibm_hotkey_acpidriver
,
866 /*************************************************************************
867 * Bluetooth subdriver
870 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
874 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
876 IBM_ACPIHANDLE_INIT(hkey
);
878 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
879 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
880 tp_features
.bluetooth
= hkey_handle
&&
881 acpi_evalf(hkey_handle
, &status
, "GBDC", "qd");
883 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s, status 0x%02x\n",
884 str_supported(tp_features
.bluetooth
),
887 if (tp_features
.bluetooth
&&
888 !(status
& TP_ACPI_BLUETOOTH_HWPRESENT
)) {
889 /* no bluetooth hardware present in system */
890 tp_features
.bluetooth
= 0;
891 dbg_printk(TPACPI_DBG_INIT
,
892 "bluetooth hardware not installed\n");
895 return (tp_features
.bluetooth
)? 0 : 1;
898 static int bluetooth_get_radiosw(void)
902 if (!tp_features
.bluetooth
)
905 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
908 return ((status
& TP_ACPI_BLUETOOTH_RADIOSSW
) != 0);
911 static int bluetooth_set_radiosw(int radio_on
)
915 if (!tp_features
.bluetooth
)
918 if (!acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
921 status
|= TP_ACPI_BLUETOOTH_RADIOSSW
;
923 status
&= ~TP_ACPI_BLUETOOTH_RADIOSSW
;
924 if (!acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
930 static int bluetooth_read(char *p
)
933 int status
= bluetooth_get_radiosw();
935 if (!tp_features
.bluetooth
)
936 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
938 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
939 (status
)? "enabled" : "disabled");
940 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
946 static int bluetooth_write(char *buf
)
950 if (!tp_features
.bluetooth
)
953 while ((cmd
= next_cmd(&buf
))) {
954 if (strlencmp(cmd
, "enable") == 0) {
955 bluetooth_set_radiosw(1);
956 } else if (strlencmp(cmd
, "disable") == 0) {
957 bluetooth_set_radiosw(0);
965 static struct ibm_struct bluetooth_driver_data
= {
967 .read
= bluetooth_read
,
968 .write
= bluetooth_write
,
971 /*************************************************************************
975 static int __init
wan_init(struct ibm_init_struct
*iibm
)
979 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
981 IBM_ACPIHANDLE_INIT(hkey
);
983 tp_features
.wan
= hkey_handle
&&
984 acpi_evalf(hkey_handle
, &status
, "GWAN", "qd");
986 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s, status 0x%02x\n",
987 str_supported(tp_features
.wan
),
990 if (tp_features
.wan
&&
991 !(status
& TP_ACPI_WANCARD_HWPRESENT
)) {
992 /* no wan hardware present in system */
994 dbg_printk(TPACPI_DBG_INIT
,
995 "wan hardware not installed\n");
998 return (tp_features
.wan
)? 0 : 1;
1001 static int wan_get_radiosw(void)
1005 if (!tp_features
.wan
)
1008 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1011 return ((status
& TP_ACPI_WANCARD_RADIOSSW
) != 0);
1014 static int wan_set_radiosw(int radio_on
)
1018 if (!tp_features
.wan
)
1021 if (!acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
1024 status
|= TP_ACPI_WANCARD_RADIOSSW
;
1026 status
&= ~TP_ACPI_WANCARD_RADIOSSW
;
1027 if (!acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
1033 static int wan_read(char *p
)
1036 int status
= wan_get_radiosw();
1038 if (!tp_features
.wan
)
1039 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1041 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1042 (status
)? "enabled" : "disabled");
1043 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1049 static int wan_write(char *buf
)
1053 if (!tp_features
.wan
)
1056 while ((cmd
= next_cmd(&buf
))) {
1057 if (strlencmp(cmd
, "enable") == 0) {
1059 } else if (strlencmp(cmd
, "disable") == 0) {
1068 static struct ibm_struct wan_driver_data
= {
1072 .flags
.experimental
= 1,
1075 /*************************************************************************
1079 static enum video_access_mode video_supported
;
1080 static int video_orig_autosw
;
1082 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
1083 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
1084 "\\_SB.PCI0.VID0", /* 770e */
1085 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
1086 "\\_SB.PCI0.AGP.VID", /* all others */
1089 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
1091 static int __init
video_init(struct ibm_init_struct
*iibm
)
1095 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
1097 IBM_ACPIHANDLE_INIT(vid
);
1098 IBM_ACPIHANDLE_INIT(vid2
);
1100 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
1101 /* G41, assume IVGA doesn't change */
1102 vid_handle
= vid2_handle
;
1105 /* video switching not supported on R30, R31 */
1106 video_supported
= TPACPI_VIDEO_NONE
;
1107 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
1109 video_supported
= TPACPI_VIDEO_570
;
1110 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
1111 /* 600e/x, 770e, 770x */
1112 video_supported
= TPACPI_VIDEO_770
;
1115 video_supported
= TPACPI_VIDEO_NEW
;
1117 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
1118 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
1121 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
1124 static void video_exit(void)
1126 dbg_printk(TPACPI_DBG_EXIT
,
1127 "restoring original video autoswitch mode\n");
1128 if (video_autosw_set(video_orig_autosw
))
1129 printk(IBM_ERR
"error while trying to restore original "
1130 "video autoswitch mode\n");
1133 static int video_outputsw_get(void)
1138 switch (video_supported
) {
1139 case TPACPI_VIDEO_570
:
1140 if (!acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd",
1141 TP_ACPI_VIDEO_570_PHSCMD
))
1143 status
= i
& TP_ACPI_VIDEO_570_PHSMASK
;
1145 case TPACPI_VIDEO_770
:
1146 if (!acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1149 status
|= TP_ACPI_VIDEO_S_LCD
;
1150 if (!acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1153 status
|= TP_ACPI_VIDEO_S_CRT
;
1155 case TPACPI_VIDEO_NEW
:
1156 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1) ||
1157 !acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
1160 status
|= TP_ACPI_VIDEO_S_CRT
;
1162 if (!acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0) ||
1163 !acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
1166 status
|= TP_ACPI_VIDEO_S_LCD
;
1167 if (!acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
1170 status
|= TP_ACPI_VIDEO_S_DVI
;
1179 static int video_outputsw_set(int status
)
1184 switch (video_supported
) {
1185 case TPACPI_VIDEO_570
:
1186 res
= acpi_evalf(NULL
, NULL
,
1187 "\\_SB.PHS2", "vdd",
1188 TP_ACPI_VIDEO_570_PHS2CMD
,
1189 status
| TP_ACPI_VIDEO_570_PHS2SET
);
1191 case TPACPI_VIDEO_770
:
1192 autosw
= video_autosw_get();
1196 res
= video_autosw_set(1);
1199 res
= acpi_evalf(vid_handle
, NULL
,
1200 "ASWT", "vdd", status
* 0x100, 0);
1201 if (!autosw
&& video_autosw_set(autosw
)) {
1202 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1206 case TPACPI_VIDEO_NEW
:
1207 res
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
1208 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
1214 return (res
)? 0 : -EIO
;
1217 static int video_autosw_get(void)
1221 switch (video_supported
) {
1222 case TPACPI_VIDEO_570
:
1223 if (!acpi_evalf(vid_handle
, &autosw
, "SWIT", "d"))
1226 case TPACPI_VIDEO_770
:
1227 case TPACPI_VIDEO_NEW
:
1228 if (!acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d"))
1238 static int video_autosw_set(int enable
)
1240 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", (enable
)? 1 : 0))
1245 static int video_outputsw_cycle(void)
1247 int autosw
= video_autosw_get();
1253 switch (video_supported
) {
1254 case TPACPI_VIDEO_570
:
1255 res
= video_autosw_set(1);
1258 res
= acpi_evalf(ec_handle
, NULL
, "_Q16", "v");
1260 case TPACPI_VIDEO_770
:
1261 case TPACPI_VIDEO_NEW
:
1262 res
= video_autosw_set(1);
1265 res
= acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
1270 if (!autosw
&& video_autosw_set(autosw
)) {
1271 printk(IBM_ERR
"video auto-switch left enabled due to error\n");
1275 return (res
)? 0 : -EIO
;
1278 static int video_expand_toggle(void)
1280 switch (video_supported
) {
1281 case TPACPI_VIDEO_570
:
1282 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v")?
1284 case TPACPI_VIDEO_770
:
1285 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v")?
1287 case TPACPI_VIDEO_NEW
:
1288 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v")?
1296 static int video_read(char *p
)
1301 if (video_supported
== TPACPI_VIDEO_NONE
) {
1302 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1306 status
= video_outputsw_get();
1310 autosw
= video_autosw_get();
1314 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1315 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
1316 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
1317 if (video_supported
== TPACPI_VIDEO_NEW
)
1318 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
1319 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
1320 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
1321 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
1322 if (video_supported
== TPACPI_VIDEO_NEW
)
1323 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
1324 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
1325 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
1330 static int video_write(char *buf
)
1333 int enable
, disable
, status
;
1336 if (video_supported
== TPACPI_VIDEO_NONE
)
1342 while ((cmd
= next_cmd(&buf
))) {
1343 if (strlencmp(cmd
, "lcd_enable") == 0) {
1344 enable
|= TP_ACPI_VIDEO_S_LCD
;
1345 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
1346 disable
|= TP_ACPI_VIDEO_S_LCD
;
1347 } else if (strlencmp(cmd
, "crt_enable") == 0) {
1348 enable
|= TP_ACPI_VIDEO_S_CRT
;
1349 } else if (strlencmp(cmd
, "crt_disable") == 0) {
1350 disable
|= TP_ACPI_VIDEO_S_CRT
;
1351 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1352 strlencmp(cmd
, "dvi_enable") == 0) {
1353 enable
|= TP_ACPI_VIDEO_S_DVI
;
1354 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1355 strlencmp(cmd
, "dvi_disable") == 0) {
1356 disable
|= TP_ACPI_VIDEO_S_DVI
;
1357 } else if (strlencmp(cmd
, "auto_enable") == 0) {
1358 res
= video_autosw_set(1);
1361 } else if (strlencmp(cmd
, "auto_disable") == 0) {
1362 res
= video_autosw_set(0);
1365 } else if (strlencmp(cmd
, "video_switch") == 0) {
1366 res
= video_outputsw_cycle();
1369 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
1370 res
= video_expand_toggle();
1377 if (enable
|| disable
) {
1378 status
= video_outputsw_get();
1381 res
= video_outputsw_set((status
& ~disable
) | enable
);
1389 static struct ibm_struct video_driver_data
= {
1392 .write
= video_write
,
1396 /*************************************************************************
1397 * Light (thinklight) subdriver
1400 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1401 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
1403 static int __init
light_init(struct ibm_init_struct
*iibm
)
1405 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
1407 IBM_ACPIHANDLE_INIT(ledb
);
1408 IBM_ACPIHANDLE_INIT(lght
);
1409 IBM_ACPIHANDLE_INIT(cmos
);
1411 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1412 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
1414 if (tp_features
.light
)
1415 /* light status not supported on
1416 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1417 tp_features
.light_status
=
1418 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
1420 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
1421 str_supported(tp_features
.light
));
1423 return (tp_features
.light
)? 0 : 1;
1426 static int light_read(char *p
)
1431 if (!tp_features
.light
) {
1432 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1433 } else if (!tp_features
.light_status
) {
1434 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
1435 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1437 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
1439 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
1440 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1446 static int light_write(char *buf
)
1448 int cmos_cmd
, lght_cmd
;
1452 if (!tp_features
.light
)
1455 while ((cmd
= next_cmd(&buf
))) {
1456 if (strlencmp(cmd
, "on") == 0) {
1459 } else if (strlencmp(cmd
, "off") == 0) {
1465 success
= cmos_handle
?
1466 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
1467 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
1475 static struct ibm_struct light_driver_data
= {
1478 .write
= light_write
,
1481 /*************************************************************************
1485 #ifdef CONFIG_THINKPAD_ACPI_DOCK
1487 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
1488 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
1489 "\\_SB.PCI0.PCI1.DOCK", /* all others */
1490 "\\_SB.PCI.ISA.SLCE", /* 570 */
1491 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
1493 /* don't list other alternatives as we install a notify handler on the 570 */
1494 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
1496 #define dock_docked() (_sta(dock_handle) & 1)
1498 static int __init
dock_init(struct ibm_init_struct
*iibm
)
1500 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
1502 IBM_ACPIHANDLE_INIT(dock
);
1503 IBM_ACPIHANDLE_INIT(pci
);
1505 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
1506 str_supported(dock_handle
!= NULL
));
1508 return (dock_handle
)? 0 : 1;
1511 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
1513 int docked
= dock_docked();
1514 int pci
= ibm
->acpi
->hid
&& strstr(ibm
->acpi
->hid
, IBM_PCI_HID
);
1516 if (event
== 1 && !pci
) /* 570 */
1517 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
1518 else if (event
== 1 && pci
) /* 570 */
1519 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
1520 else if (event
== 3 && docked
)
1521 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 1); /* button */
1522 else if (event
== 3 && !docked
)
1523 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 2); /* undock */
1524 else if (event
== 0 && docked
)
1525 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 3); /* dock */
1527 printk(IBM_ERR
"unknown dock event %d, status %d\n",
1528 event
, _sta(dock_handle
));
1529 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0); /* unknown */
1533 static int dock_read(char *p
)
1536 int docked
= dock_docked();
1539 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1541 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
1543 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
1544 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
1550 static int dock_write(char *buf
)
1557 while ((cmd
= next_cmd(&buf
))) {
1558 if (strlencmp(cmd
, "undock") == 0) {
1559 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
1560 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
1562 } else if (strlencmp(cmd
, "dock") == 0) {
1563 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
1572 static struct tp_acpi_drv_struct ibm_dock_acpidriver
[2] = {
1574 .notify
= dock_notify
,
1575 .handle
= &dock_handle
,
1576 .type
= ACPI_SYSTEM_NOTIFY
,
1580 .notify
= dock_notify
,
1581 .handle
= &pci_handle
,
1582 .type
= ACPI_SYSTEM_NOTIFY
,
1586 static struct ibm_struct dock_driver_data
[2] = {
1590 .write
= dock_write
,
1591 .acpi
= &ibm_dock_acpidriver
[0],
1595 .acpi
= &ibm_dock_acpidriver
[1],
1599 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
1601 /*************************************************************************
1605 #ifdef CONFIG_THINKPAD_ACPI_BAY
1606 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
1607 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
1608 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
1609 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
1610 ); /* A21e, R30, R31 */
1611 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
1612 "_EJ0", /* all others */
1613 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
1614 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
1615 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
1617 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
1621 static int __init
bay_init(struct ibm_init_struct
*iibm
)
1623 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
1625 IBM_ACPIHANDLE_INIT(bay
);
1627 IBM_ACPIHANDLE_INIT(bay_ej
);
1628 IBM_ACPIHANDLE_INIT(bay2
);
1630 IBM_ACPIHANDLE_INIT(bay2_ej
);
1632 tp_features
.bay_status
= bay_handle
&&
1633 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
1634 tp_features
.bay_status2
= bay2_handle
&&
1635 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
1637 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
1638 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
1639 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
1640 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
1642 vdbg_printk(TPACPI_DBG_INIT
,
1643 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
1644 str_supported(tp_features
.bay_status
),
1645 str_supported(tp_features
.bay_eject
),
1646 str_supported(tp_features
.bay_status2
),
1647 str_supported(tp_features
.bay_eject2
));
1649 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
1650 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
1653 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
1655 acpi_bus_generate_event(ibm
->acpi
->device
, event
, 0);
1658 #define bay_occupied(b) (_sta(b##_handle) & 1)
1660 static int bay_read(char *p
)
1663 int occupied
= bay_occupied(bay
);
1664 int occupied2
= bay_occupied(bay2
);
1667 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1668 tp_features
.bay_status
?
1669 (occupied
? "occupied" : "unoccupied") :
1671 if (tp_features
.bay_status2
)
1672 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
1673 "occupied" : "unoccupied");
1675 eject
= tp_features
.bay_eject
&& occupied
;
1676 eject2
= tp_features
.bay_eject2
&& occupied2
;
1678 if (eject
&& eject2
)
1679 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
1681 len
+= sprintf(p
+ len
, "commands:\teject\n");
1683 len
+= sprintf(p
+ len
, "commands:\teject2\n");
1688 static int bay_write(char *buf
)
1692 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
1695 while ((cmd
= next_cmd(&buf
))) {
1696 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
1697 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
1699 } else if (tp_features
.bay_eject2
&&
1700 strlencmp(cmd
, "eject2") == 0) {
1701 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
1710 static struct tp_acpi_drv_struct ibm_bay_acpidriver
= {
1711 .notify
= bay_notify
,
1712 .handle
= &bay_handle
,
1713 .type
= ACPI_SYSTEM_NOTIFY
,
1716 static struct ibm_struct bay_driver_data
= {
1720 .acpi
= &ibm_bay_acpidriver
,
1723 #endif /* CONFIG_THINKPAD_ACPI_BAY */
1725 /*************************************************************************
1729 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
1731 vdbg_printk(TPACPI_DBG_INIT
,
1732 "initializing cmos commands subdriver\n");
1734 IBM_ACPIHANDLE_INIT(cmos
);
1736 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
1737 str_supported(cmos_handle
!= NULL
));
1738 return (cmos_handle
)? 0 : 1;
1741 static int cmos_read(char *p
)
1745 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1746 R30, R31, T20-22, X20-21 */
1748 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1750 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1751 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
1757 static int cmos_write(char *buf
)
1762 while ((cmd
= next_cmd(&buf
))) {
1763 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
1764 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
1769 res
= issue_thinkpad_cmos_command(cmos_cmd
);
1777 static struct ibm_struct cmos_driver_data
= {
1780 .write
= cmos_write
,
1783 /*************************************************************************
1787 static enum led_access_mode led_supported
;
1789 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
1790 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1791 "LED", /* all others */
1794 static int __init
led_init(struct ibm_init_struct
*iibm
)
1796 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
1798 IBM_ACPIHANDLE_INIT(led
);
1801 /* led not supported on R30, R31 */
1802 led_supported
= TPACPI_LED_NONE
;
1803 else if (strlencmp(led_path
, "SLED") == 0)
1805 led_supported
= TPACPI_LED_570
;
1806 else if (strlencmp(led_path
, "SYSL") == 0)
1807 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1808 led_supported
= TPACPI_LED_OLD
;
1811 led_supported
= TPACPI_LED_NEW
;
1813 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
1814 str_supported(led_supported
), led_supported
);
1816 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
1819 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1821 static int led_read(char *p
)
1825 if (!led_supported
) {
1826 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1829 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1831 if (led_supported
== TPACPI_LED_570
) {
1834 for (i
= 0; i
< 8; i
++) {
1835 if (!acpi_evalf(ec_handle
,
1836 &status
, "GLED", "dd", 1 << i
))
1838 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
1839 i
, led_status(status
));
1843 len
+= sprintf(p
+ len
, "commands:\t"
1844 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
1849 /* off, on, blink */
1850 static const int led_sled_arg1
[] = { 0, 1, 3 };
1851 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
1852 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
1853 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
1855 static int led_write(char *buf
)
1863 while ((cmd
= next_cmd(&buf
))) {
1864 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
1867 if (strstr(cmd
, "off")) {
1869 } else if (strstr(cmd
, "on")) {
1871 } else if (strstr(cmd
, "blink")) {
1876 if (led_supported
== TPACPI_LED_570
) {
1879 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1880 led
, led_sled_arg1
[ind
]))
1882 } else if (led_supported
== TPACPI_LED_OLD
) {
1883 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1885 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
1888 ec_write(TPACPI_LED_EC_HLBL
,
1889 led
* led_exp_hlbl
[ind
]);
1892 ec_write(TPACPI_LED_EC_HLCL
,
1893 led
* led_exp_hlcl
[ind
]);
1898 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1899 led
, led_led_arg1
[ind
]))
1907 static struct ibm_struct led_driver_data
= {
1913 /*************************************************************************
1917 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
1919 static int __init
beep_init(struct ibm_init_struct
*iibm
)
1921 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
1923 IBM_ACPIHANDLE_INIT(beep
);
1925 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
1926 str_supported(beep_handle
!= NULL
));
1928 return (beep_handle
)? 0 : 1;
1931 static int beep_read(char *p
)
1936 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1938 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1939 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
1945 static int beep_write(char *buf
)
1953 while ((cmd
= next_cmd(&buf
))) {
1954 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
1955 beep_cmd
>= 0 && beep_cmd
<= 17) {
1959 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
1966 static struct ibm_struct beep_driver_data
= {
1969 .write
= beep_write
,
1972 /*************************************************************************
1976 static enum thermal_access_mode thermal_read_mode
;
1978 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
1984 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
1986 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
1988 if (ibm_thinkpad_ec_found
&& experimental
) {
1990 * Direct EC access mode: sensors at registers
1991 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
1992 * non-implemented, thermal sensors return 0x80 when
1997 for (i
= 0; i
< 8; i
++) {
1998 if (acpi_ec_read(TP_EC_THERMAL_TMP0
+ i
, &t
)) {
2004 if (acpi_ec_read(TP_EC_THERMAL_TMP8
+ i
, &t
)) {
2012 /* This is sheer paranoia, but we handle it anyway */
2015 "ThinkPad ACPI EC access misbehaving, "
2016 "falling back to ACPI TMPx access mode\n");
2017 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2020 "ThinkPad ACPI EC access misbehaving, "
2021 "disabling thermal sensors access\n");
2022 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2027 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
2029 } else if (acpi_tmp7
) {
2030 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
2031 /* 600e/x, 770e, 770x */
2032 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
2034 /* Standard ACPI TMPx access, max 8 sensors */
2035 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
2038 /* temperatures not supported on 570, G4x, R30, R31, R32 */
2039 thermal_read_mode
= TPACPI_THERMAL_NONE
;
2042 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
2043 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
2046 return (thermal_read_mode
!= TPACPI_THERMAL_NONE
)? 0 : 1;
2049 /* idx is zero-based */
2050 static int thermal_get_sensor(int idx
, s32
*value
)
2056 t
= TP_EC_THERMAL_TMP0
;
2058 switch (thermal_read_mode
) {
2059 #if TPACPI_MAX_THERMAL_SENSORS >= 16
2060 case TPACPI_THERMAL_TPEC_16
:
2061 if (idx
>= 8 && idx
<= 15) {
2062 t
= TP_EC_THERMAL_TMP8
;
2067 case TPACPI_THERMAL_TPEC_8
:
2069 if (!acpi_ec_read(t
+ idx
, &tmp
))
2071 *value
= tmp
* 1000;
2076 case TPACPI_THERMAL_ACPI_UPDT
:
2078 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2079 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
2081 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2083 *value
= (t
- 2732) * 100;
2088 case TPACPI_THERMAL_ACPI_TMP07
:
2090 snprintf(tmpi
, sizeof(tmpi
), "TMP%c", '0' + idx
);
2091 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
2098 case TPACPI_THERMAL_NONE
:
2106 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
2117 if (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
)
2120 for(i
= 0 ; i
< n
; i
++) {
2121 res
= thermal_get_sensor(i
, &s
->temp
[i
]);
2129 static int thermal_read(char *p
)
2133 struct ibm_thermal_sensors_struct t
;
2135 n
= thermal_get_sensors(&t
);
2136 if (unlikely(n
< 0))
2139 len
+= sprintf(p
+ len
, "temperatures:\t");
2142 for (i
= 0; i
< (n
- 1); i
++)
2143 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
2144 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
2146 len
+= sprintf(p
+ len
, "not supported\n");
2151 static struct ibm_struct thermal_driver_data
= {
2153 .read
= thermal_read
,
2156 /*************************************************************************
2160 static u8 ecdump_regs
[256];
2162 static int ecdump_read(char *p
)
2168 len
+= sprintf(p
+ len
, "EC "
2169 " +00 +01 +02 +03 +04 +05 +06 +07"
2170 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
2171 for (i
= 0; i
< 256; i
+= 16) {
2172 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
2173 for (j
= 0; j
< 16; j
++) {
2174 if (!acpi_ec_read(i
+ j
, &v
))
2176 if (v
!= ecdump_regs
[i
+ j
])
2177 len
+= sprintf(p
+ len
, " *%02x", v
);
2179 len
+= sprintf(p
+ len
, " %02x", v
);
2180 ecdump_regs
[i
+ j
] = v
;
2182 len
+= sprintf(p
+ len
, "\n");
2187 /* These are way too dangerous to advertise openly... */
2189 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
2190 " (<offset> is 00-ff, <value> is 00-ff)\n");
2191 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
2192 " (<offset> is 00-ff, <value> is 0-255)\n");
2197 static int ecdump_write(char *buf
)
2202 while ((cmd
= next_cmd(&buf
))) {
2203 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
2205 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
2209 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
2210 if (!acpi_ec_write(i
, v
))
2219 static struct ibm_struct ecdump_driver_data
= {
2221 .read
= ecdump_read
,
2222 .write
= ecdump_write
,
2223 .flags
.experimental
= 1,
2226 /*************************************************************************
2227 * Backlight/brightness subdriver
2230 static struct backlight_device
*ibm_backlight_device
= NULL
;
2232 static struct backlight_properties ibm_backlight_data
= {
2233 .owner
= THIS_MODULE
,
2234 .get_brightness
= brightness_get
,
2235 .update_status
= brightness_update_status
,
2236 .max_brightness
= 7,
2239 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
2243 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
2245 b
= brightness_get(NULL
);
2249 ibm_backlight_device
= backlight_device_register("ibm", NULL
, NULL
,
2250 &ibm_backlight_data
);
2251 if (IS_ERR(ibm_backlight_device
)) {
2252 printk(IBM_ERR
"Could not register backlight device\n");
2253 return PTR_ERR(ibm_backlight_device
);
2255 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
2257 ibm_backlight_device
->props
->brightness
= b
;
2258 brightness_update_status(ibm_backlight_device
);
2263 static void brightness_exit(void)
2265 if (ibm_backlight_device
) {
2266 vdbg_printk(TPACPI_DBG_EXIT
,
2267 "calling backlight_device_unregister()\n");
2268 backlight_device_unregister(ibm_backlight_device
);
2269 ibm_backlight_device
= NULL
;
2273 static int brightness_update_status(struct backlight_device
*bd
)
2275 return brightness_set(
2276 (bd
->props
->fb_blank
== FB_BLANK_UNBLANK
&&
2277 bd
->props
->power
== FB_BLANK_UNBLANK
) ?
2278 bd
->props
->brightness
: 0);
2281 static int brightness_get(struct backlight_device
*bd
)
2284 if (!acpi_ec_read(brightness_offset
, &level
))
2292 static int brightness_set(int value
)
2294 int cmos_cmd
, inc
, i
;
2295 int current_value
= brightness_get(NULL
);
2299 cmos_cmd
= value
> current_value
? TP_CMOS_BRIGHTNESS_UP
: TP_CMOS_BRIGHTNESS_DOWN
;
2300 inc
= value
> current_value
? 1 : -1;
2301 for (i
= current_value
; i
!= value
; i
+= inc
) {
2302 if (issue_thinkpad_cmos_command(cmos_cmd
))
2304 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
2311 static int brightness_read(char *p
)
2316 if ((level
= brightness_get(NULL
)) < 0) {
2317 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
2319 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
2320 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
2321 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
2322 " (<level> is 0-7)\n");
2328 static int brightness_write(char *buf
)
2334 while ((cmd
= next_cmd(&buf
))) {
2335 if ((level
= brightness_get(NULL
)) < 0)
2339 if (strlencmp(cmd
, "up") == 0) {
2340 new_level
= level
== 7 ? 7 : level
+ 1;
2341 } else if (strlencmp(cmd
, "down") == 0) {
2342 new_level
= level
== 0 ? 0 : level
- 1;
2343 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
2344 new_level
>= 0 && new_level
<= 7) {
2349 brightness_set(new_level
);
2355 static struct ibm_struct brightness_driver_data
= {
2356 .name
= "brightness",
2357 .read
= brightness_read
,
2358 .write
= brightness_write
,
2359 .exit
= brightness_exit
,
2362 /*************************************************************************
2366 static int volume_read(char *p
)
2371 if (!acpi_ec_read(volume_offset
, &level
)) {
2372 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
2374 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
2375 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
2376 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
2377 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
2378 " (<level> is 0-15)\n");
2384 static int volume_write(char *buf
)
2386 int cmos_cmd
, inc
, i
;
2388 int new_level
, new_mute
;
2391 while ((cmd
= next_cmd(&buf
))) {
2392 if (!acpi_ec_read(volume_offset
, &level
))
2394 new_mute
= mute
= level
& 0x40;
2395 new_level
= level
= level
& 0xf;
2397 if (strlencmp(cmd
, "up") == 0) {
2401 new_level
= level
== 15 ? 15 : level
+ 1;
2402 } else if (strlencmp(cmd
, "down") == 0) {
2406 new_level
= level
== 0 ? 0 : level
- 1;
2407 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
2408 new_level
>= 0 && new_level
<= 15) {
2410 } else if (strlencmp(cmd
, "mute") == 0) {
2415 if (new_level
!= level
) { /* mute doesn't change */
2416 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
2417 inc
= new_level
> level
? 1 : -1;
2419 if (mute
&& (issue_thinkpad_cmos_command(cmos_cmd
) ||
2420 !acpi_ec_write(volume_offset
, level
)))
2423 for (i
= level
; i
!= new_level
; i
+= inc
)
2424 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
2425 !acpi_ec_write(volume_offset
, i
+ inc
))
2428 if (mute
&& (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE
) ||
2429 !acpi_ec_write(volume_offset
,
2434 if (new_mute
!= mute
) { /* level doesn't change */
2435 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
2437 if (issue_thinkpad_cmos_command(cmos_cmd
) ||
2438 !acpi_ec_write(volume_offset
, level
+ new_mute
))
2446 static struct ibm_struct volume_driver_data
= {
2448 .read
= volume_read
,
2449 .write
= volume_write
,
2452 /*************************************************************************
2459 * TPACPI_FAN_RD_ACPI_GFAN:
2460 * ACPI GFAN method: returns fan level
2462 * see TPACPI_FAN_WR_ACPI_SFAN
2463 * EC 0x2f (HFSP) not available if GFAN exists
2465 * TPACPI_FAN_WR_ACPI_SFAN:
2466 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
2468 * EC 0x2f (HFSP) might be available *for reading*, but do not use
2471 * TPACPI_FAN_WR_TPEC:
2472 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
2473 * Supported on almost all ThinkPads
2475 * Fan speed changes of any sort (including those caused by the
2476 * disengaged mode) are usually done slowly by the firmware as the
2477 * maximum ammount of fan duty cycle change per second seems to be
2480 * Reading is not available if GFAN exists.
2481 * Writing is not available if SFAN exists.
2484 * 7 automatic mode engaged;
2485 * (default operation mode of the ThinkPad)
2486 * fan level is ignored in this mode.
2487 * 6 full speed mode (takes precedence over bit 7);
2488 * not available on all thinkpads. May disable
2489 * the tachometer while the fan controller ramps up
2490 * the speed (which can take up to a few *minutes*).
2491 * Speeds up fan to 100% duty-cycle, which is far above
2492 * the standard RPM levels. It is not impossible that
2493 * it could cause hardware damage.
2494 * 5-3 unused in some models. Extra bits for fan level
2495 * in others, but still useless as all values above
2496 * 7 map to the same speed as level 7 in these models.
2497 * 2-0 fan level (0..7 usually)
2499 * 0x07 = max (set when temperatures critical)
2500 * Some ThinkPads may have other levels, see
2501 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
2503 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
2504 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
2505 * does so, its initial value is meaningless (0x07).
2507 * For firmware bugs, refer to:
2508 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2512 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
2513 * Main fan tachometer reading (in RPM)
2515 * This register is present on all ThinkPads with a new-style EC, and
2516 * it is known not to be present on the A21m/e, and T22, as there is
2517 * something else in offset 0x84 according to the ACPI DSDT. Other
2518 * ThinkPads from this same time period (and earlier) probably lack the
2519 * tachometer as well.
2521 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
2522 * was never fixed by IBM to report the EC firmware version string
2523 * probably support the tachometer (like the early X models), so
2524 * detecting it is quite hard. We need more data to know for sure.
2526 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
2529 * FIRMWARE BUG: may go stale while the EC is switching to full speed
2532 * For firmware bugs, refer to:
2533 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2535 * TPACPI_FAN_WR_ACPI_FANS:
2536 * ThinkPad X31, X40, X41. Not available in the X60.
2538 * FANS ACPI handle: takes three arguments: low speed, medium speed,
2539 * high speed. ACPI DSDT seems to map these three speeds to levels
2540 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
2541 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
2543 * The speeds are stored on handles
2544 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
2546 * There are three default speed sets, acessible as handles:
2547 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
2549 * ACPI DSDT switches which set is in use depending on various
2552 * TPACPI_FAN_WR_TPEC is also available and should be used to
2553 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
2554 * but the ACPI tables just mention level 7.
2557 static enum fan_status_access_mode fan_status_access_mode
;
2558 static enum fan_control_access_mode fan_control_access_mode
;
2559 static enum fan_control_commands fan_control_commands
;
2561 static u8 fan_control_initial_status
;
2563 static void fan_watchdog_fire(struct work_struct
*ignored
);
2564 static int fan_watchdog_maxinterval
;
2565 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
2567 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
2568 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
2569 "\\FSPD", /* 600e/x, 770e, 770x */
2571 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
2572 "JFNS", /* 770x-JL */
2575 static int __init
fan_init(struct ibm_init_struct
*iibm
)
2577 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
2579 fan_status_access_mode
= TPACPI_FAN_NONE
;
2580 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
2581 fan_control_commands
= 0;
2582 fan_watchdog_maxinterval
= 0;
2583 tp_features
.fan_ctrl_status_undef
= 0;
2585 IBM_ACPIHANDLE_INIT(fans
);
2586 IBM_ACPIHANDLE_INIT(gfan
);
2587 IBM_ACPIHANDLE_INIT(sfan
);
2590 /* 570, 600e/x, 770e, 770x */
2591 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
2593 /* all other ThinkPads: note that even old-style
2594 * ThinkPad ECs supports the fan control register */
2595 if (likely(acpi_ec_read(fan_status_offset
,
2596 &fan_control_initial_status
))) {
2597 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
2599 /* In some ThinkPads, neither the EC nor the ACPI
2600 * DSDT initialize the fan status, and it ends up
2601 * being set to 0x07 when it *could* be either
2604 * Enable for TP-1Y (T43), TP-78 (R51e),
2605 * TP-76 (R52), TP-70 (T43, R52), which are known
2607 if (fan_control_initial_status
== 0x07 &&
2608 ibm_thinkpad_ec_found
&&
2609 ((ibm_thinkpad_ec_found
[0] == '1' &&
2610 ibm_thinkpad_ec_found
[1] == 'Y') ||
2611 (ibm_thinkpad_ec_found
[0] == '7' &&
2612 (ibm_thinkpad_ec_found
[1] == '6' ||
2613 ibm_thinkpad_ec_found
[1] == '8' ||
2614 ibm_thinkpad_ec_found
[1] == '0'))
2617 "fan_init: initial fan status is "
2618 "unknown, assuming it is in auto "
2620 tp_features
.fan_ctrl_status_undef
= 1;
2624 "ThinkPad ACPI EC access misbehaving, "
2625 "fan status and control unavailable\n");
2632 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
2633 fan_control_commands
|=
2634 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
2637 /* gfan without sfan means no fan control */
2638 /* all other models implement TP EC 0x2f control */
2642 fan_control_access_mode
=
2643 TPACPI_FAN_WR_ACPI_FANS
;
2644 fan_control_commands
|=
2645 TPACPI_FAN_CMD_SPEED
|
2646 TPACPI_FAN_CMD_LEVEL
|
2647 TPACPI_FAN_CMD_ENABLE
;
2649 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
2650 fan_control_commands
|=
2651 TPACPI_FAN_CMD_LEVEL
|
2652 TPACPI_FAN_CMD_ENABLE
;
2657 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
2658 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
2659 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
2660 fan_status_access_mode
, fan_control_access_mode
);
2662 return (fan_status_access_mode
!= TPACPI_FAN_NONE
||
2663 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
)?
2667 static int fan_get_status(u8
*status
)
2672 * Add TPACPI_FAN_RD_ACPI_FANS ? */
2674 switch (fan_status_access_mode
) {
2675 case TPACPI_FAN_RD_ACPI_GFAN
:
2676 /* 570, 600e/x, 770e, 770x */
2678 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
2686 case TPACPI_FAN_RD_TPEC
:
2687 /* all except 570, 600e/x, 770e, 770x */
2688 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
2703 static void fan_exit(void)
2705 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending fan watchdog tasks\n");
2706 cancel_delayed_work(&fan_watchdog_task
);
2707 flush_scheduled_work();
2710 static int fan_get_speed(unsigned int *speed
)
2714 switch (fan_status_access_mode
) {
2715 case TPACPI_FAN_RD_TPEC
:
2716 /* all except 570, 600e/x, 770e, 770x */
2717 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
2718 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
2722 *speed
= (hi
<< 8) | lo
;
2733 static void fan_watchdog_fire(struct work_struct
*ignored
)
2737 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
2738 rc
= fan_set_enable();
2740 printk(IBM_ERR
"fan watchdog: error %d while enabling fan, "
2741 "will try again later...\n", -rc
);
2742 /* reschedule for later */
2743 fan_watchdog_reset();
2747 static void fan_watchdog_reset(void)
2749 static int fan_watchdog_active
= 0;
2751 if (fan_watchdog_active
)
2752 cancel_delayed_work(&fan_watchdog_task
);
2754 if (fan_watchdog_maxinterval
> 0) {
2755 fan_watchdog_active
= 1;
2756 if (!schedule_delayed_work(&fan_watchdog_task
,
2757 msecs_to_jiffies(fan_watchdog_maxinterval
2759 printk(IBM_ERR
"failed to schedule the fan watchdog, "
2760 "watchdog will not trigger\n");
2763 fan_watchdog_active
= 0;
2766 static int fan_set_level(int level
)
2768 switch (fan_control_access_mode
) {
2769 case TPACPI_FAN_WR_ACPI_SFAN
:
2770 if (level
>= 0 && level
<= 7) {
2771 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
2777 case TPACPI_FAN_WR_ACPI_FANS
:
2778 case TPACPI_FAN_WR_TPEC
:
2779 if ((level
!= TP_EC_FAN_AUTO
) &&
2780 (level
!= TP_EC_FAN_FULLSPEED
) &&
2781 ((level
< 0) || (level
> 7)))
2784 if (!acpi_ec_write(fan_status_offset
, level
))
2787 tp_features
.fan_ctrl_status_undef
= 0;
2796 static int fan_set_enable(void)
2801 switch (fan_control_access_mode
) {
2802 case TPACPI_FAN_WR_ACPI_FANS
:
2803 case TPACPI_FAN_WR_TPEC
:
2804 if ((rc
= fan_get_status(&s
)) < 0)
2807 /* Don't go out of emergency fan mode */
2811 if (!acpi_ec_write(fan_status_offset
, s
))
2814 tp_features
.fan_ctrl_status_undef
= 0;
2817 case TPACPI_FAN_WR_ACPI_SFAN
:
2818 if ((rc
= fan_get_status(&s
)) < 0)
2823 /* Set fan to at least level 4 */
2827 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
2837 static int fan_set_disable(void)
2839 switch (fan_control_access_mode
) {
2840 case TPACPI_FAN_WR_ACPI_FANS
:
2841 case TPACPI_FAN_WR_TPEC
:
2842 if (!acpi_ec_write(fan_status_offset
, 0x00))
2845 tp_features
.fan_ctrl_status_undef
= 0;
2848 case TPACPI_FAN_WR_ACPI_SFAN
:
2849 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
2859 static int fan_set_speed(int speed
)
2861 switch (fan_control_access_mode
) {
2862 case TPACPI_FAN_WR_ACPI_FANS
:
2863 if (speed
>= 0 && speed
<= 65535) {
2864 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
2865 speed
, speed
, speed
))
2877 static int fan_read(char *p
)
2882 unsigned int speed
= 0;
2884 switch (fan_status_access_mode
) {
2885 case TPACPI_FAN_RD_ACPI_GFAN
:
2886 /* 570, 600e/x, 770e, 770x */
2887 if ((rc
= fan_get_status(&status
)) < 0)
2890 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
2892 (status
!= 0) ? "enabled" : "disabled", status
);
2895 case TPACPI_FAN_RD_TPEC
:
2896 /* all except 570, 600e/x, 770e, 770x */
2897 if ((rc
= fan_get_status(&status
)) < 0)
2900 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
2901 if (status
!= fan_control_initial_status
)
2902 tp_features
.fan_ctrl_status_undef
= 0;
2904 /* Return most likely status. In fact, it
2905 * might be the only possible status */
2906 status
= TP_EC_FAN_AUTO
;
2909 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2910 (status
!= 0) ? "enabled" : "disabled");
2912 if ((rc
= fan_get_speed(&speed
)) < 0)
2915 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
2917 if (status
& TP_EC_FAN_FULLSPEED
)
2918 /* Disengaged mode takes precedence */
2919 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
2920 else if (status
& TP_EC_FAN_AUTO
)
2921 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
2923 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
2926 case TPACPI_FAN_NONE
:
2928 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2931 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
2932 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
2934 switch (fan_control_access_mode
) {
2935 case TPACPI_FAN_WR_ACPI_SFAN
:
2936 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
2940 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
2941 "auto, disengaged)\n");
2946 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
2947 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
2948 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
2949 "1-120 (seconds))\n");
2951 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
2952 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
2953 " (<speed> is 0-65535)\n");
2958 static int fan_write_cmd_level(const char *cmd
, int *rc
)
2962 if (strlencmp(cmd
, "level auto") == 0)
2963 level
= TP_EC_FAN_AUTO
;
2964 else if (strlencmp(cmd
, "level disengaged") == 0)
2965 level
= TP_EC_FAN_FULLSPEED
;
2966 else if (sscanf(cmd
, "level %d", &level
) != 1)
2969 if ((*rc
= fan_set_level(level
)) == -ENXIO
)
2970 printk(IBM_ERR
"level command accepted for unsupported "
2971 "access mode %d", fan_control_access_mode
);
2976 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
2978 if (strlencmp(cmd
, "enable") != 0)
2981 if ((*rc
= fan_set_enable()) == -ENXIO
)
2982 printk(IBM_ERR
"enable command accepted for unsupported "
2983 "access mode %d", fan_control_access_mode
);
2988 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
2990 if (strlencmp(cmd
, "disable") != 0)
2993 if ((*rc
= fan_set_disable()) == -ENXIO
)
2994 printk(IBM_ERR
"disable command accepted for unsupported "
2995 "access mode %d", fan_control_access_mode
);
3000 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
3005 * Support speed <low> <medium> <high> ? */
3007 if (sscanf(cmd
, "speed %d", &speed
) != 1)
3010 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
3011 printk(IBM_ERR
"speed command accepted for unsupported "
3012 "access mode %d", fan_control_access_mode
);
3017 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
3021 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
3024 if (interval
< 0 || interval
> 120)
3027 fan_watchdog_maxinterval
= interval
;
3032 static int fan_write(char *buf
)
3037 while (!rc
&& (cmd
= next_cmd(&buf
))) {
3038 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
3039 fan_write_cmd_level(cmd
, &rc
)) &&
3040 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
3041 (fan_write_cmd_enable(cmd
, &rc
) ||
3042 fan_write_cmd_disable(cmd
, &rc
) ||
3043 fan_write_cmd_watchdog(cmd
, &rc
))) &&
3044 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
3045 fan_write_cmd_speed(cmd
, &rc
))
3049 fan_watchdog_reset();
3055 static struct ibm_struct fan_driver_data
= {
3060 .flags
.experimental
= 1,
3063 /****************************************************************************
3064 ****************************************************************************
3068 ****************************************************************************
3069 ****************************************************************************/
3072 static struct proc_dir_entry
*proc_dir
= NULL
;
3074 /* Subdriver registry */
3075 static LIST_HEAD(tpacpi_all_drivers
);
3079 * Module and infrastructure proble, init and exit handling
3082 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
3083 static const char * __init
str_supported(int is_supported
)
3085 static char text_unsupported
[] __initdata
= "not supported";
3087 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
3089 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
3091 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
3094 struct ibm_struct
*ibm
= iibm
->data
;
3095 struct proc_dir_entry
*entry
;
3097 BUG_ON(ibm
== NULL
);
3099 INIT_LIST_HEAD(&ibm
->all_drivers
);
3101 if (ibm
->flags
.experimental
&& !experimental
)
3104 dbg_printk(TPACPI_DBG_INIT
,
3105 "probing for %s\n", ibm
->name
);
3108 ret
= iibm
->init(iibm
);
3110 return 0; /* probe failed */
3114 ibm
->flags
.init_called
= 1;
3118 if (ibm
->acpi
->hid
) {
3119 ret
= register_tpacpi_subdriver(ibm
);
3124 if (ibm
->acpi
->notify
) {
3125 ret
= setup_acpi_notify(ibm
);
3126 if (ret
== -ENODEV
) {
3127 printk(IBM_NOTICE
"disabling subdriver %s\n",
3137 dbg_printk(TPACPI_DBG_INIT
,
3138 "%s installed\n", ibm
->name
);
3141 entry
= create_proc_entry(ibm
->name
,
3142 S_IFREG
| S_IRUGO
| S_IWUSR
,
3145 printk(IBM_ERR
"unable to create proc entry %s\n",
3150 entry
->owner
= THIS_MODULE
;
3152 entry
->read_proc
= &dispatch_procfs_read
;
3154 entry
->write_proc
= &dispatch_procfs_write
;
3155 ibm
->flags
.proc_created
= 1;
3158 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
3163 dbg_printk(TPACPI_DBG_INIT
,
3164 "%s: at error exit path with result %d\n",
3168 return (ret
< 0)? ret
: 0;
3171 static void ibm_exit(struct ibm_struct
*ibm
)
3173 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
3175 list_del_init(&ibm
->all_drivers
);
3177 if (ibm
->flags
.acpi_notify_installed
) {
3178 dbg_printk(TPACPI_DBG_EXIT
,
3179 "%s: acpi_remove_notify_handler\n", ibm
->name
);
3181 acpi_remove_notify_handler(*ibm
->acpi
->handle
,
3183 dispatch_acpi_notify
);
3184 ibm
->flags
.acpi_notify_installed
= 0;
3185 ibm
->flags
.acpi_notify_installed
= 0;
3188 if (ibm
->flags
.proc_created
) {
3189 dbg_printk(TPACPI_DBG_EXIT
,
3190 "%s: remove_proc_entry\n", ibm
->name
);
3191 remove_proc_entry(ibm
->name
, proc_dir
);
3192 ibm
->flags
.proc_created
= 0;
3195 if (ibm
->flags
.acpi_driver_registered
) {
3196 dbg_printk(TPACPI_DBG_EXIT
,
3197 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
3199 acpi_bus_unregister_driver(ibm
->acpi
->driver
);
3200 kfree(ibm
->acpi
->driver
);
3201 ibm
->acpi
->driver
= NULL
;
3202 ibm
->flags
.acpi_driver_registered
= 0;
3205 if (ibm
->flags
.init_called
&& ibm
->exit
) {
3207 ibm
->flags
.init_called
= 0;
3210 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
3215 static char *ibm_thinkpad_ec_found
= NULL
;
3217 static char* __init
check_dmi_for_ec(void)
3219 struct dmi_device
*dev
= NULL
;
3220 char ec_fw_string
[18];
3223 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
3224 * X32 or newer, all Z series; Some models must have an
3225 * up-to-date BIOS or they will not be detected.
3227 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
3229 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
3230 if (sscanf(dev
->name
,
3231 "IBM ThinkPad Embedded Controller -[%17c",
3232 ec_fw_string
) == 1) {
3233 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
3234 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
3235 return kstrdup(ec_fw_string
, GFP_KERNEL
);
3241 static int __init
probe_for_thinkpad(void)
3249 * Non-ancient models have better DMI tagging, but very old models
3252 is_thinkpad
= dmi_name_in_vendors("ThinkPad");
3254 /* ec is required because many other handles are relative to it */
3255 IBM_ACPIHANDLE_INIT(ec
);
3259 "Not yet supported ThinkPad detected!\n");
3264 * Risks a regression on very old machines, but reduces potential
3265 * false positives a damn great deal
3268 is_thinkpad
= dmi_name_in_vendors("IBM");
3270 if (!is_thinkpad
&& !force_load
)
3277 /* Module init, exit, parameters */
3279 static struct ibm_init_struct ibms_init
[] __initdata
= {
3281 .init
= thinkpad_acpi_driver_init
,
3282 .data
= &thinkpad_acpi_driver_data
,
3285 .init
= hotkey_init
,
3286 .data
= &hotkey_driver_data
,
3289 .init
= bluetooth_init
,
3290 .data
= &bluetooth_driver_data
,
3294 .data
= &wan_driver_data
,
3298 .data
= &video_driver_data
,
3302 .data
= &light_driver_data
,
3304 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3307 .data
= &dock_driver_data
[0],
3310 .data
= &dock_driver_data
[1],
3313 #ifdef CONFIG_THINKPAD_ACPI_BAY
3316 .data
= &bay_driver_data
,
3321 .data
= &cmos_driver_data
,
3325 .data
= &led_driver_data
,
3329 .data
= &beep_driver_data
,
3332 .init
= thermal_init
,
3333 .data
= &thermal_driver_data
,
3336 .data
= &ecdump_driver_data
,
3339 .init
= brightness_init
,
3340 .data
= &brightness_driver_data
,
3343 .data
= &volume_driver_data
,
3347 .data
= &fan_driver_data
,
3351 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
3354 struct ibm_struct
*ibm
;
3356 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
3357 ibm
= ibms_init
[i
].data
;
3358 BUG_ON(ibm
== NULL
);
3360 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
3361 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
3363 strcpy(ibms_init
[i
].param
, val
);
3364 strcat(ibms_init
[i
].param
, ",");
3372 static int experimental
;
3373 module_param(experimental
, int, 0);
3375 static u32 dbg_level
;
3376 module_param_named(debug
, dbg_level
, uint
, 0);
3378 static int force_load
;
3379 module_param(force_load
, int, 0);
3381 #define IBM_PARAM(feature) \
3382 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
3385 IBM_PARAM(bluetooth
);
3388 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3391 #ifdef CONFIG_THINKPAD_ACPI_BAY
3393 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3398 IBM_PARAM(brightness
);
3402 static int __init
thinkpad_acpi_module_init(void)
3406 /* Driver-level probe */
3407 ret
= probe_for_thinkpad();
3411 /* Driver initialization */
3412 ibm_thinkpad_ec_found
= check_dmi_for_ec();
3413 IBM_ACPIHANDLE_INIT(ecrd
);
3414 IBM_ACPIHANDLE_INIT(ecwr
);
3416 proc_dir
= proc_mkdir(IBM_PROC_DIR
, acpi_root_dir
);
3418 printk(IBM_ERR
"unable to create proc dir " IBM_PROC_DIR
);
3419 thinkpad_acpi_module_exit();
3422 proc_dir
->owner
= THIS_MODULE
;
3424 ret
= platform_driver_register(&tpacpi_pdriver
);
3426 printk(IBM_ERR
"unable to register platform driver\n");
3427 thinkpad_acpi_module_exit();
3430 ret
= tpacpi_create_driver_attributes(&tpacpi_pdriver
.driver
);
3432 printk(IBM_ERR
"unable to create sysfs driver attributes\n");
3433 thinkpad_acpi_module_exit();
3438 /* Device initialization */
3439 tpacpi_pdev
= platform_device_register_simple(IBM_DRVR_NAME
, -1,
3441 if (IS_ERR(tpacpi_pdev
)) {
3442 ret
= PTR_ERR(tpacpi_pdev
);
3444 printk(IBM_ERR
"unable to register platform device\n");
3445 thinkpad_acpi_module_exit();
3448 tpacpi_hwmon
= hwmon_device_register(&tpacpi_pdev
->dev
);
3449 if (IS_ERR(tpacpi_hwmon
)) {
3450 ret
= PTR_ERR(tpacpi_hwmon
);
3451 tpacpi_hwmon
= NULL
;
3452 printk(IBM_ERR
"unable to register hwmon device\n");
3453 thinkpad_acpi_module_exit();
3456 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
3457 ret
= ibm_init(&ibms_init
[i
]);
3458 if (ret
>= 0 && *ibms_init
[i
].param
)
3459 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
3461 thinkpad_acpi_module_exit();
3469 static void thinkpad_acpi_module_exit(void)
3471 struct ibm_struct
*ibm
, *itmp
;
3473 list_for_each_entry_safe_reverse(ibm
, itmp
,
3474 &tpacpi_all_drivers
,
3479 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
3482 hwmon_device_unregister(tpacpi_hwmon
);
3485 platform_device_unregister(tpacpi_pdev
);
3487 tpacpi_remove_driver_attributes(&tpacpi_pdriver
.driver
);
3488 platform_driver_unregister(&tpacpi_pdriver
);
3491 remove_proc_entry(IBM_PROC_DIR
, acpi_root_dir
);
3493 kfree(ibm_thinkpad_ec_found
);
3496 module_init(thinkpad_acpi_module_init
);
3497 module_exit(thinkpad_acpi_module_exit
);