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_supported
;
505 static int hotkey_mask_supported
;
506 static int hotkey_orig_status
;
507 static int hotkey_orig_mask
;
509 static int __init
hotkey_init(struct ibm_init_struct
*iibm
)
511 vdbg_printk(TPACPI_DBG_INIT
, "initializing hotkey subdriver\n");
513 IBM_HANDLE_INIT(hkey
);
515 /* hotkey not supported on 570 */
516 hotkey_supported
= hkey_handle
!= NULL
;
518 vdbg_printk(TPACPI_DBG_INIT
, "hotkeys are %s\n",
519 str_supported(hotkey_supported
));
521 if (hotkey_supported
) {
522 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
523 A30, R30, R31, T20-22, X20-21, X22-24 */
524 hotkey_mask_supported
=
525 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
527 vdbg_printk(TPACPI_DBG_INIT
, "hotkey masks are %s\n",
528 str_supported(hotkey_mask_supported
));
530 if (!hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
))
534 return (hotkey_supported
)? 0 : 1;
537 static void hotkey_exit(void)
539 if (hotkey_supported
) {
540 dbg_printk(TPACPI_DBG_EXIT
, "restoring original hotkey mask\n");
541 hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
545 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
549 if (acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d"))
550 acpi_bus_generate_event(ibm
->device
, event
, hkey
);
552 printk(IBM_ERR
"unknown hotkey event %d\n", event
);
553 acpi_bus_generate_event(ibm
->device
, event
, 0);
557 static int hotkey_get(int *status
, int *mask
)
559 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
562 if (hotkey_mask_supported
)
563 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
569 static int hotkey_set(int status
, int mask
)
573 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
576 if (hotkey_mask_supported
)
577 for (i
= 0; i
< 32; i
++) {
578 int bit
= ((1 << i
) & mask
) != 0;
579 if (!acpi_evalf(hkey_handle
,
580 NULL
, "MHKM", "vdd", i
+ 1, bit
))
587 static int hotkey_read(char *p
)
592 if (!hotkey_supported
) {
593 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
597 if (!hotkey_get(&status
, &mask
))
600 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
601 if (hotkey_mask_supported
) {
602 len
+= sprintf(p
+ len
, "mask:\t\t0x%04x\n", mask
);
603 len
+= sprintf(p
+ len
,
604 "commands:\tenable, disable, reset, <mask>\n");
606 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
607 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
613 static int hotkey_write(char *buf
)
619 if (!hotkey_supported
)
622 if (!hotkey_get(&status
, &mask
))
625 while ((cmd
= next_cmd(&buf
))) {
626 if (strlencmp(cmd
, "enable") == 0) {
628 } else if (strlencmp(cmd
, "disable") == 0) {
630 } else if (strlencmp(cmd
, "reset") == 0) {
631 status
= hotkey_orig_status
;
632 mask
= hotkey_orig_mask
;
633 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
635 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
642 if (do_cmd
&& !hotkey_set(status
, mask
))
648 static struct ibm_struct hotkey_driver_data
= {
652 .write
= hotkey_write
,
654 .notify
= hotkey_notify
,
655 .handle
= &hkey_handle
,
656 .type
= ACPI_DEVICE_NOTIFY
,
659 /*************************************************************************
660 * Bluetooth subdriver
663 static int bluetooth_supported
;
665 static int __init
bluetooth_init(struct ibm_init_struct
*iibm
)
667 vdbg_printk(TPACPI_DBG_INIT
, "initializing bluetooth subdriver\n");
669 IBM_HANDLE_INIT(hkey
);
671 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
672 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
673 bluetooth_supported
= hkey_handle
&&
674 acpi_evalf(hkey_handle
, NULL
, "GBDC", "qv");
676 vdbg_printk(TPACPI_DBG_INIT
, "bluetooth is %s\n",
677 str_supported(bluetooth_supported
));
679 return (bluetooth_supported
)? 0 : 1;
682 static int bluetooth_status(void)
686 if (!bluetooth_supported
||
687 !acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
693 static int bluetooth_read(char *p
)
696 int status
= bluetooth_status();
698 if (!bluetooth_supported
)
699 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
700 else if (!(status
& 1))
701 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
703 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
704 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
710 static int bluetooth_write(char *buf
)
712 int status
= bluetooth_status();
716 if (!bluetooth_supported
)
719 while ((cmd
= next_cmd(&buf
))) {
720 if (strlencmp(cmd
, "enable") == 0) {
722 } else if (strlencmp(cmd
, "disable") == 0) {
729 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
735 static struct ibm_struct bluetooth_driver_data
= {
737 .read
= bluetooth_read
,
738 .write
= bluetooth_write
,
741 /*************************************************************************
745 static int wan_supported
;
747 static int __init
wan_init(struct ibm_init_struct
*iibm
)
749 vdbg_printk(TPACPI_DBG_INIT
, "initializing wan subdriver\n");
751 IBM_HANDLE_INIT(hkey
);
753 wan_supported
= hkey_handle
&&
754 acpi_evalf(hkey_handle
, NULL
, "GWAN", "qv");
756 vdbg_printk(TPACPI_DBG_INIT
, "wan is %s\n",
757 str_supported(wan_supported
));
759 return (wan_supported
)? 0 : 1;
762 static int wan_status(void)
766 if (!wan_supported
|| !acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
772 static int wan_read(char *p
)
775 int status
= wan_status();
778 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
779 else if (!(status
& 1))
780 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
782 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
783 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
789 static int wan_write(char *buf
)
791 int status
= wan_status();
798 while ((cmd
= next_cmd(&buf
))) {
799 if (strlencmp(cmd
, "enable") == 0) {
801 } else if (strlencmp(cmd
, "disable") == 0) {
808 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
814 static struct ibm_struct wan_driver_data
= {
818 .flags
.experimental
= 1,
821 /*************************************************************************
825 static enum video_access_mode video_supported
;
826 static int video_orig_autosw
;
828 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
829 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
830 "\\_SB.PCI0.VID0", /* 770e */
831 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
832 "\\_SB.PCI0.AGP.VID", /* all others */
835 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
837 static int __init
video_init(struct ibm_init_struct
*iibm
)
841 vdbg_printk(TPACPI_DBG_INIT
, "initializing video subdriver\n");
843 IBM_HANDLE_INIT(vid
);
844 IBM_HANDLE_INIT(vid2
);
846 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
847 /* G41, assume IVGA doesn't change */
848 vid_handle
= vid2_handle
;
851 /* video switching not supported on R30, R31 */
852 video_supported
= TPACPI_VIDEO_NONE
;
853 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
855 video_supported
= TPACPI_VIDEO_570
;
856 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
857 /* 600e/x, 770e, 770x */
858 video_supported
= TPACPI_VIDEO_770
;
861 video_supported
= TPACPI_VIDEO_NEW
;
863 vdbg_printk(TPACPI_DBG_INIT
, "video is %s, mode %d\n",
864 str_supported(video_supported
!= TPACPI_VIDEO_NONE
),
867 return (video_supported
!= TPACPI_VIDEO_NONE
)? 0 : 1;
870 static void video_exit(void)
872 dbg_printk(TPACPI_DBG_EXIT
, "restoring original video autoswitch mode\n");
873 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", video_orig_autosw
);
876 static int video_status(void)
881 if (video_supported
== TPACPI_VIDEO_570
) {
882 if (acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd", 0x87))
884 } else if (video_supported
== TPACPI_VIDEO_770
) {
885 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
887 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
889 } else if (video_supported
== TPACPI_VIDEO_NEW
) {
890 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1);
891 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
894 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0);
895 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
897 if (acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
904 static int video_autosw(void)
908 if (video_supported
== TPACPI_VIDEO_570
)
909 acpi_evalf(vid_handle
, &autosw
, "SWIT", "d");
910 else if (video_supported
== TPACPI_VIDEO_770
||
911 video_supported
== TPACPI_VIDEO_NEW
)
912 acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d");
917 static int video_switch(void)
919 int autosw
= video_autosw();
922 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
924 ret
= video_supported
== TPACPI_VIDEO_570
?
925 acpi_evalf(ec_handle
, NULL
, "_Q16", "v") :
926 acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
927 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
932 static int video_expand(void)
934 if (video_supported
== TPACPI_VIDEO_570
)
935 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v");
936 else if (video_supported
== TPACPI_VIDEO_770
)
937 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v");
939 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v");
942 static int video_switch2(int status
)
946 if (video_supported
== TPACPI_VIDEO_570
) {
947 ret
= acpi_evalf(NULL
, NULL
,
948 "\\_SB.PHS2", "vdd", 0x8b, status
| 0x80);
949 } else if (video_supported
== TPACPI_VIDEO_770
) {
950 int autosw
= video_autosw();
951 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
954 ret
= acpi_evalf(vid_handle
, NULL
,
955 "ASWT", "vdd", status
* 0x100, 0);
957 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
959 ret
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
960 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
966 static int video_read(char *p
)
968 int status
= video_status();
969 int autosw
= video_autosw();
972 if (!video_supported
) {
973 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
977 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
978 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
979 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
980 if (video_supported
== TPACPI_VIDEO_NEW
)
981 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
982 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
983 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
984 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
985 if (video_supported
== TPACPI_VIDEO_NEW
)
986 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
987 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
988 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
993 static int video_write(char *buf
)
996 int enable
, disable
, status
;
998 if (!video_supported
)
1001 enable
= disable
= 0;
1003 while ((cmd
= next_cmd(&buf
))) {
1004 if (strlencmp(cmd
, "lcd_enable") == 0) {
1006 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
1008 } else if (strlencmp(cmd
, "crt_enable") == 0) {
1010 } else if (strlencmp(cmd
, "crt_disable") == 0) {
1012 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1013 strlencmp(cmd
, "dvi_enable") == 0) {
1015 } else if (video_supported
== TPACPI_VIDEO_NEW
&&
1016 strlencmp(cmd
, "dvi_disable") == 0) {
1018 } else if (strlencmp(cmd
, "auto_enable") == 0) {
1019 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
1021 } else if (strlencmp(cmd
, "auto_disable") == 0) {
1022 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 0))
1024 } else if (strlencmp(cmd
, "video_switch") == 0) {
1025 if (!video_switch())
1027 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
1028 if (!video_expand())
1034 if (enable
|| disable
) {
1035 status
= (video_status() & 0x0f & ~disable
) | enable
;
1036 if (!video_switch2(status
))
1043 static struct ibm_struct video_driver_data
= {
1046 .write
= video_write
,
1050 /*************************************************************************
1051 * Light (thinklight) subdriver
1054 static int light_supported
;
1055 static int light_status_supported
;
1057 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1058 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
1060 static int __init
light_init(struct ibm_init_struct
*iibm
)
1062 vdbg_printk(TPACPI_DBG_INIT
, "initializing light subdriver\n");
1064 IBM_HANDLE_INIT(ledb
);
1065 IBM_HANDLE_INIT(lght
);
1066 IBM_HANDLE_INIT(cmos
);
1068 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
1069 light_supported
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
1071 if (light_supported
)
1072 /* light status not supported on
1073 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1074 light_status_supported
= acpi_evalf(ec_handle
, NULL
,
1077 vdbg_printk(TPACPI_DBG_INIT
, "light is %s\n",
1078 str_supported(light_supported
));
1080 return (light_supported
)? 0 : 1;
1083 static int light_read(char *p
)
1088 if (!light_supported
) {
1089 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1090 } else if (!light_status_supported
) {
1091 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
1092 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1094 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
1096 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
1097 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1103 static int light_write(char *buf
)
1105 int cmos_cmd
, lght_cmd
;
1109 if (!light_supported
)
1112 while ((cmd
= next_cmd(&buf
))) {
1113 if (strlencmp(cmd
, "on") == 0) {
1116 } else if (strlencmp(cmd
, "off") == 0) {
1122 success
= cmos_handle
?
1123 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
1124 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
1132 static struct ibm_struct light_driver_data
= {
1135 .write
= light_write
,
1138 /*************************************************************************
1142 #ifdef CONFIG_THINKPAD_ACPI_DOCK
1144 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
1145 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
1146 "\\_SB.PCI0.PCI1.DOCK", /* all others */
1147 "\\_SB.PCI.ISA.SLCE", /* 570 */
1148 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
1150 /* don't list other alternatives as we install a notify handler on the 570 */
1151 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
1153 #define dock_docked() (_sta(dock_handle) & 1)
1155 static int __init
dock_init(struct ibm_init_struct
*iibm
)
1157 vdbg_printk(TPACPI_DBG_INIT
, "initializing dock subdriver\n");
1159 IBM_HANDLE_INIT(dock
);
1160 IBM_HANDLE_INIT(pci
);
1162 vdbg_printk(TPACPI_DBG_INIT
, "dock is %s\n",
1163 str_supported(dock_handle
!= NULL
));
1165 return (dock_handle
)? 0 : 1;
1168 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
1170 int docked
= dock_docked();
1171 int pci
= ibm
->hid
&& strstr(ibm
->hid
, IBM_PCI_HID
);
1173 if (event
== 1 && !pci
) /* 570 */
1174 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
1175 else if (event
== 1 && pci
) /* 570 */
1176 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
1177 else if (event
== 3 && docked
)
1178 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
1179 else if (event
== 3 && !docked
)
1180 acpi_bus_generate_event(ibm
->device
, event
, 2); /* undock */
1181 else if (event
== 0 && docked
)
1182 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
1184 printk(IBM_ERR
"unknown dock event %d, status %d\n",
1185 event
, _sta(dock_handle
));
1186 acpi_bus_generate_event(ibm
->device
, event
, 0); /* unknown */
1190 static int dock_read(char *p
)
1193 int docked
= dock_docked();
1196 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1198 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
1200 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
1201 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
1207 static int dock_write(char *buf
)
1214 while ((cmd
= next_cmd(&buf
))) {
1215 if (strlencmp(cmd
, "undock") == 0) {
1216 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
1217 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
1219 } else if (strlencmp(cmd
, "dock") == 0) {
1220 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
1229 static struct ibm_struct dock_driver_data
[2] = {
1233 .write
= dock_write
,
1234 .notify
= dock_notify
,
1235 .handle
= &dock_handle
,
1236 .type
= ACPI_SYSTEM_NOTIFY
,
1241 .notify
= dock_notify
,
1242 .handle
= &pci_handle
,
1243 .type
= ACPI_SYSTEM_NOTIFY
,
1247 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
1249 /*************************************************************************
1253 #ifdef CONFIG_THINKPAD_ACPI_BAY
1254 static int bay_status_supported
;
1255 static int bay_status2_supported
;
1256 static int bay_eject_supported
;
1257 static int bay_eject2_supported
;
1259 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
1260 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
1261 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
1262 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
1263 ); /* A21e, R30, R31 */
1264 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
1265 "_EJ0", /* all others */
1266 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
1267 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
1268 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
1270 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
1274 static int __init
bay_init(struct ibm_init_struct
*iibm
)
1276 vdbg_printk(TPACPI_DBG_INIT
, "initializing bay subdriver\n");
1278 IBM_HANDLE_INIT(bay
);
1280 IBM_HANDLE_INIT(bay_ej
);
1281 IBM_HANDLE_INIT(bay2
);
1283 IBM_HANDLE_INIT(bay2_ej
);
1285 bay_status_supported
= bay_handle
&&
1286 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
1287 bay_status2_supported
= bay2_handle
&&
1288 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
1290 bay_eject_supported
= bay_handle
&& bay_ej_handle
&&
1291 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
1292 bay_eject2_supported
= bay2_handle
&& bay2_ej_handle
&&
1293 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
1295 vdbg_printk(TPACPI_DBG_INIT
,
1296 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
1297 str_supported(bay_status_supported
),
1298 str_supported(bay_eject_supported
),
1299 str_supported(bay_status2_supported
),
1300 str_supported(bay_eject2_supported
));
1302 return (bay_status_supported
|| bay_eject_supported
||
1303 bay_status2_supported
|| bay_eject2_supported
)? 0 : 1;
1306 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
1308 acpi_bus_generate_event(ibm
->device
, event
, 0);
1311 #define bay_occupied(b) (_sta(b##_handle) & 1)
1313 static int bay_read(char *p
)
1316 int occupied
= bay_occupied(bay
);
1317 int occupied2
= bay_occupied(bay2
);
1320 len
+= sprintf(p
+ len
, "status:\t\t%s\n", bay_status_supported
?
1321 (occupied
? "occupied" : "unoccupied") :
1323 if (bay_status2_supported
)
1324 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
1325 "occupied" : "unoccupied");
1327 eject
= bay_eject_supported
&& occupied
;
1328 eject2
= bay_eject2_supported
&& occupied2
;
1330 if (eject
&& eject2
)
1331 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
1333 len
+= sprintf(p
+ len
, "commands:\teject\n");
1335 len
+= sprintf(p
+ len
, "commands:\teject2\n");
1340 static int bay_write(char *buf
)
1344 if (!bay_eject_supported
&& !bay_eject2_supported
)
1347 while ((cmd
= next_cmd(&buf
))) {
1348 if (bay_eject_supported
&& strlencmp(cmd
, "eject") == 0) {
1349 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
1351 } else if (bay_eject2_supported
&&
1352 strlencmp(cmd
, "eject2") == 0) {
1353 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
1362 static struct ibm_struct bay_driver_data
= {
1366 .notify
= bay_notify
,
1367 .handle
= &bay_handle
,
1368 .type
= ACPI_SYSTEM_NOTIFY
,
1371 #endif /* CONFIG_THINKPAD_ACPI_BAY */
1373 /*************************************************************************
1377 static int __init
cmos_init(struct ibm_init_struct
*iibm
)
1379 vdbg_printk(TPACPI_DBG_INIT
,
1380 "initializing cmos commands subdriver\n");
1382 IBM_HANDLE_INIT(cmos
);
1384 vdbg_printk(TPACPI_DBG_INIT
, "cmos commands are %s\n",
1385 str_supported(cmos_handle
!= NULL
));
1386 return (cmos_handle
)? 0 : 1;
1389 static int cmos_eval(int cmos_cmd
)
1392 return acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
);
1397 static int cmos_read(char *p
)
1401 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1402 R30, R31, T20-22, X20-21 */
1404 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1406 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1407 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
1413 static int cmos_write(char *buf
)
1421 while ((cmd
= next_cmd(&buf
))) {
1422 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
1423 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
1428 if (!cmos_eval(cmos_cmd
))
1435 static struct ibm_struct cmos_driver_data
= {
1438 .write
= cmos_write
,
1441 /*************************************************************************
1445 static enum led_access_mode led_supported
;
1447 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
1448 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1449 "LED", /* all others */
1452 static int __init
led_init(struct ibm_init_struct
*iibm
)
1454 vdbg_printk(TPACPI_DBG_INIT
, "initializing LED subdriver\n");
1456 IBM_HANDLE_INIT(led
);
1459 /* led not supported on R30, R31 */
1460 led_supported
= TPACPI_LED_NONE
;
1461 else if (strlencmp(led_path
, "SLED") == 0)
1463 led_supported
= TPACPI_LED_570
;
1464 else if (strlencmp(led_path
, "SYSL") == 0)
1465 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1466 led_supported
= TPACPI_LED_OLD
;
1469 led_supported
= TPACPI_LED_NEW
;
1471 vdbg_printk(TPACPI_DBG_INIT
, "LED commands are %s, mode %d\n",
1472 str_supported(led_supported
), led_supported
);
1474 return (led_supported
!= TPACPI_LED_NONE
)? 0 : 1;
1477 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1479 static int led_read(char *p
)
1483 if (!led_supported
) {
1484 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1487 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1489 if (led_supported
== TPACPI_LED_570
) {
1492 for (i
= 0; i
< 8; i
++) {
1493 if (!acpi_evalf(ec_handle
,
1494 &status
, "GLED", "dd", 1 << i
))
1496 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
1497 i
, led_status(status
));
1501 len
+= sprintf(p
+ len
, "commands:\t"
1502 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
1507 /* off, on, blink */
1508 static const int led_sled_arg1
[] = { 0, 1, 3 };
1509 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
1510 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
1511 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
1513 static int led_write(char *buf
)
1521 while ((cmd
= next_cmd(&buf
))) {
1522 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
1525 if (strstr(cmd
, "off")) {
1527 } else if (strstr(cmd
, "on")) {
1529 } else if (strstr(cmd
, "blink")) {
1534 if (led_supported
== TPACPI_LED_570
) {
1537 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1538 led
, led_sled_arg1
[ind
]))
1540 } else if (led_supported
== TPACPI_LED_OLD
) {
1541 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1543 ret
= ec_write(TPACPI_LED_EC_HLMS
, led
);
1546 ec_write(TPACPI_LED_EC_HLBL
,
1547 led
* led_exp_hlbl
[ind
]);
1550 ec_write(TPACPI_LED_EC_HLCL
,
1551 led
* led_exp_hlcl
[ind
]);
1556 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1557 led
, led_led_arg1
[ind
]))
1565 static struct ibm_struct led_driver_data
= {
1571 /*************************************************************************
1575 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
1577 static int __init
beep_init(struct ibm_init_struct
*iibm
)
1579 vdbg_printk(TPACPI_DBG_INIT
, "initializing beep subdriver\n");
1581 IBM_HANDLE_INIT(beep
);
1583 vdbg_printk(TPACPI_DBG_INIT
, "beep is %s\n",
1584 str_supported(beep_handle
!= NULL
));
1586 return (beep_handle
)? 0 : 1;
1589 static int beep_read(char *p
)
1594 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1596 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1597 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
1603 static int beep_write(char *buf
)
1611 while ((cmd
= next_cmd(&buf
))) {
1612 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
1613 beep_cmd
>= 0 && beep_cmd
<= 17) {
1617 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
1624 static struct ibm_struct beep_driver_data
= {
1627 .write
= beep_write
,
1630 /*************************************************************************
1634 static enum thermal_access_mode thermal_read_mode
;
1636 static int __init
thermal_init(struct ibm_init_struct
*iibm
)
1642 vdbg_printk(TPACPI_DBG_INIT
, "initializing thermal subdriver\n");
1644 acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
1646 if (ibm_thinkpad_ec_found
&& experimental
) {
1648 * Direct EC access mode: sensors at registers
1649 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
1650 * non-implemented, thermal sensors return 0x80 when
1655 for (i
= 0; i
< 8; i
++) {
1656 if (likely(acpi_ec_read(0x78 + i
, &t
))) {
1662 if (likely(acpi_ec_read(0xC0 + i
, &t
))) {
1670 /* This is sheer paranoia, but we handle it anyway */
1673 "ThinkPad ACPI EC access misbehaving, "
1674 "falling back to ACPI TMPx access mode\n");
1675 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
1678 "ThinkPad ACPI EC access misbehaving, "
1679 "disabling thermal sensors access\n");
1680 thermal_read_mode
= TPACPI_THERMAL_NONE
;
1685 TPACPI_THERMAL_TPEC_16
: TPACPI_THERMAL_TPEC_8
;
1687 } else if (acpi_tmp7
) {
1688 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
1689 /* 600e/x, 770e, 770x */
1690 thermal_read_mode
= TPACPI_THERMAL_ACPI_UPDT
;
1692 /* Standard ACPI TMPx access, max 8 sensors */
1693 thermal_read_mode
= TPACPI_THERMAL_ACPI_TMP07
;
1696 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1697 thermal_read_mode
= TPACPI_THERMAL_NONE
;
1700 vdbg_printk(TPACPI_DBG_INIT
, "thermal is %s, mode %d\n",
1701 str_supported(thermal_read_mode
!= TPACPI_THERMAL_NONE
),
1704 return (thermal_read_mode
!= TPACPI_THERMAL_NONE
)? 0 : 1;
1707 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
1711 char tmpi
[] = "TMPi";
1716 switch (thermal_read_mode
) {
1717 #if TPACPI_MAX_THERMAL_SENSORS >= 16
1718 case TPACPI_THERMAL_TPEC_16
:
1719 for (i
= 0; i
< 8; i
++) {
1720 if (!acpi_ec_read(0xC0 + i
, &tmp
))
1722 s
->temp
[i
+ 8] = tmp
* 1000;
1726 case TPACPI_THERMAL_TPEC_8
:
1727 for (i
= 0; i
< 8; i
++) {
1728 if (!acpi_ec_read(0x78 + i
, &tmp
))
1730 s
->temp
[i
] = tmp
* 1000;
1732 return (thermal_read_mode
== TPACPI_THERMAL_TPEC_16
) ? 16 : 8;
1734 case TPACPI_THERMAL_ACPI_UPDT
:
1735 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
1737 for (i
= 0; i
< 8; i
++) {
1739 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1741 s
->temp
[i
] = (t
- 2732) * 100;
1745 case TPACPI_THERMAL_ACPI_TMP07
:
1746 for (i
= 0; i
< 8; i
++) {
1748 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1750 s
->temp
[i
] = t
* 1000;
1754 case TPACPI_THERMAL_NONE
:
1760 static int thermal_read(char *p
)
1764 struct ibm_thermal_sensors_struct t
;
1766 n
= thermal_get_sensors(&t
);
1767 if (unlikely(n
< 0))
1770 len
+= sprintf(p
+ len
, "temperatures:\t");
1773 for (i
= 0; i
< (n
- 1); i
++)
1774 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
1775 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
1777 len
+= sprintf(p
+ len
, "not supported\n");
1782 static struct ibm_struct thermal_driver_data
= {
1784 .read
= thermal_read
,
1787 /*************************************************************************
1791 static u8 ecdump_regs
[256];
1793 static int ecdump_read(char *p
)
1799 len
+= sprintf(p
+ len
, "EC "
1800 " +00 +01 +02 +03 +04 +05 +06 +07"
1801 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
1802 for (i
= 0; i
< 256; i
+= 16) {
1803 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
1804 for (j
= 0; j
< 16; j
++) {
1805 if (!acpi_ec_read(i
+ j
, &v
))
1807 if (v
!= ecdump_regs
[i
+ j
])
1808 len
+= sprintf(p
+ len
, " *%02x", v
);
1810 len
+= sprintf(p
+ len
, " %02x", v
);
1811 ecdump_regs
[i
+ j
] = v
;
1813 len
+= sprintf(p
+ len
, "\n");
1818 /* These are way too dangerous to advertise openly... */
1820 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
1821 " (<offset> is 00-ff, <value> is 00-ff)\n");
1822 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
1823 " (<offset> is 00-ff, <value> is 0-255)\n");
1828 static int ecdump_write(char *buf
)
1833 while ((cmd
= next_cmd(&buf
))) {
1834 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
1836 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
1840 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
1841 if (!acpi_ec_write(i
, v
))
1850 static struct ibm_struct ecdump_driver_data
= {
1852 .read
= ecdump_read
,
1853 .write
= ecdump_write
,
1854 .flags
.experimental
= 1,
1857 /*************************************************************************
1858 * Backlight/brightness subdriver
1861 static struct backlight_device
*ibm_backlight_device
= NULL
;
1863 static struct backlight_ops ibm_backlight_data
= {
1864 .get_brightness
= brightness_get
,
1865 .update_status
= brightness_update_status
,
1868 static int __init
brightness_init(struct ibm_init_struct
*iibm
)
1872 vdbg_printk(TPACPI_DBG_INIT
, "initializing brightness subdriver\n");
1874 b
= brightness_get(NULL
);
1878 ibm_backlight_device
= backlight_device_register("ibm", NULL
, NULL
,
1879 &ibm_backlight_data
);
1880 if (IS_ERR(ibm_backlight_device
)) {
1881 printk(IBM_ERR
"Could not register backlight device\n");
1882 return PTR_ERR(ibm_backlight_device
);
1884 vdbg_printk(TPACPI_DBG_INIT
, "brightness is supported\n");
1886 ibm_backlight_device
->props
.max_brightness
= 7;
1887 ibm_backlight_device
->props
.brightness
= b
;
1888 backlight_update_status(ibm_backlight_device
);
1893 static void brightness_exit(void)
1895 if (ibm_backlight_device
) {
1896 vdbg_printk(TPACPI_DBG_EXIT
,
1897 "calling backlight_device_unregister()\n");
1898 backlight_device_unregister(ibm_backlight_device
);
1899 ibm_backlight_device
= NULL
;
1903 static int brightness_update_status(struct backlight_device
*bd
)
1905 return brightness_set(
1906 (bd
->props
.fb_blank
== FB_BLANK_UNBLANK
&&
1907 bd
->props
.power
== FB_BLANK_UNBLANK
) ?
1908 bd
->props
.brightness
: 0);
1911 static int brightness_get(struct backlight_device
*bd
)
1914 if (!acpi_ec_read(brightness_offset
, &level
))
1922 static int brightness_set(int value
)
1924 int cmos_cmd
, inc
, i
;
1925 int current_value
= brightness_get(NULL
);
1929 cmos_cmd
= value
> current_value
? TP_CMOS_BRIGHTNESS_UP
: TP_CMOS_BRIGHTNESS_DOWN
;
1930 inc
= value
> current_value
? 1 : -1;
1931 for (i
= current_value
; i
!= value
; i
+= inc
) {
1932 if (!cmos_eval(cmos_cmd
))
1934 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
1941 static int brightness_read(char *p
)
1946 if ((level
= brightness_get(NULL
)) < 0) {
1947 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
1949 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
1950 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
1951 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1952 " (<level> is 0-7)\n");
1958 static int brightness_write(char *buf
)
1964 while ((cmd
= next_cmd(&buf
))) {
1965 if ((level
= brightness_get(NULL
)) < 0)
1969 if (strlencmp(cmd
, "up") == 0) {
1970 new_level
= level
== 7 ? 7 : level
+ 1;
1971 } else if (strlencmp(cmd
, "down") == 0) {
1972 new_level
= level
== 0 ? 0 : level
- 1;
1973 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
1974 new_level
>= 0 && new_level
<= 7) {
1979 brightness_set(new_level
);
1985 static struct ibm_struct brightness_driver_data
= {
1986 .name
= "brightness",
1987 .read
= brightness_read
,
1988 .write
= brightness_write
,
1989 .exit
= brightness_exit
,
1992 /*************************************************************************
1996 static int volume_read(char *p
)
2001 if (!acpi_ec_read(volume_offset
, &level
)) {
2002 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
2004 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
2005 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
2006 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
2007 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
2008 " (<level> is 0-15)\n");
2014 static int volume_write(char *buf
)
2016 int cmos_cmd
, inc
, i
;
2018 int new_level
, new_mute
;
2021 while ((cmd
= next_cmd(&buf
))) {
2022 if (!acpi_ec_read(volume_offset
, &level
))
2024 new_mute
= mute
= level
& 0x40;
2025 new_level
= level
= level
& 0xf;
2027 if (strlencmp(cmd
, "up") == 0) {
2031 new_level
= level
== 15 ? 15 : level
+ 1;
2032 } else if (strlencmp(cmd
, "down") == 0) {
2036 new_level
= level
== 0 ? 0 : level
- 1;
2037 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
2038 new_level
>= 0 && new_level
<= 15) {
2040 } else if (strlencmp(cmd
, "mute") == 0) {
2045 if (new_level
!= level
) { /* mute doesn't change */
2046 cmos_cmd
= new_level
> level
? TP_CMOS_VOLUME_UP
: TP_CMOS_VOLUME_DOWN
;
2047 inc
= new_level
> level
? 1 : -1;
2049 if (mute
&& (!cmos_eval(cmos_cmd
) ||
2050 !acpi_ec_write(volume_offset
, level
)))
2053 for (i
= level
; i
!= new_level
; i
+= inc
)
2054 if (!cmos_eval(cmos_cmd
) ||
2055 !acpi_ec_write(volume_offset
, i
+ inc
))
2058 if (mute
&& (!cmos_eval(TP_CMOS_VOLUME_MUTE
) ||
2059 !acpi_ec_write(volume_offset
,
2064 if (new_mute
!= mute
) { /* level doesn't change */
2065 cmos_cmd
= new_mute
? TP_CMOS_VOLUME_MUTE
: TP_CMOS_VOLUME_UP
;
2067 if (!cmos_eval(cmos_cmd
) ||
2068 !acpi_ec_write(volume_offset
, level
+ new_mute
))
2076 static struct ibm_struct volume_driver_data
= {
2078 .read
= volume_read
,
2079 .write
= volume_write
,
2082 /*************************************************************************
2089 * TPACPI_FAN_RD_ACPI_GFAN:
2090 * ACPI GFAN method: returns fan level
2092 * see TPACPI_FAN_WR_ACPI_SFAN
2093 * EC 0x2f (HFSP) not available if GFAN exists
2095 * TPACPI_FAN_WR_ACPI_SFAN:
2096 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
2098 * EC 0x2f (HFSP) might be available *for reading*, but do not use
2101 * TPACPI_FAN_WR_TPEC:
2102 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
2103 * Supported on almost all ThinkPads
2105 * Fan speed changes of any sort (including those caused by the
2106 * disengaged mode) are usually done slowly by the firmware as the
2107 * maximum ammount of fan duty cycle change per second seems to be
2110 * Reading is not available if GFAN exists.
2111 * Writing is not available if SFAN exists.
2114 * 7 automatic mode engaged;
2115 * (default operation mode of the ThinkPad)
2116 * fan level is ignored in this mode.
2117 * 6 full speed mode (takes precedence over bit 7);
2118 * not available on all thinkpads. May disable
2119 * the tachometer while the fan controller ramps up
2120 * the speed (which can take up to a few *minutes*).
2121 * Speeds up fan to 100% duty-cycle, which is far above
2122 * the standard RPM levels. It is not impossible that
2123 * it could cause hardware damage.
2124 * 5-3 unused in some models. Extra bits for fan level
2125 * in others, but still useless as all values above
2126 * 7 map to the same speed as level 7 in these models.
2127 * 2-0 fan level (0..7 usually)
2129 * 0x07 = max (set when temperatures critical)
2130 * Some ThinkPads may have other levels, see
2131 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
2133 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
2134 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
2135 * does so, its initial value is meaningless (0x07).
2137 * For firmware bugs, refer to:
2138 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2142 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
2143 * Main fan tachometer reading (in RPM)
2145 * This register is present on all ThinkPads with a new-style EC, and
2146 * it is known not to be present on the A21m/e, and T22, as there is
2147 * something else in offset 0x84 according to the ACPI DSDT. Other
2148 * ThinkPads from this same time period (and earlier) probably lack the
2149 * tachometer as well.
2151 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
2152 * was never fixed by IBM to report the EC firmware version string
2153 * probably support the tachometer (like the early X models), so
2154 * detecting it is quite hard. We need more data to know for sure.
2156 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
2159 * FIRMWARE BUG: may go stale while the EC is switching to full speed
2162 * For firmware bugs, refer to:
2163 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2165 * TPACPI_FAN_WR_ACPI_FANS:
2166 * ThinkPad X31, X40, X41. Not available in the X60.
2168 * FANS ACPI handle: takes three arguments: low speed, medium speed,
2169 * high speed. ACPI DSDT seems to map these three speeds to levels
2170 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
2171 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
2173 * The speeds are stored on handles
2174 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
2176 * There are three default speed sets, acessible as handles:
2177 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
2179 * ACPI DSDT switches which set is in use depending on various
2182 * TPACPI_FAN_WR_TPEC is also available and should be used to
2183 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
2184 * but the ACPI tables just mention level 7.
2187 static enum fan_status_access_mode fan_status_access_mode
;
2188 static enum fan_control_access_mode fan_control_access_mode
;
2189 static enum fan_control_commands fan_control_commands
;
2191 static int fan_control_status_known
;
2192 static u8 fan_control_initial_status
;
2194 static void fan_watchdog_fire(struct work_struct
*ignored
);
2195 static int fan_watchdog_maxinterval
;
2196 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
2198 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
2199 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
2200 "\\FSPD", /* 600e/x, 770e, 770x */
2202 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
2203 "JFNS", /* 770x-JL */
2206 static int __init
fan_init(struct ibm_init_struct
*iibm
)
2208 vdbg_printk(TPACPI_DBG_INIT
, "initializing fan subdriver\n");
2210 fan_status_access_mode
= TPACPI_FAN_NONE
;
2211 fan_control_access_mode
= TPACPI_FAN_WR_NONE
;
2212 fan_control_commands
= 0;
2213 fan_control_status_known
= 1;
2214 fan_watchdog_maxinterval
= 0;
2216 IBM_HANDLE_INIT(fans
);
2217 IBM_HANDLE_INIT(gfan
);
2218 IBM_HANDLE_INIT(sfan
);
2221 /* 570, 600e/x, 770e, 770x */
2222 fan_status_access_mode
= TPACPI_FAN_RD_ACPI_GFAN
;
2224 /* all other ThinkPads: note that even old-style
2225 * ThinkPad ECs supports the fan control register */
2226 if (likely(acpi_ec_read(fan_status_offset
,
2227 &fan_control_initial_status
))) {
2228 fan_status_access_mode
= TPACPI_FAN_RD_TPEC
;
2230 /* In some ThinkPads, neither the EC nor the ACPI
2231 * DSDT initialize the fan status, and it ends up
2232 * being set to 0x07 when it *could* be either
2235 * Enable for TP-1Y (T43), TP-78 (R51e),
2236 * TP-76 (R52), TP-70 (T43, R52), which are known
2238 if (fan_control_initial_status
== 0x07 &&
2239 ibm_thinkpad_ec_found
&&
2240 ((ibm_thinkpad_ec_found
[0] == '1' &&
2241 ibm_thinkpad_ec_found
[1] == 'Y') ||
2242 (ibm_thinkpad_ec_found
[0] == '7' &&
2243 (ibm_thinkpad_ec_found
[1] == '6' ||
2244 ibm_thinkpad_ec_found
[1] == '8' ||
2245 ibm_thinkpad_ec_found
[1] == '0'))
2248 "fan_init: initial fan status is "
2249 "unknown, assuming it is in auto "
2251 fan_control_status_known
= 0;
2255 "ThinkPad ACPI EC access misbehaving, "
2256 "fan status and control unavailable\n");
2263 fan_control_access_mode
= TPACPI_FAN_WR_ACPI_SFAN
;
2264 fan_control_commands
|=
2265 TPACPI_FAN_CMD_LEVEL
| TPACPI_FAN_CMD_ENABLE
;
2268 /* gfan without sfan means no fan control */
2269 /* all other models implement TP EC 0x2f control */
2273 fan_control_access_mode
=
2274 TPACPI_FAN_WR_ACPI_FANS
;
2275 fan_control_commands
|=
2276 TPACPI_FAN_CMD_SPEED
|
2277 TPACPI_FAN_CMD_LEVEL
|
2278 TPACPI_FAN_CMD_ENABLE
;
2280 fan_control_access_mode
= TPACPI_FAN_WR_TPEC
;
2281 fan_control_commands
|=
2282 TPACPI_FAN_CMD_LEVEL
|
2283 TPACPI_FAN_CMD_ENABLE
;
2288 vdbg_printk(TPACPI_DBG_INIT
, "fan is %s, modes %d, %d\n",
2289 str_supported(fan_status_access_mode
!= TPACPI_FAN_NONE
||
2290 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
),
2291 fan_status_access_mode
, fan_control_access_mode
);
2293 return (fan_status_access_mode
!= TPACPI_FAN_NONE
||
2294 fan_control_access_mode
!= TPACPI_FAN_WR_NONE
)?
2298 static int fan_get_status(u8
*status
)
2303 * Add TPACPI_FAN_RD_ACPI_FANS ? */
2305 switch (fan_status_access_mode
) {
2306 case TPACPI_FAN_RD_ACPI_GFAN
:
2307 /* 570, 600e/x, 770e, 770x */
2309 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
2317 case TPACPI_FAN_RD_TPEC
:
2318 /* all except 570, 600e/x, 770e, 770x */
2319 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
2334 static void fan_exit(void)
2336 vdbg_printk(TPACPI_DBG_EXIT
, "cancelling any pending watchdogs\n");
2337 cancel_delayed_work(&fan_watchdog_task
);
2338 flush_scheduled_work();
2341 static int fan_get_speed(unsigned int *speed
)
2345 switch (fan_status_access_mode
) {
2346 case TPACPI_FAN_RD_TPEC
:
2347 /* all except 570, 600e/x, 770e, 770x */
2348 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
2349 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
2353 *speed
= (hi
<< 8) | lo
;
2364 static void fan_watchdog_fire(struct work_struct
*ignored
)
2366 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
2367 if (fan_set_enable()) {
2368 printk(IBM_ERR
"fan watchdog: error while enabling fan\n");
2369 /* reschedule for later */
2370 fan_watchdog_reset();
2374 static void fan_watchdog_reset(void)
2376 static int fan_watchdog_active
= 0;
2378 if (fan_watchdog_active
)
2379 cancel_delayed_work(&fan_watchdog_task
);
2381 if (fan_watchdog_maxinterval
> 0) {
2382 fan_watchdog_active
= 1;
2383 if (!schedule_delayed_work(&fan_watchdog_task
,
2384 msecs_to_jiffies(fan_watchdog_maxinterval
2386 printk(IBM_ERR
"failed to schedule the fan watchdog, "
2387 "watchdog will not trigger\n");
2390 fan_watchdog_active
= 0;
2393 static int fan_set_level(int level
)
2395 switch (fan_control_access_mode
) {
2396 case TPACPI_FAN_WR_ACPI_SFAN
:
2397 if (level
>= 0 && level
<= 7) {
2398 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
2404 case TPACPI_FAN_WR_ACPI_FANS
:
2405 case TPACPI_FAN_WR_TPEC
:
2406 if ((level
!= TP_EC_FAN_AUTO
) &&
2407 (level
!= TP_EC_FAN_FULLSPEED
) &&
2408 ((level
< 0) || (level
> 7)))
2411 if (!acpi_ec_write(fan_status_offset
, level
))
2414 fan_control_status_known
= 1;
2423 static int fan_set_enable(void)
2428 switch (fan_control_access_mode
) {
2429 case TPACPI_FAN_WR_ACPI_FANS
:
2430 case TPACPI_FAN_WR_TPEC
:
2431 if ((rc
= fan_get_status(&s
)) < 0)
2434 /* Don't go out of emergency fan mode */
2438 if (!acpi_ec_write(fan_status_offset
, s
))
2441 fan_control_status_known
= 1;
2444 case TPACPI_FAN_WR_ACPI_SFAN
:
2445 if ((rc
= fan_get_status(&s
)) < 0)
2450 /* Set fan to at least level 4 */
2454 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
2464 static int fan_set_disable(void)
2466 switch (fan_control_access_mode
) {
2467 case TPACPI_FAN_WR_ACPI_FANS
:
2468 case TPACPI_FAN_WR_TPEC
:
2469 if (!acpi_ec_write(fan_status_offset
, 0x00))
2472 fan_control_status_known
= 1;
2475 case TPACPI_FAN_WR_ACPI_SFAN
:
2476 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
2486 static int fan_set_speed(int speed
)
2488 switch (fan_control_access_mode
) {
2489 case TPACPI_FAN_WR_ACPI_FANS
:
2490 if (speed
>= 0 && speed
<= 65535) {
2491 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
2492 speed
, speed
, speed
))
2504 static int fan_read(char *p
)
2509 unsigned int speed
= 0;
2511 switch (fan_status_access_mode
) {
2512 case TPACPI_FAN_RD_ACPI_GFAN
:
2513 /* 570, 600e/x, 770e, 770x */
2514 if ((rc
= fan_get_status(&status
)) < 0)
2517 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
2519 (status
!= 0) ? "enabled" : "disabled", status
);
2522 case TPACPI_FAN_RD_TPEC
:
2523 /* all except 570, 600e/x, 770e, 770x */
2524 if ((rc
= fan_get_status(&status
)) < 0)
2527 if (unlikely(!fan_control_status_known
)) {
2528 if (status
!= fan_control_initial_status
)
2529 fan_control_status_known
= 1;
2531 /* Return most likely status. In fact, it
2532 * might be the only possible status */
2533 status
= TP_EC_FAN_AUTO
;
2536 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2537 (status
!= 0) ? "enabled" : "disabled");
2539 if ((rc
= fan_get_speed(&speed
)) < 0)
2542 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
2544 if (status
& TP_EC_FAN_FULLSPEED
)
2545 /* Disengaged mode takes precedence */
2546 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
2547 else if (status
& TP_EC_FAN_AUTO
)
2548 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
2550 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
2553 case TPACPI_FAN_NONE
:
2555 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2558 if (fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) {
2559 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
2561 switch (fan_control_access_mode
) {
2562 case TPACPI_FAN_WR_ACPI_SFAN
:
2563 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
2567 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
2568 "auto, disengaged)\n");
2573 if (fan_control_commands
& TPACPI_FAN_CMD_ENABLE
)
2574 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
2575 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
2576 "1-120 (seconds))\n");
2578 if (fan_control_commands
& TPACPI_FAN_CMD_SPEED
)
2579 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
2580 " (<speed> is 0-65535)\n");
2585 static int fan_write_cmd_level(const char *cmd
, int *rc
)
2589 if (strlencmp(cmd
, "level auto") == 0)
2590 level
= TP_EC_FAN_AUTO
;
2591 else if (strlencmp(cmd
, "level disengaged") == 0)
2592 level
= TP_EC_FAN_FULLSPEED
;
2593 else if (sscanf(cmd
, "level %d", &level
) != 1)
2596 if ((*rc
= fan_set_level(level
)) == -ENXIO
)
2597 printk(IBM_ERR
"level command accepted for unsupported "
2598 "access mode %d", fan_control_access_mode
);
2603 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
2605 if (strlencmp(cmd
, "enable") != 0)
2608 if ((*rc
= fan_set_enable()) == -ENXIO
)
2609 printk(IBM_ERR
"enable command accepted for unsupported "
2610 "access mode %d", fan_control_access_mode
);
2615 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
2617 if (strlencmp(cmd
, "disable") != 0)
2620 if ((*rc
= fan_set_disable()) == -ENXIO
)
2621 printk(IBM_ERR
"disable command accepted for unsupported "
2622 "access mode %d", fan_control_access_mode
);
2627 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
2632 * Support speed <low> <medium> <high> ? */
2634 if (sscanf(cmd
, "speed %d", &speed
) != 1)
2637 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
2638 printk(IBM_ERR
"speed command accepted for unsupported "
2639 "access mode %d", fan_control_access_mode
);
2644 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
2648 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
2651 if (interval
< 0 || interval
> 120)
2654 fan_watchdog_maxinterval
= interval
;
2659 static int fan_write(char *buf
)
2664 while (!rc
&& (cmd
= next_cmd(&buf
))) {
2665 if (!((fan_control_commands
& TPACPI_FAN_CMD_LEVEL
) &&
2666 fan_write_cmd_level(cmd
, &rc
)) &&
2667 !((fan_control_commands
& TPACPI_FAN_CMD_ENABLE
) &&
2668 (fan_write_cmd_enable(cmd
, &rc
) ||
2669 fan_write_cmd_disable(cmd
, &rc
) ||
2670 fan_write_cmd_watchdog(cmd
, &rc
))) &&
2671 !((fan_control_commands
& TPACPI_FAN_CMD_SPEED
) &&
2672 fan_write_cmd_speed(cmd
, &rc
))
2676 fan_watchdog_reset();
2682 static struct ibm_struct fan_driver_data
= {
2687 .flags
.experimental
= 1,
2690 /****************************************************************************
2691 ****************************************************************************
2695 ****************************************************************************
2696 ****************************************************************************/
2699 static struct proc_dir_entry
*proc_dir
= NULL
;
2701 /* Subdriver registry */
2702 static LIST_HEAD(tpacpi_all_drivers
);
2706 * Module and infrastructure proble, init and exit handling
2709 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
2710 static const char * __init
str_supported(int is_supported
)
2712 static char text_unsupported
[] __initdata
= "not supported";
2714 return (is_supported
)? &text_unsupported
[4] : &text_unsupported
[0];
2716 #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
2718 static int __init
ibm_init(struct ibm_init_struct
*iibm
)
2721 struct ibm_struct
*ibm
= iibm
->data
;
2722 struct proc_dir_entry
*entry
;
2724 BUG_ON(ibm
== NULL
);
2726 INIT_LIST_HEAD(&ibm
->all_drivers
);
2728 if (ibm
->flags
.experimental
&& !experimental
)
2731 dbg_printk(TPACPI_DBG_INIT
,
2732 "probing for %s\n", ibm
->name
);
2735 ret
= iibm
->init(iibm
);
2737 return 0; /* probe failed */
2741 ibm
->flags
.init_called
= 1;
2745 ret
= register_tpacpi_subdriver(ibm
);
2751 ret
= setup_notify(ibm
);
2752 if (ret
== -ENODEV
) {
2753 printk(IBM_NOTICE
"disabling subdriver %s\n",
2762 dbg_printk(TPACPI_DBG_INIT
,
2763 "%s installed\n", ibm
->name
);
2766 entry
= create_proc_entry(ibm
->name
,
2767 S_IFREG
| S_IRUGO
| S_IWUSR
,
2770 printk(IBM_ERR
"unable to create proc entry %s\n",
2775 entry
->owner
= THIS_MODULE
;
2777 entry
->read_proc
= &dispatch_read
;
2779 entry
->write_proc
= &dispatch_write
;
2780 ibm
->flags
.proc_created
= 1;
2783 list_add_tail(&ibm
->all_drivers
, &tpacpi_all_drivers
);
2788 dbg_printk(TPACPI_DBG_INIT
,
2789 "%s: at error exit path with result %d\n",
2793 return (ret
< 0)? ret
: 0;
2796 static void ibm_exit(struct ibm_struct
*ibm
)
2798 dbg_printk(TPACPI_DBG_EXIT
, "removing %s\n", ibm
->name
);
2800 list_del_init(&ibm
->all_drivers
);
2802 if (ibm
->flags
.notify_installed
) {
2803 dbg_printk(TPACPI_DBG_EXIT
,
2804 "%s: acpi_remove_notify_handler\n", ibm
->name
);
2805 acpi_remove_notify_handler(*ibm
->handle
, ibm
->type
,
2807 ibm
->flags
.notify_installed
= 0;
2810 if (ibm
->flags
.proc_created
) {
2811 dbg_printk(TPACPI_DBG_EXIT
,
2812 "%s: remove_proc_entry\n", ibm
->name
);
2813 remove_proc_entry(ibm
->name
, proc_dir
);
2814 ibm
->flags
.proc_created
= 0;
2817 if (ibm
->flags
.driver_registered
) {
2818 dbg_printk(TPACPI_DBG_EXIT
,
2819 "%s: acpi_bus_unregister_driver\n", ibm
->name
);
2820 acpi_bus_unregister_driver(ibm
->driver
);
2823 ibm
->flags
.driver_registered
= 0;
2826 if (ibm
->flags
.init_called
&& ibm
->exit
) {
2828 ibm
->flags
.init_called
= 0;
2831 dbg_printk(TPACPI_DBG_INIT
, "finished removing %s\n", ibm
->name
);
2836 static char *ibm_thinkpad_ec_found
= NULL
;
2838 static char* __init
check_dmi_for_ec(void)
2840 struct dmi_device
*dev
= NULL
;
2841 char ec_fw_string
[18];
2844 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
2845 * X32 or newer, all Z series; Some models must have an
2846 * up-to-date BIOS or they will not be detected.
2848 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
2850 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
2851 if (sscanf(dev
->name
,
2852 "IBM ThinkPad Embedded Controller -[%17c",
2853 ec_fw_string
) == 1) {
2854 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
2855 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
2856 return kstrdup(ec_fw_string
, GFP_KERNEL
);
2862 static int __init
probe_for_thinkpad(void)
2870 * Non-ancient models have better DMI tagging, but very old models
2873 is_thinkpad
= dmi_name_in_vendors("ThinkPad");
2875 /* ec is required because many other handles are relative to it */
2876 IBM_HANDLE_INIT(ec
);
2880 "Not yet supported ThinkPad detected!\n");
2885 * Risks a regression on very old machines, but reduces potential
2886 * false positives a damn great deal
2889 is_thinkpad
= dmi_name_in_vendors("IBM");
2891 if (!is_thinkpad
&& !force_load
)
2898 /* Module init, exit, parameters */
2900 static struct ibm_init_struct ibms_init
[] __initdata
= {
2902 .init
= thinkpad_acpi_driver_init
,
2903 .data
= &thinkpad_acpi_driver_data
,
2906 .init
= hotkey_init
,
2907 .data
= &hotkey_driver_data
,
2910 .init
= bluetooth_init
,
2911 .data
= &bluetooth_driver_data
,
2915 .data
= &wan_driver_data
,
2919 .data
= &video_driver_data
,
2923 .data
= &light_driver_data
,
2925 #ifdef CONFIG_THINKPAD_ACPI_DOCK
2928 .data
= &dock_driver_data
[0],
2931 .data
= &dock_driver_data
[1],
2934 #ifdef CONFIG_THINKPAD_ACPI_BAY
2937 .data
= &bay_driver_data
,
2942 .data
= &cmos_driver_data
,
2946 .data
= &led_driver_data
,
2950 .data
= &beep_driver_data
,
2953 .init
= thermal_init
,
2954 .data
= &thermal_driver_data
,
2957 .data
= &ecdump_driver_data
,
2960 .init
= brightness_init
,
2961 .data
= &brightness_driver_data
,
2964 .data
= &volume_driver_data
,
2968 .data
= &fan_driver_data
,
2972 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
2975 struct ibm_struct
*ibm
;
2977 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
2978 ibm
= ibms_init
[i
].data
;
2979 BUG_ON(ibm
== NULL
);
2981 if (strcmp(ibm
->name
, kp
->name
) == 0 && ibm
->write
) {
2982 if (strlen(val
) > sizeof(ibms_init
[i
].param
) - 2)
2984 strcpy(ibms_init
[i
].param
, val
);
2985 strcat(ibms_init
[i
].param
, ",");
2993 static int experimental
;
2994 module_param(experimental
, int, 0);
2996 static u32 dbg_level
;
2997 module_param_named(debug
, dbg_level
, uint
, 0);
2999 static int force_load
;
3000 module_param(force_load
, int, 0);
3002 #define IBM_PARAM(feature) \
3003 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
3006 IBM_PARAM(bluetooth
);
3009 #ifdef CONFIG_THINKPAD_ACPI_DOCK
3012 #ifdef CONFIG_THINKPAD_ACPI_BAY
3014 #endif /* CONFIG_THINKPAD_ACPI_BAY */
3019 IBM_PARAM(brightness
);
3023 static int __init
thinkpad_acpi_module_init(void)
3027 ret
= probe_for_thinkpad();
3031 ibm_thinkpad_ec_found
= check_dmi_for_ec();
3032 IBM_HANDLE_INIT(ecrd
);
3033 IBM_HANDLE_INIT(ecwr
);
3035 proc_dir
= proc_mkdir(IBM_DIR
, acpi_root_dir
);
3037 printk(IBM_ERR
"unable to create proc dir %s", IBM_DIR
);
3038 thinkpad_acpi_module_exit();
3041 proc_dir
->owner
= THIS_MODULE
;
3043 for (i
= 0; i
< ARRAY_SIZE(ibms_init
); i
++) {
3044 ret
= ibm_init(&ibms_init
[i
]);
3045 if (ret
>= 0 && *ibms_init
[i
].param
)
3046 ret
= ibms_init
[i
].data
->write(ibms_init
[i
].param
);
3048 thinkpad_acpi_module_exit();
3056 static void thinkpad_acpi_module_exit(void)
3058 struct ibm_struct
*ibm
, *itmp
;
3060 list_for_each_entry_safe_reverse(ibm
, itmp
,
3061 &tpacpi_all_drivers
,
3066 dbg_printk(TPACPI_DBG_INIT
, "finished subdriver exit path...\n");
3069 remove_proc_entry(IBM_DIR
, acpi_root_dir
);
3071 if (ibm_thinkpad_ec_found
)
3072 kfree(ibm_thinkpad_ec_found
);
3075 module_init(thinkpad_acpi_module_init
);
3076 module_exit(thinkpad_acpi_module_exit
);