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 ret
= acpi_bus_get_device(*ibm
->handle
, &ibm
->device
);
318 printk(IBM_ERR
"%s device not present\n", ibm
->name
);
322 acpi_driver_data(ibm
->device
) = ibm
;
323 sprintf(acpi_device_class(ibm
->device
), "%s/%s",
324 IBM_ACPI_EVENT_PREFIX
,
327 status
= acpi_install_notify_handler(*ibm
->handle
, ibm
->type
,
328 dispatch_notify
, ibm
);
329 if (ACPI_FAILURE(status
)) {
330 if (status
== AE_ALREADY_EXISTS
) {
331 printk(IBM_NOTICE
"another device driver is already handling %s events\n",
334 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
339 ibm
->notify_installed
= 1;
343 static int __init
ibm_device_add(struct acpi_device
*device
)
348 static int __init
register_tpacpi_subdriver(struct ibm_struct
*ibm
)
352 ibm
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
354 printk(IBM_ERR
"kzalloc(ibm->driver) failed\n");
358 sprintf(ibm
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
359 ibm
->driver
->ids
= ibm
->hid
;
360 ibm
->driver
->ops
.add
= &ibm_device_add
;
362 ret
= acpi_bus_register_driver(ibm
->driver
);
364 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
369 ibm
->driver_registered
= 1;
375 /****************************************************************************
376 ****************************************************************************
380 ****************************************************************************
381 ****************************************************************************/
383 static int dispatch_read(char *page
, char **start
, off_t off
, int count
,
384 int *eof
, void *data
)
386 struct ibm_struct
*ibm
= data
;
389 if (!ibm
|| !ibm
->read
)
392 len
= ibm
->read(page
);
396 if (len
<= off
+ count
)
408 static int dispatch_write(struct file
*file
, const char __user
* userbuf
,
409 unsigned long count
, void *data
)
411 struct ibm_struct
*ibm
= data
;
415 if (!ibm
|| !ibm
->write
)
418 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
422 if (copy_from_user(kernbuf
, userbuf
, count
)) {
428 strcat(kernbuf
, ",");
429 ret
= ibm
->write(kernbuf
);
438 static char *next_cmd(char **cmds
)
443 while ((end
= strchr(start
, ',')) && end
== start
)
455 /****************************************************************************
456 ****************************************************************************
460 ****************************************************************************
461 ****************************************************************************/
463 /*************************************************************************
464 * thinkpad-acpi init subdriver
467 static int thinkpad_acpi_driver_init(void)
469 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
470 printk(IBM_INFO
"%s\n", IBM_URL
);
472 if (ibm_thinkpad_ec_found
)
473 printk(IBM_INFO
"ThinkPad EC firmware %s\n",
474 ibm_thinkpad_ec_found
);
479 static int thinkpad_acpi_driver_read(char *p
)
483 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
484 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
489 /*************************************************************************
493 static int hotkey_supported
;
494 static int hotkey_mask_supported
;
495 static int hotkey_orig_status
;
496 static int hotkey_orig_mask
;
498 static int hotkey_init(void)
500 IBM_HANDLE_INIT(hkey
);
502 /* hotkey not supported on 570 */
503 hotkey_supported
= hkey_handle
!= NULL
;
505 if (hotkey_supported
) {
506 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
507 A30, R30, R31, T20-22, X20-21, X22-24 */
508 hotkey_mask_supported
=
509 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
511 if (!hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
))
515 return (hotkey_supported
)? 0 : 1;
518 static void hotkey_exit(void)
520 if (hotkey_supported
) {
521 hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
525 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
529 if (acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d"))
530 acpi_bus_generate_event(ibm
->device
, event
, hkey
);
532 printk(IBM_ERR
"unknown hotkey event %d\n", event
);
533 acpi_bus_generate_event(ibm
->device
, event
, 0);
537 static int hotkey_get(int *status
, int *mask
)
539 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
542 if (hotkey_mask_supported
)
543 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
549 static int hotkey_set(int status
, int mask
)
553 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
556 if (hotkey_mask_supported
)
557 for (i
= 0; i
< 32; i
++) {
558 int bit
= ((1 << i
) & mask
) != 0;
559 if (!acpi_evalf(hkey_handle
,
560 NULL
, "MHKM", "vdd", i
+ 1, bit
))
567 static int hotkey_read(char *p
)
572 if (!hotkey_supported
) {
573 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
577 if (!hotkey_get(&status
, &mask
))
580 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
581 if (hotkey_mask_supported
) {
582 len
+= sprintf(p
+ len
, "mask:\t\t0x%04x\n", mask
);
583 len
+= sprintf(p
+ len
,
584 "commands:\tenable, disable, reset, <mask>\n");
586 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
587 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
593 static int hotkey_write(char *buf
)
599 if (!hotkey_supported
)
602 if (!hotkey_get(&status
, &mask
))
605 while ((cmd
= next_cmd(&buf
))) {
606 if (strlencmp(cmd
, "enable") == 0) {
608 } else if (strlencmp(cmd
, "disable") == 0) {
610 } else if (strlencmp(cmd
, "reset") == 0) {
611 status
= hotkey_orig_status
;
612 mask
= hotkey_orig_mask
;
613 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
615 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
622 if (do_cmd
&& !hotkey_set(status
, mask
))
628 /*************************************************************************
629 * Bluetooth subdriver
632 static int bluetooth_supported
;
634 static int bluetooth_init(void)
636 IBM_HANDLE_INIT(hkey
);
638 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
639 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
640 bluetooth_supported
= hkey_handle
&&
641 acpi_evalf(hkey_handle
, NULL
, "GBDC", "qv");
643 return (bluetooth_supported
)? 0 : 1;
646 static int bluetooth_status(void)
650 if (!bluetooth_supported
||
651 !acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
657 static int bluetooth_read(char *p
)
660 int status
= bluetooth_status();
662 if (!bluetooth_supported
)
663 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
664 else if (!(status
& 1))
665 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
667 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
668 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
674 static int bluetooth_write(char *buf
)
676 int status
= bluetooth_status();
680 if (!bluetooth_supported
)
683 while ((cmd
= next_cmd(&buf
))) {
684 if (strlencmp(cmd
, "enable") == 0) {
686 } else if (strlencmp(cmd
, "disable") == 0) {
693 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
699 /*************************************************************************
703 static int wan_supported
;
705 static int wan_init(void)
707 IBM_HANDLE_INIT(hkey
);
709 wan_supported
= hkey_handle
&&
710 acpi_evalf(hkey_handle
, NULL
, "GWAN", "qv");
712 return (wan_supported
)? 0 : 1;
715 static int wan_status(void)
719 if (!wan_supported
|| !acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
725 static int wan_read(char *p
)
728 int status
= wan_status();
731 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
732 else if (!(status
& 1))
733 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
735 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
736 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
742 static int wan_write(char *buf
)
744 int status
= wan_status();
751 while ((cmd
= next_cmd(&buf
))) {
752 if (strlencmp(cmd
, "enable") == 0) {
754 } else if (strlencmp(cmd
, "disable") == 0) {
761 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
767 /*************************************************************************
771 static enum video_access_mode video_supported
;
772 static int video_orig_autosw
;
774 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
775 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
776 "\\_SB.PCI0.VID0", /* 770e */
777 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
778 "\\_SB.PCI0.AGP.VID", /* all others */
781 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
783 static int video_init(void)
787 IBM_HANDLE_INIT(vid
);
788 IBM_HANDLE_INIT(vid2
);
790 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
791 /* G41, assume IVGA doesn't change */
792 vid_handle
= vid2_handle
;
795 /* video switching not supported on R30, R31 */
796 video_supported
= TPACPI_VIDEO_NONE
;
797 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
799 video_supported
= TPACPI_VIDEO_570
;
800 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
801 /* 600e/x, 770e, 770x */
802 video_supported
= TPACPI_VIDEO_770
;
805 video_supported
= TPACPI_VIDEO_NEW
;
807 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
810 static void video_exit(void)
812 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", video_orig_autosw
);
815 static int video_status(void)
820 if (video_supported
== TPACPI_VIDEO_570
) {
821 if (acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd", 0x87))
823 } else if (video_supported
== TPACPI_VIDEO_770
) {
824 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
826 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
828 } else if (video_supported
== TPACPI_VIDEO_NEW
) {
829 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1);
830 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
833 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0);
834 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
836 if (acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
843 static int video_autosw(void)
847 if (video_supported
== TPACPI_VIDEO_570
)
848 acpi_evalf(vid_handle
, &autosw
, "SWIT", "d");
849 else if (video_supported
== TPACPI_VIDEO_770
||
850 video_supported
== TPACPI_VIDEO_NEW
)
851 acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d");
856 static int video_switch(void)
858 int autosw
= video_autosw();
861 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
863 ret
= video_supported
== TPACPI_VIDEO_570
?
864 acpi_evalf(ec_handle
, NULL
, "_Q16", "v") :
865 acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
866 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
871 static int video_expand(void)
873 if (video_supported
== TPACPI_VIDEO_570
)
874 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v");
875 else if (video_supported
== TPACPI_VIDEO_770
)
876 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v");
878 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v");
881 static int video_switch2(int status
)
885 if (video_supported
== TPACPI_VIDEO_570
) {
886 ret
= acpi_evalf(NULL
, NULL
,
887 "\\_SB.PHS2", "vdd", 0x8b, status
| 0x80);
888 } else if (video_supported
== TPACPI_VIDEO_770
) {
889 int autosw
= video_autosw();
890 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
893 ret
= acpi_evalf(vid_handle
, NULL
,
894 "ASWT", "vdd", status
* 0x100, 0);
896 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
898 ret
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
899 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
905 static int video_read(char *p
)
907 int status
= video_status();
908 int autosw
= video_autosw();
911 if (!video_supported
) {
912 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
916 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
917 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
918 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
919 if (video_supported
== TPACPI_VIDEO_NEW
)
920 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
921 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
922 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
923 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
924 if (video_supported
== TPACPI_VIDEO_NEW
)
925 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
926 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
927 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
932 static int video_write(char *buf
)
935 int enable
, disable
, status
;
937 if (!video_supported
)
940 enable
= disable
= 0;
942 while ((cmd
= next_cmd(&buf
))) {
943 if (strlencmp(cmd
, "lcd_enable") == 0) {
945 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
947 } else if (strlencmp(cmd
, "crt_enable") == 0) {
949 } else if (strlencmp(cmd
, "crt_disable") == 0) {
951 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
952 strlencmp(cmd
, "dvi_enable") == 0) {
954 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
955 strlencmp(cmd
, "dvi_disable") == 0) {
957 } else if (strlencmp(cmd
, "auto_enable") == 0) {
958 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
960 } else if (strlencmp(cmd
, "auto_disable") == 0) {
961 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 0))
963 } else if (strlencmp(cmd
, "video_switch") == 0) {
966 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
973 if (enable
|| disable
) {
974 status
= (video_status() & 0x0f & ~disable
) | enable
;
975 if (!video_switch2(status
))
982 /*************************************************************************
983 * Light (thinklight) subdriver
986 static int light_supported
;
987 static int light_status_supported
;
989 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
990 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
992 static int light_init(void)
994 IBM_HANDLE_INIT(ledb
);
995 IBM_HANDLE_INIT(lght
);
996 IBM_HANDLE_INIT(cmos
);
998 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
999 light_supported
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
1001 if (light_supported
)
1002 /* light status not supported on
1003 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1004 light_status_supported
= acpi_evalf(ec_handle
, NULL
,
1007 return (light_supported
)? 0 : 1;
1010 static int light_read(char *p
)
1015 if (!light_supported
) {
1016 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1017 } else if (!light_status_supported
) {
1018 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
1019 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1021 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
1023 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
1024 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1030 static int light_write(char *buf
)
1032 int cmos_cmd
, lght_cmd
;
1036 if (!light_supported
)
1039 while ((cmd
= next_cmd(&buf
))) {
1040 if (strlencmp(cmd
, "on") == 0) {
1043 } else if (strlencmp(cmd
, "off") == 0) {
1049 success
= cmos_handle
?
1050 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
1051 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
1059 /*************************************************************************
1063 #ifdef CONFIG_THINKPAD_ACPI_DOCK
1065 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
1066 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
1067 "\\_SB.PCI0.PCI1.DOCK", /* all others */
1068 "\\_SB.PCI.ISA.SLCE", /* 570 */
1069 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
1071 /* don't list other alternatives as we install a notify handler on the 570 */
1072 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
1074 #define dock_docked() (_sta(dock_handle) & 1)
1076 static int dock_init(void)
1078 IBM_HANDLE_INIT(dock
);
1079 IBM_HANDLE_INIT(pci
);
1081 return (dock_handle
)? 0 : 1;
1084 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
1086 int docked
= dock_docked();
1087 int pci
= ibm
->hid
&& strstr(ibm
->hid
, IBM_PCI_HID
);
1089 if (event
== 1 && !pci
) /* 570 */
1090 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
1091 else if (event
== 1 && pci
) /* 570 */
1092 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
1093 else if (event
== 3 && docked
)
1094 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
1095 else if (event
== 3 && !docked
)
1096 acpi_bus_generate_event(ibm
->device
, event
, 2); /* undock */
1097 else if (event
== 0 && docked
)
1098 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
1100 printk(IBM_ERR
"unknown dock event %d, status %d\n",
1101 event
, _sta(dock_handle
));
1102 acpi_bus_generate_event(ibm
->device
, event
, 0); /* unknown */
1106 static int dock_read(char *p
)
1109 int docked
= dock_docked();
1112 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1114 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
1116 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
1117 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
1123 static int dock_write(char *buf
)
1130 while ((cmd
= next_cmd(&buf
))) {
1131 if (strlencmp(cmd
, "undock") == 0) {
1132 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
1133 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
1135 } else if (strlencmp(cmd
, "dock") == 0) {
1136 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
1145 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
1147 /*************************************************************************
1151 #ifdef CONFIG_THINKPAD_ACPI_BAY
1152 static int bay_status_supported
;
1153 static int bay_status2_supported
;
1154 static int bay_eject_supported
;
1155 static int bay_eject2_supported
;
1157 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
1158 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
1159 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
1160 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
1161 ); /* A21e, R30, R31 */
1162 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
1163 "_EJ0", /* all others */
1164 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
1165 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
1166 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
1168 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
1172 static int bay_init(void)
1174 IBM_HANDLE_INIT(bay
);
1176 IBM_HANDLE_INIT(bay_ej
);
1177 IBM_HANDLE_INIT(bay2
);
1179 IBM_HANDLE_INIT(bay2_ej
);
1181 bay_status_supported
= bay_handle
&&
1182 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
1183 bay_status2_supported
= bay2_handle
&&
1184 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
1186 bay_eject_supported
= bay_handle
&& bay_ej_handle
&&
1187 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
1188 bay_eject2_supported
= bay2_handle
&& bay2_ej_handle
&&
1189 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
1191 return (bay_status_supported
|| bay_eject_supported
||
1192 bay_status2_supported
|| bay_eject2_supported
)? 0 : 1;
1195 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
1197 acpi_bus_generate_event(ibm
->device
, event
, 0);
1200 #define bay_occupied(b) (_sta(b##_handle) & 1)
1202 static int bay_read(char *p
)
1205 int occupied
= bay_occupied(bay
);
1206 int occupied2
= bay_occupied(bay2
);
1209 len
+= sprintf(p
+ len
, "status:\t\t%s\n", bay_status_supported
?
1210 (occupied
? "occupied" : "unoccupied") :
1212 if (bay_status2_supported
)
1213 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
1214 "occupied" : "unoccupied");
1216 eject
= bay_eject_supported
&& occupied
;
1217 eject2
= bay_eject2_supported
&& occupied2
;
1219 if (eject
&& eject2
)
1220 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
1222 len
+= sprintf(p
+ len
, "commands:\teject\n");
1224 len
+= sprintf(p
+ len
, "commands:\teject2\n");
1229 static int bay_write(char *buf
)
1233 if (!bay_eject_supported
&& !bay_eject2_supported
)
1236 while ((cmd
= next_cmd(&buf
))) {
1237 if (bay_eject_supported
&& strlencmp(cmd
, "eject") == 0) {
1238 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
1240 } else if (bay_eject2_supported
&&
1241 strlencmp(cmd
, "eject2") == 0) {
1242 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
1250 #endif /* CONFIG_THINKPAD_ACPI_BAY */
1252 /*************************************************************************
1256 static int cmos_init(void)
1258 IBM_HANDLE_INIT(cmos
);
1260 return (cmos_handle
)? 0 : 1;
1263 static int cmos_eval(int cmos_cmd
)
1266 return acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
);
1271 static int cmos_read(char *p
)
1275 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1276 R30, R31, T20-22, X20-21 */
1278 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1280 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1281 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
1287 static int cmos_write(char *buf
)
1295 while ((cmd
= next_cmd(&buf
))) {
1296 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
1297 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
1302 if (!cmos_eval(cmos_cmd
))
1310 /*************************************************************************
1314 static enum led_access_mode led_supported
;
1316 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
1317 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1318 "LED", /* all others */
1321 static int led_init(void)
1323 IBM_HANDLE_INIT(led
);
1326 /* led not supported on R30, R31 */
1327 led_supported
= TPACPI_LED_NONE
;
1328 else if (strlencmp(led_path
, "SLED") == 0)
1330 led_supported
= TPACPI_LED_570
;
1331 else if (strlencmp(led_path
, "SYSL") == 0)
1332 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1333 led_supported
= TPACPI_LED_OLD
;
1336 led_supported
= TPACPI_LED_NEW
;
1338 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
1341 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1343 static int led_read(char *p
)
1347 if (!led_supported
) {
1348 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1351 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1353 if (led_supported
== TPACPI_LED_570
) {
1356 for (i
= 0; i
< 8; i
++) {
1357 if (!acpi_evalf(ec_handle
,
1358 &status
, "GLED", "dd", 1 << i
))
1360 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
1361 i
, led_status(status
));
1365 len
+= sprintf(p
+ len
, "commands:\t"
1366 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
1371 /* off, on, blink */
1372 static const int led_sled_arg1
[] = { 0, 1, 3 };
1373 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
1374 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
1375 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
1377 static int led_write(char *buf
)
1385 while ((cmd
= next_cmd(&buf
))) {
1386 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
1389 if (strstr(cmd
, "off")) {
1391 } else if (strstr(cmd
, "on")) {
1393 } else if (strstr(cmd
, "blink")) {
1398 if (led_supported
== TPACPI_LED_570
) {
1401 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1402 led
, led_sled_arg1
[ind
]))
1404 } else if (led_supported
== TPACPI_LED_OLD
) {
1405 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1407 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
1410 ec_write(TPACPI_LED_EC_HLBL
,
1411 led
* led_exp_hlbl
[ind
]);
1414 ec_write(TPACPI_LED_EC_HLCL
,
1415 led
* led_exp_hlcl
[ind
]);
1420 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1421 led
, led_led_arg1
[ind
]))
1429 /*************************************************************************
1433 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
1435 static int beep_init(void)
1437 IBM_HANDLE_INIT(beep
);
1439 return (beep_handle
)? 0 : 1;
1442 static int beep_read(char *p
)
1447 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1449 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1450 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
1456 static int beep_write(char *buf
)
1464 while ((cmd
= next_cmd(&buf
))) {
1465 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
1466 beep_cmd
>= 0 && beep_cmd
<= 17) {
1470 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
1477 /*************************************************************************
1481 static enum thermal_access_mode thermal_read_mode
;
1483 static int thermal_init(void)
1489 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
1491 if (ibm_thinkpad_ec_found
&& experimental
) {
1493 * Direct EC access mode: sensors at registers
1494 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
1495 * non-implemented, thermal sensors return 0x80 when
1500 for (i
= 0; i
< 8; i
++) {
1501 if (likely(acpi_ec_read(0x78 + i
, &t
))) {
1507 if (likely(acpi_ec_read(0xC0 + i
, &t
))) {
1515 /* This is sheer paranoia, but we handle it anyway */
1518 "ThinkPad ACPI EC access misbehaving, "
1519 "falling back to ACPI TMPx access mode\n");
1520 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
1523 "ThinkPad ACPI EC access misbehaving, "
1524 "disabling thermal sensors access\n");
1525 thermal_read_mode
= TPACPI_THERMAL_NONE
;
1530 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
1532 } else if (acpi_tmp7
) {
1533 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
1534 /* 600e/x, 770e, 770x */
1535 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
1537 /* Standard ACPI TMPx access, max 8 sensors */
1538 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
1541 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1542 thermal_read_mode
= TPACPI_THERMAL_NONE
;
1545 return (thermal_read_mode
!= TPACPI_THERMAL_NONE
)? 0 : 1;
1548 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
1552 char tmpi
[] = "TMPi";
1557 switch (thermal_read_mode
) {
1558 #if TPACPI_MAX_THERMAL_SENSORS >= 16
1559 case TPACPI_THERMAL_TPEC_16
:
1560 for (i
= 0; i
< 8; i
++) {
1561 if (!acpi_ec_read(0xC0 + i
, &tmp
))
1563 s
->temp
[i
+ 8] = tmp
* 1000;
1567 case TPACPI_THERMAL_TPEC_8
:
1568 for (i
= 0; i
< 8; i
++) {
1569 if (!acpi_ec_read(0x78 + i
, &tmp
))
1571 s
->temp
[i
] = tmp
* 1000;
1573 return (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
) ? 16 : 8;
1575 case TPACPI_THERMAL_ACPI_UPDT
:
1576 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
1578 for (i
= 0; i
< 8; i
++) {
1580 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1582 s
->temp
[i
] = (t
- 2732) * 100;
1586 case TPACPI_THERMAL_ACPI_TMP07
:
1587 for (i
= 0; i
< 8; i
++) {
1589 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1591 s
->temp
[i
] = t
* 1000;
1595 case TPACPI_THERMAL_NONE
:
1601 static int thermal_read(char *p
)
1605 struct ibm_thermal_sensors_struct t
;
1607 n
= thermal_get_sensors(&t
);
1608 if (unlikely(n
< 0))
1611 len
+= sprintf(p
+ len
, "temperatures:\t");
1614 for (i
= 0; i
< (n
- 1); i
++)
1615 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
1616 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
1618 len
+= sprintf(p
+ len
, "not supported\n");
1623 /*************************************************************************
1627 static u8 ecdump_regs
[256];
1629 static int ecdump_read(char *p
)
1635 len
+= sprintf(p
+ len
, "EC "
1636 " +00 +01 +02 +03 +04 +05 +06 +07"
1637 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
1638 for (i
= 0; i
< 256; i
+= 16) {
1639 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
1640 for (j
= 0; j
< 16; j
++) {
1641 if (!acpi_ec_read(i
+ j
, &v
))
1643 if (v
!= ecdump_regs
[i
+ j
])
1644 len
+= sprintf(p
+ len
, " *%02x", v
);
1646 len
+= sprintf(p
+ len
, " %02x", v
);
1647 ecdump_regs
[i
+ j
] = v
;
1649 len
+= sprintf(p
+ len
, "\n");
1654 /* These are way too dangerous to advertise openly... */
1656 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
1657 " (<offset> is 00-ff, <value> is 00-ff)\n");
1658 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
1659 " (<offset> is 00-ff, <value> is 0-255)\n");
1664 static int ecdump_write(char *buf
)
1669 while ((cmd
= next_cmd(&buf
))) {
1670 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
1672 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
1676 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
1677 if (!acpi_ec_write(i
, v
))
1686 /*************************************************************************
1687 * Backlight/brightness subdriver
1690 static struct backlight_device
*ibm_backlight_device
= NULL
;
1692 static struct backlight_ops ibm_backlight_data
= {
1693 .get_brightness
= brightness_get
,
1694 .update_status
= brightness_update_status
,
1697 static int brightness_init(void)
1701 b
= brightness_get(NULL
);
1705 ibm_backlight_device
= backlight_device_register("ibm", NULL
, NULL
,
1706 &ibm_backlight_data
);
1707 if (IS_ERR(ibm_backlight_device
)) {
1708 printk(IBM_ERR
"Could not register backlight device\n");
1709 return PTR_ERR(ibm_backlight_device
);
1712 ibm_backlight_device
->props
.max_brightness
= 7;
1713 ibm_backlight_device
->props
.brightness
= b
;
1714 backlight_update_status(ibm_backlight_device
);
1719 static void brightness_exit(void)
1721 if (ibm_backlight_device
) {
1722 backlight_device_unregister(ibm_backlight_device
);
1723 ibm_backlight_device
= NULL
;
1727 static int brightness_update_status(struct backlight_device
*bd
)
1729 return brightness_set(
1730 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
1731 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
1732 bd
->props
.brightness
: 0);
1735 static int brightness_get(struct backlight_device
*bd
)
1738 if (!acpi_ec_read(brightness_offset
, &level
))
1746 static int brightness_set(int value
)
1748 int cmos_cmd
, inc
, i
;
1749 int current_value
= brightness_get(NULL
);
1753 cmos_cmd
= value
> current_value
? TP_CMOS_BRIGHTNESS_UP
: TP_CMOS_BRIGHTNESS_DOWN
;
1754 inc
= value
> current_value
? 1 : -1;
1755 for (i
= current_value
; i
!= value
; i
+= inc
) {
1756 if (!cmos_eval(cmos_cmd
))
1758 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
1765 static int brightness_read(char *p
)
1770 if ((level
= brightness_get(NULL
)) < 0) {
1771 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
1773 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
1774 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
1775 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1776 " (<level> is 0-7)\n");
1782 static int brightness_write(char *buf
)
1788 while ((cmd
= next_cmd(&buf
))) {
1789 if ((level
= brightness_get(NULL
)) < 0)
1793 if (strlencmp(cmd
, "up") == 0) {
1794 new_level
= level
== 7 ? 7 : level
+ 1;
1795 } else if (strlencmp(cmd
, "down") == 0) {
1796 new_level
= level
== 0 ? 0 : level
- 1;
1797 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
1798 new_level
>= 0 && new_level
<= 7) {
1803 brightness_set(new_level
);
1809 /*************************************************************************
1813 static int volume_read(char *p
)
1818 if (!acpi_ec_read(volume_offset
, &level
)) {
1819 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
1821 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
1822 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
1823 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
1824 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1825 " (<level> is 0-15)\n");
1831 static int volume_write(char *buf
)
1833 int cmos_cmd
, inc
, i
;
1835 int new_level
, new_mute
;
1838 while ((cmd
= next_cmd(&buf
))) {
1839 if (!acpi_ec_read(volume_offset
, &level
))
1841 new_mute
= mute
= level
& 0x40;
1842 new_level
= level
= level
& 0xf;
1844 if (strlencmp(cmd
, "up") == 0) {
1848 new_level
= level
== 15 ? 15 : level
+ 1;
1849 } else if (strlencmp(cmd
, "down") == 0) {
1853 new_level
= level
== 0 ? 0 : level
- 1;
1854 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
1855 new_level
>= 0 && new_level
<= 15) {
1857 } else if (strlencmp(cmd
, "mute") == 0) {
1862 if (new_level
!= level
) { /* mute doesn't change */
1863 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
1864 inc
= new_level
> level
? 1 : -1;
1866 if (mute
&& (!cmos_eval(cmos_cmd
) ||
1867 !acpi_ec_write(volume_offset
, level
)))
1870 for (i
= level
; i
!= new_level
; i
+= inc
)
1871 if (!cmos_eval(cmos_cmd
) ||
1872 !acpi_ec_write(volume_offset
, i
+ inc
))
1875 if (mute
&& (!cmos_eval(TP_CMOS_VOLUME_MUTE
) ||
1876 !acpi_ec_write(volume_offset
,
1881 if (new_mute
!= mute
) { /* level doesn't change */
1882 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
1884 if (!cmos_eval(cmos_cmd
) ||
1885 !acpi_ec_write(volume_offset
, level
+ new_mute
))
1894 /*************************************************************************
1901 * TPACPI_FAN_RD_ACPI_GFAN:
1902 * ACPI GFAN method: returns fan level
1904 * see TPACPI_FAN_WR_ACPI_SFAN
1905 * EC 0x2f (HFSP) not available if GFAN exists
1907 * TPACPI_FAN_WR_ACPI_SFAN:
1908 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
1910 * EC 0x2f (HFSP) might be available *for reading*, but do not use
1913 * TPACPI_FAN_WR_TPEC:
1914 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
1915 * Supported on almost all ThinkPads
1917 * Fan speed changes of any sort (including those caused by the
1918 * disengaged mode) are usually done slowly by the firmware as the
1919 * maximum ammount of fan duty cycle change per second seems to be
1922 * Reading is not available if GFAN exists.
1923 * Writing is not available if SFAN exists.
1926 * 7 automatic mode engaged;
1927 * (default operation mode of the ThinkPad)
1928 * fan level is ignored in this mode.
1929 * 6 full speed mode (takes precedence over bit 7);
1930 * not available on all thinkpads. May disable
1931 * the tachometer while the fan controller ramps up
1932 * the speed (which can take up to a few *minutes*).
1933 * Speeds up fan to 100% duty-cycle, which is far above
1934 * the standard RPM levels. It is not impossible that
1935 * it could cause hardware damage.
1936 * 5-3 unused in some models. Extra bits for fan level
1937 * in others, but still useless as all values above
1938 * 7 map to the same speed as level 7 in these models.
1939 * 2-0 fan level (0..7 usually)
1941 * 0x07 = max (set when temperatures critical)
1942 * Some ThinkPads may have other levels, see
1943 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
1945 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
1946 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
1947 * does so, its initial value is meaningless (0x07).
1949 * For firmware bugs, refer to:
1950 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
1954 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
1955 * Main fan tachometer reading (in RPM)
1957 * This register is present on all ThinkPads with a new-style EC, and
1958 * it is known not to be present on the A21m/e, and T22, as there is
1959 * something else in offset 0x84 according to the ACPI DSDT. Other
1960 * ThinkPads from this same time period (and earlier) probably lack the
1961 * tachometer as well.
1963 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
1964 * was never fixed by IBM to report the EC firmware version string
1965 * probably support the tachometer (like the early X models), so
1966 * detecting it is quite hard. We need more data to know for sure.
1968 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
1971 * FIRMWARE BUG: may go stale while the EC is switching to full speed
1974 * For firmware bugs, refer to:
1975 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
1977 * TPACPI_FAN_WR_ACPI_FANS:
1978 * ThinkPad X31, X40, X41. Not available in the X60.
1980 * FANS ACPI handle: takes three arguments: low speed, medium speed,
1981 * high speed. ACPI DSDT seems to map these three speeds to levels
1982 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
1983 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
1985 * The speeds are stored on handles
1986 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
1988 * There are three default speed sets, acessible as handles:
1989 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
1991 * ACPI DSDT switches which set is in use depending on various
1994 * TPACPI_FAN_WR_TPEC is also available and should be used to
1995 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
1996 * but the ACPI tables just mention level 7.
1999 static enum fan_status_access_mode fan_status_access_mode
;
2000 static enum fan_control_access_mode fan_control_access_mode
;
2001 static enum fan_control_commands fan_control_commands
;
2003 static int fan_control_status_known
;
2004 static u8 fan_control_initial_status
;
2006 static void fan_watchdog_fire(struct work_struct
*ignored
);
2007 static int fan_watchdog_maxinterval
;
2008 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
2010 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
2011 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
2012 "\\FSPD", /* 600e/x, 770e, 770x */
2014 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
2015 "JFNS", /* 770x-JL */
2018 static int fan_init(void)
2020 fan_status_access_mode
= TPACPI_FAN_NONE
;
2021 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
2022 fan_control_commands
= 0;
2023 fan_control_status_known
= 1;
2024 fan_watchdog_maxinterval
= 0;
2026 IBM_HANDLE_INIT(fans
);
2027 IBM_HANDLE_INIT(gfan
);
2028 IBM_HANDLE_INIT(sfan
);
2031 /* 570, 600e/x, 770e, 770x */
2032 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
2034 /* all other ThinkPads: note that even old-style
2035 * ThinkPad ECs supports the fan control register */
2036 if (likely(acpi_ec_read(fan_status_offset
,
2037 &fan_control_initial_status
))) {
2038 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
2040 /* In some ThinkPads, neither the EC nor the ACPI
2041 * DSDT initialize the fan status, and it ends up
2042 * being set to 0x07 when it *could* be either
2045 * Enable for TP-1Y (T43), TP-78 (R51e),
2046 * TP-76 (R52), TP-70 (T43, R52), which are known
2048 if (fan_control_initial_status
== 0x07 &&
2049 ibm_thinkpad_ec_found
&&
2050 ((ibm_thinkpad_ec_found
[0] == '1' &&
2051 ibm_thinkpad_ec_found
[1] == 'Y') ||
2052 (ibm_thinkpad_ec_found
[0] == '7' &&
2053 (ibm_thinkpad_ec_found
[1] == '6' ||
2054 ibm_thinkpad_ec_found
[1] == '8' ||
2055 ibm_thinkpad_ec_found
[1] == '0'))
2058 "fan_init: initial fan status is "
2059 "unknown, assuming it is in auto "
2061 fan_control_status_known
= 0;
2065 "ThinkPad ACPI EC access misbehaving, "
2066 "fan status and control unavailable\n");
2073 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
2074 fan_control_commands
|=
2075 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
2078 /* gfan without sfan means no fan control */
2079 /* all other models implement TP EC 0x2f control */
2083 fan_control_access_mode
=
2084 TPACPI_FAN_WR_ACPI_FANS
;
2085 fan_control_commands
|=
2086 TPACPI_FAN_CMD_SPEED
|
2087 TPACPI_FAN_CMD_LEVEL
|
2088 TPACPI_FAN_CMD_ENABLE
;
2090 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
2091 fan_control_commands
|=
2092 TPACPI_FAN_CMD_LEVEL
|
2093 TPACPI_FAN_CMD_ENABLE
;
2098 return (fan_status_access_mode
!= TPACPI_FAN_NONE
||
2099 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
)?
2103 static int fan_get_status(u8
*status
)
2108 * Add TPACPI_FAN_RD_ACPI_FANS ? */
2110 switch (fan_status_access_mode
) {
2111 case TPACPI_FAN_RD_ACPI_GFAN
:
2112 /* 570, 600e/x, 770e, 770x */
2114 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
2122 case TPACPI_FAN_RD_TPEC
:
2123 /* all except 570, 600e/x, 770e, 770x */
2124 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
2139 static void fan_exit(void)
2141 cancel_delayed_work(&fan_watchdog_task
);
2142 flush_scheduled_work();
2145 static int fan_get_speed(unsigned int *speed
)
2149 switch (fan_status_access_mode
) {
2150 case TPACPI_FAN_RD_TPEC
:
2151 /* all except 570, 600e/x, 770e, 770x */
2152 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
2153 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
2157 *speed
= (hi
<< 8) | lo
;
2168 static void fan_watchdog_fire(struct work_struct
*ignored
)
2170 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
2171 if (fan_set_enable()) {
2172 printk(IBM_ERR
"fan watchdog: error while enabling fan\n");
2173 /* reschedule for later */
2174 fan_watchdog_reset();
2178 static void fan_watchdog_reset(void)
2180 static int fan_watchdog_active
= 0;
2182 if (fan_watchdog_active
)
2183 cancel_delayed_work(&fan_watchdog_task
);
2185 if (fan_watchdog_maxinterval
> 0) {
2186 fan_watchdog_active
= 1;
2187 if (!schedule_delayed_work(&fan_watchdog_task
,
2188 msecs_to_jiffies(fan_watchdog_maxinterval
2190 printk(IBM_ERR
"failed to schedule the fan watchdog, "
2191 "watchdog will not trigger\n");
2194 fan_watchdog_active
= 0;
2197 static int fan_set_level(int level
)
2199 switch (fan_control_access_mode
) {
2200 case TPACPI_FAN_WR_ACPI_SFAN
:
2201 if (level
>= 0 && level
<= 7) {
2202 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
2208 case TPACPI_FAN_WR_ACPI_FANS
:
2209 case TPACPI_FAN_WR_TPEC
:
2210 if ((level
!= TP_EC_FAN_AUTO
) &&
2211 (level
!= TP_EC_FAN_FULLSPEED
) &&
2212 ((level
< 0) || (level
> 7)))
2215 if (!acpi_ec_write(fan_status_offset
, level
))
2218 fan_control_status_known
= 1;
2227 static int fan_set_enable(void)
2232 switch (fan_control_access_mode
) {
2233 case TPACPI_FAN_WR_ACPI_FANS
:
2234 case TPACPI_FAN_WR_TPEC
:
2235 if ((rc
= fan_get_status(&s
)) < 0)
2238 /* Don't go out of emergency fan mode */
2242 if (!acpi_ec_write(fan_status_offset
, s
))
2245 fan_control_status_known
= 1;
2248 case TPACPI_FAN_WR_ACPI_SFAN
:
2249 if ((rc
= fan_get_status(&s
)) < 0)
2254 /* Set fan to at least level 4 */
2258 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
2268 static int fan_set_disable(void)
2270 switch (fan_control_access_mode
) {
2271 case TPACPI_FAN_WR_ACPI_FANS
:
2272 case TPACPI_FAN_WR_TPEC
:
2273 if (!acpi_ec_write(fan_status_offset
, 0x00))
2276 fan_control_status_known
= 1;
2279 case TPACPI_FAN_WR_ACPI_SFAN
:
2280 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
2290 static int fan_set_speed(int speed
)
2292 switch (fan_control_access_mode
) {
2293 case TPACPI_FAN_WR_ACPI_FANS
:
2294 if (speed
>= 0 && speed
<= 65535) {
2295 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
2296 speed
, speed
, speed
))
2308 static int fan_read(char *p
)
2313 unsigned int speed
= 0;
2315 switch (fan_status_access_mode
) {
2316 case TPACPI_FAN_RD_ACPI_GFAN
:
2317 /* 570, 600e/x, 770e, 770x */
2318 if ((rc
= fan_get_status(&status
)) < 0)
2321 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
2323 (status
!= 0) ? "enabled" : "disabled", status
);
2326 case TPACPI_FAN_RD_TPEC
:
2327 /* all except 570, 600e/x, 770e, 770x */
2328 if ((rc
= fan_get_status(&status
)) < 0)
2331 if (unlikely(!fan_control_status_known
)) {
2332 if (status
!= fan_control_initial_status
)
2333 fan_control_status_known
= 1;
2335 /* Return most likely status. In fact, it
2336 * might be the only possible status */
2337 status
= TP_EC_FAN_AUTO
;
2340 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2341 (status
!= 0) ? "enabled" : "disabled");
2343 if ((rc
= fan_get_speed(&speed
)) < 0)
2346 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
2348 if (status
& TP_EC_FAN_FULLSPEED
)
2349 /* Disengaged mode takes precedence */
2350 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
2351 else if (status
& TP_EC_FAN_AUTO
)
2352 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
2354 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
2357 case TPACPI_FAN_NONE
:
2359 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2362 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
2363 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
2365 switch (fan_control_access_mode
) {
2366 case TPACPI_FAN_WR_ACPI_SFAN
:
2367 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
2371 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
2372 "auto, disengaged)\n");
2377 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
2378 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
2379 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
2380 "1-120 (seconds))\n");
2382 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
2383 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
2384 " (<speed> is 0-65535)\n");
2389 static int fan_write_cmd_level(const char *cmd
, int *rc
)
2393 if (strlencmp(cmd
, "level auto") == 0)
2394 level
= TP_EC_FAN_AUTO
;
2395 else if (strlencmp(cmd
, "level disengaged") == 0)
2396 level
= TP_EC_FAN_FULLSPEED
;
2397 else if (sscanf(cmd
, "level %d", &level
) != 1)
2400 if ((*rc
= fan_set_level(level
)) == -ENXIO
)
2401 printk(IBM_ERR
"level command accepted for unsupported "
2402 "access mode %d", fan_control_access_mode
);
2407 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
2409 if (strlencmp(cmd
, "enable") != 0)
2412 if ((*rc
= fan_set_enable()) == -ENXIO
)
2413 printk(IBM_ERR
"enable command accepted for unsupported "
2414 "access mode %d", fan_control_access_mode
);
2419 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
2421 if (strlencmp(cmd
, "disable") != 0)
2424 if ((*rc
= fan_set_disable()) == -ENXIO
)
2425 printk(IBM_ERR
"disable command accepted for unsupported "
2426 "access mode %d", fan_control_access_mode
);
2431 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
2436 * Support speed <low> <medium> <high> ? */
2438 if (sscanf(cmd
, "speed %d", &speed
) != 1)
2441 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
2442 printk(IBM_ERR
"speed command accepted for unsupported "
2443 "access mode %d", fan_control_access_mode
);
2448 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
2452 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
2455 if (interval
< 0 || interval
> 120)
2458 fan_watchdog_maxinterval
= interval
;
2463 static int fan_write(char *buf
)
2468 while (!rc
&& (cmd
= next_cmd(&buf
))) {
2469 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
2470 fan_write_cmd_level(cmd
, &rc
)) &&
2471 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
2472 (fan_write_cmd_enable(cmd
, &rc
) ||
2473 fan_write_cmd_disable(cmd
, &rc
) ||
2474 fan_write_cmd_watchdog(cmd
, &rc
))) &&
2475 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
2476 fan_write_cmd_speed(cmd
, &rc
))
2480 fan_watchdog_reset();
2486 /****************************************************************************
2487 ****************************************************************************
2491 ****************************************************************************
2492 ****************************************************************************/
2495 static struct proc_dir_entry
*proc_dir
= NULL
;
2497 /* Subdriver registry */
2498 static struct ibm_struct ibms
[] = {
2501 .init
= thinkpad_acpi_driver_init
,
2502 .read
= thinkpad_acpi_driver_read
,
2506 .hid
= IBM_HKEY_HID
,
2507 .init
= hotkey_init
,
2508 .read
= hotkey_read
,
2509 .write
= hotkey_write
,
2510 .exit
= hotkey_exit
,
2511 .notify
= hotkey_notify
,
2512 .handle
= &hkey_handle
,
2513 .type
= ACPI_DEVICE_NOTIFY
,
2516 .name
= "bluetooth",
2517 .init
= bluetooth_init
,
2518 .read
= bluetooth_read
,
2519 .write
= bluetooth_write
,
2532 .write
= video_write
,
2539 .write
= light_write
,
2541 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2546 .write
= dock_write
,
2547 .notify
= dock_notify
,
2548 .handle
= &dock_handle
,
2549 .type
= ACPI_SYSTEM_NOTIFY
,
2554 .notify
= dock_notify
,
2555 .handle
= &pci_handle
,
2556 .type
= ACPI_SYSTEM_NOTIFY
,
2559 #ifdef CONFIG_THINKPAD_ACPI_BAY
2565 .notify
= bay_notify
,
2566 .handle
= &bay_handle
,
2567 .type
= ACPI_SYSTEM_NOTIFY
,
2569 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2574 .write
= cmos_write
,
2586 .write
= beep_write
,
2590 .init
= thermal_init
,
2591 .read
= thermal_read
,
2595 .read
= ecdump_read
,
2596 .write
= ecdump_write
,
2600 .name
= "brightness",
2601 .read
= brightness_read
,
2602 .write
= brightness_write
,
2603 .init
= brightness_init
,
2604 .exit
= brightness_exit
,
2608 .read
= volume_read
,
2609 .write
= volume_write
,
2622 * Module and infrastructure proble, init and exit handling
2625 static int __init
ibm_init(struct ibm_struct
*ibm
)
2628 struct proc_dir_entry
*entry
;
2630 if (ibm
->experimental
&& !experimental
)
2636 return 0; /* probe failed */
2639 ibm
->init_called
= 1;
2643 ret
= register_tpacpi_subdriver(ibm
);
2649 ret
= setup_notify(ibm
);
2650 if (ret
== -ENODEV
) {
2651 printk(IBM_NOTICE
"disabling subdriver %s\n",
2661 entry
= create_proc_entry(ibm
->name
,
2662 S_IFREG
| S_IRUGO
| S_IWUSR
,
2665 printk(IBM_ERR
"unable to create proc entry %s\n",
2670 entry
->owner
= THIS_MODULE
;
2672 entry
->read_proc
= &dispatch_read
;
2674 entry
->write_proc
= &dispatch_write
;
2675 ibm
->proc_created
= 1;
2682 return (ret
< 0)? ret
: 0;
2685 static void ibm_exit(struct ibm_struct
*ibm
)
2687 if (ibm
->notify_installed
) {
2688 acpi_remove_notify_handler(*ibm
->handle
, ibm
->type
,
2690 ibm
->notify_installed
= 0;
2693 if (ibm
->proc_created
) {
2694 remove_proc_entry(ibm
->name
, proc_dir
);
2695 ibm
->proc_created
= 0;
2698 if (ibm
->driver_registered
) {
2699 acpi_bus_unregister_driver(ibm
->driver
);
2702 ibm
->driver_registered
= 0;
2705 if (ibm
->init_called
&& ibm
->exit
) {
2707 ibm
->init_called
= 0;
2713 static char *ibm_thinkpad_ec_found
= NULL
;
2715 static char* __init
check_dmi_for_ec(void)
2717 struct dmi_device
*dev
= NULL
;
2718 char ec_fw_string
[18];
2721 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
2722 * X32 or newer, all Z series; Some models must have an
2723 * up-to-date BIOS or they will not be detected.
2725 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
2727 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
2728 if (sscanf(dev
->name
,
2729 "IBM ThinkPad Embedded Controller -[%17c",
2730 ec_fw_string
) == 1) {
2731 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
2732 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
2733 return kstrdup(ec_fw_string
, GFP_KERNEL
);
2739 static int __init
probe_for_thinkpad(void)
2747 * Non-ancient models have better DMI tagging, but very old models
2750 is_thinkpad
= dmi_name_in_vendors("ThinkPad");
2752 /* ec is required because many other handles are relative to it */
2753 IBM_HANDLE_INIT(ec
);
2757 "Not yet supported ThinkPad detected!\n");
2765 /* Module init, exit, parameters */
2767 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
2771 for (i
= 0; i
< ARRAY_SIZE(ibms
); i
++)
2772 if (strcmp(ibms
[i
].name
, kp
->name
) == 0 && ibms
[i
].write
) {
2773 if (strlen(val
) > sizeof(ibms
[i
].param
) - 2)
2775 strcpy(ibms
[i
].param
, val
);
2776 strcat(ibms
[i
].param
, ",");
2783 static int experimental
;
2784 module_param(experimental
, int, 0);
2786 static u32 dbg_level
;
2787 module_param_named(debug
, dbg_level
, uint
, 0);
2789 #define IBM_PARAM(feature) \
2790 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
2793 IBM_PARAM(bluetooth
);
2796 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2799 #ifdef CONFIG_THINKPAD_ACPI_BAY
2801 #endif /* CONFIG_THINKPAD_ACPI_BAY */
2806 IBM_PARAM(brightness
);
2810 static int __init
thinkpad_acpi_module_init(void)
2814 ret
= probe_for_thinkpad();
2818 ibm_thinkpad_ec_found
= check_dmi_for_ec();
2819 IBM_HANDLE_INIT(ecrd
);
2820 IBM_HANDLE_INIT(ecwr
);
2822 proc_dir
= proc_mkdir(IBM_DIR
, acpi_root_dir
);
2824 printk(IBM_ERR
"unable to create proc dir %s", IBM_DIR
);
2825 thinkpad_acpi_module_exit();
2828 proc_dir
->owner
= THIS_MODULE
;
2830 for (i
= 0; i
< ARRAY_SIZE(ibms
); i
++) {
2831 ret
= ibm_init(&ibms
[i
]);
2832 if (ret
>= 0 && *ibms
[i
].param
)
2833 ret
= ibms
[i
].write(ibms
[i
].param
);
2835 thinkpad_acpi_module_exit();
2843 static void thinkpad_acpi_module_exit(void)
2847 for (i
= ARRAY_SIZE(ibms
) - 1; i
>= 0; i
--)
2851 remove_proc_entry(IBM_DIR
, acpi_root_dir
);
2853 if (ibm_thinkpad_ec_found
)
2854 kfree(ibm_thinkpad_ec_found
);
2857 module_init(thinkpad_acpi_module_init
);
2858 module_exit(thinkpad_acpi_module_exit
);