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"
28 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
31 * 2006-11-22 0.13 new maintainer
32 * changelog now lives in git commit history, and will
33 * not be updated further in-file.
35 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
36 * 2005-03-17 0.11 support for 600e, 770x
37 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
38 * support for 770e, G41
39 * G40 and G41 don't have a thinklight
40 * temperatures no longer experimental
41 * experimental brightness control
42 * experimental volume control
43 * experimental fan enable/disable
44 * 2005-01-16 0.10 fix module loading on R30, R31
45 * 2005-01-16 0.9 support for 570, R30, R31
46 * ultrabay support on A22p, A3x
47 * limit arg for cmos, led, beep, drop experimental status
48 * more capable led control on A21e, A22p, T20-22, X20
49 * experimental temperatures and fan speed
50 * experimental embedded controller register dump
51 * mark more functions as __init, drop incorrect __exit
53 * thanks to Henrik Brix Andersen <brix@gentoo.org>
54 * fix parameter passing on module loading
55 * thanks to Rusty Russell <rusty@rustcorp.com.au>
56 * thanks to Jim Radford <radford@blackbean.org>
57 * 2004-11-08 0.8 fix init error case, don't return from a macro
58 * thanks to Chris Wright <chrisw@osdl.org>
59 * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
60 * fix led control on A21e
61 * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
62 * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
63 * proc file format changed
64 * video_switch command
65 * experimental cmos control
66 * experimental led control
67 * experimental acpi sounds
68 * 2004-09-16 0.4 support for module parameters
69 * hotkey mask can be prefixed by 0x
70 * video output switching
71 * video expansion control
72 * ultrabay eject support
73 * removed lcd brightness/on/off control, didn't work
74 * 2004-08-17 0.3 support for R40
75 * lcd off, brightness control
77 * 2004-08-14 0.2 support for T series, X20
78 * bluetooth enable/disable
79 * hotkey events disabled by default
80 * removed fan control, currently useless
81 * 2004-08-09 0.1 initial release, support for X series
84 #include "thinkpad_acpi.h"
86 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
87 MODULE_DESCRIPTION(IBM_DESC
);
88 MODULE_VERSION(IBM_VERSION
);
89 MODULE_LICENSE("GPL");
91 /* Please remove this in year 2009 */
92 MODULE_ALIAS("ibm_acpi");
94 #define __unused __attribute__ ((unused))
96 /****************************************************************************
97 ****************************************************************************
99 * ACPI Helpers and device model
101 ****************************************************************************
102 ****************************************************************************/
104 /*************************************************************************
108 static acpi_handle root_handle
= NULL
;
110 #define IBM_HANDLE(object, parent, paths...) \
111 static acpi_handle object##_handle; \
112 static acpi_handle *object##_parent = &parent##_handle; \
113 static char *object##_path; \
114 static char *object##_paths[] = { paths }
116 IBM_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
117 "\\_SB.PCI.ISA.EC", /* 570 */
118 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
119 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
120 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
121 "\\_SB.PCI0.ICH3.EC0", /* R31 */
122 "\\_SB.PCI0.LPC.EC", /* all others */
125 IBM_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
126 IBM_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
129 /*************************************************************************
133 IBM_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
134 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
135 "\\CMS", /* R40, R40e */
138 IBM_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
139 "^HKEY", /* R30, R31 */
140 "HKEY", /* all others */
144 /*************************************************************************
148 static int acpi_evalf(acpi_handle handle
,
149 void *res
, char *method
, char *fmt
, ...)
152 struct acpi_object_list params
;
153 union acpi_object in_objs
[IBM_MAX_ACPI_ARGS
];
154 struct acpi_buffer result
, *resultp
;
155 union acpi_object out_obj
;
163 printk(IBM_ERR
"acpi_evalf() called with empty format\n");
176 params
.pointer
= &in_objs
[0];
183 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
184 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
186 /* add more types as needed */
188 printk(IBM_ERR
"acpi_evalf() called "
189 "with invalid format character '%c'\n", c
);
195 if (res_type
!= 'v') {
196 result
.length
= sizeof(out_obj
);
197 result
.pointer
= &out_obj
;
202 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
207 *(int *)res
= out_obj
.integer
.value
;
208 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
211 success
= status
== AE_OK
;
213 /* add more types as needed */
215 printk(IBM_ERR
"acpi_evalf() called "
216 "with invalid format character '%c'\n", res_type
);
220 if (!success
&& !quiet
)
221 printk(IBM_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
222 method
, fmt0
, status
);
227 static void __unused
acpi_print_int(acpi_handle handle
, char *method
)
231 if (acpi_evalf(handle
, &i
, method
, "d"))
232 printk(IBM_INFO
"%s = 0x%x\n", method
, i
);
234 printk(IBM_ERR
"error calling %s\n", method
);
237 static int acpi_ec_read(int i
, u8
* p
)
242 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
246 if (ec_read(i
, p
) < 0)
253 static int acpi_ec_write(int i
, u8 v
)
256 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
259 if (ec_write(i
, v
) < 0)
266 static int _sta(acpi_handle handle
)
270 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
276 /*************************************************************************
280 static void ibm_handle_init(char *name
,
281 acpi_handle
*handle
, acpi_handle parent
,
282 char **paths
, int num_paths
, char **path
)
287 for (i
= 0; i
< num_paths
; i
++) {
288 status
= acpi_get_handle(parent
, paths
[i
], handle
);
289 if (ACPI_SUCCESS(status
)) {
298 static void dispatch_notify(acpi_handle handle
, u32 event
, void *data
)
300 struct ibm_struct
*ibm
= data
;
302 if (!ibm
|| !ibm
->notify
)
305 ibm
->notify(ibm
, event
);
308 static int __init
setup_notify(struct ibm_struct
*ibm
)
316 dbg_printk(TPACPI_DBG_INIT
,
317 "setting up ACPI notify for %s\n", ibm
->name
);
319 ret
= acpi_bus_get_device(*ibm
->handle
, &ibm
->device
);
321 printk(IBM_ERR
"%s device not present\n", ibm
->name
);
325 acpi_driver_data(ibm
->device
) = ibm
;
326 sprintf(acpi_device_class(ibm
->device
), "%s/%s",
327 IBM_ACPI_EVENT_PREFIX
,
330 status
= acpi_install_notify_handler(*ibm
->handle
, ibm
->type
,
331 dispatch_notify
, ibm
);
332 if (ACPI_FAILURE(status
)) {
333 if (status
== AE_ALREADY_EXISTS
) {
334 printk(IBM_NOTICE
"another device driver is already handling %s events\n",
337 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
342 ibm
->flags
.notify_installed
= 1;
346 static int __init
ibm_device_add(struct acpi_device
*device
)
351 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
355 dbg_printk(TPACPI_DBG_INIT
,
356 "registering %s as an ACPI driver\n", ibm
->name
);
358 ibm
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
360 printk(IBM_ERR
"kzalloc(ibm->driver) failed\n");
364 sprintf(ibm
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
365 ibm
->driver
->ids
= ibm
->hid
;
366 ibm
->driver
->ops
.add
= &ibm_device_add
;
368 ret
= acpi_bus_register_driver(ibm
->driver
);
370 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
375 ibm
->flags
.driver_registered
= 1;
381 /****************************************************************************
382 ****************************************************************************
386 ****************************************************************************
387 ****************************************************************************/
389 static int dispatch_read(char *page
, char **start
, off_t off
, int count
,
390 int *eof
, void *data
)
392 struct ibm_struct
*ibm
= data
;
395 if (!ibm
|| !ibm
->read
)
398 len
= ibm
->read(page
);
402 if (len
<= off
+ count
)
414 static int dispatch_write(struct file
*file
, const char __user
* userbuf
,
415 unsigned long count
, void *data
)
417 struct ibm_struct
*ibm
= data
;
421 if (!ibm
|| !ibm
->write
)
424 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
428 if (copy_from_user(kernbuf
, userbuf
, count
)) {
434 strcat(kernbuf
, ",");
435 ret
= ibm
->write(kernbuf
);
444 static char *next_cmd(char **cmds
)
449 while ((end
= strchr(start
, ',')) && end
== start
)
461 /****************************************************************************
462 ****************************************************************************
466 ****************************************************************************
467 ****************************************************************************/
469 /*************************************************************************
470 * thinkpad-acpi init subdriver
473 static int __init
thinkpad_acpi_driver_init(struct ibm_init_struct
*iibm
)
475 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
476 printk(IBM_INFO
"%s\n", IBM_URL
);
478 if (ibm_thinkpad_ec_found
)
479 printk(IBM_INFO
"ThinkPad EC firmware %s\n",
480 ibm_thinkpad_ec_found
);
485 static int thinkpad_acpi_driver_read(char *p
)
489 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
490 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
495 static struct ibm_struct thinkpad_acpi_driver_data
= {
497 .read
= thinkpad_acpi_driver_read
,
500 /*************************************************************************
504 static int hotkey_orig_status
;
505 static int hotkey_orig_mask
;
507 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
509 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
511 IBM_HANDLE_INIT(hkey
);
513 /* hotkey not supported on 570 */
514 tp_features
.hotkey
= hkey_handle
!= NULL
;
516 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
517 str_supported(tp_features
.hotkey
));
519 if (tp_features
.hotkey
) {
520 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
521 A30, R30, R31, T20-22, X20-21, X22-24 */
522 tp_features
.hotkey_mask
=
523 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
525 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
526 str_supported(tp_features
.hotkey_mask
));
528 if (!hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
))
532 return (tp_features
.hotkey
)? 0 : 1;
535 static void hotkey_exit(void)
537 if (tp_features
.hotkey
) {
538 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
539 hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
543 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
547 if (acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d"))
548 acpi_bus_generate_event(ibm
->device
, event
, hkey
);
550 printk(IBM_ERR
"unknown hotkey event %d\n", event
);
551 acpi_bus_generate_event(ibm
->device
, event
, 0);
555 static int hotkey_get(int *status
, int *mask
)
557 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
560 if (tp_features
.hotkey_mask
)
561 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
567 static int hotkey_set(int status
, int mask
)
571 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
574 if (tp_features
.hotkey_mask
)
575 for (i
= 0; i
< 32; i
++) {
576 int bit
= ((1 << i
) & mask
) != 0;
577 if (!acpi_evalf(hkey_handle
,
578 NULL
, "MHKM", "vdd", i
+ 1, bit
))
585 static int hotkey_read(char *p
)
590 if (!tp_features
.hotkey
) {
591 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
595 if (!hotkey_get(&status
, &mask
))
598 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
599 if (tp_features
.hotkey_mask
) {
600 len
+= sprintf(p
+ len
, "mask:\t\t0x%04x\n", mask
);
601 len
+= sprintf(p
+ len
,
602 "commands:\tenable, disable, reset, <mask>\n");
604 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
605 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
611 static int hotkey_write(char *buf
)
617 if (!tp_features
.hotkey
)
620 if (!hotkey_get(&status
, &mask
))
623 while ((cmd
= next_cmd(&buf
))) {
624 if (strlencmp(cmd
, "enable") == 0) {
626 } else if (strlencmp(cmd
, "disable") == 0) {
628 } else if (strlencmp(cmd
, "reset") == 0) {
629 status
= hotkey_orig_status
;
630 mask
= hotkey_orig_mask
;
631 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
633 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
640 if (do_cmd
&& !hotkey_set(status
, mask
))
646 static struct ibm_struct hotkey_driver_data
= {
650 .write
= hotkey_write
,
652 .notify
= hotkey_notify
,
653 .handle
= &hkey_handle
,
654 .type
= ACPI_DEVICE_NOTIFY
,
657 /*************************************************************************
658 * Bluetooth subdriver
661 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
663 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
665 IBM_HANDLE_INIT(hkey
);
667 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
668 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
669 tp_features
.bluetooth
= hkey_handle
&&
670 acpi_evalf(hkey_handle
, NULL
, "GBDC", "qv");
672 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s\n",
673 str_supported(tp_features
.bluetooth
));
675 return (tp_features
.bluetooth
)? 0 : 1;
678 static int bluetooth_status(void)
682 if (!tp_features
.bluetooth
||
683 !acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
689 static int bluetooth_read(char *p
)
692 int status
= bluetooth_status();
694 if (!tp_features
.bluetooth
)
695 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
696 else if (!(status
& 1))
697 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
699 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
700 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
706 static int bluetooth_write(char *buf
)
708 int status
= bluetooth_status();
712 if (!tp_features
.bluetooth
)
715 while ((cmd
= next_cmd(&buf
))) {
716 if (strlencmp(cmd
, "enable") == 0) {
718 } else if (strlencmp(cmd
, "disable") == 0) {
725 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
731 static struct ibm_struct bluetooth_driver_data
= {
733 .read
= bluetooth_read
,
734 .write
= bluetooth_write
,
737 /*************************************************************************
741 static int __init
wan_init(struct ibm_init_struct
*iibm
)
743 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
745 IBM_HANDLE_INIT(hkey
);
747 tp_features
.wan
= hkey_handle
&&
748 acpi_evalf(hkey_handle
, NULL
, "GWAN", "qv");
750 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s\n",
751 str_supported(tp_features
.wan
));
753 return (tp_features
.wan
)? 0 : 1;
756 static int wan_status(void)
760 if (!tp_features
.wan
||
761 !acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
767 static int wan_read(char *p
)
770 int status
= wan_status();
772 if (!tp_features
.wan
)
773 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
774 else if (!(status
& 1))
775 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
777 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
778 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
784 static int wan_write(char *buf
)
786 int status
= wan_status();
790 if (!tp_features
.wan
)
793 while ((cmd
= next_cmd(&buf
))) {
794 if (strlencmp(cmd
, "enable") == 0) {
796 } else if (strlencmp(cmd
, "disable") == 0) {
803 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
809 static struct ibm_struct wan_driver_data
= {
813 .flags
.experimental
= 1,
816 /*************************************************************************
820 static enum video_access_mode video_supported
;
821 static int video_orig_autosw
;
823 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
824 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
825 "\\_SB.PCI0.VID0", /* 770e */
826 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
827 "\\_SB.PCI0.AGP.VID", /* all others */
830 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
832 static int __init
video_init(struct ibm_init_struct
*iibm
)
836 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
838 IBM_HANDLE_INIT(vid
);
839 IBM_HANDLE_INIT(vid2
);
841 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
842 /* G41, assume IVGA doesn't change */
843 vid_handle
= vid2_handle
;
846 /* video switching not supported on R30, R31 */
847 video_supported
= TPACPI_VIDEO_NONE
;
848 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
850 video_supported
= TPACPI_VIDEO_570
;
851 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
852 /* 600e/x, 770e, 770x */
853 video_supported
= TPACPI_VIDEO_770
;
856 video_supported
= TPACPI_VIDEO_NEW
;
858 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
859 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
862 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
865 static void video_exit(void)
867 dbg_printk(TPACPI_DBG_EXIT
, "restoring original video autoswitch mode\n");
868 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", video_orig_autosw
);
871 static int video_status(void)
876 if (video_supported
== TPACPI_VIDEO_570
) {
877 if (acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd", 0x87))
879 } else if (video_supported
== TPACPI_VIDEO_770
) {
880 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
882 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
884 } else if (video_supported
== TPACPI_VIDEO_NEW
) {
885 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1);
886 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
889 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0);
890 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
892 if (acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
899 static int video_autosw(void)
903 if (video_supported
== TPACPI_VIDEO_570
)
904 acpi_evalf(vid_handle
, &autosw
, "SWIT", "d");
905 else if (video_supported
== TPACPI_VIDEO_770
||
906 video_supported
== TPACPI_VIDEO_NEW
)
907 acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d");
912 static int video_switch(void)
914 int autosw
= video_autosw();
917 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
919 ret
= video_supported
== TPACPI_VIDEO_570
?
920 acpi_evalf(ec_handle
, NULL
, "_Q16", "v") :
921 acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
922 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
927 static int video_expand(void)
929 if (video_supported
== TPACPI_VIDEO_570
)
930 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v");
931 else if (video_supported
== TPACPI_VIDEO_770
)
932 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v");
934 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v");
937 static int video_switch2(int status
)
941 if (video_supported
== TPACPI_VIDEO_570
) {
942 ret
= acpi_evalf(NULL
, NULL
,
943 "\\_SB.PHS2", "vdd", 0x8b, status
| 0x80);
944 } else if (video_supported
== TPACPI_VIDEO_770
) {
945 int autosw
= video_autosw();
946 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
949 ret
= acpi_evalf(vid_handle
, NULL
,
950 "ASWT", "vdd", status
* 0x100, 0);
952 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
954 ret
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
955 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
961 static int video_read(char *p
)
963 int status
= video_status();
964 int autosw
= video_autosw();
967 if (!video_supported
) {
968 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
972 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
973 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
974 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
975 if (video_supported
== TPACPI_VIDEO_NEW
)
976 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
977 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
978 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
979 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
980 if (video_supported
== TPACPI_VIDEO_NEW
)
981 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
982 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
983 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
988 static int video_write(char *buf
)
991 int enable
, disable
, status
;
993 if (!video_supported
)
996 enable
= disable
= 0;
998 while ((cmd
= next_cmd(&buf
))) {
999 if (strlencmp(cmd
, "lcd_enable") == 0) {
1001 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
1003 } else if (strlencmp(cmd
, "crt_enable") == 0) {
1005 } else if (strlencmp(cmd
, "crt_disable") == 0) {
1007 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1008 strlencmp(cmd
, "dvi_enable") == 0) {
1010 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1011 strlencmp(cmd
, "dvi_disable") == 0) {
1013 } else if (strlencmp(cmd
, "auto_enable") == 0) {
1014 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
1016 } else if (strlencmp(cmd
, "auto_disable") == 0) {
1017 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 0))
1019 } else if (strlencmp(cmd
, "video_switch") == 0) {
1020 if (!video_switch())
1022 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
1023 if (!video_expand())
1029 if (enable
|| disable
) {
1030 status
= (video_status() & 0x0f & ~disable
) | enable
;
1031 if (!video_switch2(status
))
1038 static struct ibm_struct video_driver_data
= {
1041 .write
= video_write
,
1045 /*************************************************************************
1046 * Light (thinklight) subdriver
1049 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1050 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
1052 static int __init
light_init(struct ibm_init_struct
*iibm
)
1054 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
1056 IBM_HANDLE_INIT(ledb
);
1057 IBM_HANDLE_INIT(lght
);
1058 IBM_HANDLE_INIT(cmos
);
1060 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1061 tp_features
.light
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
1063 if (tp_features
.light
)
1064 /* light status not supported on
1065 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1066 tp_features
.light_status
=
1067 acpi_evalf(ec_handle
, NULL
, "KBLT", "qv");
1069 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
1070 str_supported(tp_features
.light
));
1072 return (tp_features
.light
)? 0 : 1;
1075 static int light_read(char *p
)
1080 if (!tp_features
.light
) {
1081 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1082 } else if (!tp_features
.light_status
) {
1083 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
1084 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1086 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
1088 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
1089 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1095 static int light_write(char *buf
)
1097 int cmos_cmd
, lght_cmd
;
1101 if (!tp_features
.light
)
1104 while ((cmd
= next_cmd(&buf
))) {
1105 if (strlencmp(cmd
, "on") == 0) {
1108 } else if (strlencmp(cmd
, "off") == 0) {
1114 success
= cmos_handle
?
1115 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
1116 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
1124 static struct ibm_struct light_driver_data
= {
1127 .write
= light_write
,
1130 /*************************************************************************
1134 #ifdef CONFIG_THINKPAD_ACPI_DOCK
1136 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
1137 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
1138 "\\_SB.PCI0.PCI1.DOCK", /* all others */
1139 "\\_SB.PCI.ISA.SLCE", /* 570 */
1140 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
1142 /* don't list other alternatives as we install a notify handler on the 570 */
1143 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
1145 #define dock_docked() (_sta(dock_handle) & 1)
1147 static int __init
dock_init(struct ibm_init_struct
*iibm
)
1149 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
1151 IBM_HANDLE_INIT(dock
);
1152 IBM_HANDLE_INIT(pci
);
1154 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
1155 str_supported(dock_handle
!= NULL
));
1157 return (dock_handle
)? 0 : 1;
1160 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
1162 int docked
= dock_docked();
1163 int pci
= ibm
->hid
&& strstr(ibm
->hid
, IBM_PCI_HID
);
1165 if (event
== 1 && !pci
) /* 570 */
1166 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
1167 else if (event
== 1 && pci
) /* 570 */
1168 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
1169 else if (event
== 3 && docked
)
1170 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
1171 else if (event
== 3 && !docked
)
1172 acpi_bus_generate_event(ibm
->device
, event
, 2); /* undock */
1173 else if (event
== 0 && docked
)
1174 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
1176 printk(IBM_ERR
"unknown dock event %d, status %d\n",
1177 event
, _sta(dock_handle
));
1178 acpi_bus_generate_event(ibm
->device
, event
, 0); /* unknown */
1182 static int dock_read(char *p
)
1185 int docked
= dock_docked();
1188 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1190 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
1192 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
1193 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
1199 static int dock_write(char *buf
)
1206 while ((cmd
= next_cmd(&buf
))) {
1207 if (strlencmp(cmd
, "undock") == 0) {
1208 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
1209 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
1211 } else if (strlencmp(cmd
, "dock") == 0) {
1212 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
1221 static struct ibm_struct dock_driver_data
[2] = {
1225 .write
= dock_write
,
1226 .notify
= dock_notify
,
1227 .handle
= &dock_handle
,
1228 .type
= ACPI_SYSTEM_NOTIFY
,
1233 .notify
= dock_notify
,
1234 .handle
= &pci_handle
,
1235 .type
= ACPI_SYSTEM_NOTIFY
,
1239 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
1241 /*************************************************************************
1245 #ifdef CONFIG_THINKPAD_ACPI_BAY
1246 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
1247 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
1248 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
1249 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
1250 ); /* A21e, R30, R31 */
1251 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
1252 "_EJ0", /* all others */
1253 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
1254 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
1255 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
1257 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
1261 static int __init
bay_init(struct ibm_init_struct
*iibm
)
1263 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
1265 IBM_HANDLE_INIT(bay
);
1267 IBM_HANDLE_INIT(bay_ej
);
1268 IBM_HANDLE_INIT(bay2
);
1270 IBM_HANDLE_INIT(bay2_ej
);
1272 tp_features
.bay_status
= bay_handle
&&
1273 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
1274 tp_features
.bay_status2
= bay2_handle
&&
1275 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
1277 tp_features
.bay_eject
= bay_handle
&& bay_ej_handle
&&
1278 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
1279 tp_features
.bay_eject2
= bay2_handle
&& bay2_ej_handle
&&
1280 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
1282 vdbg_printk(TPACPI_DBG_INIT
,
1283 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
1284 str_supported(tp_features
.bay_status
),
1285 str_supported(tp_features
.bay_eject
),
1286 str_supported(tp_features
.bay_status2
),
1287 str_supported(tp_features
.bay_eject2
));
1289 return (tp_features
.bay_status
|| tp_features
.bay_eject
||
1290 tp_features
.bay_status2
|| tp_features
.bay_eject2
)? 0 : 1;
1293 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
1295 acpi_bus_generate_event(ibm
->device
, event
, 0);
1298 #define bay_occupied(b) (_sta(b##_handle) & 1)
1300 static int bay_read(char *p
)
1303 int occupied
= bay_occupied(bay
);
1304 int occupied2
= bay_occupied(bay2
);
1307 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1308 tp_features
.bay_status
?
1309 (occupied
? "occupied" : "unoccupied") :
1311 if (tp_features
.bay_status2
)
1312 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
1313 "occupied" : "unoccupied");
1315 eject
= tp_features
.bay_eject
&& occupied
;
1316 eject2
= tp_features
.bay_eject2
&& occupied2
;
1318 if (eject
&& eject2
)
1319 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
1321 len
+= sprintf(p
+ len
, "commands:\teject\n");
1323 len
+= sprintf(p
+ len
, "commands:\teject2\n");
1328 static int bay_write(char *buf
)
1332 if (!tp_features
.bay_eject
&& !tp_features
.bay_eject2
)
1335 while ((cmd
= next_cmd(&buf
))) {
1336 if (tp_features
.bay_eject
&& strlencmp(cmd
, "eject") == 0) {
1337 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
1339 } else if (tp_features
.bay_eject2
&&
1340 strlencmp(cmd
, "eject2") == 0) {
1341 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
1350 static struct ibm_struct bay_driver_data
= {
1354 .notify
= bay_notify
,
1355 .handle
= &bay_handle
,
1356 .type
= ACPI_SYSTEM_NOTIFY
,
1359 #endif /* CONFIG_THINKPAD_ACPI_BAY */
1361 /*************************************************************************
1365 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
1367 vdbg_printk(TPACPI_DBG_INIT
,
1368 "initializing cmos commands subdriver\n");
1370 IBM_HANDLE_INIT(cmos
);
1372 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
1373 str_supported(cmos_handle
!= NULL
));
1374 return (cmos_handle
)? 0 : 1;
1377 static int cmos_eval(int cmos_cmd
)
1380 return acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
);
1385 static int cmos_read(char *p
)
1389 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1390 R30, R31, T20-22, X20-21 */
1392 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1394 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1395 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
1401 static int cmos_write(char *buf
)
1409 while ((cmd
= next_cmd(&buf
))) {
1410 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
1411 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
1416 if (!cmos_eval(cmos_cmd
))
1423 static struct ibm_struct cmos_driver_data
= {
1426 .write
= cmos_write
,
1429 /*************************************************************************
1433 static enum led_access_mode led_supported
;
1435 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
1436 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1437 "LED", /* all others */
1440 static int __init
led_init(struct ibm_init_struct
*iibm
)
1442 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
1444 IBM_HANDLE_INIT(led
);
1447 /* led not supported on R30, R31 */
1448 led_supported
= TPACPI_LED_NONE
;
1449 else if (strlencmp(led_path
, "SLED") == 0)
1451 led_supported
= TPACPI_LED_570
;
1452 else if (strlencmp(led_path
, "SYSL") == 0)
1453 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1454 led_supported
= TPACPI_LED_OLD
;
1457 led_supported
= TPACPI_LED_NEW
;
1459 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
1460 str_supported(led_supported
), led_supported
);
1462 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
1465 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1467 static int led_read(char *p
)
1471 if (!led_supported
) {
1472 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1475 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1477 if (led_supported
== TPACPI_LED_570
) {
1480 for (i
= 0; i
< 8; i
++) {
1481 if (!acpi_evalf(ec_handle
,
1482 &status
, "GLED", "dd", 1 << i
))
1484 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
1485 i
, led_status(status
));
1489 len
+= sprintf(p
+ len
, "commands:\t"
1490 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
1495 /* off, on, blink */
1496 static const int led_sled_arg1
[] = { 0, 1, 3 };
1497 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
1498 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
1499 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
1501 static int led_write(char *buf
)
1509 while ((cmd
= next_cmd(&buf
))) {
1510 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
1513 if (strstr(cmd
, "off")) {
1515 } else if (strstr(cmd
, "on")) {
1517 } else if (strstr(cmd
, "blink")) {
1522 if (led_supported
== TPACPI_LED_570
) {
1525 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1526 led
, led_sled_arg1
[ind
]))
1528 } else if (led_supported
== TPACPI_LED_OLD
) {
1529 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1531 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
1534 ec_write(TPACPI_LED_EC_HLBL
,
1535 led
* led_exp_hlbl
[ind
]);
1538 ec_write(TPACPI_LED_EC_HLCL
,
1539 led
* led_exp_hlcl
[ind
]);
1544 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1545 led
, led_led_arg1
[ind
]))
1553 static struct ibm_struct led_driver_data
= {
1559 /*************************************************************************
1563 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
1565 static int __init
beep_init(struct ibm_init_struct
*iibm
)
1567 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
1569 IBM_HANDLE_INIT(beep
);
1571 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
1572 str_supported(beep_handle
!= NULL
));
1574 return (beep_handle
)? 0 : 1;
1577 static int beep_read(char *p
)
1582 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1584 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1585 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
1591 static int beep_write(char *buf
)
1599 while ((cmd
= next_cmd(&buf
))) {
1600 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
1601 beep_cmd
>= 0 && beep_cmd
<= 17) {
1605 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
1612 static struct ibm_struct beep_driver_data
= {
1615 .write
= beep_write
,
1618 /*************************************************************************
1622 static enum thermal_access_mode thermal_read_mode
;
1624 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
1630 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
1632 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
1634 if (ibm_thinkpad_ec_found
&& experimental
) {
1636 * Direct EC access mode: sensors at registers
1637 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
1638 * non-implemented, thermal sensors return 0x80 when
1643 for (i
= 0; i
< 8; i
++) {
1644 if (likely(acpi_ec_read(0x78 + i
, &t
))) {
1650 if (likely(acpi_ec_read(0xC0 + i
, &t
))) {
1658 /* This is sheer paranoia, but we handle it anyway */
1661 "ThinkPad ACPI EC access misbehaving, "
1662 "falling back to ACPI TMPx access mode\n");
1663 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
1666 "ThinkPad ACPI EC access misbehaving, "
1667 "disabling thermal sensors access\n");
1668 thermal_read_mode
= TPACPI_THERMAL_NONE
;
1673 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
1675 } else if (acpi_tmp7
) {
1676 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
1677 /* 600e/x, 770e, 770x */
1678 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
1680 /* Standard ACPI TMPx access, max 8 sensors */
1681 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
1684 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1685 thermal_read_mode
= TPACPI_THERMAL_NONE
;
1688 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
1689 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
1692 return (thermal_read_mode
!= TPACPI_THERMAL_NONE
)? 0 : 1;
1695 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
1699 char tmpi
[] = "TMPi";
1704 switch (thermal_read_mode
) {
1705 #if TPACPI_MAX_THERMAL_SENSORS >= 16
1706 case TPACPI_THERMAL_TPEC_16
:
1707 for (i
= 0; i
< 8; i
++) {
1708 if (!acpi_ec_read(0xC0 + i
, &tmp
))
1710 s
->temp
[i
+ 8] = tmp
* 1000;
1714 case TPACPI_THERMAL_TPEC_8
:
1715 for (i
= 0; i
< 8; i
++) {
1716 if (!acpi_ec_read(0x78 + i
, &tmp
))
1718 s
->temp
[i
] = tmp
* 1000;
1720 return (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
) ? 16 : 8;
1722 case TPACPI_THERMAL_ACPI_UPDT
:
1723 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
1725 for (i
= 0; i
< 8; i
++) {
1727 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1729 s
->temp
[i
] = (t
- 2732) * 100;
1733 case TPACPI_THERMAL_ACPI_TMP07
:
1734 for (i
= 0; i
< 8; i
++) {
1736 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1738 s
->temp
[i
] = t
* 1000;
1742 case TPACPI_THERMAL_NONE
:
1748 static int thermal_read(char *p
)
1752 struct ibm_thermal_sensors_struct t
;
1754 n
= thermal_get_sensors(&t
);
1755 if (unlikely(n
< 0))
1758 len
+= sprintf(p
+ len
, "temperatures:\t");
1761 for (i
= 0; i
< (n
- 1); i
++)
1762 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
1763 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
1765 len
+= sprintf(p
+ len
, "not supported\n");
1770 static struct ibm_struct thermal_driver_data
= {
1772 .read
= thermal_read
,
1775 /*************************************************************************
1779 static u8 ecdump_regs
[256];
1781 static int ecdump_read(char *p
)
1787 len
+= sprintf(p
+ len
, "EC "
1788 " +00 +01 +02 +03 +04 +05 +06 +07"
1789 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
1790 for (i
= 0; i
< 256; i
+= 16) {
1791 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
1792 for (j
= 0; j
< 16; j
++) {
1793 if (!acpi_ec_read(i
+ j
, &v
))
1795 if (v
!= ecdump_regs
[i
+ j
])
1796 len
+= sprintf(p
+ len
, " *%02x", v
);
1798 len
+= sprintf(p
+ len
, " %02x", v
);
1799 ecdump_regs
[i
+ j
] = v
;
1801 len
+= sprintf(p
+ len
, "\n");
1806 /* These are way too dangerous to advertise openly... */
1808 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
1809 " (<offset> is 00-ff, <value> is 00-ff)\n");
1810 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
1811 " (<offset> is 00-ff, <value> is 0-255)\n");
1816 static int ecdump_write(char *buf
)
1821 while ((cmd
= next_cmd(&buf
))) {
1822 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
1824 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
1828 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
1829 if (!acpi_ec_write(i
, v
))
1838 static struct ibm_struct ecdump_driver_data
= {
1840 .read
= ecdump_read
,
1841 .write
= ecdump_write
,
1842 .flags
.experimental
= 1,
1845 /*************************************************************************
1846 * Backlight/brightness subdriver
1849 static struct backlight_device
*ibm_backlight_device
= NULL
;
1851 static struct backlight_ops ibm_backlight_data
= {
1852 .get_brightness
= brightness_get
,
1853 .update_status
= brightness_update_status
,
1856 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
1860 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
1862 b
= brightness_get(NULL
);
1866 ibm_backlight_device
= backlight_device_register("ibm", NULL
, NULL
,
1867 &ibm_backlight_data
);
1868 if (IS_ERR(ibm_backlight_device
)) {
1869 printk(IBM_ERR
"Could not register backlight device\n");
1870 return PTR_ERR(ibm_backlight_device
);
1872 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
1874 ibm_backlight_device
->props
.max_brightness
= 7;
1875 ibm_backlight_device
->props
.brightness
= b
;
1876 backlight_update_status(ibm_backlight_device
);
1881 static void brightness_exit(void)
1883 if (ibm_backlight_device
) {
1884 vdbg_printk(TPACPI_DBG_EXIT
,
1885 "calling backlight_device_unregister()\n");
1886 backlight_device_unregister(ibm_backlight_device
);
1887 ibm_backlight_device
= NULL
;
1891 static int brightness_update_status(struct backlight_device
*bd
)
1893 return brightness_set(
1894 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
1895 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
1896 bd
->props
.brightness
: 0);
1899 static int brightness_get(struct backlight_device
*bd
)
1902 if (!acpi_ec_read(brightness_offset
, &level
))
1910 static int brightness_set(int value
)
1912 int cmos_cmd
, inc
, i
;
1913 int current_value
= brightness_get(NULL
);
1917 cmos_cmd
= value
> current_value
? TP_CMOS_BRIGHTNESS_UP
: TP_CMOS_BRIGHTNESS_DOWN
;
1918 inc
= value
> current_value
? 1 : -1;
1919 for (i
= current_value
; i
!= value
; i
+= inc
) {
1920 if (!cmos_eval(cmos_cmd
))
1922 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
1929 static int brightness_read(char *p
)
1934 if ((level
= brightness_get(NULL
)) < 0) {
1935 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
1937 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
1938 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
1939 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1940 " (<level> is 0-7)\n");
1946 static int brightness_write(char *buf
)
1952 while ((cmd
= next_cmd(&buf
))) {
1953 if ((level
= brightness_get(NULL
)) < 0)
1957 if (strlencmp(cmd
, "up") == 0) {
1958 new_level
= level
== 7 ? 7 : level
+ 1;
1959 } else if (strlencmp(cmd
, "down") == 0) {
1960 new_level
= level
== 0 ? 0 : level
- 1;
1961 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
1962 new_level
>= 0 && new_level
<= 7) {
1967 brightness_set(new_level
);
1973 static struct ibm_struct brightness_driver_data
= {
1974 .name
= "brightness",
1975 .read
= brightness_read
,
1976 .write
= brightness_write
,
1977 .exit
= brightness_exit
,
1980 /*************************************************************************
1984 static int volume_read(char *p
)
1989 if (!acpi_ec_read(volume_offset
, &level
)) {
1990 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
1992 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
1993 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
1994 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
1995 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1996 " (<level> is 0-15)\n");
2002 static int volume_write(char *buf
)
2004 int cmos_cmd
, inc
, i
;
2006 int new_level
, new_mute
;
2009 while ((cmd
= next_cmd(&buf
))) {
2010 if (!acpi_ec_read(volume_offset
, &level
))
2012 new_mute
= mute
= level
& 0x40;
2013 new_level
= level
= level
& 0xf;
2015 if (strlencmp(cmd
, "up") == 0) {
2019 new_level
= level
== 15 ? 15 : level
+ 1;
2020 } else if (strlencmp(cmd
, "down") == 0) {
2024 new_level
= level
== 0 ? 0 : level
- 1;
2025 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
2026 new_level
>= 0 && new_level
<= 15) {
2028 } else if (strlencmp(cmd
, "mute") == 0) {
2033 if (new_level
!= level
) { /* mute doesn't change */
2034 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
2035 inc
= new_level
> level
? 1 : -1;
2037 if (mute
&& (!cmos_eval(cmos_cmd
) ||
2038 !acpi_ec_write(volume_offset
, level
)))
2041 for (i
= level
; i
!= new_level
; i
+= inc
)
2042 if (!cmos_eval(cmos_cmd
) ||
2043 !acpi_ec_write(volume_offset
, i
+ inc
))
2046 if (mute
&& (!cmos_eval(TP_CMOS_VOLUME_MUTE
) ||
2047 !acpi_ec_write(volume_offset
,
2052 if (new_mute
!= mute
) { /* level doesn't change */
2053 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
2055 if (!cmos_eval(cmos_cmd
) ||
2056 !acpi_ec_write(volume_offset
, level
+ new_mute
))
2064 static struct ibm_struct volume_driver_data
= {
2066 .read
= volume_read
,
2067 .write
= volume_write
,
2070 /*************************************************************************
2077 * TPACPI_FAN_RD_ACPI_GFAN:
2078 * ACPI GFAN method: returns fan level
2080 * see TPACPI_FAN_WR_ACPI_SFAN
2081 * EC 0x2f (HFSP) not available if GFAN exists
2083 * TPACPI_FAN_WR_ACPI_SFAN:
2084 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
2086 * EC 0x2f (HFSP) might be available *for reading*, but do not use
2089 * TPACPI_FAN_WR_TPEC:
2090 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
2091 * Supported on almost all ThinkPads
2093 * Fan speed changes of any sort (including those caused by the
2094 * disengaged mode) are usually done slowly by the firmware as the
2095 * maximum ammount of fan duty cycle change per second seems to be
2098 * Reading is not available if GFAN exists.
2099 * Writing is not available if SFAN exists.
2102 * 7 automatic mode engaged;
2103 * (default operation mode of the ThinkPad)
2104 * fan level is ignored in this mode.
2105 * 6 full speed mode (takes precedence over bit 7);
2106 * not available on all thinkpads. May disable
2107 * the tachometer while the fan controller ramps up
2108 * the speed (which can take up to a few *minutes*).
2109 * Speeds up fan to 100% duty-cycle, which is far above
2110 * the standard RPM levels. It is not impossible that
2111 * it could cause hardware damage.
2112 * 5-3 unused in some models. Extra bits for fan level
2113 * in others, but still useless as all values above
2114 * 7 map to the same speed as level 7 in these models.
2115 * 2-0 fan level (0..7 usually)
2117 * 0x07 = max (set when temperatures critical)
2118 * Some ThinkPads may have other levels, see
2119 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
2121 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
2122 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
2123 * does so, its initial value is meaningless (0x07).
2125 * For firmware bugs, refer to:
2126 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2130 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
2131 * Main fan tachometer reading (in RPM)
2133 * This register is present on all ThinkPads with a new-style EC, and
2134 * it is known not to be present on the A21m/e, and T22, as there is
2135 * something else in offset 0x84 according to the ACPI DSDT. Other
2136 * ThinkPads from this same time period (and earlier) probably lack the
2137 * tachometer as well.
2139 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
2140 * was never fixed by IBM to report the EC firmware version string
2141 * probably support the tachometer (like the early X models), so
2142 * detecting it is quite hard. We need more data to know for sure.
2144 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
2147 * FIRMWARE BUG: may go stale while the EC is switching to full speed
2150 * For firmware bugs, refer to:
2151 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2153 * TPACPI_FAN_WR_ACPI_FANS:
2154 * ThinkPad X31, X40, X41. Not available in the X60.
2156 * FANS ACPI handle: takes three arguments: low speed, medium speed,
2157 * high speed. ACPI DSDT seems to map these three speeds to levels
2158 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
2159 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
2161 * The speeds are stored on handles
2162 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
2164 * There are three default speed sets, acessible as handles:
2165 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
2167 * ACPI DSDT switches which set is in use depending on various
2170 * TPACPI_FAN_WR_TPEC is also available and should be used to
2171 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
2172 * but the ACPI tables just mention level 7.
2175 static enum fan_status_access_mode fan_status_access_mode
;
2176 static enum fan_control_access_mode fan_control_access_mode
;
2177 static enum fan_control_commands fan_control_commands
;
2179 static u8 fan_control_initial_status
;
2181 static void fan_watchdog_fire(struct work_struct
*ignored
);
2182 static int fan_watchdog_maxinterval
;
2183 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
2185 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
2186 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
2187 "\\FSPD", /* 600e/x, 770e, 770x */
2189 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
2190 "JFNS", /* 770x-JL */
2193 static int __init
fan_init(struct ibm_init_struct
*iibm
)
2195 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
2197 fan_status_access_mode
= TPACPI_FAN_NONE
;
2198 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
2199 fan_control_commands
= 0;
2200 fan_watchdog_maxinterval
= 0;
2201 tp_features
.fan_ctrl_status_undef
= 0;
2203 IBM_HANDLE_INIT(fans
);
2204 IBM_HANDLE_INIT(gfan
);
2205 IBM_HANDLE_INIT(sfan
);
2208 /* 570, 600e/x, 770e, 770x */
2209 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
2211 /* all other ThinkPads: note that even old-style
2212 * ThinkPad ECs supports the fan control register */
2213 if (likely(acpi_ec_read(fan_status_offset
,
2214 &fan_control_initial_status
))) {
2215 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
2217 /* In some ThinkPads, neither the EC nor the ACPI
2218 * DSDT initialize the fan status, and it ends up
2219 * being set to 0x07 when it *could* be either
2222 * Enable for TP-1Y (T43), TP-78 (R51e),
2223 * TP-76 (R52), TP-70 (T43, R52), which are known
2225 if (fan_control_initial_status
== 0x07 &&
2226 ibm_thinkpad_ec_found
&&
2227 ((ibm_thinkpad_ec_found
[0] == '1' &&
2228 ibm_thinkpad_ec_found
[1] == 'Y') ||
2229 (ibm_thinkpad_ec_found
[0] == '7' &&
2230 (ibm_thinkpad_ec_found
[1] == '6' ||
2231 ibm_thinkpad_ec_found
[1] == '8' ||
2232 ibm_thinkpad_ec_found
[1] == '0'))
2235 "fan_init: initial fan status is "
2236 "unknown, assuming it is in auto "
2238 tp_features
.fan_ctrl_status_undef
= 1;
2242 "ThinkPad ACPI EC access misbehaving, "
2243 "fan status and control unavailable\n");
2250 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
2251 fan_control_commands
|=
2252 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
2255 /* gfan without sfan means no fan control */
2256 /* all other models implement TP EC 0x2f control */
2260 fan_control_access_mode
=
2261 TPACPI_FAN_WR_ACPI_FANS
;
2262 fan_control_commands
|=
2263 TPACPI_FAN_CMD_SPEED
|
2264 TPACPI_FAN_CMD_LEVEL
|
2265 TPACPI_FAN_CMD_ENABLE
;
2267 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
2268 fan_control_commands
|=
2269 TPACPI_FAN_CMD_LEVEL
|
2270 TPACPI_FAN_CMD_ENABLE
;
2275 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
2276 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
2277 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
2278 fan_status_access_mode
, fan_control_access_mode
);
2280 return (fan_status_access_mode
!= TPACPI_FAN_NONE
||
2281 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
)?
2285 static int fan_get_status(u8
*status
)
2290 * Add TPACPI_FAN_RD_ACPI_FANS ? */
2292 switch (fan_status_access_mode
) {
2293 case TPACPI_FAN_RD_ACPI_GFAN
:
2294 /* 570, 600e/x, 770e, 770x */
2296 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
2304 case TPACPI_FAN_RD_TPEC
:
2305 /* all except 570, 600e/x, 770e, 770x */
2306 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
2321 static void fan_exit(void)
2323 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending watchdogs\n");
2324 cancel_delayed_work(&fan_watchdog_task
);
2325 flush_scheduled_work();
2328 static int fan_get_speed(unsigned int *speed
)
2332 switch (fan_status_access_mode
) {
2333 case TPACPI_FAN_RD_TPEC
:
2334 /* all except 570, 600e/x, 770e, 770x */
2335 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
2336 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
2340 *speed
= (hi
<< 8) | lo
;
2351 static void fan_watchdog_fire(struct work_struct
*ignored
)
2353 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
2354 if (fan_set_enable()) {
2355 printk(IBM_ERR
"fan watchdog: error while enabling fan\n");
2356 /* reschedule for later */
2357 fan_watchdog_reset();
2361 static void fan_watchdog_reset(void)
2363 static int fan_watchdog_active
= 0;
2365 if (fan_watchdog_active
)
2366 cancel_delayed_work(&fan_watchdog_task
);
2368 if (fan_watchdog_maxinterval
> 0) {
2369 fan_watchdog_active
= 1;
2370 if (!schedule_delayed_work(&fan_watchdog_task
,
2371 msecs_to_jiffies(fan_watchdog_maxinterval
2373 printk(IBM_ERR
"failed to schedule the fan watchdog, "
2374 "watchdog will not trigger\n");
2377 fan_watchdog_active
= 0;
2380 static int fan_set_level(int level
)
2382 switch (fan_control_access_mode
) {
2383 case TPACPI_FAN_WR_ACPI_SFAN
:
2384 if (level
>= 0 && level
<= 7) {
2385 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
2391 case TPACPI_FAN_WR_ACPI_FANS
:
2392 case TPACPI_FAN_WR_TPEC
:
2393 if ((level
!= TP_EC_FAN_AUTO
) &&
2394 (level
!= TP_EC_FAN_FULLSPEED
) &&
2395 ((level
< 0) || (level
> 7)))
2398 if (!acpi_ec_write(fan_status_offset
, level
))
2401 tp_features
.fan_ctrl_status_undef
= 0;
2410 static int fan_set_enable(void)
2415 switch (fan_control_access_mode
) {
2416 case TPACPI_FAN_WR_ACPI_FANS
:
2417 case TPACPI_FAN_WR_TPEC
:
2418 if ((rc
= fan_get_status(&s
)) < 0)
2421 /* Don't go out of emergency fan mode */
2425 if (!acpi_ec_write(fan_status_offset
, s
))
2428 tp_features
.fan_ctrl_status_undef
= 0;
2431 case TPACPI_FAN_WR_ACPI_SFAN
:
2432 if ((rc
= fan_get_status(&s
)) < 0)
2437 /* Set fan to at least level 4 */
2441 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
2451 static int fan_set_disable(void)
2453 switch (fan_control_access_mode
) {
2454 case TPACPI_FAN_WR_ACPI_FANS
:
2455 case TPACPI_FAN_WR_TPEC
:
2456 if (!acpi_ec_write(fan_status_offset
, 0x00))
2459 tp_features
.fan_ctrl_status_undef
= 0;
2462 case TPACPI_FAN_WR_ACPI_SFAN
:
2463 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
2473 static int fan_set_speed(int speed
)
2475 switch (fan_control_access_mode
) {
2476 case TPACPI_FAN_WR_ACPI_FANS
:
2477 if (speed
>= 0 && speed
<= 65535) {
2478 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
2479 speed
, speed
, speed
))
2491 static int fan_read(char *p
)
2496 unsigned int speed
= 0;
2498 switch (fan_status_access_mode
) {
2499 case TPACPI_FAN_RD_ACPI_GFAN
:
2500 /* 570, 600e/x, 770e, 770x */
2501 if ((rc
= fan_get_status(&status
)) < 0)
2504 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
2506 (status
!= 0) ? "enabled" : "disabled", status
);
2509 case TPACPI_FAN_RD_TPEC
:
2510 /* all except 570, 600e/x, 770e, 770x */
2511 if ((rc
= fan_get_status(&status
)) < 0)
2514 if (unlikely(tp_features
.fan_ctrl_status_undef
)) {
2515 if (status
!= fan_control_initial_status
)
2516 tp_features
.fan_ctrl_status_undef
= 0;
2518 /* Return most likely status. In fact, it
2519 * might be the only possible status */
2520 status
= TP_EC_FAN_AUTO
;
2523 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2524 (status
!= 0) ? "enabled" : "disabled");
2526 if ((rc
= fan_get_speed(&speed
)) < 0)
2529 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
2531 if (status
& TP_EC_FAN_FULLSPEED
)
2532 /* Disengaged mode takes precedence */
2533 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
2534 else if (status
& TP_EC_FAN_AUTO
)
2535 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
2537 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
2540 case TPACPI_FAN_NONE
:
2542 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2545 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
2546 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
2548 switch (fan_control_access_mode
) {
2549 case TPACPI_FAN_WR_ACPI_SFAN
:
2550 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
2554 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
2555 "auto, disengaged)\n");
2560 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
2561 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
2562 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
2563 "1-120 (seconds))\n");
2565 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
2566 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
2567 " (<speed> is 0-65535)\n");
2572 static int fan_write_cmd_level(const char *cmd
, int *rc
)
2576 if (strlencmp(cmd
, "level auto") == 0)
2577 level
= TP_EC_FAN_AUTO
;
2578 else if (strlencmp(cmd
, "level disengaged") == 0)
2579 level
= TP_EC_FAN_FULLSPEED
;
2580 else if (sscanf(cmd
, "level %d", &level
) != 1)
2583 if ((*rc
= fan_set_level(level
)) == -ENXIO
)
2584 printk(IBM_ERR
"level command accepted for unsupported "
2585 "access mode %d", fan_control_access_mode
);
2590 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
2592 if (strlencmp(cmd
, "enable") != 0)
2595 if ((*rc
= fan_set_enable()) == -ENXIO
)
2596 printk(IBM_ERR
"enable command accepted for unsupported "
2597 "access mode %d", fan_control_access_mode
);
2602 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
2604 if (strlencmp(cmd
, "disable") != 0)
2607 if ((*rc
= fan_set_disable()) == -ENXIO
)
2608 printk(IBM_ERR
"disable command accepted for unsupported "
2609 "access mode %d", fan_control_access_mode
);
2614 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
2619 * Support speed <low> <medium> <high> ? */
2621 if (sscanf(cmd
, "speed %d", &speed
) != 1)
2624 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
2625 printk(IBM_ERR
"speed command accepted for unsupported "
2626 "access mode %d", fan_control_access_mode
);
2631 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
2635 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
2638 if (interval
< 0 || interval
> 120)
2641 fan_watchdog_maxinterval
= interval
;
2646 static int fan_write(char *buf
)
2651 while (!rc
&& (cmd
= next_cmd(&buf
))) {
2652 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
2653 fan_write_cmd_level(cmd
, &rc
)) &&
2654 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
2655 (fan_write_cmd_enable(cmd
, &rc
) ||
2656 fan_write_cmd_disable(cmd
, &rc
) ||
2657 fan_write_cmd_watchdog(cmd
, &rc
))) &&
2658 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
2659 fan_write_cmd_speed(cmd
, &rc
))
2663 fan_watchdog_reset();
2669 static struct ibm_struct fan_driver_data
= {
2674 .flags
.experimental
= 1,
2677 /****************************************************************************
2678 ****************************************************************************
2682 ****************************************************************************
2683 ****************************************************************************/
2686 static struct proc_dir_entry
*proc_dir
= NULL
;
2688 /* Subdriver registry */
2689 static LIST_HEAD(tpacpi_all_drivers
);
2693 * Module and infrastructure proble, init and exit handling
2696 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
2697 static const char * __init
str_supported(int is_supported
)
2699 static char text_unsupported
[] __initdata
= "not supported";
2701 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
2703 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
2705 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
2708 struct ibm_struct
*ibm
= iibm
->data
;
2709 struct proc_dir_entry
*entry
;
2711 BUG_ON(ibm
== NULL
);
2713 INIT_LIST_HEAD(&ibm
->all_drivers
);
2715 if (ibm
->flags
.experimental
&& !experimental
)
2718 dbg_printk(TPACPI_DBG_INIT
,
2719 "probing for %s\n", ibm
->name
);
2722 ret
= iibm
->init(iibm
);
2724 return 0; /* probe failed */
2728 ibm
->flags
.init_called
= 1;
2732 ret
= register_tpacpi_subdriver(ibm
);
2738 ret
= setup_notify(ibm
);
2739 if (ret
== -ENODEV
) {
2740 printk(IBM_NOTICE
"disabling subdriver %s\n",
2749 dbg_printk(TPACPI_DBG_INIT
,
2750 "%s installed\n", ibm
->name
);
2753 entry
= create_proc_entry(ibm
->name
,
2754 S_IFREG
| S_IRUGO
| S_IWUSR
,
2757 printk(IBM_ERR
"unable to create proc entry %s\n",
2762 entry
->owner
= THIS_MODULE
;
2764 entry
->read_proc
= &dispatch_read
;
2766 entry
->write_proc
= &dispatch_write
;
2767 ibm
->flags
.proc_created
= 1;
2770 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
2775 dbg_printk(TPACPI_DBG_INIT
,
2776 "%s: at error exit path with result %d\n",
2780 return (ret
< 0)? ret
: 0;
2783 static void ibm_exit(struct ibm_struct
*ibm
)
2785 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
2787 list_del_init(&ibm
->all_drivers
);
2789 if (ibm
->flags
.notify_installed
) {
2790 dbg_printk(TPACPI_DBG_EXIT
,
2791 "%s: acpi_remove_notify_handler\n", ibm
->name
);
2792 acpi_remove_notify_handler(*ibm
->handle
, ibm
->type
,
2794 ibm
->flags
.notify_installed
= 0;
2797 if (ibm
->flags
.proc_created
) {
2798 dbg_printk(TPACPI_DBG_EXIT
,
2799 "%s: remove_proc_entry\n", ibm
->name
);
2800 remove_proc_entry(ibm
->name
, proc_dir
);
2801 ibm
->flags
.proc_created
= 0;
2804 if (ibm
->flags
.driver_registered
) {
2805 dbg_printk(TPACPI_DBG_EXIT
,
2806 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
2807 acpi_bus_unregister_driver(ibm
->driver
);
2810 ibm
->flags
.driver_registered
= 0;
2813 if (ibm
->flags
.init_called
&& ibm
->exit
) {
2815 ibm
->flags
.init_called
= 0;
2818 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
2823 static char *ibm_thinkpad_ec_found
= NULL
;
2825 static char* __init
check_dmi_for_ec(void)
2827 struct dmi_device
*dev
= NULL
;
2828 char ec_fw_string
[18];
2831 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
2832 * X32 or newer, all Z series; Some models must have an
2833 * up-to-date BIOS or they will not be detected.
2835 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
2837 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
2838 if (sscanf(dev
->name
,
2839 "IBM ThinkPad Embedded Controller -[%17c",
2840 ec_fw_string
) == 1) {
2841 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
2842 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
2843 return kstrdup(ec_fw_string
, GFP_KERNEL
);
2849 static int __init
probe_for_thinkpad(void)
2857 * Non-ancient models have better DMI tagging, but very old models
2860 is_thinkpad
= dmi_name_in_vendors("ThinkPad");
2862 /* ec is required because many other handles are relative to it */
2863 IBM_HANDLE_INIT(ec
);
2867 "Not yet supported ThinkPad detected!\n");
2872 * Risks a regression on very old machines, but reduces potential
2873 * false positives a damn great deal
2876 is_thinkpad
= dmi_name_in_vendors("IBM");
2878 if (!is_thinkpad
&& !force_load
)
2885 /* Module init, exit, parameters */
2887 static struct ibm_init_struct ibms_init
[] __initdata
= {
2889 .init
= thinkpad_acpi_driver_init
,
2890 .data
= &thinkpad_acpi_driver_data
,
2893 .init
= hotkey_init
,
2894 .data
= &hotkey_driver_data
,
2897 .init
= bluetooth_init
,
2898 .data
= &bluetooth_driver_data
,
2902 .data
= &wan_driver_data
,
2906 .data
= &video_driver_data
,
2910 .data
= &light_driver_data
,
2912 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2915 .data
= &dock_driver_data
[0],
2918 .data
= &dock_driver_data
[1],
2921 #ifdef CONFIG_THINKPAD_ACPI_BAY
2924 .data
= &bay_driver_data
,
2929 .data
= &cmos_driver_data
,
2933 .data
= &led_driver_data
,
2937 .data
= &beep_driver_data
,
2940 .init
= thermal_init
,
2941 .data
= &thermal_driver_data
,
2944 .data
= &ecdump_driver_data
,
2947 .init
= brightness_init
,
2948 .data
= &brightness_driver_data
,
2951 .data
= &volume_driver_data
,
2955 .data
= &fan_driver_data
,
2959 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
2962 struct ibm_struct
*ibm
;
2964 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
2965 ibm
= ibms_init
[i
].data
;
2966 BUG_ON(ibm
== NULL
);
2968 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
2969 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
2971 strcpy(ibms_init
[i
].param
, val
);
2972 strcat(ibms_init
[i
].param
, ",");
2980 static int experimental
;
2981 module_param(experimental
, int, 0);
2983 static u32 dbg_level
;
2984 module_param_named(debug
, dbg_level
, uint
, 0);
2986 static int force_load
;
2987 module_param(force_load
, int, 0);
2989 #define IBM_PARAM(feature) \
2990 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
2993 IBM_PARAM(bluetooth
);
2996 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2999 #ifdef CONFIG_THINKPAD_ACPI_BAY
3001 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3006 IBM_PARAM(brightness
);
3010 static int __init
thinkpad_acpi_module_init(void)
3014 ret
= probe_for_thinkpad();
3018 ibm_thinkpad_ec_found
= check_dmi_for_ec();
3019 IBM_HANDLE_INIT(ecrd
);
3020 IBM_HANDLE_INIT(ecwr
);
3022 proc_dir
= proc_mkdir(IBM_DIR
, acpi_root_dir
);
3024 printk(IBM_ERR
"unable to create proc dir %s", IBM_DIR
);
3025 thinkpad_acpi_module_exit();
3028 proc_dir
->owner
= THIS_MODULE
;
3030 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
3031 ret
= ibm_init(&ibms_init
[i
]);
3032 if (ret
>= 0 && *ibms_init
[i
].param
)
3033 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
3035 thinkpad_acpi_module_exit();
3043 static void thinkpad_acpi_module_exit(void)
3045 struct ibm_struct
*ibm
, *itmp
;
3047 list_for_each_entry_safe_reverse(ibm
, itmp
,
3048 &tpacpi_all_drivers
,
3053 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
3056 remove_proc_entry(IBM_DIR
, acpi_root_dir
);
3058 if (ibm_thinkpad_ec_found
)
3059 kfree(ibm_thinkpad_ec_found
);
3062 module_init(thinkpad_acpi_module_init
);
3063 module_exit(thinkpad_acpi_module_exit
);